Esempio n. 1
0
 public function createNewEmergency()
 {
     $patient = $this->patient->createNewPatientOnlyName('EMER');
     if ($patient['success']) {
         $this->pid = $patient['patient']['pid'];
         /**
          * send new patient to the emergency pool area
          */
         $params = new stdClass();
         $params->pid = $this->pid;
         $params->priority = $this->priority;
         $params->sendTo = 3;
         $this->poolArea->sendPatientToPoolArea($params);
         /**
          * create new encounter
          */
         $params = new stdClass();
         $params->pid = $this->pid;
         $params->brief_description = '***EMERGENCY***';
         $params->visit_category = 'Emergency';
         $params->priority = $this->priority;
         $params->service_date = Time::getLocalTime();
         $params->open_uid = $_SESSION['user']['id'];
         $encounter = $this->encounter->createEncounter($params);
         $this->eid = $encounter['encounter']['eid'];
         /**
          * log the emergency
          */
         $this->logEmergency();
         /*
          * update patient first name to EMERGENCY- encounter id
          */
         $data['fname'] = 'EMER-' . $this->emergencyId;
         $this->db->setSQL($this->db->sqlBind($data, 'patient', 'U', array('pid' => $this->pid)));
         $this->db->execOnly();
         return array('success' => true, 'emergency' => array('pid' => $this->pid, 'eid' => $this->eid, 'name' => 'EMER-' . $this->emergencyId, 'priority' => $params->priority));
     } else {
         return array('success' => false, 'error' => $patient['error']);
     }
 }
Esempio n. 2
0
 /**
  * @param HL7 $hl7
  * @param ADT $msg
  * @param stdClass $msgRecord
  */
 protected function ProcessADT($hl7, $msg, $msgRecord)
 {
     $evt = $hl7->getMsgEventType();
     if ($evt == 'A01') {
         /**
          * Admit Visit
          */
     } elseif ($evt == 'A04') {
         /**
          * Register a Patient
          */
         $patientData = $this->PidToPatient($msg->data['PID'], $hl7);
         $patient = $this->p->load($patientData[$this->updateKey])->one();
         if ($patient === false) {
             $this->ackStatus = 'AR';
             $this->ackMessage = 'Unable to find patient ' . $patientData[$this->updateKey];
         }
         $patient = array_merge($patient, $patientData);
         $patient = $this->p->save((object) $patient);
         $this->InsuranceGroupHandler($msg->data['INSURANCE'], $hl7, $patient);
         return;
     } elseif ($evt == 'A08') {
         /**
          * Update Patient Information
          */
         $patientData = $this->PidToPatient($msg->data['PID'], $hl7);
         $patient = $this->p->load($patientData[$this->updateKey])->one();
         if ($patient === false) {
             $this->ackStatus = 'AR';
             $this->ackMessage = 'Unable to find patient ' . $patientData[$this->updateKey];
         }
         $patient = array_merge($patient, $patientData);
         $patient = $this->p->save((object) $patient);
         $this->InsuranceGroupHandler($msg->data['INSURANCE'], $hl7, $patient);
         return;
     } elseif ($evt == 'A09') {
         /**
          * Patient Departing - Tracking
          * PV1-3 - Assigned Patient Location
          * PV1-6 - Prior Patient Location
          * PV1-11 - Temporary Location
          * PV1-42 - Pending Location
          * PV1-43 - Prior Temporary Location
          */
         $PID = $msg->data['PID'];
         $PV1 = $msg->data['PV1'];
         $filter = array();
         if ($PID[3][4][1] == $this->getAssigningAuthority()) {
             $filter['pid'] = $PID[3][1];
         } else {
             $filter['pubpid'] = $PID[3][1];
         }
         $patient = $this->p->load($filter)->one();
         if ($patient === false) {
             $this->ackStatus = 'AR';
             $this->ackMessage = 'Unable to find patient ' . $PID[3][1];
         }
         $newAreaId = $PV1[3][1];
         //$oldAreaId = $PV1[6][1];
         $PoolArea = new PoolArea();
         $areas = $PoolArea->getAreasArray();
         if (!array_key_exists($newAreaId, $areas)) {
             $this->ackStatus = 'AR';
             $this->ackMessage = 'Unable to find Area ID ' . $newAreaId;
             return;
         }
         $params = new stdClass();
         $params->pid = $patient['pid'];
         $params->sendTo = $newAreaId;
         $PoolArea->sendPatientToPoolArea($params);
         unset($params);
         return;
     } elseif ($evt == 'A10') {
         /**
          * Patient Arriving - Tracking
          * PV1-3  - As signed Patient Location
          * PV1-6  - Prior Patient Location
          * PV1-11 - Temporary Location
          * PV1-43 - Prior Temporary Location
          */
         $PID = $msg->data['PID'];
         $PV1 = $msg->data['PV1'];
         $filter = array();
         if ($PID[3][4][1] == $this->getAssigningAuthority()) {
             $filter['pid'] = $PID[3][1];
         } else {
             $filter['pubpid'] = $PID[3][1];
         }
         $patient = $this->p->load($filter)->one();
         if ($patient === false) {
             $this->ackStatus = 'AR';
             $this->ackMessage = 'Unable to find patient ' . $PID[3][1];
         }
         $newAreaId = $PV1[3][1];
         //$oldAreaId = $PV1[6][1];
         $PoolArea = new PoolArea();
         $areas = $PoolArea->getAreasArray();
         if (!array_key_exists($newAreaId, $areas)) {
             $this->ackStatus = 'AR';
             $this->ackMessage = 'Unable to find Area ID ' . $newAreaId;
             return;
         }
         $params = new stdClass();
         $params->pid = $patient['pid'];
         $params->sendTo = $newAreaId;
         $PoolArea->sendPatientToPoolArea($params);
         unset($params);
         return;
     } elseif ($evt == 'A18') {
         /**
          * Merge Patient Information
          * PID-2.1 <= MRG-4.1
          */
         $pid = $msg->data['PATIENT']['PID'][2][1];
         $mrg = $msg->data['PATIENT']['MRG'][4][1];
         $aPatient = $this->p->load(array('pubpid' => $pid))->one();
         $bPatient = $this->p->load(array('pubpid' => $mrg))->one();
         $this->MergeHandler($aPatient, $bPatient, $pid, $mrg);
         return;
     } elseif ($evt == 'A28') {
         /**
          * Add Person or Patient Information
          * PID-2.1 <= MRG-4.1
          */
         $patientData = $this->PidToPatient($msg->data['PID'], $hl7);
         $patientData['pubpid'] = $patientData['pid'];
         $patientData['pid'] = 0;
         $patient = $this->p->save((object) $patientData);
         $this->InsuranceGroupHandler($msg->data['INSURANCE'], $hl7, $patient);
         return;
     } elseif ($evt == 'A29') {
         /**
          * Delete Person Information
          */
     } elseif ($evt == 'A31') {
         /**
          * Update Person Information
          */
         $patientData = $this->PidToPatient($msg->data['PID'], $hl7);
         $patient = $this->p->load($patientData[$this->updateKey])->one();
         if ($patient === false) {
             $this->ackStatus = 'AR';
             $this->ackMessage = 'Unable to find patient ' . $patientData[$this->updateKey];
         }
         $patient = array_merge($patient, $patientData);
         $patient = $this->p->save((object) $patient);
         $this->InsuranceGroupHandler($msg->data['INSURANCE'], $hl7, $patient);
         return;
     } elseif ($evt == 'A32') {
         /** Cancel Patient Arriving - Tracking **/
         return;
     } elseif ($evt == 'A33') {
         /** Cancel Patient Departing - Tracking **/
         return;
     } elseif ($evt == 'A39') {
         /**
          * Merge Person - Patient ID (Using External ID)
          * PID-2.1 <= MRG-4.1
          */
         $pid = $msg->data['PATIENT']['PID'][2][1];
         $mrg = $msg->data['PATIENT']['MRG'][4][1];
         $aPatient = $this->p->load(array('pubpid' => $pid))->one();
         $bPatient = $this->p->load(array('pubpid' => $mrg))->one();
         $this->MergeHandler($aPatient, $bPatient, $pid, $mrg);
         return;
     } elseif ($evt == 'A40') {
         /**
          * Merge Patient - Patient Identifier List
          * PID-3.1 <= MRG-1.1
          */
         $pid = $msg->data['PATIENT']['PID'][3][1];
         $mrg = $msg->data['PATIENT']['MRG'][1][1];
         $aPatient = $this->p->load(array('pid' => $pid))->one();
         $bPatient = $this->p->load(array('pid' => $mrg))->one();
         $this->MergeHandler($aPatient, $bPatient, $pid, $mrg);
         return;
     } elseif ($evt == 'A41') {
         /**
          * Merge Account - Patient Account Number
          * PID-18.1 <= MRG-3.1
          */
         $pid = $msg->data['PATIENT']['PID'][18][1];
         $mrg = $msg->data['PATIENT']['MRG'][3][1];
         $aPatient = $this->p->load(array('pubaccount' => $pid))->one();
         $bPatient = $this->p->load(array('pubaccount' => $mrg))->one();
         $this->MergeHandler($aPatient, $bPatient, $pid, $mrg);
         return;
     }
     /**
      * Un handle event error
      */
     $this->ackStatus = 'AR';
     $this->ackMessage = 'Unable to handle ADT_' . $evt;
 }