EDPRPT2 ;SLC/MKB - Delay Report ;6/13/12 12:33pm
;;2.0;EMERGENCY DEPARTMENT;**6,2**;Feb 24, 2012;Build 23
;
DEL(BEG,END,CSV) ; Get Delay Report for EDPSITE by date range
; CNT = counters
; MIN = accumulate #minutes
N IN,OUT,LOG,X,X0,X1,X3,DX,ELAPSE,ADMDEC,ADMDEL,DISP,VADISP,CNT,MIN,DEL,ACU,ED,NOT
D INIT ;set counters, sums to 0
D:'$G(CSV) XML^EDPX("<logEntries>") I $G(CSV) D ;headers
. N TAB S TAB=$C(9)
. ;drp 9/27/2012 begin EDP*2.0*2 changes
. S X="ED IEN"_TAB_"Patient Name"_TAB_"Time In"_TAB_"Elapsed"_TAB_"Dispo"_TAB_"Delay Reason"_TAB_"MD"_TAB_"Adm Dec"_TAB_"Adm Delay"_TAB_"Acuity"_TAB_"Diagnosis"_TAB_"ICD"_TAB_"ICD Type"
. ;End EDP*2.0*2 Changes
. D ADD^EDPCSV(X)
S IN=BEG-.000001
F S IN=$O(^EDP(230,"ATI",EDPSITE,IN)) Q:'IN Q:IN>END S LOG=0 F S LOG=+$O(^EDP(230,"ATI",EDPSITE,IN,LOG)) Q:LOG<1 D
. S X0=^EDP(230,LOG,0),X1=$G(^(1)),X3=$G(^(3))
. S ACU=$$ECODE^EDPRPT($P(X3,U,3)),DEL=+$P(X1,U,5),CNT=CNT+1
. S DISP=$$ECODE^EDPRPT($P(X1,U,2)),VADISP=$$VADMIT(DISP)
. ;TDP - Patch 2 mod to catch all dispositions listed as VA admit
. I VADISP=0 S VADISP=$$VADMIT1($P(X1,U,2))
. I DISP="" S DISP=$$DISP^EDPRPT($P(X1,U,2))
. S OUT=$P(X0,U,9) ;S:OUT="" OUT=NOW
. S ELAPSE=$S(OUT:($$FMDIFF^XLFDT(OUT,IN,2)\60),1:0),MIN=MIN+ELAPSE
D1 . ; all admissions
. S (ADMDEC,ADMDEL)=0
. S X=$$ADMIT^EDPRPT(LOG) I X D
.. S ADMDEC=$$FMDIFF^XLFDT(X,IN,2)\60
.. S:ADMDEC CNT("DEC")=CNT("DEC")+1,MIN("DEC")=MIN("DEC")+ADMDEC
.. S ADMDEL=$S(OUT:($$FMDIFF^XLFDT(OUT,X,2)\60),1:0)
D2 . ; VA admissions only
. I VADISP D
.. S CNT("VA")=CNT("VA")+1
.. S MIN("VA")=MIN("VA")+ELAPSE
.. S MIN("VADEC")=MIN("VADEC")+ADMDEC
.. S MIN("VADEL")=MIN("VADEL")+ADMDEL
.. S:ADMDEL>359 CNT("VADEL6")=CNT("VADEL6")+1
D3 . ; elapsed visit time >=6 hrs
. S:ELAPSE>1380 CNT("23+")=CNT("23+")+1
. I ELAPSE>359 D
.. S CNT("6+")=CNT("6+")+1
.. S:VADISP CNT("VA6")=CNT("VA6")+1
.. S DX=$$DXPRI^EDPQPCE(+$P(X0,U,3),LOG)
.. N ROW S ROW("id")=LOG
.. S ROW("patientName")=$S($P(X0,U,6)'="":$$GET1^DIQ(2,$P(X0,U,6),.01,"E"),1:$P(X0,U,4))
.. S ROW("inTS")=$S($G(CSV):$$EDATE^EDPRPT(IN),1:IN)
.. S ROW("elapsed")=$$ETIME^EDPRPT(ELAPSE)_" *"
.. S ROW("disposition")=DISP
.. S ROW("acuity")=ACU
.. S ROW("delayReason")=$$ENAME^EDPRPT(DEL)
.. S ROW("md")=$$EPERS^EDPRPT($P(X3,U,5))
.. S ROW("dx")=$P(DX,U,2)
.. S ROW("icd")=$P(DX,U,1)
.. S ROW("icdType")=$P(DX,U,3)
.. S ROW("admDec")=ADMDEC
.. S ROW("admDel")=ADMDEL
.. D LOCTIMES ;split Elapsed into Time in/out of ED
.. S ROW("timeInED")=$$ETIME^EDPRPT(ED)
.. S ROW("timeOutED")=$$ETIME^EDPRPT(NOT)
.. I '$G(CSV) S X=$$XMLA^EDPX("log",.ROW) D XML^EDPX(X) Q
.. S X=ROW("id")
.. ;Begin EDP*2.0*2 Changes
.. F I="patientName","inTS","elapsed","disposition","delayReason","md","admDec","admDel","acuity","dx","icd","icdType" S X=X_$C(9)_$G(ROW(I))
.. ; End EDP*2.0*2 changes
.. F I="patientName","inTS","elapsed","disposition","delayReason","md","admDec","admDel","acuity","dx" S X=X_$C(9)_$G(ROW(I))
.. D ADD^EDPCSV(X)
D:'$G(CSV) XML^EDPX("</logEntries>")
Q
;
D4 ; return counts and averages
D XML^EDPX("<averages>")
S X="<average type='All Patients' total='"_CNT_"' avgTime='"_$S(CNT:$$ETIME^EDPRPT(MIN/CNT),1:0)_"' num6hr='"_CNT("6+")_"' num23hr='"_CNT("23+")_"' avgAdmDec='"_$S(CNT("DEC"):$$ETIME^EDPRPT(MIN("DEC")/CNT("DEC")),1:0)_"' />"
D XML^EDPX(X)
S X="<average type='Not VA Admitted' total='"_(CNT-CNT("VA"))_"' avgTime='"_$S(CNT-CNT("VA"):$$ETIME^EDPRPT((MIN-MIN("VA")/(CNT-CNT("VA")))),1:0)_"' />"
D XML^EDPX(X)
S X="<average type='VA Admitted' total='"_CNT("VA")_"' num6hr='"_CNT("VA6")_"' numAdmDel6hr='"_CNT("VADEL6")
S X=X_"' avgAdmDel='"_$S(CNT("VA"):$$ETIME^EDPRPT(MIN("VADEL")/CNT("VA")),1:0)_"' avgAdmDec='"_$S(CNT("VA"):$$ETIME^EDPRPT(MIN("VADEC")/CNT("VA")),1:0)_"' />"
D XML^EDPX(X)
D XML^EDPX("</averages>")
Q
;
INIT ; Initialize counters and sums
N I S (CNT,MIN)=0
F I="DEC","VA","VA6","VADEL6","6+","23+" S CNT(I)=0
F I="DEC","VA","VADEC","VADEL" S MIN(I)=0
Q
;
VADMIT(X) ; -- Return 1 or 0, if disposition indicates a VA admission
I $G(X)="" Q 0
N I,Y S X=$$UP^XLFSTR(X)
S I=+$O(^EDPB(233.1,"AB","disposition",X,0))
S Y=$S($P($G(^EDPB(233.1,I,0)),U,5)["V":1,1:0)
Q Y
;
VADMIT1(X) ; -- Return 1 or 0, if disposition indicates a VA admission
I +$G(X)=0 Q 0
N Y
S Y=$S($P($G(^EDPB(233.1,X,0)),U,5)["V":1,1:0)
Q Y
;
LOCTIMES ; -- Returns time in ED and NOT ed locations
; Expects LOG, IN, OUT from above
N LIST,I,TM,LOC,X,T1,T2,TYPE
S LIST(IN)="ED",LIST(OUT)="NOT"
S I=0 F S I=$O(^EDP(230.1,"B",LOG,I)) Q:I<1 D
. S TM=+$P($G(^EDP(230.1,I,0)),U,2),LOC=+$P($G(^(3)),U,4) Q:'LOC
. S X=$P($G(^EDPB(231.8,LOC,0)),U,9)
. S LIST(TM)=$S(X>2:"NOT",1:"ED")
; get time in each type of location
S (ED,NOT)=0,TYPE=LIST(IN)
S (T1,T2)=IN
F S T2=$O(LIST(T2)) Q:T2<1 D
. S X=LIST(T2) I T2<OUT,X=TYPE Q
. S @TYPE=@TYPE+$$FMDIFF^XLFDT(T2,T1,2) ;#seconds
. S T1=T2,TYPE=X
S ED=ED\60,NOT=NOT\60 ;#minutes
Q
--- Routine Detail --- with STRUCTURED ROUTINE LISTING ---[H[J[2J[HEDPRPT2 5067 printed Dec 13, 2024@01:52:20 Page 2
EDPRPT2 ;SLC/MKB - Delay Report ;6/13/12 12:33pm
+1 ;;2.0;EMERGENCY DEPARTMENT;**6,2**;Feb 24, 2012;Build 23
+2 ;
DEL(BEG,END,CSV) ; Get Delay Report for EDPSITE by date range
+1 ; CNT = counters
+2 ; MIN = accumulate #minutes
+3 NEW IN,OUT,LOG,X,X0,X1,X3,DX,ELAPSE,ADMDEC,ADMDEL,DISP,VADISP,CNT,MIN,DEL,ACU,ED,NOT
+4 ;set counters, sums to 0
DO INIT
+5 ;headers
if '$GET(CSV)
DO XML^EDPX("<logEntries>")
IF $GET(CSV)
Begin DoDot:1
+6 NEW TAB
SET TAB=$CHAR(9)
+7 ;drp 9/27/2012 begin EDP*2.0*2 changes
+8 SET X="ED IEN"_TAB_"Patient Name"_TAB_"Time In"_TAB_"Elapsed"_TAB_"Dispo"_TAB_"Delay Reason"_TAB_"MD"_TAB_"Adm Dec"_TAB_"Adm Delay"_TAB_"Acuity"_TAB_"Diagnosis"_TAB_"ICD"_TAB_"ICD Type"
+9 ;End EDP*2.0*2 Changes
+10 DO ADD^EDPCSV(X)
End DoDot:1
+11 SET IN=BEG-.000001
+12 FOR
SET IN=$ORDER(^EDP(230,"ATI",EDPSITE,IN))
if 'IN
QUIT
if IN>END
QUIT
SET LOG=0
FOR
SET LOG=+$ORDER(^EDP(230,"ATI",EDPSITE,IN,LOG))
if LOG<1
QUIT
Begin DoDot:1
+13 SET X0=^EDP(230,LOG,0)
SET X1=$GET(^(1))
SET X3=$GET(^(3))
+14 SET ACU=$$ECODE^EDPRPT($PIECE(X3,U,3))
SET DEL=+$PIECE(X1,U,5)
SET CNT=CNT+1
+15 SET DISP=$$ECODE^EDPRPT($PIECE(X1,U,2))
SET VADISP=$$VADMIT(DISP)
+16 ;TDP - Patch 2 mod to catch all dispositions listed as VA admit
+17 IF VADISP=0
SET VADISP=$$VADMIT1($PIECE(X1,U,2))
+18 IF DISP=""
SET DISP=$$DISP^EDPRPT($PIECE(X1,U,2))
+19 ;S:OUT="" OUT=NOW
SET OUT=$PIECE(X0,U,9)
+20 SET ELAPSE=$SELECT(OUT:($$FMDIFF^XLFDT(OUT,IN,2)\60),1:0)
SET MIN=MIN+ELAPSE
D1 ; all admissions
+1 SET (ADMDEC,ADMDEL)=0
+2 SET X=$$ADMIT^EDPRPT(LOG)
IF X
Begin DoDot:2
+3 SET ADMDEC=$$FMDIFF^XLFDT(X,IN,2)\60
+4 if ADMDEC
SET CNT("DEC")=CNT("DEC")+1
SET MIN("DEC")=MIN("DEC")+ADMDEC
+5 SET ADMDEL=$SELECT(OUT:($$FMDIFF^XLFDT(OUT,X,2)\60),1:0)
End DoDot:2
D2 ; VA admissions only
+1 IF VADISP
Begin DoDot:2
+2 SET CNT("VA")=CNT("VA")+1
+3 SET MIN("VA")=MIN("VA")+ELAPSE
+4 SET MIN("VADEC")=MIN("VADEC")+ADMDEC
+5 SET MIN("VADEL")=MIN("VADEL")+ADMDEL
+6 if ADMDEL>359
SET CNT("VADEL6")=CNT("VADEL6")+1
End DoDot:2
D3 ; elapsed visit time >=6 hrs
+1 if ELAPSE>1380
SET CNT("23+")=CNT("23+")+1
+2 IF ELAPSE>359
Begin DoDot:2
+3 SET CNT("6+")=CNT("6+")+1
+4 if VADISP
SET CNT("VA6")=CNT("VA6")+1
+5 SET DX=$$DXPRI^EDPQPCE(+$PIECE(X0,U,3),LOG)
+6 NEW ROW
SET ROW("id")=LOG
+7 SET ROW("patientName")=$SELECT($PIECE(X0,U,6)'="":$$GET1^DIQ(2,$PIECE(X0,U,6),.01,"E"),1:$PIECE(X0,U,4))
+8 SET ROW("inTS")=$SELECT($GET(CSV):$$EDATE^EDPRPT(IN),1:IN)
+9 SET ROW("elapsed")=$$ETIME^EDPRPT(ELAPSE)_" *"
+10 SET ROW("disposition")=DISP
+11 SET ROW("acuity")=ACU
+12 SET ROW("delayReason")=$$ENAME^EDPRPT(DEL)
+13 SET ROW("md")=$$EPERS^EDPRPT($PIECE(X3,U,5))
+14 SET ROW("dx")=$PIECE(DX,U,2)
+15 SET ROW("icd")=$PIECE(DX,U,1)
+16 SET ROW("icdType")=$PIECE(DX,U,3)
+17 SET ROW("admDec")=ADMDEC
+18 SET ROW("admDel")=ADMDEL
+19 ;split Elapsed into Time in/out of ED
DO LOCTIMES
+20 SET ROW("timeInED")=$$ETIME^EDPRPT(ED)
+21 SET ROW("timeOutED")=$$ETIME^EDPRPT(NOT)
+22 IF '$GET(CSV)
SET X=$$XMLA^EDPX("log",.ROW)
DO XML^EDPX(X)
QUIT
+23 SET X=ROW("id")
+24 ;Begin EDP*2.0*2 Changes
+25 FOR I="patientName","inTS","elapsed","disposition","delayReason","md","admDec","admDel","acuity","dx","icd","icdType"
SET X=X_$CHAR(9)_$GET(ROW(I))
+26 ; End EDP*2.0*2 changes
+27 FOR I="patientName","inTS","elapsed","disposition","delayReason","md","admDec","admDel","acuity","dx"
SET X=X_$CHAR(9)_$GET(ROW(I))
+28 DO ADD^EDPCSV(X)
End DoDot:2
End DoDot:1
+29 if '$GET(CSV)
DO XML^EDPX("</logEntries>")
+30 QUIT
+31 ;
D4 ; return counts and averages
+1 DO XML^EDPX("<averages>")
+2 SET X="<average type='All Patients' total='"_CNT_"' avgTime='"_$SELECT(CNT:$$ETIME^EDPRPT(MIN/CNT),1:0)_"' num6hr='"_CNT("6+")_"' num23hr='"_CNT("23+")_"' avgAdmDec='"_$SELECT(CNT("DEC"):$$ETIME^EDPRPT(MIN("DEC")/CNT("DEC")),1:0)_"' />"
+3 DO XML^EDPX(X)
+4 SET X="<average type='Not VA Admitted' total='"_(CNT-CNT("VA"))_"' avgTime='"_$SELECT(CNT-CNT("VA"):$$ETIME^EDPRPT((MIN-MIN("VA")/(CNT-CNT("VA")))),1:0)_"' />"
+5 DO XML^EDPX(X)
+6 SET X="<average type='VA Admitted' total='"_CNT("VA")_"' num6hr='"_CNT("VA6")_"' numAdmDel6hr='"_CNT("VADEL6")
+7 SET X=X_"' avgAdmDel='"_$SELECT(CNT("VA"):$$ETIME^EDPRPT(MIN("VADEL")/CNT("VA")),1:0)_"' avgAdmDec='"_$SELECT(CNT("VA"):$$ETIME^EDPRPT(MIN("VADEC")/CNT("VA")),1:0)_"' />"
+8 DO XML^EDPX(X)
+9 DO XML^EDPX("</averages>")
+10 QUIT
+11 ;
INIT ; Initialize counters and sums
+1 NEW I
SET (CNT,MIN)=0
+2 FOR I="DEC","VA","VA6","VADEL6","6+","23+"
SET CNT(I)=0
+3 FOR I="DEC","VA","VADEC","VADEL"
SET MIN(I)=0
+4 QUIT
+5 ;
VADMIT(X) ; -- Return 1 or 0, if disposition indicates a VA admission
+1 IF $GET(X)=""
QUIT 0
+2 NEW I,Y
SET X=$$UP^XLFSTR(X)
+3 SET I=+$ORDER(^EDPB(233.1,"AB","disposition",X,0))
+4 SET Y=$SELECT($PIECE($GET(^EDPB(233.1,I,0)),U,5)["V":1,1:0)
+5 QUIT Y
+6 ;
VADMIT1(X) ; -- Return 1 or 0, if disposition indicates a VA admission
+1 IF +$GET(X)=0
QUIT 0
+2 NEW Y
+3 SET Y=$SELECT($PIECE($GET(^EDPB(233.1,X,0)),U,5)["V":1,1:0)
+4 QUIT Y
+5 ;
LOCTIMES ; -- Returns time in ED and NOT ed locations
+1 ; Expects LOG, IN, OUT from above
+2 NEW LIST,I,TM,LOC,X,T1,T2,TYPE
+3 SET LIST(IN)="ED"
SET LIST(OUT)="NOT"
+4 SET I=0
FOR
SET I=$ORDER(^EDP(230.1,"B",LOG,I))
if I<1
QUIT
Begin DoDot:1
+5 SET TM=+$PIECE($GET(^EDP(230.1,I,0)),U,2)
SET LOC=+$PIECE($GET(^(3)),U,4)
if 'LOC
QUIT
+6 SET X=$PIECE($GET(^EDPB(231.8,LOC,0)),U,9)
+7 SET LIST(TM)=$SELECT(X>2:"NOT",1:"ED")
End DoDot:1
+8 ; get time in each type of location
+9 SET (ED,NOT)=0
SET TYPE=LIST(IN)
+10 SET (T1,T2)=IN
+11 FOR
SET T2=$ORDER(LIST(T2))
if T2<1
QUIT
Begin DoDot:1
+12 SET X=LIST(T2)
IF T2<OUT
IF X=TYPE
QUIT
+13 ;#seconds
SET @TYPE=@TYPE+$$FMDIFF^XLFDT(T2,T1,2)
+14 SET T1=T2
SET TYPE=X
End DoDot:1
+15 ;#minutes
SET ED=ED\60
SET NOT=NOT\60
+16 QUIT