public function executeAdd(sfWebRequest $request) { if ($request->isMethod('Post')) { $lab_test = new LabTest(); $lab_test->setTitle($this->getRequestParameter('title')); $lab_test->setPrice($this->getRequestParameter('price')); $lab_test->setStatus(Constant::RECORD_STATUS_ACTIVE); $lab_test->save(); $this->getUser()->setFlash('SUCCESS_MESSAGE', Constant::RECORD_ADDED_SUCCESSFULLY); $this->redirect('LabTest/list'); } //end if }
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 function loadTestLabsAction() { $f = fopen('/tmp/labdata.csv', "r"); $counter = 0; $labOrderId = 0; $labTestId = 0; while (($line = fgetcsv($f)) && $counter < 100) { $date = date('Y-m-d H:i:s', mt_rand(strtotime('2000-01-01'), strtotime('today'))); if ($counter == 0 || $counter % 20 == 0) { $lo = new LabOrder(); $lo->patientId = 65650; $lo->status = "F"; $lo->persist(); $labOrderId = $lo->labOrderId; $lt = new LabTest(); $lt->labOrderId = $labOrderId; $lt->observationTime = $date; $lt->status = "F"; $lt->persist(); $labTestId = $lt->labTestId; } $lr = new LabResult(); $lr->value = $line[2]; $lr->description = $line[0]; $lr->labTestId = $labTestId; //echo $lr->toString(); $lr->persist(); $counter++; } exit; }
public function setLabTestAction() { $params = $this->_getParam('labTest'); $labTest = new LabTest(); if (isset($params['labTestId'])) { $labTest->labTestId = (int) $params['labTestId']; $labTest->populate(); } $labTest->populateWithArray($params); $labTest->persist(); $data = __('Lab test successfully set.'); $json = Zend_Controller_Action_HelperBroker::getStaticHelper('json'); $json->suppressExit = true; $json->direct($data); }
/** * Adds an object to the instance pool. * * Propel keeps cached copies of objects in an instance pool when they are retrieved * from the database. In some cases -- especially when you override doSelect*() * methods in your stub classes -- you may need to explicitly add objects * to the cache in order to ensure that the same objects are always returned by doSelect*() * and retrieveByPK*() calls. * * @param LabTest $value A LabTest object. * @param string $key (optional) key to use for instance map (for performance boost if key was already calculated externally). */ public static function addInstanceToPool(LabTest $obj, $key = null) { if (Propel::isInstancePoolingEnabled()) { if ($key === null) { $key = (string) $obj->getId(); } // if key === null self::$instances[$key] = $obj; } }
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); }
public static function hl7Lab($hl7msg, $personId) { $hl7msg = preg_replace("/\r/", "\n", $hl7msg); $db = Zend_Registry::get('dbAdapter'); $xml = new HL7XML($hl7msg); $xml->parse(); file_put_contents('/tmp/xml', print_r($xml, true)); $orders = $xml->xml->xpath("//MSH"); $ordersCtr = count($orders); for ($o = 0; $o < $ordersCtr; $o++) { $orderXml = simplexml_load_string($orders[$o]->asXml()); $pid = 0; if (strlen((string) current($orderXml->xpath("//PID.3"))) > 0 && isset($mrn2pid[(string) current($orderXml->xpath("//PID.3"))])) { $pid = $mrn2pid[(string) current($orderXml->xpath("//PID.3"))]; } else { $sqlSelect = $db->select()->from("patient")->join("person", "person.person_id = patient.person_id")->where("patient.record_number = ?", (string) current($orderXml->xpath("//PID.3"))); $patients = $db->query($sqlSelect)->fetchAll(); if (!count($patients) > 0) { continue; } $pid = $patients[0]['person_id']; $mrn2pid[(string) current($orderXml->xpath("//PID.3"))] = $pid; if (!$pid > 0) { continue; } // last name, first name and DOB } $order = new LabOrder(); $order->_shouldAudit = false; $order->_cascadePersist = false; $order->patientId = $pid; //$order->type = ''; $order->status = 'F'; //$order->manualOrderDate = date('Y-m-d',strtotime((string)current($orderXml->xpath("//ORC/ORC.9")))); $orderingProvider = current($orderXml->xpath("//ORC.12.3")); $orderingProvider .= " " . current($orderXml->xpath("//ORC.12.2")); $orderingProvider .= " " . current($orderXml->xpath("//ORC.12.1")); $orderingProvider .= " (" . current($orderXml->xpath("//ORC.12.0")) . ")"; $order->ordering_provider = $orderingProvider; $order->persist(); $testsGroup = $orderXml->xpath("//ORC"); //var_dump($testsGroup);continue; $tgCtr = count($testsGroup); for ($x = 0; $x < $tgCtr; $x++) { //echo "test\n"; $test = simplexml_load_string($testsGroup[$x]->asXml()); //var_dump($test); $t = new LabTest(); $t->_shouldAudit = false; $t->_cascadePersist = false; $t->labOrderId = $order->labOrderId; $t->orderNum = (string) current($test->xpath("//OBR.2.0")); $t->filer_order_num = (string) current($test->xpath("//OBR.3.0")); $observation_time = preg_replace('/([0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]).*/', '${1}', current($test->xpath("//OBR.22"))); $t->observation_time = date('Y-m-d H:i:s', strtotime($observation_time)); $manual_order_date = preg_replace('/([0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]).*/', '${1}', current($test->xpath("//OBR.7"))); $order->manual_order_date = date('Y-m-d H:i:s', strtotime($manual_order_date)); $order->persist(); $specimen_received_time = preg_replace('/([0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]).*/', '${1}', current($test->xpath("//OBR.14"))); $t->specimen_received_time = date('Y-m-d H:i:s', strtotime($observation_time)); $report_time = preg_replace('/([0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]).*/', '${1}', current($test->xpath("//OBR.22"))); $t->report_time = date('Y-m-d H:i:s', strtotime($report_time)); //$t->ordering_provider = ; $t->service = (string) current($test->xpath("//OBR.4.1")) . " " . current($test->xpath("//OBR.4.2")); $t->component_code = (string) current($test->xpath("//OBR.3.0")); $t->status = (string) current($test->xpath("//OBR.25")); $t->clia_disclosure = (string) current($test->xpath("//OBR.21.0")) . " " . (string) current($test->xpath("//OBR.21.1")) . " " . (string) current($test->xpath("//OBR.21.2")) . " " . (string) current($test->xpath("//OBR.21.3")) . " " . (string) current($test->xpath("//OBR.21.4")) . " " . (string) current($test->xpath("//OBR.21.4")) . " " . (string) current($test->xpath("//OBR.21.5")) . " " . (string) current($test->xpath("//OBR.21.6")); $t->persist(); //echo $t->toString(); $resultsGroup = $test->xpath("//OBR/OBX"); //var_dump($t->toString()); continue; $rgCtr = count($resultsGroup); for ($i = 0; $i < $rgCtr; $i++) { $result = simplexml_load_string($resultsGroup[$i]->asXml()); //var_dump($result->asXml()); $lr = null; $lr = new LabResult(); $lr->_shouldAudit = false; $lr->_cascadePersist = false; $lr->labTestId = $t->labTestId; $lr->description = (string) current($result->xpath("//OBX.3.1")) . " " . (string) current($result->xpath("//OBX.3.2")) . "(" . (string) current($result->xpath("//OBX.3.0")) . ")"; //$lr->extra = ',$row['Group']); $lr->identifier = (string) current($result->xpath("//OBX.3")); $lr->reference_range = (string) current($result->xpath("//OBX.7")); $lr->abnormal_flag = (string) current($result->xpath("//OBX.8")); $lrobservation_time = preg_replace('/([0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]).*/', '${1}', current($test->xpath("//OBR.22"))); $lr->observation_time = date('Y-m-d H:i:s', strtotime($lrobservation_time)); $lr->units = (string) current($result->xpath("//OBX.6")); $lr->value = (string) current($result->xpath("//OBX.5")); $lr->result_status = (string) current($result->xpath("//OBX.11")); //echo $lr->toString() . "\n\n"; $lr->persist(); if (count($result->xpath("//NTE")) > 0) { $note = ""; foreach ($result->xpath("//NTE") as $noteLine) { $note .= trim($noteLine->{'NTE.3'}) . "\n"; } $labNote = new LabNote(); $labNote->_shouldAudit = false; $labNote->_cascadePersist = false; $labNote->labTestId = $t->labTestId; $labNote->labResultId = $lr->labResultId; $labNote->note = $note; $labNote->persist(); } } } } }
/** * Declares an association between this object and a LabTest object. * * @param LabTest $v * @return LabReport The current object (for fluent API support) * @throws PropelException */ public function setLabTest(LabTest $v = null) { if ($v === null) { $this->setLabTestId(NULL); } else { $this->setLabTestId($v->getId()); } $this->aLabTest = $v; // Add binding for other direction of this n:n relationship. // If this object has already been added to the LabTest object, it will not be re-added. if ($v !== null) { $v->addLabReport($this); } return $this; }