EDPRPT11 ;SLC/MKB - Patient Intake Report ;2/28/12 08:33am
;;2.0;EMERGENCY DEPARTMENT;;May 2, 2012;Build 103
;
CNT(BEG,END,CSV) ; Get Patient Intake Report for EDPSITE by date range
; CNT = counters
N IN,LOG,LAST,X,CNT,HR,DAY,%H,%T,%Y,H,D,ROW,AVG,NM,TAB,DAYS
D INIT S LAST="" ;set counters to 0
S IN=BEG-.000001,TAB=$C(9)
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 X=$P($G(^EDP(230,LOG,0)),U,8) Q:X<1
. D H^%DTC S H=%T\3600,D=%Y
. S CNT=CNT+1,HR(H)=HR(H)+1,CNT(H,D)=CNT(H,D)+1
. S DAY(D)=DAY(D)+1
. I LAST=""!($P(LAST,".")'=$P(IN,".")) S DAYS(D)=DAYS(D)+1,LAST=IN
C1 ; return counts and averages
D:'$G(CSV) XML^EDPX("<averages>") I $G(CSV) D ;headers
. S X="Time/Day"_TAB_"Sunday"_TAB_"Monday"_TAB_"Tuesday"_TAB_"Wednesday"_TAB_"Thursday"_TAB_"Friday"_TAB_"Saturday"_TAB_"Totals"_TAB_"Avg/Day"
. D ADD^EDPCSV(X),BLANK^EDPCSV
F H=0:1:23 D
. K ROW S ROW("time")=$$TIME(H)_"-"_$$TIME(H+1)
. S ROW=ROW("time") ;CSV
. F D=0:1:6 S NM=$$NAME(D) D
.. S ROW(NM)=CNT(H,D)
.. S ROW=ROW_TAB_ROW(NM) ;CSV
. S ROW("total")=HR(H),ROW("average")=$$ROUND(HR(H)/DAYS)
. I '$G(CSV) S X=$$XMLA^EDPX("row",.ROW) D XML^EDPX(X) Q
. S ROW=ROW_TAB_ROW("total")_TAB_ROW("average") D ADD^EDPCSV(ROW)
; total & average rows
K ROW S ROW("time")="Totals",ROW=ROW("time")
S AVG("time")="Avg/Hour",AVG=AVG("time")
F D=0:1:6 S NM=$$NAME(D) D
. S ROW(NM)=DAY(D),X=0
. S:DAYS(D) X=DAY(D)/(24*DAYS(D))
. S AVG(NM)=$$ROUND(X)
. S ROW=ROW_TAB_ROW(NM) ;CSV
. S AVG=AVG_TAB_AVG(NM) ;CSV
S ROW("total")=CNT,ROW("average")=$$ROUND(CNT/DAYS)
S ROW=ROW_TAB_ROW("total")_TAB_ROW("average")
I $G(CSV) D BLANK^EDPCSV,ADD^EDPCSV(ROW),ADD^EDPCSV(AVG) Q
S X=$$XMLA^EDPX("row",.ROW) D XML^EDPX(X)
S X=$$XMLA^EDPX("row",.AVG) D XML^EDPX(X)
D XML^EDPX("</averages>")
Q
;
INIT ; Initialize counters and sums
N H,D S CNT=0
F H=0:1:23 S HR(H)=0 F D=0:1:6 S CNT(H,D)=0
F D=0:1:6 S DAY(D)=0,DAYS(D)=0
S DAYS=$$FMDIFF^XLFDT(END,BEG)+1
Q
;
ROUND(X) ; Round X to one decimal place
N Y1,Y2,Y S X=+$G(X)
S Y1=+$P(X,"."),Y2=$E($P(X,".",2)_"00",1,2)
S:$E(Y2,2)'>4 Y2=+$E(Y2) I $E(Y2,2)>4 D
. I $E(Y2)=9 S Y1=Y1+1,Y2=0 Q
. S Y2=$E(Y2)+1
S Y=Y1_"."_Y2
Q Y
;
ZROUND(X) ; Round X to nearest integer
N Y S Y=+$E($P(X,".",2)),X=X\1
S:Y>4 X=X+1
Q X
;
TIME(X) ; Return 0000 form of hour# X
N Y S Y=$S($L(X)=1:"0"_X,1:X)_"00"
Q Y
;
NAME(X) ; Return name of day# X
I X=1 Q "Monday"
I X=2 Q "Tuesday"
I X=3 Q "Wednesday"
I X=4 Q "Thursday"
I X=5 Q "Friday"
I X=6 Q "Saturday"
Q "Sunday"
--- Routine Detail --- with STRUCTURED ROUTINE LISTING ---[H[J[2J[HEDPRPT11 2641 printed Dec 13, 2024@01:52:18 Page 2
EDPRPT11 ;SLC/MKB - Patient Intake Report ;2/28/12 08:33am
+1 ;;2.0;EMERGENCY DEPARTMENT;;May 2, 2012;Build 103
+2 ;
CNT(BEG,END,CSV) ; Get Patient Intake Report for EDPSITE by date range
+1 ; CNT = counters
+2 NEW IN,LOG,LAST,X,CNT,HR,DAY,%H,%T,%Y,H,D,ROW,AVG,NM,TAB,DAYS
+3 ;set counters to 0
DO INIT
SET LAST=""
+4 SET IN=BEG-.000001
SET TAB=$CHAR(9)
+5 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
+6 SET X=$PIECE($GET(^EDP(230,LOG,0)),U,8)
if X<1
QUIT
+7 DO H^%DTC
SET H=%T\3600
SET D=%Y
+8 SET CNT=CNT+1
SET HR(H)=HR(H)+1
SET CNT(H,D)=CNT(H,D)+1
+9 SET DAY(D)=DAY(D)+1
+10 IF LAST=""!($PIECE(LAST,".")'=$PIECE(IN,"."))
SET DAYS(D)=DAYS(D)+1
SET LAST=IN
End DoDot:1
C1 ; return counts and averages
+1 ;headers
if '$GET(CSV)
DO XML^EDPX("<averages>")
IF $GET(CSV)
Begin DoDot:1
+2 SET X="Time/Day"_TAB_"Sunday"_TAB_"Monday"_TAB_"Tuesday"_TAB_"Wednesday"_TAB_"Thursday"_TAB_"Friday"_TAB_"Saturday"_TAB_"Totals"_TAB_"Avg/Day"
+3 DO ADD^EDPCSV(X)
DO BLANK^EDPCSV
End DoDot:1
+4 FOR H=0:1:23
Begin DoDot:1
+5 KILL ROW
SET ROW("time")=$$TIME(H)_"-"_$$TIME(H+1)
+6 ;CSV
SET ROW=ROW("time")
+7 FOR D=0:1:6
SET NM=$$NAME(D)
Begin DoDot:2
+8 SET ROW(NM)=CNT(H,D)
+9 ;CSV
SET ROW=ROW_TAB_ROW(NM)
End DoDot:2
+10 SET ROW("total")=HR(H)
SET ROW("average")=$$ROUND(HR(H)/DAYS)
+11 IF '$GET(CSV)
SET X=$$XMLA^EDPX("row",.ROW)
DO XML^EDPX(X)
QUIT
+12 SET ROW=ROW_TAB_ROW("total")_TAB_ROW("average")
DO ADD^EDPCSV(ROW)
End DoDot:1
+13 ; total & average rows
+14 KILL ROW
SET ROW("time")="Totals"
SET ROW=ROW("time")
+15 SET AVG("time")="Avg/Hour"
SET AVG=AVG("time")
+16 FOR D=0:1:6
SET NM=$$NAME(D)
Begin DoDot:1
+17 SET ROW(NM)=DAY(D)
SET X=0
+18 if DAYS(D)
SET X=DAY(D)/(24*DAYS(D))
+19 SET AVG(NM)=$$ROUND(X)
+20 ;CSV
SET ROW=ROW_TAB_ROW(NM)
+21 ;CSV
SET AVG=AVG_TAB_AVG(NM)
End DoDot:1
+22 SET ROW("total")=CNT
SET ROW("average")=$$ROUND(CNT/DAYS)
+23 SET ROW=ROW_TAB_ROW("total")_TAB_ROW("average")
+24 IF $GET(CSV)
DO BLANK^EDPCSV
DO ADD^EDPCSV(ROW)
DO ADD^EDPCSV(AVG)
QUIT
+25 SET X=$$XMLA^EDPX("row",.ROW)
DO XML^EDPX(X)
+26 SET X=$$XMLA^EDPX("row",.AVG)
DO XML^EDPX(X)
+27 DO XML^EDPX("</averages>")
+28 QUIT
+29 ;
INIT ; Initialize counters and sums
+1 NEW H,D
SET CNT=0
+2 FOR H=0:1:23
SET HR(H)=0
FOR D=0:1:6
SET CNT(H,D)=0
+3 FOR D=0:1:6
SET DAY(D)=0
SET DAYS(D)=0
+4 SET DAYS=$$FMDIFF^XLFDT(END,BEG)+1
+5 QUIT
+6 ;
ROUND(X) ; Round X to one decimal place
+1 NEW Y1,Y2,Y
SET X=+$GET(X)
+2 SET Y1=+$PIECE(X,".")
SET Y2=$EXTRACT($PIECE(X,".",2)_"00",1,2)
+3 if $EXTRACT(Y2,2)'>4
SET Y2=+$EXTRACT(Y2)
IF $EXTRACT(Y2,2)>4
Begin DoDot:1
+4 IF $EXTRACT(Y2)=9
SET Y1=Y1+1
SET Y2=0
QUIT
+5 SET Y2=$EXTRACT(Y2)+1
End DoDot:1
+6 SET Y=Y1_"."_Y2
+7 QUIT Y
+8 ;
ZROUND(X) ; Round X to nearest integer
+1 NEW Y
SET Y=+$EXTRACT($PIECE(X,".",2))
SET X=X\1
+2 if Y>4
SET X=X+1
+3 QUIT X
+4 ;
TIME(X) ; Return 0000 form of hour# X
+1 NEW Y
SET Y=$SELECT($LENGTH(X)=1:"0"_X,1:X)_"00"
+2 QUIT Y
+3 ;
NAME(X) ; Return name of day# X
+1 IF X=1
QUIT "Monday"
+2 IF X=2
QUIT "Tuesday"
+3 IF X=3
QUIT "Wednesday"
+4 IF X=4
QUIT "Thursday"
+5 IF X=5
QUIT "Friday"
+6 IF X=6
QUIT "Saturday"
+7 QUIT "Sunday"