source: WorldVistAEHR/trunk/r/HEALTH_LEVEL_SEVEN-HL/HLOAPI2.m@ 836

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

revised back to 6/30/08 version

File size: 7.5 KB
RevLine 
[623]1HLOAPI2 ;ALB/CJM-HL7 - Developer API's for sending application acks ;12/11/2006
2 ;;1.6;HEALTH LEVEL SEVEN;**126,131,133,134**;Oct 13, 1995;Build 30
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:"AE")
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 I $G(PARMS("SENDING APPLICATION"))="" D
120 .S ERROR="SENDING APPLICATION IS REQUIRED"
121 .S PARMS("SENDING APPLICATION")=""
122 E D
123 .I '$D(^HLD(779.2,"C",PARMS("SENDING APPLICATION"))) S ERROR="SENDING APPLICATION NOT FOUND IN THE HLO APPLICATION REGISTRY"
124 ;
125 ;move parameters into HLMSTATE
126 S @HARY@("ACCEPT ACK TYPE")=PARMS("ACCEPT ACK TYPE")
127 S @HARY@("APP ACK TYPE")=PARMS("APP ACK TYPE")
128 S @HARY@("SENDING APPLICATION")=$E(PARMS("SENDING APPLICATION"),1,60)
129 S @HARY@("SECURITY")=$G(PARMS("SECURITY"))
130 S @SARY@("APP ACK RESPONSE")=$G(PARMS("APP ACK RESPONSE"))
131 S @SARY@("ACCEPT ACK RESPONSE")=$G(PARMS("ACCEPT ACK RESPONSE"))
132 S @SARY@("FAILURE RESPONSE")=$G(PARMS("FAILURE RESPONSE"))
133 S @SARY@("QUEUE")=PARMS("QUEUE")
134 Q:$L(ERROR) 0
135 Q 1
136 ;
137SETCODE(SEG,VALUE,FIELD,COMP,REP) ;
138 ;Implements SETCNE and SETCWE
139 ;
140 N SUB,VAR
141 Q:'$G(FIELD)
142 S:'$G(REP) REP=1
143 I '$G(COMP) D
144 .S VAR="COMP",SUB=1
145 E D
146 .S VAR="SUB"
147 S @VAR=1,SEG(FIELD,REP,COMP,SUB)=$G(VALUE("ID"))
148 S @VAR=2,SEG(FIELD,REP,COMP,SUB)=$G(VALUE("TEXT"))
149 S @VAR=3,SEG(FIELD,REP,COMP,SUB)=$G(VALUE("SYSTEM"))
150 S @VAR=4,SEG(FIELD,REP,COMP,SUB)=$G(VALUE("ALTERNATE ID"))
151 S @VAR=5,SEG(FIELD,REP,COMP,SUB)=$G(VALUE("ALTERNATE TEXT"))
152 S @VAR=6,SEG(FIELD,REP,COMP,SUB)=$G(VALUE("ALTERNATE SYSTEM"))
153 S @VAR=7,SEG(FIELD,REP,COMP,SUB)=$G(VALUE("SYSTEM VERSION"))
154 S @VAR=8,SEG(FIELD,REP,COMP,SUB)=$G(VALUE("ALTERNATE SYSTEM VERSION"))
155 S @VAR=9,SEG(FIELD,REP,COMP,SUB)=$G(VALUE("ORIGINAL TEXT"))
156 Q
Note: See TracBrowser for help on using the repository browser.