* $Id: ajax_edit_observation_timed_picture.php 20370 2013-09-16 09:56:03Z phenxdesign $
 *
 * @package    Mediboard
 * @subpackage SalleOp
 * @author     SARL OpenXtrem <*****@*****.**>
 * @license    GNU General Public License, see http://www.gnu.org/licenses/gpl.html
 * @version    $Revision: 20370 $
 */
CCanDo::checkRead();
$object_guid = CValue::get("object_guid");
$timed_picture_id = CValue::get("timed_picture_id");
/** @var COperation|CSejour $object */
$object = CStoredObject::loadFromGuid($object_guid);
$timed_picture = new CSupervisionTimedPicture();
$timed_picture->load($timed_picture_id);
$timed_picture->loadRefsFiles();
$result = new CObservationResult();
$result->value_type_id = $timed_picture->value_type_id;
$result->loadRefValueType();
$result->value = "FILE";
$result_set = new CObservationResultSet();
$result_set->context_class = $object->_class;
$result_set->context_id = $object->_id;
$result_set->datetime = CMbDT::dateTime();
$result_set->patient_id = $object->loadRelPatient()->_id;
// Création du template
$smarty = new CSmartyDP();
$smarty->assign("result", $result);
$smarty->assign("result_set", $result_set);
$smarty->assign("timed_picture", $timed_picture);
$smarty->display("inc_edit_observation_timed_picture.tpl");
                $_result->loadRefValueType();
                $_result->_serie_title = $_serie->title ? $_serie->title : $_axis->_view;
                $_serie->_result = $_result;
            }
        }
    } elseif ($_graph instanceof CSupervisionTimedData) {
        $_result = new CObservationResult();
        $_result->value_type_id = $_graph->value_type_id;
        if ($result_set->_id) {
            $_result->observation_result_set_id = $result_set->_id;
            $_result->loadMatchingObject();
        }
        $_result->loadRefValueType();
        $_graph->_result = $_result;
    } elseif ($_graph instanceof CSupervisionTimedPicture) {
        $_result = new CObservationResult();
        $_result->value_type_id = $_graph->value_type_id;
        if ($result_set->_id) {
            $_result->observation_result_set_id = $result_set->_id;
            $_result->loadMatchingObject();
        }
        $_result->loadRefValueType();
        $_graph->loadRefsFiles();
        $_graph->_result = $_result;
    }
}
// Création du template
$smarty = new CSmartyDP();
$smarty->assign("object", $object);
$smarty->assign("result_set", $result_set);
$smarty->assign("pack", $pack);
    $observation_result_set->context_id = $context_id;
    $observation_result_set->patient_id = $patient_id;
    $observation_result_set->datetime = $datetime;
    $observation_result_set->loadMatchingObject();
    $observation_result_set->store();
    $times[$datetime] = $observation_result_set;
    $datetime = CMbDT::dateTime("+{$period} SECONDS", $datetime);
}
foreach ($graphs as $_graph) {
    $_axes = $_graph->loadRefsAxes();
    foreach ($_axes as $_axis) {
        $_series = $_axis->loadRefsSeries();
        foreach ($_series as $_serie) {
            $_samples = $_serie->getSampleData(array_keys($times));
            foreach ($_samples as $_sample) {
                list($_datetime, $_value) = $_sample;
                $result = new CObservationResult();
                $result->observation_result_set_id = $times[$_datetime]->_id;
                $result->unit_id = $_serie->value_unit_id ? $_serie->value_unit_id : "";
                $result->value_type_id = $_serie->value_type_id;
                $result->status = "I";
                $result->method = "SAMPLE";
                $result->loadMatchingObject();
                $result->value = $_value;
                $result->store();
            }
        }
    }
}
CAppUI::stepAjax("Données de test générées", UI_MSG_OK);
CApp::rip();