/** * Get affectation HL7 event code * * @param CAffectation $affectation Affectation * @param CAffectation $first_affectation First affectation * * @return null|string */ function getCodeAffectation(CAffectation $affectation, CAffectation $first_affectation = null) { $current_log = $affectation->_ref_current_log; if (!in_array($current_log->type, array("create", "store"))) { return null; } $receiver = $affectation->_receiver; $configs = $receiver->_configs; $service = $affectation->loadRefService(); $code = "A02"; if ($service->uhcd || $service->radiologie || $service->urgence) { $code = $this->getModificationAdmitCode($receiver); } if ($current_log->type == "create") { /* Affectation dans un service externe */ if ($service->externe) { return "A21"; } // Dans le cas où il s'agit de la première affectation du séjour on ne fait pas une mutation mais une modification if ($first_affectation && $first_affectation->_id == $affectation->_id) { switch ($configs["send_first_affectation"]) { case 'Z99': return $this->getModificationAdmitCode($receiver); default: return $code; } } // Création d'une affectation switch ($configs["send_transfer_patient"]) { case 'Z99': return $this->getModificationAdmitCode($receiver); default: return $code; } } /* Affectation dans un service externe effectuée */ if ($service->externe && !$affectation->_old->effectue && $affectation->effectue) { return "A22"; } /* Affectation dans un service externe effectuée */ if ($service->externe && $affectation->_old->effectue && !$affectation->effectue) { return "A53"; } /* Changement d'UF Médicale */ if ($affectation->_old->uf_medicale_id && $affectation->fieldModified("uf_medicale_id")) { /* @todo Gérer le cas où : création d'une nouvelle affectation && UM1 # UM2 */ switch ($configs["send_change_medical_responsibility"]) { case 'Z80': return "Z80"; case 'A02': return "A02"; default: return $this->getModificationAdmitCode($receiver); } } /* Changement d'UF de Soins */ if ($affectation->_old->uf_soins_id && $affectation->fieldModified("uf_soins_id")) { /* @todo Gérer le cas où : création d'une nouvelle affectation && US1 # US2 */ switch ($configs["send_change_nursing_ward"]) { case 'Z84': return "Z84"; case 'A02': return "A02"; default: return $this->getModificationAdmitCode($receiver); } } // Modifcation d'une affectation return $this->getModificationAdmitCode($affectation->_receiver); }