Home   Package List   Routine Alphabetical List   Global Alphabetical List   FileMan Files List   FileMan Sub-Files List   Package Component Lists   Package-Namespace Mapping  
Routine: HLMA

HLMA.m

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