public function nsdrPopulate($tthis, $context, $data) { $ret = array(); //debug_print_backtrace(); $labsIter = new LabsIterator(); $filters = array(); $filters['patientId'] = key($context); if (isset($context[key($context)]['filters']['description'])) { $filters['description'] = $context[key($context)]['filters']['description']; } $filters['limit'] = '1'; $labsIter->setFilters($filters); $ret = $labsIter->first()->toArray(); return $ret; }
public static function generate($patient, $provider) { if (!$patient instanceof Patient) { $patientId = (int) $patient; $patient = new Patient(); $patient->personId = $patientId; $patient->populate(); } self::$patient = $patient; if (!$provider instanceof Provider) { $providerId = (int) $provider; $provider = new Provider(); $provider->personId = $providerId; $provider->populate(); } self::$provider = $provider; $building = Building::getBuildingDefaultLocation($provider->personId); self::$providerBuilding = $building; $data = array(); $data[] = self::generateMSH(array('buildingName' => $building->name)); $data[] = self::generateSFT(); $data[] = self::generatePID($patient); $order = new OrderLabTest(); $iterator = $order->getIteratorByPersonId($patient->personId); foreach ($iterator as $orderLabTest) { $data[] = self::generateORC($orderLabTest->order->provider); $result = array(); $result['orderLabTest'] = $orderLabTest; $loinc = new ProcedureCodesLOINC(); $loinc->loincNum = $orderLabTest->labTest; $loinc->populate(); $result['loinc'] = $loinc; $orderId = (int) $orderLabTest->orderId; $labTest = new LabTest(); $labTest->populateByLabOrderId($orderId); $result['labTest'] = $labTest; $data[] = self::generateOBR($result); $labsIterator = new LabsIterator(); $labsIterator->setFilters(array('orderId' => $orderId)); foreach ($labsIterator as $row) { $result['result'] = $row; $data[] = self::generateOBX($result); } $data[] = self::generateSPM($orderLabTest->collectionSample); } return implode("\n", $data); }
protected function _getLabResults($filters) { $labs = array(); $showCalcLabs = (bool) $this->_getParam('showCalcLabs', false); $calcLabsArray = array(); if (true) { $calcLabs = new CalcLabs(); $calcLabsArray = $calcLabs->getAllCalcLabsArray($filters['patientId']); } $labs = $calcLabsArray; $labsIterator = new LabsIterator(); $labsIterator->setFilters($filters); foreach ($labsIterator as $lab) { $tmpArr = array(); $tmpArr[] = $lab->observationTime; $tmpArr[] = $lab->description; $tmpArr[] = $lab->value; $tmpArr[] = $lab->units; $tmpArr[] = $lab->referenceRange; $tmpArr[] = $lab->abnormalFlag; $tmpArr[] = $lab->resultStatus; $tmpValue = $lab->value; if (!is_numeric($tmpValue)) { if (strtolower($lab->abnormalFlag) != "abnormal") { // normal $tmpValue = 1; } else { // abnormal $tmpValue = 0; } } $tmpArr[] = date('Y-m-d', strtotime($lab->observationTime)) . '::' . $tmpValue; $labs[$lab->labResultId] = $tmpArr; } $rows = $this->_toJsonArray($labs); return $rows; }
public function populate($patientId, $userId, $visitId) { $this->_patientId = (int) $patientId; $patient = new Patient(); $patient->personId = $this->_patientId; $patient->populate(); $this->_title = $patient->displayName . ' Healthcare Record'; $this->patient = $patient; $this->_userId = (int) $userId; $user = new User(); $user->personId = $this->_userId; $user->populate(); $this->user = $user; $visit = new Visit(); $visit->visitId = (int) $visitId; if ($visit->visitId > 0 && $visit->populate()) { $this->visit = $visit; } $this->building = Building::getBuildingDefaultLocation($this->user->personId); $performers = array(); $problemList = new ProblemList(); $filters = array(); $filters['personId'] = $this->_patientId; $this->setFiltersDateRange($filters); $problems = array(); $problemListIterator = new ProblemListIterator(); $problemListIterator->setFilters($filters); foreach ($problemListIterator as $problem) { $problems[] = $problem; $providerId = (int) $problem->providerId; if (!isset($performers[$providerId])) { $provider = new Provider(); $provider->personId = $providerId; $provider->populate(); $performers[$providerId] = $provider; } } $this->problemLists = $problems; unset($filters['personId']); $filters['patientId'] = $this->_patientId; $labResults = array(); $labTests = array(); $labOrderTests = array(); $labsIterator = new LabsIterator(); $labsIterator->setFilters($filters); foreach ($labsIterator as $lab) { // get the lab order $labTestId = (int) $lab->labTestId; if (!isset($labTests[$labTestId])) { $labTest = new LabTest(); $labTest->labTestId = (int) $lab->labTestId; $labTest->populate(); $labTests[$labTestId] = $labTest; } $labTest = $labTests[$labTestId]; $orderId = (int) $labTest->labOrderId; if (!isset($labOrderTests[$orderId])) { $orderLabTest = new OrderLabTest(); $orderLabTest->orderId = $orderId; $orderLabTest->populate(); $labOrderTests[$orderId] = $orderLabTest; } $orderLabTest = $labOrderTests[$orderId]; $providerId = (int) $orderLabTest->order->providerId; if (!isset($performers[$providerId])) { $provider = new Provider(); $provider->personId = $providerId; $provider->populate(); $performers[$providerId] = $provider; } if (!isset($labResults[$orderId])) { $labResults[$orderId] = array(); $labResults[$orderId]['results'] = array(); $labResults[$orderId]['labTest'] = $labTest; $labResults[$orderId]['orderLabTest'] = $orderLabTest; } $labResults[$orderId]['results'][] = $lab; } $this->labResults = $labResults; $this->performers = $performers; $this->populateHeader($this->_xml); $this->populateBody($this->_xml); return $this->_xml->asXML(); }
protected function _getLabResults($filters) { $order = $this->_getParam('order'); if (strlen($order) > 0) { $orders = explode(';', $order); $values = array(); foreach ($orders as $val) { $x = explode(':', $val); if (!isset($x[1])) { $x[1] = 'ASC'; } $values[] = $x; } $filters['orders'] = $values; } $labs = array(); $showCalcLabs = (bool) $this->_getParam('showCalcLabs', false); $calcLabsArray = array(); if (false) { $calcLabs = new CalcLabs(); $calcLabsArray = $calcLabs->getAllCalcLabsArray($filters['patientId']); } $labs = $calcLabsArray; $labsIterator = new LabsIterator(); $labsIterator->setFilters($filters); foreach ($labsIterator as $lab) { $tmpArr = array(); $tmpArr[] = $lab->observationTime; $tmpArr[] = $lab->description; $tmpArr[] = $lab->value; $tmpArr[] = $lab->units; $tmpArr[] = $lab->referenceRange; $tmpArr[] = $lab->abnormalFlag; $tmpArr[] = $lab->resultStatus; $tmpArr[] = $lab->labTest->clia_disclosure; $tmpValue = $lab->value; if (!is_numeric($tmpValue)) { if (strtolower($lab->abnormalFlag) != '' || strtolower($lab->abnormalFlag) != 'n') { // normal $tmpValue = 1; } else { // abnormal $tmpValue = 0; } } $tmpArr[] = date('Y-m-d', strtotime($lab->observationTime)) . '::' . $tmpValue; $sign = (int) $lab->labTest->labOrder->hasSigningEntry(); $tmpArr[] = (int) $sign . '::' . $lab->labTest->labOrder->labOrderId; $labs[$lab->labResultId] = $tmpArr; } $rows = $this->_toJsonArray($labs); return $rows; }
public function listLabResultsJsonAction() { $orderId = (int) $this->_getParam('orderId'); $rows = array(); $labsIterator = new LabsIterator(); $labsIterator->setFilters(array('orderId' => $orderId)); foreach ($labsIterator as $lab) { $rows[] = $this->_generateLabResultRowData($lab); } $data = array(); $data['rows'] = $rows; $json = Zend_Controller_Action_HelperBroker::getStaticHelper('json'); $json->suppressExit = true; $json->direct($data); }
public static function generate($patientId) { // v2.5.1 $patientId = (int) $patientId; $ret = array(); $msh = array(); $msh['messageType'] = array('code' => 'ORU', 'eventType' => 'R01', 'structure' => 'ORU_R01'); $ret[] = self::generateMSH($msh); // MSH $ret[] = self::generateSFT(); // SFT $ret[] = self::generatePID($patientId); // PID $filters = array('patientId' => $patientId); $labResults = array(); $labTests = array(); $labOrderTests = array(); $labsIterator = new LabsIterator(); $labsIterator->setFilters($filters); foreach ($labsIterator as $lab) { // get the lab order $labTestId = (int) $lab->labTestId; if (!isset($labTests[$labTestId])) { $labTest = new LabTest(); $labTest->labTestId = (int) $lab->labTestId; $labTest->populate(); $labTests[$labTestId] = $labTest; } $labTest = $labTests[$labTestId]; $orderId = (int) $labTest->labOrderId; if (!isset($labOrderTests[$orderId])) { $orderLabTest = new OrderLabTest(); $orderLabTest->orderId = $orderId; $orderLabTest->populate(); $labOrderTests[$orderId] = $orderLabTest; } $orderLabTest = $labOrderTests[$orderId]; if (!isset($labResults[$orderId])) { $labResults[$orderId] = array(); $labResults[$orderId]['results'] = array(); $labResults[$orderId]['labTest'] = $labTest; $labResults[$orderId]['orderLabTest'] = $orderLabTest; $providerId = (int) $orderLabTest->order->providerId; $provider = new Provider(); $provider->personId = $providerId; $provider->populate(); $labResults[$orderId]['provider'] = $provider; } $labResults[$orderId]['results'][] = $lab; } foreach ($base->labResults as $orderId => $value) { $ret[] = self::generateORC($value); // ORC $ret[] = self::generateOBR($value); // OBR foreach ($value['results'] as $result) { $data = array('result' => $result, 'labTest' => $value['labTest'], 'orderLabTest' => $value['orderLabTest'], 'provider' => $value['provider']); $ret[] = self::generateOBX($data); // OBX } $ret[] = self::generateSPM($value); // SPM } /*$iterator = new LabsIterator(); $iterator->setFilters(array('patientId'=>$patientId)); foreach ($iterator as $lab) { $data = array(); $data['lab'] = $lab; $orderLabTest = new OrderLabTest(); $orderLabTest->orderId = $lab->labTest->labOrderId; $orderLabTest->populate(); $data['orderLabTest'] = $orderLabTest; $loinc = new ProcedureCodesLOINC(); $loinc->loincNum = $orderLabTest->labTest; $loinc->populate(); $data['loinc'] = $loinc; $ret[] = self::generateOBR($data); // OBR $ret[] = self::generateOBX($data); // OBX $ret[] = self::generateSPM($data); // SPM }*/ return implode("\r\n", $ret); }