- HLOAPI ;ALB/CJM-HL7 - Developer API's for sending & receiving messages ;09/13/2006
- ;;1.6;HEALTH LEVEL SEVEN;**126,133**;Oct 13, 1995;Build 13
- ;Per VHA Directive 2004-038, this routine should not be modified.
- ;
- NEWMSG(PARMS,HLMSTATE,ERROR) ;
- ;Starts a new message.
- ;Input:
- ; PARMS( *pass by reference*
- ; "COUNTRY")=3 character country code (optional)
- ; "CONTINUATION POINTER" -indicates a fragmented message
- ; "EVENT")=3 character event type (required)
- ; "FIELD SEPARATOR")=field separator (optional, defaults to "|")
- ; "ENCODING CHARACTERS")= 4 HL7 encoding characters (optional,defaults to "^~\&")
- ; "MESSAGE STRUCTURE" - MSH 9, component 3 - a code from the standard HL7 table (optional)
- ; "MESSAGE TYPE")=3 character message type (required)
- ; "PROCESSING MODE" - MSH 11, component 2 - a 1 character code (optional)
- ; "VERSION")=the HL7 Version ID, for example, "2.4" (optional, defaults to 2.4)
- ;Output:
- ; Function- returns 1 on success, 0 on failure
- ; HLMSTATE() - (pass by reference, required) This array is used by the HL7 package to track the progress of the message. The application MUST NOT touch it!
- ; PARMS - left defined when the function returns
- ; ERROR (optional, pass by reference) - returns an error message on failure
- ;
- ;
- N DATA,I,SYSTEM,SUCCESS
- S SUCCESS=0
- K ERROR,HLMSTATE
- D
- .I $L($G(PARMS("PROCESSING MODE"))),$L(PARMS("PROCESSING MODE"))'=1 S ERROR="INVALID PROCESSING MODE" Q
- .I $L($G(PARMS("COUNTRY"))),$L(PARMS("COUNTRY"))'=3 S ERROR="INVALID COUNTRY CODE" Q
- .I $L($G(PARMS("EVENT")))'=3 S ERROR="INVALID EVENT CODE" Q
- .I $L($G(PARMS("MESSAGE TYPE")))'=3 S ERROR="INVALID MESSAGE TYPE" Q
- .I $L($G(PARMS("ENCODING CHARACTERS"))),$L(PARMS("ENCODING CHARACTERS"))'=4 S ERROR="INVALID ENCODING CHARACTERS" Q
- .I $L($G(PARMS("FIELD SEPARATOR"))),$L(PARMS("FIELD SEPARATOR"))'=1 S ERROR="INVALID FIELD SEPARATOR" Q
- .I '$L($G(PARMS("FIELD SEPARATOR"))) S PARMS("FIELD SEPARATOR")="|"
- .I '$L($G(PARMS("ENCODING CHARACTERS"))) S PARMS("ENCODING CHARACTERS")="^~\&"
- .I $G(PARMS("VERSION"))="" S PARMS("VERSION")="2.4"
- .I ($L($G(PARMS("VERSION")))>20) S ERROR="VERSION > 20 CHARACTERS" Q
- .F I="MESSAGE TYPE","EVENT","COUNTRY","FIELD SEPARATOR","ENCODING CHARACTERS","VERSION","CONTINUATION POINTER","MESSAGE STRUCTURE","PROCESSING MODE" S HLMSTATE("HDR",I)=$G(PARMS(I))
- .S HLMSTATE("BATCH")=0 ;not a batch
- .S HLMSTATE("DIRECTION")="OUT"
- .S HLMSTATE("IEN")=""
- .S HLMSTATE("BODY")="" ;record not yet created
- .S HLMSTATE("CURRENT SEGMENT")=0 ;no segments cached
- .S HLMSTATE("UNSTORED LINES")=0 ;nothing in cache
- .S HLMSTATE("LINE COUNT")=0
- .D GETSYS(.HLMSTATE)
- .S SUCCESS=1
- Q SUCCESS
- ;
- NEWBATCH(PARMS,HLMSTATE,ERROR) ;
- ;Starts a new batch message.
- ;Input:
- ; PARMS( *pass by reference*
- ; "COUNTRY")=3 character country code (optional)
- ; "FIELD SEPARATOR")=field separator (optional, defaults to "|")
- ; "ENCODING CHARACTERS")= 4 HL7 encoding characters (optional,defaults to "^~\&")
- ; "VERSION")=the HL7 Version ID, for example, "2.4" (optional, defaults to 2.4)
- ;Output:
- ; Function - returns 1 on success, 0 on failure
- ; PARMS - left defined when the function returns
- ; HLMSTATE() - (pass by reference, required) This array is used by the HL7 package to track the progress of the message. The application MUST NOT touch it!
- ; ERROR (optional, pass by reference) - returns an error message on failure
- ;
- ;
- N DATA,I,SYSTEM,SUCCESS
- S SUCCESS=0
- K ERROR,HLMSTATE
- D
- .I $L($G(PARMS("COUNTRY"))),$L(PARMS("COUNTRY"))'=3 S ERROR="INVALID COUNTRY CODE" Q
- .I $L($G(PARMS("ENCODING CHARACTERS"))),$L(PARMS("ENCODING CHARACTERS"))'=4 S ERROR="INVALID ENCODING CHARACTERS" Q
- .I $L($G(PARMS("FIELD SEPARATOR"))),$L(PARMS("FIELD SEPARATOR"))'=1 S ERROR="INVALID FIELD SEPARATOR" Q
- .I '$L($G(PARMS("FIELD SEPARATOR"))) S PARMS("FIELD SEPARATOR")="|"
- .I '$L($G(PARMS("ENCODING CHARACTERS"))) S PARMS("ENCODING CHARACTERS")="^~\&"
- .I $G(PARMS("VERSION"))="" S PARMS("VERSION")="2.4"
- .I ($L(PARMS("VERSION"))>20) S ERROR="VERSION > 20 CHARACTERS" Q
- .F I="COUNTRY","FIELD SEPARATOR","ENCODING CHARACTERS","VERSION" S HLMSTATE("HDR",I)=$G(PARMS(I))
- .S HLMSTATE("IEN")=""
- .S HLMSTATE("BODY")="" ;msg not yet stored
- .S HLMSTATE("BATCH")=1
- .S HLMSTATE("DIRECTION")="OUT"
- .S HLMSTATE("BATCH","CURRENT MESSAGE")=0 ;no messages in batch
- .S HLMSTATE("CURRENT SEGMENT")=0 ;no segments in cache
- .S HLMSTATE("UNSTORED LINES")=0 ;nothing in cache
- .S HLMSTATE("LINE COUNT")=0 ;no lines within message stored
- .D GETSYS(.HLMSTATE)
- .S SUCCESS=1
- Q SUCCESS
- ;
- SET(SEG,VALUE,FIELD,COMP,SUBCOMP,REP) ;
- ;Sets a value to the array SEG(), used for building segments.
- ;Input:
- ; SEG - (required, pass by reference) - this is the array where the segment is being built.
- ; VALUE - the individual value to be set into the segment
- ; FIELD - the sequence # of the field (optional, defaults to 0)
- ; *NOTE: FIELD=0 is used to denote the segment type.
- ; COMP - the # of the component (optional, defaults to 1)
- ; SUBCOMP - the # of the subcomponent (optional, defaults to 1)
- ; REP - the occurrence# (optional, defaults to 1) For a non-repeating field, the occurrence # need not be provided, because it would be 1.
- ;Output:
- ; SEG array
- ;
- ; Example:
- ; D SET(.SEG,"MSA",0) creates an MSA segment
- ; D SET(.SEG,"AE",1) will place the value into the array position
- ; reserved for the 1st field,1st occurence,1st comp,1st subcomp
- ;
- ;Implementation Note - This format is used for the segment array built by calls to SET: SEGMENT(<SEQ #>,<occurrence #>,<component #>,<subcomponent #>)=<subcomponent value>
- ;
- S:'$G(FIELD) FIELD=0
- S:'$G(COMP) COMP=1
- S:'$G(SUBCOMP) SUBCOMP=1
- S:'$G(REP) REP=1
- S SEG(FIELD,REP,COMP,SUBCOMP)=$G(VALUE)
- Q
- ;
- ADDSEG(HLMSTATE,SEG,ERROR) ;Adds a segment to the message.
- ;Input:
- ; HLMSTATE() - (pass by reference, required) This array is used by the HL7 package to track the progress of the message. The application MUST NOT touch it!
- ; SEG() - (pass by reference, required) Contains the data. It must be built by calls to SET prior to calling $$ADDSEG.
- ;
- ;Note#1: The message control segments, including the MSH and BHS segments, are added automatically.
- ;Note#2: The 0th field must be a 3 character segment type
- ;Note#3: ***SEG is killed upon successfully adding the segment***
- ;
- ;Output:
- ; HLMSTATE() - (pass by reference, required) This array is used by the HL7 package to track the progress of the message.
- ; FUNCTION - returns 1 on success, 0 on failure
- ; ERROR (optional, pass by reference) - returns an error message on failure
- ;
- ;
- K ERROR
- N TOARY,TYPE
- ;
- S TYPE=$G(SEG(0,1,1,1)) ;segment type
- ;
- ;if a 'generic' app ack MSA was built, add it as the first segment before this one
- I $D(HLMSTATE("MSA")) D
- .I TYPE'="MSA" S TOARY(1)=HLMSTATE("MSA") D ADDSEG^HLOMSG(.HLMSTATE,.TOARY) K TOARY
- .K HLMSTATE("MSA")
- ;
- I ($L(TYPE)'=3) S ERROR="INVALID SEGMENT TYPE" Q 0
- I (TYPE="MSH")!(TYPE="BHS")!(TYPE="BTS")!(TYPE="FHS")!(TYPE="FTS") S ERROR="INVALID SEGMENT TYPE" Q 0
- I HLMSTATE("BATCH"),'HLMSTATE("BATCH","CURRENT MESSAGE") S ERROR="NO MESSAGES IN BATCH, SO SEGMENTS NOT ALLOWED" Q 0
- I $$BUILDSEG^HLOPBLD(.HLMSTATE,.SEG,.TOARY,.ERROR) D ADDSEG^HLOMSG(.HLMSTATE,.TOARY) K SEG Q 1
- Q 0
- ;
- ADDMSG(HLMSTATE,PARMS,ERROR) ;
- ;Begins a new message in the batch.
- ;Input:
- ; HLMSTATE() - (pass by reference, required) This array is used by the HL7 package to track the progress of the message. The application MUST NOT touch it!
- ; PARMS( *pass by reference*
- ; "EVENT")=3 character event type (required)
- ; "MESSAGE TYPE")=3 character message type (required)
- ;
- ;Output:
- ; FUNCTION - returns 1 on success, 0 on failure
- ; HLMSTATE() - (pass by reference, required) This array is used by the HL7 package to track the progress of the message.
- ; PARMS - left defined when this function returns
- ; ERROR (optional, pass by reference) - returns an error message on failure
- ;
- N I
- K ERROR
- ;if a 'generic' app ack MSA was built, add it as the first segment before this one
- I $D(HLMSTATE("MSA")) D
- .I TYPE'="MSA" N TOARY M TOARY=HLMSTATE("MSA") D ADDSEG^HLOMSG(.HLMSTATE,.TOARY) K TOARY
- .K HLMSTATE("MSA")
- I $L($G(PARMS("EVENT")))'=3 S ERROR="EVENT TYPE INVALID" Q 0
- I $L($G(PARMS("MESSAGE TYPE")))'=3 S ERROR="MESSAGE TYPE INVALID" Q 0
- D ADDMSG^HLOMSG(.HLMSTATE,.PARMS)
- Q 1
- ;
- GETSYS(HLMSTATE) ;
- N SYS,SUB
- D SYSPARMS^HLOSITE(.SYS)
- F SUB="DOMAIN","STATION","PROCESSING ID","MAXSTRING","ERROR PURGE","NORMAL PURGE","PORT" S HLMSTATE("SYSTEM",SUB)=SYS(SUB)
- S HLMSTATE("SYSTEM","BUFFER")=SYS("USER BUFFER")
- Q
- ;
- MOVEMSG(HLMSTATE,ARY) ;
- ;If a message was built in the 'old' way, and resides in an array, this routine will move it into file 777 (HL7 Message Body)
- ;Input:
- ; HLMSTATE (pass by reference) the array created by calling $$NEWMSG or $$NEWBATCH
- ; ARY - is the name of the array, local or global, where the message was built, used to reference the array by indirection.
- ;
- N I S I=0
- F S I=$O(@ARY@(I)) Q:'I D
- .N SEG,J,J2
- .S J=0,J2=1
- .S SEG(J2)=@ARY@(I)
- .F S J=$O(@ARY@(I,J)) Q:'J S J2=J2+1,SEG(J2)=@ARY@(I,J)
- .I 'HLMSTATE("BATCH") D
- ..D ADDSEG^HLOMSG(.HLMSTATE,.SEG)
- .E D
- ..I $E(SEG(1),1,3)="MSH" D
- ...D SPLITHDR^HLOSRVR1(.SEG)
- ...D ADDMSG2^HLOMSG(.HLMSTATE,.SEG)
- ..E D ADDSEG^HLOMSG(.HLMSTATE,.SEG)
- ;
- ;signal SENDACK^HLOAPI2 that the application built its own msg
- K HLMSTATE("MSA")
- Q
- HLOAPI ;ALB/CJM-HL7 - Developer API's for sending & receiving messages ;09/13/2006
- +1 ;;1.6;HEALTH LEVEL SEVEN;**126,133**;Oct 13, 1995;Build 13
- +2 ;Per VHA Directive 2004-038, this routine should not be modified.
- +3 ;
- NEWMSG(PARMS,HLMSTATE,ERROR) ;
- +1 ;Starts a new message.
- +2 ;Input:
- +3 ; PARMS( *pass by reference*
- +4 ; "COUNTRY")=3 character country code (optional)
- +5 ; "CONTINUATION POINTER" -indicates a fragmented message
- +6 ; "EVENT")=3 character event type (required)
- +7 ; "FIELD SEPARATOR")=field separator (optional, defaults to "|")
- +8 ; "ENCODING CHARACTERS")= 4 HL7 encoding characters (optional,defaults to "^~\&")
- +9 ; "MESSAGE STRUCTURE" - MSH 9, component 3 - a code from the standard HL7 table (optional)
- +10 ; "MESSAGE TYPE")=3 character message type (required)
- +11 ; "PROCESSING MODE" - MSH 11, component 2 - a 1 character code (optional)
- +12 ; "VERSION")=the HL7 Version ID, for example, "2.4" (optional, defaults to 2.4)
- +13 ;Output:
- +14 ; Function- returns 1 on success, 0 on failure
- +15 ; HLMSTATE() - (pass by reference, required) This array is used by the HL7 package to track the progress of the message. The application MUST NOT touch it!
- +16 ; PARMS - left defined when the function returns
- +17 ; ERROR (optional, pass by reference) - returns an error message on failure
- +18 ;
- +19 ;
- +20 NEW DATA,I,SYSTEM,SUCCESS
- +21 SET SUCCESS=0
- +22 KILL ERROR,HLMSTATE
- +23 Begin DoDot:1
- +24 IF $LENGTH($GET(PARMS("PROCESSING MODE")))
- IF $LENGTH(PARMS("PROCESSING MODE"))'=1
- SET ERROR="INVALID PROCESSING MODE"
- QUIT
- +25 IF $LENGTH($GET(PARMS("COUNTRY")))
- IF $LENGTH(PARMS("COUNTRY"))'=3
- SET ERROR="INVALID COUNTRY CODE"
- QUIT
- +26 IF $LENGTH($GET(PARMS("EVENT")))'=3
- SET ERROR="INVALID EVENT CODE"
- QUIT
- +27 IF $LENGTH($GET(PARMS("MESSAGE TYPE")))'=3
- SET ERROR="INVALID MESSAGE TYPE"
- QUIT
- +28 IF $LENGTH($GET(PARMS("ENCODING CHARACTERS")))
- IF $LENGTH(PARMS("ENCODING CHARACTERS"))'=4
- SET ERROR="INVALID ENCODING CHARACTERS"
- QUIT
- +29 IF $LENGTH($GET(PARMS("FIELD SEPARATOR")))
- IF $LENGTH(PARMS("FIELD SEPARATOR"))'=1
- SET ERROR="INVALID FIELD SEPARATOR"
- QUIT
- +30 IF '$LENGTH($GET(PARMS("FIELD SEPARATOR")))
- SET PARMS("FIELD SEPARATOR")="|"
- +31 IF '$LENGTH($GET(PARMS("ENCODING CHARACTERS")))
- SET PARMS("ENCODING CHARACTERS")="^~\&"
- +32 IF $GET(PARMS("VERSION"))=""
- SET PARMS("VERSION")="2.4"
- +33 IF ($LENGTH($GET(PARMS("VERSION")))>20)
- SET ERROR="VERSION > 20 CHARACTERS"
- QUIT
- +34 FOR I="MESSAGE TYPE","EVENT","COUNTRY","FIELD SEPARATOR","ENCODING CHARACTERS","VERSION","CONTINUATION POINTER","MESSAGE STRUCTURE","PROCESSING MODE"
- SET HLMSTATE("HDR",I)=$GET(PARMS(I))
- +35 ;not a batch
- SET HLMSTATE("BATCH")=0
- +36 SET HLMSTATE("DIRECTION")="OUT"
- +37 SET HLMSTATE("IEN")=""
- +38 ;record not yet created
- SET HLMSTATE("BODY")=""
- +39 ;no segments cached
- SET HLMSTATE("CURRENT SEGMENT")=0
- +40 ;nothing in cache
- SET HLMSTATE("UNSTORED LINES")=0
- +41 SET HLMSTATE("LINE COUNT")=0
- +42 DO GETSYS(.HLMSTATE)
- +43 SET SUCCESS=1
- End DoDot:1
- +44 QUIT SUCCESS
- +45 ;
- NEWBATCH(PARMS,HLMSTATE,ERROR) ;
- +1 ;Starts a new batch message.
- +2 ;Input:
- +3 ; PARMS( *pass by reference*
- +4 ; "COUNTRY")=3 character country code (optional)
- +5 ; "FIELD SEPARATOR")=field separator (optional, defaults to "|")
- +6 ; "ENCODING CHARACTERS")= 4 HL7 encoding characters (optional,defaults to "^~\&")
- +7 ; "VERSION")=the HL7 Version ID, for example, "2.4" (optional, defaults to 2.4)
- +8 ;Output:
- +9 ; Function - returns 1 on success, 0 on failure
- +10 ; PARMS - left defined when the function returns
- +11 ; HLMSTATE() - (pass by reference, required) This array is used by the HL7 package to track the progress of the message. The application MUST NOT touch it!
- +12 ; ERROR (optional, pass by reference) - returns an error message on failure
- +13 ;
- +14 ;
- +15 NEW DATA,I,SYSTEM,SUCCESS
- +16 SET SUCCESS=0
- +17 KILL ERROR,HLMSTATE
- +18 Begin DoDot:1
- +19 IF $LENGTH($GET(PARMS("COUNTRY")))
- IF $LENGTH(PARMS("COUNTRY"))'=3
- SET ERROR="INVALID COUNTRY CODE"
- QUIT
- +20 IF $LENGTH($GET(PARMS("ENCODING CHARACTERS")))
- IF $LENGTH(PARMS("ENCODING CHARACTERS"))'=4
- SET ERROR="INVALID ENCODING CHARACTERS"
- QUIT
- +21 IF $LENGTH($GET(PARMS("FIELD SEPARATOR")))
- IF $LENGTH(PARMS("FIELD SEPARATOR"))'=1
- SET ERROR="INVALID FIELD SEPARATOR"
- QUIT
- +22 IF '$LENGTH($GET(PARMS("FIELD SEPARATOR")))
- SET PARMS("FIELD SEPARATOR")="|"
- +23 IF '$LENGTH($GET(PARMS("ENCODING CHARACTERS")))
- SET PARMS("ENCODING CHARACTERS")="^~\&"
- +24 IF $GET(PARMS("VERSION"))=""
- SET PARMS("VERSION")="2.4"
- +25 IF ($LENGTH(PARMS("VERSION"))>20)
- SET ERROR="VERSION > 20 CHARACTERS"
- QUIT
- +26 FOR I="COUNTRY","FIELD SEPARATOR","ENCODING CHARACTERS","VERSION"
- SET HLMSTATE("HDR",I)=$GET(PARMS(I))
- +27 SET HLMSTATE("IEN")=""
- +28 ;msg not yet stored
- SET HLMSTATE("BODY")=""
- +29 SET HLMSTATE("BATCH")=1
- +30 SET HLMSTATE("DIRECTION")="OUT"
- +31 ;no messages in batch
- SET HLMSTATE("BATCH","CURRENT MESSAGE")=0
- +32 ;no segments in cache
- SET HLMSTATE("CURRENT SEGMENT")=0
- +33 ;nothing in cache
- SET HLMSTATE("UNSTORED LINES")=0
- +34 ;no lines within message stored
- SET HLMSTATE("LINE COUNT")=0
- +35 DO GETSYS(.HLMSTATE)
- +36 SET SUCCESS=1
- End DoDot:1
- +37 QUIT SUCCESS
- +38 ;
- SET(SEG,VALUE,FIELD,COMP,SUBCOMP,REP) ;
- +1 ;Sets a value to the array SEG(), used for building segments.
- +2 ;Input:
- +3 ; SEG - (required, pass by reference) - this is the array where the segment is being built.
- +4 ; VALUE - the individual value to be set into the segment
- +5 ; FIELD - the sequence # of the field (optional, defaults to 0)
- +6 ; *NOTE: FIELD=0 is used to denote the segment type.
- +7 ; COMP - the # of the component (optional, defaults to 1)
- +8 ; SUBCOMP - the # of the subcomponent (optional, defaults to 1)
- +9 ; REP - the occurrence# (optional, defaults to 1) For a non-repeating field, the occurrence # need not be provided, because it would be 1.
- +10 ;Output:
- +11 ; SEG array
- +12 ;
- +13 ; Example:
- +14 ; D SET(.SEG,"MSA",0) creates an MSA segment
- +15 ; D SET(.SEG,"AE",1) will place the value into the array position
- +16 ; reserved for the 1st field,1st occurence,1st comp,1st subcomp
- +17 ;
- +18 ;Implementation Note - This format is used for the segment array built by calls to SET: SEGMENT(<SEQ #>,<occurrence #>,<component #>,<subcomponent #>)=<subcomponent value>
- +19 ;
- +20 IF '$GET(FIELD)
- SET FIELD=0
- +21 IF '$GET(COMP)
- SET COMP=1
- +22 IF '$GET(SUBCOMP)
- SET SUBCOMP=1
- +23 IF '$GET(REP)
- SET REP=1
- +24 SET SEG(FIELD,REP,COMP,SUBCOMP)=$GET(VALUE)
- +25 QUIT
- +26 ;
- ADDSEG(HLMSTATE,SEG,ERROR) ;Adds a segment to the message.
- +1 ;Input:
- +2 ; HLMSTATE() - (pass by reference, required) This array is used by the HL7 package to track the progress of the message. The application MUST NOT touch it!
- +3 ; SEG() - (pass by reference, required) Contains the data. It must be built by calls to SET prior to calling $$ADDSEG.
- +4 ;
- +5 ;Note#1: The message control segments, including the MSH and BHS segments, are added automatically.
- +6 ;Note#2: The 0th field must be a 3 character segment type
- +7 ;Note#3: ***SEG is killed upon successfully adding the segment***
- +8 ;
- +9 ;Output:
- +10 ; HLMSTATE() - (pass by reference, required) This array is used by the HL7 package to track the progress of the message.
- +11 ; FUNCTION - returns 1 on success, 0 on failure
- +12 ; ERROR (optional, pass by reference) - returns an error message on failure
- +13 ;
- +14 ;
- +15 KILL ERROR
- +16 NEW TOARY,TYPE
- +17 ;
- +18 ;segment type
- SET TYPE=$GET(SEG(0,1,1,1))
- +19 ;
- +20 ;if a 'generic' app ack MSA was built, add it as the first segment before this one
- +21 IF $DATA(HLMSTATE("MSA"))
- Begin DoDot:1
- +22 IF TYPE'="MSA"
- SET TOARY(1)=HLMSTATE("MSA")
- DO ADDSEG^HLOMSG(.HLMSTATE,.TOARY)
- KILL TOARY
- +23 KILL HLMSTATE("MSA")
- End DoDot:1
- +24 ;
- +25 IF ($LENGTH(TYPE)'=3)
- SET ERROR="INVALID SEGMENT TYPE"
- QUIT 0
- +26 IF (TYPE="MSH")!(TYPE="BHS")!(TYPE="BTS")!(TYPE="FHS")!(TYPE="FTS")
- SET ERROR="INVALID SEGMENT TYPE"
- QUIT 0
- +27 IF HLMSTATE("BATCH")
- IF 'HLMSTATE("BATCH","CURRENT MESSAGE")
- SET ERROR="NO MESSAGES IN BATCH, SO SEGMENTS NOT ALLOWED"
- QUIT 0
- +28 IF $$BUILDSEG^HLOPBLD(.HLMSTATE,.SEG,.TOARY,.ERROR)
- DO ADDSEG^HLOMSG(.HLMSTATE,.TOARY)
- KILL SEG
- QUIT 1
- +29 QUIT 0
- +30 ;
- ADDMSG(HLMSTATE,PARMS,ERROR) ;
- +1 ;Begins a new message in the batch.
- +2 ;Input:
- +3 ; HLMSTATE() - (pass by reference, required) This array is used by the HL7 package to track the progress of the message. The application MUST NOT touch it!
- +4 ; PARMS( *pass by reference*
- +5 ; "EVENT")=3 character event type (required)
- +6 ; "MESSAGE TYPE")=3 character message type (required)
- +7 ;
- +8 ;Output:
- +9 ; FUNCTION - returns 1 on success, 0 on failure
- +10 ; HLMSTATE() - (pass by reference, required) This array is used by the HL7 package to track the progress of the message.
- +11 ; PARMS - left defined when this function returns
- +12 ; ERROR (optional, pass by reference) - returns an error message on failure
- +13 ;
- +14 NEW I
- +15 KILL ERROR
- +16 ;if a 'generic' app ack MSA was built, add it as the first segment before this one
- +17 IF $DATA(HLMSTATE("MSA"))
- Begin DoDot:1
- +18 IF TYPE'="MSA"
- NEW TOARY
- MERGE TOARY=HLMSTATE("MSA")
- DO ADDSEG^HLOMSG(.HLMSTATE,.TOARY)
- KILL TOARY
- +19 KILL HLMSTATE("MSA")
- End DoDot:1
- +20 IF $LENGTH($GET(PARMS("EVENT")))'=3
- SET ERROR="EVENT TYPE INVALID"
- QUIT 0
- +21 IF $LENGTH($GET(PARMS("MESSAGE TYPE")))'=3
- SET ERROR="MESSAGE TYPE INVALID"
- QUIT 0
- +22 DO ADDMSG^HLOMSG(.HLMSTATE,.PARMS)
- +23 QUIT 1
- +24 ;
- GETSYS(HLMSTATE) ;
- +1 NEW SYS,SUB
- +2 DO SYSPARMS^HLOSITE(.SYS)
- +3 FOR SUB="DOMAIN","STATION","PROCESSING ID","MAXSTRING","ERROR PURGE","NORMAL PURGE","PORT"
- SET HLMSTATE("SYSTEM",SUB)=SYS(SUB)
- +4 SET HLMSTATE("SYSTEM","BUFFER")=SYS("USER BUFFER")
- +5 QUIT
- +6 ;
- MOVEMSG(HLMSTATE,ARY) ;
- +1 ;If a message was built in the 'old' way, and resides in an array, this routine will move it into file 777 (HL7 Message Body)
- +2 ;Input:
- +3 ; HLMSTATE (pass by reference) the array created by calling $$NEWMSG or $$NEWBATCH
- +4 ; ARY - is the name of the array, local or global, where the message was built, used to reference the array by indirection.
- +5 ;
- +6 NEW I
- SET I=0
- +7 FOR
- SET I=$ORDER(@ARY@(I))
- IF 'I
- QUIT
- Begin DoDot:1
- +8 NEW SEG,J,J2
- +9 SET J=0
- SET J2=1
- +10 SET SEG(J2)=@ARY@(I)
- +11 FOR
- SET J=$ORDER(@ARY@(I,J))
- IF 'J
- QUIT
- SET J2=J2+1
- SET SEG(J2)=@ARY@(I,J)
- +12 IF 'HLMSTATE("BATCH")
- Begin DoDot:2
- +13 DO ADDSEG^HLOMSG(.HLMSTATE,.SEG)
- End DoDot:2
- +14 IF '$TEST
- Begin DoDot:2
- +15 IF $EXTRACT(SEG(1),1,3)="MSH"
- Begin DoDot:3
- +16 DO SPLITHDR^HLOSRVR1(.SEG)
- +17 DO ADDMSG2^HLOMSG(.HLMSTATE,.SEG)
- End DoDot:3
- +18 IF '$TEST
- DO ADDSEG^HLOMSG(.HLMSTATE,.SEG)
- End DoDot:2
- End DoDot:1
- +19 ;
- +20 ;signal SENDACK^HLOAPI2 that the application built its own msg
- +21 KILL HLMSTATE("MSA")
- +22 QUIT