EDPRPT8 ;SLC/MKB - Acuity Report ;2/28/12 08:33am
;;2.0;EMERGENCY DEPARTMENT;**6**;Feb 24, 2012;Build 200
;
ACU(BEG,END,CSV) ; Get Acuity Report for EDPSITE by date range
; CNT = counters by acuity
; ADM = counters for all admissions
; VA = counters for VA admissions
; MIN = accumulate #minutes
N IN,OUT,X,X0,X1,X3,X4,DISP,ACU,CNT,ADM,MIN,VA,ROW,ADMDEC,ADMDEL,LOG
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)),ACU=$$ECODE($P(X3,U,3))
. S CNT=CNT+1,CNT(ACU)=CNT(ACU)+1
. ; all admissions
. S (ADMDEC,ADMDEL)=0
. S X=$$ADMIT^EDPRPT(LOG) I X D ;decision to admit
.. S ADM=ADM+1,ADM(ACU)=ADM(ACU)+1
.. S ADMDEC=$$FMDIFF^XLFDT(X,IN,2)\60
.. S:ADMDEC MIN("DEC")=MIN("DEC")+ADMDEC,MIN("DEC",ACU)=MIN("DEC",ACU)+ADMDEC
.. S OUT=$P(X0,U,9) ;S:OUT="" OUT=NOW
.. S:OUT ADMDEL=$$FMDIFF^XLFDT(OUT,X,2)\60
. ;TDP - Patch 2, insure all VA Admissions are counted. Added VADMIT1.
. I (($$VADMIT^EDPRPT2(DISP))!($$VADMIT1^EDPRPT2($P(X1,U,2)))) D ;VA admissions
.. S VA=VA+1,VA(ACU)=VA(ACU)+1
.. S MIN("VADEC")=MIN("VADEC")+ADMDEC
.. S MIN("VADEC",ACU)=MIN("VADEC",ACU)+ADMDEC
.. S MIN("VADEL")=MIN("VADEL")+ADMDEL
.. S MIN("VADEL",ACU)=MIN("VADEL",ACU)+ADMDEL
A1 ; return counts and averages
S I="" F S I=$O(ADM(I)) Q:I="" D ;avg #min admit dec by acuity
. S MIN("DEC",I)=$S(ADM(I):$$ETIME^EDPRPT(MIN("DEC",I)\ADM(I)),1:0)
. S MIN("VADEC",I)=$S(VA(I):$$ETIME^EDPRPT(MIN("VADEC",I)\VA(I)),1:0)
. S MIN("VADEL",I)=$S(VA(I):$$ETIME^EDPRPT(MIN("VADEL",I)\VA(I)),1:0)
S CNT("total")=CNT,ADM("total")=ADM,VA("total")=VA
S CNT("type")="Number of Patients",ADM("type")="Number Admitted",VA("type")="Number VA Admitted"
S MIN("DEC","type")="Avg All Admit Dec Time",MIN("VADEC","type")="Avg VA Admit Dec Time",MIN("VADEL","type")="Avg VA Admit Delay Time"
S MIN("DEC","total")=$S(ADM:$$ETIME^EDPRPT(MIN("DEC")\ADM),1:0)
S MIN("VADEC","total")=$S(VA:$$ETIME^EDPRPT(MIN("VADEC")\VA),1:0)
S MIN("VADEL","total")=$S(VA:$$ETIME^EDPRPT(MIN("VADEL")\VA),1:0)
; as CSV
I $G(CSV) D Q
. N TAB S TAB=$C(9)
. ;S X="Acuity->"_TAB_"0"_TAB_"1"_TAB_"2"_TAB_"3"_TAB_"4"_TAB_"5"_TAB_"Total/Average"
. S X="Acuity->"_TAB_"None"_TAB_"1"_TAB_"2"_TAB_"3"_TAB_"4"_TAB_"5"_TAB_"Total/Average"
. D ADD^EDPCSV(X)
. D ROW("Number of Patients",.CNT)
. D ROW("Number Admitted",.ADM)
. D ROW("Number VA Admitted",.VA)
. M ROW=MIN("DEC") D ROW("Avg All Admit Dec Time",.ROW) K ROW
. M ROW=MIN("VADEC") D ROW("Avg VA Admit Dec Time",.ROW) K ROW
. M ROW=MIN("VADEL") D ROW("Avg VA Admit Delay Time",.ROW) K ROW
; or as XML
D XML^EDPX("<statistics>")
S X=$$XMLA^EDPX("row",.CNT) D XML^EDPX(X)
S X=$$XMLA^EDPX("row",.ADM) D XML^EDPX(X)
S X=$$XMLA^EDPX("row",.VA) D XML^EDPX(X)
M ROW=MIN("DEC") S X=$$XMLA^EDPX("row",.ROW) D XML^EDPX(X) K ROW
M ROW=MIN("VADEC") S X=$$XMLA^EDPX("row",.ROW) D XML^EDPX(X) K ROW
M ROW=MIN("VADEL") S X=$$XMLA^EDPX("row",.ROW) D XML^EDPX(X) K ROW
D XML^EDPX("</statistics>")
Q
;
ROW(NAME,LIST) ; add line
N I S X=NAME
F I="none","one","two","three","four","five","total" S X=X_TAB_LIST(I)
D ADD^EDPCSV(X)
Q
;
INIT ; Initialize acuity counters
N X S (CNT,ADM,VA)=0
F X="none","one","two","three","four","five" D
. S (CNT(X),ADM(X),VA(X),MIN("DEC",X),MIN("VADEC",X),MIN("VADEL",X))=0
F X="DEC","VADEC","VADEL" S MIN(X)=0
Q
;
ECODE(IEN) ; Return external value for an Acuity code
N X0,X,Y S X0=$G(^EDPB(233.1,+IEN,0))
S X=$P(X0,U,3) S:X<1 X=$P(X0,U,4) ;code or nat'l code
S Y=$S(X=1:"one",X=2:"two",X=3:"three",X=4:"four",X=5:"five",1:"none")
Q Y
--- Routine Detail --- with STRUCTURED ROUTINE LISTING ---[H[J[2J[HEDPRPT8 3815 printed Oct 16, 2024@17:53:17 Page 2
EDPRPT8 ;SLC/MKB - Acuity Report ;2/28/12 08:33am
+1 ;;2.0;EMERGENCY DEPARTMENT;**6**;Feb 24, 2012;Build 200
+2 ;
ACU(BEG,END,CSV) ; Get Acuity Report for EDPSITE by date range
+1 ; CNT = counters by acuity
+2 ; ADM = counters for all admissions
+3 ; VA = counters for VA admissions
+4 ; MIN = accumulate #minutes
+5 NEW IN,OUT,X,X0,X1,X3,X4,DISP,ACU,CNT,ADM,MIN,VA,ROW,ADMDEC,ADMDEL,LOG
+6 ;set counters, sums to 0
DO INIT
+7 SET IN=BEG-.000001
+8 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
+9 SET X0=^EDP(230,LOG,0)
SET X1=$GET(^(1))
SET X3=$GET(^(3))
SET X4=$GET(^(4,1,0))
+10 SET DISP=$$ECODE^EDPRPT($PIECE(X1,U,2))
SET ACU=$$ECODE($PIECE(X3,U,3))
+11 SET CNT=CNT+1
SET CNT(ACU)=CNT(ACU)+1
+12 ; all admissions
+13 SET (ADMDEC,ADMDEL)=0
+14 ;decision to admit
SET X=$$ADMIT^EDPRPT(LOG)
IF X
Begin DoDot:2
+15 SET ADM=ADM+1
SET ADM(ACU)=ADM(ACU)+1
+16 SET ADMDEC=$$FMDIFF^XLFDT(X,IN,2)\60
+17 if ADMDEC
SET MIN("DEC")=MIN("DEC")+ADMDEC
SET MIN("DEC",ACU)=MIN("DEC",ACU)+ADMDEC
+18 ;S:OUT="" OUT=NOW
SET OUT=$PIECE(X0,U,9)
+19 if OUT
SET ADMDEL=$$FMDIFF^XLFDT(OUT,X,2)\60
End DoDot:2
+20 ;TDP - Patch 2, insure all VA Admissions are counted. Added VADMIT1.
+21 ;VA admissions
IF (($$VADMIT^EDPRPT2(DISP))!($$VADMIT1^EDPRPT2($PIECE(X1,U,2))))
Begin DoDot:2
+22 SET VA=VA+1
SET VA(ACU)=VA(ACU)+1
+23 SET MIN("VADEC")=MIN("VADEC")+ADMDEC
+24 SET MIN("VADEC",ACU)=MIN("VADEC",ACU)+ADMDEC
+25 SET MIN("VADEL")=MIN("VADEL")+ADMDEL
+26 SET MIN("VADEL",ACU)=MIN("VADEL",ACU)+ADMDEL
End DoDot:2
End DoDot:1
A1 ; return counts and averages
+1 ;avg #min admit dec by acuity
SET I=""
FOR
SET I=$ORDER(ADM(I))
if I=""
QUIT
Begin DoDot:1
+2 SET MIN("DEC",I)=$SELECT(ADM(I):$$ETIME^EDPRPT(MIN("DEC",I)\ADM(I)),1:0)
+3 SET MIN("VADEC",I)=$SELECT(VA(I):$$ETIME^EDPRPT(MIN("VADEC",I)\VA(I)),1:0)
+4 SET MIN("VADEL",I)=$SELECT(VA(I):$$ETIME^EDPRPT(MIN("VADEL",I)\VA(I)),1:0)
End DoDot:1
+5 SET CNT("total")=CNT
SET ADM("total")=ADM
SET VA("total")=VA
+6 SET CNT("type")="Number of Patients"
SET ADM("type")="Number Admitted"
SET VA("type")="Number VA Admitted"
+7 SET MIN("DEC","type")="Avg All Admit Dec Time"
SET MIN("VADEC","type")="Avg VA Admit Dec Time"
SET MIN("VADEL","type")="Avg VA Admit Delay Time"
+8 SET MIN("DEC","total")=$SELECT(ADM:$$ETIME^EDPRPT(MIN("DEC")\ADM),1:0)
+9 SET MIN("VADEC","total")=$SELECT(VA:$$ETIME^EDPRPT(MIN("VADEC")\VA),1:0)
+10 SET MIN("VADEL","total")=$SELECT(VA:$$ETIME^EDPRPT(MIN("VADEL")\VA),1:0)
+11 ; as CSV
+12 IF $GET(CSV)
Begin DoDot:1
+13 NEW TAB
SET TAB=$CHAR(9)
+14 ;S X="Acuity->"_TAB_"0"_TAB_"1"_TAB_"2"_TAB_"3"_TAB_"4"_TAB_"5"_TAB_"Total/Average"
+15 SET X="Acuity->"_TAB_"None"_TAB_"1"_TAB_"2"_TAB_"3"_TAB_"4"_TAB_"5"_TAB_"Total/Average"
+16 DO ADD^EDPCSV(X)
+17 DO ROW("Number of Patients",.CNT)
+18 DO ROW("Number Admitted",.ADM)
+19 DO ROW("Number VA Admitted",.VA)
+20 MERGE ROW=MIN("DEC")
DO ROW("Avg All Admit Dec Time",.ROW)
KILL ROW
+21 MERGE ROW=MIN("VADEC")
DO ROW("Avg VA Admit Dec Time",.ROW)
KILL ROW
+22 MERGE ROW=MIN("VADEL")
DO ROW("Avg VA Admit Delay Time",.ROW)
KILL ROW
End DoDot:1
QUIT
+23 ; or as XML
+24 DO XML^EDPX("<statistics>")
+25 SET X=$$XMLA^EDPX("row",.CNT)
DO XML^EDPX(X)
+26 SET X=$$XMLA^EDPX("row",.ADM)
DO XML^EDPX(X)
+27 SET X=$$XMLA^EDPX("row",.VA)
DO XML^EDPX(X)
+28 MERGE ROW=MIN("DEC")
SET X=$$XMLA^EDPX("row",.ROW)
DO XML^EDPX(X)
KILL ROW
+29 MERGE ROW=MIN("VADEC")
SET X=$$XMLA^EDPX("row",.ROW)
DO XML^EDPX(X)
KILL ROW
+30 MERGE ROW=MIN("VADEL")
SET X=$$XMLA^EDPX("row",.ROW)
DO XML^EDPX(X)
KILL ROW
+31 DO XML^EDPX("</statistics>")
+32 QUIT
+33 ;
ROW(NAME,LIST) ; add line
+1 NEW I
SET X=NAME
+2 FOR I="none","one","two","three","four","five","total"
SET X=X_TAB_LIST(I)
+3 DO ADD^EDPCSV(X)
+4 QUIT
+5 ;
INIT ; Initialize acuity counters
+1 NEW X
SET (CNT,ADM,VA)=0
+2 FOR X="none","one","two","three","four","five"
Begin DoDot:1
+3 SET (CNT(X),ADM(X),VA(X),MIN("DEC",X),MIN("VADEC",X),MIN("VADEL",X))=0
End DoDot:1
+4 FOR X="DEC","VADEC","VADEL"
SET MIN(X)=0
+5 QUIT
+6 ;
ECODE(IEN) ; Return external value for an Acuity code
+1 NEW X0,X,Y
SET X0=$GET(^EDPB(233.1,+IEN,0))
+2 ;code or nat'l code
SET X=$PIECE(X0,U,3)
if X<1
SET X=$PIECE(X0,U,4)
+3 SET Y=$SELECT(X=1:"one",X=2:"two",X=3:"three",X=4:"four",X=5:"five",1:"none")
+4 QUIT Y