source: FOIAVistA/trunk/r/HEALTH_LEVEL_SEVEN-HL/HLMA.m@ 1611

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

initial load of FOIAVistA 6/30/08 version

File size: 8.9 KB
Line 
1HLMA ;AISC/SAW-Message Administration Module ;10/24/2007 10:15
2 ;;1.6;HEALTH LEVEL SEVEN;**19,43,58,63,66,82,91,109,115,133,132,122**;Oct 13, 1995;Build 14
3 ;Per VHA Directive 2004-038, this routine should not be modified.
4GENERATE(HLEID,HLARYTYP,HLFORMAT,HLRESLT,HLMTIEN,HLP) ;
5 ;Entry point to generate a deferred message
6 ;
7 ;This is a subroutine call with parameter passing. It returns a
8 ;value in the variable HLRESLT with 1 to 3 pieces separated by uparrows
9 ;as follows: 1st message ID^error code^error description
10 ;If no error occurs, only the first piece is returned equal to a unique
11 ;ID for the 1st message. If message was sent to more than 1 subscriber
12 ;than the other message IDs will be in the array HLRESLT(n)=ID
13 ;Otherwise, three pieces are returned with the
14 ;first piece equal to the message ID, if one was assigned, otherwise 0
15 ;
16 ;Required Input Parameters
17 ; HLEID = Name or IEN of event driver protocol in the Protocol file
18 ; HLARYTYP = Array type. One of the following codes:
19 ; LM = local array containing a single message
20 ; LB = local array containig a batch of messages
21 ; GM = global array containing a single message
22 ; GB = global array containing a batch of messages
23 ; HLFORMAT = Format of array, 1 for pre-formatted in HL7 format,
24 ; otherwise 0
25 ;NOTE: The parameter HLRESLT must be passed by reference
26 ; HLRESLT = The variable that will be returned to the calling
27 ; application as descibed above
28 ;Optional Parameters
29 ; HLMTIEN = IEN of entry in Message Text file where the message
30 ; being generated is to be stored. This parameter is
31 ; only passed for a batch type message
32 ;NOTE: The parameter HLP used for the following parameters must be
33 ; passed by reference
34 ; HLP("SECURITY") = A 1 to 40 character string
35 ; HLP("CONTPTR") = Continuation pointer, a 1 to 180 character string
36 ; HLP("NAMESPACE") = Passed in by application namespace - HL*1.6*91
37 ; HLP("EXCLUDE SUBSCRIBER",<n=1,2,3...>)=<subscriber protocol ien> or
38 ; <subscriber protocol name> - A list of protocols to dynamically
39 ; drop from the event protocol's subscriber multiple.
40 ;
41 ;can't have link open when generating new message
42 N HLTCP,HLTCPO,HLPRIO,HLMIDAR
43 S HLPRIO="D"
44 S HLRESLT=""
45 ;Check for required parameters
46CONT ;
47 I $G(HLEID)']""!($G(HLARYTYP)']"")!($G(HLFORMAT)']"") D G EXIT
48 . S HLRESLT="0^7^"_$G(^HL(771.7,7,0))_" at GENERATE^HLMA entry point"
49 I 'HLEID S HLEID=$O(^ORD(101,"B",HLEID,0)) I 'HLEID S HLRESLT="0^1^"_$G(^HL(771.7,1,0)) G EXIT
50 N HLRESLT1,HLRESLTA S (HLRESLTA,HLRESLT1)=""
51 I "GL"'[$E(HLARYTYP) S HLRESLT="0^4^"_$G(^HL(771.7,4,0)) G EXIT
52 I $L($G(HLP("SECURITY")))>40 S HLRESLT="0^6^"_$G(^HL(771.7,6,0)) G EXIT
53 I $L($G(HLP("CONTPTR")))>180 S HLRESLT="0^11^"_$G(^HL(771.7,11,0)) G EXIT
54 I $D(HLL("LINKS")) D G:$G(HLRESLT)]"" EXIT
55 . N I,HLPNAM,HLPIEN,HLLNAM,HLLIEN
56 . S I=0
57 . F S I=$O(HLL("LINKS",I)) Q:'I D Q:$G(HLRESLT)]""
58 . . S HLPNAM=$P(HLL("LINKS",I),U)
59 . . S HLPIEN=+$O(^ORD(101,"B",HLPNAM,0))
60 . . I $P($G(^ORD(101,HLPIEN,0)),U,4)'="S" S HLRESLT="0^15^Invalid Subscriber Protocol in HLL('LINKS'): "_HLL("LINKS",I) Q
61 . . S HLLNAM=$P(HLL("LINKS",I),U,2)
62 . . S HLLIEN=+$O(^HLCS(870,"B",HLLNAM,0))
63 . . I '$D(^HLCS(870,HLLIEN,0)) S HLRESLT="0^15^Invalid HL Node in HLL('LINKS'): "_HLL("LINKS",I) Q
64 ;Extract data from Protocol file
65 D EVENT^HLUTIL1(HLEID,"15,20,771",.HLN)
66 S HLENROU=$G(HLN(20)),HLEXROU=$G(HLN(15))
67 S HLP("GROUTINE")=$G(HLN(771)) K HLN I HLP("GROUTINE")']"",'HLFORMAT S HLRESLT="0^3^"_$G(^HL(771.7,3,0)) G EXIT
68 ;Create message ID and Message Text IEN if Message Text IEN not
69 ;previously created ('$G(HLMTIEN))
70 I '$G(HLMTIEN) D CREATE^HLTF(.HLMID,.HLMTIEN,.HLDT,.HLDT1)
71 ;Get message ID if Message Text IEN already created
72 I '$G(HLMID) D
73 .S HLDT=$G(^HL(772,HLMTIEN,0)),HLMID=$P(HLDT,"^",6),HLDT=+HLDT
74 .S HLDT1=$$HLDATE^HLFNC(HLDT)
75 S HLMIDAR=0,HLRESLT=HLMID,HLP("DT")=HLDT,HLP("DTM")=HLDT1
76 ;Execute entry action for event driver protocol
77 I HLENROU]"" X HLENROU
78 ;Invoke transaction processor
79 K HLDT,HLDT1,HLENROU
80 D GENERATE^HLTP(HLMID,HLMTIEN,HLEID,HLARYTYP,HLFORMAT,.HLRESLT1,.HLP)
81 ;HLMIDAR is array of message IDs, only set for broadcast messages
82 I HLMIDAR K HLMIDAR("N") M HLRESLT=HLMIDAR
83 S HLRESLT=HLRESLT_"^"_HLRESLT1
84 ;
85 ; patch HL*1.6*122
86 S HLRESLT("HLMID")=$G(HLMIDAR("HLMID"))
87 S HLRESLT("IEN773")=$G(HLMIDAR("IEN773"))
88 ;
89 ;Execute exit action for event driver protocol
90 I HLEXROU]"" X HLEXROU
91EXIT ;Update status if Message Text file entry has been created
92 K HLTCP
93 I $D(HLMTIEN) D STATUS^HLTF0(HLMTIEN,$S($P(HLRESLT,"^",2):4,1:3),$S($P(HLRESLT,"^",2):$P(HLRESLT,"^",2),1:""),$S($P(HLRESLT,"^",2):$P(HLRESLT,"^",3),1:""))
94 K HLDT,HLDT1,HLMID,HLRESLT1,HLENROU,HLEXROU
95 Q
96DIRECT(HLEID,HLARYTYP,HLFORMAT,HLRESLT,HLMTIENO,HLP) ;
97 ;Entry point to generate an immediate message, must be TCP Logical Link
98 ;Input:
99 ; The same as GENERATE,with one additional subscript to the HLP input
100 ; array:
101 ;
102 ; HLP("OPEN TIMEOUT") (optional, pass by reference) a number between
103 ; 1 and 120 that specifies how many seconds the DIRECT CONNECT should
104 ; try to open a connection before failing. It is killed upon
105 ; completion.
106 ;
107 N HLTCP,HLTCPO,HLPRIO,HLSAN,HLN,HLMIDAR,HLMTIENR,ZMID,HLDIRECT
108 S HLRESLT=""
109 ;HLMTIENO=ien passed in, batch message
110 S HLMTIEN=$G(HLMTIENO)
111 I $G(HLP("OPEN TIMEOUT")),((HLP("OPEN TIMEOUT")\1)'=+HLP("OPEN TIMEOUT"))!HLP("OPEN TIMEOUT")>120 Q "0^4^INVALID OPEN TIMEOUT PARAMETER"
112 I $G(HLP("OPEN TIMEOUT")) D
113 .S HLDIRECT("OPEN TIMEOUT")=HLP("OPEN TIMEOUT")
114 .K HLP("OPEN TIMEOUT")
115 K HL,HLMTIENO
116 D INIT^HLFNC2(HLEID,.HL)
117 I $G(HL) S HLRESLT="0^"_HL Q
118 S HLPRIO="I" D CONT
119 ;HLMTIENO=original msg. ien in file 772, HLMTIENR=response ien set in HLMA2
120 S HLMTIENO=HLMTIEN,HLMTIEN=$G(HLMTIENR)
121 ;Set special HL variables
122 S HLQUIT=0,HLNODE="",HLNEXT="D HLNEXT^HLCSUTL"
123 Q
124 ;
125CLOSE(LOGLINK) ;close connection that was open in tag DIRECT
126 Q
127PING ;ping another VAMC to test Link
128 ;set HLQUIET =1 to skip writes
129 ;look for HLTPUT to get turnaround time over network.
130 N DA,DIC,HLDP,HLDPNM,HLDPDM,HLCSOUT,HLDBSIZE,HLDREAD,HLOS,HLTCPADD,HLTCPCS,HLTCPLNK,HLTCPORT,HLTCPRET,HLCSFAIL,HLPARAM
131 N HCS,HCSCMD,HLCS,HCSDAT,HCSER,HCSEXIT,HCSTRACE,HLDT1,HLDRETR,HLRETRA,HLDBACK,HLDWAIT,HLTCPCS,INPUT,OUTPUT,POP,X,Y,HLX1,HLX2
132 S HLQUIET=$G(HLQUIET)
133 S HLCS="",HCSTRACE="C: ",POP=1,INPUT="INPUT",OUTPUT="OUTPUT"
134 S DIC="^HLCS(870,",DIC(0)="QEAMZ"
135 D ^DIC Q:Y<0
136 S HLDP=+Y,HLDPNM=Y(0,0),HLDPDM=$P($$PARAM^HLCS2,U,2)
137 ;I $P($G(^HLCS(870,HLDP,400)),U)="" W !,"Missing IP Address" Q
138 D SETUP^HLCSAC G:HLCS PINGQ
139 ; patch HL*1.6*122
140 G:$$DONTPING^HLMA4 PINGQ
141 ;PING header=MSH^PING^domain^PING^logical link^datetime
142 S INPUT(1)="MSH^PING^"_HLDPDM_"^PING^"_HLDPNM_"^"_$$HTE^XLFDT($H)
143 D OPEN^HLCSAC
144 I HLCS D DNS G:HLCS PINGQ
145 D
146 . N $ETRAP,$ESTACK S $ETRAP="D PINGERR^HLMA"
147 . ;non-standard HL7 header; start block,header,end block
148 . S HLX1=$H
149 . ;
150 . ; HL*1.6*122 start
151 . ; replace flush character '!' with @IOF (! or #)
152 . ; W $C(11)_INPUT(1)_$C(28)_$C(13),! ;HL*1.6*115, restored ! char
153 . W $C(11)_INPUT(1)_$C(28)_$C(13),@IOF
154 . ; HL*1.6*122 end
155 . ;
156 . ;read response
157 . R X:HLDREAD
158 . S HLX2=$H
159 . S X=$P(X,$C(28)),HLCS=$S(X=INPUT(1):"PING worked",X="":"No response",1:"Incorrect response")
160 . ;Get roundtrip time
161 . K HLTPUT I X]"" S HLTPUT=$$HDIFF^XLFDT(HLX2,HLX1,2)
162 D CLOSE^%ZISTCP
163PINGQ ;write back status and quit
164 I 'HLQUIET W !,HLCS,!
165 Q
166PINGERR ;process errors from PING
167 S $ETRAP="G UNWIND^%ZTER",HLCS="-1^Error"
168 ;I $ZE["READ" S HLCS="-1^Error during read"
169 ;I $ZE["WRITE" S HLCS="-1^Error during write"
170 ; HL*1.6*115, SACC compliance
171 I $$EC^%ZOSV["READ" S HLCS="-1^Error during read"
172 I $$EC^%ZOSV["WRITE" S HLCS="-1^Error during write"
173 G UNWIND^%ZTER
174DNS ;
175 ;openfail-try DNS lookup-Link must contain point to Domain Name
176 S POP=$G(POP)
177 S HLQUIET=$G(HLQUIET)
178 I 'HLQUIET W !,"Calling DNS"
179 N HLDOM,HLIP S HLCS=""
180 S HLDOM=$P(^HLCS(870,HLDP,0),U,7)
181 ; patch HL*1.6*122 start
182 S HLDOM("DNS")=$P($G(^HLCS(870,+$G(HLDP),0)),"^",8)
183 ; I 'HLDOM,'HLQUIET W !,"Domain Unknown" Q
184 I 'HLDOM,($L(HLDOM("DNS"),".")<3) D Q
185 . I 'HLQUIET W !,"Domain Unknown"
186 . S HLCS="-1^Connection Fail"
187 ; patch HL*1.6*122 end
188 I HLDOM S HLDOM=$P(^DIC(4.2,HLDOM,0),U)
189 ; patch HL*1.6*122
190 ; I HLDOM]"" D Q:'POP
191 I HLDOM]""!($L(HLDOM("DNS"),".")>2) D Q:'POP
192 . I HLDOM["VA.GOV"&(HLDOM'[".MED.") S HLDOM=$P(HLDOM,".VA.GOV")_".MED.VA.GOV"
193 . I HLTCPORT=5000 S HLDOM="HL7."_HLDOM
194 . I HLTCPORT=5500 S HLDOM="MPI."_HLDOM
195 . ; patch HL*1.6*122
196 . I ($L(HLDOM("DNS"),".")>2) S HLDOM=HLDOM("DNS")
197 . I 'HLQUIET W !,"Domain, "_HLDOM
198 . I 'HLQUIET W !,"Port: ",HLTCPORT
199 . S HLIP=$$ADDRESS^XLFNSLK(HLDOM)
200 . I HLIP]"",'HLQUIET W !,"DNS Returned: ",HLIP
201 . I HLIP]"" D
202 . . ;If more than one IP returned, try each, cache successful open
203 . . N HLI,HLJ,HLIP1
204 . . F HLJ=1:1:$L(HLIP,",") D Q:'POP
205 . . . S HLIP1=$P(HLIP,",",HLJ)
206 . . . F HLI=1:1:HLDRETR W:'HLQUIET !,"Trying ",HLIP1 D CALL^%ZISTCP(HLIP1,HLTCPORT,1) Q:'POP
207 . . . I 'POP S $P(^HLCS(870,HLDP,400),U)=HLIP1
208 . . . U IO
209 I POP S HLCS="-1^DNS Lookup Failed"
Note: See TracBrowser for help on using the repository browser.