HLMA ;AISC/SAW-Message Administration Module ;09/13/2006
;;1.6;HEALTH LEVEL SEVEN;**19,43,58,63,66,82,91,109,115,133**;Oct 13, 1995;Build 13
;Per VHA Directive 2004-038, this routine should not be modified.
GENERATE(HLEID,HLARYTYP,HLFORMAT,HLRESLT,HLMTIEN,HLP) ;
;Entry point to generate a deferred message
;
;This is a subroutine call with parameter passing. It returns a
;value in the variable HLRESLT with 1 to 3 pieces separated by uparrows
;as follows: 1st message ID^error code^error description
;If no error occurs, only the first piece is returned equal to a unique
;ID for the 1st message. If message was sent to more than 1 subscriber
;than the other message IDs will be in the array HLRESLT(n)=ID
;Otherwise, three pieces are returned with the
;first piece equal to the message ID, if one was assigned, otherwise 0
;
;Required Input Parameters
; HLEID = Name or IEN of event driver protocol in the Protocol file
; HLARYTYP = Array type. One of the following codes:
; LM = local array containing a single message
; LB = local array containig a batch of messages
; GM = global array containing a single message
; GB = global array containing a batch of messages
; HLFORMAT = Format of array, 1 for pre-formatted in HL7 format,
; otherwise 0
;NOTE: The parameter HLRESLT must be passed by reference
; HLRESLT = The variable that will be returned to the calling
; application as descibed above
;Optional Parameters
; HLMTIEN = IEN of entry in Message Text file where the message
; being generated is to be stored. This parameter is
; only passed for a batch type message
;NOTE: The parameter HLP used for the following parameters must be
; passed by reference
; HLP("SECURITY") = A 1 to 40 character string
; HLP("CONTPTR") = Continuation pointer, a 1 to 180 character string
; HLP("NAMESPACE") = Passed in by application namespace - HL*1.6*91
;
;can't have link open when generating new message
N HLTCP,HLTCPO,HLPRIO,HLMIDAR
S HLPRIO="D"
S HLRESLT=""
;Check for required parameters
CONT I $G(HLEID)']""!($G(HLARYTYP)']"")!($G(HLFORMAT)']"") S HLRESLT="0^7^"_$G(^HL(771.7,7,0))_" at GENERATE^HLMA entry point" G EXIT
I 'HLEID S HLEID=$O(^ORD(101,"B",HLEID,0)) I 'HLEID S HLRESLT="0^1^"_$G(^HL(771.7,1,0)) G EXIT
N HLRESLT1,HLRESLTA S (HLRESLTA,HLRESLT1)=""
I "GL"'[$E(HLARYTYP) S HLRESLT="0^4^"_$G(^HL(771.7,4,0)) G EXIT
I $L($G(HLP("SECURITY")))>40 S HLRESLT="0^6^"_$G(^HL(771.7,6,0)) G EXIT
I $L($G(HLP("CONTPTR")))>180 S HLRESLT="0^11^"_$G(^HL(771.7,11,0)) G EXIT
I $D(HLL("LINKS")) D G:$G(HLRESLT)]"" EXIT
. N I,HLPNAM,HLPIEN,HLLNAM,HLLIEN
. S I=0
. F S I=$O(HLL("LINKS",I)) Q:'I D Q:$G(HLRESLT)]""
. . S HLPNAM=$P(HLL("LINKS",I),U)
. . S HLPIEN=+$O(^ORD(101,"B",HLPNAM,0))
. . I $P($G(^ORD(101,HLPIEN,0)),U,4)'="S" S HLRESLT="0^15^Invalid Subscriber Protocol in HLL('LINKS'): "_HLL("LINKS",I) Q
. . S HLLNAM=$P(HLL("LINKS",I),U,2)
. . S HLLIEN=+$O(^HLCS(870,"B",HLLNAM,0))
. . I '$D(^HLCS(870,HLLIEN,0)) S HLRESLT="0^15^Invalid HL Node in HLL('LINKS'): "_HLL("LINKS",I) Q
;Extract data from Protocol file
D EVENT^HLUTIL1(HLEID,"15,20,771",.HLN)
S HLENROU=$G(HLN(20)),HLEXROU=$G(HLN(15))
S HLP("GROUTINE")=$G(HLN(771)) K HLN I HLP("GROUTINE")']"",'HLFORMAT S HLRESLT="0^3^"_$G(^HL(771.7,3,0)) G EXIT
;Create message ID and Message Text IEN if Message Text IEN not
;previously created ('$G(HLMTIEN))
I '$G(HLMTIEN) D CREATE^HLTF(.HLMID,.HLMTIEN,.HLDT,.HLDT1)
;Get message ID if Message Text IEN already created
I '$G(HLMID) D
.S HLDT=$G(^HL(772,HLMTIEN,0)),HLMID=$P(HLDT,"^",6),HLDT=+HLDT
.S HLDT1=$$HLDATE^HLFNC(HLDT)
S HLMIDAR=0,HLRESLT=HLMID,HLP("DT")=HLDT,HLP("DTM")=HLDT1
;Execute entry action for event driver protocol
I HLENROU]"" X HLENROU
;Invoke transaction processor
K HLDT,HLDT1,HLENROU
D GENERATE^HLTP(HLMID,HLMTIEN,HLEID,HLARYTYP,HLFORMAT,.HLRESLT1,.HLP)
;HLMIDAR is array of message IDs, only set for broadcast messages
I HLMIDAR K HLMIDAR("N") M HLRESLT=HLMIDAR
S HLRESLT=HLRESLT_"^"_HLRESLT1
;Execute exit action for event driver protocol
I HLEXROU]"" X HLEXROU
EXIT ;Update status if Message Text file entry has been created
K HLTCP
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:""))
K HLDT,HLDT1,HLMID,HLRESLT1,HLENROU,HLEXROU
Q
DIRECT(HLEID,HLARYTYP,HLFORMAT,HLRESLT,HLMTIENO,HLP) ;
;Entry point to generate an immediate message, must be TCP Logical Link
;Input:
; The same as GENERATE,with one additional subscript to the HLP input array:
;
; HLP("OPEN TIMEOUT") (optional, pass by reference) a number between
; 1 and 120 that specifies how many seconds the DIRECT CONNECT should
; try to open a connection before failing. It is killed upon completion.
;
N HLTCP,HLTCPO,HLPRIO,HLSAN,HLN,HLMIDAR,HLMTIENR,ZMID,HLDIRECT
S HLRESLT=""
;HLMTIENO=ien passed in, batch message
S HLMTIEN=$G(HLMTIENO)
I $G(HLP("OPEN TIMEOUT")),((HLP("OPEN TIMEOUT")\1)'=+HLP("OPEN TIMEOUT"))!HLP("OPEN TIMEOUT")>120 Q "0^4^INVALID OPEN TIMEOUT PARAMETER"
I $G(HLP("OPEN TIMEOUT")) D
.S HLDIRECT("OPEN TIMEOUT")=HLP("OPEN TIMEOUT")
.K HLP("OPEN TIMEOUT")
K HL,HLMTIENO
D INIT^HLFNC2(HLEID,.HL)
I $G(HL) S HLRESLT="0^"_HL Q
S HLPRIO="I" D CONT
;HLMTIENO=original msg. ien in file 772, HLMTIENR=response ien set in HLMA2
S HLMTIENO=HLMTIEN,HLMTIEN=$G(HLMTIENR)
;Set special HL variables
S HLQUIT=0,HLNODE="",HLNEXT="D HLNEXT^HLCSUTL"
Q
;
CLOSE(LOGLINK) ;close connection that was open in tag DIRECT
Q
PING ;ping another VAMC to test Link
;set HLQUIET =1 to skip writes
;look for HLTPUT to get turnaround time over network.
N DA,DIC,HLDP,HLDPNM,HLDPDM,HLCSOUT,HLDBSIZE,HLDREAD,HLOS,HLTCPADD,HLTCPCS,HLTCPLNK,HLTCPORT,HLTCPRET,HLCSFAIL,HLPARAM
N HCS,HCSCMD,HLCS,HCSDAT,HCSER,HCSEXIT,HCSTRACE,HLDT1,HLDRETR,HLRETRA,HLDBACK,HLDWAIT,HLTCPCS,INPUT,OUTPUT,POP,X,Y,HLX1,HLX2
S HLQUIET=$G(HLQUIET)
S HLCS="",HCSTRACE="C: ",POP=1,INPUT="INPUT",OUTPUT="OUTPUT"
S DIC="^HLCS(870,",DIC(0)="QEAMZ"
D ^DIC Q:Y<0
S HLDP=+Y,HLDPNM=Y(0,0),HLDPDM=$P($$PARAM^HLCS2,U,2)
;I $P($G(^HLCS(870,HLDP,400)),U)="" W !,"Missing IP Address" Q
D SETUP^HLCSAC G:HLCS PINGQ
;PING header=MSH^PING^domain^PING^logical link^datetime
S INPUT(1)="MSH^PING^"_HLDPDM_"^PING^"_HLDPNM_"^"_$$HTE^XLFDT($H)
D OPEN^HLCSAC
I HLCS D DNS G:HLCS PINGQ
D
. N $ETRAP,$ESTACK S $ETRAP="D PINGERR^HLMA"
. ;non-standard HL7 header; start block,header,end block
. S HLX1=$H
. W $C(11)_INPUT(1)_$C(28)_$C(13),! ;HL*1.6*115, restored ! char
. ;read response
. R X:HLDREAD
. S HLX2=$H
. S X=$P(X,$C(28)),HLCS=$S(X=INPUT(1):"PING worked",X="":"No response",1:"Incorrect response")
. ;Get roundtrip time
. K HLTPUT I X]"" S HLTPUT=$$HDIFF^XLFDT(HLX2,HLX1,2)
D CLOSE^%ZISTCP
PINGQ ;write back status and quit
I 'HLQUIET W !,HLCS,!
Q
PINGERR ;process errors from PING
S $ETRAP="G UNWIND^%ZTER",HLCS="-1^Error"
;I $ZE["READ" S HLCS="-1^Error during read"
;I $ZE["WRITE" S HLCS="-1^Error during write"
; HL*1.6*115, SACC compliance
I $$EC^%ZOSV["READ" S HLCS="-1^Error during read"
I $$EC^%ZOSV["WRITE" S HLCS="-1^Error during write"
G UNWIND^%ZTER
DNS ;
;openfail-try DNS lookup-Link must contain point to Domain Name
S POP=$G(POP)
S HLQUIET=$G(HLQUIET)
I 'HLQUIET W !,"Calling DNS"
N HLDOM,HLIP S HLCS=""
S HLDOM=$P(^HLCS(870,HLDP,0),U,7)
I 'HLDOM,'HLQUIET W !,"Domain Unknown" Q
I HLDOM S HLDOM=$P(^DIC(4.2,HLDOM,0),U)
I HLDOM]"" D Q:'POP
. I HLDOM["VA.GOV"&(HLDOM'[".MED.") S HLDOM=$P(HLDOM,".VA.GOV")_".MED.VA.GOV"
. I HLTCPORT=5000 S HLDOM="HL7."_HLDOM
. I HLTCPORT=5500 S HLDOM="MPI."_HLDOM
. I 'HLQUIET W !,"Domain, "_HLDOM
. I 'HLQUIET W !,"Port: ",HLTCPORT
. S HLIP=$$ADDRESS^XLFNSLK(HLDOM)
. I HLIP]"",'HLQUIET W !,"DNS Returned: ",HLIP
. I HLIP]"" D
. . ;If more than one IP returned, try each, cache successful open
. . N HLI,HLJ,HLIP1
. . F HLJ=1:1:$L(HLIP,",") D Q:'POP
. . . S HLIP1=$P(HLIP,",",HLJ)
. . . F HLI=1:1:HLDRETR W:'HLQUIET !,"Trying ",HLIP1 D CALL^%ZISTCP(HLIP1,HLTCPORT,1) Q:'POP
. . . I 'POP S $P(^HLCS(870,HLDP,400),U)=HLIP1
. . . U IO
I POP S HLCS="-1^DNS Lookup Failed"
HLMA ;AISC/SAW-Message Administration Module ;09/13/2006
+1 ;;1.6;HEALTH LEVEL SEVEN;**19,43,58,63,66,82,91,109,115,133**;Oct 13, 1995;Build 13
+2 ;Per VHA Directive 2004-038, this routine should not be modified.
GENERATE(HLEID,HLARYTYP,HLFORMAT,HLRESLT,HLMTIEN,HLP) ;
+1 ;Entry point to generate a deferred message
+2 ;
+3 ;This is a subroutine call with parameter passing. It returns a
+4 ;value in the variable HLRESLT with 1 to 3 pieces separated by uparrows
+5 ;as follows: 1st message ID^error code^error description
+6 ;If no error occurs, only the first piece is returned equal to a unique
+7 ;ID for the 1st message. If message was sent to more than 1 subscriber
+8 ;than the other message IDs will be in the array HLRESLT(n)=ID
+9 ;Otherwise, three pieces are returned with the
+10 ;first piece equal to the message ID, if one was assigned, otherwise 0
+11 ;
+12 ;Required Input Parameters
+13 ; HLEID = Name or IEN of event driver protocol in the Protocol file
+14 ; HLARYTYP = Array type. One of the following codes:
+15 ; LM = local array containing a single message
+16 ; LB = local array containig a batch of messages
+17 ; GM = global array containing a single message
+18 ; GB = global array containing a batch of messages
+19 ; HLFORMAT = Format of array, 1 for pre-formatted in HL7 format,
+20 ; otherwise 0
+21 ;NOTE: The parameter HLRESLT must be passed by reference
+22 ; HLRESLT = The variable that will be returned to the calling
+23 ; application as descibed above
+24 ;Optional Parameters
+25 ; HLMTIEN = IEN of entry in Message Text file where the message
+26 ; being generated is to be stored. This parameter is
+27 ; only passed for a batch type message
+28 ;NOTE: The parameter HLP used for the following parameters must be
+29 ; passed by reference
+30 ; HLP("SECURITY") = A 1 to 40 character string
+31 ; HLP("CONTPTR") = Continuation pointer, a 1 to 180 character string
+32 ; HLP("NAMESPACE") = Passed in by application namespace - HL*1.6*91
+33 ;
+34 ;can't have link open when generating new message
+35 NEW HLTCP,HLTCPO,HLPRIO,HLMIDAR
+36 SET HLPRIO="D"
+37 SET HLRESLT=""
+38 ;Check for required parameters
CONT IF $GET(HLEID)']""!($GET(HLARYTYP)']"")!($GET(HLFORMAT)']"")
SET HLRESLT="0^7^"_$GET(^HL(771.7,7,0))_" at GENERATE^HLMA entry point"
GOTO EXIT
+1 IF 'HLEID
SET HLEID=$ORDER(^ORD(101,"B",HLEID,0))
IF 'HLEID
SET HLRESLT="0^1^"_$GET(^HL(771.7,1,0))
GOTO EXIT
+2 NEW HLRESLT1,HLRESLTA
SET (HLRESLTA,HLRESLT1)=""
+3 IF "GL"'[$EXTRACT(HLARYTYP)
SET HLRESLT="0^4^"_$GET(^HL(771.7,4,0))
GOTO EXIT
+4 IF $LENGTH($GET(HLP("SECURITY")))>40
SET HLRESLT="0^6^"_$GET(^HL(771.7,6,0))
GOTO EXIT
+5 IF $LENGTH($GET(HLP("CONTPTR")))>180
SET HLRESLT="0^11^"_$GET(^HL(771.7,11,0))
GOTO EXIT
+6 IF $DATA(HLL("LINKS"))
Begin DoDot:1
+7 NEW I,HLPNAM,HLPIEN,HLLNAM,HLLIEN
+8 SET I=0
+9 FOR
SET I=$ORDER(HLL("LINKS",I))
IF 'I
QUIT
Begin DoDot:2
+10 SET HLPNAM=$PIECE(HLL("LINKS",I),U)
+11 SET HLPIEN=+$ORDER(^ORD(101,"B",HLPNAM,0))
+12 IF $PIECE($GET(^ORD(101,HLPIEN,0)),U,4)'="S"
SET HLRESLT="0^15^Invalid Subscriber Protocol in HLL('LINKS'): "_HLL("LINKS",I)
QUIT
+13 SET HLLNAM=$PIECE(HLL("LINKS",I),U,2)
+14 SET HLLIEN=+$ORDER(^HLCS(870,"B",HLLNAM,0))
+15 IF '$DATA(^HLCS(870,HLLIEN,0))
SET HLRESLT="0^15^Invalid HL Node in HLL('LINKS'): "_HLL("LINKS",I)
QUIT
End DoDot:2
IF $GET(HLRESLT)]""
QUIT
End DoDot:1
IF $GET(HLRESLT)]""
GOTO EXIT
+16 ;Extract data from Protocol file
+17 DO EVENT^HLUTIL1(HLEID,"15,20,771",.HLN)
+18 SET HLENROU=$GET(HLN(20))
SET HLEXROU=$GET(HLN(15))
+19 SET HLP("GROUTINE")=$GET(HLN(771))
KILL HLN
IF HLP("GROUTINE")']""
IF 'HLFORMAT
SET HLRESLT="0^3^"_$GET(^HL(771.7,3,0))
GOTO EXIT
+20 ;Create message ID and Message Text IEN if Message Text IEN not
+21 ;previously created ('$G(HLMTIEN))
+22 IF '$GET(HLMTIEN)
DO CREATE^HLTF(.HLMID,.HLMTIEN,.HLDT,.HLDT1)
+23 ;Get message ID if Message Text IEN already created
+24 IF '$GET(HLMID)
Begin DoDot:1
+25 SET HLDT=$GET(^HL(772,HLMTIEN,0))
SET HLMID=$PIECE(HLDT,"^",6)
SET HLDT=+HLDT
+26 SET HLDT1=$$HLDATE^HLFNC(HLDT)
End DoDot:1
+27 SET HLMIDAR=0
SET HLRESLT=HLMID
SET HLP("DT")=HLDT
SET HLP("DTM")=HLDT1
+28 ;Execute entry action for event driver protocol
+29 IF HLENROU]""
XECUTE HLENROU
+30 ;Invoke transaction processor
+31 KILL HLDT,HLDT1,HLENROU
+32 DO GENERATE^HLTP(HLMID,HLMTIEN,HLEID,HLARYTYP,HLFORMAT,.HLRESLT1,.HLP)
+33 ;HLMIDAR is array of message IDs, only set for broadcast messages
+34 IF HLMIDAR
KILL HLMIDAR("N")
MERGE HLRESLT=HLMIDAR
+35 SET HLRESLT=HLRESLT_"^"_HLRESLT1
+36 ;Execute exit action for event driver protocol
+37 IF HLEXROU]""
XECUTE HLEXROU
EXIT ;Update status if Message Text file entry has been created
+1 KILL HLTCP
+2 IF $DATA(HLMTIEN)
DO STATUS^HLTF0(HLMTIEN,$SELECT($PIECE(HLRESLT,"^",2):4,1:3),$SELECT($PIECE(HLRESLT,"^",2):$PIECE(HLRESLT,"^",2),1:""),$SELECT($PIECE(HLRESLT,"^",2):$PIECE(HLRESLT,"^",3),1:""))
+3 KILL HLDT,HLDT1,HLMID,HLRESLT1,HLENROU,HLEXROU
+4 QUIT
DIRECT(HLEID,HLARYTYP,HLFORMAT,HLRESLT,HLMTIENO,HLP) ;
+1 ;Entry point to generate an immediate message, must be TCP Logical Link
+2 ;Input:
+3 ; The same as GENERATE,with one additional subscript to the HLP input array:
+4 ;
+5 ; HLP("OPEN TIMEOUT") (optional, pass by reference) a number between
+6 ; 1 and 120 that specifies how many seconds the DIRECT CONNECT should
+7 ; try to open a connection before failing. It is killed upon completion.
+8 ;
+9 NEW HLTCP,HLTCPO,HLPRIO,HLSAN,HLN,HLMIDAR,HLMTIENR,ZMID,HLDIRECT
+10 SET HLRESLT=""
+11 ;HLMTIENO=ien passed in, batch message
+12 SET HLMTIEN=$GET(HLMTIENO)
+13 IF $GET(HLP("OPEN TIMEOUT"))
IF ((HLP("OPEN TIMEOUT")\1)'=+HLP("OPEN TIMEOUT"))!HLP("OPEN TIMEOUT")>120
QUIT "0^4^INVALID OPEN TIMEOUT PARAMETER"
+14 IF $GET(HLP("OPEN TIMEOUT"))
Begin DoDot:1
+15 SET HLDIRECT("OPEN TIMEOUT")=HLP("OPEN TIMEOUT")
+16 KILL HLP("OPEN TIMEOUT")
End DoDot:1
+17 KILL HL,HLMTIENO
+18 DO INIT^HLFNC2(HLEID,.HL)
+19 IF $GET(HL)
SET HLRESLT="0^"_HL
QUIT
+20 SET HLPRIO="I"
DO CONT
+21 ;HLMTIENO=original msg. ien in file 772, HLMTIENR=response ien set in HLMA2
+22 SET HLMTIENO=HLMTIEN
SET HLMTIEN=$GET(HLMTIENR)
+23 ;Set special HL variables
+24 SET HLQUIT=0
SET HLNODE=""
SET HLNEXT="D HLNEXT^HLCSUTL"
+25 QUIT
+26 ;
CLOSE(LOGLINK) ;close connection that was open in tag DIRECT
+1 QUIT
PING ;ping another VAMC to test Link
+1 ;set HLQUIET =1 to skip writes
+2 ;look for HLTPUT to get turnaround time over network.
+3 NEW DA,DIC,HLDP,HLDPNM,HLDPDM,HLCSOUT,HLDBSIZE,HLDREAD,HLOS,HLTCPADD,HLTCPCS,HLTCPLNK,HLTCPORT,HLTCPRET,HLCSFAIL,HLPARAM
+4 NEW HCS,HCSCMD,HLCS,HCSDAT,HCSER,HCSEXIT,HCSTRACE,HLDT1,HLDRETR,HLRETRA,HLDBACK,HLDWAIT,HLTCPCS,INPUT,OUTPUT,POP,X,Y,HLX1,HLX2
+5 SET HLQUIET=$GET(HLQUIET)
+6 SET HLCS=""
SET HCSTRACE="C: "
SET POP=1
SET INPUT="INPUT"
SET OUTPUT="OUTPUT"
+7 SET DIC="^HLCS(870,"
SET DIC(0)="QEAMZ"
+8 DO ^DIC
IF Y<0
QUIT
+9 SET HLDP=+Y
SET HLDPNM=Y(0,0)
SET HLDPDM=$PIECE($$PARAM^HLCS2,U,2)
+10 ;I $P($G(^HLCS(870,HLDP,400)),U)="" W !,"Missing IP Address" Q
+11 DO SETUP^HLCSAC
IF HLCS
GOTO PINGQ
+12 ;PING header=MSH^PING^domain^PING^logical link^datetime
+13 SET INPUT(1)="MSH^PING^"_HLDPDM_"^PING^"_HLDPNM_"^"_$$HTE^XLFDT($HOROLOG)
+14 DO OPEN^HLCSAC
+15 IF HLCS
DO DNS
IF HLCS
GOTO PINGQ
+16 Begin DoDot:1
+17 NEW $ETRAP,$ESTACK
SET $ETRAP="D PINGERR^HLMA"
+18 ;non-standard HL7 header; start block,header,end block
+19 SET HLX1=$HOROLOG
+20 ;HL*1.6*115, restored ! char
WRITE $CHAR(11)_INPUT(1)_$CHAR(28)_$CHAR(13),!
+21 ;read response
+22 READ X:HLDREAD
+23 SET HLX2=$HOROLOG
+24 SET X=$PIECE(X,$CHAR(28))
SET HLCS=$SELECT(X=INPUT(1):"PING worked",X="":"No response",1:"Incorrect response")
+25 ;Get roundtrip time
+26 KILL HLTPUT
IF X]""
SET HLTPUT=$$HDIFF^XLFDT(HLX2,HLX1,2)
End DoDot:1
+27 DO CLOSE^%ZISTCP
PINGQ ;write back status and quit
+1 IF 'HLQUIET
WRITE !,HLCS,!
+2 QUIT
PINGERR ;process errors from PING
+1 SET $ETRAP="G UNWIND^%ZTER"
SET HLCS="-1^Error"
+2 ;I $ZE["READ" S HLCS="-1^Error during read"
+3 ;I $ZE["WRITE" S HLCS="-1^Error during write"
+4 ; HL*1.6*115, SACC compliance
+5 IF $$EC^%ZOSV["READ"
SET HLCS="-1^Error during read"
+6 IF $$EC^%ZOSV["WRITE"
SET HLCS="-1^Error during write"
+7 GOTO UNWIND^%ZTER
DNS ;
+1 ;openfail-try DNS lookup-Link must contain point to Domain Name
+2 SET POP=$GET(POP)
+3 SET HLQUIET=$GET(HLQUIET)
+4 IF 'HLQUIET
WRITE !,"Calling DNS"
+5 NEW HLDOM,HLIP
SET HLCS=""
+6 SET HLDOM=$PIECE(^HLCS(870,HLDP,0),U,7)
+7 IF 'HLDOM
IF 'HLQUIET
WRITE !,"Domain Unknown"
QUIT
+8 IF HLDOM
SET HLDOM=$PIECE(^DIC(4.2,HLDOM,0),U)
+9 IF HLDOM]""
Begin DoDot:1
+10 IF HLDOM["VA.GOV"&(HLDOM'[".MED.")
SET HLDOM=$PIECE(HLDOM,".VA.GOV")_".MED.VA.GOV"
+11 IF HLTCPORT=5000
SET HLDOM="HL7."_HLDOM
+12 IF HLTCPORT=5500
SET HLDOM="MPI."_HLDOM
+13 IF 'HLQUIET
WRITE !,"Domain, "_HLDOM
+14 IF 'HLQUIET
WRITE !,"Port: ",HLTCPORT
+15 SET HLIP=$$ADDRESS^XLFNSLK(HLDOM)
+16 IF HLIP]""
IF 'HLQUIET
WRITE !,"DNS Returned: ",HLIP
+17 IF HLIP]""
Begin DoDot:2
+18 ;If more than one IP returned, try each, cache successful open
+19 NEW HLI,HLJ,HLIP1
+20 FOR HLJ=1:1:$LENGTH(HLIP,",")
Begin DoDot:3
+21 SET HLIP1=$PIECE(HLIP,",",HLJ)
+22 FOR HLI=1:1:HLDRETR
IF 'HLQUIET
WRITE !,"Trying ",HLIP1
DO CALL^%ZISTCP(HLIP1,HLTCPORT,1)
IF 'POP
QUIT
+23 IF 'POP
SET $PIECE(^HLCS(870,HLDP,400),U)=HLIP1
+24 USE IO
End DoDot:3
IF 'POP
QUIT
End DoDot:2
End DoDot:1
IF 'POP
QUIT
+25 IF POP
SET HLCS="-1^DNS Lookup Failed"