Exemple #1
0
 public function Process($msg = '', $addSocketCharacters = true)
 {
     //		try{
     $this->msg = $msg;
     $this->ackStatus = 'AA';
     $this->ackMessage = '';
     /**
      * Parse the HL7 Message
      */
     $hl7 = new HL7();
     $msg = $hl7->readMessage($this->msg);
     $application = $hl7->getSendingApplication();
     $facility = $hl7->getSendingFacility();
     $version = $hl7->getMsgVersionId();
     /**
      * check HL7 version
      */
     if ($version != '2.5.1') {
         $this->ackStatus = 'AR';
         $this->ackMessage = 'HL7 version unsupported';
     }
     /**
      * Check for IP address access
      */
     $this->recipient = $this->r->load(array('application_name' => $application))->one();
     if ($this->recipient === false) {
         $this->ackStatus = 'AR';
         $this->ackMessage = "This application '{$application}' Not Authorized";
     }
     /**
      *
      */
     if ($msg === false) {
         $this->ackStatus = 'AE';
         $this->ackMessage = 'Unable to parse HL7 message, please contact Support Desk';
     }
     /**
      *
      */
     $msgRecord = new stdClass();
     $msgRecord->msg_type = $hl7->getMsgType();
     $msgRecord->message = $this->msg;
     $msgRecord->foreign_facility = $hl7->getSendingFacility();
     $msgRecord->foreign_application = $hl7->getSendingApplication();
     $msgRecord->foreign_address = isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : '';
     $msgRecord->isOutbound = '0';
     $msgRecord->status = '2';
     $msgRecord->date_processed = date('Y-m-d H:i:s');
     $msgRecord = $this->m->save($msgRecord);
     $msgRecord = (array) $msgRecord['data'];
     if ($this->ackStatus == 'AA') {
         /**
          *
          */
         switch ($hl7->getMsgType()) {
             case 'ORU':
                 $this->ProcessORU($hl7, $msg, $msgRecord);
                 break;
             case 'ADT':
                 $this->ProcessADT($hl7, $msg, $msgRecord);
                 break;
             default:
                 break;
         }
     }
     /**
      *
      */
     $ack = new HL7();
     $msh = $ack->addSegment('MSH');
     $msh->setValue('3.1', 'GaiaEHR');
     // Sending Application
     $msh->setValue('4.1', 'Gaia');
     // Sending Facility
     $msh->setValue('9.1', 'ACK');
     $msh->setValue('11.1', 'P');
     // P = Production
     $msh->setValue('12.1', '2.5.1');
     // HL7 version
     $msa = $ack->addSegment('MSA');
     $msa->setValue('1', $this->ackStatus);
     // AA = Positive acknowledgment, AE = Application error, AR = Application reject
     $msa->setValue('2', $hl7->getMsgControlId());
     // Message Control ID from MSH
     $msa->setValue('3', $this->ackMessage);
     // Error Message
     $ackMsg = $ack->getMessage();
     $msgRecord['response'] = $ackMsg;
     $this->m->save((object) $msgRecord);
     // unset all the variables to release memory
     unset($ack, $hl7, $msg, $msgRecord, $oData, $result);
     return $addSocketCharacters ? "\v" . $ackMsg . chr(0x1c) . chr(0xd) : $ackMsg;
 }