RGADT ;HIRMFO/GJC-ADT MESSAGE PROCESSING/ROUTING ;09/21/99
;;1.0;CLINICAL INFO RESOURCE NETWORK;**4,8,14,17**;30 Apr 99
Q ; quit if called from the top
;
EN ;entry point to process local ADT messages.
;
;This is call by the following clients:
; RG ADT-A01 CLIENT & RG ADT-A03 CLIENT (Generate/Process
; Routine(771) & Routing Logic(774) field definitions
;
; Integration Agreements (IAs) utilized in this application:
; #2051-$$FIND1^DIC
; #2165-GENACK^HLMA1
; #2171-$$LKUP^XUAF4
; #2541-$$KSP^XUPARAM
; #2701-$$GETDFN^MPIF001
; #2702-$$MPINODE^MPIFAPI
; #2988-IAs for VAFCTFU utilities
; #3037-ADT/HL7 EVENT REASON (#391.72) file access
; #10106-$$FMDATE^HLFNC
;
Q:$G(HL("MTN"))="ACK" ; quit if a ACK message type is passed here
K RGDC,RGDCDFN,RGDCERR,RGDCEVN,RGDCEVT1,RGDCPID,RGDCSFN,RGDCV,RGFLG
S RGFLG=0,U="^" D INITIZE^RGRSUTIL ; copy HL7 message into local RGDC
; array
S RGDCV=$$EN^RGRSMSH() ;return: dt rec'd^event dt^sending fac.(xternal)
; note: the above dates are in FileMan internal format
S RGDCFROM=$$LKUP^XUAF4(+$P(RGDCV,U,3)) ; facility that sent the
; message. Could differ from the facility where the event occurred
; if inbound data is sent from a site running RG*1.0*17
S RGDCPID=$$SEG1^RGRSUTIL("PID",1,"PID")
S RGDCPV1=$$SEG1^RGRSUTIL("PV1",1,"PV1")
S RGFLG=$S($P($P(RGDCPV1,HL("FS"),3),$E(HL("ECH")),4)["&":1,1:0)
; if RGFLG, the inbound message is from a patch 17 site and this
; site has patch 17 installed, so the message can be processed using
; TF data off the PV1 segment
S RGDCEVN=$P($$SEG1^RGRSUTIL("EVN",1,"EVN"),HL("FS"),5)
; RGDCEVN is the event reason code
S RGDCEVN=$$FIND1^DIC(391.72,"","AXM",RGDCEVN) ; event reason(internal)
S RGDCEVT1=$P($$SEG1^RGRSUTIL("EVN",1,"EVN"),HL("FS"),2) ; event type
S RGDCDFN=$$GETDFN^MPIF001(+$P(RGDCPID,HL("FS"),3))
; Note: $P(RGDCPID,HL("FS"),3) is: ICN_"V"_ICN checksum
I RGFLG S RGDCSFN=$$SFN(RGDCPV1),RGDCSFN=$$LKUP^XUAF4(RGDCSFN)
S:'RGFLG RGDCSFN=RGDCFROM ; TF from MSH segment
; RGDCSFN - obtain treating facility ien (file 4) from station #
;
; input variables to FILE^VAFCTFU
; RGDCDFN - patient ien ; RGDCSFN - treating facility
; $P(RGDCV,U,2) - date last treated ; RGDCEVN - event reason
D FILE^VAFCTFU(RGDCDFN,RGDCSFN_U_$P(RGDCV,U,2)_U_RGDCEVN,$$SFCMOR(RGDCDFN,RGDCFROM))
; call to the TFL utility routine VAFCTFU. Centrally located code
; to add or edit to the TFL file. If $$SFCMOR(RGDCDFN,RGDCFROM)
; returns 1, let the Pivot file handle updates (MFUs) to subscribers.
; If 0, file data and do not re-broadcast.
;
D GENACK ; generate the 'ack' message
;
KILL ; kill and exit
K HLINKP,HLINKX,HLL,RGDC,RGDCDFN,RGDCERR,RGDCEVN,RGDCEVT1,RGDCFROM,RGDCPID,RGDCPV1,RGDCSFN,RGDCV,RGFLG
Q
;
DYNROU(RGDCEVT) ; dynamic message routing, but first need to update the
; TREATING FACILITY LIST (TFL-391.91) file at the local site
; input-{RGDCEVT=event type
K RGDCEDT,RGDCEVTR,RGDCSITE
S RGDCSITE=$$KSP^XUPARAM("INST"),U="^"
S RGDCEDT=$$FMDATE^HLFNC($P($$EVN(),U,3)) ; determine event date/time
S RGDCEVTR=$$FIND1^DIC(391.72,"","AXM",$P($$EVN(),U,5)) ; event reason
;
; input variables to FILE^VAFCTFU
; DFN - patient ien ; RGDCSITE - treating facility
; RGDCEDT - date last treated ; RGDCEVTR - event reason
D FILE^VAFCTFU(DFN,RGDCSITE_U_RGDCEDT_U_RGDCEVTR,1)
; call to the TFL utility routine VAFCTFU. Centrally located code
; to add or edit to the TFL file.
;
; route the message
D EN^RGRSDYN("RG ADT-"_RGDCEVT_" CLIENT",0)
K RGDCEDT,RGDCEVTR,RGDCSITE
Q
EVN() ; pass back the EVN segment.
N I,X S I=0
F S I=$O(HLA("HLS",I)) Q:I'>0 D Q:$D(X)
. S:$P(HLA("HLS",I),U)="EVN" X=$G(HLA("HLS",I))
. Q
Q $G(X)
GENACK ; Compile the 'ACK' segment, generate the 'ACK' message.
S HLA("HLA",1)="MSA"_HL("FS")_$S($G(RGDCERR)]"":"AE",1:"AA")_HL("FS")_HL("MID")_$S($G(RGDCERR)]"":HL("FS")_$G(RGDCERR),1:"")
S HLEID=HL("EID"),HLEIDS=HL("EIDS"),HLARYTYP="LM",HLFORMAT=1
D GENACK^HLMA1(HLEID,HLMTIENS,HLEIDS,HLARYTYP,HLFORMAT,.HLRESTLA)
Q
;
SFCMOR(DFN,SFAC) ; sent from CMOR? Determine if the patient's CMOR sent
; this VistA HL7 message
; input: DFN (patient dfn); SFAC (sending facility, ptr file 4)
; yield: 1 if sent from CMOR of patient, else 0
Q $S(SFAC=$P($$MPINODE^MPIFAPI(DFN),"^",3):1,1:0)
;
SFN(X) ; return the station number of the sending facility; PV1(3)
; input: PV1 segment
; yield: station number of sending facility
N Y S Y=$P(X,HL("FS"),4) ; pnt_of_care~room~bed~&fac. station #
S Y=$P(Y,$E(HL("ECH")),4) ; &fac. station #
Q $P(Y,$E(HL("ECH"),4),2) ; fac. station #
--- Routine Detail --- with STRUCTURED ROUTINE LISTING ---[H[J[2J[HRGADT 4649 printed Oct 16, 2024@17:42:11 Page 2
RGADT ;HIRMFO/GJC-ADT MESSAGE PROCESSING/ROUTING ;09/21/99
+1 ;;1.0;CLINICAL INFO RESOURCE NETWORK;**4,8,14,17**;30 Apr 99
+2 ; quit if called from the top
QUIT
+3 ;
EN ;entry point to process local ADT messages.
+1 ;
+2 ;This is call by the following clients:
+3 ; RG ADT-A01 CLIENT & RG ADT-A03 CLIENT (Generate/Process
+4 ; Routine(771) & Routing Logic(774) field definitions
+5 ;
+6 ; Integration Agreements (IAs) utilized in this application:
+7 ; #2051-$$FIND1^DIC
+8 ; #2165-GENACK^HLMA1
+9 ; #2171-$$LKUP^XUAF4
+10 ; #2541-$$KSP^XUPARAM
+11 ; #2701-$$GETDFN^MPIF001
+12 ; #2702-$$MPINODE^MPIFAPI
+13 ; #2988-IAs for VAFCTFU utilities
+14 ; #3037-ADT/HL7 EVENT REASON (#391.72) file access
+15 ; #10106-$$FMDATE^HLFNC
+16 ;
+17 ; quit if a ACK message type is passed here
if $GET(HL("MTN"))="ACK"
QUIT
+18 KILL RGDC,RGDCDFN,RGDCERR,RGDCEVN,RGDCEVT1,RGDCPID,RGDCSFN,RGDCV,RGFLG
+19 ; copy HL7 message into local RGDC
SET RGFLG=0
SET U="^"
DO INITIZE^RGRSUTIL
+20 ; array
+21 ;return: dt rec'd^event dt^sending fac.(xternal)
SET RGDCV=$$EN^RGRSMSH()
+22 ; note: the above dates are in FileMan internal format
+23 ; facility that sent the
SET RGDCFROM=$$LKUP^XUAF4(+$PIECE(RGDCV,U,3))
+24 ; message. Could differ from the facility where the event occurred
+25 ; if inbound data is sent from a site running RG*1.0*17
+26 SET RGDCPID=$$SEG1^RGRSUTIL("PID",1,"PID")
+27 SET RGDCPV1=$$SEG1^RGRSUTIL("PV1",1,"PV1")
+28 SET RGFLG=$SELECT($PIECE($PIECE(RGDCPV1,HL("FS"),3),$EXTRACT(HL("ECH")),4)["&":1,1:0)
+29 ; if RGFLG, the inbound message is from a patch 17 site and this
+30 ; site has patch 17 installed, so the message can be processed using
+31 ; TF data off the PV1 segment
+32 SET RGDCEVN=$PIECE($$SEG1^RGRSUTIL("EVN",1,"EVN"),HL("FS"),5)
+33 ; RGDCEVN is the event reason code
+34 ; event reason(internal)
SET RGDCEVN=$$FIND1^DIC(391.72,"","AXM",RGDCEVN)
+35 ; event type
SET RGDCEVT1=$PIECE($$SEG1^RGRSUTIL("EVN",1,"EVN"),HL("FS"),2)
+36 SET RGDCDFN=$$GETDFN^MPIF001(+$PIECE(RGDCPID,HL("FS"),3))
+37 ; Note: $P(RGDCPID,HL("FS"),3) is: ICN_"V"_ICN checksum
+38 IF RGFLG
SET RGDCSFN=$$SFN(RGDCPV1)
SET RGDCSFN=$$LKUP^XUAF4(RGDCSFN)
+39 ; TF from MSH segment
if 'RGFLG
SET RGDCSFN=RGDCFROM
+40 ; RGDCSFN - obtain treating facility ien (file 4) from station #
+41 ;
+42 ; input variables to FILE^VAFCTFU
+43 ; RGDCDFN - patient ien ; RGDCSFN - treating facility
+44 ; $P(RGDCV,U,2) - date last treated ; RGDCEVN - event reason
+45 DO FILE^VAFCTFU(RGDCDFN,RGDCSFN_U_$PIECE(RGDCV,U,2)_U_RGDCEVN,$$SFCMOR(RGDCDFN,RGDCFROM))
+46 ; call to the TFL utility routine VAFCTFU. Centrally located code
+47 ; to add or edit to the TFL file. If $$SFCMOR(RGDCDFN,RGDCFROM)
+48 ; returns 1, let the Pivot file handle updates (MFUs) to subscribers.
+49 ; If 0, file data and do not re-broadcast.
+50 ;
+51 ; generate the 'ack' message
DO GENACK
+52 ;
KILL ; kill and exit
+1 KILL HLINKP,HLINKX,HLL,RGDC,RGDCDFN,RGDCERR,RGDCEVN,RGDCEVT1,RGDCFROM,RGDCPID,RGDCPV1,RGDCSFN,RGDCV,RGFLG
+2 QUIT
+3 ;
DYNROU(RGDCEVT) ; dynamic message routing, but first need to update the
+1 ; TREATING FACILITY LIST (TFL-391.91) file at the local site
+2 ; input-{RGDCEVT=event type
+3 KILL RGDCEDT,RGDCEVTR,RGDCSITE
+4 SET RGDCSITE=$$KSP^XUPARAM("INST")
SET U="^"
+5 ; determine event date/time
SET RGDCEDT=$$FMDATE^HLFNC($PIECE($$EVN(),U,3))
+6 ; event reason
SET RGDCEVTR=$$FIND1^DIC(391.72,"","AXM",$PIECE($$EVN(),U,5))
+7 ;
+8 ; input variables to FILE^VAFCTFU
+9 ; DFN - patient ien ; RGDCSITE - treating facility
+10 ; RGDCEDT - date last treated ; RGDCEVTR - event reason
+11 DO FILE^VAFCTFU(DFN,RGDCSITE_U_RGDCEDT_U_RGDCEVTR,1)
+12 ; call to the TFL utility routine VAFCTFU. Centrally located code
+13 ; to add or edit to the TFL file.
+14 ;
+15 ; route the message
+16 DO EN^RGRSDYN("RG ADT-"_RGDCEVT_" CLIENT",0)
+17 KILL RGDCEDT,RGDCEVTR,RGDCSITE
+18 QUIT
EVN() ; pass back the EVN segment.
+1 NEW I,X
SET I=0
+2 FOR
SET I=$ORDER(HLA("HLS",I))
if I'>0
QUIT
Begin DoDot:1
+3 if $PIECE(HLA("HLS",I),U)="EVN"
SET X=$GET(HLA("HLS",I))
+4 QUIT
End DoDot:1
if $DATA(X)
QUIT
+5 QUIT $GET(X)
GENACK ; Compile the 'ACK' segment, generate the 'ACK' message.
+1 SET HLA("HLA",1)="MSA"_HL("FS")_$SELECT($GET(RGDCERR)]"":"AE",1:"AA")_HL("FS")_HL("MID")_$SELECT($GET(RGDCERR)]"":HL("FS")_$GET(RGDCERR),1:"")
+2 SET HLEID=HL("EID")
SET HLEIDS=HL("EIDS")
SET HLARYTYP="LM"
SET HLFORMAT=1
+3 DO GENACK^HLMA1(HLEID,HLMTIENS,HLEIDS,HLARYTYP,HLFORMAT,.HLRESTLA)
+4 QUIT
+5 ;
SFCMOR(DFN,SFAC) ; sent from CMOR? Determine if the patient's CMOR sent
+1 ; this VistA HL7 message
+2 ; input: DFN (patient dfn); SFAC (sending facility, ptr file 4)
+3 ; yield: 1 if sent from CMOR of patient, else 0
+4 QUIT $SELECT(SFAC=$PIECE($$MPINODE^MPIFAPI(DFN),"^",3):1,1:0)
+5 ;
SFN(X) ; return the station number of the sending facility; PV1(3)
+1 ; input: PV1 segment
+2 ; yield: station number of sending facility
+3 ; pnt_of_care~room~bed~&fac. station #
NEW Y
SET Y=$PIECE(X,HL("FS"),4)
+4 ; &fac. station #
SET Y=$PIECE(Y,$EXTRACT(HL("ECH")),4)
+5 ; fac. station #
QUIT $PIECE(Y,$EXTRACT(HL("ECH"),4),2)