function loadRefGroup()
 {
     if (!$this->_ref_group) {
         $this->_ref_group = new CGroups();
         $this->_ref_group->load($this->group_id);
     }
 }
 /**
  * Get group host
  *
  * @param bool $get_id Only get the ID, not the object
  *
  * @return CGroups|int|null
  */
 static function getHostGroup($get_id = true)
 {
     if (isset(self::$_host_group)) {
         return $get_id ? self::$_host_group->_id : self::$_host_group;
     }
     $host_group_id = CAppUI::conf("dPstock host_group_id");
     if (!$host_group_id) {
         $host_group_id = CGroups::loadCurrent()->_id;
     }
     $group = new CGroups();
     $group->load($host_group_id);
     self::$_host_group = $group;
     if ($get_id) {
         return $group->_id;
     }
     return $group;
 }
 /**
  * Recording NDA
  * 
  * @param CIdSante400    $NDA    Object id400
  * @param CSejour        $sejour Admit
  * @param CInteropSender $sender Sender
  * 
  * @return null|string null if successful otherwise returns and error message
  */
 static function storeNDA(CIdSante400 $NDA, CSejour $sejour, CInteropSender $sender)
 {
     /* Gestion du numéroteur */
     $group = new CGroups();
     $group->load($sender->group_id);
     $group->loadConfigValues();
     // Purge du NDA existant sur le séjour et on le remplace par le nouveau
     if ($sender->_configs["purge_idex_movements"]) {
         // On charge le NDA courant du séjour
         $sejour->loadNDA($sender->group_id);
         $ref_NDA = $sejour->_ref_NDA;
         if ($ref_NDA) {
             // Si le NDA actuel est identique à celui qu'on reçoit on ne fait rien
             if ($ref_NDA->id400 == $NDA->id400) {
                 return;
             }
             // On passe le NDA courant en trash
             $ref_NDA->tag = CAppUI::conf("dPplanningOp CSejour tag_dossier_trash") . $ref_NDA->tag;
             $ref_NDA->_eai_sender_guid = $sender->_guid;
             $ref_NDA->store();
         }
         // On sauvegarde le nouveau
         $NDA->tag = $sender->_tag_sejour;
         $NDA->object_class = "CSejour";
         $NDA->object_id = $sejour->_id;
         $NDA->last_update = CMbDT::dateTime();
         $NDA->_eai_sender_guid = $sender->_guid;
         return $NDA->store();
     }
     // Génération du NDA ?
     // Non
     if (!$group->_configs["smp_idex_generator"]) {
         if (!$NDA->id400) {
             return null;
         }
         if ($sejour) {
             $NDA->object_id = $sejour->_id;
         }
         $NDA->last_update = CMbDT::dateTime();
         $NDA->_eai_sender_guid = $sender->_guid;
         return $NDA->store();
     } else {
         $NDA_temp = CIdSante400::getMatch("CSejour", $sender->_tag_sejour, null, $sejour->_id);
         if ($NDA_temp->_id) {
             return;
         }
         // Pas de NDA passé
         if (!$NDA->id400) {
             if (!CIncrementer::generateIdex($sejour, $sender->_tag_sejour, $sender->group_id)) {
                 return CAppUI::tr("CEAISejour-error-generate-idex");
             }
             return null;
         } else {
             $incrementer = $sender->loadRefGroup()->loadDomainSupplier("CSejour");
             if ($incrementer && $NDA->id400 < $incrementer->range_min || $NDA->id400 > $incrementer->range_max) {
                 return CAppUI::tr("CEAISejour-idex-not-in-the-range");
             }
             $NDA->object_id = $sejour->_id;
             $NDA->last_update = CMbDT::dateTime();
             $NDA->_eai_sender_guid = $sender->_guid;
             return $NDA->store();
         }
     }
 }
Exemple #4
0
        CAppUI::redirect("m=system&a=module_missing&mod={$m}");
    }
    $m = "dP{$m}";
}
// Get current module permissions
// these can be further modified by the included action files
$can = $module->canDo();
$a = CAppUI::checkFileName(CValue::get("a", $index));
$u = CAppUI::checkFileName(CValue::get("u", ""));
$dosql = CAppUI::checkFileName(CValue::post("dosql", ""));
$class = CAppUI::checkFileName(CValue::post("@class", ""));
$tab = $a == "index" ? CValue::getOrSession("tab", $tab) : CValue::get("tab");
// set the group in use, put the user group if not allowed
$g = CValue::getOrSessionAbs("g", CAppUI::$instance->user_group);
$indexGroup = new CGroups();
if ($indexGroup->load($g) && !$indexGroup->canRead()) {
    $g = CAppUI::$instance->user_group;
    CValue::setSessionAbs("g", $g);
}
$user = CAppUI::$user;
// Check whether the password is strong enough
// If account is not a robot
if ($user->_id && !$user->isRobot() && (!($m == "admin" && $tab == "chpwd") && !($m == "admin" && $dosql == "do_chpwd_aed"))) {
    if (CAppUI::$instance->weak_password && (!CAppUI::$instance->user_remote || CAppUI::conf("admin CUser apply_all_users"))) {
        CAppUI::redirect("m=admin&tab=chpwd&forceChange=1");
    }
    // If we want to force user to periodically change password
    if (CAppUI::conf("admin CUser force_changing_password") || $user->_ref_user->force_change_password) {
        // Need to change
        if ($user->_ref_user->force_change_password) {
            CAppUI::redirect("m=admin&tab=chpwd&forceChange=1");
<?php

/**
 * $Id$
 *  
 * @category CDA
 * @package  Mediboard
 * @author   SARL OpenXtrem <*****@*****.**>
 * @license  GNU General Public License, see http://www.gnu.org/licenses/gpl.html
 * @version  $Revision$
 * @link     http://www.mediboard.org
 */
$group_type = CValue::post("group_type");
$group_id = CValue::post("group_id");
$group = new CGroups();
$group->load($group_id);
$idex = new CIdSante400();
$idex->tag = "cda_association_code";
$idex->setObject($group);
$idex->loadMatchingObject();
$idex->last_update = CMbDT::dateTime();
$idex->id400 = $group_type;
if ($group_type && ($msg = $idex->store())) {
    CAppUI::setMsg($msg, UI_MSG_ERROR);
}
CAppUI::setMsg("Configuration effectué");
 /**
  * @see parent::extractData
  */
 function extractData()
 {
     /** @var CDocumentItem $docItem */
     $docItem = $this->mbObject;
     $this->realm_code = "FR";
     $this->langage = $docItem->language;
     //Récupération du dernier log qui correspond à la date de création de cette version
     $last_log = $docItem->loadLastLog();
     $this->date_creation = $last_log->date;
     $this->date_author = $last_log->date;
     $this->targetObject = $object = $docItem->loadTargetObject();
     if ($object instanceof CConsultAnesth) {
         $this->targetObject = $object = $object->loadRefConsultation();
     }
     $this->practicien = $object->loadRefPraticien();
     $this->patient = $object->loadRefPatient();
     $this->patient->loadLastINS();
     $this->patient->loadIPP();
     $this->mbObject = $docItem;
     $this->root = CMbOID::getOIDFromClass($docItem, $this->receiver);
     $this->practicien->loadRefFunction();
     $this->practicien->loadRefOtherSpec();
     $group = new CGroups();
     $group->load($this->practicien->_group_id);
     $this->healt_care = CCdaTools::loadEntryJV("CI-SIS_jdv_healthcareFacilityTypeCode.xml", CIdSante400::getValueFor($group, "cda_association_code"));
     if ($docItem instanceof CFile) {
         $this->version = "1";
         $this->nom = basename($docItem->file_name);
     } else {
         $this->version = $docItem->version;
         $this->nom = $docItem->nom;
     }
     $this->id_cda_lot = "{$this->root}.{$docItem->_id}";
     $this->id_cda = "{$this->id_cda_lot}.{$this->version}";
     $confidentialite = "N";
     if ($docItem->private) {
         $confidentialite = "R";
     }
     $this->confidentialite = CCdaTools::loadEntryJV("CI-SIS_jdv_confidentialityCode.xml", $confidentialite);
     if ($docItem->type_doc) {
         $type = explode("^", $docItem->type_doc);
         $this->code = CCdaTools::loadEntryJV("CI-SIS_jdv_typeCode.xml", $type[1]);
     }
     //conformité HL7
     $this->templateId[] = $this->createTemplateID("2.16.840.1.113883.2.8.2.1", "HL7 France");
     //Conformité CI-SIS
     $this->templateId[] = $this->createTemplateID("1.2.250.1.213.1.1.1.1", "CI-SIS");
     //Confirmité IHE XSD-SD => contenu non structuré
     $this->templateId[] = $this->createTemplateID("1.3.6.1.4.1.19376.1.2.20", "IHE XDS-SD");
     $this->industry_code = CCdaTools::loadEntryJV("CI-SIS_jdv_practiceSettingCode.xml", "ETABLISSEMENT");
     $mediaType = "application/pdf";
     //Génération du PDF
     if ($docItem instanceof CFile) {
         $path = $docItem->_file_path;
         switch ($docItem->file_type) {
             case "image/tiff":
                 $mediaType = "image/tiff";
                 break;
             case "application/pdf":
                 $mediaType = $docItem->file_type;
                 $path = CCdaTools::generatePDFA($docItem->_file_path);
                 break;
             case "image/jpeg":
             case "image/jpg":
                 $mediaType = "image/jpeg";
                 break;
             case "application/rtf":
                 $mediaType = "text/rtf";
                 break;
             default:
                 $docItem->convertToPDF();
                 $file = $docItem->loadPDFconverted();
                 $path = CCdaTools::generatePDFA($file->_file_path);
         }
     } else {
         if ($msg = $docItem->makePDFpreview(1, 0)) {
             throw new CMbException($msg);
         }
         $file = $docItem->_ref_file;
         $path = CCdaTools::generatePDFA($file->_file_path);
     }
     $this->file = $path;
     $this->mediaType = $mediaType;
     $service["nullflavor"] = null;
     switch (get_class($object)) {
         case "CSejour":
             /** @var CSejour $object CSejour */
             $dp = $object->DP;
             $service["time_start"] = $object->entree;
             $service["time_stop"] = $object->sortie;
             $service["executant"] = $object->loadRefPraticien();
             if ($dp) {
                 $service["oid"] = "2.16.840.1.113883.6.3";
                 $service["code"] = $dp;
                 $service["type_code"] = "cim10";
             } else {
                 $service["nullflavor"] = "UNK";
             }
             break;
         case "COperation":
             /** @var COperation $object COperation */
             $no_acte = 0;
             foreach ($object->loadRefsActesCCAM() as $_acte_ccam) {
                 if ($_acte_ccam->code_activite === "4" || !$_acte_ccam->_check_coded || $no_acte >= 1) {
                     continue;
                 }
                 $service["time_start"] = $_acte_ccam->execution;
                 $service["time_stop"] = "";
                 $service["code"] = $_acte_ccam->code_acte;
                 $service["oid"] = "1.2.250.1.213.2.5";
                 $_acte_ccam->loadRefExecutant();
                 $service["executant"] = $_acte_ccam->_ref_executant;
                 $service["type_code"] = "ccam";
                 $no_acte++;
             }
             if ($no_acte === 0) {
                 $service["time_start"] = $object->debut_op;
                 $service["time_stop"] = $object->fin_op;
                 $service["executant"] = $object->loadRefPraticien();
                 $service["nullflavor"] = "UNK";
             }
             break;
         case "CConsultation":
             /** @var CConsultation $object CConsultation */
             $object->loadRefPlageConsult();
             $no_acte = 0;
             foreach ($object->loadRefsActesCCAM() as $_acte_ccam) {
                 if (!$_acte_ccam->_check_coded || $_acte_ccam->code_activite === "4" || $no_acte >= 1) {
                     continue;
                 }
                 $service["time_start"] = $_acte_ccam->execution;
                 $service["time_stop"] = "";
                 $service["code"] = $_acte_ccam->code_acte;
                 $service["oid"] = "1.2.250.1.213.2.5";
                 $_acte_ccam->loadRefExecutant();
                 $service["executant"] = $_acte_ccam->_ref_executant;
                 $service["type_code"] = "ccam";
                 $no_acte++;
             }
             if ($no_acte === 0) {
                 $service["time_start"] = $object->_datetime;
                 $service["time_stop"] = $object->_date_fin;
                 $service["executant"] = $object->loadRefPraticien();
                 $service["nullflavor"] = "UNK";
             }
             break;
         default:
     }
     $this->service_event = $service;
     if ($this->old_version) {
         $oid = CMbOID::getOIDFromClass($docItem, $this->receiver);
         $this->old_version = "{$oid}.{$this->old_id}.{$this->old_version}";
     }
 }
 /**
  * Trigger after event store
  *
  * @param CMbObject $mbObject Object
  *
  * @throws CMbException
  *
  * @return bool
  */
 function onAfterStore(CMbObject $mbObject)
 {
     if (!$this->isHandled($mbObject)) {
         return false;
     }
     $receiver = $mbObject->_receiver;
     if ($mbObject instanceof CCorrespondantPatient) {
         $patient = $mbObject->loadRefPatient();
         $patient->_receiver = $receiver;
     } else {
         $patient = $mbObject;
     }
     // Si Serveur
     if (CAppUI::conf('sip server')) {
         $echange_hprim = new CEchangeHprim();
         if (isset($patient->_eai_exchange_initiator_id)) {
             $echange_hprim->load($patient->_eai_exchange_initiator_id);
         }
         $initiateur = $receiver->_id == $echange_hprim->sender_id ? $echange_hprim->_id : null;
         $group = new CGroups();
         $group->load($receiver->group_id);
         $group->loadConfigValues();
         if (!$initiateur && !$group->_configs["sip_notify_all_actors"]) {
             return false;
         }
         $patient->_id400 = null;
         $idexPatient = new CIdSante400();
         $idexPatient->loadLatestFor($patient, $receiver->_tag_patient);
         $patient->_id400 = $idexPatient->id400;
         $this->generateTypeEvenement("CHPrimXMLEnregistrementPatient", $patient, true, $initiateur);
     } else {
         if (!$receiver->isMessageSupported("CHPrimXMLEnregistrementPatient")) {
             return false;
         }
         if (!$patient->_IPP) {
             // Génération de l'IPP dans le cas de la création, ce dernier n'était pas créé
             if ($msg = $patient->generateIPP()) {
                 CAppUI::setMsg($msg, UI_MSG_ERROR);
             }
             $IPP = new CIdSante400();
             $IPP->loadLatestFor($patient, $receiver->_tag_patient);
             $patient->_IPP = $IPP->id400;
         }
         // Envoi pas les patients qui n'ont pas d'IPP
         if (!$receiver->_configs["send_all_patients"] && !$patient->_IPP) {
             return false;
         }
         $this->sendEvenementPatient("CHPrimXMLEnregistrementPatient", $patient);
         if ($receiver->_configs["send_insured_without_admit"]) {
             if (!$receiver->isMessageSupported("CHPrimXMLDebiteursVenue")) {
                 return false;
             }
             $sejour = new CSejour();
             $where = array();
             $where["patient_id"] = "= '{$patient->_id}'";
             $where["group_id"] = "= '{$receiver->group_id}'";
             $datetime = CMbDT::dateTime();
             $where["sortie"] = ">= '{$datetime}'";
             /** @var CSejour[] $sejours */
             $sejours = $sejour->loadList($where);
             // On va transmettre les informations sur le débiteur pour le séjour en cours, et ceux à venir
             foreach ($sejours as $_sejour) {
                 if (!$patient->code_regime) {
                     continue;
                 }
                 $_sejour->_receiver = $receiver;
                 $_sejour->loadLastLog();
                 $_sejour->loadRefPatient();
                 if (!$_sejour->_NDA) {
                     // Génération du NDA dans le cas de la création, ce dernier n'était pas créé
                     if ($msg = $_sejour->generateNDA()) {
                         CAppUI::setMsg($msg, UI_MSG_ERROR);
                     }
                     $NDA = new CIdSante400();
                     $NDA->loadLatestFor($_sejour, $receiver->_tag_sejour);
                     $sejour->_NDA = $NDA->id400;
                 }
                 if ($receiver->isMessageSupported("CHPrimXMLDebiteursVenue")) {
                     $this->sendEvenementPatient("CHPrimXMLDebiteursVenue", $_sejour);
                 }
             }
         }
         $patient->_IPP = null;
     }
     return true;
 }
Exemple #8
0
/**
 * $Id: $
 *
 * @package    Mediboard
 * @subpackage dPetablissement
 * @author     SARL OpenXtrem <*****@*****.**>
 * @license    GNU General Public License, see http://www.gnu.org/licenses/gpl.html
 * @version    $Revision: 18985 $
 */
CCanDo::checkRead();
// Récupération du groupe selectionné
$group_id = CValue::getOrSession("group_id");
// Fiche établissement
$etab = new CGroups();
$etab->load($group_id);
// Services d'hospitalisation
$service = new CService();
$service->group_id = $etab->_id;
$service->cancelled = 0;
$service->externe = 0;
/** @var CService[] $services */
$services = $service->loadMatchingList("nom");
foreach ($services as $_service) {
    $_service->loadRefsChambres(false);
    foreach ($_service->_ref_chambres as $_chambre) {
        $_chambre->loadRefsLits(false);
    }
}
// Blocs opératoires
$bloc = new CBlocOperatoire();
 /**
  * Trigger after event store
  *
  * @param CMbObject $mbObject Object
  *
  * @throws CMbException
  *
  * @return bool
  */
 function onAfterStore(CMbObject $mbObject)
 {
     if (!$this->isHandled($mbObject)) {
         return false;
     }
     $receiver = $mbObject->_receiver;
     // Traitement Sejour
     if ($mbObject instanceof CSejour) {
         $sejour = $mbObject;
         $sejour->loadRefPraticien();
         $sejour->loadNDA();
         $sejour->loadLastLog();
         $sejour->loadRefPatient();
         $sejour->loadRefAdresseParPraticien();
         // Si Serveur
         if (CAppUI::conf('smp server')) {
             $echange_hprim = new CEchangeHprim();
             if (isset($sejour->_eai_exchange_initiator_id)) {
                 $echange_hprim->load($sejour->_eai_exchange_initiator_id);
             }
             $initiateur = $receiver->_id == $echange_hprim->sender_id ? $echange_hprim->_id : null;
             $group = new CGroups();
             $group->load($receiver->group_id);
             $group->loadConfigValues();
             $mbObject->_id400 = null;
             $idexPatient = new CIdSante400();
             $idexPatient->loadLatestFor($sejour, $receiver->_tag_sejour);
             $mbObject->_id400 = $idexPatient->id400;
             $this->generateTypeEvenement("CHPrimXMLVenuePatient", $sejour, true, $initiateur);
         } else {
             if (!$receiver->isMessageSupported("CHPrimXMLVenuePatient")) {
                 return false;
             }
             if (CGroups::loadCurrent()->_id != $receiver->group_id) {
                 return false;
             }
             if (!$sejour->_NDA) {
                 // Génération du NDA dans le cas de la création, ce dernier n'était pas créé
                 if ($msg = $sejour->generateNDA()) {
                     CAppUI::setMsg($msg, UI_MSG_ERROR);
                 }
                 $NDA = new CIdSante400();
                 $NDA->loadLatestFor($sejour, $receiver->_tag_sejour);
                 $sejour->_NDA = $NDA->id400;
             }
             if (!$sejour->_ref_patient->_IPP) {
                 $IPP = new CIdSante400();
                 //Paramétrage de l'id 400
                 $IPP->loadLatestFor($sejour->_ref_patient, $receiver->_tag_patient);
                 $sejour->_ref_patient->_IPP = $IPP->id400;
             }
             $this->sendEvenementPatient("CHPrimXMLVenuePatient", $sejour);
             if ($receiver->isMessageSupported("CHPrimXMLDebiteursVenue") && $sejour->_ref_patient->code_regime) {
                 $this->sendEvenementPatient("CHPrimXMLDebiteursVenue", $sejour);
             }
             if ($receiver->isMessageSupported("CHPrimXMLMouvementPatient") && $sejour->_ref_last_log->type == "create") {
                 $affectation = $sejour->loadRefFirstAffectation();
                 // $this->sendEvenementPatient("CHPrimXMLMouvementPatient", $affectation);
             }
             $sejour->_NDA = null;
         }
         return true;
     } elseif ($mbObject instanceof CAffectation) {
         $affectation = $mbObject;
         $current_log = $affectation->_ref_current_log;
         if (!$current_log || $affectation->_no_synchro || !in_array($current_log->type, array("create", "store"))) {
             return false;
         }
         // Cas où :
         // * on est l'initiateur du message
         // * le destinataire ne supporte pas le message
         if (!$receiver->isMessageSupported("CHPrimXMLMouvementPatient")) {
             return false;
         }
         // Affectation non liée à un séjour
         $sejour = $affectation->loadRefSejour();
         if (!$sejour->_id) {
             return false;
         }
         $sejour->loadRefPatient();
         $sejour->_receiver = $receiver;
         // Envoi de l'événement
         $this->sendEvenementPatient("CHPrimXMLMouvementPatient", $affectation);
     }
     return true;
 }
Exemple #10
0
<?php

/**
 * $Id$
 *
 * @package    Mediboard
 * @subpackage dPetablissement
 * @author     SARL OpenXtrem <*****@*****.**>
 * @license    GNU General Public License, see http://www.gnu.org/licenses/gpl.html
 * @version    $Revision$
 */
CCanDo::checkRead();
// Récupération du groupe selectionné
$group = new CGroups();
$group->load(CValue::getOrSession("group_id"));
if ($group && $group->_id) {
    $group->loadFunctions();
    $group->loadRefsNotes();
    $group->loadRefLegalEntity();
}
$legal_entity = new CLegalEntity();
$legal_entities = $legal_entity->loadList();
// Création du template
$smarty = new CSmartyDP();
$smarty->assign("group", $group);
$smarty->assign("legal_entities", $legal_entities);
$smarty->display("inc_vw_groups.tpl");
 /**
  * Charge tous les modèles pour une classe d'objets associés à un utilisateur
  *
  * @param integer $id           Identifiant du propriétaire
  * @param string  $owner        Type de propriétaire du modèle: prat, func ou etab
  * @param string  $object_class Nom de la classe d'objet, optionnel. Doit être un CMbObject
  * @param string  $type         Type de composant, optionnel
  * @param bool    $fast_edit    Inclue les modèles en édition rapide
  * @param string  $order        Ordre de tri de la liste
  *
  * @return CCompteRendu[][] Par propriétaire: prat => CCompteRendu[], func => CCompteRendu[], etab => CCompteRendu[]
  */
 static function loadAllModelesFor($id, $owner = 'prat', $object_class = null, $type = null, $fast_edit = true, $order = "")
 {
     // Accès aux modèles de la fonction et de l'établissement
     $module = CModule::getActive("dPcompteRendu");
     $is_admin = $module && $module->canAdmin();
     $access_function = $is_admin || CAppUI::conf("compteRendu CCompteRendu access_function");
     $access_group = $is_admin || CAppUI::conf("compteRendu CCompteRendu access_group");
     $modeles = array();
     $modeles["prat"] = array();
     if ($access_function) {
         $modeles["func"] = array();
     }
     if ($access_group) {
         $modeles["etab"] = array();
     }
     if (!$id) {
         return $modeles;
     }
     // Clauses de recherche
     $modele = new CCompteRendu();
     $where = array();
     $where["object_id"] = "IS NULL";
     if ($object_class) {
         $where["object_class"] = "= '{$object_class}'";
     }
     if ($type) {
         $where["type"] = "= '{$type}'";
     }
     if (!$fast_edit) {
         $where["fast_edit"] = " = '0'";
         $where["fast_edit_pdf"] = " = '0'";
     }
     if (!$order) {
         $order = "object_class, type, nom";
     }
     switch ($owner) {
         case 'prat':
             // Modèle du praticien
             $prat = new CMediusers();
             if (!$prat->load($id)) {
                 return $modeles;
             }
             $prat->loadRefFunction();
             $where["user_id"] = "= '{$prat->_id}'";
             $where["function_id"] = "IS NULL";
             $where["group_id"] = "IS NULL";
             $modeles["prat"] = $modele->loadListWithPerms(PERM_READ, $where, $order);
             $sec_func = $prat->loadRefsSecondaryFunctions();
             foreach ($sec_func as $_func) {
                 $where["user_id"] = "IS NULL";
                 $where["function_id"] = "= '{$_func->_id}'";
                 $where["group_id"] = "IS NULL";
                 $modeles["func" . $_func->_id] = $modele->loadListWithPerms(PERM_READ, $where, $order);
             }
         case 'func':
             // Modèle de la fonction
             if (isset($modeles["func"])) {
                 if (isset($prat)) {
                     $func_id = $prat->function_id;
                 } else {
                     $func = new CFunctions();
                     if (!$func->load($id)) {
                         return $modeles;
                     }
                     $func_id = $func->_id;
                 }
                 $where["user_id"] = "IS NULL";
                 $where["function_id"] = "= '{$func_id}'";
                 $where["group_id"] = "IS NULL";
                 $modeles["func"] = $modele->loadListWithPerms(PERM_READ, $where, $order);
             }
         case 'etab':
             // Modèle de l'établissement
             if (isset($modeles["etab"])) {
                 $etab_id = CGroups::loadCurrent()->_id;
                 if ($owner == 'etab') {
                     $etab = new CGroups();
                     if (!$etab->load($id)) {
                         return $modeles;
                     }
                     $etab_id = $etab->_id;
                 } elseif (isset($func)) {
                     $etab_id = $func->group_id;
                 } elseif (isset($func_id)) {
                     $func = new CFunctions();
                     $func->load($func_id);
                     $etab_id = $func->group_id;
                 }
                 $where["user_id"] = "IS NULL";
                 $where["function_id"] = "IS NULL";
                 $where["group_id"] = " = '{$etab_id}'";
                 $modeles["etab"] = $modele->loadListWithPerms(PERM_READ, $where, $order);
             }
             break;
         default:
             trigger_error("Wrong type '{$owner}'", E_WARNING);
     }
     return $modeles;
 }
 /**
  * Charge les packs pour un propriétaire donné
  * 
  * @param int    $id           identifiant du propriétaire
  * @param string $owner        [optional]
  * @param string $object_class [optional]
  * 
  * @todo: refactor this to be in a super class
  * 
  * @return array
  */
 static function loadAllPacksFor($id, $owner = 'user', $object_class = null)
 {
     // Accès aux packs de modèles de la fonction et de l'établissement
     $module = CModule::getActive("dPcompteRendu");
     $is_admin = $module && $module->canAdmin();
     $access_function = $is_admin || CAppUI::conf("compteRendu CCompteRendu access_function");
     $access_group = $is_admin || CAppUI::conf("compteRendu CCompteRendu access_group");
     $packs = array();
     $packs["prat"] = array();
     if ($access_function) {
         $packs["func"] = array();
     }
     if ($access_group) {
         $packs["etab"] = array();
     }
     // Clauses de recherche
     $pack = new CPack();
     $where = array();
     if ($object_class) {
         $where["object_class"] = "= '{$object_class}'";
     }
     $order = "object_class, nom";
     switch ($owner) {
         case 'prat':
             // Modèle du praticien
             $user = new CMediusers();
             if (!$user->load($id)) {
                 return $packs;
             }
             $user->loadRefFunction();
             $where["user_id"] = "= '{$user->_id}'";
             $where["function_id"] = "IS NULL";
             $where["group_id"] = "IS NULL";
             $packs["prat"] = $pack->loadlist($where, $order);
         case 'func':
             // Modèle de la fonction
             if (isset($packs["func"])) {
                 if (isset($user)) {
                     $func_id = $user->function_id;
                 } else {
                     $func = new CFunctions();
                     if (!$func->load($id)) {
                         return $packs;
                     }
                     $func_id = $func->_id;
                 }
                 $where["user_id"] = "IS NULL";
                 $where["function_id"] = "= '{$func_id}'";
                 $where["group_id"] = "IS NULL";
                 $packs["func"] = $pack->loadlist($where, $order);
             }
         case 'etab':
             // Modèle de l'établissement
             if (isset($packs["etab"])) {
                 $etab_id = CGroups::loadCurrent()->_id;
                 if ($owner == 'etab') {
                     $etab = new CGroups();
                     if (!$etab->load($id)) {
                         return $packs;
                     }
                     $etab_id = $etab->_id;
                 } else {
                     if (isset($func)) {
                         $etab_id = $func->group_id;
                     } else {
                         if (isset($func_id)) {
                             $func = new CFunctions();
                             $func->load($func_id);
                             $etab_id = $func->group_id;
                         }
                     }
                 }
                 $where["user_id"] = "IS NULL";
                 $where["function_id"] = "IS NULL";
                 $where["group_id"] = " = '{$etab_id}'";
                 $packs["etab"] = $pack->loadlist($where, $order);
             }
             break;
         default:
             trigger_error("Wrong type '{$owner}'", E_WARNING);
     }
     return $packs;
 }
 /**
  * Recording IPP
  * 
  * @param CIdSante400    $IPP     Object id400
  * @param CPatient       $patient Patient
  * @param CInteropSender $sender  Sender
  * 
  * @return null|string null if successful otherwise returns and error message
  */
 static function storeIPP(CIdSante400 $IPP, CPatient $patient, CInteropSender $sender)
 {
     /* Gestion du numéroteur */
     $group = new CGroups();
     $group->load($sender->group_id);
     $group->loadConfigValues();
     // Purge de l'IPP existant sur le patient et on le remplace par le nouveau
     if ($sender->_configs && $sender->_configs["purge_idex_movements"]) {
         // On charge l'IPP courant du patient
         $patient->loadIPP($sender->group_id);
         $ref_IPP = $patient->_ref_IPP;
         if ($ref_IPP) {
             // Si l'IPP actuel est identique à celui qu'on reçoit on ne fait rien
             if ($ref_IPP->id400 == $IPP->id400) {
                 return;
             }
             // On passe l'IPP courant en trash
             $ref_IPP->tag = CAppUI::conf("dPpatients CPatient tag_ipp_trash") . $ref_IPP->tag;
             $ref_IPP->_eai_sender_guid = $sender->_guid;
             $ref_IPP->store();
             $patient->trashIPP($ref_IPP);
         }
         // On sauvegarde le nouveau
         $IPP->tag = $sender->_tag_patient;
         $IPP->object_class = "CPatient";
         $IPP->object_id = $patient->_id;
         $IPP->last_update = CMbDT::dateTime();
         $IPP->_eai_sender_guid = $sender->_guid;
         return $IPP->store();
     }
     // Génération de l'IPP ?
     /* @todo sip_idex_generator doit être remplacé par isIPPSupplier */
     if ($sender->_configs && !$group->_configs["sip_idex_generator"]) {
         if (!$IPP->id400) {
             return null;
         }
         if ($patient) {
             $IPP->object_id = $patient->_id;
         }
         $IPP->last_update = CMbDT::dateTime();
         $IPP->_eai_sender_guid = $sender->_guid;
         return $IPP->store();
     } else {
         $IPP_temp = CIdSante400::getMatch("CPatient", $sender->_tag_patient, null, $patient->_id);
         // Pas d'IPP passé
         if (!$IPP->id400) {
             if ($IPP_temp->_id) {
                 return null;
             }
             if (!CIncrementer::generateIdex($patient, $sender->_tag_patient, $sender->group_id)) {
                 return CAppUI::tr("CEAIPatient-error-generate-idex");
             }
             return null;
         } else {
             // Si j'ai déjà un identifiant
             if ($IPP_temp->_id) {
                 // On passe l'IPP courant en trash
                 $IPP_temp->tag = CAppUI::conf("dPpatients CPatient tag_ipp_trash") . $IPP_temp->tag;
                 $IPP_temp->_eai_sender_guid = $sender->_guid;
                 $IPP_temp->store();
             }
             $incrementer = $sender->loadRefGroup()->loadDomainSupplier("CPatient");
             if ($incrementer && $IPP->id400 < $incrementer->range_min || $IPP->id400 > $incrementer->range_max) {
                 return CAppUI::tr("CEAIPatient-idex-not-in-the-range");
             }
             $IPP->object_id = $patient->_id;
             $IPP->last_update = CMbDT::dateTime();
             $IPP->_eai_sender_guid = $sender->_guid;
             return $IPP->store();
         }
     }
 }