/** * merge the patient * * @param String $identifier identifier * @param String $tag tag * @param CPatient $patient patient * * @return null|CHPrimSanteError */ function mergePatient($identifier, $tag, CPatient $patient) { $idex = CIdSante400::getMatch("CPatient", $tag, $identifier["identifier"]); if (!$idex->_id) { return new CHPrimSanteError($this->_ref_exchange_hpr, "P", "02", array("P", $this->loop, $this->identifier_patient), "8.3.1"); } $idex2 = CIdSante400::getMatch("CPatient", $tag, $identifier["identifier_merge"]); if (!$idex2->_id) { return new CHPrimSanteError($this->_ref_exchange_hpr, "P", "02", array("P", $this->loop, $this->identifier_patient), "8.3.2"); } $patient->load($idex->object_id); $patient2 = new CPatient(); $patient2->load($idex2->object_id); $patientsElimine_array = array($patient2); $first_patient_id = $patient->_id; // Erreur sur le check du merge if ($checkMerge = $patient->checkMerge($patientsElimine_array)) { return new CHPrimSanteError($this->_ref_exchange_hpr, "P", "12", array("P", $this->loop, $this->identifier_patient), "8.3.3", $checkMerge); } $mbPatientElimine_id = $patient2->_id; /** @todo mergePlainFields resets the _id */ $patient->_id = $first_patient_id; // Notifier les autres destinataires $patient->_eai_sender_guid = $this->_ref_sender->_guid; $patient->_merging = CMbArray::pluck($patientsElimine_array, "_id"); if ($msg = $patient->merge($patientsElimine_array)) { return new CHPrimSanteError($this->_ref_exchange_hpr, "P", "12", array("P", $this->loop, $this->identifier_patient), "8.3.3", $msg); } $patient->_mbPatientElimine_id = $mbPatientElimine_id; return null; }
/** * Handle event * * @param CHL7Acknowledgment $ack Acknowledgement * @param CPatient $newPatient Person * @param array $data Nodes data * * @return null|string */ function handle(CHL7Acknowledgment $ack, CPatient $newPatient, $data) { // Traitement du message des erreurs $comment = $warning = ""; $exchange_hl7v2 = $this->_ref_exchange_hl7v2; $exchange_hl7v2->_ref_sender->loadConfigValues(); $sender = $exchange_hl7v2->_ref_sender; foreach ($data["merge"] as $_data_merge) { $data = $_data_merge; $mbPatient = new CPatient(); $mbPatientElimine = new CPatient(); $patientPI = CValue::read($data['personIdentifiers'], "PI"); $patientRI = CValue::read($data['personIdentifiers'], "RI"); $patientEliminePI = CValue::read($data['personElimineIdentifiers'], "PI"); $patientElimineRI = CValue::read($data['personElimineIdentifiers'], "RI"); // Acquittement d'erreur : identifiants RI et PI non fournis if (!$patientRI && !$patientPI || !$patientElimineRI && !$patientEliminePI) { return $exchange_hl7v2->setAckAR($ack, "E100", null, $newPatient); } $idexPatient = CIdSante400::getMatch("CPatient", $sender->_tag_patient, $patientPI); if ($mbPatient->load($patientRI)) { if ($idexPatient->object_id && $mbPatient->_id != $idexPatient->object_id) { $comment = "L'identifiant source fait référence au patient : {$idexPatient->object_id}"; $comment .= " et l'identifiant cible au patient : {$mbPatient->_id}."; return $exchange_hl7v2->setAckAR($ack, "E130", $comment, $newPatient); } } if (!$mbPatient->_id) { $mbPatient->load($idexPatient->object_id); } $idexPatientElimine = CIdSante400::getMatch("CPatient", $sender->_tag_patient, $patientEliminePI); if ($mbPatientElimine->load($patientElimineRI)) { if ($idexPatientElimine->object_id && $mbPatientElimine->_id != $idexPatientElimine->object_id) { $comment = "L'identifiant source fait référence au patient : {$idexPatientElimine->object_id}"; $comment .= "et l'identifiant cible au patient : {$mbPatientElimine->_id}."; return $exchange_hl7v2->setAckAR($ack, "E131", $comment, $newPatient); } } if (!$mbPatientElimine->_id) { $mbPatientElimine->load($idexPatientElimine->object_id); } if (!$mbPatient->_id || !$mbPatientElimine->_id) { $comment = !$mbPatient->_id ? "Le patient {$mbPatient->_id} est inconnu dans Mediboard." : "Le patient {$mbPatientElimine->_id} est inconnu dans Mediboard."; return $exchange_hl7v2->setAckAR($ack, "E120", $comment, $newPatient); } // Passage en trash de l'IPP du patient a éliminer $newPatient->trashIPP($idexPatientElimine); if ($mbPatient->_id == $mbPatientElimine->_id) { return $exchange_hl7v2->setAckAA($ack, "I104", null, $newPatient); } $patientsElimine_array = array($mbPatientElimine); $first_patient_id = $mbPatient->_id; $checkMerge = $mbPatient->checkMerge($patientsElimine_array); // Erreur sur le check du merge if ($checkMerge) { $comment = "La fusion de ces deux patients n'est pas possible à cause des problèmes suivants : {$checkMerge}"; return $exchange_hl7v2->setAckAR($ack, "E121", $comment, $newPatient); } $mbPatientElimine_id = $mbPatientElimine->_id; /** @todo mergePlainFields resets the _id */ $mbPatient->_id = $first_patient_id; // Notifier les autres destinataires $mbPatient->_eai_sender_guid = $sender->_guid; $mbPatient->_merging = CMbArray::pluck($patientsElimine_array, "_id"); if ($msg = $mbPatient->merge($patientsElimine_array)) { return $exchange_hl7v2->setAckAR($ack, "E103", $msg, $mbPatient); } $mbPatient->_mbPatientElimine_id = $mbPatientElimine_id; $comment = CEAIPatient::getComment($mbPatient, $mbPatientElimine); } return $exchange_hl7v2->setAckAA($ack, "I103", $comment, $mbPatient); }
/** * Fusion and recording a patient with an IPP in the system * * @param CHPrimXMLAcquittementsPatients $dom_acq Acquittement * @param CPatient $newPatient Patient * @param array $data Datas * * @return string acquittement **/ function fusionPatient(CHPrimXMLAcquittementsPatients $dom_acq, CPatient $newPatient, $data) { $echg_hprim = $this->_ref_echange_hprim; $commentaire = $avertissement = ""; $codes = array(); $sender = $echg_hprim->_ref_sender; $sender->loadConfigValues(); $this->_ref_sender = $sender; // Si CIP if (!CAppUI::conf('sip server')) { $mbPatientElimine = new CPatient(); $mbPatient = new CPatient(); $sender = $echg_hprim->_ref_sender; // Acquittement d'erreur : identifiants source et cible non fournis pour le patient / patientElimine if (!$data['idSourcePatient'] && !$data['idCiblePatient'] && !$data['idSourcePatientElimine'] && !$data['idCiblePatientElimine']) { return $echg_hprim->setAckError($dom_acq, "E005", $commentaire, $newPatient); } $idexPatient = CIdSante400::getMatch("CPatient", $sender->_tag_patient, $data['idSourcePatient']); if ($mbPatient->load($data['idCiblePatient'])) { if ($mbPatient->_id != $idexPatient->object_id) { $commentaire = "L'identifiant source fait référence au patient : {$idexPatient->object_id} et l'identifiant cible"; $commentaire .= "au patient : {$mbPatient->_id}."; return $echg_hprim->setAckError($dom_acq, "E004", $commentaire, $newPatient); } } if (!$mbPatient->_id) { $mbPatient->load($idexPatient->object_id); } $idexPatientElimine = CIdSante400::getMatch("CPatient", $sender->_tag_patient, $data['idSourcePatientElimine']); if ($mbPatientElimine->load($data['idCiblePatientElimine'])) { if ($mbPatientElimine->_id != $idexPatientElimine->object_id) { $commentaire = "L'identifiant source fait référence au patient : {$idexPatientElimine->object_id} et l'identifiant cible"; $commentaire .= "au patient : {$mbPatientElimine->_id}."; return $echg_hprim->setAckError($dom_acq, "E041", $commentaire, $newPatient); } } if (!$mbPatientElimine->_id) { $mbPatientElimine->load($idexPatientElimine->object_id); } if (!$mbPatient->_id || !$mbPatientElimine->_id) { $commentaire = !$mbPatient->_id ? "Le patient {$mbPatient->_id} est inconnu dans Mediboard." : "Le patient {$mbPatientElimine->_id} est inconnu dans Mediboard."; return $echg_hprim->setAckError($dom_acq, "E012", $commentaire, $newPatient); } // Passage en trash de l'IPP du patient a éliminer $idexPatientElimine->tag = CAppUI::conf('dPpatients CPatient tag_ipp_trash') . $sender->_tag_patient; $idexPatientElimine->store(); $avertissement = null; $patientsElimine_array = array($mbPatientElimine); $first_patient_id = $mbPatient->_id; $checkMerge = $mbPatient->checkMerge($patientsElimine_array); // Erreur sur le check du merge if ($checkMerge) { $commentaire = "La fusion de ces deux patients n'est pas possible à cause des problèmes suivants : {$checkMerge}"; return $echg_hprim->setAckError($dom_acq, "E010", $commentaire, $newPatient); } $mbPatientElimine->_id; /** @todo mergePlainFields resets the _id */ $mbPatient->_id = $first_patient_id; // Notifier les autres destinataires $mbPatient->_eai_sender_guid = $sender->_guid; $mbPatient->_merging = CMbArray::pluck($patientsElimine_array, "_id"); $msg = $mbPatient->merge($patientsElimine_array); $commentaire = CEAIPatient::getComment($newPatient, $mbPatientElimine); $codes = array($msg ? "A010" : "I010"); if ($msg) { $avertissement = $msg . " "; } } return $echg_hprim->setAck($dom_acq, $codes, $avertissement, $commentaire, $newPatient); }