/**
 * $Id$
 *
 * @package    Mediboard
 * @subpackage Labo
 * @author     SARL OpenXtrem <*****@*****.**>
 * @license    GNU General Public License, see http://www.gnu.org/licenses/gpl.html
 * @version    $Revision$
 */
CCanDo::checkRead();
$user = CMediusers::get();
$patient_id = CValue::getOrSession("patient_id");
$prescription_labo_id = CValue::getOrSession("prescription_labo_id");
if (!$patient_id) {
    return;
}
// Chargement de la prescription demandée
$prescription = new CPrescriptionLabo();
$prescription->load($prescription_labo_id);
$prescription->loadRefs();
$patient = new CPatient();
$patient->load($patient_id);
$patient->loadRefsPrescriptions(PERM_EDIT);
foreach ($patient->_ref_prescriptions as $_prescription) {
    $_prescription->loadRefs();
}
// Création du template
$smarty = new CSmartyDP();
$smarty->assign("patient", $patient);
$smarty->assign("prescription", $prescription);
$smarty->display("inc_vw_prescriptions.tpl");
CCanDo::checkRead();
$doc = new CMbXMLDocument();
$doc->setSchema("modules/dPlabo/remote/prescription.xsd");
if (!$doc->checkSchema()) {
    CAppUI::setMsg("Schema manquant", UI_MSG_ERROR);
    redirect();
}
$mbPrescription = new CPrescriptionLabo();
// Chargement de la prescription
$mb_prescription_id = CValue::post("prescription_labo_id", null);
if (!$mb_prescription_id) {
    CAppUI::setMsg("Veuillez spécifier une prescription", UI_MSG_ERROR);
    redirect();
}
if ($mbPrescription->load($mb_prescription_id)) {
    $mbPrescription->loadRefs();
}
// Chargement de l'id400 "labo code4" du praticien
$prat =& $mbPrescription->_ref_praticien;
$tagCode4 = "labo code4";
$idSantePratCode4 = new CIdSante400();
$idSantePratCode4->loadLatestFor($prat, $tagCode4);
// Chargement de l'id400 "labo code9" du praticien
$tagCode9 = "labo code9";
$idSantePratCode9 = new CIdSante400();
$idSantePratCode9->loadLatestFor($prat, $tagCode9);
// Si le praticien n'a pas d'id400, il ne peut pas envoyer la prescription
if (!$idSantePratCode4->_id || !$idSantePratCode9->_id) {
    CAppUI::setMsg("Le praticien n'a pas d'id400 pour le catalogue LABO", UI_MSG_ERROR);
    redirect();
}