/** * Charge les hiérarchies CsARR filles * * @return self[] */ function loadRefsChildHierarchies() { $where["code"] = "LIKE '{$this->code}.__'"; $hierarchie = new self(); $hierarchies = $hierarchie->loadList($where); return $this->_ref_child_hierarchies = $hierarchies; }
/** * Charge les prestations journalières de l'établissement * pour un éventuel type d'hospitalisation donné * * @param string $type Type d'hospitalisation * * @return self[] */ static function loadCurrentList($type = null) { $prestation = new self(); $where = array("group_id" => "= '" . CGroups::loadCurrent()->_id . "'"); if ($type) { $where[] = "type_hospi IS NULL OR type_hospi = '{$type}'"; } return $prestation->loadList($where, "nom"); }
/** * Load user preferences as an associative array * * @param null $user_id The user to load the preferences from * * @return array */ static function get($user_id = null, $restricted = false) { $where["user_id"] = "IS NULL"; if ($user_id) { $where["user_id"] = "= '{$user_id}'"; $where["value"] = "IS NOT NULL"; } if ($restricted) { $where["restricted"] = "= '1'"; } $preferences = array(); $pref = new self(); /** @var self[] $list */ $list = $pref->loadList($where); foreach ($list as $_pref) { $preferences[$_pref->key] = $_pref->value; } return $preferences; }
static function loadAllFor($libelles) { $libelles = array_map("strtoupper", $libelles); // Initialisation du tableau $colors_by_libelle = array(); foreach ($libelles as $_libelle) { $color = new self(); $color->libelle = $_libelle; $colors_by_libelle[$_libelle] = $color; } $color = new self(); $where = array(); $libelles = array_map("addslashes", $libelles); $where["libelle"] = CSQLDataSource::prepareIn($libelles); foreach ($color->loadList($where) as $_color) { $colors_by_libelle[$_color->libelle] = $_color; } return $colors_by_libelle; }
/** * Load unread messages * * @param null $user_id user to load, null = current * * @return CUserMessageDest[] */ static function loadNewMessages($user_id = null) { $dests = array(); if (CModule::getActive("messagerie")) { $dest = new self(); if ($dest->_ref_module->mod_version < 0.3) { CAppUI::stepAjax("CModule%s-msg-pls_update_module", UI_MSG_WARNING, $dest->_ref_module->mod_name); return $dests; } $user = CMediusers::get($user_id); $where = array(); $where["to_user_id"] = " = '{$user->_id}'"; $where["datetime_sent"] = " IS NOT NULL"; $where["datetime_read"] = " IS NULL"; /** @var CUserMessageDest[] $dests */ $dests = $dest->loadList($where); foreach ($dests as $_dest) { $_dest->loadRefFwd(); } } return $dests; }
/** * Get list types tree * * @return array */ static function getListTypesTree() { $object = new self(); $group_id = CGroups::loadCurrent()->_id; $targets = array(); $by_type = array(); foreach ($object->_specs["type"]->_locales as $type => $trad) { if ($type != "intervention") { /** @var CSalle|CBlocOperatoire $_object */ $_object = $type == "ouverture_salle" || $type == "fermeture_salle" ? new CSalle() : new CBlocOperatoire(); $_targets = $_object->loadGroupList(); array_unshift($_targets, $_object); $targets[$type] = array_combine(CMbArray::pluck($_targets, "_id"), $_targets); $where = array("type" => "= '{$type}'", "group_id" => "= '{$group_id}'", "check_list_group_id" => " IS NULL"); $by_type[$type] = $object->loadList($where, "title"); } } return array($targets, $by_type); }
/** * * * @param null|int $user_id * @param null|string $date_start * @param null|string $date_end * @param array $object_classes * * @return CBrisDeGlace[] $briss */ static function loadBrisForUser($user_id = null, $date_start = null, $date_end = null, $object_classes = array()) { $date_start = $date_start ? $date_start : CMbDT::date(); $date_end = $date_end ? $date_end : $date_start; $bris = new self(); $ds = $bris->getDS(); $where = array(); $where["date"] = " BETWEEN '{$date_start} 00:00:00' AND '{$date_end} 23:59:59' "; if (count($object_classes)) { $where["object_class"] = $ds->prepareIn($object_classes); } if ($user_id) { $where["user_id"] = " = '{$user_id}'"; } /** @var CBrisDeGlace[] $briss */ $briss = $bris->loadList($where, "date DESC"); return $briss; }
/** * Get categories tree * * @param bool $operation see operations * * @return array */ static function getCategoriesTree($operation = false) { $object = new self(); $target_classes = CDailyCheckList::getNonHASClasses($operation); $targets = array(); $by_class = array(); foreach ($target_classes as $_class) { if ($_class != "COperation") { /** @var CSalle|CBlocOperatoire $_object */ $_object = new $_class(); //$_targets = $_object->loadGroupList(); $_targets = $_object->loadList(); array_unshift($_targets, $_object); $targets[$_class] = array_combine(CMbArray::pluck($_targets, "_id"), $_targets); } $where = array("target_class" => "= '{$_class}'"); if ($_class == "COperation") { $where["list_type_id"] = ' IS NOT NULL'; } /** @var CDailyCheckItemCategory[] $_list */ $_list = $object->loadList($where, "target_id+0, title"); // target_id+0 to have NULL at the beginning $by_object = array(); foreach ($_list as $_category) { $_key = $_category->target_id ? $_category->target_id : "all"; $by_object[$_key][$_category->_id] = $_category; } $by_class[$_class] = $by_object; } return array($targets, $by_class); }
/** * Get all the instant data for an object * * @param CMbObject $object The object to get timed data of * * @return self[] */ static function getAllFor(CMbObject $object) { $graph = new self(); $where = array("owner_class" => "= '{$object->_class}'", "owner_id" => "= '{$object->_id}'"); return $graph->loadList($where, "title"); }
/** * Get all pakcs from an object * * @param CMbObject $object The object to get the packs of * @param bool $with_disabled List disabled items * * @return self[] */ static function getAllFor(CMbObject $object, $with_disabled = false) { $pack = new self(); $where = array("owner_class" => "= '{$object->_class}'", "owner_id" => "= '{$object->_id}'"); if (!$with_disabled) { $where["disabled"] = "= '0'"; } return $pack->loadList($where, "title"); }
/** * Get events for an object * * @param CMbObject|string $object Object or GUID * @param string $event_name Event name * @param string $type Type: required, disabled or conditional * @param array $exclude_ex_class_event_ids List of class events' ids * * @return CExClassEvent[] */ static function getForObject($object, $event_name, $type = "required", $exclude_ex_class_event_ids = array()) { static $events_cache = array(); if (is_string($object)) { $object = CMbObject::loadFromGuid($object); } if ($type == "required" && !CValue::read($object->_spec->events[$event_name], "auto", false)) { return array(); } $ex_class_event = new self(); $group_id = CGroups::loadCurrent()->_id; $ds = $ex_class_event->_spec->ds; $key = "{$object->_class}/{$event_name}/{$group_id}/{$type}"; if (isset($events_cache[$key])) { $ex_class_events = $events_cache[$key]; } else { $where = array("ex_class_event.host_class" => $ds->prepare("=%", $object->_class), "ex_class_event.event_name" => $ds->prepare("=%", $event_name), "ex_class_event.disabled" => $ds->prepare("=%", 0), "ex_class.conditional" => $ds->prepare("=%", 0), $ds->prepare("ex_class.group_id = % OR group_id IS NULL", $group_id)); $ljoin = array("ex_class" => "ex_class.ex_class_id = ex_class_event.ex_class_id"); switch ($type) { case "disabled": $where["ex_class_event.disabled"] = 1; break; case "conditional": $where["ex_class.conditional"] = 1; break; } /** @var CExClassEvent[] $ex_class_events */ $ex_class_events = $ex_class_event->loadList($where, null, null, null, $ljoin); $events_cache[$key] = $ex_class_events; } foreach ($ex_class_events as $_id => $_ex_class_event) { if (isset($exclude_ex_class_event_ids[$_id]) || !$_ex_class_event->checkConstraints($object)) { unset($ex_class_events[$_id]); } else { $_ex_class_event->_host_object = $object; } } return $ex_class_events; }
/** * Charge les médecins identiques * * @param bool $strict_cp Stricte sur la recherche par code postal * * @return self[] */ function loadExactSiblings($strict_cp = true) { $medecin = new self(); $where = array(); $where["nom"] = $this->_spec->ds->prepare(" = %", $this->nom); $where["prenom"] = $this->_spec->ds->prepare(" = %", $this->prenom); if (!$strict_cp) { $cp = substr($this->cp, 0, 2); $where["cp"] = " LIKE '{$cp}___'"; } else { $where["cp"] = " = '{$this->cp}'"; } $medecin->escapeValues(); $siblings = $medecin->loadList($where); unset($siblings[$this->_id]); return $siblings; }
/** * Find all therapeutes for a patient * * @param ref $patient_id Patient * @param ref $function_id May restrict to a function * * @return CMediusers[] */ static function getAllTherapeutes($patient_id, $function_id = null) { // Filter on patient $join["sejour"] = "sejour.sejour_id = evenement_ssr.sejour_id"; $where["patient_id"] = "= '{$patient_id}'"; // Filter on function if ($function_id) { $join["users_mediboard"] = "users_mediboard.user_id = evenement_ssr.therapeute_id"; $where["function_id"] = "= '{$function_id}'"; } // Load grouped $group = "therapeute_id"; $evenement = new self(); $evenements = $evenement->loadList($where, null, null, $group, $join); // Load therapeutes $therapeutes = CMbObject::massLoadFwdRef($evenements, "therapeute_id"); foreach ($therapeutes as $_therapeute) { $_therapeute->loadRefFunction(); } return $therapeutes; }
/** * @param string $object_class * @param CTag $parent * @param array $tree * * @return array */ static function getTree($object_class, CTag $parent = null, &$tree = array()) { $tag = new self(); $where = array("object_class" => "= '{$object_class}'", "parent_id" => $parent && $parent->_id ? "= '{$parent->_id}'" : "IS NULL"); $tree["parent"] = $parent; $tree["children"] = array(); /** @var self[] $tags */ $tags = $tag->loadList($where, "name"); foreach ($tags as $_tag) { $_tag->getDeepness(); self::getTree($object_class, $_tag, $sub_tree); $tree["children"][] = $sub_tree; } return $tree; }
/** * Upgrade all modules * * @return void */ static function upgradeAll() { $module = new self(); /** @var self[] $installed */ $installed = $module->loadList(); $upgradeables = array(); foreach ($installed as $_module) { $setupClass = "CSetup{$_module->mod_name}"; if (!class_exists($setupClass)) { continue; } /** @var CSetup $setup */ $setup = new $setupClass(); $_module->compareToSetup($setup); if ($_module->_upgradable) { $upgradeables[$_module->mod_name] = array("module" => $_module, "setup" => $setup); } } foreach ($upgradeables as $_upgrade) { /** @var CModule $_module */ $_module = $_upgrade["module"]; /** @var CSetup $_setup */ $_setup = $_upgrade["setup"]; if ($_module->mod_version = $_setup->upgrade($_module->mod_version)) { $_module->mod_type = $_setup->mod_type; $_module->store(); if ($_setup->mod_version == $_module->mod_version) { CAppUI::setMsg("Installation de '%s' à la version %s", UI_MSG_OK, $_module->mod_name, $_setup->mod_version); } else { CAppUI::setMsg("Installation de '{$_module->mod_name}' à la version {$_module->mod_version} sur {$_setup->mod_version}", UI_MSG_WARNING, true); } } else { CAppUI::setMsg("Module '%s' non mis à jour", UI_MSG_WARNING, $_module->mod_name); } } }
/** * Get a group's stock locations * * @param int $group_id Group ID * * @return CStoredObject[] */ static function getGroupStockLocations($group_id) { $where = "\r\n (product_stock_location.object_id = '{$group_id}' AND product_stock_location.object_class = 'CGroups') OR \r\n (service.group_id = '{$group_id}' AND product_stock_location.object_class = 'CService') OR \r\n (bloc_operatoire.group_id = '{$group_id}' AND product_stock_location.object_class = 'CBlocOperatoire')"; $ljoin = array("service" => "service.service_id = product_stock_location.object_id", "bloc_operatoire" => "bloc_operatoire.bloc_operatoire_id = product_stock_location.object_id"); $sl = new self(); return $sl->loadList($where, null, null, null, $ljoin); }
/** * Get suppliers * * @param bool $also_inactive Load also inactive ones * * @return CSociete[] */ static function getSuppliers($also_inactive = true) { $societe = new self(); $list = $societe->loadList(null, "name"); foreach ($list as $_id => $_societe) { if (!($_societe->_is_supplier || $also_inactive && !$_societe->_is_manufacturer)) { unset($list[$_id]); } } return $list; }
/** * Mass load mechanism for forward references of an object collection * * @param CMbObject[] $objects Array of objects * @param string $tag Tag * * @return self[] Loaded collection, null if unavailable, with ids as keys of guids for meta references */ static function massGetMatchFor($objects, $tag) { if (!count($objects)) { return array(); } $object = reset($objects); $idex = new self(); $where["object_class"] = " = '{$object->_class}'"; $where["tag"] = " = '{$tag}'"; $where["object_id"] = CSQLDataSource::prepareIn(CMbArray::pluck($objects, "_id")); $group = "object_id"; return $idex->loadList($where, null, null, $group); }
/** * Load groups with given permission * * @param int $permType Permission level * * @return self[] */ static function loadGroups($permType = PERM_READ) { $group = new self(); $groups = $group->loadList(null, "text"); self::filterByPerm($groups, $permType); return $groups; }
/** * Load all salutation from a given class * * @param string $object_class Target object class * @param integer|null $object_id Target object ID * @param int $perm Permission needed on owners * @param integer|null $owner_id Specific owner ID * * @return CSalutation[] */ static function loadAllSalutations($object_class, $object_id = null, $perm = PERM_EDIT, $owner_id = null) { if (!$owner_id) { $users = new CMediusers(); $users = $users->loadListWithPerms($perm, array('actif' => "= '1'")); $user_ids = $users ? CMbArray::pluck($users, '_id') : array(CMediusers::get()->_id); unset($users); } else { $user_ids = array($owner_id); } /** @var CSalutation $salutation */ $salutation = new self(); $ds = $salutation->_spec->ds; $where = array('owner_id' => $ds->prepareIn($user_ids), 'object_class' => $ds->prepare('= ?', $object_class)); if ($object_id) { $where['object_id'] = $ds->prepare('= ?', $object_id); } return $salutation->loadList($where); }
/** * Get chronological list * * @param COperation $interv Intervention * @param int $pack_id Pack ID * * @return CObservationResultSet[] */ static function getChronological(COperation $interv, $pack_id) { $result_set = new self(); $where = array("observation_result_set.context_class" => "= '{$interv->_class}'", "observation_result_set.context_id" => "= '{$interv->_id}'"); $order = array("observation_result_set.datetime", "observation_result_set.observation_result_set_id"); $pack = new CSupervisionGraphPack(); $pack->load($pack_id); $graph_links = $pack->loadRefsGraphLinks(); $list_by_datetime = array(); $graphs = self::massLoadFwdRef($graph_links, "graph_id"); /** @var self[] $list */ $list = $result_set->loadList($where, $order); $grid = array(); // Build the data structure $count = 0; $labels = array(); foreach ($graphs as $_graph) { if ($_graph instanceof CSupervisionGraph) { $_axes = $_graph->loadRefsAxes(); self::massCountBackRefs($_axes, "series"); foreach ($_axes as $_axis) { $_series = $_axis->loadRefsSeries(); $count += count($_series); foreach ($_series as $_serie) { $labels[] = $_serie; } } } elseif ($_graph instanceof CSupervisionTimedData || $_graph instanceof CSupervisionTimedPicture) { $count++; $labels[] = $_graph; } } self::massCountBackRefs($list, "observation_results"); // Fill the data structure foreach ($list as $_set) { $results = $_set->loadRefsResults(); self::massLoadFwdRef($results, "file_id"); foreach ($results as $_result) { $_result->loadRefFile(); $_result->loadRefValueUnit(); } $p = 0; $_row = array_fill(0, $count, null); foreach ($graphs as $_graph) { if ($_graph instanceof CSupervisionGraph) { $_axes = $_graph->_ref_axes; foreach ($_axes as $_axis) { $_series = $_axis->_ref_series; foreach ($_series as $_serie) { foreach ($results as $_result) { if ($_result->value_type_id == $_serie->value_type_id && $_result->unit_id == $_serie->value_unit_id) { $_row[$p] = $_result; } } $p++; } } } elseif ($_graph instanceof CSupervisionTimedData || $_graph instanceof CSupervisionTimedPicture) { foreach ($results as $_result) { if ($_result->value_type_id == $_graph->value_type_id && $_result->unit_id == null) { $_row[$p] = $_result; } } $p++; } } $grid[$_set->datetime] = $_row; $list_by_datetime[$_set->datetime] = $_set; } return array($list, $grid, $graphs, $labels, $list_by_datetime); }
/** * Get related constant values * * @param string[] $selection Constants selection * @param CPatient $patient Related patient * @param CMbObject $context Related context * @param null $date_min Minimal date * @param null $date_max Maximal date * @param null $limit Limit count * * @return self[] */ static function getRelated($selection, CPatient $patient, CMbObject $context = null, $date_min = null, $date_max = null, $limit = null) { $where = array("patient_id" => " = '{$patient->_id}'"); if ($context) { $where["context_class"] = " = '{$context->_class}'"; $where["context_id"] = " = '{$context->_id}'"; } $whereOr = array(); foreach ($selection as $name) { if ($name[0] === "_") { continue; } $whereOr[] = "`{$name}` IS NOT NULL"; } $where[] = implode(" OR ", $whereOr); if ($date_min) { $where[] = "datetime >= '{$date_min}'"; } if ($date_max) { $where[] = "datetime <= '{$date_max}'"; } $constantes = new self(); return array_reverse($constantes->loadList($where, "datetime DESC", $limit), true); }
/** * get the plage list between 2 days or for one day * * @param string $chir_id chir of plage * @param string $date_start date of start * @param string|null $date_end date of end (if null, check only for start) * * @return CPlageconsult[] */ function loadForDays($chir_id, $date_start, $date_end = null) { $plage = new self(); $where = array(); $chir = new CMediusers(); $chir->load($chir_id); $where["date"] = $date_end ? "BETWEEN '{$date_start}' AND '{$date_end}' " : " = '{$date_start}'"; $where[] = " chir_id = '{$chir_id}' OR remplacant_id = '{$chir_id}'"; return $plage->loadList($where, "debut ASC, fin ASC, chir_id"); }
/** * Chargement des droits du user * * @param int $user_id The user to load the perms of * * @return self[] */ static function loadExactPerms($user_id = null) { $perm = new self(); $where = array("user_id" => "= '{$user_id}'"); return $perm->loadList($where); }
/** * @param array $user_ids list of user's id * @param date $date date targeted * @return CPlageConge[] */ static function loadForIdsForDate($user_ids, $date) { $plage = new self(); $ds = $plage->getDS(); $where = array(); $where["user_id"] = $ds->prepareIn($user_ids); $where[] = " '{$date}' BETWEEN date_debut AND date_fin "; $plages = $plage->loadList($where); return $plages; }
/** * Récupération des salles activers pour les stats * * @param int $salle_id Limitation du retour à une seule salle * @param int $bloc_id Limitation du retour à un seul bloc * * @return self[] */ static function getSallesStats($salle_id = null, $bloc_id = null) { $group_id = CGroups::loadCurrent()->_id; $where = array(); $where['stats'] = " = '1'"; $ljoin = array(); if ($salle_id) { $where['salle_id'] = " = '{$salle_id}'"; } elseif ($bloc_id) { $where['bloc_id'] = "= '{$bloc_id}'"; } else { $where['bloc_operatoire.group_id'] = "= '{$group_id}'"; $ljoin['bloc_operatoire'] = 'bloc_operatoire.bloc_operatoire_id = sallesbloc.bloc_id'; } $salle = new self(); return $salle->loadList($where, null, null, null, $ljoin); }
/** * Chargement des types d'ufs * * @param string $object_class classe concernée * * @return array() */ static function getUFs($object_class = null) { $uf = new self(); $group_id = CGroups::loadCurrent()->_id; $tab_ufs = array("hebergement" => $uf->loadList(array("type" => "= 'hebergement'", "group_id" => "= '{$group_id}'"), "libelle"), "medicale" => $uf->loadList(array("type" => "= 'medicale'", "group_id" => "= '{$group_id}'"), "libelle"), "soins" => $uf->loadList(array("type" => "= 'soins'", "group_id" => "= '{$group_id}'"), "libelle")); if ($object_class == "CChambre" || $object_class == "C**t") { unset($tab_ufs["medicale"]); unset($tab_ufs["soins"]); } elseif ($object_class == "CService") { unset($tab_ufs["medicale"]); } elseif ($object_class == "CMediusers" || $object_class == "CFunctions") { unset($tab_ufs["hebergement"]); unset($tab_ufs["soins"]); } return $tab_ufs; }
/** * load catalogues with same identifier * * @return self[] */ function getSiblings() { $examen = new self(); $where = array(); $where["identifiant"] = "= '{$this->identifiant}'"; $where["examen_labo_id"] = "!= '{$this->examen_labo_id}'"; return $this->_ref_siblings = $examen->loadList($where); }
/** * load the list of access for a sejour * * @param $sejour * @param $page * * @return CLogAccessMedicalData[] */ static function loadListForSejour($sejour, $page = 0, $step = 50) { $log = new self(); $where = array(); $where["object_class"] = " = '{$sejour->_class}'"; $where["object_id"] = " = '{$sejour->_id}' "; $logs = $log->loadList($where, "datetime DESC", "{$page}, {$step}"); return $logs; }