/**
  * Enregistrement de la grossesse
  *
  * @param CSejour $newVenue Admit
  *
  * @return null|string|void
  */
 function storeGrossesse(CSejour $newVenue)
 {
     $sender = $this->_ref_sender;
     if (!$sender->_configs["create_grossesse"]) {
         return null;
     }
     if ($newVenue->type_pec != "O") {
         return null;
     }
     $grossesse = $newVenue->loadRefGrossesse();
     if (!$grossesse->_id) {
         $patient = $newVenue->loadRefPatient();
         $grossesse = $patient->loadLastGrossesse();
         if (!$grossesse->_id) {
             $grossesse->parturiente_id = $newVenue->patient_id;
             $grossesse->group_id = $newVenue->group_id;
             $grossesse->terme_prevu = CMbDT::date($newVenue->sortie);
             $grossesse->_eai_sender_guid = $sender->_guid;
             if ($msg = $grossesse->store()) {
                 return $msg;
             }
         }
     }
     $newVenue->grossesse_id = $grossesse->_id;
     // On ne check pas la cohérence des dates des consults/intervs
     $newVenue->_skip_date_consistencies = true;
     $newVenue->_eai_sender_guid = $sender->_guid;
     if ($msg = $newVenue->store()) {
         return $msg;
     }
     return null;
 }
Example #2
0
 /**
  * Ordonnancement par degré des constantes notées
  *
  * @return void
  */
 function orderCtes()
 {
     if (!$this->_id) {
         return null;
     }
     $this->_ref_cts_degre = array(1 => array(), 2 => array(), 3 => array(), 4 => array());
     $this->_estimation_ccmu = 4;
     $this->_ref_latest_constantes = CConstantesMedicales::getLatestFor($this->_patient_id, null, array(), $this->_ref_sejour, false);
     $where = array();
     $where["patient_id"] = " = '" . $this->_patient_id . "'";
     $where["context_class"] = " = '" . $this->_ref_sejour->_class . "'";
     $where["context_id"] = " = '" . $this->_ref_sejour->_id . "'";
     $where["comment"] = " IS NOT NULL";
     $constante = new CConstantesMedicales();
     $constante->loadObject($where, "datetime ASC");
     if ($constante->_id) {
         $this->_ref_latest_constantes[0]->comment = $constante->comment;
     }
     $latest_constantes = $this->_ref_latest_constantes;
     $echelle_tri = $this->loadRefEchelleTri();
     $grossesse = $this->_ref_sejour->loadRefGrossesse();
     $sa_grossesse = CModule::getActive("maternite") && $grossesse->terme_prevu ? $grossesse->_semaine_grossesse : $echelle_tri->enceinte == 1 ?: 0;
     if ($glasgow = $latest_constantes[0]->glasgow) {
         $degre = $glasgow <= 8 ? 1 : 4;
         if ($glasgow >= 9 && $glasgow <= 13) {
             $degre = 2;
         } elseif ($glasgow == 14 && $glasgow == 15) {
             $degre = 3;
         }
         $this->_ref_cts_degre[$degre][] = 'glasgow';
     }
     if ($pouls = $latest_constantes[0]->pouls) {
         $degre = $pouls < 40 || $pouls > 150 ? 1 : 4;
         if ($pouls >= 40 && $pouls <= 50 || $pouls >= 130 && $pouls <= 150) {
             $degre = 2;
         } elseif ($pouls >= 51 && $pouls <= 129) {
             $degre = 3;
         }
         $this->_ref_cts_degre[$degre][] = 'pouls';
     }
     //Tensions
     if ($latest_constantes[0]->ta_gauche) {
         $this->orderTA("ta_gauche", $latest_constantes[0]->_ta_gauche_systole, $latest_constantes[0]->_ta_gauche_diastole);
     }
     if ($latest_constantes[0]->ta_droit) {
         $this->orderTA("ta_droit", $latest_constantes[0]->_ta_droit_systole, $latest_constantes[0]->_ta_droit_diastole);
     }
     if ($latest_constantes[0]->ta) {
         $this->orderTA("ta", $latest_constantes[0]->_ta_systole, $latest_constantes[0]->_ta_diastole);
     }
     if ($frequence = $latest_constantes[0]->frequence_respiratoire) {
         $degre = $frequence > 35 || $frequence <= 8 ? 1 : 4;
         if ($frequence >= 25 && $frequence <= 35 || $frequence >= 9 && $frequence <= 12) {
             $degre = 2;
         } elseif ($frequence >= 13 && $frequence <= 24) {
             $degre = 3;
         }
         $this->_ref_cts_degre[$degre][] = 'frequence_respiratoire';
     }
     if ($spo2 = $latest_constantes[0]->spo2) {
         $degre = $spo2 < 90 ? 1 : 4;
         if ($spo2 >= 90 && $spo2 <= 93) {
             $degre = 2;
         } elseif ($spo2 >= 94 && $spo2 <= 100) {
             $degre = 3;
         }
         $this->_ref_cts_degre[$degre][] = 'spo2';
     }
     if ($temp = $latest_constantes[0]->temperature) {
         $degre = $temp < 32 ? 1 : 4;
         if ($temp >= 32 && $temp <= 35 || $temp > 40) {
             $degre = 2;
         } elseif ($temp > 35 && $temp <= 40) {
             $degre = 3;
         }
         $this->_ref_cts_degre[$degre][] = 'temperature';
     }
     if ($glycemie = $latest_constantes[0]->glycemie) {
         if ($glycemie < 4 || $glycemie >= 25) {
             $degre = 2;
         } elseif ($glycemie >= 4 && $glycemie < 25) {
             $degre = 3;
         }
         $this->_ref_cts_degre[$degre][] = 'glycemie';
     }
     if ($cetonemie = $latest_constantes[0]->cetonemie) {
         if ($cetonemie >= 0.6) {
             $degre = 2;
         } elseif ($cetonemie < 0.6) {
             $degre = 3;
         }
         $this->_ref_cts_degre[$degre][] = 'cetonemie';
     }
     $patient = $this->_ref_sejour->_ref_patient;
     if ($latest_constantes[0]->peak_flow && $latest_constantes[0]->taille && $patient->_annees && $patient->sexe) {
         //(H)DEPTh = Exp[(0,544 x Log(Age)) - (0,0151 x Age) - (74,7 / Taille) + 5,48]
         //((F)DEPTh = Exp[(0,376 x Log(Age)) - (0,0120 x Age) - (58,8 / Taille) + 5,63]
         if ($patient->sexe == 'f') {
             $depth = round(exp(0.376 * log($patient->_annees) - 0.012 * $patient->_annees - 58.8 / $latest_constantes[0]->taille + 5.63), 2);
         } else {
             $depth = round(exp(0.544 * log($patient->_annees) - 0.0151 * $patient->_annees - 74.7 / $latest_constantes[0]->taille + 5.48));
         }
         $taux = round($latest_constantes[0]->peak_flow / $depth * 100, 2);
         $degre = $taux > 50 ? 3 : 2;
         $this->_ref_cts_degre[$degre][$depth] = 'peak_flow';
     }
     if ($contraction_uterine = $latest_constantes[0]->contraction_uterine) {
         $degre = $contraction_uterine >= 3 ? 1 : 4;
         if ($contraction_uterine > 1 && $contraction_uterine < 3) {
             $degre = 2;
         } elseif ($contraction_uterine <= 1) {
             $degre = 3;
         }
         $this->_ref_cts_degre[$degre][] = 'contraction_uterine';
     }
     if ($latest_constantes[0]->bruit_foetal && $sa_grossesse >= 20) {
         $bruit_foetal = $latest_constantes[0]->bruit_foetal;
         $degre = 4;
         if ($sa_grossesse > 24) {
             if ($bruit_foetal >= 40 && $bruit_foetal <= 100 || $bruit_foetal >= 180) {
                 $degre = 1;
             } elseif ($bruit_foetal == 0 || $bruit_foetal >= 101 && $bruit_foetal <= 119 || $bruit_foetal >= 160 && $bruit_foetal <= 179) {
                 $degre = 2;
             } elseif ($bruit_foetal >= 120 && $bruit_foetal <= 159) {
                 $degre = 3;
             }
         } else {
             $degre = $bruit_foetal > 0 ? 3 : 2;
         }
         $this->_ref_cts_degre[$degre][] = 'bruit_foetal';
     }
     if ($echelle_tri->liquide && $grossesse->_id) {
         $degre = $echelle_tri->liquide == 'meconial' ? 2 : 3;
         $this->_ref_cts_degre[$degre][] = 'liquide';
     }
     if ($echelle_tri->pupille_droite || $echelle_tri->pupille_gauche) {
         $gauche = $echelle_tri->pupille_gauche;
         $droit = $echelle_tri->pupille_droite;
         $degre = $gauche == 3 || $gauche == 1 || $droit == 3 || $droit == 1 ? 2 : 3;
         $this->_ref_cts_degre[$degre][] = 'pupilles';
     }
     unset($this->_ref_cts_degre[4]);
     if (count($this->_ref_cts_degre[1])) {
         $this->_estimation_ccmu = 1;
     } elseif (count($this->_ref_cts_degre[2])) {
         $this->_estimation_ccmu = 2;
     } elseif (count($this->_ref_cts_degre[3])) {
         $this->_estimation_ccmu = 3;
     }
     ksort($this->_ref_cts_degre);
 }
$mins_duree = range(0, 59, $config["min_intervalle"]);
// Chargement des etablissements externes
$etab = new CEtabExterne();
$count_etab_externe = $etab->countList();
// Récupération des services
$service = new CService();
$where = array();
$where["group_id"] = "= '" . CGroups::loadCurrent()->_id . "'";
$where["cancelled"] = "= '0'";
$order = "nom";
$listServices = $service->loadListWithPerms(PERM_READ, $where, $order);
foreach ($listServices as $_service) {
    $_service->loadRefUFSoins();
}
if (CModule::getActive("maternite")) {
    $sejour->loadRefGrossesse();
}
// Création du template
$smarty = new CSmartyDP();
$smarty->assign("sejours_collision", $patient->getSejoursCollisions());
$smarty->assign("urgInstalled", CModule::getInstalled("dPurgences"));
$smarty->assign("isPrescriptionInstalled", CModule::getActive("dPprescription"));
$smarty->assign("heure_sortie_ambu", $heure_sortie_ambu);
$smarty->assign("heure_sortie_autre", $heure_sortie_autre);
$smarty->assign("heure_entree_veille", $heure_entree_veille);
$smarty->assign("heure_entree_jour", $heure_entree_jour);
$smarty->assign("hours", $hours);
$smarty->assign("mins", $mins);
$smarty->assign("hours_duree", $hours_duree);
$smarty->assign("hours_urgence", $hours_urgence);
$smarty->assign("mins_duree", $mins_duree);
 /**
  * @see parent::store()
  */
 function store()
 {
     $this->completeField("sejour_id", "lit_id", "entree", "sortie");
     $create_affectations = false;
     $sejour = $this->loadRefSejour();
     $sejour->loadRefPatient();
     // Conserver l'ancien objet avant d'enregistrer
     $old = new CAffectation();
     if ($this->_id) {
         $old->load($this->_id);
         // Si ce n'est pas la première affectation de la série, alors la ref_prev et la ref_next sont erronées
         // si prises depuis l'affectation old
         if (isset($this->_is_prev) || isset($this->_is_next)) {
             $this->loadRefsAffectations();
             $old->_ref_prev = $this->_ref_prev;
             $old->_ref_next = $this->_ref_next;
         } else {
             $old->loadRefsAffectations();
         }
     }
     // Gestion du service_id
     if ($this->lit_id) {
         $this->service_id = $this->loadRefLit(false)->loadRefChambre(false)->service_id;
     }
     // Gestion des UFs
     $this->makeUF();
     // Si c'est une création d'affectation, avec ni une précédente ni une suivante,
     // que le séjour est relié à une grossesse, et que le module maternité est actif,
     // alors il faut créer les affectations des bébés.
     if (CModule::getActive("maternite") && !is_numeric($sejour->_ref_patient->nom) && $sejour->grossesse_id && !$this->_id) {
         $this->loadRefsAffectations();
         if (!$this->_ref_prev->_id && !$this->_ref_next->_id) {
             $create_affectations = true;
         }
     }
     $store_prestations = false;
     if ($this->lit_id && $this->sejour_id && (!$this->_id || $this->fieldModified("lit_id"))) {
         $store_prestations = true;
     }
     // Si on place le patient alors que le séjour a déjà une sortie réelle
     // alors on passe le flag effectue à 1 sur l'affectation
     if (!$this->_id && $sejour->sortie_reelle) {
         $this->effectue = 1;
     }
     // Enregistrement standard
     if ($msg = parent::store()) {
         return $msg;
     }
     // Niveaux de prestations réalisées à créer
     // pour une nouvelle affectation (par rapport aux niveaux de prestations du lit)
     if ($store_prestations) {
         $this->loadRefsAffectations();
         $lit = $this->_ref_lit;
         $liaisons_lit = $lit->loadRefsLiaisonsItems();
         CMbObject::massLoadFwdRef($liaisons_lit, "item_prestation_id");
         $where = array();
         $ljoin = array();
         $where["sejour_id"] = "= '{$sejour->_id}'";
         $where["item_prestation.object_class"] = "= 'CPrestationJournaliere'";
         // On teste également le réalisé, si une affectation avait déjà été faite puis supprimée.
         $ljoin["item_prestation"] = "item_prestation.item_prestation_id = item_liaison.item_souhait_id\r\n      OR item_prestation.item_prestation_id = item_liaison.item_realise_id";
         $filter_entree = CMbDT::date($this->entree);
         foreach ($liaisons_lit as $_liaison) {
             $item_liaison = new CItemLiaison();
             $_item = $_liaison->loadRefItemPrestation();
             // Recherche d'une liaison :
             // - date de début si première affectation ou dans la même journée
             // - le jour suivant sinon, car il doit y avoir un passage d'une case pour le calcul des prestations
             $where["item_prestation.object_id"] = "= '{$_item->object_id}'";
             $where["date"] = "= '" . $filter_entree . "'";
             $item_liaison->loadObject($where, null, null, $ljoin);
             // Si existante, alors on affecte le réalisé au niveau de prestation du lit
             if ($item_liaison->_id) {
                 $item_liaison->item_realise_id = $_liaison->item_prestation_id;
                 if ($msg = $item_liaison->store()) {
                     CAppUI::setMsg($msg, UI_MSG_ERROR);
                 }
             } else {
                 $item_liaison->sejour_id = $sejour->_id;
                 $item_liaison->date = $filter_entree;
                 $item_liaison->quantite = 0;
                 $item_liaison->item_realise_id = $_liaison->item_prestation_id;
                 // Recherche d'une précédente liaison pour appliquer l'item souhaité s'il existe
                 $where["date"] = "<= '" . CMbDT::date($this->entree) . "'";
                 $ljoin["item_prestation"] = "item_prestation.item_prestation_id = item_liaison.item_souhait_id";
                 $_item_liaison_souhait = new CItemLiaison();
                 $_item_liaison_souhait->loadObject($where, "date DESC", null, $ljoin);
                 if ($_item_liaison_souhait->_id) {
                     $item_liaison->item_souhait_id = $_item_liaison_souhait->item_souhait_id;
                     $item_liaison->sous_item_id = $_item_liaison_souhait->sous_item_id;
                 }
                 if ($msg = $item_liaison->store()) {
                     CAppUI::setMsg($msg, UI_MSG_ERROR);
                 }
             }
             // Dans tous les cas, il faut parcourir les liaisons existantes entre les dates de début et fin de l'affectation
             $where["date"] = "BETWEEN '" . $filter_entree . "' AND '" . CMbDT::date($this->sortie) . "'";
             $ljoin["item_prestation"] = "item_prestation.item_prestation_id = item_liaison.item_souhait_id\r\n          OR item_prestation.item_prestation_id = item_liaison.item_realise_id";
             $liaisons_existantes = $item_liaison->loadList($where, null, null, null, $ljoin);
             foreach ($liaisons_existantes as $_liaison_existante) {
                 $_liaison_existante->item_realise_id = $_liaison->item_prestation_id;
                 if ($msg = $_liaison_existante->store()) {
                     CAppUI::setMsg($msg, UI_MSG_ERROR);
                 }
             }
         }
     }
     if ($create_affectations) {
         $grossesse = $this->_ref_sejour->loadRefGrossesse();
         $naissances = $grossesse->loadRefsNaissances();
         $sejours = CMbObject::massLoadFwdRef($naissances, "sejour_enfant_id");
         foreach ($sejours as $_sejour) {
             $_affectation = new CAffectation();
             $_affectation->lit_id = $this->lit_id;
             $_affectation->sejour_id = $_sejour->_id;
             $_affectation->parent_affectation_id = $this->_id;
             $_affectation->entree = CMbDT::dateTime();
             $_affectation->sortie = $this->sortie;
             if ($msg = $_affectation->store()) {
                 return $msg;
             }
         }
     }
     // Pas de problème de synchro pour les blocages de lits
     if (!$this->sejour_id || $this->_no_synchro) {
         return $msg;
     }
     // Modification de la date d'admission et de la durée de l'hospi
     $this->load($this->_id);
     if ($old->_id) {
         $this->_ref_prev = $old->_ref_prev;
         $this->_ref_next = $old->_ref_next;
     } else {
         $this->loadRefsAffectations();
     }
     $changeSejour = 0;
     $changePrev = 0;
     $changeNext = 0;
     $prev = $this->_ref_prev;
     $next = $this->_ref_next;
     // Mise à jour vs l'entrée
     if (!$prev->_id) {
         if ($this->entree != $sejour->entree) {
             $field = $sejour->entree_reelle ? "entree_reelle" : "entree_prevue";
             $sejour->{$field} = $this->entree;
             $changeSejour = 1;
         }
     } elseif ($this->entree != $prev->sortie) {
         $prev->sortie = $this->entree;
         $changePrev = 1;
     }
     // Mise à jour vs la sortie
     if (!$next->_id) {
         if ($this->sortie != $sejour->sortie) {
             $field = $sejour->sortie_reelle ? "sortie_reelle" : "sortie_prevue";
             $sejour->{$field} = $this->sortie;
             $changeSejour = 1;
         }
     } elseif ($this->sortie != $next->entree) {
         $next->entree = $this->sortie;
         $changeNext = 1;
     }
     if ($changePrev) {
         $prev->_is_prev = 1;
         $prev->store();
     }
     if ($changeNext) {
         $next->_is_next = 1;
         $next->store();
     }
     if ($changeSejour) {
         $sejour->_no_synchro = 1;
         $sejour->updateFormFields();
         if ($msg = $sejour->store()) {
             return $msg;
         }
     }
     return $msg;
 }