[613] | 1 | HLPRS ;IRMFO-ALB/CJM -RTNs for parsing messages;03/24/2004 14:43
|
---|
| 2 | ;;1.6;HEALTH LEVEL SEVEN;**118**;Oct 13, 1995
|
---|
| 3 | ;
|
---|
| 4 | STARTMSG(MSG,IEN,HDR) ;
|
---|
| 5 | ;Description: This function begins the parsing of the message, parsing
|
---|
| 6 | ;the header and returning the individual values in the array HDR().
|
---|
| 7 | ;Input:
|
---|
| 8 | ; IEN - The internal entry number of the message in file 773.
|
---|
| 9 | ;Output:
|
---|
| 10 | ; Function returns 1 on success, 0 on failure. Failure would indicate that the message was not found.
|
---|
| 11 | ; 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!
|
---|
| 12 | ; HDR (pass by reference, optional) This array contains the results of parsing the message header.
|
---|
| 13 | K MSG,HDR
|
---|
| 14 | Q:'$G(IEN) 0
|
---|
| 15 | Q:'$$GETMSG^HLMSG(IEN,.MSG) 0
|
---|
| 16 | N SEG
|
---|
| 17 | M SEG=MSG("HDR")
|
---|
| 18 | Q:'$$PARSEHDR(.SEG,.HDR) 0
|
---|
| 19 | ;after parsing the header, reset these subscripts:
|
---|
| 20 | I HDR("SEGMENT TYPE")="BHS" D
|
---|
| 21 | .S MSG("BATCH")=1
|
---|
| 22 | .S MSG("BATCH","CURRENT MESSAGE")=0
|
---|
| 23 | E D
|
---|
| 24 | .S MSG("BATCH")=0
|
---|
| 25 | ;
|
---|
| 26 | K MSG("HDR")
|
---|
| 27 | M MSG("HDR")=HDR
|
---|
| 28 | Q 1
|
---|
| 29 | ;
|
---|
| 30 | NEXTSEG(MSG,SEG) ;
|
---|
| 31 | ;Description: Advances parsing to the next segment and returns the parsed values from that segment.
|
---|
| 32 | ;Input:
|
---|
| 33 | ; 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!
|
---|
| 34 | ;Output:
|
---|
| 35 | ; 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.
|
---|
| 36 | ; MSG - (pass by reference, required)
|
---|
| 37 | ; SEG - (pass by reference, required) The segment is returned in this array.
|
---|
| 38 | ;
|
---|
| 39 | N TEMP,CODES
|
---|
| 40 | K SEG
|
---|
| 41 | I '$$NEXTSEG^HLMSG(.MSG,.TEMP) Q 0
|
---|
| 42 | S CODES=MSG("HDR","ENCODING CHARACTERS")
|
---|
| 43 | Q $$PARSE^HLOPRS1(MSG("HDR","FIELD SEPARATOR"),$E(CODES,2),$E(CODES,1),$E(CODES,4),$E(CODES,3),.TEMP,.SEG)
|
---|
| 44 | ;
|
---|
| 45 | NEXTMSG(MSG,MSH) ;
|
---|
| 46 | ;Description: Advances to the next message within the batch, with the MSH segment returned.
|
---|
| 47 | ;Input:
|
---|
| 48 | ; 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!
|
---|
| 49 | ;OUTPUT:
|
---|
| 50 | ; Function returns 1 on success, 0 if there are no more messages
|
---|
| 51 | ; MSG - (pass by reference) (remember, off limits to the application developer!)
|
---|
| 52 | ; MSH - (pass by reference, required) Returns the parsed message header
|
---|
| 53 | ;
|
---|
| 54 | K MSH
|
---|
| 55 | N HDR
|
---|
| 56 | Q:'$$NEXTMSG^HLMSG(.MSG,.HDR) 0
|
---|
| 57 | Q:'$$PARSEHDR(.HDR,.MSH) 0
|
---|
| 58 | Q 1
|
---|
| 59 | ;
|
---|
| 60 | PARSEHDR(SEG,HDR) ;
|
---|
| 61 | ;Parses the segment (SEG, pass by reference) into the HDR() array using meaningful subscripts.
|
---|
| 62 | ;Input:
|
---|
| 63 | ; SEG (pass by reference, required) contains the segment in the format SEG(1), SEG(2),...
|
---|
| 64 | ;Output:
|
---|
| 65 | ; HDR (pass by reference, required) This array will contain all the individual values.
|
---|
| 66 | ; Function - returns 1 if the segment is indeed an MSH or BHS segment, 0 otherwise
|
---|
| 67 | ;
|
---|
| 68 | N VALUE,TO
|
---|
| 69 | K HDR
|
---|
| 70 | S VALUE=$E($G(SEG(1)),1,3)
|
---|
| 71 | I VALUE'="MSH",VALUE'="BHS" Q 0
|
---|
| 72 | S HDR("SEGMENT TYPE")=VALUE
|
---|
| 73 | S HDR("FIELD SEPARATOR")=$E(SEG(1),4)
|
---|
| 74 | Q:$L(HDR("FIELD SEPARATOR"))'=1 0
|
---|
| 75 | S VALUE=$E(SEG(1),5,8)
|
---|
| 76 | S HDR("ENCODING CHARACTERS")=VALUE
|
---|
| 77 | S HDR("COMPONENT SEPARATOR")=$E(VALUE,1)
|
---|
| 78 | S HDR("REPETITION SEPARATOR")=$E(VALUE,2)
|
---|
| 79 | S HDR("ESCAPE CHARACTER")=$E(VALUE,3)
|
---|
| 80 | S HDR("SUBCOMPONENT SEPARATOR")=$E(VALUE,4)
|
---|
| 81 | I $$PARSE^HLOPRS1(HDR("FIELD SEPARATOR"),$E(VALUE,2),$E(VALUE,1),$E(VALUE,4),$E(VALUE,3),.SEG,.TO) D
|
---|
| 82 | .S HDR("SENDING APPLICATION")=$$GET^HLOPRS(.TO,3)
|
---|
| 83 | .S HDR("SENDING FACILITY",1)=$$GET^HLOPRS(.TO,4,1)
|
---|
| 84 | .S HDR("SENDING FACILITY",2)=$$GET^HLOPRS(.TO,4,2)
|
---|
| 85 | .S HDR("SENDING FACILTY",3)=$$GET^HLOPRS(.TO,4,3)
|
---|
| 86 | .S HDR("RECEIVING APPLICATION")=$$GET^HLOPRS(.TO,5)
|
---|
| 87 | .S HDR("RECEIVING FACILITY",1)=$$GET^HLOPRS(.TO,6,1)
|
---|
| 88 | .S HDR("RECEIVING FACILITY",2)=$$GET^HLOPRS(.TO,6,2)
|
---|
| 89 | .S HDR("RECEIVING FACILITY",3)=$$GET^HLOPRS(.TO,6,3)
|
---|
| 90 | .S HDR("DT/TM OF MESSAGE")=$$FMDATE^HLFNC($$GET^HLOPRS(.TO,7))
|
---|
| 91 | .S HDR("SECURITY")=$$GET^HLOPRS(.TO,8)
|
---|
| 92 | .I HDR("SEGMENT TYPE")="MSH" D
|
---|
| 93 | ..S HDR("MESSAGE TYPE")=$$GET^HLOPRS(.TO,9,1)
|
---|
| 94 | ..S HDR("EVENT")=$$GET^HLOPRS(.TO,9,2)
|
---|
| 95 | ..S HDR("MESSAGE STRUCTURE")=$$GET^HLOPRS(.TO,9,3)
|
---|
| 96 | ..S HDR("MESSAGE CONTROL ID")=$$GET^HLOPRS(.TO,10)
|
---|
| 97 | ..S HDR("PROCESSING ID")=$$GET^HLOPRS(.TO,11)
|
---|
| 98 | ..S HDR("PROCESSING MODE")=$$GET^HLOPRS(.TO,11,2)
|
---|
| 99 | ..S HDR("VERSION")=$$GET^HLOPRS(.TO,12)
|
---|
| 100 | ..S HDR("CONTINUATION POINTER")=$$GET^HLOPRS(.TO,14)
|
---|
| 101 | ..S HDR("ACCEPT ACK TYPE")=$$GET^HLOPRS(.TO,15)
|
---|
| 102 | ..S HDR("APP ACK TYPE")=$$GET^HLOPRS(.TO,16)
|
---|
| 103 | ..S HDR("COUNTRY")=$$GET^HLOPRS(.TO,17)
|
---|
| 104 | .I HDR("SEGMENT TYPE")="BHS" D
|
---|
| 105 | ..S VALUE=$$GET^HLOPRS(.TO,9)
|
---|
| 106 | ..S HDR("BATCH NAME/ID/TYPE")=VALUE
|
---|
| 107 | ..S HDR("PROCESSING ID")=$S((VALUE["PROCESSING ID="):$E($P(VALUE,"PROCESSING ID=",2),1),1:$$GET^HLOPRS(.TO,9,2))
|
---|
| 108 | ..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))
|
---|
| 109 | ..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))
|
---|
| 110 | ..S HDR("BATCH COMMENT")=$$GET^HLOPRS(.TO,10)
|
---|
| 111 | ..S HDR("BATCH CONTROL ID")=$$GET^HLOPRS(.TO,11)
|
---|
| 112 | ..S HDR("REFERENCE BATCH CONTROL ID")=$$GET^HLOPRS(.TO,12)
|
---|
| 113 | ..;
|
---|
| 114 | Q 1
|
---|