source: FOIAVistA/trunk/r/HEALTH_LEVEL_SEVEN-HL/HLOAPI2.m@ 1328

Last change on this file since 1328 was 628, checked in by George Lilly, 15 years ago

initial load of FOIAVistA 6/30/08 version

File size: 8.5 KB
Line 
1HLOAPI2 ;ALB/CJM-HL7 - Developer API's for sending application acks ;07/30/2007
2 ;;1.6;HEALTH LEVEL SEVEN;**126,131,133,134,137**;Oct 13, 1995;Build 21
3 ;Per VHA Directive 2004-038, this routine should not be modified.
4 ;
5ACK(HLMSTATE,PARMS,ACK,ERROR) ;Default behavior is to return a general
6 ;application ack. The application may optionally specify the message
7 ;type and event or call $$ADDSEG^HLOAPI to add segments.
8 ;A generic MSA segment (components 1-3) is added automatically IF the
9 ;application doesn't call $$ADDSEG^HLOAPI to add an MSA segment as the
10 ;FIRST segment following the header.
11 ;$$SENDACK must be called when the ack is completed. The return
12 ;destination is determined automatically from the original message
13 ;
14 ;This API should NOT be called for batch messages, use $$BATCHACK instead.
15 ;Input:
16 ; HLMSTATE (pass by reference, required) the array obtained by calling $$STARTMSG^HLOPRS when parsing the original message
17 ; PARMS (pass by reference) These subscripts may be defined:
18 ; "ACK CODE" (required) MSA1[ {AA,AE,AR}
19 ; "ERROR MESSAGE" - MSA3, should be used only if AE or AR
20 ; "ACCEPT ACK RESPONSE" - the <tag^routine> to call when the commit ack is received (optional)
21 ; "ACCEPT ACK TYPE" - {AL,NE} (optional, defaults to AL)
22 ; "CONTINUATION POINTER" (optional)indicates a fragmented message
23 ; "COUNTRY" - the 3 character country code (optional)
24 ; "EVENT" - the 3 character event type (optional, defaults to the event code of the original message)
25 ; "ENCODING CHARACTERS" - the four HL7 encoding characters (optional,defaults to "^~\&"
26 ; "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.
27 ; "FIELD SEPARATOR" - field separator (optional, defaults to "|")
28 ; "MESSAGE TYPE" - if not defined, ACK is used
29 ; "MESSAGE STRUCTURE" (optional)
30 ; "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
31 ; "SECURITY" (optional) security information to include in the header segment, SEQ 8 (optional)
32 ; "VERSION" - the HL7 Version ID (optional, defaults to 2.4)
33 ;Output:
34 ; Function returns 1 on success, 0 on failure
35 ; PARMS - left undefined when the function returns
36 ; ACK (pass by reference, required) the acknowledgment message being built.
37 ; ERROR (pass by reference) error msg
38 N I,SEG,TOLINK,SUCCESS
39 S SUCCESS=0,ERROR=""
40 ;
41 D
42 .N PORT
43 .I $G(PARMS("ACK CODE"))'="AA",$G(PARMS("ACK CODE"))'="AE",$G(PARMS("ACK CODE"))'="AR" S ERROR="INVALID ACK CODE" Q
44 .;
45 .I '$G(HLMSTATE("IEN")) S ERROR="ORIGINAL MESSAGE TO ACKNOWLEDGE IS NOT IDENTIFIED" Q
46 .I $G(HLMSTATE("BATCH")) S ERROR="BATCH ACKNOWLEDGMENTS MUST USE $$BATCHACK^HLOAPI3" Q
47 .;
48 .I $G(HLMSTATE("HDR","MESSAGE CONTROL ID"))="" S ERROR="MESSAGE CONTROL ID MUST EXIST TO RETURN AN APPLICATION ACK" Q
49 .S PARMS("MESSAGE TYPE")=$G(PARMS("MESSAGE TYPE"),"ACK")
50 .S:PARMS("MESSAGE TYPE")="ACK" PARMS("MESSAGE STRUCTURE")="ACK"
51 .S PARMS("EVENT")=$G(PARMS("EVENT"),$G(HLMSTATE("HDR","EVENT")))
52 .I $$NEWMSG^HLOAPI(.PARMS,.ACK) ;can't fail!
53 .;
54 .;if the return link can not be determined, the HL Logical Link file has a problem that must be fixed at the site
55 .S PORT=$P(HLMSTATE("HDR","SENDING FACILITY",2),":",2)
56 .S TOLINK=$$ACKLINK(.HLMSTATE)
57 .I TOLINK="" S ERROR="TRANSMISSION LINK FOR APPLICATION ACK CANNOT BE DETERMINED" Q
58 .I 'PORT S PORT=$$PORT2^HLOTLNK(TOLINK)
59 .;
60 .S ACK("HDR","APP ACK TYPE")="NE"
61 .S ACK("HDR","ACCEPT ACK TYPE")=$G(PARMS("ACCEPT ACK TYPE"),"AL")
62 .S ACK("STATUS","QUEUE")=$G(PARMS("QUEUE"),$G(HLMSTATE("STATUS","QUEUE")))
63 .S ACK("STATUS","PORT")=PORT
64 .S ACK("HDR","SECURITY")=$G(PARMS("SECURITY"))
65 .S ACK("HDR","SENDING APPLICATION")=$G(HLMSTATE("HDR","RECEIVING APPLICATION"))
66 .S ACK("HDR","RECEIVING APPLICATION")=$G(HLMSTATE("HDR","SENDING APPLICATION"))
67 .F I=1:1:3 S ACK("HDR","RECEIVING FACILITY",I)=$G(HLMSTATE("HDR","SENDING FACILITY",I))
68 .S ACK("ACK TO","STATUS")=$S(PARMS("ACK CODE")="AA":"SU",1:"ER")
69 .S ACK("ACK TO")=$G(HLMSTATE("HDR","MESSAGE CONTROL ID"))
70 .S ACK("ACK TO","IEN")=HLMSTATE("IEN")
71 .S ACK("STATUS","LINK NAME")=TOLINK
72 .S ACK("LINE COUNT")=0
73 .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"))
74 .S SUCCESS=1
75 K PARMS
76 K:'SUCCESS ACK
77 Q SUCCESS
78 ;
79SENDACK(ACK,ERROR) ;This is used to signal that an application acknowledgment is complete.
80 ;Input:
81 ; ACK (pass by reference,required) An array that contains the acknowledgment msg
82 ;Output:
83 ; Function returns 1 on success, 0 on failure
84 ; ERROR (pass by reference) error msg
85 ;
86 N SEG
87 ;if the application added its own MSA, then the ACK("MSA") node was killed
88 I $D(ACK("MSA")) S SEG(1)=ACK("MSA") D ADDSEG^HLOMSG(.ACK,.SEG)
89 ;
90 I $$SEND^HLOAPI1(.ACK,.ERROR) Q 1
91 Q 0
92 ;
93ACKLINK(HLMSTATE) ;
94 ;Finds the link to return the application ack to.
95 N LINK
96 S LINK=$$RTRNLNK^HLOAPP($G(HLMSTATE("HDR","RECEIVING APPLICATION")))
97 Q:LINK]"" LINK
98 S LINK=$$RTRNLNK^HLOTLNK($G(HLMSTATE("HDR","SENDING FACILITY",1)),$G(HLMSTATE("HDR","SENDING FACILITY",2)),$G(HLMSTATE("HDR","SENDING FACILITY",3)))
99 Q LINK
100 ;
101CHKPARMS(HLMSTATE,PARMS,ERROR) ;
102 N LEN,SARY,HARY
103 ;
104 ;shortcut to reference the header sub-array
105 S HARY="HLMSTATE(""HDR"")"
106 ;
107 ;shortcut to reference the status sub-array
108 S SARY="HLMSTATE(""STATUS"")"
109 ;
110 S ERROR=""
111 I $G(PARMS("ACCEPT ACK TYPE"))="" S PARMS("ACCEPT ACK TYPE")="AL"
112 I $G(PARMS("APP ACK TYPE"))="" S PARMS("APP ACK TYPE")="NE"
113 I PARMS("ACCEPT ACK TYPE")'="NE",PARMS("ACCEPT ACK TYPE")'="AL" S ERROR="INVALID ACCEPT ACKNOWLEDGMENT TYPE"
114 I PARMS("APP ACK TYPE")'="NE",PARMS("APP ACK TYPE")'="AL" S ERROR="INVALID APPLICATION ACKNOWLEDGMENT TYPE"
115 S LEN=$L($G(PARMS("QUEUE")))
116 I $G(PARMS("QUEUE"))["^" S ERROR="QUEUE NAME MAY NOT CONTAIN '^'"
117 I LEN>20 S ERROR="QUEUE PARAMETER IS MAX 20 LENGTH",PARMS("QUEUE")=$E(PARMS("QUEUE"),1,20)
118 I 'LEN S PARMS("QUEUE")="DEFAULT"
119 D
120 .N APPIEN
121 .I $G(PARMS("SENDING APPLICATION"))="" D Q
122 ..S ERROR="SENDING APPLICATION IS REQUIRED"
123 ..S PARMS("SENDING APPLICATION")=""
124 .E D Q:'APPIEN
125 ..S APPIEN=$$GETIEN^HLOAPP(PARMS("SENDING APPLICATION"))
126 ..I 'APPIEN S ERROR="SENDING APPLICATION NOT FOUND IN THE HLO APPLICATION REGISTRY"
127 .I $L($G(PARMS("SEQUENCE QUEUE"))) D
128 ..I ($L(PARMS("SEQUENCE QUEUE"))>30) S ERROR="SEQUENCE QUEUE NAME > 30 CHARACTERS" Q
129 ..I PARMS("SEQUENCE QUEUE")["^" S ERROR="SEQUENCE QUEUE NAME MAY NOT CONTAIN '^'" Q
130 ..I $G(PARMS("APP ACK TYPE"))'="AL" S ERROR="SEQUENCE QUEUES REQUIRE AN APPLICATION ACKNOWLEDGMENT" Q
131 ..I $G(PARMS("ACCEPT ACK TYPE"))'="AL" S ERROR="SEQUENCE QUEUES REQUIRE AN ACCEPT ACKNOWLEDGMENT" Q
132 ;
133 ;move parameters into HLMSTATE
134 S @HARY@("ACCEPT ACK TYPE")=PARMS("ACCEPT ACK TYPE")
135 S @HARY@("APP ACK TYPE")=PARMS("APP ACK TYPE")
136 S @HARY@("SENDING APPLICATION")=$E(PARMS("SENDING APPLICATION"),1,60)
137 S @HARY@("SECURITY")=$G(PARMS("SECURITY"))
138 S @SARY@("APP ACK RESPONSE")=$G(PARMS("APP ACK RESPONSE"))
139 S @SARY@("ACCEPT ACK RESPONSE")=$G(PARMS("ACCEPT ACK RESPONSE"))
140 S @SARY@("FAILURE RESPONSE")=$G(PARMS("FAILURE RESPONSE"))
141 S @SARY@("QUEUE")=PARMS("QUEUE")
142 S @SARY@("SEQUENCE QUEUE")=$G(PARMS("SEQUENCE QUEUE"))
143 Q:$L(ERROR) 0
144 Q 1
145 ;
146 ;
147SETCODE(SEG,VALUE,FIELD,COMP,REP) ;
148 ;Implements SETCNE and SETCWE
149 ;
150 N SUB,VAR
151 Q:'$G(FIELD)
152 S:'$G(REP) REP=1
153 I '$G(COMP) D
154 .S VAR="COMP",SUB=1
155 E D
156 .S VAR="SUB"
157 S @VAR=1,SEG(FIELD,REP,COMP,SUB)=$G(VALUE("ID"))
158 S @VAR=2,SEG(FIELD,REP,COMP,SUB)=$G(VALUE("TEXT"))
159 S @VAR=3,SEG(FIELD,REP,COMP,SUB)=$G(VALUE("SYSTEM"))
160 S @VAR=4,SEG(FIELD,REP,COMP,SUB)=$G(VALUE("ALTERNATE ID"))
161 S @VAR=5,SEG(FIELD,REP,COMP,SUB)=$G(VALUE("ALTERNATE TEXT"))
162 S @VAR=6,SEG(FIELD,REP,COMP,SUB)=$G(VALUE("ALTERNATE SYSTEM"))
163 S @VAR=7,SEG(FIELD,REP,COMP,SUB)=$G(VALUE("SYSTEM VERSION"))
164 S @VAR=8,SEG(FIELD,REP,COMP,SUB)=$G(VALUE("ALTERNATE SYSTEM VERSION"))
165 S @VAR=9,SEG(FIELD,REP,COMP,SUB)=$G(VALUE("ORIGINAL TEXT"))
166 Q
167 ;
168CHKWHO(HLMSTATE,WHOTO,ERROR) ;
169 N RETURN,I
170 S RETURN=1
171 I '$$CHECKWHO^HLOASUB1(.WHOTO,.RETURN,.ERROR) S RETURN=0
172 ;
173 ;move parameters into HLMSTATE
174 S HLMSTATE("STATUS","LINK IEN")=$G(RETURN("LINK IEN"))
175 S HLMSTATE("STATUS","LINK NAME")=$G(RETURN("LINK NAME"))
176 S HLMSTATE("STATUS","PORT")=$P($G(RETURN("RECEIVING FACILITY",2)),":",2)
177 S HLMSTATE("HDR","RECEIVING APPLICATION")=$G(RETURN("RECEIVING APPLICATION"))
178 F I=1:1:3 S HLMSTATE("HDR","RECEIVING FACILITY",I)=$G(RETURN("RECEIVING FACILITY",I))
179 Q RETURN
Note: See TracBrowser for help on using the repository browser.