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); }
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(); }
public static function factory($orderId) { $orm = new self(); $orm->orderId = (int) $orderId; $orm->populate(); if ($orm->type == self::TYPE_LAB_TEST) { $ormObj = new OrderLabTest(); $ormObj->orderId = $orm->orderId; $ormObj->populate(); } else { if ($orm->type == self::TYPE_IMAGING) { $ormObj = new OrderImaging(); $ormObj->orderId = $orm->orderId; $ormObj->populate(); } else { $ormObj = $orm; } } return $ormObj; }
public function labResultsAction() { $orderId = (int) $this->_getParam('orderId'); $order = new OrderLabTest(); $order->orderId = $orderId; if (!$order->populate()) { $error = 'Order Id ' . $orderId . ' not found'; trigger_error($error); throw new Exception($error); } $loinc = new ProcedureCodesLOINC(); $loinc->loincNum = $order->labTest; $loinc->populate(); $shortname = $loinc->shortname; if (!strlen($shortname) > 0) { $shortname = $loinc->longCommonName; } $labTest = new LabTest(); $labTest->labOrderId = $order->orderId; $labTest->populateByLabOrderId(); $labOrder = new LabOrder(); $labOrder->labOrderId = $order->orderId; if (!$labOrder->populate()) { $labOrder->labOrderId = $order->orderId; $labOrder->patientId = $order->order->patientId; $labOrder->personId = $order->order->patientId; $labOrder->orderingProvider = $order->order->provider->displayName; $labOrder->manualOrderDate = $order->order->dateTime; $labOrder->orderDescription = $shortname; $labOrder->persist(); $labTest = new LabTest(); $labTest->labOrderId = $labOrder->labOrderId; $labTest->componentCode = $loinc->class; $labTest->service = $shortname; $labTest->orderNum = $order->orderId; $labTest->persist(); $orderObs = strtolower($loinc->orderObs); if ($orderObs == 'both') { // create default lab_results $labResult = new LabResult(); $labResult->description = $order->displayLabTest; $labResult->labTestId = $labTest->labTestId; $labResult->observationTime = date('Y-m-d H:i'); $labResult->units = $loinc->exampleUcumUnits; $labResult->identifier = $loinc->loincNum; $labResult->persist(); } else { if ($orderObs == 'order') { // temporarily do nothing } } } $this->view->order = $order; $form = new WebVista_Form(array('name' => 'labTestId')); $form->setAction(Zend_Registry::get('baseUrl') . 'orders.raw/set-lab-test'); $form->loadORM($labTest, 'LabTest'); $this->view->form = $form; $this->render(); }
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); }