/**
  * Création du patientRole
  *
  * @return CCDAPOCD_MT000040_PatientRole
  */
 function setPatientRole()
 {
     $patientRole = new CCDAPOCD_MT000040_PatientRole();
     $patient = self::$cda_factory->patient;
     if ($patient->_ref_last_ins) {
         $ii = new CCDAII();
         $ii->setRoot("1.2.250.1.213.1.4.2");
         $ii->setExtension($patient->_ref_last_ins->ins);
         $patientRole->appendId($ii);
     }
     $ii = new CCDAII();
     $ii->setRoot(CMbOID::getOIDOfInstance($patient, self::$cda_factory->receiver));
     $ii->setExtension($patient->_id);
     $patientRole->appendId($ii);
     if ($patient->_IPP) {
         $ii = new CCDAII();
         /* @todo Gérer le master domaine*/
         //$group_domain = new CGroupDomain();
         //$group_domain->loadM
         $ii->setRoot(self::$cda_factory->root);
         $ii->setExtension($patient->_IPP);
         //libelle du domaine
         $ii->setAssigningAuthorityName("");
         $patientRole->appendId($ii);
     }
     $ad = $this->setAddress($patient);
     $patientRole->appendAddr($ad);
     $this->setTelecom($patientRole, $patient);
     $patientRole->setPatient(parent::$entite->setPatient());
     return $patientRole;
 }
 /**
  * Retourne l'OID du patient
  *
  * @param CPatient         $patient  Patient
  * @param CInteropReceiver $receiver Receiver
  *
  * @return string
  */
 function getID($patient, $receiver)
 {
     $oid = CMbOID::getOIDOfInstance($patient, $receiver);
     $comp4 = $oid;
     $comp4 = "&{$comp4}&ISO";
     $comp1 = $patient->_IPP ? $patient->_IPP : $patient->_id;
     $comp5 = "PI";
     $result = "{$comp1}^^^{$comp4}^{$comp5}";
     return $result;
 }
 /**
  * @see parent::createRegistryPackage
  */
 function createRegistryPackage($id)
 {
     /** @var CCDAFactory $factory */
     $factory = $this->mbObject;
     $cla_id =& $this->id_classification;
     $ei_id =& $this->id_external;
     $ins = $this->ins_patient;
     $this->name_submission = $id;
     $specialty = $this->specialty;
     $object = $this->targetObject;
     $registry = new CXDSRegistryPackage($id);
     //date de soumission
     $registry->setSubmissionTime(array(CXDSTools::getTimeUtc()));
     //PS qui envoie le document
     $document = new CXDSDocumentEntryAuthor("cla{$cla_id}", $id, true);
     $this->setClaId();
     $document->setAuthorPerson(array($this->xcn_mediuser));
     $document->setAuthorSpecialty(array($specialty));
     //Institution qui envoie le document
     $document->setAuthorInstitution(array($this->xon_etablissement));
     $registry->appendDocumentEntryAuthor($document);
     //type d'activité pour lequel on envoie les documents
     $code = "";
     switch (get_class($object)) {
         case "COperation":
             $object = $object->loadRefSejour();
         case "CSejour":
             switch ($object->type) {
                 case "comp":
                     $code = "03";
                     break;
                 case "ambu":
                     $code = "23";
                     break;
                 case "urg":
                     $code = "10";
                     break;
                 default:
                     $code = "07";
             }
             break;
         case "CConsultation":
             $code = "07";
             break;
         default:
     }
     $entry = CXDSTools::loadEntryJV("ASIP-SANTE_contentTypeCode.xml", $code);
     $content = new CXDSContentType("cla{$cla_id}", $id, $entry["id"]);
     $this->setClaId();
     $content->setCodingScheme(array($entry["oid"]));
     $content->setContentTypeCodeDisplayName($entry["name"]);
     $registry->setContentType($content);
     //spécification d'un SubmissionSet ou d'un folder, ici submissionSet
     $registry->setSubmissionSet("cla{$cla_id}", $id, false);
     $this->setClaId();
     //patient du document
     $registry->setPatientId("ei{$ei_id}", $id, $ins);
     $this->setEiId();
     $receiver = $factory->receiver;
     //OID de l'instance serveur
     $oid_instance = CMbOID::getOIDOfInstance($registry, $receiver);
     $registry->setSourceId("ei{$ei_id}", $id, $oid_instance);
     $this->setEiId();
     //OID unique
     $oid = CMbOID::getOIDFromClass($registry, $receiver);
     $cxds_submissionlot = new CXDSSubmissionLot();
     $cxds_submissionlot->date = "now";
     $cxds_submissionlot->type = $this->type;
     if ($msg = $cxds_submissionlot->store()) {
         throw new CMbException($msg);
     }
     $this->id_submission = $cxds_submissionlot->_id;
     $this->oid["lot"] = "{$oid}.{$cxds_submissionlot->_id}";
     $registry->setUniqueId("ei{$ei_id}", $id, $this->oid["lot"]);
     $this->setEiId();
     return $registry;
 }