Ejemplo n.º 1
0
 static function generateIdex(CMbObject $object, $tag, $group_id)
 {
     $group = CGroups::loadFromGuid("CGroups-{$group_id}");
     // On préfère générer un identifiant d'un établissement virtuel pour les séjours non-facturables
     $group_id_pour_sejour_facturable = CAppUI::conf('dPsante400 CDomain group_id_pour_sejour_facturable', $group);
     if ($object instanceof CSejour && !$object->facturable && $group_id_pour_sejour_facturable) {
         $group_id = $group_id_pour_sejour_facturable;
     }
     $group_domain = new CGroupDomain();
     $group_domain->object_class = $object->_class;
     $group_domain->group_id = $group_id;
     $group_domain->master = 1;
     $group_domain->loadMatchingObject();
     if (!$group_domain->_id) {
         return;
     }
     $domain = $group_domain->loadRefDomain();
     $conf = CAppUI::conf("dPsante400 CIncrementer");
     $cluster_count = abs(intval($conf["cluster_count"]));
     $cluster_position = abs(intval($conf["cluster_position"]));
     if ($cluster_count == 0) {
         $cluster_count = 1;
     }
     if ($cluster_count == 1) {
         $cluster_position = 0;
     }
     $mutex = new CMbSemaphore("incrementer-{$object->_class}");
     $mutex->acquire();
     $incrementer = $domain->loadRefIncrementer();
     // Chargement du dernier 'increment' s'il existe sinon on déclenche une erreur
     if (!$incrementer->_id) {
         $mutex->release();
         return;
     }
     // Incrementation de l'idex
     $value = $incrementer->value;
     // Valeur compatible avec la position dans le cluster
     do {
         $value++;
     } while ($value % $cluster_count != $cluster_position);
     do {
         // Idex vraiment disponible ?
         $idex = new CIdSante400();
         $idex->object_class = $object->_class;
         $idex->tag = $tag;
         $idex->id400 = self::formatValue($object, $incrementer->pattern, $value);
         $idex->loadMatchingObject();
     } while ($idex->_id && ($value += $cluster_count));
     $incrementer->value = $value;
     $incrementer->last_update = CMbDT::dateTime();
     $incrementer->store();
     // Création de l'identifiant externe
     $idex->object_id = $object->_id;
     $idex->last_update = CMbDT::dateTime();
     $idex->store();
     $mutex->release();
     return $idex;
 }
Ejemplo n.º 2
0
 /**
  * Load the domain supplier
  *
  * @param string $domain_type Domain type (CSejour, CPatient, etc)
  *
  * @return null|CIncrementer
  */
 function loadDomainSupplier($domain_type)
 {
     if (!$this->_id) {
         return null;
     }
     $group_domain = new CGroupDomain();
     $group_domain->object_class = $domain_type;
     $group_domain->group_id = $this->_id;
     $group_domain->master = true;
     $group_domain->loadMatchingObject();
     if (!$group_domain->_id) {
         return null;
     }
     return $group_domain->loadRefDomain()->loadRefIncrementer();
 }
 /**
  * Get person identifiers
  *
  * @param CPatient      $patient Person
  * @param CGroups       $group   Group
  * @param CInteropActor $actor   Actor
  *
  * @return array
  */
 function getPersonIdentifiers(CPatient $patient, CGroups $group, CInteropActor $actor = null)
 {
     if (!$patient->_IPP) {
         $patient->loadIPP($group->_id);
     }
     $assigning_authority = $this->getAssigningAuthority("FINESS", $group->finess);
     if (CValue::read($actor->_configs, "build_PID_3_4") === "actor") {
         $assigning_authority = $this->getAssigningAuthority("actor", null, $actor);
     } elseif (CValue::read($actor->_configs, "build_PID_3_4") === "domain") {
         // Master domain
         $group_domain = new CGroupDomain();
         $group_domain->group_id = $group->_id;
         $group_domain->master = 1;
         $group_domain->object_class = "CPatient";
         $group_domain->loadMatchingObject();
         $domain = $group_domain->loadRefDomain();
         $assigning_authority = $this->getAssigningAuthority("domain", null, null, $domain);
     }
     $IPP = $patient->_IPP;
     if (!$patient->_IPP && !CValue::read($actor->_configs, "send_not_master_IPP")) {
         $IPP = "===IPP_MISSING===";
     }
     // Table - 0203
     // RI - Resource identifier
     // PI - Patient internal identifier
     // INS-C - Identifiant national de santé calculé
     $identifiers = array();
     if (CHL7v2Message::$build_mode == "simple") {
         if ($actor->_configs["send_own_identifier"]) {
             $identifiers[] = array($IPP, null, null, !$actor->_configs["send_assigning_authority"] ? null : $assigning_authority, "PI");
             $identifiers[] = array($patient->_id, null, null, !$actor->_configs["send_assigning_authority"] ? null : $this->getAssigningAuthority("mediboard"), "RI");
         } else {
             $identifiers[] = array(!$IPP ? 0 : $IPP);
         }
         return $identifiers;
     }
     if ($IPP) {
         $identifiers[] = array($IPP, null, null, empty($actor->_configs["send_assigning_authority"]) ? null : $assigning_authority, "PI");
     }
     // Ajout des identifiants des acteurs d'intégration
     $this->fillActorsIdentifiers($identifiers, $patient, $actor);
     // Ajout d'auutres identifiants
     $this->fillOtherIdentifiers($identifiers, $patient, $actor);
     return $identifiers;
 }
 /**
  * Build PID segement
  *
  * @param CHL7v2Event $event Event
  *
  * @return null
  */
 function build(CHL7v2Event $event)
 {
     parent::build($event);
     $message = $event->message;
     $receiver = $event->_receiver;
     $group = $receiver->loadRefGroup();
     $patient = $this->patient;
     $mother = null;
     $sejour_maman = null;
     $naissance = null;
     if ($patient->_naissance_id) {
         $naissance = new CNaissance();
         $naissance->load($patient->_naissance_id);
         $sejour_maman = $naissance->loadRefSejourMaman();
         $sejour_maman->loadNDA($group->_id);
         $sejour_maman->loadRefPatient()->loadIPP($group->_id);
         $mother = $sejour_maman->_ref_patient;
     }
     $data = array();
     // PID-1: Set ID - PID (SI) (optional)
     $data[] = $this->set_id;
     // PID-2: Patient ID (CX) (optional)
     $data[] = null;
     // PID-3: Patient Identifier List (CX) (repeating)
     $data[] = $this->getPersonIdentifiers($patient, $group, $receiver);
     // PID-4: Alternate Patient ID - PID (CX) (optional repeating)
     $data[] = null;
     // PID-5: Patient Name (XPN) (repeating)
     $data[] = $this->getXPN($patient, $receiver);
     // PID-6: Mother's Maiden Name (XPN) (optional repeating)
     if ($patient->nom_jeune_fille && $receiver->_configs["build_PID_6"] == "nom_naissance") {
         $anonyme = is_numeric($patient->nom);
         $mode_identito_vigilance = $receiver->_configs["mode_identito_vigilance"];
         $prenom = CPatient::applyModeIdentitoVigilance($patient->prenom, true, $mode_identito_vigilance, $anonyme);
         $nom_jf = CPatient::applyModeIdentitoVigilance($patient->nom_jeune_fille, true, $mode_identito_vigilance, $anonyme);
         $data[] = array(array($nom_jf, $prenom, null, null, null, null, null, "L"));
     } else {
         // Dans le cas d'une naissance on va mettre l'identité de la mère
         $data[] = $mother ? $this->getXPN($mother, $receiver) : null;
     }
     // PID-7: Date/Time of Birth (TS) (optional)
     if ($patient->_naissance_id) {
         $data[] = $naissance->date_time;
     } else {
         if ($patient->naissance) {
             $data[] = CMbDT::isLunarDate($patient->naissance) ? null : $patient->naissance;
         } else {
             $data[] = null;
         }
     }
     // PID-8: Administrative Sex (IS) (optional)
     // Table - 0001
     // F - Female
     // M - Male
     // O - Other
     // U - Unknown
     // A - Ambiguous
     // N - Not applicable
     $sexe = CHL7v2TableEntry::mapTo("1", $patient->sexe);
     $data[] = $sexe ?: "U";
     // PID-9: Patient Alias (XPN) (optional repeating)
     $data[] = null;
     // PID-10: Race (CE) (optional repeating)
     $data[] = null;
     // PID-11: Patient Address (XAD) (optional repeating)
     $address = array();
     if ($patient->adresse || $patient->ville || $patient->cp) {
         $linesAdress = explode("\n", $patient->adresse, 2);
         $address[] = array(CValue::read($linesAdress, 0), str_replace("\n", $message->componentSeparator, CValue::read($linesAdress, 1)), $patient->ville, null, $patient->cp, CPaysInsee::getAlpha3($patient->pays_insee), "H");
     }
     if ($receiver->_configs["build_PID_11"] == "simple") {
         $address = array(reset($address));
     } else {
         if ($patient->lieu_naissance || $patient->cp_naissance || $patient->pays_naissance_insee) {
             $address[] = array(null, null, $patient->lieu_naissance, null, $patient->cp_naissance, CPaysInsee::getAlpha3($patient->pays_naissance_insee), "BDL");
         }
     }
     $data[] = $address;
     // PID-12: County Code (IS) (optional)
     $data[] = null;
     // PID-13: Phone Number - Home (XTN) (optional repeating)
     // Table - 0201
     // ASN - Answering Service Number
     // BPN - Beeper Number
     // EMR - Emergency Number
     // NET - Network (email) Address
     // ORN - Other Residence Number
     // PRN - Primary Residence Number
     // VHN - Vacation Home Number
     // WPN - Work Number
     // Table - 0202
     // BP       - Beeper
     // CP       - Cellular Phone
     // FX       - Fax
     // Internet - Internet Address: Use Only If Telecommunication Use Code Is NET
     // MD       - Modem
     // PH       - Telephone
     // TDD      - Telecommunications Device for the Deaf
     // TTY      - Teletypewriter
     $phones = array();
     if ($patient->tel) {
         $phones[] = $this->getXTN($receiver, $patient->tel, "PRN", "PH");
     }
     if ($patient->tel2) {
         // Pour le portable on met soit PRN ou ORN
         $phones[] = $this->getXTN($receiver, $patient->tel2, $receiver->_configs["build_cellular_phone"], "CP");
     }
     if ($patient->tel_autre) {
         $phones[] = $this->getXTN($receiver, $patient->tel_autre, $receiver->_configs["build_other_residence_number"], "PH");
     }
     if ($patient->email) {
         $phones[] = array(null, "NET", "Internet", $patient->email);
     }
     if ($receiver->_configs["build_PID_13"] === "simple") {
         $phones = array(reset($phones));
     }
     $data[] = $phones;
     // PID-14: Phone Number - Business (XTN) (optional repeating)
     $data[] = null;
     // PID-15: Primary Language (CE) (optional)
     $data[] = null;
     // PID-16: Marital Status (CE) (table 0002)(optional)
     $data[] = $patient->situation_famille;
     // PID-17: Religion (CE) (optional)
     $data[] = null;
     // PID-18: Patient Account Number (CX) (optional)
     if ($this->sejour && $receiver->_configs["build_NDA"] == "PID_18") {
         switch ($build_PID_18 = $receiver->_configs["build_PID_18"]) {
             case 'normal':
             case 'simple':
             case 'sejour_id':
                 $sejour = $this->sejour;
                 $sejour->loadNDA($group->_id);
                 $NDA = $sejour->_NDA;
                 if ($build_PID_18 == "sejour_id" && !$sejour->_NDA) {
                     $data[] = array(array($sejour->_id, null, null, $this->getAssigningAuthority("mediboard"), "RI"));
                     break;
                 }
                 if (!$sejour->_NDA && !CValue::read($receiver->_configs, "send_not_master_NDA")) {
                     $NDA = "===NDA_MISSING===";
                 }
                 if ($build_PID_18 == "simple") {
                     $data[] = $NDA;
                 } else {
                     // Même traitement que pour l'IPP
                     switch ($receiver->_configs["build_PID_3_4"]) {
                         case 'actor':
                             $assigning_authority = $this->getAssigningAuthority("actor", null, $receiver);
                             break;
                         case 'domain':
                             // Master domain
                             $group_domain = new CGroupDomain();
                             $group_domain->group_id = $group->_id;
                             $group_domain->master = 1;
                             $group_domain->object_class = "CSejour";
                             $group_domain->loadMatchingObject();
                             $domain = $group_domain->loadRefDomain();
                             $assigning_authority = $this->getAssigningAuthority("domain", null, null, $domain);
                             break;
                         default:
                             $assigning_authority = $this->getAssigningAuthority("FINESS", $group->finess);
                             break;
                     }
                     $data[] = $NDA ? array(array($NDA, null, null, $assigning_authority, "AN")) : null;
                 }
                 break;
             default:
                 $data[] = null;
         }
     } else {
         $data[] = null;
     }
     // PID-19: SSN Number - Patient (ST) (forbidden)
     switch ($receiver->_configs["build_PID_19"]) {
         case 'matricule':
             $data[] = $patient->matricule;
             break;
         default:
             $data[] = null;
             break;
     }
     // PID-20: Driver's License Number - Patient (DLN) (optional)
     $data[] = null;
     // PID-21: Mother's Identifier (CX) (optional repeating)
     // Même traitement que pour l'IPP
     switch ($receiver->_configs["build_PID_3_4"]) {
         case 'actor':
             $assigning_authority = $this->getAssigningAuthority("actor", null, $receiver);
             break;
         default:
             $assigning_authority = $this->getAssigningAuthority("FINESS", $group->finess);
             break;
     }
     if ($this->sejour) {
         $naissance = new CNaissance();
         $naissance->sejour_enfant_id = $this->sejour->_id;
         $naissance->loadMatchingObject();
         if ($naissance->_id) {
             $sejour_maman = $naissance->loadRefSejourMaman();
             $sejour_maman->loadNDA($group->_id);
             $sejour_maman->loadRefPatient()->loadIPP($group->_id);
             $mother = $sejour_maman->_ref_patient;
             $identifiers = array();
             if ($mother->_IPP) {
                 $identifiers[] = array($mother->_IPP, null, null, $assigning_authority, "PI");
             }
             if ($sejour_maman->_NDA) {
                 $identifiers[] = array($sejour_maman->_NDA, null, null, $assigning_authority, "AN");
             }
             $data[] = $identifiers;
         } else {
             $data[] = null;
         }
     } else {
         if ($mother) {
             $identifiers = array();
             if ($mother->_IPP) {
                 $identifiers[] = array($mother->_IPP, null, null, $assigning_authority, "PI");
             }
             if ($sejour_maman->_NDA) {
                 $identifiers[] = array($sejour_maman->_NDA, null, null, $assigning_authority, "AN");
             }
             $data[] = $identifiers;
         } else {
             $data[] = null;
         }
     }
     // PID-22: Ethnic Group (CE) (optional repeating)
     $data[] = null;
     // PID-23: Birth Place (ST) (optional)
     $data[] = null;
     // PID-24: Multiple Birth Indicator (ID) (optional)
     $data[] = null;
     // PID-25: Birth Order (NM) (optional)
     $data[] = $patient->rang_naissance;
     // PID-26: Citizenship (CE) (optional repeating)
     $data[] = null;
     // PID-27: Veterans Military Status (CE) (optional)
     $data[] = null;
     // PID-28: Nationality (CE) (optional)
     $data[] = null;
     // PID-29: Patient Death Date and Time (TS) (optional)
     $data[] = $patient->deces ? $patient->deces : null;
     // PID-30: Patient Death Indicator (ID) (optional)
     $data[] = $patient->deces ? "Y" : "N";
     // PID-31: Identity Unknown Indicator (ID) (optional)
     switch ($receiver->_configs["build_PID_31"]) {
         case 'avs':
             $data[] = $patient->avs;
             break;
         default:
             $data[] = null;
             break;
     }
     // PID-32: Identity Reliability Code (IS) (optional repeating)
     // Table - 0445
     // VIDE  - Identité non encore qualifiée
     // PROV  - Provisoire
     // VALI  - Validé
     // DOUB  - Doublon ou esclave
     // DESA  - Désactivé
     // DPOT  - Doublon potentiel
     // DOUA  - Doublon avéré
     // COLP  - Collision potentielle
     // COLV  - Collision validée
     // FILI  - Filiation
     // CACH  - Cachée
     // ANOM  - Anonyme
     // IDVER - Identité vérifiée par le patient
     // RECD  - Reçue d'un autre domaine
     // IDRA  - Identité rapprochée dans un autre domaine
     // USUR  - Usurpation
     // HOMD  - Homonyme detecté
     // HOMA  - Homonyme avéré
     if (CAppUI::conf("dPpatients CPatient manage_identity_status", $receiver->_ref_group)) {
         //todo voir pour DPOT
         $data[] = array($patient->status, $patient->vip ? "CACH" : null);
     } else {
         $data[] = array(is_numeric($patient->nom) ? "ANOM" : "VALI");
     }
     // PID-33: Last Update Date/Time (TS) (optional)
     $data[] = $event->last_log->date;
     // PID-34: Last Update Facility (HD) (optional)
     $data[] = null;
     // PID-35: Species Code (CE) (optional)
     $data[] = null;
     // PID-36: Breed Code (CE) (optional)
     $data[] = null;
     // PID-37: Strain (ST) (optional)
     $data[] = null;
     // PID-38: Production Class Code (CE) (optional)
     $data[] = null;
     // PID-39: Tribal Citizenship (CWE) (optional repeating)
     $data[] = null;
     $this->fill($data);
 }
Ejemplo n.º 5
0
 /**
  * Get master domain tag
  *
  * @param string $domain_type Object class
  * @param string $group_id    Group
  *
  * @return CDomain
  */
 static function getMasterDomain($domain_type, $group_id = null)
 {
     $group = CGroups::loadCurrent();
     if (!$group_id) {
         $group_id = $group->_id;
     }
     $group_domain = new CGroupDomain();
     $group_domain->object_class = $domain_type;
     $group_domain->group_id = $group_id;
     $group_domain->master = true;
     $group_domain->loadMatchingObject();
     $domain = new CDomain();
     $domain->load($group_domain->domain_id);
     return $domain;
 }