Example #1
0
}
$directory = str_replace("\\\\", "\\", $directory);
CValue::setSession("praticien_id", $praticien_id);
CValue::setSession("all_prats", $all_prats);
CValue::setSession("step", $step);
CValue::setSession("start", $start);
CValue::setSession("directory", $directory);
CValue::setSession("ignore_files", $ignore_files);
CValue::setSession("generate_pdfpreviews", $generate_pdfpreviews);
CValue::setSession("date_min", $date_min);
$step = min($step, 1000);
CStoredObject::$useObjectCache = false;
$backrefs_tree = array("CPatient" => array("identifiants", "notes", "files", "documents", "permissions", "observation_result_sets", "constantes", "contextes_constante", "consultations", "correspondants", "correspondants_patient", "sejours", "dossier_medical", "correspondants_courrier", "grossesses", "allaitements", "patient_observation_result_sets", "patient_links", 'arret_travail', "facture_patient_consult", "facture_patient_sejour"), "CConsultation" => array("files", "documents", "notes", "consult_anesth", "examaudio", "examcomp", "examnyha", "exampossum", "sejours_lies", "intervs_liees", "consults_liees", "facturable", "actes_ngap", "actes_ccam", "codages_ccam", "actes_caisse"), "CConsultAnesth" => array("files", "documents", "notes", "techniques"), "CSejour" => array("identifiants", "files", "documents", "notes", "dossier_medical", "operations", "facturable", "actes_ngap", "actes_ccam", "codages_ccam", "actes_caisse"), "COperation" => array("files", "documents", "notes", "anesth_perops", "facturable", "actes_ngap", "actes_ccam", "actes_caisse"), "CCompteRendu" => array("files"), "CDossierMedical" => array("antecedents", "traitements", "etats_dent"), "CFactureCabinet" => array("items", "reglements"), "CFactureEtablissement" => array("items", "reglements"));
$fwdrefs_tree = array("CPatient" => array("medecin_traitant"), "CConstantesMedicales" => array("context_id", "patient_id", "user_id"), "CConsultation" => array("plageconsult_id", "sejour_id", "grossesse_id", "patient_id", "consult_related_id"), "CConsultAnesth" => array("consultation_id", "operation_id", "sejour_id", "chir_id"), "CPlageconsult" => array("chir_id"), "CSejour" => array("patient_id", "praticien_id", "service_id", "group_id", "grossesse_id"), "COperation" => array("sejour_id", "chir_id", "anesth_id", "plageop_id", "salle_id", "type_anesth", "consult_related_id", "prat_visite_anesth_id"), "CGrossesse" => array("group_id", "parturiente_id"), "CCorrespondant" => array("patient_id", "medecin_id"), "CMediusers" => array("user_id"), "CPlageOp" => array("chir_id", "anesth_id", "spec_id", "salle_id"), "CActeCCAM" => array("executant_id"), "CActeNGAP" => array("executant_id"), "CActeCaisse" => array("executant_id"), "CFraidDivers" => array("executant_id"), "CFactureItem" => array("object_id"), "CFactureLiaison" => array("facture_id", "object_id"), "CFactureCabinet" => array("group_id", "patient_id", "praticien_id"), "CFactureEtablissement" => array("group_id", "patient_id", "praticien_id"), "CTypeAnesth" => array("group_id"), "CFile" => array("object_id", "author_id"), "CCompteRendu" => array("object_id", "author_id", "user_id", "function_id", "group_id", "content_id", "locker_id"));
$patient = new CPatient();
$ds = $patient->getDS();
$order = array("patients.nom", "patients.nom_jeune_fille", "patients.prenom", "patients.naissance", "patients.patient_id");
if ($all_prats && !$date_min) {
    $limit = "{$start}, {$step}";
    /** @var CPatient[] $patients */
    $patients = $patient->loadList(null, $order, $limit);
    $patient_count = count($patients);
    $patient_total = $patient->countList();
} else {
    $ljoin_consult = array("consultation" => "consultation.patient_id = patients.patient_id", "plageconsult" => "plageconsult.plageconsult_id = consultation.plageconsult_id");
    $where_consult = array();
    if (!$all_prats) {
        $where_consult["plageconsult.chir_id"] = $ds->prepareIn($praticien_id);
    }
    if ($date_min) {
        $where_consult["plageconsult.date"] = $ds->prepare(">= ?", $date_min);
 /**
  * Handle event
  *
  * @param CHL7v2PatientDemographicsAndVisitResponse $ack     Acknowledgement
  * @param CPatient                                  $patient Person
  * @param array                                     $data    Nodes data
  *
  * @return null|string
  */
 function handle(CHL7v2PatientDemographicsAndVisitResponse $ack, CPatient $patient, $data)
 {
     $exchange_hl7v2 = $this->_ref_exchange_hl7v2;
     $sender = $exchange_hl7v2->_ref_sender;
     $sender->loadConfigValues();
     $this->_ref_sender = $sender;
     $ds = $patient->getDS();
     $where = array();
     foreach ($this->getRequestPatient($data["QPD"]) as $field => $value) {
         if ($value == "") {
             continue;
         }
         if (!in_array($field, array("naissance", "cp"))) {
             $value = preg_replace("/[^a-z\\d\\*]/i", "_", $value);
             $value = preg_replace("/\\*+/", "%", $value);
         }
         $where["patients.{$field}"] = $ds->prepare("LIKE %", $value);
     }
     $ljoin = null;
     $identifier_list = $this->getRequestPatientIdentifierList($data["QPD"]);
     if (count(array_filter($identifier_list)) > 0) {
         $ljoin[10] = "id_sante400 AS id_pat_list ON id_pat_list.object_id = patients.patient_id";
         $where[] = "`id_pat_list`.`object_class` = 'CPatient'";
         // Requête sur un IPP
         if (!empty($identifier_list["id_number"]) && empty($identifier_list["namespace_id"]) && empty($identifier_list["universal_id"]) && empty($identifier_list["universal_id_type"])) {
             $where[] = $ds->prepare("id_pat_list.id400 = %", $identifier_list["id_number"]);
         }
         if (!empty($identifier_list["id_number"]) && (!empty($identifier_list["namespace_id"]) || !empty($identifier_list["universal_id"]))) {
             $namespace_id = $identifier_list["namespace_id"];
             $universal_id = $identifier_list["universal_id"];
             $domain = new CDomain();
             if ($namespace_id) {
                 $domain->namespace_id = $namespace_id;
             }
             if ($universal_id) {
                 $domain->OID = $universal_id;
             }
             if ($domain->tag || $domain->OID) {
                 $domain->loadMatchingObject();
             }
             $where[] = $ds->prepare("id_pat_list.id400 = %", $identifier_list["id_number"]);
             $where[] = $ds->prepare("id_pat_list.tag = %", $domain->tag);
         }
         if (empty($identifier_list["id_number"]) && (!empty($identifier_list["namespace_id"]) || !empty($identifier_list["universal_id"]))) {
             $namespace_id = $identifier_list["namespace_id"];
             $universal_id = $identifier_list["universal_id"];
             $domain = new CDomain();
             if ($namespace_id) {
                 $domain->namespace_id = $namespace_id;
             }
             if ($universal_id) {
                 $domain->OID = $universal_id;
             }
             if ($domain->namespace_id || $domain->OID) {
                 $domain->loadMatchingObject();
                 $where[] = $ds->prepare("id_pat_list.tag = %", $domain->tag);
             }
         }
     }
     $request_admit = false;
     // Requête sur un NDA
     $identifier_list = $this->getRequestSejourIdentifierList($data["QPD"]);
     if (count(array_filter($identifier_list)) > 0) {
         $ljoin[100] = "sejour ON `patients`.`patient_id` = `sejour`.`patient_id`";
         $ljoin[10] = "id_sante400 AS id_sej_list ON id_sej_list.object_id = sejour.sejour_id";
         $where[] = "`id_sej_list`.`object_class` = 'CSejour'";
         // Requête sur un IPP
         if (!empty($identifier_list["id_number"]) && empty($identifier_list["namespace_id"]) && empty($identifier_list["universal_id"]) && empty($identifier_list["universal_id_type"])) {
             $where[] = $ds->prepare("id_sej_list.id400 = %", $identifier_list["id_number"]);
         }
         if (!empty($identifier_list["id_number"]) && (!empty($identifier_list["namespace_id"]) || !empty($identifier_list["universal_id"]))) {
             $namespace_id = $identifier_list["namespace_id"];
             $universal_id = $identifier_list["universal_id"];
             $domain = new CDomain();
             if ($namespace_id) {
                 $domain->namespace_id = $namespace_id;
             }
             if ($universal_id) {
                 $domain->OID = $universal_id;
             }
             if ($domain->namespace_id || $domain->OID) {
                 $domain->loadMatchingObject();
             }
             $where[] = $ds->prepare("id_sej_list.id400 = %", $identifier_list["id_number"]);
             $where[] = $ds->prepare("id_sej_list.tag = %", $domain->tag);
         }
         if (empty($identifier_list["id_number"]) && (!empty($identifier_list["namespace_id"]) || !empty($identifier_list["universal_id"]))) {
             $namespace_id = $identifier_list["namespace_id"];
             $universal_id = $identifier_list["universal_id"];
             $domain = new CDomain();
             if ($namespace_id) {
                 $domain->namespace_id = $namespace_id;
             }
             if ($universal_id) {
                 $domain->OID = $universal_id;
             }
             if ($domain->namespace_id || $domain->OID) {
                 $domain->loadMatchingObject();
                 $where[] = $ds->prepare("id_sej_list.tag = %", $domain->tag);
             }
         }
     }
     foreach ($this->getRequestSejour($data["QPD"]) as $field => $value) {
         if ($value == "") {
             continue;
         }
         $value = preg_replace("/[^a-z\\*]/i", "_", $value);
         $value = preg_replace("/\\*+/", "%", $value);
         $where["sejour.{$field}"] = $ds->prepare("LIKE %", $value);
         $request_admit = true;
     }
     if ($other_request = $this->getOtherRequestSejour($data["QPD"])) {
         $where = array_merge($other_request, $where);
         $request_admit = true;
     }
     $i = 1;
     $domains = array();
     foreach ($this->getQPD8s($data["QPD"]) as $_QPD8) {
         // Requête sur un domaine particulier
         $domains_returned_namespace_id = $_QPD8["domains_returned_namespace_id"];
         // Requête sur un OID particulier
         $domains_returned_universal_id = $_QPD8["domains_returned_universal_id"];
         $domain = new CDomain();
         if ($domains_returned_namespace_id) {
             $domain->namespace_id = $domains_returned_namespace_id;
         }
         if ($domains_returned_universal_id) {
             $domain->OID = $domains_returned_universal_id;
         }
         if ($domain->namespace_id || $domain->OID) {
             $domain->loadMatchingObject();
         }
         $value = $domain->OID ? $domain->OID : $domain->tag;
         // Cas où le domaine n'est pas retrouvé
         if (!$domain->_id) {
             return $exchange_hl7v2->setPDRAE($ack, null, $value);
         }
         $domains[] = $domain;
         if ($domains_returned_namespace_id) {
             $ljoin[20 + $i] = "id_sante400 AS id{$i} ON id{$i}.object_id = patients.patient_id";
             $where[] = $ds->prepare("id{$i}.tag = %", $domain->tag);
             $i++;
         }
     }
     $quantity_limited_request = $this->getQuantityLimitedRequest($data["RCP"]);
     $limit_quantity = !!$quantity_limited_request;
     $quantity_limited_request = $quantity_limited_request ? $quantity_limited_request : 100;
     $pointer = null;
     if (isset($data["DSC"])) {
         $pointer = $this->getContinuationPointer($data["DSC"]);
     }
     $objects = array();
     if (!$request_admit) {
         // Pointeur pour continuer
         if ($pointer) {
             $patient->_pointer = $pointer;
             // is_numeric
             $where["patients.patient_id"] = $ds->prepare(" > %", $pointer);
         }
         $order = "patients.patient_id ASC";
         if (!empty($where)) {
             $objects = $patient->loadList($where, $order, $quantity_limited_request, "patients.patient_id", $ljoin);
             // If we have no next match, we won't have to add a DSC segment
             if ($limit_quantity) {
                 $next_one = $patient->loadList($where, $order, "{$quantity_limited_request},1", "patients.patient_id", $ljoin);
                 if (count($next_one) == 0) {
                     $limit_quantity = false;
                 }
             }
         }
     } else {
         $ljoin[100] = "patients ON `patients`.`patient_id` = `sejour`.`patient_id`";
         /** @var $sejour CSejour */
         $sejour = new CSejour();
         if (!empty($where)) {
             $objects = $sejour->loadList($where, null, $quantity_limited_request, "sejour.sejour_id", $ljoin);
         }
     }
     // Save information indicating that we are doing an incremental query
     $last = end($objects);
     if ($last && $limit_quantity) {
         $last->_incremental_query = true;
     }
     return $exchange_hl7v2->setPDRAA($ack, $objects, null, $domains);
 }