DGPFHLS ;ALB/RPM - PRF HL7 SEND DRIVERS ; 7/31/06 10:10am
;;5.3;Registration;**425,650,1015**;Aug 13, 1993;Build 21
;
SNDORU(DGPFIEN,DGPFHARR,DGFAC) ;Send ORU Message Types (ORU~R01)
;This function builds and transmits a single ORU message to all sites
;in the associated patient's TREATING FACILITY LIST (#391.91) file.
;The optional input parameter DGFAC overrides selection of sites
;from the TREATING FACILITY LIST file.
;
; Supported DBIA #2990: This supported DBIA is used to access the
; Registration API to generate a list of
; treating facilities for a given patient.
; Input:
; DGPFIEN - (required) IEN of assignment in PRF ASSIGNMENT (#26.13)
; file to transmit
; DGPFHARR - (optional) array of assignment history IENs from the
; PRF ASSIGNMENT HISTORY (#26.14) file to
; include in ORU.
; format: DGPFHARR(assignment_date_time)=IEN
; assignment_date_time in FM format
; [default = $$GETLAST^DGPFAAH(DGPFIEN)]
; DGFAC - (optional) array of message destination facilities
; passed by reference
; format: DGFAC(#)=station#
;
; Output:
; Function value - 1 on success, 0 on failure
;
N DGHLEID ;event protocol ID
N DGHL ;VistA HL7 environment array
N DGHLROOT ;message array location
N DGPFA ;assignment data array
N DGPFAH ;assignment history data array
N DGPFHIEN ;assignment history IEN
N DGRSLT ;function value
;
S DGRSLT=0
S DGHLROOT=$NA(^TMP("PRFORU",$J))
K @DGHLROOT
;
I +$G(DGPFIEN)>0,$D(^DGPF(26.13,DGPFIEN)) D
. ;
. ;retrieve assignment record
. Q:'$$GETASGN^DGPFAA(DGPFIEN,.DGPFA)
. ;
. ;set up default history IEN array
. I '$O(DGPFHARR(0)) D
. . N DGPFAH
. . S DGPFHIEN=$$GETLAST^DGPFAAH(DGPFIEN)
. . Q:'$$GETHIST^DGPFAAH(DGPFHIEN,.DGPFAH)
. . S DGPFHARR(+$G(DGPFAH("ASSIGNDT")))=DGPFHIEN
. Q:'$O(DGPFHARR(0))
. ;
. ;retrieve treating facilities when no destination is provided
. I $G(DGFAC(1))'>0 D TFL^VAFCTFU1(.DGFAC,+$G(DGPFA("DFN")))
. Q:$G(DGFAC(1))'>0
. ;
. ;initialize VistA HL7 environment
. S DGHLEID=$$INIT^DGPFHLUT("DGPF PRF ORU/R01 EVENT",.DGHL)
. Q:'DGHLEID
. ;
. ;build ORU segments array
. S DGPFHIEN=$$BLDORU^DGPFHLU(.DGPFA,.DGPFHARR,.DGHL,DGHLROOT)
. Q:'DGPFHIEN
. ;
. ;transmit and log messages
. Q:'$$XMIT^DGPFHLU6(DGPFHIEN,DGHLEID,.DGFAC,DGHLROOT,.DGHL)
. ;
. ;success
. S DGRSLT=1
;
;cleanup
K @DGHLROOT
Q DGRSLT
;
SNDACK(DGACKTYP,DGMIEN,DGHL,DGSEGERR,DGSTOERR) ;Send ACK Message Type (ACK~R01)
;This procedure assumes the the VistA HL7 environment is providing the
;environment variables and will produce a fatal error if they are
;missing.
;
; Input:
; DGACKTYP - (required) ACK message type ("AA","AE")
; DGMIEN - (required) IEN of message entry in file #773
; DGHL - (required) HL7 environment array
; DGSEGERR - (optional) Errors found during parsing
; DGSTOERR - (optional) Errors during data storage
;
; Output:
; none
;
N DGHLROOT
N DGHLERR
;
Q:($G(DGACKTYP)']"")
Q:('+$G(DGMIEN))
;
S DGHLROOT=$NA(^TMP("HLA",$J))
K @DGHLROOT
;
;build ACK segments array
I $$BLDACK^DGPFHLU4(DGACKTYP,DGHLROOT,.DGHL,.DGSEGERR,.DGSTOERR) D
. ;
. ;generate the message
. D GENACK^HLMA1(DGHL("EID"),DGMIEN,DGHL("EIDS"),"GM",1,.DGHLERR)
;
;cleanup
K @DGHLROOT
Q
;
SNDQRY(DGDFN,DGMODE,DGFAC) ;Send QRY Message Types (QRY~R02)
;This function transmits a PRF Query (QRY~R02) HL7 message to a given
;patient's treating facility.
;
; Input:
; DGDFN - (required) pointer to patient in PATIENT (#2) file
; DGMODE - (optional) type of HL7 connection to use ("1" - direct
; connection, "2" - deferred connection [default],
; "3" - direct connection/display mode)
; DGFAC - (optional) station number of query destination.
; [default - most recent unqueried treating facility]
;
; Output:
; Function value - 1 on success, 0 on failure
;
N DGEVNT
N DGHLROOT
N DGHLLNK
N DGHL
N DGICN
N DGLSQ
N DGMSG
N DGMSGID
N DGNXTF
N DGRSLT
N HLL
N DGHLEID
N DGHLRSLT
;
;the following HL* variables are created by DIRECT^HLMA
N HL,HLCS,HLDOM,HLECH,HLFS,HLINST,HLINSTN
N HLMTIEN,HLNEXT,HLNODE,HLPARAM,HLPROD,HLQ
N HLQUIT
;
S DGMODE=+$G(DGMODE)
S DGFAC=$G(DGFAC)
S DGRSLT=0
S DGHLROOT=$NA(^TMP("HLS",$J))
K @DGHLROOT
;
I +$G(DGDFN)>0,$D(^DPT(DGDFN,0)) D
. ;
. ;ICN must be national
. Q:'$$MPIOK^DGPFUT(DGDFN,.DGICN)
. ;
. ;find event, get last site queried and next treating facility
. S DGEVNT=$$FNDEVNT^DGPFHLL1(DGDFN)
. I 'DGEVNT,DGMODE'=3 D ;no event and not display? create it!
. . D STOEVNT^DGPFHLL1(DGDFN)
. . S DGEVNT=$$FNDEVNT^DGPFHLL1(DGDFN)
. S DGLSQ=$$GETLSQ^DGPFHLL(DGEVNT)
. S DGNXTF=$$GETNXTF^DGPFUT(DGDFN,DGLSQ)
. ;
. ;determine treating facility institution number to query
. S DGFAC=$S(DGFAC]"":$$IEN^XUAF4(DGFAC),DGNXTF:DGNXTF,DGLSQ&('DGNXTF):$$GETNXTF^DGPFUT(DGDFN),1:0)
. ;
. ;mark query event COMPLETE and return SUCCESS when no non-local
. ;treating facilities are found and no previous queries have been run.
. I DGFAC'>0,'DGLSQ D
. . D STOEVNT^DGPFHLL1(DGDFN,"C")
. . S DGRSLT=1
. Q:(DGFAC'>0)
. ;
. ;retrieve treating facility HL Logical Link and build HLL array
. S DGHLLNK=$$GETLINK^DGPFHLUT(DGFAC)
. Q:(DGHLLNK=0)
. S HLL("LINKS",1)="DGPF PRF ORF/R04 SUBSC"_U_DGHLLNK
. ;
. ;initialize VistA HL7 environment
. S DGHLEID=$$INIT^DGPFHLUT("DGPF PRF QRY/R02 EVENT",.DGHL)
. Q:'DGHLEID
. ;
. ;build QRY segments array
. Q:'$$BLDQRY^DGPFHLQ(DGDFN,DGICN,DGHLROOT,.DGHL)
. ;
. ;display busy message to interactive users when direct-connect
. I DGMODE=1!(DGMODE=3),$E($G(IOST),1,2)="C-" D
. . S DGMSG(1)="Attempting to connect to "_$P($$NS^XUAF4(DGFAC),U)
. . S DGMSG(2)="to search for Patient Record Flag Assignments."
. . S DGMSG(3)="This request may take sometime, please be patient ..."
. . D EN^DDIOL(.DGMSG)
. ;
. ;generate HL7 message
. I DGMODE=1!(DGMODE=3) D ;generate direct-connect HL7 message
. . D DIRECT^HLMA(DGHLEID,"GM",1,.DGHLRSLT,"","")
. . ;The DIRECT^HLMA API contains a bug that causes the message ID
. . ;returned to be based on the HL7 MESSAGE TEXT (#772) file IEN and
. . ;not the HL7 MESSAGE ADMINISTRATION (#773) file IEN. Therefore,
. . ;the following call to $$CONVMID is required to convert the
. . ;message ID to the value stored in file #773.
. . S DGMSGID=$$CONVMID^DGPFHLUT($P(DGHLRSLT,U))
. . I DGMODE=1,DGMSGID>0 D STOQXMIT^DGPFHLL(DGEVNT,DGMSGID,DGFAC)
. . I HLMTIEN,DGMODE'=3 D RCV^DGPFHLR
. . I DGMODE=3 D DISPLAY^DGPFHLUQ(HLMTIEN,DGHLRSLT)
. . ;success
. . I '+$P(DGHLRSLT,U,2) S DGRSLT=1
. ;
. E D ;generate deferred HL7 message
. . D GENERATE^HLMA(DGHLEID,"GM",1,.DGHLRSLT,"","")
. . I $P(DGHLRSLT,U)>0 D STOQXMIT^DGPFHLL(DGEVNT,$P(DGHLRSLT,U),DGFAC)
. . ;success
. . I '+$P(DGHLRSLT,U,2) S DGRSLT=1
;
;cleanup
K @DGHLROOT
Q DGRSLT
;
SNDORF(DGQRY,DGMIEN,DGHL,DGDFN,DGSEGERR,DGQRYERR) ;Send ORF Message Type (ORF~R04)
;This procedure assumes the the VistA HL7 environment is providing the
;environment variables and will produce a fatal error if they are
;missing.
;
; Input:
; DGQRY - (required) Array of QRY parsing results
; DGMIEN - (required) IEN of message entry in file #773
; DGHL - (required) HL7 environment array
; DGDFN - (required) Pointer to patient in PATIENT (#2) file
; DGSEGERR - (optional) Errors found during parsing
; DGQRYERR - (optional) Errors found during query
;
; Output:
; none
;
N DGHLROOT
N DGHLERR
;
Q:('$D(DGQRY))
Q:('+$G(DGMIEN))
;
S DGHLROOT=$NA(^TMP("HLA",$J))
K @DGHLROOT
;
;build ORF segments array
I $$BLDORF^DGPFHLQ(DGHLROOT,.DGHL,DGDFN,.DGQRY,.DGSEGERR,.DGQRYERR) D
. ;
. ;generate the message
. D GENACK^HLMA1(DGHL("EID"),DGMIEN,DGHL("EIDS"),"GM",1,.DGHLERR)
;
;cleanup
K @DGHLROOT
Q
DGPFHLS ;ALB/RPM - PRF HL7 SEND DRIVERS ; 7/31/06 10:10am
+1 ;;5.3;Registration;**425,650,1015**;Aug 13, 1993;Build 21
+2 ;
SNDORU(DGPFIEN,DGPFHARR,DGFAC) ;Send ORU Message Types (ORU~R01)
+1 ;This function builds and transmits a single ORU message to all sites
+2 ;in the associated patient's TREATING FACILITY LIST (#391.91) file.
+3 ;The optional input parameter DGFAC overrides selection of sites
+4 ;from the TREATING FACILITY LIST file.
+5 ;
+6 ; Supported DBIA #2990: This supported DBIA is used to access the
+7 ; Registration API to generate a list of
+8 ; treating facilities for a given patient.
+9 ; Input:
+10 ; DGPFIEN - (required) IEN of assignment in PRF ASSIGNMENT (#26.13)
+11 ; file to transmit
+12 ; DGPFHARR - (optional) array of assignment history IENs from the
+13 ; PRF ASSIGNMENT HISTORY (#26.14) file to
+14 ; include in ORU.
+15 ; format: DGPFHARR(assignment_date_time)=IEN
+16 ; assignment_date_time in FM format
+17 ; [default = $$GETLAST^DGPFAAH(DGPFIEN)]
+18 ; DGFAC - (optional) array of message destination facilities
+19 ; passed by reference
+20 ; format: DGFAC(#)=station#
+21 ;
+22 ; Output:
+23 ; Function value - 1 on success, 0 on failure
+24 ;
+25 ;event protocol ID
NEW DGHLEID
+26 ;VistA HL7 environment array
NEW DGHL
+27 ;message array location
NEW DGHLROOT
+28 ;assignment data array
NEW DGPFA
+29 ;assignment history data array
NEW DGPFAH
+30 ;assignment history IEN
NEW DGPFHIEN
+31 ;function value
NEW DGRSLT
+32 ;
+33 SET DGRSLT=0
+34 SET DGHLROOT=$NAME(^TMP("PRFORU",$JOB))
+35 KILL @DGHLROOT
+36 ;
+37 IF +$GET(DGPFIEN)>0
IF $DATA(^DGPF(26.13,DGPFIEN))
Begin DoDot:1
+38 ;
+39 ;retrieve assignment record
+40 IF '$$GETASGN^DGPFAA(DGPFIEN,.DGPFA)
QUIT
+41 ;
+42 ;set up default history IEN array
+43 IF '$ORDER(DGPFHARR(0))
Begin DoDot:2
+44 NEW DGPFAH
+45 SET DGPFHIEN=$$GETLAST^DGPFAAH(DGPFIEN)
+46 IF '$$GETHIST^DGPFAAH(DGPFHIEN,.DGPFAH)
QUIT
+47 SET DGPFHARR(+$GET(DGPFAH("ASSIGNDT")))=DGPFHIEN
End DoDot:2
+48 IF '$ORDER(DGPFHARR(0))
QUIT
+49 ;
+50 ;retrieve treating facilities when no destination is provided
+51 IF $GET(DGFAC(1))'>0
DO TFL^VAFCTFU1(.DGFAC,+$GET(DGPFA("DFN")))
+52 IF $GET(DGFAC(1))'>0
QUIT
+53 ;
+54 ;initialize VistA HL7 environment
+55 SET DGHLEID=$$INIT^DGPFHLUT("DGPF PRF ORU/R01 EVENT",.DGHL)
+56 IF 'DGHLEID
QUIT
+57 ;
+58 ;build ORU segments array
+59 SET DGPFHIEN=$$BLDORU^DGPFHLU(.DGPFA,.DGPFHARR,.DGHL,DGHLROOT)
+60 IF 'DGPFHIEN
QUIT
+61 ;
+62 ;transmit and log messages
+63 IF '$$XMIT^DGPFHLU6(DGPFHIEN,DGHLEID,.DGFAC,DGHLROOT,.DGHL)
QUIT
+64 ;
+65 ;success
+66 SET DGRSLT=1
End DoDot:1
+67 ;
+68 ;cleanup
+69 KILL @DGHLROOT
+70 QUIT DGRSLT
+71 ;
SNDACK(DGACKTYP,DGMIEN,DGHL,DGSEGERR,DGSTOERR) ;Send ACK Message Type (ACK~R01)
+1 ;This procedure assumes the the VistA HL7 environment is providing the
+2 ;environment variables and will produce a fatal error if they are
+3 ;missing.
+4 ;
+5 ; Input:
+6 ; DGACKTYP - (required) ACK message type ("AA","AE")
+7 ; DGMIEN - (required) IEN of message entry in file #773
+8 ; DGHL - (required) HL7 environment array
+9 ; DGSEGERR - (optional) Errors found during parsing
+10 ; DGSTOERR - (optional) Errors during data storage
+11 ;
+12 ; Output:
+13 ; none
+14 ;
+15 NEW DGHLROOT
+16 NEW DGHLERR
+17 ;
+18 IF ($GET(DGACKTYP)']"")
QUIT
+19 IF ('+$GET(DGMIEN))
QUIT
+20 ;
+21 SET DGHLROOT=$NAME(^TMP("HLA",$JOB))
+22 KILL @DGHLROOT
+23 ;
+24 ;build ACK segments array
+25 IF $$BLDACK^DGPFHLU4(DGACKTYP,DGHLROOT,.DGHL,.DGSEGERR,.DGSTOERR)
Begin DoDot:1
+26 ;
+27 ;generate the message
+28 DO GENACK^HLMA1(DGHL("EID"),DGMIEN,DGHL("EIDS"),"GM",1,.DGHLERR)
End DoDot:1
+29 ;
+30 ;cleanup
+31 KILL @DGHLROOT
+32 QUIT
+33 ;
SNDQRY(DGDFN,DGMODE,DGFAC) ;Send QRY Message Types (QRY~R02)
+1 ;This function transmits a PRF Query (QRY~R02) HL7 message to a given
+2 ;patient's treating facility.
+3 ;
+4 ; Input:
+5 ; DGDFN - (required) pointer to patient in PATIENT (#2) file
+6 ; DGMODE - (optional) type of HL7 connection to use ("1" - direct
+7 ; connection, "2" - deferred connection [default],
+8 ; "3" - direct connection/display mode)
+9 ; DGFAC - (optional) station number of query destination.
+10 ; [default - most recent unqueried treating facility]
+11 ;
+12 ; Output:
+13 ; Function value - 1 on success, 0 on failure
+14 ;
+15 NEW DGEVNT
+16 NEW DGHLROOT
+17 NEW DGHLLNK
+18 NEW DGHL
+19 NEW DGICN
+20 NEW DGLSQ
+21 NEW DGMSG
+22 NEW DGMSGID
+23 NEW DGNXTF
+24 NEW DGRSLT
+25 NEW HLL
+26 NEW DGHLEID
+27 NEW DGHLRSLT
+28 ;
+29 ;the following HL* variables are created by DIRECT^HLMA
+30 NEW HL,HLCS,HLDOM,HLECH,HLFS,HLINST,HLINSTN
+31 NEW HLMTIEN,HLNEXT,HLNODE,HLPARAM,HLPROD,HLQ
+32 NEW HLQUIT
+33 ;
+34 SET DGMODE=+$GET(DGMODE)
+35 SET DGFAC=$GET(DGFAC)
+36 SET DGRSLT=0
+37 SET DGHLROOT=$NAME(^TMP("HLS",$JOB))
+38 KILL @DGHLROOT
+39 ;
+40 IF +$GET(DGDFN)>0
IF $DATA(^DPT(DGDFN,0))
Begin DoDot:1
+41 ;
+42 ;ICN must be national
+43 IF '$$MPIOK^DGPFUT(DGDFN,.DGICN)
QUIT
+44 ;
+45 ;find event, get last site queried and next treating facility
+46 SET DGEVNT=$$FNDEVNT^DGPFHLL1(DGDFN)
+47 ;no event and not display? create it!
IF 'DGEVNT
IF DGMODE'=3
Begin DoDot:2
+48 DO STOEVNT^DGPFHLL1(DGDFN)
+49 SET DGEVNT=$$FNDEVNT^DGPFHLL1(DGDFN)
End DoDot:2
+50 SET DGLSQ=$$GETLSQ^DGPFHLL(DGEVNT)
+51 SET DGNXTF=$$GETNXTF^DGPFUT(DGDFN,DGLSQ)
+52 ;
+53 ;determine treating facility institution number to query
+54 SET DGFAC=$SELECT(DGFAC]"":$$IEN^XUAF4(DGFAC),DGNXTF:DGNXTF,DGLSQ&('DGNXTF):$$GETNXTF^DGPFUT(DGDFN),1:0)
+55 ;
+56 ;mark query event COMPLETE and return SUCCESS when no non-local
+57 ;treating facilities are found and no previous queries have been run.
+58 IF DGFAC'>0
IF 'DGLSQ
Begin DoDot:2
+59 DO STOEVNT^DGPFHLL1(DGDFN,"C")
+60 SET DGRSLT=1
End DoDot:2
+61 IF (DGFAC'>0)
QUIT
+62 ;
+63 ;retrieve treating facility HL Logical Link and build HLL array
+64 SET DGHLLNK=$$GETLINK^DGPFHLUT(DGFAC)
+65 IF (DGHLLNK=0)
QUIT
+66 SET HLL("LINKS",1)="DGPF PRF ORF/R04 SUBSC"_U_DGHLLNK
+67 ;
+68 ;initialize VistA HL7 environment
+69 SET DGHLEID=$$INIT^DGPFHLUT("DGPF PRF QRY/R02 EVENT",.DGHL)
+70 IF 'DGHLEID
QUIT
+71 ;
+72 ;build QRY segments array
+73 IF '$$BLDQRY^DGPFHLQ(DGDFN,DGICN,DGHLROOT,.DGHL)
QUIT
+74 ;
+75 ;display busy message to interactive users when direct-connect
+76 IF DGMODE=1!(DGMODE=3)
IF $EXTRACT($GET(IOST),1,2)="C-"
Begin DoDot:2
+77 SET DGMSG(1)="Attempting to connect to "_$PIECE($$NS^XUAF4(DGFAC),U)
+78 SET DGMSG(2)="to search for Patient Record Flag Assignments."
+79 SET DGMSG(3)="This request may take sometime, please be patient ..."
+80 DO EN^DDIOL(.DGMSG)
End DoDot:2
+81 ;
+82 ;generate HL7 message
+83 ;generate direct-connect HL7 message
IF DGMODE=1!(DGMODE=3)
Begin DoDot:2
+84 DO DIRECT^HLMA(DGHLEID,"GM",1,.DGHLRSLT,"","")
+85 ;The DIRECT^HLMA API contains a bug that causes the message ID
+86 ;returned to be based on the HL7 MESSAGE TEXT (#772) file IEN and
+87 ;not the HL7 MESSAGE ADMINISTRATION (#773) file IEN. Therefore,
+88 ;the following call to $$CONVMID is required to convert the
+89 ;message ID to the value stored in file #773.
+90 SET DGMSGID=$$CONVMID^DGPFHLUT($PIECE(DGHLRSLT,U))
+91 IF DGMODE=1
IF DGMSGID>0
DO STOQXMIT^DGPFHLL(DGEVNT,DGMSGID,DGFAC)
+92 IF HLMTIEN
IF DGMODE'=3
DO RCV^DGPFHLR
+93 IF DGMODE=3
DO DISPLAY^DGPFHLUQ(HLMTIEN,DGHLRSLT)
+94 ;success
+95 IF '+$PIECE(DGHLRSLT,U,2)
SET DGRSLT=1
End DoDot:2
+96 ;
+97 ;generate deferred HL7 message
IF '$TEST
Begin DoDot:2
+98 DO GENERATE^HLMA(DGHLEID,"GM",1,.DGHLRSLT,"","")
+99 IF $PIECE(DGHLRSLT,U)>0
DO STOQXMIT^DGPFHLL(DGEVNT,$PIECE(DGHLRSLT,U),DGFAC)
+100 ;success
+101 IF '+$PIECE(DGHLRSLT,U,2)
SET DGRSLT=1
End DoDot:2
End DoDot:1
+102 ;
+103 ;cleanup
+104 KILL @DGHLROOT
+105 QUIT DGRSLT
+106 ;
SNDORF(DGQRY,DGMIEN,DGHL,DGDFN,DGSEGERR,DGQRYERR) ;Send ORF Message Type (ORF~R04)
+1 ;This procedure assumes the the VistA HL7 environment is providing the
+2 ;environment variables and will produce a fatal error if they are
+3 ;missing.
+4 ;
+5 ; Input:
+6 ; DGQRY - (required) Array of QRY parsing results
+7 ; DGMIEN - (required) IEN of message entry in file #773
+8 ; DGHL - (required) HL7 environment array
+9 ; DGDFN - (required) Pointer to patient in PATIENT (#2) file
+10 ; DGSEGERR - (optional) Errors found during parsing
+11 ; DGQRYERR - (optional) Errors found during query
+12 ;
+13 ; Output:
+14 ; none
+15 ;
+16 NEW DGHLROOT
+17 NEW DGHLERR
+18 ;
+19 IF ('$DATA(DGQRY))
QUIT
+20 IF ('+$GET(DGMIEN))
QUIT
+21 ;
+22 SET DGHLROOT=$NAME(^TMP("HLA",$JOB))
+23 KILL @DGHLROOT
+24 ;
+25 ;build ORF segments array
+26 IF $$BLDORF^DGPFHLQ(DGHLROOT,.DGHL,DGDFN,.DGQRY,.DGSEGERR,.DGQRYERR)
Begin DoDot:1
+27 ;
+28 ;generate the message
+29 DO GENACK^HLMA1(DGHL("EID"),DGMIEN,DGHL("EIDS"),"GM",1,.DGHLERR)
End DoDot:1
+30 ;
+31 ;cleanup
+32 KILL @DGHLROOT
+33 QUIT