/** * Build ZBE segement * * @param CHL7v2Event $event Event * * @return null */ function build(CHL7v2Event $event) { parent::build($event); $receiver = $event->_receiver; $sejour = $this->sejour; $movement = $this->movement; $affectation = $this->curr_affectation; if ($this->other_affectation) { $affectation = $this->other_affectation; } $action_movement = null; if ($sejour->_cancel_hospitalization) { $action_movement = "CANCEL"; } else { foreach (self::$actions as $action => $events) { if (in_array($event->code, $events)) { $action_movement = $action; } } } // ZBE-1: Movement ID (EI) (optional) $identifiers[] = array($movement->_view, CAppUI::conf("hl7 assigning_authority_namespace_id"), CAppUI::conf("hl7 assigning_authority_universal_id"), CAppUI::conf("hl7 assigning_authority_universal_type_id")); $idexMovement = CIdSante400::getMatch("CMovement", $receiver->_tag_movement, null, $movement->_id); if ($idexMovement->_id) { $configs = $receiver->_configs; $identifiers[] = array($idexMovement->id400, $configs["assigning_authority_namespace_id"], $configs["assigning_authority_universal_id"], $configs["assigning_authority_universal_type_id"]); } $data[] = $identifiers; // ZBE-2: Start of Movement Date/Time (TS) $start_of_movement = $action_movement == "CANCEL" ? $movement->last_update : $movement->start_of_movement; $data[] = $start_of_movement > $sejour->sortie ? $sejour->sortie : $start_of_movement; // ZBE-3: End of Movement Date/Time (TS) (optional) // Forbidden (IHE France) $data[] = null; // ZBE-4: Action on the Movement (ID) $data[] = $action_movement; // ZBE-5: Indicator "Historical Movement" (ID) $data[] = $movement->_current ? "N" : "Y"; // ZBE-6: Original trigger event code (ID) (optional) $data[] = $action_movement == "UPDATE" || $action_movement == "CANCEL" ? $movement->original_trigger_code : null; $ufs = $sejour->getUFs(null, $affectation->_id); // ZBE-7: Ward of medical responsibility in the period starting with this movement (XON) (optional) $uf_type = $receiver->_configs["build_ZBE_7"]; $uf_medicale = isset($ufs[$uf_type]) ? $ufs[$uf_type] : null; if (isset($uf_medicale->_id)) { $data[] = array(array($uf_medicale->libelle, null, null, null, null, $this->getAssigningAuthority("mediboard"), "UF", null, null, $uf_medicale->code)); } else { $data[] = null; } // Traitement des segments spécifiques extension PAM $this->fillOtherSegments($data, $ufs, $event); $this->fill($data); }
/** * import the patient file * * @param string $file path to the file * @param int $start start int * @param int $count number of iterations * @param resource $file_import file for report * * @return null */ function importFile($file, $start, $count, $file_import) { $fp = fopen($file, 'r'); $patient = new CPatient(); $patient_specs = CModelObjectFieldDescription::getSpecList($patient); CModelObjectFieldDescription::addBefore($patient->_specs["_IPP"], $patient_specs); /** @var CMbFieldSpec[] $_patient_specs */ $_patient_specs = CModelObjectFieldDescription::getArray($patient_specs); echo count($_patient_specs) . " traits d'import"; //0 = first line if ($start == 0) { $start++; } $line_nb = 0; while ($line = fgetcsv($fp, null, ";")) { $patient = new CPatient(); if ($line_nb >= $start && $line_nb < $start + $count) { $line_rapport = "ligne {$line_nb} - "; //foreach SPECS, first load foreach ($_patient_specs as $key => $_specs) { $field = $_specs->fieldName; $data = iconv("UTF-8", "ISO-8859-1//TRANSLIT", $line[$key]); //specific cleanups if ($_specs instanceof CPhoneSpec) { $data = preg_replace('/\\D/', '', $data); } if ($field == "sexe") { $data = strtolower($data); } if ($field == "deces" && $data == "0000-00-00") { $data = null; } $patient->{$field} = $data; } $line_rapport .= "Patient {$patient->nom} {$patient->prenom} ({$patient->naissance})"; //clone and IPP $IPP = $patient->_IPP; $patient->_generate_IPP = false; $patient_full = new CPatient(); $patient_full->extendsWith($patient); // load by ipp if basic didn't find. if (!$patient->_id) { $patient->loadFromIPP(); if ($patient->_id) { $line_rapport .= " (trouvé par IPP)"; } } //load patient with basics if (!$patient->_id) { $patient->_IPP = null; $patient->loadMatchingPatient(); if ($patient->_id) { $line_rapport .= " (trouvé par matching)"; } } //update fields if import have more data foreach ($patient->getPlainFields() as $field => $value) { if (!$patient->{$field}) { $patient->{$field} = $patient_full->{$field}; } } // fields created by store, let the store do the job for these $patient->civilite = "guess"; //found if ($patient->_id) { //check IPP $patient->loadIPP(); //update $patient->store(); if (!$patient->_IPP) { $idex = CIdSante400::getMatch($patient->_class, CPatient::getTagIPP(), $IPP, $patient->_id); $idex->last_update = CMbDT::dateTime(); $idex->store(); if ($idex->_id) { $line_rapport .= ", IPP créé : {$IPP}"; } echo "<tr style=\"color:#c98000\"><td>{$line_nb}</td><td>patient [{$patient->nom} {$patient->prenom}] déjà existant (MAJ ipp : {$idex->id400})</td></tr>"; } else { $line_rapport .= " déjà existant"; if ($patient->_IPP != $IPP) { mbLog($patient->_view . " [ipp: " . $patient->_IPP . " / ipp_import:" . $IPP); $line_rapport .= " [IPP du fichier: {$IPP} / ipp en base: {$patient->_IPP} ]"; } $line_rapport .= " [IPP en base et fichier identiques]"; echo "<tr style=\"color:#c98000\"><td>{$line_nb}</td><td>patient [{$patient->nom} {$patient->prenom}] déjà existant (ipp : {$patient->_IPP})</td></tr>"; } } else { $result = $patient->store(); if (!$result) { $line_rapport .= " créé avec succes"; //create IPP $idex = CIdSante400::getMatch($patient->_class, CPatient::getTagIPP(), $IPP, $patient->_id); if ($idex->_id) { $line_rapport .= ", IPP précédente : {$idex->id400}"; } $idex->last_update = CMbDT::dateTime(); $idex->store(); if ($idex->_id) { $line_rapport .= ", IPP enregistrée : {$idex->id400}"; } echo "<tr style=\"color:green\"><td>{$line_nb}</td><td>patient [{$patient->nom} {$patient->prenom}] créé (ipp : {$idex->id400})</td></tr>"; } else { $patient->repair(); $result = $patient->store(); $line_rapport .= " réparé et créé"; if (!$result) { //create IPP $idex = CIdSante400::getMatch($patient->_class, CPatient::getTagIPP(), $IPP, $patient->_id); if ($idex->_id) { $line_rapport .= ", IPP précédente : {$idex->id400}"; } $idex->last_update = CMbDT::dateTime(); $idex->store(); if ($idex->_id) { $line_rapport .= ", IPP enregistrée : {$idex->id400}"; } echo "<tr style=\"color:green\"><td>{$line_nb}</td><td>patient [{$patient->nom} {$patient->prenom}] créé (ipp : {$idex->id400})</td></tr>"; } else { $line_rapport .= " non créé : {$result}"; mbLog("LINE {$line_nb} : erreur: " . $result); echo "<tr style=\"color:red\"><td>{$line_nb}</td><td>\n <div class=\"error\">le patient [{$patient->nom} {$patient->prenom}] n'a pas été créé<br/>\n erreur: {$result}</div></td></tr>"; } } } $line_rapport .= "\n"; fwrite($file_import, $line_rapport); } if ($line_nb > $start + $count) { break; } $line_nb++; } }
function loadFromIPP($group_id = null) { if (!$this->_IPP) { return; } // Pas de tag IPP => pas d'affichage d'IPP if (null == ($tag_ipp = $this->getTagIPP($group_id))) { return; } // Recuperation de la valeur de l'id400 $idex = CIdSante400::getMatch('CPatient', $tag_ipp, $this->_IPP); $this->load($idex->object_id); }
/** * Store Acte * * @param String[] $data Value * @param String $type CCAM or NGAP * @param CSejour $sejour Sejour * @param CPatient $patient Patient * @param String $tag Tag * * @return String|CActe; */ function storeActe($data, $type, $sejour, $patient, $tag) { $code_acte = "code"; if ($type == "CCAM") { $field_object = "codes_ccam"; $code_acte = "code_acte"; } $action = $data["action"]; $idex = CIdSante400::getMatch("CActe{$type}", $tag, $data["idSourceActe{$type}"]); $executant_id = $data["executant_id"]; if ($idex->_id) { $class = "CActe{$type}"; /** @var CActeCCAM|CActeNGAP $acte */ $acte = new $class(); $acte->load($idex->object_id); $object = $acte->loadTargetObject(); if ($action === "suppression") { if ($type == "CCAM") { $code = $acte->{$code_acte}; $replace = explode("|", $object->{$field_object}); CMbArray::removeValue($code, $replace); $object->{$field_object} = $replace ? implode("|", $replace) : ""; } if ($msg = $this->deleteActe($acte, $object, $idex)) { return $msg; } return $acte; } /** @var CActeCCAM|CActeNGAP $new_acte */ $new_acte = $this->{"createActe{$type}"}($data["acte{$type}"], $object, $executant_id); $modification = $new_acte->{$code_acte} != $acte->{$code_acte}; if ($modification) { if ($type == "CCAM") { $new_code = preg_replace("#{$acte}->{$code_acte}#", $new_acte->{$code_acte}, $object->{$field_object}, 1); $object->{$field_object} = $new_code; } if ($msg = $this->deleteActe($acte, $object, $idex)) { return $msg; } $acte = new $class(); } $acte->extendsWith($new_acte, true); if ($msg = $acte->store()) { return $msg; } if ($modification) { $idex->setObject($acte); if ($msg = $idex->store()) { return $msg; } } return $acte; } if ($action !== "création") { return "{$action} impossible car l'acte n'a pas été trouvé"; } $date = CMbDT::date($data["acte{$type}"]["date"]); $object = $this->getObject($date, $executant_id, $patient->_id); $object = $object ? $object : $sejour; /** @var CActe $acte */ $acte = $this->{"createActe{$type}"}($data["acte{$type}"], $object, $executant_id); if ($type == "CCAM") { $object->{$field_object} .= $object->{$field_object} ? "|{$acte->{$code_acte}}" : $acte->{$code_acte}; } if ($msg = $object->store()) { return $msg; } if ($msg = $acte->store()) { return $msg; } $idex = new CIdSante400(); $idex->id400 = $data["idSourceActe{$type}"]; $idex->tag = $tag; $idex->setObject($acte); if ($msg = $idex->store()) { return $msg; } return $acte; }
/** * Récupération du segment ZBE * * @param DOMNode $node Node * @param CSejour $newVenue Admit * @param CMovement $movement Movement * * @return CMovement|string|null */ function getZBE(DOMNode $node, CSejour $newVenue, CMovement $movement) { $sender = $this->_ref_sender; $idex_create = false; $event_code = $this->_ref_exchange_hl7v2->code; $own_movement = null; $sender_movement = null; foreach ($this->queryNodes("ZBE.1", $node) as $ZBE_1) { $EI_1 = $this->queryTextNode("EI.1", $ZBE_1); $EI_2 = $this->queryTextNode("EI.2", $ZBE_1); $EI_3 = $this->queryTextNode("EI.3", $ZBE_1); // Notre propre identifiant de mouvement if ($EI_2 == CAppUI::conf("hl7 assigning_authority_namespace_id") || $EI_3 == CAppUI::conf("hl7 assigning_authority_universal_id")) { $own_movement = $EI_1; break; } // L'identifiant de mouvement du sender if ($EI_3 == $sender->_configs["assigning_authority_universal_id"] || $EI_2 == $sender->_configs["assigning_authority_universal_id"]) { $sender_movement = $EI_1; continue; } } if (!$own_movement && !$sender_movement) { return "Impossible d'identifier le mouvement"; } $movement_id = $own_movement ? $own_movement : $sender_movement; if (!$movement_id) { return null; } $start_movement_dt = $this->queryTextNode("ZBE.2/TS.1", $node); $action = $this->queryTextNode("ZBE.4", $node); $original_trigger = $this->queryTextNode("ZBE.6", $node); if (!$original_trigger) { $original_trigger = $event_code; } $movement->sejour_id = $newVenue->_id; $movement->original_trigger_code = $original_trigger; $movement->cancel = 0; $idexMovement = new CIdSante400(); // Notre propre ID de mouvement if ($own_movement) { $movement_id_split = explode("-", $movement_id); $movement->movement_type = $movement_id_split[0]; $movement->_id = $movement_id_split[1]; $movement->loadMatchingObjectEsc(); if (!$movement->_id) { return null; } if ($sender_movement) { $idexMovement = CIdSante400::getMatch("CMovement", $sender->_tag_movement, $sender_movement); if (!$idexMovement->_id) { $idex_create = true; } } } else { $idexMovement = CIdSante400::getMatch("CMovement", $sender->_tag_movement, $movement_id); if ($idexMovement->_id) { $movement->load($idexMovement->object_id); } else { $idex_create = true; if ($event_code != "A02" && $event_code != "A21") { $movement->cancel = 0; $movement->loadMatchingObjectEsc(); } } $movement->movement_type = $newVenue->getMovementType($original_trigger); } // Erreur dans le cas où le type du mouvement est UPDATE ou CANCEL et que l'on a pas retrouvé le mvt if (($action == "UPDATE" || $action == "CANCEL") && !$movement->_id) { return null; } if ($action == "CANCEL") { $movement->cancel = true; } $movement->start_of_movement = $start_movement_dt; $movement->last_update = CMbDT::dateTime(); $movement->_eai_sender_guid = $sender->_guid; if ($msg = $movement->store()) { return $msg; } if ($idex_create) { $idexMovement->last_update = CMbDT::dateTime(); $idexMovement->object_id = $movement->_id; $idexMovement->_eai_sender_guid = $sender->_guid; if ($msg = $idexMovement->store()) { return $msg; } } return $movement; }
function admitFound($NDA, CSejour $sejour) { $sender = $this->_ref_sender; // NDA $idexNDA = CIdSante400::getMatch("CSejour", $sender->_tag_sejour, $NDA); if ($idexNDA->_id) { $sejour->load($idexNDA->object_id); return true; } return false; }
/** * Lookup an object already imported * * @param string $guid Guid of the object to lookup * @param string $tag Tag of it's Idex * * @return CIdSante400 */ function lookupObject($guid, $tag = "migration") { list($class, ) = explode("-", $guid); $idex = CIdSante400::getMatch($class, $tag, $guid); return $idex; }
/** * Récupération du type d'anesthésie * * @param DOMNode $node Node * @param COperation $operation Intervention * * @return void */ function getTypeAnesthesie(DOMNode $node, COperation $operation) { $xpath = new CHPrimXPath($node->ownerDocument); if (!($typeAnesthesie = $xpath->queryTextNode("hprim:typeAnesthesie", $node))) { return; } $operation->type_anesth = CIdSante400::getMatch("CTypeAnesth", $this->_ref_sender->_tag_hprimxml, $typeAnesthesie)->object_id; }
/** * Is the user a robot? * * @return bool */ function isRobot() { if (!$this->_id) { return false; } $tag_software = CMediusers::getTagSoftware(); if (CModule::getActive("dPsante400") && $tag_software) { if (CIdSante400::getMatch($this->_class, $tag_software, null, $this->_id)->_id != null) { return true; } } if (!$this->_ref_user || !$this->_ref_user->_id) { $this->loadRefUser(); } return $this->_ref_user->dont_log_connection; }
/** * Récupération du médecin * * @param DOMNode $node Node * * @return int */ function getMedecin(DOMNode $node) { $xpath = new CHPrimXPath($node->ownerDocument); $code = $xpath->queryTextNode("hprim:identification/hprim:code", $node); $mediuser = new CMediusers(); $tag = $this->_ref_echange_hprim->_ref_sender->_tag_mediuser; $idex = CIdSante400::getMatch("CMediusers", $tag, $code); if ($idex->_id) { return $idex->object_id; } $rpps = $xpath->queryTextNode("hprim:noRPPS", $node); if ($rpps) { $mediuser = new CMediusers(); $where = array(); $where["users_mediboard.rpps"] = " = '{$rpps}'"; $mediuser->loadObject($where); return $mediuser->_id; } $adeli = $xpath->queryTextNode("hprim:numeroAdeli", $node); if ($adeli) { $mediuser = CMediusers::loadFromAdeli($adeli); return $mediuser->_id; } // Récupération du typePersonne // Obligatoire pour MB $personne = $xpath->queryUniqueNode("hprim:personne", $node, false); $mediuser = self::getPersonne($personne, $mediuser); $mediuser->_id = $this->createPraticien($mediuser); $idex->object_id = $mediuser->_id; $idex->last_update = CMbDT::dateTime(); $idex->store(); return $mediuser->_id; }
/** * Enregistrement des interventions * * @param CHPrimXMLAcquittementsServeurActivitePmsi $dom_acq DOM Acquittement * @param CMbObject $mbObject Object * @param array $data Data that contain the nodes * * @return string Acquittement **/ function handle(CHPrimXMLAcquittementsServeurActivitePmsi $dom_acq, CMbObject $mbObject, $data) { $operation = $mbObject; $exchange_hprim = $this->_ref_echange_hprim; $sender = $exchange_hprim->_ref_sender; $sender->loadConfigValues(); $this->_ref_sender = $sender; $warning = null; $comment = null; // Acquittement d'erreur : identifiants source du patient / séjour non fournis if (!$data['idSourcePatient'] || !$data['idSourceVenue']) { return $exchange_hprim->setAckError($dom_acq, "E206", null, $mbObject); } // IPP non connu => message d'erreur $IPP = CIdSante400::getMatch("CPatient", $sender->_tag_patient, $data['idSourcePatient']); if (!$IPP->_id) { return $exchange_hprim->setAckError($dom_acq, "E013", null, $mbObject); } // Chargement du patient $patient = new CPatient(); $patient->load($IPP->object_id); // Num dossier non connu => message d'erreur $NDA = CIdSante400::getMatch("CSejour", $sender->_tag_sejour, $data['idSourceVenue']); if (!$NDA->_id) { return $exchange_hprim->setAckError($dom_acq, "E014", null, $mbObject); } // Chargement du séjour $sejour = new CSejour(); $sejour->load($NDA->object_id); // Si patient H'XML est différent du séjour if ($sejour->patient_id != $patient->_id) { return $exchange_hprim->setAckError($dom_acq, "E015", null, $mbObject); } // Chargement du patient du séjour $sejour->loadRefPatient(); $operation->sejour_id = $sejour->_id; // Mapping du séjour $sejour = $this->mappingVenue($data['venue'], $sejour); // Notifier les autres destinataires autre que le sender $sejour->_eai_sender_guid = $sender->_guid; /* TODO Supprimer ceci après l'ajout des times picker */ $sejour->_hour_entree_prevue = null; $sejour->_min_entree_prevue = null; $sejour->_hour_sortie_prevue = null; $sejour->_min_sortie_prevue = null; if ($msgVenue = $sejour->store()) { return $exchange_hprim->setAck($dom_acq, "A102", $msgVenue, null, $sejour); } // idex de l'intervention $idex = CIdSante400::getMatch("COperation", $sender->_tag_hprimxml, $data['idSourceIntervention']); if ($idex->_id) { $operation_source = new COperation(); $operation_source->load($idex->object_id); if ($operation_source->sejour_id != $sejour->_id) { return $exchange_hprim->setAckError($dom_acq, "E204", null, $mbObject); } $operation = $operation_source; } // ID Mediboard de l'intervention if ($data['idCibleIntervention']) { $operation_source = new COperation(); $operation_source->load($data['idCibleIntervention']); if ($operation_source->sejour_id != $sejour->_id) { return $exchange_hprim->setAckError($dom_acq, "E204", null, $mbObject); } if ($idex->_id && $operation->_id != $operation_source->_id) { return $exchange_hprim->setAckError($dom_acq, "E205", null, $mbObject); } $operation = $operation_source; } // Recherche de la salle $salle = $this->getSalle($data['intervention'], $sejour); if ($salle->nom && !$salle->_id) { $comment = "Salle '{$salle->nom}' inconnue dans l'infrastructure de l'établissement"; return $exchange_hprim->setAckError($dom_acq, "E202", $comment, $mbObject); } $operation->salle_id = $salle->_id; // Mapping du chirurgien $mediuser = $this->getParticipant($data['intervention'], $sejour); if ($mediuser->adeli && !$mediuser->_id || !$mediuser->adeli) { $comment = $mediuser->adeli ? "Participant '{$mediuser->adeli}' inconnu" : "Le code ADELI n'est pas renseigné"; return $exchange_hprim->setAckError($dom_acq, "E203", $comment, $mbObject); } $operation->chir_id = $mediuser->_id; // Mapping de la plage $this->mappingPlage($data['intervention'], $operation); $plageop_id = $operation->plageop_id; // Recherche d'une intervention existante sinon création if (!$operation->_id) { $operation->loadMatchingObject(); } // Si pas trouvé on recherche en hors plage if (!$operation->_id) { $operation->loadRefPlageOp(); $operation->plageop_id = null; $operation->temp_operation = null; $operation->time_operation = null; $operation->date = $operation->_ref_plageop->_id ? $operation->_ref_plageop->date : $operation->date; if ($operation->countMatchingList() == 1) { $operation->loadMatchingObject(); } if (!$operation->_id && $plageop_id) { $operation->plageop_id = $plageop_id; $operation->date = null; } } // Mapping de l'intervention $this->mappingIntervention($data, $operation); // Store de l'intervention // Notifier les autres destinataires autre que le sender $operation->_eai_sender_guid = $sender->_guid; $msgInterv = $operation->store(); CEAIMbObject::storeIdex($idex, $operation, $sender); $modified_fields = CEAIMbObject::getModifiedFields($operation); $codes = array($msgInterv ? "A201" : "I201"); if ($msgInterv) { $warning .= $msgInterv . " "; } else { $comment .= "Intervention : {$operation->_id}."; $comment .= $modified_fields ? " Les champs mis à jour sont les suivants : {$modified_fields}." : null; } return $exchange_hprim->setAck($dom_acq, $codes, $warning, $comment, $operation); }
/** * Handle event A50 - change visit number * * @param CHL7Acknowledgment $ack Acknowledgment * @param CPatient $newPatient Person * @param array $data Datas * * @return string */ function handleA50(CHL7Acknowledgment $ack, CPatient $newPatient, $data) { // Traitement du message des erreurs $comment = ""; $venue = new CSejour(); $exchange_hl7v2 = $this->_ref_exchange_hl7v2; $sender = $exchange_hl7v2->_ref_sender; // Prise en charge du A50 seulement pour le NRA if (!CAppUI::conf("dPplanningOp CSejour use_dossier_rang")) { return $exchange_hl7v2->setAckAR($ack, "E801", null, $venue); } $patientPI = CValue::read($data['personIdentifiers'], "PI"); $venueAN = $this->getVenueAN($sender, $data); // Acquittement d'erreur : identifiants RI et PI non fournis if (!$patientPI || !$venueAN) { return $exchange_hl7v2->setAckAR($ack, "E100", null, $newPatient); } $idexVenue = CIdSante400::getMatch("CSejour", $sender->_tag_sejour, $venueAN); $venue->load($idexVenue->object_id); if (!$venue->_id) { return $exchange_hl7v2->setAckAR($ack, "E802", null, $venue); } // Chargement du NRA $venue->loadNRA($sender->group_id); $NRA = $venue->_ref_NRA; // MRG-6 Ancien FID $MRG_6 = $this->queryTextNode("MRG.6/CX.1", $data["MRG"]); if ($NRA->id400 != $MRG_6) { return $exchange_hl7v2->setAckAR($ack, "E803", null, $venue); } // Réattribution du nouveau NRA $PV1_50 = $this->queryTextNode("PV1.50/CX.1", $data["PV1"]); $NRA->id400 = $PV1_50; $NRA->last_update = CMbDT::dateTime(); if ($msg = $NRA->store()) { return $exchange_hl7v2->setAckAR($ack, "E804", $msg, $venue); } return $exchange_hl7v2->setAckAA($ack, "I800", $comment, $venue); }
/** * 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; }
/** * 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); }
/** * Record admit * * @param CHPrimXMLAcquittementsPatients $dom_acq Acquittement * @param CPatient $newPatient Patient * @param array $data Data * @param CSejour &$newVenue Admit * * @return CHPrimXMLAcquittementsPatients $msgAcq **/ function venuePatient(CHPrimXMLAcquittementsPatients $dom_acq, CPatient $newPatient, $data, &$newVenue = null) { $echg_hprim = $this->_ref_echange_hprim; // Cas 1 : Traitement du patient $domEnregistrementPatient = new CHPrimXMLEnregistrementPatient(); $domEnregistrementPatient->_ref_echange_hprim = $echg_hprim; $msgAcq = $domEnregistrementPatient->enregistrementPatient($dom_acq, $newPatient, $data); if ($echg_hprim->statut_acquittement != "OK") { return $msgAcq; } // Cas 2 : Traitement de la venue $dom_acq = new CHPrimXMLAcquittementsPatients(); $dom_acq->_identifiant_acquitte = $data['identifiantMessage']; $dom_acq->_sous_type_evt = $this->sous_type; $dom_acq->_ref_echange_hprim = $echg_hprim; // Traitement du message des erreurs $avertissement = $msgID400 = $msgVenue = $msgNDA = ""; $_code_Venue = $_code_NumDos = $_num_dos_create = $_modif_venue = false; $sender = $echg_hprim->_ref_sender; $sender->loadConfigValues(); $this->_ref_sender = $sender; $idSourceVenue = $data['idSourceVenue']; $idCibleVenue = $data['idCibleVenue']; if (!$newVenue) { $newVenue = new CSejour(); } // Cas d'une annulation $cancel = false; if ($data['action'] == "suppression") { $cancel = true; } // Affectation du patient $newVenue->patient_id = $newPatient->_id; // Affectation de l'établissement $newVenue->group_id = $sender->group_id; $commentaire = ""; $codes = array(); // Si CIP if (!CAppUI::conf('smp server')) { // Acquittement d'erreur : identifiants source et cible non fournis pour le patient / venue if (!$idSourceVenue && !$idCibleVenue) { return $echg_hprim->setAckError($dom_acq, "E100", $commentaire, $newVenue); } $nda = CIdSante400::getMatch("CSejour", $sender->_tag_sejour, $idSourceVenue); // idSource non connu if (!$nda->_id) { // idCible fourni if ($idCibleVenue) { if ($newVenue->load($idCibleVenue)) { // Dans le cas d'une annulation de la venue if ($cancel) { if ($msgAcq = $this->doNotCancelVenue($newVenue, $dom_acq, $echg_hprim)) { return $msgAcq; } } // Recherche d'un num dossier déjà existant pour cette venue // Mise en trash du numéro de dossier reçu $newVenue->loadNDA(); if ($this->trashNDA($newVenue, $sender)) { $nda->_trash = true; } else { // Mapping du séjour si pas de numéro de dossier $newVenue = $this->mappingVenue($data['venue'], $newVenue, $cancel); $msgVenue = CEAISejour::storeSejour($newVenue, $sender); $commentaire = CEAISejour::getComment($newVenue); $_code_NumDos = "I121"; $_code_Venue = true; } } else { $_code_NumDos = "I120"; } } else { $_code_NumDos = "I122"; } if (!$newVenue->_id) { // Mapping du séjour $newVenue->_NDA = $nda->id400; $newVenue = $this->mappingVenue($data['venue'], $newVenue, $cancel); // Séjour retrouvé if (CAppUI::conf("hprimxml strictSejourMatch")) { if ($newVenue->loadMatchingSejour(null, true, $sender->_configs["use_sortie_matching"])) { // Dans le cas d'une annulation de la venue if ($cancel) { if ($msgAcq = $this->doNotCancelVenue($newVenue, $dom_acq, $echg_hprim)) { return $msgAcq; } } // Recherche d'un num dossier déjà existant pour cette venue // Mise en trash du numéro de dossier reçu $newVenue->loadNDA(); if ($this->trashNDA($newVenue, $sender)) { $nda->_trash = true; } else { // Mapping du séjour $newVenue = $this->mappingVenue($data['venue'], $newVenue, $cancel); $msgVenue = CEAISejour::storeSejour($newVenue, $sender); $commentaire = CEAISejour::getComment($newVenue); $_code_NumDos = "A121"; $_code_Venue = true; } } } else { $collision = $newVenue->getCollisions(); if (count($collision) == 1) { $newVenue = reset($collision); // Dans le cas d'une annulation de la venue if ($cancel) { if ($msgAcq = $this->doNotCancelVenue($newVenue, $dom_acq, $echg_hprim)) { return $msgAcq; } } // Recherche d'un num dossier déjà existant pour cette venue // Mise en trash du numéro de dossier reçu $newVenue->loadNDA(); if ($this->trashNDA($newVenue, $sender)) { $nda->_trash = true; } else { // Mapping du séjour $newVenue = $this->mappingVenue($data['venue'], $newVenue, $cancel); $msgVenue = CEAISejour::storeSejour($newVenue, $sender); $commentaire = CEAISejour::getComment($newVenue); $_code_NumDos = "A122"; $_code_Venue = true; } } } if (!$newVenue->_id && !isset($nda->_trash)) { // Mapping du séjour $newVenue = $this->mappingVenue($data['venue'], $newVenue, $cancel); $msgVenue = CEAISejour::storeSejour($newVenue, $sender); $commentaire = CEAISejour::getComment($newVenue); } } if (isset($nda->_trash)) { $nda->tag = CAppUI::conf('dPplanningOp CSejour tag_dossier_trash') . $sender->_tag_sejour; $nda->loadMatchingObject(); $codes = array("I125"); $commentaire = "Sejour non récupéré. Impossible d'associer le numéro de dossier."; } if ($cancel) { $codes[] = "A130"; $nda->tag = CAppUI::conf('dPplanningOp CSejour tag_dossier_trash') . $sender->_tag_sejour; } $msgNDA = CEAISejour::storeNDA($nda, $newVenue, $sender); if (!isset($nda->_trash)) { $codes = array($msgVenue ? $_code_Venue ? "A103" : "A102" : ($_code_Venue ? "I102" : "I101"), $msgNDA ? "A105" : $_code_NumDos); } if ($msgVenue || $msgNDA) { $avertissement = $msgVenue . " " . $msgNDA; } else { if (!isset($nda->_trash)) { $commentaire .= "Numéro dossier créé : {$nda->id400}."; } } } else { $newVenue->_NDA = $nda->id400; $newVenue->load($nda->object_id); // Dans le cas d'une annulation de la venue if ($cancel) { if ($msgAcq = $this->doNotCancelVenue($newVenue, $dom_acq, $echg_hprim)) { return $msgAcq; } } // Mapping du séjour $newVenue = $this->mappingVenue($data['venue'], $newVenue, $cancel); // idCible non fourni if (!$idCibleVenue) { $_code_NumDos = "I123"; } else { $tmpVenue = new CSejour(); // idCible connu if ($tmpVenue->load($idCibleVenue)) { if ($tmpVenue->_id != $nda->object_id) { $commentaire = "L'identifiant source fait référence au séjour : {$nda->object_id}"; $commentaire .= "et l'identifiant cible au séjour : {$tmpVenue->_id}."; return $dom_acq->generateAcquittementsError("E104", $commentaire, $newVenue); } $_code_NumDos = "I124"; } else { $_code_NumDos = "A120"; } } $msgVenue = CEAISejour::storeSejour($newVenue, $sender); $codes = array($msgVenue ? "A103" : "I102", $_code_NumDos); if ($cancel) { $codes[] = "A130"; $nda->tag = CAppUI::conf('dPplanningOp CSejour tag_dossier_trash') . $sender->_tag_sejour; $nda->last_update = CMbDT::dateTime(); $msgNDA = $nda->store(); } if ($msgVenue || $msgNDA) { $avertissement = $msgVenue . " " . $msgNDA; } $commentaire = CEAISejour::getComment($newVenue); } return $echg_hprim->setAck($dom_acq, $codes, $avertissement, $commentaire, $newVenue); } }
/** * Get PV2.45 : operation * * @param CInteropReceiver $receiver Receiver * @param CSejour $sejour Admit * * @return array|null */ function getPV245(CInteropReceiver $receiver, CSejour $sejour) { $operation = $sejour->loadRefFirstOperation(); $operation->loadRefPlageOp(); $value = null; if (!empty($receiver->_configs["build_PV2_45"])) { $value = $receiver->_configs["build_PV2_45"]; } // Advance Directive Code switch ($value) { // Transmission de l'intervention case 'operation': if (!$operation) { return null; } $datetime = CHL7v2::getDateTime($operation->_datetime); $type_anesth = new CIdSante400(); if ($operation->type_anesth) { $tag_hl7 = $receiver->_tag_hl7; $type_anesth = CIdSante400::getMatch("CTypeAnesth", $tag_hl7, null, $operation->type_anesth); } $idex_chir = CIdSante400::getMatchFor($operation->loadRefChir(), $receiver->_tag_mediuser); $anesth = $operation->loadRefAnesth(); $idex_anesth = new CIdSante400(); if ($anesth->_id) { $idex_anesth = CIdSante400::getMatchFor($anesth, $receiver->_tag_mediuser); } $libelle = $operation->libelle; $PV2_45_2 = ""; // Datetime if ($datetime) { $PV2_45_2 .= "{$datetime}"; } $PV2_45_2 .= "#"; // Type anesth if ($type_anesth->id400) { $PV2_45_2 .= "{$type_anesth->id400}"; } $PV2_45_2 .= "#"; // Idex chir if ($idex_chir->id400) { $PV2_45_2 .= "{$idex_chir->id400}"; } $PV2_45_2 .= "#"; // Idex anesth if ($idex_anesth->id400) { $PV2_45_2 .= "{$idex_anesth->id400}"; } $PV2_45_2 .= "#"; // Libelle if ($libelle) { $PV2_45_2 .= "{$libelle}"; } if (CModule::getActive("mvsante")) { $PV2_45_2 .= CMVSante::getPV245($receiver, $sejour, $operation); } return array(array(null, $PV2_45_2)); default: return null; } }
/** * Handle A29 event - Delete person information * * @param CHL7Acknowledgment $ack Acknowledgement * @param CPatient $newPatient Person * @param array $data Nodes data * * @return null|string */ function handleA29(CHL7Acknowledgment $ack, CPatient $newPatient, $data) { // Traitement du message des erreurs $comment = $warning = ""; $exchange_hl7v2 = $this->_ref_exchange_hl7v2; $sender = $this->_ref_sender; $patientPI = CValue::read($data['personIdentifiers'], "PI"); $IPP = new CIdSante400(); if ($patientPI) { $IPP = CIdSante400::getMatch("CPatient", $sender->_tag_patient, $patientPI); } if (!$patientPI || !$IPP->_id) { return $exchange_hl7v2->setAckAR($ack, "E150", null, $newPatient); } $newPatient->load($IPP->object_id); // Passage en trash de l'IPP du patient if ($msg = $newPatient->trashIPP($IPP)) { return $exchange_hl7v2->setAckAR($ack, "E151", $msg, $newPatient); } // Annulation de tous les séjours du patient qui n'ont pas d'entrée réelle $where = array(); $where['entree_reelle'] = "IS NULL"; $where['group_id'] = " = '{$sender->group_id}'"; $sejours = $newPatient->loadRefsSejours($where); foreach ($sejours as $_sejour) { // Notifier les autres destinataires autre que le sender $_sejour->_eai_sender_guid = $sender->_guid; // Pas de génération de NDA $_sejour->_generate_NDA = false; // On ne check pas la cohérence des dates des consults/intervs $_sejour->_skip_date_consistencies = true; // On annule le séjour $_sejour->annule = 1; $_sejour->store(); } $codes = array("I150"); return $exchange_hl7v2->setAckAA($ack, $codes, $comment, $newPatient); }
/** * Handle event * * @param CHL7Acknowledgment $ack Acknowledgement * @param CPatient $patient Person * @param array $data Nodes data * * @return null|string */ function handle(CHL7Acknowledgment $ack, CPatient $patient, $data) { // Traitement du message des erreurs $comment = ""; $object = null; $exchange_hl7v2 = $this->_ref_exchange_hl7v2; $exchange_hl7v2->_ref_sender->loadConfigValues(); $sender = $this->_ref_sender = $exchange_hl7v2->_ref_sender; // Patient $patientPI = CValue::read($data['personIdentifiers'], "PI"); if (!$patientPI) { return $exchange_hl7v2->setAckAR($ack, "E007", null, $patient); } $IPP = CIdSante400::getMatch("CPatient", $sender->_tag_patient, $patientPI); // Patient non retrouvé par son IPP if (!$IPP->_id) { return $exchange_hl7v2->setAckAR($ack, "E105", null, $patient); } $patient->load($IPP->object_id); $sejour = null; // Sejour $venueAN = CValue::read($data["personIdentifiers"], "AN"); if (!$venueAN) { $venueAN = CValue::read($data["admitIdentifiers"], "AN"); } if ($venueAN) { $NDA = CIdSante400::getMatch("CSejour", $sender->_tag_sejour, $venueAN); // Séjour non retrouvé par son NDA if (!$NDA->_id) { return $exchange_hl7v2->setAckAR($ack, "E205", null, $patient); } /** @var CSejour $sejour */ $sejour = $NDA->loadTargetObject(); if (!$sejour->_id) { return $exchange_hl7v2->setAckAR($ack, "E220", null, $patient); } if ($sejour->patient_id !== $patient->_id) { return $exchange_hl7v2->setAckAR($ack, "E606", null, $patient); } } // Pas d'observations $first_result = reset($data["observations"]); if (!$first_result) { return $exchange_hl7v2->setAckAR($ack, "E225", null, $patient); } // Recherche par date $observation_dt = $this->getOBRObservationDateTime($first_result["OBR"]); if (!$sejour) { $sejours = $patient->getCurrSejour($observation_dt); //FIXME ignorer les annulés $sejour = reset($sejours); if (!$sejour || !$sejour->_id) { return $exchange_hl7v2->setAckAR($ack, "E220", null, $patient); } } // Récupération des observations foreach ($data["observations"] as $_observation) { // Récupération de la date du relevé $observation_dt = $this->getOBRObservationDateTime($_observation["OBR"]); $name = $this->getOBRServiceIdentifier($_observation["OBR"]); // OBR identity identifier $OBR_identity_identifier = null; $handle_OBR_identity_identifier = $sender->_configs["handle_OBR_identity_identifier"]; if ($handle_OBR_identity_identifier) { $OBR_identity_identifier = $this->queryTextNode($handle_OBR_identity_identifier, $_observation["OBR"]); } foreach ($_observation["OBX"] as $key => $_OBX) { $status = $this->getObservationResultStatus($_OBX); if ($status === "X") { continue; } // OBX.2 : Value type $value_type = $this->getOBXValueType($_OBX); $date = $observation_dt ? $observation_dt : $this->getOBXObservationDateTime($_OBX); $praticien_id = $this->getObservationAuthor($_OBX); // Recherche de l'objet avec la date correspondante fourni dans l'observation $object = $this->getObjectWithDate($date, $patient, $praticien_id, $sejour); if (!$object || !$object->_id) { return $exchange_hl7v2->setAckAR($ack, "E301", null, $patient); } $name = $name . $key; switch ($value_type) { // Reference Pointer to External Report case "RP": if (!$this->getReferencePointerToExternalReport($_OBX, $object, $name)) { return $exchange_hl7v2->setAckAR($ack, $this->codes, null, $object); } break; // Encapsulated Data // Encapsulated Data case "ED": if (!$this->getEncapsulatedData($_OBX, $object, $name)) { return $exchange_hl7v2->setAckAR($ack, $this->codes, null, $object); } break; // Pulse Generator and Lead Observation Results // Pulse Generator and Lead Observation Results case "ST": case "CWE": case "DTM": case "NM": case "SN": if (!$this->getPulseGeneratorAndLeadObservationResults($_OBX, $patient, $object, $observation_dt)) { return $exchange_hl7v2->setAckAR($ack, $this->codes, null, $object); } break; // Not supported // Not supported default: return $exchange_hl7v2->setAckAR($ack, "E302", null, $object); } // On store l'idex de l'identifiant du système tiers $idex = new CIdSante400(); $idex->object_class = $object->_class; $idex->object_id = $object->_id; $idex->tag = "OBR_{$sender->_tag_hl7}"; $idex->id400 = $OBR_identity_identifier; $idex->loadMatchingObject(); $idex->store(); } } return $exchange_hl7v2->setAckCA($ack, $this->codes, $comment, $object); }
/** * Recording NPA * * @param String $NPA NPA * @param CSejour $sejour Sejour * @param CInteropSender $sender Sender * * @return null|string */ static function storeNPA($NPA, CSejour $sejour, CInteropSender $sender) { if (!$NPA) { return null; } // L'expéditeur gère les NPA $manage_npa = CMbArray::get($sender->_configs, "manage_npa"); if (!$manage_npa) { return null; } //Récupération du tag pour les NPA $tag = CSejour::getTagNPA($sender->group_id); if (!$tag) { return null; } $idex_NPA = CIdSante400::getMatch("CSejour", $tag, null, $sejour->_id); $idex_NPA->object_id = $sejour->_id; $idex_NPA->last_update = CMbDT::dateTime(); $idex_NPA->_eai_sender_guid = $sender->_guid; $idex_NPA->id400 = $NPA; return $idex_NPA->store(); }
/** * Returns an MBObject by its class and its Import ID * * @param string $class The Mediboard class name * @param string $db_id The Import ID * * @return CStoredObject The MB Object */ function getMbObjectByClass($class, $db_id) { static $objects = array(); $db_id = addslashes($db_id); if (isset($objects[$class][$db_id])) { return $objects[$class][$db_id]; } $idex = CIdSante400::getMatch($class, $this->getImportTag(), $db_id); $target = $idex->loadTargetObject(); if ($idex->_id) { $objects[$class][$db_id] = $target; } return $target; }
/** * Passage en trash du NDA * * @param CSejour $venue Venue * @param CInteropSender $sender Expéditeur * * @return bool */ function trashNDA(CSejour $venue, CInteropSender $sender) { if (isset($sender->_configs["type_sej_pa"])) { if ($venue->_NDA && preg_match($sender->_configs["type_sej_pa"], $venue->_NDA)) { // Passage en pa_ de l'id externe $num_pa = CIdSante400::getMatch("CSejour", $sender->_tag_sejour, $venue->_NDA); if ($num_pa->_id) { $num_pa->tag = CAppUI::conf('dPplanningOp CSejour tag_dossier_pa') . $sender->_tag_sejour; $num_pa->last_update = CMbDT::dateTime(); $num_pa->store(); } return false; } } if ($venue->_NDA) { return true; } return false; }
/** * Handle event A47 * * @param CHL7Acknowledgment $ack Acknowledgment * @param CPatient $patient Person * @param array $data Data * * @return string */ function handleA47(CHL7Acknowledgment $ack, CPatient $patient, $data) { $exchange_hl7v2 = $this->_ref_exchange_hl7v2; $sender = $exchange_hl7v2->_ref_sender; $sender->loadConfigValues(); $this->_ref_sender = $sender; $incorrect_identifier = null; // Traitement du mode simple, cad if (CHL7v2Message::$handle_mode == "simple") { $MRG_4 = $this->queryNodes("MRG.4", $data["MRG"])->item(0); $incorrect_identifier = $this->queryTextNode("CX.1", $MRG_4); $patient->load($incorrect_identifier); // ID non connu (non fourni ou non retrouvé) if (!$incorrect_identifier || !$patient->_id) { return $exchange_hl7v2->setAckAR($ack, "E141", null, $patient); } } else { $MRG_1 = $this->queryNodes("MRG.1", $data["MRG"])->item(0); if ($this->queryTextNode("CX.5", $MRG_1) == "PI") { $incorrect_identifier = $this->queryTextNode("CX.1", $MRG_1); } // Chargement de l'IPP $IPP_incorrect = new CIdSante400(); if ($incorrect_identifier) { $IPP_incorrect = CIdSante400::getMatch("CPatient", $sender->_tag_patient, $incorrect_identifier); } // PI non connu (non fourni ou non retrouvé) if (!$incorrect_identifier || !$IPP_incorrect->_id) { return $exchange_hl7v2->setAckAR($ack, "E141", null, $patient); } $patient->load($IPP_incorrect->object_id); // Passage en trash de l'IPP du patient a éliminer if ($msg = $patient->trashIPP($IPP_incorrect)) { return $exchange_hl7v2->setAckAR($ack, "E140", $msg, $patient); } } // Sauvegarde du nouvel IPP $IPP = new CIdSante400(); $IPP->object_id = $patient->_id; $IPP->object_class = "CPatient"; $IPP->id400 = $data['personIdentifiers']["PI"]; $IPP->tag = $sender->_tag_patient; $IPP->last_update = CMbDT::dateTime(); if ($msg = $IPP->store()) { return $exchange_hl7v2->setAckAR($ack, "E140", $msg, $patient); } return $exchange_hl7v2->setAckAA($ack, "I140", null, $patient); }
// Récupération des spécialités CPAM $spec_cpam = new CSpecCPAM(); $spec_cpam = $spec_cpam->loadList(null, 'spec_cpam_id ASC'); // Récupération des profils $profile = new CUser(); $profile->template = 1; /** @var CUser[] $profiles */ $profiles = $profile->loadMatchingList(); // Creation du tableau de profil en fonction du type $tabProfil = array(); foreach ($profiles as $profil) { $tabProfil[$profil->user_type][] = $profil->_id; } $tag = false; if ($object->_id) { $tag = CIdSante400::getMatch($object->_class, CMediusers::getTagSoftware(), null, $object->_id)->id400; } $password_info = CAppUI::$user->_specs['_user_password']->minLength > 4 ? "Le mot de passe doit être composé d'au moins 6 caractères, comprenant des lettres et au moins un chiffre." : "Le mot de passe doit être composé d'au moins 4 caractères."; // Création du template $smarty = new CSmartyDP(); $smarty->assign("tabProfil", $tabProfil); $smarty->assign("utypes", CUser::$types); $smarty->assign("ps_types", CUser::$ps_types); $smarty->assign("banques", $banques); $smarty->assign("object", $object); $smarty->assign("profiles", $profiles); $smarty->assign("functions", $functions); $smarty->assign("disciplines", $disciplines); $smarty->assign("spec_cpam", $spec_cpam); $smarty->assign("tag_mediuser", CMediusers::getTagMediusers($group->_id)); $smarty->assign("is_admin", CAppUI::$user->isAdmin());
/** * @param string $ldap_guid * * @return CUser */ static function getFromLDAPGuid($ldap_guid) { if (!$ldap_guid) { throw new CMbException("CUser_no-ldap-guid"); } $id_ext = CIdSante400::getMatch("CUser", CAppUI::conf("admin LDAP ldap_tag"), $ldap_guid); if (!$id_ext->_id) { throw new CMbException("CUser_ldap-guid-no-user"); } CAppUI::$instance->auth_method = "ldap_guid"; return $id_ext->loadTargetObject(); }
} $mov = new CMovement(); $query = $request->makeSelect(); $list = $mov->_spec->ds->loadList($query); if (!$do_it) { CAppUI::setMsg(count($list) . " doublons à traiter"); } else { foreach ($list as $_mvt) { $ids = explode(",", $_mvt["ids"]); sort($ids); // IMPORTANT, must use the first movement created as a reference $first = new CMovement(); $first->load($ids[0]); $second = new CMovement(); $second->load($ids[1]); $tag = CIdSante400::getMatch($second->_class, $second->getTagMovement(), null, $second->_id); if ($tag->_id) { $tag->tag = "trash_{$tag->tag}"; $tag->last_update = CMbDT::dateTime(); $tag->store(); } else { CAppUI::setMsg("Aucun tag sur mouvement #{$second->_id}"); } $msg = $first->merge(array($second->_id => $second)); if ($msg) { CAppUI::setMsg($msg, UI_MSG_WARNING); } else { CAppUI::setMsg("Mouvements fusionnés"); } } if ($auto && count($list)) {
/** * Build SCH segement * * @param CHL7v2Event $event Event * * @return null */ function build(CHL7v2Event $event) { parent::build($event); $receiver = $event->_receiver; $appointment = $this->appointment; $data = array(); // SCH-1: Placer Appointment ID (EI) (optional) $data[] = null; // SCH-2: Filler Appointment ID (EI) (optional) $identifiers[] = array($appointment->_id, CAppUI::conf("hl7 assigning_authority_namespace_id"), CAppUI::conf("hl7 assigning_authority_universal_id"), CAppUI::conf("hl7 assigning_authority_universal_type_id")); $idex = CIdSante400::getMatch("CConsultation", $receiver->_tag_consultation, null, $appointment->_id); if ($idex->_id) { $configs = $receiver->_configs; $identifiers[] = array($idex->id400, $configs["assigning_authority_namespace_id"], $configs["assigning_authority_universal_id"], $configs["assigning_authority_universal_type_id"]); } $data[] = $identifiers; // SCH-3: Occurrence Number (NM) (optional) $data[] = null; // SCH-4: Placer Group Number (EI) (optional) $data[] = null; // SCH-5: Schedule ID (CE) (optional) $data[] = null; // SCH-6: Event Reason (CE) /* @todo Voir comment améliorer */ $data[] = array(array(1, "CConsultation")); // SCH-7: Appointment Reason (CE) (optional) $data[] = array(array($appointment->_id, $appointment->motif)); // SCH-8: Appointment Type (CE) (optional) $data[] = null; // SCH-9: Appointment Duration (NM) (optional) $data[] = null; // SCH-10: Appointment Duration Units (CE) (optional) $data[] = null; // SCH-11: Appointment Timing Quantity (TQ) (optional repeating) $data[] = array(array(null, null, "M" . $appointment->_duree, $appointment->_datetime, $appointment->_date_fin)); // SCH-12: Placer Contact Person (XCN) (optional repeating) $data[] = $this->getXCN($appointment->_ref_praticien, $receiver); // SCH-13: Placer Contact Phone Number (XTN) (optional) $data[] = null; // SCH-14: Placer Contact Address (XAD) (optional repeating) $data[] = null; // SCH-15: Placer Contact Location (PL) (optional) $data[] = null; // SCH-16: Filler Contact Person (XCN) ( repeating) $first_log = $appointment->loadFirstLog(); $mediuser = $first_log->loadRefUser()->loadRefMediuser(); $data[] = $this->getXCN($mediuser, $receiver); // SCH-17: Filler Contact Phone Number (XTN) (optional) $data[] = null; // SCH-18: Filler Contact Address (XAD) (optional repeating) $data[] = null; // SCH-19: Filler Contact Location (PL) (optional) $data[] = null; // SCH-20: Entered By Person (XCN) ( repeating) $data[] = $this->getXCN($mediuser, $receiver); // SCH-21: Entered By Phone Number (XTN) (optional repeating) $data[] = null; // SCH-22: Entered By Location (PL) (optional) $data[] = null; // SCH-23: Parent Placer Appointment ID (EI) (optional) $data[] = null; // SCH-24: Parent Filler Appointment ID (EI) (optional) $data[] = null; // SCH-25: Filler Status Code (CE) (optional) $data[] = $this->getFillerStatutsCode($appointment); // SCH-26: Placer Order Number (EI) (optional repeating) $data[] = null; // SCH-27: Filler Order Number (EI) (optional repeating) $data[] = null; $this->fill($data); }
/** * import the patient file * * @param string $file path to the file * @param int $start start int * @param int $count number of iterations * @param resource $file_import file for report * * @return null */ function importFile($file, $start, $count, $file_import) { $fp = fopen($file, 'r'); $csv_file = new CCSVFile($fp); $csv_file->column_names = $csv_file->readLine(); if ($start == 0) { $start++; } elseif ($start > 1) { $csv_file->jumpLine($start); } $group_id = CGroups::loadCurrent()->_id; $treated_line = 0; while ($treated_line < $count) { $treated_line++; $patient = new CPatient(); $_patient = $csv_file->readLine(true); if (!$_patient) { CAppUI::stepAjax('Importation terminée', UI_MSG_OK); CApp::rip(); } $patient->bind($_patient); $patient->loadFromIPP($group_id); if ($patient->_id) { $start++; continue; } $nom = $_patient['nom'] ? $_patient['nom'] : $_patient['nom_jeune_fille']; if (!$patient->nom) { if ($patient->nom_jeune_fille) { $patient->nom = $patient->nom_jeune_fille; } else { CMbDebug::log("Ligne #{$start} : Pas de nom"); $start++; continue; } } $naissance = null; if ($patient->naissance) { $naissance = preg_replace('/(\\d{2})\\/(\\d{2})\\/(\\d{4})/', '\\3-\\2-\\1', $patient->naissance); $patient->naissance = $naissance; } $patient->repair(); if (!$patient->naissance) { CMbDebug::log($_patient); CMbDebug::log("Ligne #{$start} : Date de naissance invalide ({$_patient['naissance']})"); $start++; continue; } $patient->loadMatchingPatient(); if (!$patient->_id) { $patient->bind($_patient); $patient->nom = $nom; $patient->naissance = $naissance; $patient->tel = preg_replace("/[^0-9]/", "", $patient->tel); $patient->tel_autre = preg_replace("/[^0-9]/", "", $patient->tel_autre); $patient->sexe = strtolower($patient->sexe); $patient->repair(); if ($msg = $patient->store()) { CMbDebug::log($patient, null, true); CMbDebug::log("Ligne #{$start} :{$msg}"); $start++; continue; } } $ipp = CIdSante400::getMatch($patient->_class, CPatient::getTagIPP($group_id), $patient->_IPP, $patient->_id); if ($ipp->_id && $ipp->id400 != $patient->_IPP) { CMbDebug::log("Ligne #{$start} : Ce patient possède déjà un IPP ({$ipp->id400})"); $start++; continue; } if (!$ipp->_id) { if ($msg = $ipp->store()) { CMbDebug::log("Ligne #{$start} :{$msg}"); $start++; continue; } } CAppUI::setMsg('CPatient-msg-create', UI_MSG_OK); } echo CAppUI::getMsg(); }
/** * Return the Object with the information of the medecin in the message * * @param DOMNode $node Node * @param CMbObject $object object * * @return int|null|string */ function getDoctor(DOMNode $node, CMbObject $object) { $type_id = $this->queryTextNode("XCN.13", $node); $id = $this->queryTextNode("XCN.1", $node); $last_name = $this->queryTextNode("XCN.2/FN.1", $node); $first_name = $this->queryTextNode("XCN.3", $node); switch ($type_id) { case "RPPS": $object->rpps = $id; break; case "ADELI": $object->adeli = $id; break; case "RI": // Notre propre RI if ($this->queryTextNode("XCN.9/HD.2", $node) == CAppUI::conf("hl7 assigning_authority_universal_id")) { return $id; } default: // Recherche du praticien par son idex $idex = CIdSante400::getMatch($object->_class, $this->_ref_sender->_tag_mediuser, $id); if ($idex->_id) { return $idex->object_id; } if ($object instanceof CMediusers) { $object->_user_first_name = $first_name; $object->_user_last_name = $last_name; } if ($object instanceof CMedecin) { $object->prenom = $first_name; $object->nom = $last_name; } break; } // Cas où l'on a aucune information sur le médecin if (!$object->rpps && !$object->adeli && !$object->_id && ($object instanceof CMediusers && !$object->_user_last_name || $object instanceof CMedecin && !$object->nom)) { return null; } if ($object instanceof CMedecin && $object->loadMatchingObjectEsc()) { return $object->_id; } $sender = $this->_ref_sender; $ds = $object->getDS(); if ($object instanceof CMediusers) { $ljoin = array(); $ljoin["functions_mediboard"] = "functions_mediboard.function_id = users_mediboard.function_id"; $where = array(); $where["functions_mediboard.group_id"] = " = '{$sender->group_id}'"; if ($object->rpps || $object->adeli) { if ($object->rpps) { $where[] = $ds->prepare("rpps = %", $object->rpps); } if ($object->adeli) { $where[] = $ds->prepare("adeli = %", $object->adeli); } // Dans le cas où le praticien recherché par son ADELI ou RPPS est multiple if ($object->countList($where, null, $ljoin) > 1) { $ljoin["users"] = "users_mediboard.user_id = users.user_id"; $where[] = $ds->prepare("users.user_last_name = %", $last_name); } $object->loadObject($where, null, null, $ljoin); if ($object->_id) { return $object->_id; } } $user = new CUser(); $ljoin = array(); $ljoin["users_mediboard"] = "users.user_id = users_mediboard.user_id"; $ljoin["functions_mediboard"] = "functions_mediboard.function_id = users_mediboard.function_id"; $where = array(); $where["functions_mediboard.group_id"] = " = '{$sender->group_id}'"; $where[] = $ds->prepare("users.user_first_name = %", $first_name); $where[] = $ds->prepare("users.user_last_name = %", $last_name); $order = "users.user_id ASC"; if ($user->loadObject($where, $order, null, $ljoin)) { return $user->_id; } $object->_user_first_name = $first_name; $object->_user_last_name = $last_name; return $this->createDoctor($object); } }
/** * 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); }
$user->user_last_name = $results[$i]["lastname"]; $user->user_first_name = $results[$i]["firstname"]; $count = $user->countMatchingList(); if ($count == "0") { $results[$i]["error"] = "L'utilisateur n'a pas été retrouvé dans Mediboard"; $i++; continue; } elseif ($count > 1) { $results[$i]["error"] = "Plusieurs utilisateurs correspondent à cette recherche"; $i++; continue; } $user->loadMatchingObject(); $mediuser = $user->loadRefMediuser(); } $idex = CIdSante400::getMatch($mediuser->_class, CMediusers::getTagMediusers(), null, $mediuser->_id); if ($idex->_id && $idex->id400 != $results[$i]["idex"]) { $results[$i]["error"] = "L'utilisateur possède déjà un identifiant ('{$idex->id400}') externe dans Mediboard"; $i++; continue; } if ($idex->_id) { $i++; continue; } $idex->id400 = $results[$i]["idex"]; $idex->last_update = CMbDT::dateTime(); if ($msg = $idex->store()) { CAppUI::setMsg($msg, UI_MSG_ERROR); $results[$i]["error"] = $msg; $i++;