HLOAPI2 ;ALB/CJM-HL7 - Developer API's for sending application acks ;09/13/2006
;;1.6;HEALTH LEVEL SEVEN;**126,131,133**;Oct 13, 1995;Build 13
;Per VHA Directive 2004-038, this routine should not be modified.
;
ACK(HLMSTATE,PARMS,ACK,ERROR) ;Default behavior is to return a general
;application ack. The application may optionally specify the message
;type and event or call $$ADDSEG^HLOAPI to add segments.
;A generic MSA segment (components 1-3) is added automatically IF the
;application doesn't call $$ADDSEG^HLOAPI to add an MSA segment as the
;FIRST segment following the header.
;$$SENDACK must be called when the ack is completed. The return
;destination is determined automatically from the original message
;
;This API should NOT be called for batch messages, use $$BATCHACK instead.
;Input:
; HLMSTATE (pass by reference, required) the array obtained by calling $$STARTMSG^HLOPRS when parsing the original message
; PARMS (pass by reference) These subscripts may be defined:
; "ACK CODE" (required) MSA1[ {AA,AE,AR}
; "ERROR MESSAGE" - MSA3, should be used only if AE or AR
; "ACCEPT ACK RESPONSE" - the <tag^routine> to call when the commit ack is received (optional)
; "ACCEPT ACK TYPE" - {AL,NE} (optional, defaults to AL)
; "CONTINUATION POINTER" (optional)indicates a fragmented message
; "COUNTRY" - the 3 character country code (optional)
; "EVENT" - the 3 character event type (optional, defaults to the event code of the original message)
; "ENCODING CHARACTERS" - the four HL7 encoding characters (optional,defaults to "^~\&"
; "FAILURE RESPONSE" (optional) the <tag>^<routine> that the sending application routine should execute if the transmission of the message fails, i.e., the message can not be sent or a requested commit ack is not received.
; "FIELD SEPARATOR" - field separator (optional, defaults to "|")
; "MESSAGE TYPE" - if not defined, ACK is used
; "MESSAGE STRUCTURE" (optional)
; "QUEUE" - (optional) An application can name its own private queue (a string under 20 characters,namespaced). The default is the name of the queue of the original message
; "SECURITY" (optional) security information to include in the header segment, SEQ 8 (optional)
; "VERSION" - the HL7 Version ID (optional, defaults to 2.4)
;Output:
; Function returns 1 on success, 0 on failure
; PARMS - left undefined when the function returns
; ACK (pass by reference, required) the acknowledgment message being built.
; ERROR (pass by reference) error msg
N I,SEG,TOLINK,SUCCESS
S SUCCESS=0,ERROR=""
;
D
.N PORT
.I $G(PARMS("ACK CODE"))'="AA",$G(PARMS("ACK CODE"))'="AE",$G(PARMS("ACK CODE"))'="AR" S ERROR="INVALID ACK CODE" Q
.;
.I '$G(HLMSTATE("IEN")) S ERROR="ORIGINAL MESSAGE TO ACKNOWLEDGE IS NOT IDENTIFIED" Q
.I $G(HLMSTATE("BATCH")) S ERROR="BATCH ACKNOWLEDGMENTS MUST USE $$BATCHACK^HLOAPI3" Q
.;
.I $G(HLMSTATE("HDR","MESSAGE CONTROL ID"))="" S ERROR="MESSAGE CONTROL ID MUST EXIST TO RETURN AN APPLICATION ACK" Q
.S PARMS("MESSAGE TYPE")=$G(PARMS("MESSAGE TYPE"),"ACK")
.S:PARMS("MESSAGE TYPE")="ACK" PARMS("MESSAGE STRUCTURE")="ACK"
.S PARMS("EVENT")=$G(PARMS("EVENT"),$G(HLMSTATE("HDR","EVENT")))
.I $$NEWMSG^HLOAPI(.PARMS,.ACK) ;can't fail!
.;
.;if the return link can not be determined, the HL Logical Link file has a problem that must be fixed at the site
.S PORT=$P(HLMSTATE("HDR","SENDING FACILITY",2),":",2)
.S TOLINK=$$ACKLINK(.HLMSTATE)
.I TOLINK="" S ERROR="TRANSMISSION LINK FOR APPLICATION ACK CANNOT BE DETERMINED" Q
.I 'PORT S PORT=$$PORT2^HLOTLNK(TOLINK)
.;
.S ACK("HDR","APP ACK TYPE")="NE"
.S ACK("HDR","ACCEPT ACK TYPE")=$G(PARMS("ACCEPT ACK TYPE"),"AL")
.S ACK("STATUS","QUEUE")=$G(PARMS("QUEUE"),$G(HLMSTATE("STATUS","QUEUE")))
.S ACK("STATUS","PORT")=PORT
.S ACK("HDR","SECURITY")=$G(PARMS("SECURITY"))
.S ACK("HDR","SENDING APPLICATION")=$G(HLMSTATE("HDR","RECEIVING APPLICATION"))
.S ACK("HDR","RECEIVING APPLICATION")=$G(HLMSTATE("HDR","SENDING APPLICATION"))
.F I=1:1:3 S ACK("HDR","RECEIVING FACILITY",I)=$G(HLMSTATE("HDR","SENDING FACILITY",I))
.S ACK("ACK TO","STATUS")=$S(PARMS("ACK CODE")="AA":"SU",1:"AE")
.S ACK("ACK TO")=$G(HLMSTATE("HDR","MESSAGE CONTROL ID"))
.S ACK("ACK TO","IEN")=HLMSTATE("IEN")
.S ACK("STATUS","LINK NAME")=TOLINK
.S ACK("LINE COUNT")=0
.S ACK("MSA")="MSA"_ACK("HDR","FIELD SEPARATOR")_PARMS("ACK CODE")_ACK("HDR","FIELD SEPARATOR")_$G(HLMSTATE("HDR","MESSAGE CONTROL ID"))_ACK("HDR","FIELD SEPARATOR")_$G(PARMS("ERROR MESSAGE"))
.S SUCCESS=1
K PARMS
K:'SUCCESS ACK
Q SUCCESS
;
SENDACK(ACK,ERROR) ;This is used to signal that an application acknowledgment is complete.
;Input:
; ACK (pass by reference,required) An array that contains the acknowledgment msg
;Output:
; Function returns 1 on success, 0 on failure
; ERROR (pass by reference) error msg
;
N SEG
;if the application added its own MSA, then the ACK("MSA") node was killed
I $D(ACK("MSA")) S SEG(1)=ACK("MSA") D ADDSEG^HLOMSG(.ACK,.SEG)
;
I $$SEND^HLOAPI1(.ACK,.ERROR) Q 1
Q 0
;
ACKLINK(HLMSTATE) ;
;Finds the link to return the application ack to.
N LINK
S LINK=$$RTRNLNK^HLOAPP($G(HLMSTATE("HDR","RECEIVING APPLICATION")))
Q:LINK]"" LINK
S LINK=$$RTRNLNK^HLOTLNK($G(HLMSTATE("HDR","SENDING FACILITY",1)),$G(HLMSTATE("HDR","SENDING FACILITY",2)),$G(HLMSTATE("HDR","SENDING FACILITY",3)))
Q LINK
;
CHKPARMS(HLMSTATE,PARMS,ERROR) ;
N LEN,SARY,HARY
;
;shortcut to reference the header sub-array
S HARY="HLMSTATE(""HDR"")"
;
;shortcut to reference the status sub-array
S SARY="HLMSTATE(""STATUS"")"
;
S ERROR=""
I $G(PARMS("ACCEPT ACK TYPE"))="" S PARMS("ACCEPT ACK TYPE")="AL"
I $G(PARMS("APP ACK TYPE"))="" S PARMS("APP ACK TYPE")="NE"
I PARMS("ACCEPT ACK TYPE")'="NE",PARMS("ACCEPT ACK TYPE")'="AL" S ERROR="INVALID ACCEPT ACKNOWLEDGMENT TYPE"
I PARMS("APP ACK TYPE")'="NE",PARMS("APP ACK TYPE")'="AL" S ERROR="INVALID APPLICATION ACKNOWLEDGMENT TYPE"
S LEN=$L($G(PARMS("QUEUE")))
I $G(PARMS("QUEUE"))["^" S ERROR="QUEUE NAME MAY NOT CONTAIN '^'"
I LEN>20 S ERROR="QUEUE PARAMETER IS MAX 20 LENGTH",PARMS("QUEUE")=$E(PARMS("QUEUE"),1,20)
I 'LEN S PARMS("QUEUE")="DEFAULT"
I $G(PARMS("SENDING APPLICATION"))="" D
.S ERROR="SENDING APPLICATION IS REQUIRED"
.S PARMS("SENDING APPLICATION")=""
E D
.I '$D(^HLD(779.2,"C",PARMS("SENDING APPLICATION"))) S ERROR="SENDING APPLICATION NOT FOUND IN THE HLO APPLICATION REGISTRY"
;
;move parameters into HLMSTATE
S @HARY@("ACCEPT ACK TYPE")=PARMS("ACCEPT ACK TYPE")
S @HARY@("APP ACK TYPE")=PARMS("APP ACK TYPE")
S @HARY@("SENDING APPLICATION")=$E(PARMS("SENDING APPLICATION"),1,60)
S @HARY@("SECURITY")=$G(PARMS("SECURITY"))
S @SARY@("APP ACK RESPONSE")=$G(PARMS("APP ACK RESPONSE"))
S @SARY@("ACCEPT ACK RESPONSE")=$G(PARMS("ACCEPT ACK RESPONSE"))
S @SARY@("FAILURE RESPONSE")=$G(PARMS("FAILURE RESPONSE"))
S @SARY@("QUEUE")=PARMS("QUEUE")
Q:$L(ERROR) 0
Q 1
;
SETCODE(SEG,VALUE,FIELD,COMP,REP) ;
;Implements SETCNE and SETCWE
;
N SUB,VAR
Q:'$G(FIELD)
S:'$G(REP) REP=1
I '$G(COMP) D
.S VAR="COMP",SUB=1
E D
.S VAR="SUB"
S @VAR=1,SEG(FIELD+1,REP,COMP,SUB)=$G(VALUE("ID"))
S @VAR=2,SEG(FIELD+1,REP,COMP,SUB)=$G(VALUE("TEXT"))
S @VAR=3,SEG(FIELD+1,REP,COMP,SUB)=$G(VALUE("SYSTEM"))
S @VAR=4,SEG(FIELD+1,REP,COMP,SUB)=$G(VALUE("ALTERNATE ID"))
S @VAR=5,SEG(FIELD+1,REP,COMP,SUB)=$G(VALUE("ALTERNATE TEXT"))
S @VAR=6,SEG(FIELD+1,REP,COMP,SUB)=$G(VALUE("ALTERNATE SYSTEM"))
S @VAR=7,SEG(FIELD+1,REP,COMP,SUB)=$G(VALUE("SYSTEM VERSION"))
S @VAR=8,SEG(FIELD+1,REP,COMP,SUB)=$G(VALUE("ALTERNATE SYSTEM VERSION"))
S @VAR=9,SEG(FIELD+1,REP,COMP,SUB)=$G(VALUE("ORIGINAL TEXT"))
Q
HLOAPI2 ;ALB/CJM-HL7 - Developer API's for sending application acks ;09/13/2006
+1 ;;1.6;HEALTH LEVEL SEVEN;**126,131,133**;Oct 13, 1995;Build 13
+2 ;Per VHA Directive 2004-038, this routine should not be modified.
+3 ;
ACK(HLMSTATE,PARMS,ACK,ERROR) ;Default behavior is to return a general
+1 ;application ack. The application may optionally specify the message
+2 ;type and event or call $$ADDSEG^HLOAPI to add segments.
+3 ;A generic MSA segment (components 1-3) is added automatically IF the
+4 ;application doesn't call $$ADDSEG^HLOAPI to add an MSA segment as the
+5 ;FIRST segment following the header.
+6 ;$$SENDACK must be called when the ack is completed. The return
+7 ;destination is determined automatically from the original message
+8 ;
+9 ;This API should NOT be called for batch messages, use $$BATCHACK instead.
+10 ;Input:
+11 ; HLMSTATE (pass by reference, required) the array obtained by calling $$STARTMSG^HLOPRS when parsing the original message
+12 ; PARMS (pass by reference) These subscripts may be defined:
+13 ; "ACK CODE" (required) MSA1[ {AA,AE,AR}
+14 ; "ERROR MESSAGE" - MSA3, should be used only if AE or AR
+15 ; "ACCEPT ACK RESPONSE" - the <tag^routine> to call when the commit ack is received (optional)
+16 ; "ACCEPT ACK TYPE" - {AL,NE} (optional, defaults to AL)
+17 ; "CONTINUATION POINTER" (optional)indicates a fragmented message
+18 ; "COUNTRY" - the 3 character country code (optional)
+19 ; "EVENT" - the 3 character event type (optional, defaults to the event code of the original message)
+20 ; "ENCODING CHARACTERS" - the four HL7 encoding characters (optional,defaults to "^~\&"
+21 ; "FAILURE RESPONSE" (optional) the <tag>^<routine> that the sending application routine should execute if the transmission of the message fails, i.e., the message can not be sent or a requested commit ack is not received.
+22 ; "FIELD SEPARATOR" - field separator (optional, defaults to "|")
+23 ; "MESSAGE TYPE" - if not defined, ACK is used
+24 ; "MESSAGE STRUCTURE" (optional)
+25 ; "QUEUE" - (optional) An application can name its own private queue (a string under 20 characters,namespaced). The default is the name of the queue of the original message
+26 ; "SECURITY" (optional) security information to include in the header segment, SEQ 8 (optional)
+27 ; "VERSION" - the HL7 Version ID (optional, defaults to 2.4)
+28 ;Output:
+29 ; Function returns 1 on success, 0 on failure
+30 ; PARMS - left undefined when the function returns
+31 ; ACK (pass by reference, required) the acknowledgment message being built.
+32 ; ERROR (pass by reference) error msg
+33 NEW I,SEG,TOLINK,SUCCESS
+34 SET SUCCESS=0
SET ERROR=""
+35 ;
+36 Begin DoDot:1
+37 NEW PORT
+38 IF $GET(PARMS("ACK CODE"))'="AA"
IF $GET(PARMS("ACK CODE"))'="AE"
IF $GET(PARMS("ACK CODE"))'="AR"
SET ERROR="INVALID ACK CODE"
QUIT
+39 ;
+40 IF '$GET(HLMSTATE("IEN"))
SET ERROR="ORIGINAL MESSAGE TO ACKNOWLEDGE IS NOT IDENTIFIED"
QUIT
+41 IF $GET(HLMSTATE("BATCH"))
SET ERROR="BATCH ACKNOWLEDGMENTS MUST USE $$BATCHACK^HLOAPI3"
QUIT
+42 ;
+43 IF $GET(HLMSTATE("HDR","MESSAGE CONTROL ID"))=""
SET ERROR="MESSAGE CONTROL ID MUST EXIST TO RETURN AN APPLICATION ACK"
QUIT
+44 SET PARMS("MESSAGE TYPE")=$GET(PARMS("MESSAGE TYPE"),"ACK")
+45 IF PARMS("MESSAGE TYPE")="ACK"
SET PARMS("MESSAGE STRUCTURE")="ACK"
+46 SET PARMS("EVENT")=$GET(PARMS("EVENT"),$GET(HLMSTATE("HDR","EVENT")))
+47 ;can't fail!
IF $$NEWMSG^HLOAPI(.PARMS,.ACK)
+48 ;
+49 ;if the return link can not be determined, the HL Logical Link file has a problem that must be fixed at the site
+50 SET PORT=$PIECE(HLMSTATE("HDR","SENDING FACILITY",2),":",2)
+51 SET TOLINK=$$ACKLINK(.HLMSTATE)
+52 IF TOLINK=""
SET ERROR="TRANSMISSION LINK FOR APPLICATION ACK CANNOT BE DETERMINED"
QUIT
+53 IF 'PORT
SET PORT=$$PORT2^HLOTLNK(TOLINK)
+54 ;
+55 SET ACK("HDR","APP ACK TYPE")="NE"
+56 SET ACK("HDR","ACCEPT ACK TYPE")=$GET(PARMS("ACCEPT ACK TYPE"),"AL")
+57 SET ACK("STATUS","QUEUE")=$GET(PARMS("QUEUE"),$GET(HLMSTATE("STATUS","QUEUE")))
+58 SET ACK("STATUS","PORT")=PORT
+59 SET ACK("HDR","SECURITY")=$GET(PARMS("SECURITY"))
+60 SET ACK("HDR","SENDING APPLICATION")=$GET(HLMSTATE("HDR","RECEIVING APPLICATION"))
+61 SET ACK("HDR","RECEIVING APPLICATION")=$GET(HLMSTATE("HDR","SENDING APPLICATION"))
+62 FOR I=1:1:3
SET ACK("HDR","RECEIVING FACILITY",I)=$GET(HLMSTATE("HDR","SENDING FACILITY",I))
+63 SET ACK("ACK TO","STATUS")=$SELECT(PARMS("ACK CODE")="AA":"SU",1:"AE")
+64 SET ACK("ACK TO")=$GET(HLMSTATE("HDR","MESSAGE CONTROL ID"))
+65 SET ACK("ACK TO","IEN")=HLMSTATE("IEN")
+66 SET ACK("STATUS","LINK NAME")=TOLINK
+67 SET ACK("LINE COUNT")=0
+68 SET ACK("MSA")="MSA"_ACK("HDR","FIELD SEPARATOR")_PARMS("ACK CODE")_ACK("HDR","FIELD SEPARATOR")_$GET(HLMSTATE("HDR","MESSAGE CONTROL ID"))_ACK("HDR","FIELD SEPARATOR")_$GET(PARMS("ERROR MESSAGE"))
+69 SET SUCCESS=1
End DoDot:1
+70 KILL PARMS
+71 IF 'SUCCESS
KILL ACK
+72 QUIT SUCCESS
+73 ;
SENDACK(ACK,ERROR) ;This is used to signal that an application acknowledgment is complete.
+1 ;Input:
+2 ; ACK (pass by reference,required) An array that contains the acknowledgment msg
+3 ;Output:
+4 ; Function returns 1 on success, 0 on failure
+5 ; ERROR (pass by reference) error msg
+6 ;
+7 NEW SEG
+8 ;if the application added its own MSA, then the ACK("MSA") node was killed
+9 IF $DATA(ACK("MSA"))
SET SEG(1)=ACK("MSA")
DO ADDSEG^HLOMSG(.ACK,.SEG)
+10 ;
+11 IF $$SEND^HLOAPI1(.ACK,.ERROR)
QUIT 1
+12 QUIT 0
+13 ;
ACKLINK(HLMSTATE) ;
+1 ;Finds the link to return the application ack to.
+2 NEW LINK
+3 SET LINK=$$RTRNLNK^HLOAPP($GET(HLMSTATE("HDR","RECEIVING APPLICATION")))
+4 IF LINK]""
QUIT LINK
+5 SET LINK=$$RTRNLNK^HLOTLNK($GET(HLMSTATE("HDR","SENDING FACILITY",1)),$GET(HLMSTATE("HDR","SENDING FACILITY",2)),$GET(HLMSTATE("HDR","SENDING FACILITY",3)))
+6 QUIT LINK
+7 ;
CHKPARMS(HLMSTATE,PARMS,ERROR) ;
+1 NEW LEN,SARY,HARY
+2 ;
+3 ;shortcut to reference the header sub-array
+4 SET HARY="HLMSTATE(""HDR"")"
+5 ;
+6 ;shortcut to reference the status sub-array
+7 SET SARY="HLMSTATE(""STATUS"")"
+8 ;
+9 SET ERROR=""
+10 IF $GET(PARMS("ACCEPT ACK TYPE"))=""
SET PARMS("ACCEPT ACK TYPE")="AL"
+11 IF $GET(PARMS("APP ACK TYPE"))=""
SET PARMS("APP ACK TYPE")="NE"
+12 IF PARMS("ACCEPT ACK TYPE")'="NE"
IF PARMS("ACCEPT ACK TYPE")'="AL"
SET ERROR="INVALID ACCEPT ACKNOWLEDGMENT TYPE"
+13 IF PARMS("APP ACK TYPE")'="NE"
IF PARMS("APP ACK TYPE")'="AL"
SET ERROR="INVALID APPLICATION ACKNOWLEDGMENT TYPE"
+14 SET LEN=$LENGTH($GET(PARMS("QUEUE")))
+15 IF $GET(PARMS("QUEUE"))["^"
SET ERROR="QUEUE NAME MAY NOT CONTAIN '^'"
+16 IF LEN>20
SET ERROR="QUEUE PARAMETER IS MAX 20 LENGTH"
SET PARMS("QUEUE")=$EXTRACT(PARMS("QUEUE"),1,20)
+17 IF 'LEN
SET PARMS("QUEUE")="DEFAULT"
+18 IF $GET(PARMS("SENDING APPLICATION"))=""
Begin DoDot:1
+19 SET ERROR="SENDING APPLICATION IS REQUIRED"
+20 SET PARMS("SENDING APPLICATION")=""
End DoDot:1
+21 IF '$TEST
Begin DoDot:1
+22 IF '$DATA(^HLD(779.2,"C",PARMS("SENDING APPLICATION")))
SET ERROR="SENDING APPLICATION NOT FOUND IN THE HLO APPLICATION REGISTRY"
End DoDot:1
+23 ;
+24 ;move parameters into HLMSTATE
+25 SET @HARY@("ACCEPT ACK TYPE")=PARMS("ACCEPT ACK TYPE")
+26 SET @HARY@("APP ACK TYPE")=PARMS("APP ACK TYPE")
+27 SET @HARY@("SENDING APPLICATION")=$EXTRACT(PARMS("SENDING APPLICATION"),1,60)
+28 SET @HARY@("SECURITY")=$GET(PARMS("SECURITY"))
+29 SET @SARY@("APP ACK RESPONSE")=$GET(PARMS("APP ACK RESPONSE"))
+30 SET @SARY@("ACCEPT ACK RESPONSE")=$GET(PARMS("ACCEPT ACK RESPONSE"))
+31 SET @SARY@("FAILURE RESPONSE")=$GET(PARMS("FAILURE RESPONSE"))
+32 SET @SARY@("QUEUE")=PARMS("QUEUE")
+33 IF $LENGTH(ERROR)
QUIT 0
+34 QUIT 1
+35 ;
SETCODE(SEG,VALUE,FIELD,COMP,REP) ;
+1 ;Implements SETCNE and SETCWE
+2 ;
+3 NEW SUB,VAR
+4 IF '$GET(FIELD)
QUIT
+5 IF '$GET(REP)
SET REP=1
+6 IF '$GET(COMP)
Begin DoDot:1
+7 SET VAR="COMP"
SET SUB=1
End DoDot:1
+8 IF '$TEST
Begin DoDot:1
+9 SET VAR="SUB"
End DoDot:1
+10 SET @VAR=1
SET SEG(FIELD+1,REP,COMP,SUB)=$GET(VALUE("ID"))
+11 SET @VAR=2
SET SEG(FIELD+1,REP,COMP,SUB)=$GET(VALUE("TEXT"))
+12 SET @VAR=3
SET SEG(FIELD+1,REP,COMP,SUB)=$GET(VALUE("SYSTEM"))
+13 SET @VAR=4
SET SEG(FIELD+1,REP,COMP,SUB)=$GET(VALUE("ALTERNATE ID"))
+14 SET @VAR=5
SET SEG(FIELD+1,REP,COMP,SUB)=$GET(VALUE("ALTERNATE TEXT"))
+15 SET @VAR=6
SET SEG(FIELD+1,REP,COMP,SUB)=$GET(VALUE("ALTERNATE SYSTEM"))
+16 SET @VAR=7
SET SEG(FIELD+1,REP,COMP,SUB)=$GET(VALUE("SYSTEM VERSION"))
+17 SET @VAR=8
SET SEG(FIELD+1,REP,COMP,SUB)=$GET(VALUE("ALTERNATE SYSTEM VERSION"))
+18 SET @VAR=9
SET SEG(FIELD+1,REP,COMP,SUB)=$GET(VALUE("ORIGINAL TEXT"))
+19 QUIT