function setVitalSignValues(array $vitalSigns)
 {
     foreach ($vitalSigns as $vitalSignData) {
         $vitalSignValue = new VitalSignValue();
         $vitalSignValue->populateWithArray($vitalSignData);
         $this->vitalSignValues[] = $vitalSignValue;
     }
 }
 public function current()
 {
     $ormObj = new $this->_ormClass();
     //echo $this->_dbSelect->__toString();exit;
     //echo $this->_offset . "offset<br>\n";
     if (isset($this->_currentRow)) {
         $row = $this->_currentRow;
         $this->_currentRow = null;
         $this->_offset--;
     } else {
         $row = $this->_dbStmt->fetch(null, null, $this->_offset);
     }
     if (is_null($this->_currentGroupId)) {
         $this->_currentGroupId = $row['vitalSignGroupId'];
     }
     //echo "start: " . $this->_currentGroupId . "<br>";
     //echo "start: " . $row['vital'] . "<br>";
     $ormObj->populateWithArray($row);
     $values = array();
     $vitalSignValue = new VitalSignValue();
     $vitalSignValue->populateWithArray($row);
     $values[] = $vitalSignValue;
     while ($this->_offset + 1 < $this->_dbStmt->rowCount()) {
         $row = $this->_dbStmt->fetch(null, null, $this->_offset);
         $this->_offset++;
         $this->_currentRow = $row;
         if ($row['vitalSignGroupId'] === $this->_currentGroupId) {
             $vitalSignValue = new VitalSignValue();
             $vitalSignValue->populateWithArray($row);
             $values[] = $vitalSignValue;
         } else {
             break;
         }
     }
     $this->_currentGroupId = null;
     $ormObj->setVitalSignValues($values);
     //echo $ormObj->toString();
     return $ormObj;
 }
Esempio n. 3
0
 public static function getAllVitals(array $filters, $dateOfBirth = null)
 {
     $data = array();
     $dates = array();
     $results = VitalSignGroup::getVitalsByFilters($filters);
     self::$_vitalSigns = array();
     foreach ($results as $result) {
         self::$_vitalSigns[] = $result;
         // get the age the date taken
         if (!isset($dates[$result['vitalSignGroupId']])) {
             $v = $result['vitalSignGroupId'];
             if ($dateOfBirth !== null) {
                 $v = GrowthChartBase::calculateMonthsDiff($dateOfBirth, strtotime($result['dateTime']), true);
             }
             $dates[$result['vitalSignGroupId']] = $v;
             $data["{$v}"] = array();
         }
         $convertedValues = VitalSignValue::convertValues($result['vital'], $result['value'], $result['units']);
         if ($convertedValues !== false) {
             $x = explode(' ', $convertedValues['metric']);
             $unit = array_pop($x);
             $y = implode(' ', $x);
         } else {
             $y = $result['value'];
         }
         $data["{$dates[$result['vitalSignGroupId']]}"][$result['vital']] = $y;
     }
     return $data;
 }
 public function indexAction()
 {
     $personId = (int) $this->_getParam('personId');
     $person = new Person();
     $person->personId = $personId;
     $person->populate();
     $this->view->person = $person;
     $this->view->chartList = GrowthChartBase::listCharts();
     switch (strtolower($person->displayGender)) {
         case 'female':
             $gender = GrowthChartBase::GENDER_FEMALE;
             break;
         case 'male':
         default:
             $gender = GrowthChartBase::GENDER_MALE;
             break;
     }
     $listGrowthCharts = array();
     foreach ($this->view->chartList as $key => $value) {
         $ormClass = ucfirst($key);
         $orm = new $ormClass();
         $ormIterator = $orm->getIteratorByGender($gender);
         $xMax = 0;
         $yMax = 0;
         $xMin = 0;
         $yMin = 0;
         $percentiles = array();
         $mappings = $orm->_dataTableMappings;
         list($base, $fields) = each($mappings);
         $columns = array();
         foreach ($ormIterator as $row) {
             if ($row->{$base} > $xMax) {
                 $xMax = $row->{$base};
             }
             if ($xMin == 0 || $row->{$base} < $xMin) {
                 $xMin = $row->{$base};
             }
             foreach ($fields as $field) {
                 if ($row->{$field} > $yMax) {
                     $yMax = $row->{$field};
                 }
                 if ($yMin == 0 || $row->{$field} < $yMin) {
                     $yMin = $row->{$field};
                 }
                 $columns[$field]['name'] = substr($field, 1);
                 $columns[$field]['percentiles'][$row->{$base}] = $row->{$field};
             }
         }
         $listGrowthCharts[$key]['data'] = $orm->listVitals($person);
         // this MUST be called right after $orm->listVitals($person) is called
         $vitalSigns = array();
         foreach (GrowthChartBase::$_vitalSigns as $vitalSign) {
             $dateVitalsTime = strtotime($vitalSign['dateTime']);
             if (!isset($vitalSigns[$vitalSign['vitalSignGroupId']])) {
                 list($bYear, $bMonth, $bDay) = explode('-', date('Y-m-d', strtotime($person->dateOfBirth)));
                 list($vYear, $vMonth, $vDay) = explode('-', date('Y-m-d', $dateVitalsTime));
                 $age = $vMonth >= $bMonth && $vDay >= $bDay || $vMonth > $bMonth ? $vYear - $bYear : $vYear - $bYear - 1;
                 $vitalSigns[$vitalSign['vitalSignGroupId']]['label'] = date('m/d/Y h:iA', $dateVitalsTime) . ': Age=' . $age * 12 . ' months';
                 $vitalSigns[$vitalSign['vitalSignGroupId']]['data'] = array();
             }
             $value = $vitalSign['value'];
             $ussValue = $value;
             $metricValue = '';
             if (strlen($vitalSign['units']) > 0) {
                 if (strlen($ussValue) > 0) {
                     $ussValue .= ' ' . $vitalSign['units'];
                 }
                 $ret = VitalSignValue::convertValues($vitalSign['vital'], $value, $vitalSign['units']);
                 if ($ret !== false) {
                     $ussValue = $ret['uss'];
                     $metricValue = $ret['metric'];
                 }
             }
             $tmp['data'][] = $ussValue;
             $tmp['data'][] = $metricValue;
             $vitalSigns[$vitalSign['vitalSignGroupId']]['data'][] = $vitalSign['vital'] . '=' . $metricValue . ' (' . $ussValue . ')';
         }
         $vitalTxt = array();
         foreach ($vitalSigns as $groupId => $value) {
             $arr = array();
             foreach ($value['data'] as $val) {
                 $arr[] = $val;
             }
             $vitalTxt[] = $value['label'] . ' ' . implode(' ', $arr);
         }
         $listGrowthCharts[$key]['vitalSigns'] = implode("\n", $vitalTxt);
         $listGrowthCharts[$key]['columns'] = $columns;
         $listGrowthCharts[$key]['name'] = GrowthChartBase::prettyName($base);
         $listGrowthCharts[$key]['unit'] = constant("{$ormClass}::BASE_UNIT");
         $listGrowthCharts[$key]['percentileName'] = constant("{$ormClass}::PERCENTILE_NAME");
         $listGrowthCharts[$key]['percentileUnit'] = constant("{$ormClass}::PERCENTILE_UNIT");
         $listGrowthCharts[$key]['xMax'] = ceil($xMax);
         $listGrowthCharts[$key]['yMax'] = ceil($yMax);
         $listGrowthCharts[$key]['xMin'] = floor($xMin);
         $listGrowthCharts[$key]['yMin'] = floor($yMin);
     }
     //file_put_contents('/tmp/growth.charts',print_r($listGrowthCharts,true));
     $this->view->listGrowthCharts = $listGrowthCharts;
     $this->render();
 }
 public function processEditVitalSignValueFieldAction()
 {
     $vitalSignValueId = (int) $this->_getParam('id');
     $field = $this->_getParam('field');
     $value = $this->_getParam('value');
     // expected format "[value] [unit]" e.g. "120 LB"
     $conversion = (int) $this->_getParam('conversion');
     // flag to check if value needs conversion?
     $ret = false;
     $vitalSignValue = new VitalSignValue();
     $vitalSignValue->vitalSignValueId = $vitalSignValueId;
     $validFields = array('date' => 'date', 'value' => 'value');
     if (isset($validFields[$field]) && $vitalSignValue->populate()) {
         if ($field == 'date') {
             $vitalSignValue->vitalSignGroup->dateTime = date('Y-m-d H:i:s', strtotime($value));
             $vitalSignValue->vitalSignGroup->persist();
             $ret = true;
         } else {
             if ($field == 'value') {
                 // units is part of value and needs to be extracted, if no units is specified it will used the same unit in db
                 $arrValue = explode(' ', $value);
                 if (count($arrValue) > 1) {
                     $units = array_pop($arrValue);
                 } else {
                     $units = $vitalSignValue->units;
                 }
                 $value = implode(' ', $arrValue);
                 // is value contains spaces?
                 // check if value needs conversion
                 if ($conversion) {
                     // needs conversion
                     $convertedValues = VitalSignValue::convertValues($vitalSignValue->vital, $value, $units);
                     if ($convertedValues !== false) {
                         $type = VitalSignValue::unitType($vitalSignValue->vital, $vitalSignValue->units);
                         $x = explode(' ', $convertedValues[$type]);
                         array_pop($x);
                         $value = implode(' ', $x);
                     }
                 }
                 $vitalSignValue->{$field} = $value;
                 $vitalSignValue->persist();
                 if ($vitalSignValue->vital == 'height' || $vitalSignValue->vital == 'weight') {
                     VitalSignValue::recalculate($vitalSignValue->vitalSignGroupId);
                 }
                 $ret = true;
             }
         }
     }
     $json = Zend_Controller_Action_HelperBroker::getStaticHelper('json');
     $json->suppressExit = true;
     $json->direct($ret);
 }
 public function listXmlAction()
 {
     $personId = (int) $this->_getParam('personId');
     $filter = $this->_getParam('filter');
     $dateToday = date('Y-m-d');
     $today = strtotime($dateToday);
     $filterRange = array();
     $filterRange['begin'] = $dateToday;
     $filterRange['end'] = date('Y-m-d 23:59:59', $today);
     switch ($filter) {
         case 'd-1':
         case 'd-2':
         case 'd-3':
         case 'd-4':
         case 'd-5':
         case 'd-6':
         case 'd-7':
         case 'd-15':
         case 'd-30':
             $filterRange['begin'] = date('Y-m-d', strtotime(substr($filter, 1) . ' days', $today));
             break;
         case 'm-6':
             $filterRange['begin'] = date('Y-m-d', strtotime(substr($filter, 1) . ' months', $today));
             break;
         case 'y-1':
         case 'y-2':
             $filterRange['begin'] = date('Y-m-d', strtotime(substr($filter, 1) . ' years', $today));
             break;
         case 'all':
             $filterRange['begin'] = date('Y-m-d', strtotime(''));
             break;
         default:
             $x = explode('|', $filter);
             if (isset($x[1])) {
                 $filterRange['begin'] = date('Y-m-d', strtotime($x[0]));
                 $filterRange['end'] = date('Y-m-d', strtotime($x[1]));
             }
             break;
     }
     trigger_error(print_r($filterRange, true), E_USER_NOTICE);
     $filters = array();
     $filters['personId'] = $personId;
     $filters['dateBegin'] = $filterRange['begin'];
     $filters['dateEnd'] = $filterRange['end'];
     $filters['vitalSignTemplateId'] = 1;
     $results = VitalSignGroup::getVitalsByFilters($filters);
     $vitals = array();
     $dates = array();
     $data = array();
     foreach ($results as $result) {
         if (!isset($vitals[$result['vital']])) {
             $vitals[$result['vital']] = array();
         }
         if (!isset($dates[$result['vitalSignGroupId']])) {
             $dates[$result['vitalSignGroupId']] = date('m/d/Y h:i A', strtotime($result['dateTime']));
         }
         $convertedValues = VitalSignValue::convertValues($result['vital'], $result['value'], $result['units']);
         if ($convertedValues !== false) {
             trigger_error(print_r($convertedValues, true), E_USER_NOTICE);
             $x = explode(' ', $convertedValues['uss']);
             $unit = array_pop($x);
             $value = implode(' ', $x) . ' (' . $convertedValues['metric'] . ')';
             $vitals[$result['vital']][$result['vitalSignGroupId']] = $value;
         } else {
             $vitals[$result['vital']][$result['vitalSignGroupId']] = $result['value'];
         }
         if (!isset($data[$result['vitalSignGroupId']])) {
             $data[$result['vitalSignGroupId']] = array();
         }
         $data[$result['vitalSignGroupId']][$result['vital']] = $result;
     }
     $xml = new SimpleXMLElement('<rows />');
     $head = $xml->addChild('head');
     $column = $head->addChild('column', '');
     $column->addAttribute('type', 'ro');
     $column->addAttribute('width', '150');
     $column->addAttribute('color', '#ddd');
     if (!empty($dates)) {
         $row = $xml->addChild('row');
         $row->addAttribute('id', 'dates');
         $row->addChild('cell', '');
         foreach ($dates as $date) {
             $row->addChild('cell', date('m/d/y h:iA', strtotime($date)));
             $column = $head->addChild('column', '');
             $column->addAttribute('type', 'ro');
             $column->addAttribute('width', '130');
         }
     }
     $labelKeyValues = $this->getVitalSignsTemplateKeyValue();
     foreach ($labelKeyValues as $key => $value) {
         $row = $xml->addChild('row');
         $row->addAttribute('id', $key);
         $row->addChild('cell', $value);
         if (isset($vitals[$key])) {
             foreach ($vitals[$key] as $vital) {
                 $row->addChild('cell', $vital);
             }
         }
     }
     header('Content-Type: text/xml');
     $this->view->xmlContents = $xml->asXML();
     trigger_error($this->view->xmlContents, E_USER_NOTICE);
     $this->render('list-xml');
 }