EDPRPT4 ;SLC/MKB - Delay Summary Report ;4/26/13 12:27pm
;;2.0;EMERGENCY DEPARTMENT;**6**;May 2, 2012;Build 200
;
SUM(BEG,END,CSV) ; Get Delay Report for EDPSITE by date range
; CNT = counters
; MIN = accumulate #minutes
N IN,OUT,LOG,X,X0,X1,X3,X4,ELAPSE,ADMDEC,ADMDEL,DISP,STS,VADM,CNT,MIN,PROV,DEL,ACU,Y
D INIT ;set counters, sums to 0
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)),X4=$G(^(4,1,0))
. S DISP=$$ECODE^EDPRPT($P(X1,U,2)),VADM=$$VADMIT^EDPRPT2(DISP)
. ;TDP - Patch 2, additional check for VA Admissions w/o abbreviation
. I VADM=0 S VADM=$$VADMIT1^EDPRPT2($P(X1,U,2))
. S ACU=$$ECODE($P(X3,U,3)),STS=$P(X3,U,2)
. S DEL=+$P(X1,U,5),CNT=CNT+1
. 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)
. S:$$OBS(STS) CNT("OBS")=CNT("OBS")+1
D2 . ; VA admissions only
. I VADM 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:VADM CNT("VA6")=CNT("VA6")+1
. S:DEL CNT(DEL,ACU)=+$G(CNT(DEL,ACU))+1,CNT(DEL)=+$G(CNT(DEL))+1
;
D4 ; return counts and averages as CSV
I $G(CSV) D Q
. N TAB S TAB=$C(9)
. ;***pij 4/25/2013
. ;S X=TAB_TAB_"Delay Reason"_TAB_"0"_TAB_"1"_TAB_"2"_TAB_"3"_TAB_"4"_TAB_"5"_TAB_"Total"
. ; BWF 4/26/2013 - Adding proper header
. S X="Delay Summary Report from "_$$FMTE^XLFDT(BEG)_" to "_$$FMTE^XLFDT(END)
. D ADD^EDPCSV(X),BLANK^EDPCSV ;headers
. S X="All ED Visits"_TAB_"VA Admitted"_TAB_"Not VA Admitted"
. D ADD^EDPCSV(X),BLANK^EDPCSV
. S Y=CNT("VA")
. S X="Total Visits: "_CNT_TAB_"Total Visits: "_Y
. S Y=CNT-CNT("VA"),X=X_TAB_"Total Visits: "_Y
. D ADD^EDPCSV(X),BLANK^EDPCSV
. S X="Total Visits Over Six Hours: "_CNT("6+")_TAB
. S X=X_"Total Visits Over Six Hours: "_CNT("VA6")_TAB
. S X=X_"Average Visit Time: "_$S(Y:$$ETIME^EDPRPT((MIN-MIN("VA")\Y)),1:0)
. D ADD^EDPCSV(X),BLANK^EDPCSV
. S X="Total Visits Over 23 Hours: "_CNT("23+")_TAB
. S Y=CNT("VA"),X=X_"Average Admit Decision Time: "_$S(Y:$$ETIME^EDPRPT(MIN("VADEC")\Y),1:0)
. D ADD^EDPCSV(X),BLANK^EDPCSV
. S X="Average Visit Time: "_$S(CNT:$$ETIME^EDPRPT(MIN\CNT),1:0)_TAB
. S Y=CNT("VA"),X=X_"Average Delay Time: "_$S(Y:$$ETIME^EDPRPT(MIN("VADEL")\Y),1:0)
. D ADD^EDPCSV(X),BLANK^EDPCSV
. S Y=CNT("DEC"),X="Average Admit Decision Time: "_$S(Y:$$ETIME^EDPRPT(MIN("DEC")\Y),1:0)_TAB
. S X=X_"Number of Admit Delays over Six Hours: "_CNT("VADEL6")
. D ADD^EDPCSV(X),BLANK^EDPCSV
. S X="Number Admitted to Observation: "_CNT("OBS")
. D ADD^EDPCSV(X),BLANK^EDPCSV
. D BLANK^EDPCSV
. ;***pij 4/26/2013 delete 2 TABs
. ;S X=TAB_TAB_"Delay Chart" D ADD^EDPCSV(X),BLANK^EDPCSV
. ;BWF 4/26/2013 - Adding Header for rest of report
. D BLANK^EDPCSV ;add blank line
. S X="Delay Chart from "_$$FMTE^XLFDT(BEG)_" to "_$$FMTE^XLFDT(END) D ADD^EDPCSV(X),BLANK^EDPCSV
. ;S X="Delay Chart" D ADD^EDPCSV(X),BLANK^EDPCSV
. ;S X=TAB_TAB_"Acuity"_TAB_"None"_TAB_"1"_TAB_"2"_TAB_"3"_TAB_"4"_TAB_"5"_TAB_"Total"
. S X="Acuity"_TAB_"None"_TAB_"1"_TAB_"2"_TAB_"3"_TAB_"4"_TAB_"5"_TAB_"Total"
. ;***
. D ADD^EDPCSV(X),BLANK^EDPCSV
. S DEL=0 F S DEL=$O(CNT(DEL)) Q:+DEL'=DEL D
.. ;***pij 4/26/2013 remove the 2 TABs for each row from Delay Chart
.. ;S X=$$ENAME^EDPRPT(DEL) Q:X="" Q:X?1." " S X=TAB_TAB_X ;novalue
.. S X=$$ENAME^EDPRPT(DEL) Q:X="" Q:X?1." " ;S X=TAB_TAB_X ;novalue
.. ;***
.. F I="none","one","two","three","four","five" S X=X_TAB_+$G(CNT(DEL,I))
.. S X=X_TAB_CNT(DEL) D ADD^EDPCSV(X)
D5 ; or return counts and averages as XML
D XML^EDPX("<averages>")
S X="<average type='All Patients' total='"_CNT
S X=X_"' avgTime='"_$S(CNT:$$ETIME^EDPRPT(MIN\CNT),1:0)
S X=X_"' num6hr='"_CNT("6+")_"' num23hr='"_CNT("23+"),Y=CNT("DEC")
S X=X_"' avgAdmDec='"_$S(Y:$$ETIME^EDPRPT(MIN("DEC")\Y),1:0)
S X=X_"' numObs='"_CNT("OBS")_"' />"
D XML^EDPX(X)
S Y=CNT-CNT("VA")
S X="<average type='Not VA Admitted' total='"_Y_"' avgTime='"_$S(Y:$$ETIME^EDPRPT((MIN-MIN("VA")\Y)),1:0)_"' />"
D XML^EDPX(X)
S Y=CNT("VA"),X="<average type='VA Admitted' total='"_Y
S X=X_"' num6hr='"_CNT("VA6")_"' numAdmDel6hr='"_CNT("VADEL6")
S X=X_"' avgAdmDel='"_$S(Y:$$ETIME^EDPRPT(MIN("VADEL")\Y),1:0)
S X=X_"' avgAdmDec='"_$S(Y:$$ETIME^EDPRPT(MIN("VADEC")\Y),1:0)_"' />"
D XML^EDPX(X)
D XML^EDPX("</averages>")
D XML^EDPX("<delayChart>")
S DEL=0 F S DEL=$O(CNT(DEL)) Q:+DEL'=DEL D
. S X=$$ENAME^EDPRPT(DEL) Q:X="" Q:X?1." " ;novalue
. S CNT(DEL,"reason")=X,CNT(DEL,"total")=CNT(DEL)
. F I="none","one","two","three","four","five" S CNT(DEL,I)=+$G(CNT(DEL,I))
. K ROW M ROW=CNT(DEL)
. S X=$$XMLA^EDPX("delay",.ROW) D XML^EDPX(X)
D XML^EDPX("</delayChart>")
Q
;
INIT ; Initialize counters and sums
N I S (CNT,MIN)=0
F I="DEC","VA","VA6","VADEL6","6+","23+","OBS" S CNT(I)=0
F I="DEC","VA","VADEC","VADEL" S MIN(I)=0
Q
;
ECODE(IEN) ; Return external value for an Acuity code
N X,Y S X=$P($G(^EDPB(233.1,+IEN,0)),U,3) ;code
S Y=$S(X="":"none",X=1:"one",X=2:"two",X=3:"three",X=4:"four",X=5:"five",1:"X")
Q Y
;
OBS(IEN) ; Return 1 or 0, if status IEN indicates Observation
I $G(IEN),$P($G(^EDPB(233.1,+IEN,0)),U,5)["O" Q 1
Q 0
--- Routine Detail --- with STRUCTURED ROUTINE LISTING ---[H[J[2J[HEDPRPT4 5802 printed Oct 16, 2024@17:53:12 Page 2
EDPRPT4 ;SLC/MKB - Delay Summary Report ;4/26/13 12:27pm
+1 ;;2.0;EMERGENCY DEPARTMENT;**6**;May 2, 2012;Build 200
+2 ;
SUM(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,X4,ELAPSE,ADMDEC,ADMDEL,DISP,STS,VADM,CNT,MIN,PROV,DEL,ACU,Y
+4 ;set counters, sums to 0
DO INIT
+5 SET IN=BEG-.000001
+6 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
+7 SET X0=^EDP(230,LOG,0)
SET X1=$GET(^(1))
SET X3=$GET(^(3))
SET X4=$GET(^(4,1,0))
+8 SET DISP=$$ECODE^EDPRPT($PIECE(X1,U,2))
SET VADM=$$VADMIT^EDPRPT2(DISP)
+9 ;TDP - Patch 2, additional check for VA Admissions w/o abbreviation
+10 IF VADM=0
SET VADM=$$VADMIT1^EDPRPT2($PIECE(X1,U,2))
+11 SET ACU=$$ECODE($PIECE(X3,U,3))
SET STS=$PIECE(X3,U,2)
+12 SET DEL=+$PIECE(X1,U,5)
SET CNT=CNT+1
+13 ;S:OUT="" OUT=NOW
SET OUT=$PIECE(X0,U,9)
+14 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
+6 if $$OBS(STS)
SET CNT("OBS")=CNT("OBS")+1
D2 ; VA admissions only
+1 IF VADM
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 VADM
SET CNT("VA6")=CNT("VA6")+1
End DoDot:2
+5 if DEL
SET CNT(DEL,ACU)=+$GET(CNT(DEL,ACU))+1
SET CNT(DEL)=+$GET(CNT(DEL))+1
End DoDot:1
+6 ;
D4 ; return counts and averages as CSV
+1 IF $GET(CSV)
Begin DoDot:1
+2 NEW TAB
SET TAB=$CHAR(9)
+3 ;***pij 4/25/2013
+4 ;S X=TAB_TAB_"Delay Reason"_TAB_"0"_TAB_"1"_TAB_"2"_TAB_"3"_TAB_"4"_TAB_"5"_TAB_"Total"
+5 ; BWF 4/26/2013 - Adding proper header
+6 SET X="Delay Summary Report from "_$$FMTE^XLFDT(BEG)_" to "_$$FMTE^XLFDT(END)
+7 ;headers
DO ADD^EDPCSV(X)
DO BLANK^EDPCSV
+8 SET X="All ED Visits"_TAB_"VA Admitted"_TAB_"Not VA Admitted"
+9 DO ADD^EDPCSV(X)
DO BLANK^EDPCSV
+10 SET Y=CNT("VA")
+11 SET X="Total Visits: "_CNT_TAB_"Total Visits: "_Y
+12 SET Y=CNT-CNT("VA")
SET X=X_TAB_"Total Visits: "_Y
+13 DO ADD^EDPCSV(X)
DO BLANK^EDPCSV
+14 SET X="Total Visits Over Six Hours: "_CNT("6+")_TAB
+15 SET X=X_"Total Visits Over Six Hours: "_CNT("VA6")_TAB
+16 SET X=X_"Average Visit Time: "_$SELECT(Y:$$ETIME^EDPRPT((MIN-MIN("VA")\Y)),1:0)
+17 DO ADD^EDPCSV(X)
DO BLANK^EDPCSV
+18 SET X="Total Visits Over 23 Hours: "_CNT("23+")_TAB
+19 SET Y=CNT("VA")
SET X=X_"Average Admit Decision Time: "_$SELECT(Y:$$ETIME^EDPRPT(MIN("VADEC")\Y),1:0)
+20 DO ADD^EDPCSV(X)
DO BLANK^EDPCSV
+21 SET X="Average Visit Time: "_$SELECT(CNT:$$ETIME^EDPRPT(MIN\CNT),1:0)_TAB
+22 SET Y=CNT("VA")
SET X=X_"Average Delay Time: "_$SELECT(Y:$$ETIME^EDPRPT(MIN("VADEL")\Y),1:0)
+23 DO ADD^EDPCSV(X)
DO BLANK^EDPCSV
+24 SET Y=CNT("DEC")
SET X="Average Admit Decision Time: "_$SELECT(Y:$$ETIME^EDPRPT(MIN("DEC")\Y),1:0)_TAB
+25 SET X=X_"Number of Admit Delays over Six Hours: "_CNT("VADEL6")
+26 DO ADD^EDPCSV(X)
DO BLANK^EDPCSV
+27 SET X="Number Admitted to Observation: "_CNT("OBS")
+28 DO ADD^EDPCSV(X)
DO BLANK^EDPCSV
+29 DO BLANK^EDPCSV
+30 ;***pij 4/26/2013 delete 2 TABs
+31 ;S X=TAB_TAB_"Delay Chart" D ADD^EDPCSV(X),BLANK^EDPCSV
+32 ;BWF 4/26/2013 - Adding Header for rest of report
+33 ;add blank line
DO BLANK^EDPCSV
+34 SET X="Delay Chart from "_$$FMTE^XLFDT(BEG)_" to "_$$FMTE^XLFDT(END)
DO ADD^EDPCSV(X)
DO BLANK^EDPCSV
+35 ;S X="Delay Chart" D ADD^EDPCSV(X),BLANK^EDPCSV
+36 ;S X=TAB_TAB_"Acuity"_TAB_"None"_TAB_"1"_TAB_"2"_TAB_"3"_TAB_"4"_TAB_"5"_TAB_"Total"
+37 SET X="Acuity"_TAB_"None"_TAB_"1"_TAB_"2"_TAB_"3"_TAB_"4"_TAB_"5"_TAB_"Total"
+38 ;***
+39 DO ADD^EDPCSV(X)
DO BLANK^EDPCSV
+40 SET DEL=0
FOR
SET DEL=$ORDER(CNT(DEL))
if +DEL'=DEL
QUIT
Begin DoDot:2
+41 ;***pij 4/26/2013 remove the 2 TABs for each row from Delay Chart
+42 ;S X=$$ENAME^EDPRPT(DEL) Q:X="" Q:X?1." " S X=TAB_TAB_X ;novalue
+43 ;S X=TAB_TAB_X ;novalue
SET X=$$ENAME^EDPRPT(DEL)
if X=""
QUIT
if X?1." "
QUIT
+44 ;***
+45 FOR I="none","one","two","three","four","five"
SET X=X_TAB_+$GET(CNT(DEL,I))
+46 SET X=X_TAB_CNT(DEL)
DO ADD^EDPCSV(X)
End DoDot:2
End DoDot:1
QUIT
D5 ; or return counts and averages as XML
+1 DO XML^EDPX("<averages>")
+2 SET X="<average type='All Patients' total='"_CNT
+3 SET X=X_"' avgTime='"_$SELECT(CNT:$$ETIME^EDPRPT(MIN\CNT),1:0)
+4 SET X=X_"' num6hr='"_CNT("6+")_"' num23hr='"_CNT("23+")
SET Y=CNT("DEC")
+5 SET X=X_"' avgAdmDec='"_$SELECT(Y:$$ETIME^EDPRPT(MIN("DEC")\Y),1:0)
+6 SET X=X_"' numObs='"_CNT("OBS")_"' />"
+7 DO XML^EDPX(X)
+8 SET Y=CNT-CNT("VA")
+9 SET X="<average type='Not VA Admitted' total='"_Y_"' avgTime='"_$SELECT(Y:$$ETIME^EDPRPT((MIN-MIN("VA")\Y)),1:0)_"' />"
+10 DO XML^EDPX(X)
+11 SET Y=CNT("VA")
SET X="<average type='VA Admitted' total='"_Y
+12 SET X=X_"' num6hr='"_CNT("VA6")_"' numAdmDel6hr='"_CNT("VADEL6")
+13 SET X=X_"' avgAdmDel='"_$SELECT(Y:$$ETIME^EDPRPT(MIN("VADEL")\Y),1:0)
+14 SET X=X_"' avgAdmDec='"_$SELECT(Y:$$ETIME^EDPRPT(MIN("VADEC")\Y),1:0)_"' />"
+15 DO XML^EDPX(X)
+16 DO XML^EDPX("</averages>")
+17 DO XML^EDPX("<delayChart>")
+18 SET DEL=0
FOR
SET DEL=$ORDER(CNT(DEL))
if +DEL'=DEL
QUIT
Begin DoDot:1
+19 ;novalue
SET X=$$ENAME^EDPRPT(DEL)
if X=""
QUIT
if X?1." "
QUIT
+20 SET CNT(DEL,"reason")=X
SET CNT(DEL,"total")=CNT(DEL)
+21 FOR I="none","one","two","three","four","five"
SET CNT(DEL,I)=+$GET(CNT(DEL,I))
+22 KILL ROW
MERGE ROW=CNT(DEL)
+23 SET X=$$XMLA^EDPX("delay",.ROW)
DO XML^EDPX(X)
End DoDot:1
+24 DO XML^EDPX("</delayChart>")
+25 QUIT
+26 ;
INIT ; Initialize counters and sums
+1 NEW I
SET (CNT,MIN)=0
+2 FOR I="DEC","VA","VA6","VADEL6","6+","23+","OBS"
SET CNT(I)=0
+3 FOR I="DEC","VA","VADEC","VADEL"
SET MIN(I)=0
+4 QUIT
+5 ;
ECODE(IEN) ; Return external value for an Acuity code
+1 ;code
NEW X,Y
SET X=$PIECE($GET(^EDPB(233.1,+IEN,0)),U,3)
+2 SET Y=$SELECT(X="":"none",X=1:"one",X=2:"two",X=3:"three",X=4:"four",X=5:"five",1:"X")
+3 QUIT Y
+4 ;
OBS(IEN) ; Return 1 or 0, if status IEN indicates Observation
+1 IF $GET(IEN)
IF $PIECE($GET(^EDPB(233.1,+IEN,0)),U,5)["O"
QUIT 1
+2 QUIT 0