public function listStatsAction()
 {
     $personId = (int) $this->_getParam('personId');
     $psd = new PatientStatisticsDefinition();
     $stats = PatientStatisticsDefinition::getPatientStatistics($personId);
     $psdIterator = $psd->getAllActive();
     $rows = array();
     foreach ($psdIterator as $row) {
         $tmp = array();
         $tmp['id'] = $row->name;
         $tmp['data'] = array();
         $tmp['data'][] = GrowthChartBase::prettyName($row->name);
         $tmp['data'][] = isset($stats[$row->name]) ? $stats[$row->name] : '';
         $options = array();
         if ($row->type == PatientStatisticsDefinition::TYPE_ENUM) {
             $enumerationClosure = new EnumerationClosure();
             $paths = $enumerationClosure->generatePaths($row->value);
             foreach ($paths as $id => $name) {
                 $options[] = array('key' => $id, 'value' => $name);
             }
         }
         $tmp['userdata']['type'] = $row->type;
         $tmp['userdata']['options'] = $options;
         $rows[] = $tmp;
     }
     $json = Zend_Controller_Action_HelperBroker::getStaticHelper('json');
     $json->suppressExit = true;
     $json->direct(array('rows' => $rows));
 }
 public function filterDemographicsAction()
 {
     $psd = new PatientStatisticsDefinition();
     $psdIterator = $psd->getAllActive();
     $demographics = array('age' => array('name' => 'Age', 'type' => ''), 'gender' => array('name' => 'Gender', 'type' => PatientStatisticsDefinition::TYPE_ENUM, 'options' => Enumeration::getEnumArray('Gender', 'key')), 'marital_status' => array('name' => 'Marital Status', 'type' => PatientStatisticsDefinition::TYPE_ENUM, 'options' => Enumeration::getEnumArray('Marital Status', 'key')));
     foreach ($psdIterator as $row) {
         $tmp = array();
         $tmp['name'] = GrowthChartBase::prettyName($row->name);
         $options = array();
         if ($row->type == PatientStatisticsDefinition::TYPE_ENUM) {
             $enumerationClosure = new EnumerationClosure();
             $options = $enumerationClosure->generatePathsKeyName($row->value);
         }
         $tmp['type'] = $row->type;
         asort($options);
         $tmp['options'] = $options;
         $demographics[$row->name] = $tmp;
     }
     $this->view->demographics = $demographics;
     $this->view->filters = $this->_session->filters['demographics'];
     $operators = array('' => '');
     foreach (Claim::balanceOperators() as $key => $value) {
         $operators[$key] = $value;
     }
     $this->view->operators = $operators;
     $this->render();
 }
 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();
 }
示例#4
0
 public static function listDemographics(array $filters)
 {
     if (!$filters) {
         return array();
     }
     // key => array('[key]-enabled','name','type','operator','operand1','operand2')
     $db = Zend_Registry::get('dbAdapter');
     $sqlSelect = $db->select()->from('patient', 'person_id AS patientPersonId')->join('person', 'person.person_id = patient.person_id', array('gender', 'marital_status', "(DATE_FORMAT(NOW(),'%Y') - DATE_FORMAT(person.date_of_birth,'%Y') - (DATE_FORMAT(NOW(),'00-%m-%d') < DATE_FORMAT(person.date_of_birth,'00-%m-%d'))) AS age"))->joinLeft('patientStatistics', 'person.person_id = patientStatistics.personId')->group('patient.person_id');
     $keys = array();
     foreach ($filters as $key => $value) {
         if ($key == 'reminders') {
             $config = Zend_Registry::get('config');
             $sqlSelect->joinLeft('address', 'address.person_id = patient.person_id', 'address_id AS addressId');
             $sqlSelect->joinLeft('number', 'number.person_id = patient.person_id', 'number_id AS numberId');
             if (strtolower($config->patient->detailsView2x) == 'true') {
                 $sqlSelect->joinLeft('person_address', 'person_address.address_id=address.address_id', null);
                 $sqlSelect->joinLeft('person_number', 'person_number.number_id=number.number_id', null);
             }
             $sqlSelect->where("(address.type = 'REMINDERS' OR number.type = 'REMINDERS')");
             continue;
         }
         if (!$value['enabled']) {
             continue;
         }
         $keys[] = $key;
         $operand1 = isset($value['operand1']) ? $value['operand1'] : '';
         $operator = isset($value['operator']) ? $value['operator'] : '';
         switch ($operator) {
             case '>':
             case '>=':
             case '<':
             case '<=':
                 $where = $value['operator'] . ' ' . $db->quote($operand1);
                 break;
             case 'between':
                 $operand2 = isset($value['operand2']) ? $value['operand2'] : '';
                 $where = 'BETWEEN ' . $db->quote($operand1) . ' AND ' . $db->quote($operand2);
                 break;
             case '=':
             default:
                 $where = '= ' . $db->quote($operand1);
                 break;
         }
         switch ($key) {
             case 'gender':
             case 'marital_status':
                 $sqlSelect->where('person.' . $key . ' ' . $where);
                 break;
             case 'age':
                 $sqlSelect->having("age {$where}");
                 break;
             default:
                 // patient statistics
                 $sqlSelect->where('patientStatistics.`' . $key . '` ' . $where);
                 break;
         }
     }
     //trigger_error($sqlSelect->__toString());
     $rows = array();
     $dbStmt = $db->query($sqlSelect);
     while ($row = $dbStmt->fetch()) {
         $personId = (int) $row['patientPersonId'];
         $tmp = self::generateRowData($personId);
         if (isset($filters['reminders'])) {
             $addressId = isset($row['addressId']) ? (int) $row['addressId'] : 0;
             $numberId = isset($row['numberId']) ? (int) $row['numberId'] : 0;
             if (!$addressId > 0 && !$numberId > 0) {
                 continue;
             }
             $tmp['addressId'] = $addressId;
             $tmp['numberId'] = $numberId;
         }
         $rows[$personId] = $tmp;
         if (!isset($rows[$personId]['demographics'])) {
             $rows[$personId]['demographics'] = array();
         }
         foreach ($keys as $key) {
             if (!isset($row[$key])) {
                 continue;
             }
             $rows[$personId]['demographics'][] = GrowthChartBase::prettyName($key) . ': ' . $row[$key];
         }
     }
     return $rows;
 }