Home   Package List   Routine Alphabetical List   Global Alphabetical List   FileMan Files List   FileMan Sub-Files List   Package Component Lists   Package-Namespace Mapping  
Routine: HLPRS

HLPRS.m

Go to the documentation of this file.
  1. HLPRS ;IRMFO-ALB/CJM -RTNs for parsing messages;03/24/2004 14:43
  1. ;;1.6;HEALTH LEVEL SEVEN;**118**;Oct 13, 1995
  1. ;
  1. STARTMSG(MSG,IEN,HDR) ;
  1. ;Description: This function begins the parsing of the message, parsing
  1. ;the header and returning the individual values in the array HDR().
  1. ;Input:
  1. ; IEN - The internal entry number of the message in file 773.
  1. ;Output:
  1. ; Function returns 1 on success, 0 on failure. Failure would indicate that the message was not found.
  1. ; MSG - (pass by reference, required) This array is used by the HL7 package to track the progress of parsing the message. The application MUST NOT touch it!
  1. ; HDR (pass by reference, optional) This array contains the results of parsing the message header.
  1. K MSG,HDR
  1. Q:'$G(IEN) 0
  1. Q:'$$GETMSG^HLMSG(IEN,.MSG) 0
  1. N SEG
  1. M SEG=MSG("HDR")
  1. Q:'$$PARSEHDR(.SEG,.HDR) 0
  1. ;after parsing the header, reset these subscripts:
  1. I HDR("SEGMENT TYPE")="BHS" D
  1. .S MSG("BATCH")=1
  1. .S MSG("BATCH","CURRENT MESSAGE")=0
  1. E D
  1. .S MSG("BATCH")=0
  1. ;
  1. K MSG("HDR")
  1. M MSG("HDR")=HDR
  1. Q 1
  1. ;
  1. NEXTSEG(MSG,SEG) ;
  1. ;Description: Advances parsing to the next segment and returns the parsed values from that segment.
  1. ;Input:
  1. ; MSG - (pass by reference, required) This array is used by the HL7 package to track the current position in the message. The application MUST NOT touch it!
  1. ;Output:
  1. ; Function returns 1 on success, 0 if there are no more segments in this message. For batch messages, a return value of 0 does not preclude the possibility that there are additional individual messages within the batch.
  1. ; MSG - (pass by reference, required)
  1. ; SEG - (pass by reference, required) The segment is returned in this array.
  1. ;
  1. N TEMP,CODES
  1. K SEG
  1. I '$$NEXTSEG^HLMSG(.MSG,.TEMP) Q 0
  1. S CODES=MSG("HDR","ENCODING CHARACTERS")
  1. Q $$PARSE^HLOPRS1(MSG("HDR","FIELD SEPARATOR"),$E(CODES,2),$E(CODES,1),$E(CODES,4),$E(CODES,3),.TEMP,.SEG)
  1. ;
  1. NEXTMSG(MSG,MSH) ;
  1. ;Description: Advances to the next message within the batch, with the MSH segment returned.
  1. ;Input:
  1. ; MSG (pass by reference, required) This array is used by the HL7 package to track the current position in the message. The application MUST NOT touch it!
  1. ;OUTPUT:
  1. ; Function returns 1 on success, 0 if there are no more messages
  1. ; MSG - (pass by reference) (remember, off limits to the application developer!)
  1. ; MSH - (pass by reference, required) Returns the parsed message header
  1. ;
  1. K MSH
  1. N HDR
  1. Q:'$$NEXTMSG^HLMSG(.MSG,.HDR) 0
  1. Q:'$$PARSEHDR(.HDR,.MSH) 0
  1. Q 1
  1. ;
  1. PARSEHDR(SEG,HDR) ;
  1. ;Parses the segment (SEG, pass by reference) into the HDR() array using meaningful subscripts.
  1. ;Input:
  1. ; SEG (pass by reference, required) contains the segment in the format SEG(1), SEG(2),...
  1. ;Output:
  1. ; HDR (pass by reference, required) This array will contain all the individual values.
  1. ; Function - returns 1 if the segment is indeed an MSH or BHS segment, 0 otherwise
  1. ;
  1. N VALUE,TO
  1. K HDR
  1. S VALUE=$E($G(SEG(1)),1,3)
  1. I VALUE'="MSH",VALUE'="BHS" Q 0
  1. S HDR("SEGMENT TYPE")=VALUE
  1. S HDR("FIELD SEPARATOR")=$E(SEG(1),4)
  1. Q:$L(HDR("FIELD SEPARATOR"))'=1 0
  1. S VALUE=$E(SEG(1),5,8)
  1. S HDR("ENCODING CHARACTERS")=VALUE
  1. S HDR("COMPONENT SEPARATOR")=$E(VALUE,1)
  1. S HDR("REPETITION SEPARATOR")=$E(VALUE,2)
  1. S HDR("ESCAPE CHARACTER")=$E(VALUE,3)
  1. S HDR("SUBCOMPONENT SEPARATOR")=$E(VALUE,4)
  1. I $$PARSE^HLOPRS1(HDR("FIELD SEPARATOR"),$E(VALUE,2),$E(VALUE,1),$E(VALUE,4),$E(VALUE,3),.SEG,.TO) D
  1. .S HDR("SENDING APPLICATION")=$$GET^HLOPRS(.TO,3)
  1. .S HDR("SENDING FACILITY",1)=$$GET^HLOPRS(.TO,4,1)
  1. .S HDR("SENDING FACILITY",2)=$$GET^HLOPRS(.TO,4,2)
  1. .S HDR("SENDING FACILTY",3)=$$GET^HLOPRS(.TO,4,3)
  1. .S HDR("RECEIVING APPLICATION")=$$GET^HLOPRS(.TO,5)
  1. .S HDR("RECEIVING FACILITY",1)=$$GET^HLOPRS(.TO,6,1)
  1. .S HDR("RECEIVING FACILITY",2)=$$GET^HLOPRS(.TO,6,2)
  1. .S HDR("RECEIVING FACILITY",3)=$$GET^HLOPRS(.TO,6,3)
  1. .S HDR("DT/TM OF MESSAGE")=$$FMDATE^HLFNC($$GET^HLOPRS(.TO,7))
  1. .S HDR("SECURITY")=$$GET^HLOPRS(.TO,8)
  1. .I HDR("SEGMENT TYPE")="MSH" D
  1. ..S HDR("MESSAGE TYPE")=$$GET^HLOPRS(.TO,9,1)
  1. ..S HDR("EVENT")=$$GET^HLOPRS(.TO,9,2)
  1. ..S HDR("MESSAGE STRUCTURE")=$$GET^HLOPRS(.TO,9,3)
  1. ..S HDR("MESSAGE CONTROL ID")=$$GET^HLOPRS(.TO,10)
  1. ..S HDR("PROCESSING ID")=$$GET^HLOPRS(.TO,11)
  1. ..S HDR("PROCESSING MODE")=$$GET^HLOPRS(.TO,11,2)
  1. ..S HDR("VERSION")=$$GET^HLOPRS(.TO,12)
  1. ..S HDR("CONTINUATION POINTER")=$$GET^HLOPRS(.TO,14)
  1. ..S HDR("ACCEPT ACK TYPE")=$$GET^HLOPRS(.TO,15)
  1. ..S HDR("APP ACK TYPE")=$$GET^HLOPRS(.TO,16)
  1. ..S HDR("COUNTRY")=$$GET^HLOPRS(.TO,17)
  1. .I HDR("SEGMENT TYPE")="BHS" D
  1. ..S VALUE=$$GET^HLOPRS(.TO,9)
  1. ..S HDR("BATCH NAME/ID/TYPE")=VALUE
  1. ..S HDR("PROCESSING ID")=$S((VALUE["PROCESSING ID="):$E($P(VALUE,"PROCESSING ID=",2),1),1:$$GET^HLOPRS(.TO,9,2))
  1. ..S HDR("ACCEPT ACK TYPE")=$S((VALUE["ACCEPT ACK TYPE="):$E($P(VALUE,"ACCEPT ACK TYPE=",2),1,2),1:$$GET^HLOPRS(.TO,9,3,1,2))
  1. ..S HDR("APP ACK TYPE")=$S((VALUE["APP ACK TYPE="):$E($P(VALUE,"APP ACK TYPE=",2),1,2),1:$$GET^HLOPRS(.TO,9,4,1,2))
  1. ..S HDR("BATCH COMMENT")=$$GET^HLOPRS(.TO,10)
  1. ..S HDR("BATCH CONTROL ID")=$$GET^HLOPRS(.TO,11)
  1. ..S HDR("REFERENCE BATCH CONTROL ID")=$$GET^HLOPRS(.TO,12)
  1. ..;
  1. Q 1