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 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', ''); $ctr = 1; foreach ($dates as $vitalSignGroupId => $date) { $row->addChild('cell', date('m/d/Y h:iA', strtotime($date))); $column = $head->addChild('column', ''); $column->addAttribute('type', 'ro'); $column->addAttribute('width', '130'); $userdata = $xml->addChild('userdata', $vitalSignGroupId); $userdata->addAttribute('name', 'groupId' . $ctr++); } } $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'); }