function calculateGFRResult() { $tmpArr = array(); $tmpArr[] = date('Y-m-d H:i:s'); //observation time $tmpArr[] = 'GFR (CALC)'; //desc $gender = NSDR::populate($this->_patientId . "::com.clearhealth.person.displayGender"); $crea = NSDR::populate($this->_patientId . "::com.clearhealth.labResults[populate(@description=CREA)]"); $genderFactor = null; $creaValue = null; $personAge = null; $raceFactor = 1; switch ($gender[key($gender)]) { case 'M': $genderFactor = 1; break; case 'F': $genderFactor = 0.742; break; } if ((int) strtotime($crea['observation_time']) >= strtotime('now - 60 days') && strtolower($crea[key($crea)]['units']) == 'mg/dl') { $creaValue = $crea[key($crea)]['value']; } $person = new Person(); $person->personId = $this->_patientId; $person->populate(); if ($person->age > 0) { $personAge = $person->age; } $personStat = new PatientStatistics(); $personStat->personId = $this->_patientId; $personStat->populate(); if ($personStat->race == "AFAM") { $raceFactor = 1.21; } $gfrValue = "INC"; if ($personAge > 0 && $creaValue > 0) { $gfrValue = "" . (int) round(pow($creaValue, -1.154) * pow($personAge, -0.203) * $genderFactor * $raceFactor * 186); } trigger_error("gfr:: " . $gfrValue, E_USER_NOTICE); $tmpArr[] = $gfrValue; // lab value $tmpArr[] = 'mL/min/1.73 m2'; //units $tmpArr[] = ''; //ref range $tmpArr[] = ''; //abnormal $tmpArr[] = 'F'; //status $tmpArr[] = date('Y-m-d H:i:s') . '::' . '0'; // observationTime::(boolean)normal; 0 = abnormal, 1 = normal $tmpArr[] = '0'; //sign //$this->_calcLabResults[uniqid()] = $tmpArr; $this->_calcLabResults[1] = $tmpArr; // temporarily set index to one(1) to be able to include in selected lab results return $tmpArr; }
public function templatedTextAction() { $personId = $this->_getParam('personId', 0); $templateId = $this->_getParam('templateId', 0); $templateName = $this->_getParam('templateName'); $templatedText = new TemplatedText(); if ($templateId > 0) { $templatedText->templateId = $templateId; $templatedText->populate(); } else { $templatedText->populateByName($templateName); } $template = $templatedText->template; preg_match_all('/{nsdr:(.*)}/', $template, $matches); if (count($matches[1]) > 0) { foreach ($matches[1] as $val) { $namespace = str_replace('[selectedPatientId]', $personId, $val); if (Zend_Registry::get('memcacheStatus') === 0) { $resultValue = __("Memcache server not started"); } else { $result = NSDR::populate($namespace); $resultValue = $result[$namespace]; if (is_array($resultValue) && isset($resultValue['error'])) { $resultValue = $resultValue['error']; $resultValue = __('No current data for: ') . $val; } } $template = preg_replace('/{nsdr:(.*)}/', $resultValue, $template, 1); } } $this->view->template = $template; $this->render(); }
public function testEnumerations() { $memcache = Zend_Registry::get('memcache'); $memcache->flush(); NSDR::systemStart(); $namespace = "*::com.clearhealth.enumerations.gender"; $nsdr = NSDR::populate($namespace); //$this->assertEquals(count($nsdr[$namespace]),3); $namespace = "F::com.clearhealth.enumerations.gender"; $nsdr = NSDR::populate($namespace); //$this->assertEquals(isset($nsdr[$namespace]['key']),true); //$this->assertEquals($nsdr[$namespace]['key'],'F'); }
/** * Returns an array */ protected function populateGET() { return NSDR::populate($this->_nsdrNamespace); $result = ''; $key = $this->_nsdrNamespace; // extract method name from namespace preg_match('/\\[(.*)\\(\\)\\]$/', $this->_nsdrNamespace, $matches); // return if no method defined if (!isset($matches[1])) { return $result; } $nsdrMethodName = $matches[1]; if ($method = $this->_memcache->get($key)) { // get returns FALSE if error or key not found $nsdrBase = new NSDRBase(); // create anonymous function and use the code from memcache $anonFunc = create_function('$tthis', $method); if ($anonFunc === false) { return $result; } // assign the unique function name returned by create_function to NSDRBase property $nsdrBase->{$nsdrMethodName} = $anonFunc; // execute the function and pass the base as $tthis instead of $this $result = $nsdrBase->{$nsdrMethodName}($nsdrBase); } return $result; }
public function executeQueries(array $filters, ReportView $view) { $config = Zend_Registry::get('config'); $dbName = $config->database->params->dbname; $db = Zend_Registry::get('dbAdapter'); $ret = array(); $reportFilters = array(); foreach ($this->reportFilters as $key => $filter) { $reportFilters['{{' . $filter->name . '}}'] = $filter; } //trigger_error(print_r($reportFilters,true),E_USER_NOTICE); $reportQuery = new ReportQuery(); $reportQueryIterator = $reportQuery->getIteratorByBaseId($this->reportBaseId); foreach ($reportQueryIterator as $query) { $row = array(); $row['reportQuery'] = $query->toArray(); $queryValue = $query->query; $tokens = $this->_extractTokens($queryValue); if (isset($tokens[0])) { // tokens defined // check for undefined/orphaned filter $undefinedTokens = array(); foreach ($tokens as $token) { if (!isset($reportFilters[$token])) { $undefinedTokens[] = $token; } } if (isset($undefinedTokens[0])) { $error = 'Query "' . $query->displayName . '" contains undefined tokens: ' . implode(', ', $undefinedTokens); $row['error'] = $error; trigger_error($error, E_USER_NOTICE); $ret[] = $row; continue; } $queryValue = $this->_applyFilters($filters, $queryValue, $tokens); } $columnDefinitions = $view->unserializedColumnDefinitions; switch ($query->type) { case ReportQuery::TYPE_SQL: trigger_error($queryValue, E_USER_NOTICE); try { if ($view->customizeColumnNames) { $results = array(); $stmt = $db->query($queryValue, array(), Zend_Db::FETCH_NUM); $columnInfo = array(); $rowCount = $stmt->rowCount(); for ($i = 0; $i < $rowCount; $i++) { $fetchRow = $stmt->fetch(Zend_Db::FETCH_NUM, null, $i); if ($i == 0) { for ($ctr = 0, $rowLen = count($fetchRow); $ctr < $rowLen; $ctr++) { $columnMeta = $stmt->getColumnMeta($ctr); $resultSetName = $dbName . '.' . $columnMeta['table'] . '.' . $columnMeta['name']; foreach ($columnDefinitions as $id => $mapping) { // id, queryId, queryName, resultSetName, displayName, transform if ($mapping->resultSetName == $resultSetName) { $columnInfo[$ctr] = $mapping; break; } } } } $tmp = array(); foreach ($columnInfo as $index => $mapping) { $tmp[$mapping->displayName] = $this->_applyTransforms($mapping->transforms, $fetchRow[$index]); } $tmpResult = array(); foreach ($columnDefinitions as $id => $mapping) { // id, queryId, queryName, resultSetName, displayName, transform $tmpResult[$mapping->displayName] = $tmp[$mapping->displayName]; } $results[] = $tmpResult; } } else { $results = $db->fetchAll($queryValue); } $row['rows'] = $results; } catch (Exception $e) { $uniqErrCode = uniqid(); $row['error'] = 'There was a problem executing query: ' . $query->displayName . '. Contact your administrator with error code: ' . $uniqErrCode; trigger_error('Exception error (' . $uniqErrCode . '): ' . $e->getMessage(), E_USER_NOTICE); trigger_error('SQL Query (' . $uniqErrCode . '): ' . $queryValue, E_USER_NOTICE); } $ret[] = $row; break; case ReportQuery::TYPE_NSDR: $nsdr = explode("\n", $queryValue); $results = array(); foreach ($nsdr as $key => $value) { $tokens = $this->_extractTokens($queryValue); if (isset($tokens[0])) { $value = $this->_applyFilters($filters, $value); } $resultSetName = ReportView::extractNamespace($value); $displayName = ReportView::metaDataPrettyName($resultSetName); $nsdrResult = NSDR::populate($value); $tmp = array('Name' => $displayName, 'Value' => ''); $tmp['Value'] = $nsdrResult[$value]; $results[] = $tmp; } if ($view->customizeColumnNames) { $tmpResults = $results; $results = array(); foreach ($columnDefinitions as $id => $mapping) { // id, queryId, queryName, resultSetName, displayName, transform if ($mapping->queryId != $query->reportQueryId && $mapping->queryName != $query->displayName) { continue; } $displayName = ReportView::metaDataPrettyName($mapping->resultSetName); $tmp = array('Name' => $displayName, 'Value' => ''); if (isset($tmpResults[$displayName])) { $tmp['Value'] = $this->_applyTransforms($mapping->transforms, $tmpResults[$displayName]); } $results[] = $tmp; } } $row['rows'] = $results; $ret[] = $row; break; } } return $ret; }