VAFCTF ;BIR/DLR-Utility for capturing patient's Date Last Treated and Event Reason ;9/9/2002
;;5.3;PIMS;**428,713,1015,1016**;JUN 30, 2012;Build 20
Q ; quit if called from the top
;
;Reference to ^SCE("ADFN" supported by IA# 2953
;Reference to EXC^RGHLLOG supported by IA# 2796
;Reference to $$ICNLC^MPIF001 supported by IA #3072
;
EN1(VAFCDFN,VAFCSUP) ; determine the LAST TREATMENT DATE for a single
; patient
; input: VAFCDFN - the dfn of the patient
; VAFCSUP - if 1, suppress add entries to the ADT HL7 PIVOT
; (#391.71) file for TF messaging - VAFCTFMF (optional)
; output: VAFCDATE - patient's DATE LAST TREATED
; VAFCENVR - event reason
;
N ERR,VAFCSITE,VAFCLAST,VAFCSITE,VAFCADMD,VAFCENDT,VAFCDATE,VAFCENVR,VAFCTYPE
S U="^"
S:'$D(VAFCSITE) VAFCSITE=$$KSP^XUPARAM("INST") ;defines the local facility
S (VAFCLAST,VAFCADMD)=$$ADMDIS(VAFCDFN) ; dt_"^"_event type or ""
S VAFCADMD=$S(VAFCADMD]"":$P(VAFCADMD,"^"),1:"") ; event dt or null
S:$P(VAFCLAST,"^",2)=3!(VAFCLAST="") VAFCENDT=$$ENCDT(VAFCDFN,VAFCADMD)
; patient has been discharged or has never been admitted. Has this
; individual been checked out of a clinic?
I $D(VAFCENDT)#2,($P(VAFCLAST,U)) S VAFCLAST=$S(+VAFCENDT>+VAFCLAST:VAFCENDT,1:VAFCLAST)
I $D(VAFCENDT)#2,('$P(VAFCLAST,U)) S VAFCLAST=VAFCENDT
S VAFCTYPE=$P(VAFCLAST,"^",2),VAFCDATE=+VAFCLAST
; input variables to FILE^VAFCTFU
; VAFCDFN - patient ien ; VAFCSITE - treating facility
; VAFCDATE - date last treated ; VAFCENVR - event reason
;
I +VAFCDATE'>0 S VAFCDATE="",VAFCENVR=""
I +VAFCDATE>0 S VAFCENVR=$S(VAFCTYPE=1:"A1",VAFCTYPE=3:"A2",1:"A3") ;A1=adm;A2=dis;A3=CO
N STA,ICN S ICN=$$ICNLC^MPIF001(VAFCDFN),STA=$P($$SITE^VASITE,"^",3)
D FILE^VAFCTFU(VAFCDFN,VAFCSITE_U_VAFCDATE_U_VAFCENVR,$G(VAFCSUP),1,.ERR) I $D(ERR(STA)) D EXC^RGHLLOG(212,ERR(STA),VAFCDFN)
;
Q
ADMDIS(DFN) ; find the patient's last admission and discharge dates if
; they exist.
; Input: DFN - ien of the patient (file 2)
;Output: a valid discharge/admission date/time concatenated with
; the event type (1=admission, 3=discharge) -or- null
N %,VAERR,VAIP S VAIP("D")="LAST" D IN5^VADPT
I '+$G(VAIP(17,1)),('+$G(VAIP(13,1))) Q ""
; no discharge date, no admission date, return null
I '+$G(VAIP(17,1)) Q $P($G(VAIP(13,1)),U)_"^1"
; no discharge date, return admission date
I '+$G(VAIP(13,1)) Q $P($G(VAIP(17,1)),U)_"^3"
; no admission date, return discharge date
I +$G(VAIP(17,1))>(+$G(VAIP(13,1))) Q +$G(VAIP(17,1))_"^3"
; return discharge date
Q +$G(VAIP(13,1))_"^1" ; return admission date
;
ENCDT(DFN,INPDT) ; find the last patient check out date/time. 'ADFN'
; cross-reference accessed through DBIA: 2953
; Input: DFN - ien of the patient (file 2)
; INPDT - date (if any) returned from the inpatient admission/
; discharge subroutine
;Output: a valid discharge/admission date/time concatenated with
; the event type (5=check out) -or- null
Q:'DFN "" ; we need dfn defined
N VAFCDATA,VAFCPURG,VAFCX,VAFCX1,VAFCX2,VAFCX3
S VAFCX=9999999.9999999,VAFCX2=0,VAFCX3=""
F S VAFCX=$O(^SCE("ADFN",DFN,VAFCX),-1) Q:'VAFCX!(INPDT>VAFCX) D Q:VAFCX2
. S VAFCX1=0 F S VAFCX1=$O(^SCE("ADFN",DFN,VAFCX,VAFCX1)) Q:'VAFCX1 D Q:VAFCX2
.. D GETGEN^SDOE(VAFCX1,"VAFCDATA")
.. D PARSE^SDOE(.VAFCDATA,"EXTERNAL","VAFCPARS")
.. I $G(VAFCPARS(.12))="CHECKED OUT" S VAFCX2=1,VAFCX3=VAFCX
.. K VAFCDATA,VAFCPARS
.. Q
. Q
K VAFCDATA,VAFCPURG,VAFCX,VAFCX1,VAFCX2
;DG*5.3*766
I $E(VAFCX3,9,10)>23 S VAFCX3=$E(VAFCX3,1,8)_"23"_$E(VAFCX3,11,14)
I $E(VAFCX3,11)>5 S VAFCX3=$E(VAFCX3,1,10)_"59"_$E(VAFCX3,13,14)
;DG*5.3*713
I $E(VAFCX3,13)>5 S VAFCX3=$E(VAFCX3,1,12)_"59"
Q VAFCX3_"^5" ; X is either null or the date/time of the check out
;
VAFCTF ;BIR/DLR-Utility for capturing patient's Date Last Treated and Event Reason ;9/9/2002
+1 ;;5.3;PIMS;**428,713,1015,1016**;JUN 30, 2012;Build 20
+2 ; quit if called from the top
QUIT
+3 ;
+4 ;Reference to ^SCE("ADFN" supported by IA# 2953
+5 ;Reference to EXC^RGHLLOG supported by IA# 2796
+6 ;Reference to $$ICNLC^MPIF001 supported by IA #3072
+7 ;
EN1(VAFCDFN,VAFCSUP) ; determine the LAST TREATMENT DATE for a single
+1 ; patient
+2 ; input: VAFCDFN - the dfn of the patient
+3 ; VAFCSUP - if 1, suppress add entries to the ADT HL7 PIVOT
+4 ; (#391.71) file for TF messaging - VAFCTFMF (optional)
+5 ; output: VAFCDATE - patient's DATE LAST TREATED
+6 ; VAFCENVR - event reason
+7 ;
+8 NEW ERR,VAFCSITE,VAFCLAST,VAFCSITE,VAFCADMD,VAFCENDT,VAFCDATE,VAFCENVR,VAFCTYPE
+9 SET U="^"
+10 ;defines the local facility
IF '$DATA(VAFCSITE)
SET VAFCSITE=$$KSP^XUPARAM("INST")
+11 ; dt_"^"_event type or ""
SET (VAFCLAST,VAFCADMD)=$$ADMDIS(VAFCDFN)
+12 ; event dt or null
SET VAFCADMD=$SELECT(VAFCADMD]"":$PIECE(VAFCADMD,"^"),1:"")
+13 IF $PIECE(VAFCLAST,"^",2)=3!(VAFCLAST="")
SET VAFCENDT=$$ENCDT(VAFCDFN,VAFCADMD)
+14 ; patient has been discharged or has never been admitted. Has this
+15 ; individual been checked out of a clinic?
+16 IF $DATA(VAFCENDT)#2
IF ($PIECE(VAFCLAST,U))
SET VAFCLAST=$SELECT(+VAFCENDT>+VAFCLAST:VAFCENDT,1:VAFCLAST)
+17 IF $DATA(VAFCENDT)#2
IF ('$PIECE(VAFCLAST,U))
SET VAFCLAST=VAFCENDT
+18 SET VAFCTYPE=$PIECE(VAFCLAST,"^",2)
SET VAFCDATE=+VAFCLAST
+19 ; input variables to FILE^VAFCTFU
+20 ; VAFCDFN - patient ien ; VAFCSITE - treating facility
+21 ; VAFCDATE - date last treated ; VAFCENVR - event reason
+22 ;
+23 IF +VAFCDATE'>0
SET VAFCDATE=""
SET VAFCENVR=""
+24 ;A1=adm;A2=dis;A3=CO
IF +VAFCDATE>0
SET VAFCENVR=$SELECT(VAFCTYPE=1:"A1",VAFCTYPE=3:"A2",1:"A3")
+25 NEW STA,ICN
SET ICN=$$ICNLC^MPIF001(VAFCDFN)
SET STA=$PIECE($$SITE^VASITE,"^",3)
+26 DO FILE^VAFCTFU(VAFCDFN,VAFCSITE_U_VAFCDATE_U_VAFCENVR,$GET(VAFCSUP),1,.ERR)
IF $DATA(ERR(STA))
DO EXC^RGHLLOG(212,ERR(STA),VAFCDFN)
+27 ;
+28 QUIT
ADMDIS(DFN) ; find the patient's last admission and discharge dates if
+1 ; they exist.
+2 ; Input: DFN - ien of the patient (file 2)
+3 ;Output: a valid discharge/admission date/time concatenated with
+4 ; the event type (1=admission, 3=discharge) -or- null
+5 NEW %,VAERR,VAIP
SET VAIP("D")="LAST"
DO IN5^VADPT
+6 IF '+$GET(VAIP(17,1))
IF ('+$GET(VAIP(13,1)))
QUIT ""
+7 ; no discharge date, no admission date, return null
+8 IF '+$GET(VAIP(17,1))
QUIT $PIECE($GET(VAIP(13,1)),U)_"^1"
+9 ; no discharge date, return admission date
+10 IF '+$GET(VAIP(13,1))
QUIT $PIECE($GET(VAIP(17,1)),U)_"^3"
+11 ; no admission date, return discharge date
+12 IF +$GET(VAIP(17,1))>(+$GET(VAIP(13,1)))
QUIT +$GET(VAIP(17,1))_"^3"
+13 ; return discharge date
+14 ; return admission date
QUIT +$GET(VAIP(13,1))_"^1"
+15 ;
ENCDT(DFN,INPDT) ; find the last patient check out date/time. 'ADFN'
+1 ; cross-reference accessed through DBIA: 2953
+2 ; Input: DFN - ien of the patient (file 2)
+3 ; INPDT - date (if any) returned from the inpatient admission/
+4 ; discharge subroutine
+5 ;Output: a valid discharge/admission date/time concatenated with
+6 ; the event type (5=check out) -or- null
+7 ; we need dfn defined
IF 'DFN
QUIT ""
+8 NEW VAFCDATA,VAFCPURG,VAFCX,VAFCX1,VAFCX2,VAFCX3
+9 SET VAFCX=9999999.9999999
SET VAFCX2=0
SET VAFCX3=""
+10 FOR
SET VAFCX=$ORDER(^SCE("ADFN",DFN,VAFCX),-1)
IF 'VAFCX!(INPDT>VAFCX)
QUIT
Begin DoDot:1
+11 SET VAFCX1=0
FOR
SET VAFCX1=$ORDER(^SCE("ADFN",DFN,VAFCX,VAFCX1))
IF 'VAFCX1
QUIT
Begin DoDot:2
+12 DO GETGEN^SDOE(VAFCX1,"VAFCDATA")
+13 DO PARSE^SDOE(.VAFCDATA,"EXTERNAL","VAFCPARS")
+14 IF $GET(VAFCPARS(.12))="CHECKED OUT"
SET VAFCX2=1
SET VAFCX3=VAFCX
+15 KILL VAFCDATA,VAFCPARS
+16 QUIT
End DoDot:2
IF VAFCX2
QUIT
+17 QUIT
End DoDot:1
IF VAFCX2
QUIT
+18 KILL VAFCDATA,VAFCPURG,VAFCX,VAFCX1,VAFCX2
+19 ;DG*5.3*766
+20 IF $EXTRACT(VAFCX3,9,10)>23
SET VAFCX3=$EXTRACT(VAFCX3,1,8)_"23"_$EXTRACT(VAFCX3,11,14)
+21 IF $EXTRACT(VAFCX3,11)>5
SET VAFCX3=$EXTRACT(VAFCX3,1,10)_"59"_$EXTRACT(VAFCX3,13,14)
+22 ;DG*5.3*713
+23 IF $EXTRACT(VAFCX3,13)>5
SET VAFCX3=$EXTRACT(VAFCX3,1,12)_"59"
+24 ; X is either null or the date/time of the check out
QUIT VAFCX3_"^5"
+25 ;