/**
  * @see parent::getPerm()
  */
 function getPerm($perm_type)
 {
     if ($this->function_id && !$this->pere_id) {
         $this->loadRefFunction();
         return $this->_ref_function->getPerm($perm_type);
     } elseif ($this->pere_id) {
         $this->loadParent();
         return $this->_ref_pere->getPerm($perm_type);
     }
     return true;
 }
 /**
  * Load complete catalogue classification
  */
 function loadClassification()
 {
     $this->loadCatalogue();
     $catalogue = $this->_ref_catalogue_labo;
     $catalogues = array();
     $catalogues[$catalogue->_id] = $catalogue;
     while ($parent_id = $catalogue->pere_id) {
         $catalogue = new CCatalogueLabo();
         $catalogue->load($parent_id);
         $catalogues[$catalogue->_id] = $catalogue;
     }
     $level = count($catalogues);
     foreach ($catalogues as &$catalogue) {
         $catalogue->_level = --$level;
     }
     $this->_ref_catalogues = array_reverse($catalogues, true);
 }
Example #3
0
<?php

/**
 * $Id: add_pack_exams.php 19285 2013-05-26 13:10:13Z phenxdesign $
 *
 * @package    Mediboard
 * @subpackage Labo
 * @author     SARL OpenXtrem <*****@*****.**>
 * @license    GNU General Public License, see http://www.gnu.org/licenses/gpl.html
 * @version    $Revision: 19285 $
 */
CCanDo::checkRead();
//Chargement de tous les catalogues
$catalogue = new CCatalogueLabo();
$where = array("pere_id" => "IS NULL");
$order = "identifiant";
$listCatalogues = $catalogue->loadList($where, $order);
foreach ($listCatalogues as $key => $curr_catalogue) {
    $listCatalogues[$key]->loadRefsDeep();
}
// Création du template
$smarty = new CSmartyDP();
$smarty->assign("listCatalogues", $listCatalogues);
$smarty->display("add_packs_exams.tpl");
CCanDo::checkRead();
// Fonction de l'utilisateur courant
$user = CMediusers::get();
$function_id = $user->function_id;
// Liste des fonctions disponibles
$functions = new CFunctions();
$order = "text";
$functions = $functions->loadListWithPerms(PERM_EDIT, null, $order);
// Chargement du catalogue demandé
$catalogue = new CCatalogueLabo();
$catalogue->load(CValue::getOrSession("catalogue_labo_id"));
if ($catalogue->_id && $catalogue->getPerm(PERM_EDIT)) {
    $catalogue->loadRefs();
    $function_id = $catalogue->function_id;
} else {
    $catalogue = new CCatalogueLabo();
}
// Chargement de tous les catalogues
$where = array();
$where["pere_id"] = "IS NULL";
$where[] = "function_id IS NULL OR function_id " . CSQLDataSource::prepareIn(array_keys($functions));
$order = "identifiant";
$listCatalogues = $catalogue->loadList($where, $order);
foreach ($listCatalogues as &$_catalogue) {
    $_catalogue->loadRefsDeep();
}
// Création du template
$smarty = new CSmartyDP();
$smarty->assign("canSante400", CModule::getCanDo("dPsante400"));
$smarty->assign("listCatalogues", $listCatalogues);
$smarty->assign("catalogue", $catalogue);
/**
 * Catalogue import
 */
function importCatalogue($cat, $parent_id = null)
{
    global $remote_name;
    CApp::setTimeLimit(180);
    // On rend toutes les analyses du catalogue obsoletes
    $idAnalyse = new CIdSante400();
    $idAnalyse->tag = $remote_name;
    $idAnalyse->object_class = "CExamenLabo";
    $idAnalyses = $idAnalyse->loadMatchingList();
    foreach ($idAnalyses as $_id_analyse) {
        $examenLabo = new CExamenLabo();
        $examenLabo->identifiant = $_id_analyse->id400;
        $examenLabo->loadMatchingObject();
        if ($examenLabo->_id) {
            $examenLabo->obsolete = 1;
            $examenLabo->store();
        }
    }
    $idCatalogue = new CIdSante400();
    $idCatalogue->tag = $remote_name;
    $idCatalogue->object_class = "CCatalogueLabo";
    $idCatalogues = $idCatalogue->loadMatchingList();
    foreach ($idCatalogues as $_id_catalogue) {
        $catalogueLabo = new CCatalogueLabo();
        $catalogueLabo->identifiant = $_id_catalogue->id400;
        $catalogueLabo->loadMatchingObject();
        if ($catalogueLabo->_id) {
            $catalogueLabo->obsolete = 1;
            $catalogueLabo->store();
        }
    }
    $compteur["analyses"] = 0;
    $compteur["chapitres"] = 0;
    $compteur["sousChapitre"] = 0;
    $catalogues = array();
    // Creation du catalogue global LABO
    $catal = new CCatalogueLabo();
    $catalogue = new CCatalogueLabo();
    $catal->identifiant = substr(hash('md5', $remote_name), 0, 4);
    // libelle modifié par hash
    $catal->libelle = $remote_name;
    $catal->pere_id = $parent_id;
    // creation de son id400
    $idCat = new CIdSante400();
    $idCat->tag = $remote_name;
    $idCat->id400 = $remote_name;
    $catal->obsolete = 0;
    $idCat->bindObject($catal);
    //CAppUI::stepAjax("Catalogue '$catal->libelle' importé", UI_MSG_OK);
    $path = $remote_name;
    // on met a jour $catalogues
    $catalogues[$path] = $catal;
    //Parcours des analyses
    foreach ($cat->analyse as $_analyse) {
        $chapitre = (string) $_analyse->chapitre;
        $path = "{$remote_name}/{$chapitre}/";
        if (!$chapitre) {
            $path = $remote_name;
        }
        $catChapitre = new CCatalogueLabo();
        // si le catalogue n'existe pas deja
        if (!array_key_exists($path, $catalogues)) {
            // creation du catalogue
            $catChapitre->identifiant = substr(hash('md5', $chapitre), 0, 4);
            // libelle modifié par hash;
            $catChapitre->libelle = $chapitre;
            $catChapitre->pere_id = $catal->_id;
            $catChapitre->decodeUtfStrings();
            //creation de l'id400
            $idCatChapitre = new CIdSante400();
            $idCatChapitre->tag = $remote_name;
            $idCatChapitre->id400 = substr(hash('md5', $chapitre), 0, 4);
            $catChapitre->obsolete = 0;
            $idCatChapitre->bindObject($catChapitre);
            //CAppUI::stepAjax("Catalogue '$catChapitre->libelle' importé", UI_MSG_OK);
            $compteur["chapitres"]++;
            // on met a jour $catalogues
            $catalogues[$path] = $catChapitre;
        }
        $catChapitre = $catalogues[$path];
        $catalogue = $catChapitre;
        // si il y a un sous chapitre a creer==> le pere du sous chapitre est $catalogue->_id;
        $sschapitre = (string) $_analyse->sschapitre;
        if ($sschapitre) {
            // modification du path
            $path .= $sschapitre;
            $catssChapitre = new CCatalogueLabo();
            if (!array_key_exists($path, $catalogues)) {
                // creation du catalogue
                $catssChapitre->identifiant = substr(hash('md5', $sschapitre), 0, 4);
                // libelle modifié par hash;
                $catssChapitre->libelle = $sschapitre;
                $catssChapitre->pere_id = $catChapitre->_id;
                $catssChapitre->decodeUtfStrings();
                //creation de l'id400
                $idCatssChapitre = new CIdSante400();
                $idCatssChapitre->tag = $remote_name;
                $idCatssChapitre->id400 = substr(hash('md5', $sschapitre), 0, 4);
                $catssChapitre->obsolete = 0;
                $idCatssChapitre->bindObject($catssChapitre);
                //CAppUI::stepAjax("Sous Catalogue '$catssChapitre->libelle' importé", UI_MSG_OK);
                $compteur["sousChapitre"]++;
                //on met à jour les catalogues
                $catalogues[$path] = $catssChapitre;
            }
            $catssChapitre = $catalogues[$path];
            $catalogue = $catssChapitre;
        }
        // Code de l'analyse
        $catAtt = $_analyse->attributes();
        $code = $catAtt["code"];
        $idAnalyse = new CIdSante400();
        $idAnalyse->tag = $remote_name;
        $idAnalyse->id400 = (string) $code;
        $analyse = new CExamenLabo();
        $analyse->identifiant = (string) $code;
        $analyse->libelle = (string) $_analyse->libelle;
        $analyse->decodeUtfStrings();
        $analyse->technique = (string) $_analyse->technique;
        $analyse->duree_execution = (string) $_analyse->delaitechnique;
        $materiel = utf8_decode((string) $_analyse->materiel);
        $materiel = trim($materiel);
        switch ($materiel) {
            case "SANG VEINEUX":
                $analyse->type_prelevement = "sang";
                break;
            case "URINE":
                $analyse->type_prelevement = "urine";
                break;
            case "BIOPSIE":
                $analyse->type_prelevement = "biopsie";
                break;
        }
        //$analyse->applicabilite = (string) $_analyse->applicablesexe;
        $analyse->execution_lun = (string) $_analyse->joursrealisation->lundi;
        $analyse->execution_mar = (string) $_analyse->joursrealisation->mardi;
        $analyse->execution_mer = (string) $_analyse->joursrealisation->mercredi;
        $analyse->execution_jeu = (string) $_analyse->joursrealisation->jeudi;
        $analyse->execution_ven = (string) $_analyse->joursrealisation->vendredi;
        $analyse->execution_sam = (string) $_analyse->joursrealisation->samedi;
        $analyse->execution_dim = (string) $_analyse->joursrealisation->dimanche;
        $analyse->catalogue_labo_id = $catalogue->_id;
        $analyse->type = "num";
        $analyse->obsolete = 0;
        $idAnalyse->bindObject($analyse);
        //CAppUI::stepAjax("Analyse '$analyse->identifiant' importée", UI_MSG_OK);
        $compteur["analyses"]++;
    }
    // fin du foreach
    CAppUI::stepAjax("Analyses Importées: " . $compteur["analyses"] . ", Chapitres Importés: " . $compteur["chapitres"] . ", Sous chapitres Importés: " . $compteur["sousChapitre"], UI_MSG_OK);
}
    $examen_labo_id = null;
    CValue::setSession("examen_labo_id");
}
if ($examen_labo_id) {
    $examen->load($examen_labo_id);
    $examen->loadRefs();
    $examen->getSiblings();
    $examen->getRootCatalogue();
    foreach ($examen->_ref_siblings as &$_sibling) {
        $_sibling->loadClassification();
    }
    $examen->loadClassification();
    $catalogue =& $examen->_ref_catalogue_labo;
} else {
    $catalogue_labo_id = CValue::getOrSession("catalogue_labo_id");
    $catalogue = new CCatalogueLabo();
    $catalogue->load($catalogue_labo_id);
    $examen->catalogue_labo_id = $catalogue->_id;
}
$catalogue->loadRefs();
$groups = CGroups::loadGroups();
foreach ($groups as &$group) {
    $group->loadFunctions(null);
    foreach ($group->_ref_functions as $keyFunc => &$function) {
        if ($function->getPerm(PERM_EDIT)) {
            $function->loadRefsUsers();
        } else {
            unset($group->_ref_functions[$keyFunc]);
        }
    }
}
 /**
  * Load minimal catalogue classification to cover the prescription analyses
  */
 function loadClassification()
 {
     $catalogues = array();
     // Load needed catalogues
     foreach ($this->_ref_examens as $examen) {
         $catalogue_id = $examen->catalogue_labo_id;
         if (!array_key_exists($catalogue_id, $catalogues)) {
             $catalogue = new CCatalogueLabo();
             $catalogue->load($catalogue_id);
             $catalogue->_ref_catalogues_labo = array();
             $catalogues[$catalogue->_id] = $catalogue;
         }
     }
     // Complete catalogue hierarchy
     foreach ($catalogues as $_catalogue) {
         $child_catalogue = $_catalogue;
         while ($child_catalogue->pere_id && !array_key_exists($child_catalogue->pere_id, $catalogues)) {
             $catalogue = new CCatalogueLabo();
             $catalogue->load($child_catalogue->pere_id);
             $catalogues[$catalogue->_id] = $catalogue;
             $child_catalogue = $catalogue;
         }
     }
     // Prepare catalogues collections
     foreach ($catalogues as &$ref_catalogue) {
         $ref_catalogue->_ref_catalogues_labo = array();
         $ref_catalogue->_ref_prescription_items = array();
     }
     // Feed prescription items
     foreach ($this->_ref_prescription_items as $_item) {
         $catalogue_id = $_item->_ref_examen_labo->catalogue_labo_id;
         $catalogues[$catalogue_id]->_ref_prescription_items[$_item->_id] = $_item;
     }
     // Link catalogue hierarchy
     foreach ($catalogues as &$link_catalogue) {
         if ($parent_id = $link_catalogue->pere_id) {
             $parent_catalogue =& $catalogues[$parent_id];
             $parent_catalogue->_ref_catalogues_labo[$link_catalogue->_id] =& $link_catalogue;
             $link_catalogue->_ref_pere =& $parent_catalogue;
         }
     }
     // Find classifications roots
     foreach ($catalogues as &$root_catalogue) {
         if ($root_catalogue->computeLevel() == 0) {
             $this->_ref_classification_roots[$root_catalogue->_id] =& $root_catalogue;
         }
     }
 }
<?php

/**
 * $Id: httpreq_vw_examens_catalogues.php 19285 2013-05-26 13:10:13Z phenxdesign $
 *
 * @package    Mediboard
 * @subpackage Labo
 * @author     SARL OpenXtrem <*****@*****.**>
 * @license    GNU General Public License, see http://www.gnu.org/licenses/gpl.html
 * @version    $Revision: 19285 $
 */
CCanDo::checkRead();
$catalogue_labo_id = CValue::getOrSession("catalogue_labo_id");
// Chargement du catalogue demandé
$catalogue = new CCatalogueLabo();
$catalogue->load($catalogue_labo_id);
$catalogue->loadRefs();
// Création du template
$smarty = new CSmartyDP();
$smarty->assign("search", 0);
$smarty->assign("catalogue", $catalogue);
$smarty->display("inc_vw_examens_catalogues.tpl");