$result_set = new CObservationResultSet();
if ($result_set_id) {
    $result_set->load($result_set_id);
    $object = $result_set->loadRefContext();
} else {
    /** @var COperation|CSejour $object */
    $object = CStoredObject::loadFromGuid($object_guid);
    $result_set->context_class = $object->_class;
    $result_set->context_id = $object->_id;
    $result_set->datetime = CMbDT::dateTime();
    $result_set->patient_id = $object->loadRelPatient()->_id;
}
list($results) = CObservationResultSet::getResultsFor($object);
$pack = new CSupervisionGraphPack();
$pack->load($pack_id);
$links = $pack->loadRefsGraphLinks();
foreach ($links as $_link) {
    $_graph = $_link->loadRefGraph();
    if ($_graph instanceof CSupervisionGraph) {
        $axes = $_graph->loadRefsAxes();
        foreach ($axes as $_axis) {
            $series = $_axis->loadRefsSeries();
            $_axis->loadRefsLabels();
            foreach ($series as $_serie) {
                $_result = new CObservationResult();
                $_result->value_type_id = $_serie->value_type_id;
                $_result->unit_id = $_serie->value_unit_id ? $_serie->value_unit_id : null;
                if ($result_set->_id) {
                    $_result->observation_result_set_id = $result_set->_id;
                    $_result->loadMatchingObject();
                }
 /**
  * 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);
 }