AMEROUT4 ; IHS/ANMC/GIS - HOURLY WORKLOAD REPORTS ;
;;3.0;ER VISIT SYSTEM;;FEB 23, 2009
;
NEW N X,Y,Z,%,AMERHSRT,DN1,DN2,DDB,AMERFLTR S AMERFLTR=0
K ^TMP("AMER HOUR",$J),^TMP("AMER HF",$J),^TMP("AMER PRINT",$J)
RUN D SORT I $D(AMERQUIT) G EXIT
D FILTER^AMEROUT5 I $D(AMERQUIT) G EXIT
;
; Allow user to pick a shift to report on
S AMERSHFT=$$SHIFT()
I AMERSHFT'=-1 D
.D GET(AMERSHFT)
.D SUBTOT(AMERSHFT)
.D FORMAT(AMERSHFT)
.D ZIS^AMEROUT5
.Q
;
EXIT ;ENTRY POINT FROM AMEROUT5
K ^TMP("AMER HOUR",$J),^TMP("AMER TOT",$J),^TMP("AMER PRINT",$J)
Q
;
SORT ; SORT BY PROVIDER?
S DIR(0)="SO^1:SORT BY A SPECIFIC PROVIDER;2:SORT BY ALL PROVIDERS;3:DO NOT SORT BY PROVIDER",DIR("A")="Sort option",DIR("?")="",DIR("B")=3 D ^DIR K DIR
D OUT^AMEROUT I $D(AMERQUIT) Q
I Y=3 S AMERHSRT="" Q
I Y=2 S AMERHSRT=0 Q
N DIC S DIC="^VA(200,",DIC("A")="Enter PROVIDER NAME: ",DIC(0)="AEQM"
; Screen so only providers with key can be selected
S DIC("S")="I $D(^VA(200,""AK.PROVIDER"",$P($G(^VA(200,+Y,0)),U),+Y))"
D ^DIC,OUT^AMEROUT I $D(AMERQUIT) Q
I $G(Y)'>0 G SORT
S AMERHSRT=+Y
Q
;
GET(AMERSHFT) ; GET ENTRIES WITHIN THE SORT RANGES
N A,B,C,N,I,%,D,X,Y,Z
S D=$O(^AMERVSIT("B",AMERD1),-1),I=0
; Looking at every visit time stamp, quitting if the time stamp is bigger than end date
F S D=$O(^AMERVSIT("B",D)) Q:'D Q:D>AMERD2 S N=0 F S N=$O(^AMERVSIT("B",D,N)) Q:'N S X=$G(^AMERVSIT(N,0)),Y=$G(^(6)) I X]"",Y]"" D
.I AMERHSRT,$P(Y,U,3)'=AMERHSRT Q
.; If we are sorting by provider, quit if this isn't the provider we are working with right now
.S %=+X
.; quit if this isn't the time range we are working with
.I $P(AMERSHFT,U,1)>+$E($P(%,".",2),1,2) Q
.I +$E($P(%,".",2),1,2)>$P(AMERSHFT,U,2) Q
.S I=I+1
.S A("TIME")=+$E($P(%,".",2),1,2),A("DAY")=$P(%,"."),%=$P(X,U,17),A("AGE")="" I % S A("AGE")=(%<14)
.S A("ETOH")=+$P($G(^AMERVSIT(N,11)),U)
.S A("TRAUMA")=($P($G(^AMERVSIT(N,3)),U)>0)
.S A("PRV")=$P(Y,U,3) I A("PRV")="" Q ; MISSING PROVIDER
.S A("P TIME")=$P($G(^AMERVSIT(N,12)),U,3),A("T TIME")=$P($G(^(12)),U,4)
.I AMERFLTR D
..S %=A("P TIME") I %,%>240 S A("P TIME")=""
..S %=A("T TIME") I %,%<-5,%>120 S A("T TIME")=""
..Q
.S %=A("AGE")_U_A("ETOH")_U_A("TRAUMA")_U_A("T TIME")_U_A("P TIME")
.S ^TMP("AMER HOUR",$J,$S(AMERHSRT="":0,1:A("PRV")),A("DAY"),A("TIME"),N)=%
.Q
Q
;
SUBTOT(AMERSHFT) ; COMPUTE THE HOURLY SUBTOTALS
N D,H,A,E,T,G,N,F,X,%,P,V,AMERPRV,AMERI
S G="^TMP(""AMER HOUR"",$J,AMERPRV)"
S AMERPRV="" F S AMERPRV=$O(@G) Q:AMERPRV="" S D=0 F S D=$O(@G@(D)) Q:'D D
.K F S AMERI=0
.; LOOP control modified to only total the selected shift
.F H=$P(AMERSHFT,U,1):1:$P(AMERSHFT,U,2) D
..;IF THERE IS SOMETHING FOR THIS DATE AT THIS HOUR SET F(H)
..I '$O(@G@(D,H,0)) S F(H)="" Q
..K P,V S (A,E,T,P,V,N,I)=0
..F S N=$O(@G@(D,H,N)) Q:'N S X=@G@(D,H,N) D
...S AMERI=AMERI+1,I=I+1
...S %=+X I % S A=A+1
...S %=$P(X,U,2) I % S E=E+1
...S %=$P(X,U,3) I % S T=T+1
...S %=$P(X,U,4) I % D
....S P=P+1
....I P=1 S P(0)=%,P(1)=%,P(2)=% Q
....S P(2)=P(2)+%
....I %<P(0) S P(0)=% Q
....I %>P(1) S P(1)=%
....Q
...S %=$P(X,U,5) I % D
....S V=V+1
....I V=1 S V(0)=%,V(1)=%,V(2)=% Q
....S V(2)=V(2)+%
....I %<V(0) S V(0)=% Q
....I %>V(1) S V(1)=%
....Q
...Q
..I P S %=P(2)/P,P(3)=$J(%,0,1)
..I V S %=V(2)/V,V(3)=$J(%,0,1)
..S %=I_U_A_U_E_U_T_U_$G(P(0))_U_$G(P(1))_U_$G(P(3))_U_$G(V(0))_U_$G(V(1))_U_$G(V(3))
..S F(H)=%
..Q
.S %=$S(AMERHSRT="":0,1:AMERPRV)
.M ^TMP("AMER TOT",$J,%,D)=F ;M(ERGE) command
.D TOTALS(AMERPRV,AMERI,D)
.Q
Q
;
TOTALS(P,J,D) ; GET TOTALS AND AVERAGES FOR A GIVEN PROVIDER-DAY
; 1=TOTAL,2=AGE<14,3=ETOH,4=TRAUMA,5=P MIN,6=P MAX,7=P AVE,8=T MIN,9=T MAX,10=T AVE
N X,H,%,I,T,J,K,L,M,R,Q
F I=1:1:10 S T(I)=0 I I>4 S T(I,0)=0
F I=11:1:16 S T(I)=""
S H="" F S H=$O(F(H)) Q:H="" S X=F(H) F I=1:1:10 I $P(X,U,I)]"" S T(I)=$P(X,U,I)+T(I) I I>4 S T(I,0)=T(I,0)+1
F I=5:1:10 S %=T(I,0) I % S %=T(I)/T(I,0),T(I+6)=$J(%,0,1)
S (J,K,L,M)=0,Q=""
F S Q=$O(^TMP("AMER HOUR",$J,P,D,Q)) Q:'Q S R=0 F S R=$O(^TMP("AMER HOUR",$J,P,D,Q,R)) Q:'R S Z=^(R),%=$P(Z,U,4) S:%]"" J=J+1,K=K+% S %=$P(Z,U,5) S:%]"" L=L+1,M=M+%
S T(13)="" I J S %=K/J,T(13)=$J(%,0,1)
S T(16)="" I L S %=M/L,T(16)=$J(%,0,1)
S ^TMP("AMER TOT",$J,P,D)=T(1)_U_T(2)_U_T(3)_U_T(4)_U_T(11)_U_T(12)_U_T(13)_U_T(14)_U_T(15)_U_T(16)
Q
;
FORMAT(AMERSHFT) ; CREATE FORMATTED OUTPUT AND STORE IN AN ARRAY
N A,B,C,X,Y,Z,%,I,J,H,L,S,OCXI
S OCXI=0
S A="VISIT TIME^# PTS^MINS TO TRIAGER ^MINS TO PROVIDER^AGE<14^ETOH^INJURY"
S B=0,J=0 F I=1:1:($L(A,U)-1) S X=$P(A,U,I),J=J+$L(X)+2,B=B_U_J
S C="" F I=1:1:$L(A,U) S X=$P(A,U,I) S:C]"" C=C_U S C=C_$L(X)
S H="" F I=1:1:$L(A,U) S:H]"" H=H_" " S H=H_$P(A,U,I)
S %="MIN MAX AVE"
S X="",$P(X," ",$P(B,U,3)+1)="" S Z=X_%_" "_%
S %="---- ---- ----"
S L="" F I=1:1:7 S X=$P(C,U,I) D
. I L]"" S L=L_" "
. I I=3!(I=4) S L=L_% Q
. S Y="",$P(Y,"-",X+1)="",L=L_Y
. Q
I $O(^TMP("AMER TOT",$J,0)) D F1(AMERSHFT) Q
D F2(0,AMERSHFT)
Q
;
INC(X) ; STORE A PRINTABLE LINE IN THE ARRAY
S OCXI=OCXI+1
S ^TMP("AMER PRINT",$J,OCXI)=X
Q
;
F2(P,AMERSHFT) ; DATE SORT
N A,D,X,T,Y S D=0
F S D=$O(^TMP("AMER TOT",$J,P,D)) Q:'D D
.S Y=D X ^DD("DD") D INC(Y),INC(H),INC(Z),INC(L)
.S T="" F S T=$O(^TMP("AMER TOT",$J,P,D,T)) Q:T="" S X=^(T) D
..I T=12 D
...D INC("<>")
...I $P($G(AMERSHFT),U,3)=0 D INC(H),INC(Z),INC(L)
..S A=$$HOUR(T)_" "_$J(+X,$P(C,U,2))_" "
..; Only print if not "daily"
..I X=""&$P($G(AMERSHFT),U,3)=0 D INC(A) Q
..F I=5:1:7 S %=$P(X,U,I) S:% %=%\1,%=$J(%,4),A=A_%_" "
..F I=8:1:10 S %=$P(X,U,I) S:% %=%\1,%=$J(%,4),A=A_%_" "
..F I=2:1:4 S %=$P(X,U,I),%=$J(%,$P(C,U,I+3)) S A=A_%_" "
..; Only print if not "daily"
..I $P($G(AMERSHFT),U,3)=0 D INC(A)
..Q
.D F3(P,D)
.Q
Q
;
F1(AMERSHFT) ; PROVIDER LOOP
N P S P=0
F S P=$O(^TMP("AMER TOT",$J,P)) Q:'P D:$O(^(P),-1) INC("<>") D INC($P(^VA(200,P,0),U)),F2(P,AMERSHFT)
Q
;
HOUR(X) ; CONVERT TIME TO HOUR RANGE
N Y,Z,%
I X=24 S X=0
S Y=X_"00" I $L(Y)=3 S Y="0"_Y
S Z=X_"59" I $L(Z)=3 S Z="0"_Z
S %=Y_"-"_Z
Q %
;
F3(P,D) ; TOTALS
N X,Y,Z,%,A,I
S X=$G(^TMP("AMER TOT",$J,P,D)) I X="" Q
S A="TOTALS "_$J(+X,5)
S %="",$P(%," ",39)="",A=A_%
F I=2:1:4 S %=$P(X,U,I),%=$J(+%,$P(C,U,I+3))_" " S A=A_%
D INC(" "),INC(A)
S A="AVERAGES "
F I=5:1:10 S %=$P(X,U,I) S:%]"" %=%\1 S %=$J(%,4)_" " S A=A_%
D INC(A)
Q
;
SHIFT() ;Allow user to select "DAILY TOTALS ONLY"
; OR
; Allow a start and stop military hour to be selected
N DIR,AMERTEMP,AMERRTRN,AMERSHOW,Y
; If daily totals are desired return 24 hour shift and a flag and quit
S DIR("A")="Report daily totals only"
S DIR(0)="Y",DIR("B")="YES"
D ^DIR
I Y=1 S AMERRTRN="00^23^1" Q AMERRTRN
; Daily totals are not desired, so allow START and STOP hour to be selected
S DIR("B")=24
S DIR(0)="N^1:24:0",DIR("A")="Enter STARTING hour",DIR("?")="Enter a number between 1-24"
D ^DIR
I Y=""!(Y="^") S AMERRTRN=-1
E D
.S:Y=24 Y="00"
.S AMERRTRN=Y
.S AMERSHOW=Y_"00" I $L(AMERSHOW)=3 S AMERSHOW="0"_AMERSHOW
.Q
I AMERRTRN=-1 Q AMERRTRN
S DIR("B")=24
S DIR(0)="N^1:24:0",DIR("A")="Enter ENDING hour",DIR("?")="Enter a number between 1-24"
D ^DIR
I Y=""!(Y="^") S AMERRTRN=-1 Q AMERRTRN
E D
.S Y=Y-1
.S:Y=0 Y="00"
.S AMERRTRN=AMERRTRN_"^"_Y
.S AMERTEMP=Y_"59" I $L(AMERTEMP)=3 S AMERTEMP="0"_AMERTEMP
.S AMERSHOW=AMERSHOW_"^"_AMERTEMP
.Q
S AMERRTRN=AMERRTRN_"^0"
D EN^DDIOL("Reporting from: "_$P(AMERSHOW,U,1)_" to: "_$P(AMERSHOW,U,2),"","!!")
Q AMERRTRN
AMEROUT4 ; IHS/ANMC/GIS - HOURLY WORKLOAD REPORTS ;
+1 ;;3.0;ER VISIT SYSTEM;;FEB 23, 2009
+2 ;
NEW NEW X,Y,Z,%,AMERHSRT,DN1,DN2,DDB,AMERFLTR
SET AMERFLTR=0
+1 KILL ^TMP("AMER HOUR",$JOB),^TMP("AMER HF",$JOB),^TMP("AMER PRINT",$JOB)
RUN DO SORT
IF $DATA(AMERQUIT)
GOTO EXIT
+1 DO FILTER^AMEROUT5
IF $DATA(AMERQUIT)
GOTO EXIT
+2 ;
+3 ; Allow user to pick a shift to report on
+4 SET AMERSHFT=$$SHIFT()
+5 IF AMERSHFT'=-1
Begin DoDot:1
+6 DO GET(AMERSHFT)
+7 DO SUBTOT(AMERSHFT)
+8 DO FORMAT(AMERSHFT)
+9 DO ZIS^AMEROUT5
+10 QUIT
End DoDot:1
+11 ;
EXIT ;ENTRY POINT FROM AMEROUT5
+1 KILL ^TMP("AMER HOUR",$JOB),^TMP("AMER TOT",$JOB),^TMP("AMER PRINT",$JOB)
+2 QUIT
+3 ;
SORT ; SORT BY PROVIDER?
+1 SET DIR(0)="SO^1:SORT BY A SPECIFIC PROVIDER;2:SORT BY ALL PROVIDERS;3:DO NOT SORT BY PROVIDER"
SET DIR("A")="Sort option"
SET DIR("?")=""
SET DIR("B")=3
DO ^DIR
KILL DIR
+2 DO OUT^AMEROUT
IF $DATA(AMERQUIT)
QUIT
+3 IF Y=3
SET AMERHSRT=""
QUIT
+4 IF Y=2
SET AMERHSRT=0
QUIT
+5 NEW DIC
SET DIC="^VA(200,"
SET DIC("A")="Enter PROVIDER NAME: "
SET DIC(0)="AEQM"
+6 ; Screen so only providers with key can be selected
+7 SET DIC("S")="I $D(^VA(200,""AK.PROVIDER"",$P($G(^VA(200,+Y,0)),U),+Y))"
+8 DO ^DIC
DO OUT^AMEROUT
IF $DATA(AMERQUIT)
QUIT
+9 IF $GET(Y)'>0
GOTO SORT
+10 SET AMERHSRT=+Y
+11 QUIT
+12 ;
GET(AMERSHFT) ; GET ENTRIES WITHIN THE SORT RANGES
+1 NEW A,B,C,N,I,%,D,X,Y,Z
+2 SET D=$ORDER(^AMERVSIT("B",AMERD1),-1)
SET I=0
+3 ; Looking at every visit time stamp, quitting if the time stamp is bigger than end date
+4 FOR
SET D=$ORDER(^AMERVSIT("B",D))
IF 'D
QUIT
IF D>AMERD2
QUIT
SET N=0
FOR
SET N=$ORDER(^AMERVSIT("B",D,N))
IF 'N
QUIT
SET X=$GET(^AMERVSIT(N,0))
SET Y=$GET(^(6))
IF X]""
IF Y]""
Begin DoDot:1
+5 IF AMERHSRT
IF $PIECE(Y,U,3)'=AMERHSRT
QUIT
+6 ; If we are sorting by provider, quit if this isn't the provider we are working with right now
+7 SET %=+X
+8 ; quit if this isn't the time range we are working with
+9 IF $PIECE(AMERSHFT,U,1)>+$EXTRACT($PIECE(%,".",2),1,2)
QUIT
+10 IF +$EXTRACT($PIECE(%,".",2),1,2)>$PIECE(AMERSHFT,U,2)
QUIT
+11 SET I=I+1
+12 SET A("TIME")=+$EXTRACT($PIECE(%,".",2),1,2)
SET A("DAY")=$PIECE(%,".")
SET %=$PIECE(X,U,17)
SET A("AGE")=""
IF %
SET A("AGE")=(%<14)
+13 SET A("ETOH")=+$PIECE($GET(^AMERVSIT(N,11)),U)
+14 SET A("TRAUMA")=($PIECE($GET(^AMERVSIT(N,3)),U)>0)
+15 ; MISSING PROVIDER
SET A("PRV")=$PIECE(Y,U,3)
IF A("PRV")=""
QUIT
+16 SET A("P TIME")=$PIECE($GET(^AMERVSIT(N,12)),U,3)
SET A("T TIME")=$PIECE($GET(^(12)),U,4)
+17 IF AMERFLTR
Begin DoDot:2
+18 SET %=A("P TIME")
IF %
IF %>240
SET A("P TIME")=""
+19 SET %=A("T TIME")
IF %
IF %<-5
IF %>120
SET A("T TIME")=""
+20 QUIT
End DoDot:2
+21 SET %=A("AGE")_U_A("ETOH")_U_A("TRAUMA")_U_A("T TIME")_U_A("P TIME")
+22 SET ^TMP("AMER HOUR",$JOB,$SELECT(AMERHSRT="":0,1:A("PRV")),A("DAY"),A("TIME"),N)=%
+23 QUIT
End DoDot:1
+24 QUIT
+25 ;
SUBTOT(AMERSHFT) ; COMPUTE THE HOURLY SUBTOTALS
+1 NEW D,H,A,E,T,G,N,F,X,%,P,V,AMERPRV,AMERI
+2 SET G="^TMP(""AMER HOUR"",$J,AMERPRV)"
+3 SET AMERPRV=""
FOR
SET AMERPRV=$ORDER(@G)
IF AMERPRV=""
QUIT
SET D=0
FOR
SET D=$ORDER(@G@(D))
IF 'D
QUIT
Begin DoDot:1
+4 KILL F
SET AMERI=0
+5 ; LOOP control modified to only total the selected shift
+6 FOR H=$PIECE(AMERSHFT,U,1):1:$PIECE(AMERSHFT,U,2)
Begin DoDot:2
+7 ;IF THERE IS SOMETHING FOR THIS DATE AT THIS HOUR SET F(H)
+8 IF '$ORDER(@G@(D,H,0))
SET F(H)=""
QUIT
+9 KILL P,V
SET (A,E,T,P,V,N,I)=0
+10 FOR
SET N=$ORDER(@G@(D,H,N))
IF 'N
QUIT
SET X=@G@(D,H,N)
Begin DoDot:3
+11 SET AMERI=AMERI+1
SET I=I+1
+12 SET %=+X
IF %
SET A=A+1
+13 SET %=$PIECE(X,U,2)
IF %
SET E=E+1
+14 SET %=$PIECE(X,U,3)
IF %
SET T=T+1
+15 SET %=$PIECE(X,U,4)
IF %
Begin DoDot:4
+16 SET P=P+1
+17 IF P=1
SET P(0)=%
SET P(1)=%
SET P(2)=%
QUIT
+18 SET P(2)=P(2)+%
+19 IF %<P(0)
SET P(0)=%
QUIT
+20 IF %>P(1)
SET P(1)=%
+21 QUIT
End DoDot:4
+22 SET %=$PIECE(X,U,5)
IF %
Begin DoDot:4
+23 SET V=V+1
+24 IF V=1
SET V(0)=%
SET V(1)=%
SET V(2)=%
QUIT
+25 SET V(2)=V(2)+%
+26 IF %<V(0)
SET V(0)=%
QUIT
+27 IF %>V(1)
SET V(1)=%
+28 QUIT
End DoDot:4
+29 QUIT
End DoDot:3
+30 IF P
SET %=P(2)/P
SET P(3)=$JUSTIFY(%,0,1)
+31 IF V
SET %=V(2)/V
SET V(3)=$JUSTIFY(%,0,1)
+32 SET %=I_U_A_U_E_U_T_U_$GET">GET">GET">GET">GET">GET">GET">GET">GET">GET">GET">GET">GET">GET">GET">GET">GET">GET">GET">GET">GET">GET">GET">GET">GET">GET">GET">GET">GET">GET">GET">GET(P(0))_U_$GET">GET">GET">GET">GET">GET">GET">GET">GET">GET">GET">GET">GET">GET">GET">GET">GET">GET">GET">GET">GET">GET">GET">GET">GET">GET">GET">GET">GET">GET">GET">GET(P(1))_U_$GET">GET">GET">GET">GET">GET">GET">GET">GET">GET">GET">GET">GET">GET">GET">GET">GET">GET">GET">GET">GET">GET">GET">GET">GET">GET">GET">GET">GET">GET">GET">GET(P(3))_U_$GET">GET">GET">GET">GET">GET">GET">GET">GET">GET">GET">GET">GET">GET">GET">GET">GET">GET">GET">GET">GET">GET">GET">GET">GET">GET">GET">GET">GET">GET">GET">GET(V(0))_U_$GET">GET">GET">GET">GET">GET">GET">GET">GET">GET">GET">GET">GET">GET">GET">GET">GET">GET">GET">GET">GET">GET">GET">GET">GET">GET">GET">GET">GET">GET">GET">GET(V(1))_U_$GET">GET">GET">GET">GET">GET">GET">GET">GET">GET">GET">GET">GET">GET">GET">GET">GET">GET">GET">GET">GET">GET">GET">GET">GET">GET">GET">GET">GET">GET">GET">GET(V(3))
+33 SET F(H)=%
+34 QUIT
End DoDot:2
+35 SET %=$SELECT(AMERHSRT="":0,1:AMERPRV)
+36 ;M(ERGE) command
MERGE ^TMP("AMER TOT",$JOB,%,D)=F
+37 DO TOTALS(AMERPRV,AMERI,D)
+38 QUIT
End DoDot:1
+39 QUIT
+40 ;
TOTALS(P,J,D) ; GET TOTALS AND AVERAGES FOR A GIVEN PROVIDER-DAY
+1 ; 1=TOTAL,2=AGE<14,3=ETOH,4=TRAUMA,5=P MIN,6=P MAX,7=P AVE,8=T MIN,9=T MAX,10=T AVE
+2 NEW X,H,%,I,T,J,K,L,M,R,Q
+3 FOR I=1:1:10
SET T(I)=0
IF I>4
SET T(I,0)=0
+4 FOR I=11:1:16
SET T(I)=""
+5 SET H=""
FOR
SET H=$ORDER(F(H))
IF H=""
QUIT
SET X=F(H)
FOR I=1:1:10
IF $PIECE(X,U,I)]""
SET T(I)=$PIECE(X,U,I)+T(I)
IF I>4
SET T(I,0)=T(I,0)+1
+6 FOR I=5:1:10
SET %=T(I,0)
IF %
SET %=T(I)/T(I,0)
SET T(I+6)=$JUSTIFY(%,0,1)
+7 SET (J,K,L,M)=0
SET Q=""
+8 FOR
SET Q=$ORDER(^TMP("AMER HOUR",$JOB,P,D,Q))
IF 'Q
QUIT
SET R=0
FOR
SET R=$ORDER(^TMP("AMER HOUR",$JOB,P,D,Q,R))
IF 'R
QUIT
SET Z=^(R)
SET %=$PIECE(Z,U,4)
IF %]""
SET J=J+1
SET K=K+%
SET %=$PIECE(Z,U,5)
IF %]""
SET L=L+1
SET M=M+%
+9 SET T(13)=""
IF J
SET %=K/J
SET T(13)=$JUSTIFY(%,0,1)
+10 SET T(16)=""
IF L
SET %=M/L
SET T(16)=$JUSTIFY(%,0,1)
+11 SET ^TMP("AMER TOT",$JOB,P,D)=T(1)_U_T(2)_U_T(3)_U_T(4)_U_T(11)_U_T(12)_U_T(13)_U_T(14)_U_T(15)_U_T(16)
+12 QUIT
+13 ;
FORMAT(AMERSHFT) ; CREATE FORMATTED OUTPUT AND STORE IN AN ARRAY
+1 NEW A,B,C,X,Y,Z,%,I,J,H,L,S,OCXI
+2 SET OCXI=0
+3 SET A="VISIT TIME^# PTS^MINS TO TRIAGER ^MINS TO PROVIDER^AGE<14^ETOH^INJURY"
+4 SET B=0
SET J=0
FOR I=1:1:($LENGTH(A,U)-1)
SET X=$PIECE(A,U,I)
SET J=J+$LENGTH(X)+2
SET B=B_U_J
+5 SET C=""
FOR I=1:1:$LENGTH(A,U)
SET X=$PIECE(A,U,I)
IF C]""
SET C=C_U
SET C=C_$LENGTH(X)
+6 SET H=""
FOR I=1:1:$LENGTH(A,U)
IF H]""
SET H=H_" "
SET H=H_$PIECE(A,U,I)
+7 SET %="MIN MAX AVE"
+8 SET X=""
SET $PIECE(X," ",$PIECE(B,U,3)+1)=""
SET Z=X_%_" "_%
+9 SET %="---- ---- ----"
+10 SET L=""
FOR I=1:1:7
SET X=$PIECE(C,U,I)
Begin DoDot:1
+11 IF L]""
SET L=L_" "
+12 IF I=3!(I=4)
SET L=L_%
QUIT
+13 SET Y=""
SET $PIECE(Y,"-",X+1)=""
SET L=L_Y
+14 QUIT
End DoDot:1
+15 IF $ORDER(^TMP("AMER TOT",$JOB,0))
DO F1(AMERSHFT)
QUIT
+16 DO F2(0,AMERSHFT)
+17 QUIT
+18 ;
INC(X) ; STORE A PRINTABLE LINE IN THE ARRAY
+1 SET OCXI=OCXI+1
+2 SET ^TMP("AMER PRINT",$JOB,OCXI)=X
+3 QUIT
+4 ;
F2(P,AMERSHFT) ; DATE SORT
+1 NEW A,D,X,T,Y
SET D=0
+2 FOR
SET D=$ORDER(^TMP("AMER TOT",$JOB,P,D))
IF 'D
QUIT
Begin DoDot:1
+3 SET Y=D
XECUTE ^DD("DD")
DO INC(Y)
DO INC(H)
DO INC(Z)
DO INC(L)
+4 SET T=""
FOR
SET T=$ORDER(^TMP("AMER TOT",$JOB,P,D,T))
IF T=""
QUIT
SET X=^(T)
Begin DoDot:2
+5 IF T=12
Begin DoDot:3
+6 DO INC("<>")
+7 IF $PIECE($GET(AMERSHFT),U,3)=0
DO INC(H)
DO INC(Z)
DO INC(L)
End DoDot:3
+8 SET A=$$HOUR(T)_" "_$JUSTIFY(+X,$PIECE(C,U,2))_" "
+9 ; Only print if not "daily"
+10 IF X=""&$PIECE($GET(AMERSHFT),U,3)=0
DO INC(A)
QUIT
+11 FOR I=5:1:7
SET %=$PIECE(X,U,I)
IF %
SET %=%\1
SET %=$JUSTIFY(%,4)
SET A=A_%_" "
+12 FOR I=8:1:10
SET %=$PIECE(X,U,I)
IF %
SET %=%\1
SET %=$JUSTIFY(%,4)
SET A=A_%_" "
+13 FOR I=2:1:4
SET %=$PIECE(X,U,I)
SET %=$JUSTIFY(%,$PIECE(C,U,I+3))
SET A=A_%_" "
+14 ; Only print if not "daily"
+15 IF $PIECE($GET(AMERSHFT),U,3)=0
DO INC(A)
+16 QUIT
End DoDot:2
+17 DO F3(P,D)
+18 QUIT
End DoDot:1
+19 QUIT
+20 ;
F1(AMERSHFT) ; PROVIDER LOOP
+1 NEW P
SET P=0
+2 FOR
SET P=$ORDER(^TMP("AMER TOT",$JOB,P))
IF 'P
QUIT
IF $ORDER(^(P),-1)
DO INC("<>")
DO INC($PIECE(^VA(200,P,0),U))
DO F2(P,AMERSHFT)
+3 QUIT
+4 ;
HOUR(X) ; CONVERT TIME TO HOUR RANGE
+1 NEW Y,Z,%
+2 IF X=24
SET X=0
+3 SET Y=X_"00"
IF $LENGTH(Y)=3
SET Y="0"_Y
+4 SET Z=X_"59"
IF $LENGTH(Z)=3
SET Z="0"_Z
+5 SET %=Y_"-"_Z
+6 QUIT %
+7 ;
F3(P,D) ; TOTALS
+1 NEW X,Y,Z,%,A,I
+2 SET X=$GET(^TMP("AMER TOT",$JOB,P,D))
IF X=""
QUIT
+3 SET A="TOTALS "_$JUSTIFY(+X,5)
+4 SET %=""
SET $PIECE(%," ",39)=""
SET A=A_%
+5 FOR I=2:1:4
SET %=$PIECE(X,U,I)
SET %=$JUSTIFY(+%,$PIECE(C,U,I+3))_" "
SET A=A_%
+6 DO INC(" ")
DO INC(A)
+7 SET A="AVERAGES "
+8 FOR I=5:1:10
SET %=$PIECE(X,U,I)
IF %]""
SET %=%\1
SET %=$JUSTIFY(%,4)_" "
SET A=A_%
+9 DO INC(A)
+10 QUIT
+11 ;
SHIFT() ;Allow user to select "DAILY TOTALS ONLY"
+1 ; OR
+2 ; Allow a start and stop military hour to be selected
+3 NEW DIR,AMERTEMP,AMERRTRN,AMERSHOW,Y
+4 ; If daily totals are desired return 24 hour shift and a flag and quit
+5 SET DIR("A")="Report daily totals only"
+6 SET DIR(0)="Y"
SET DIR("B")="YES"
+7 DO ^DIR
+8 IF Y=1
SET AMERRTRN="00^23^1"
QUIT AMERRTRN
+9 ; Daily totals are not desired, so allow START and STOP hour to be selected
+10 SET DIR("B")=24
+11 SET DIR(0)="N^1:24:0"
SET DIR("A")="Enter STARTING hour"
SET DIR("?")="Enter a number between 1-24"
+12 DO ^DIR
+13 IF Y=""!(Y="^")
SET AMERRTRN=-1
+14 IF '$TEST
Begin DoDot:1
+15 IF Y=24
SET Y="00"
+16 SET AMERRTRN=Y
+17 SET AMERSHOW=Y_"00"
IF $LENGTH(AMERSHOW)=3
SET AMERSHOW="0"_AMERSHOW
+18 QUIT
End DoDot:1
+19 IF AMERRTRN=-1
QUIT AMERRTRN
+20 SET DIR("B")=24
+21 SET DIR(0)="N^1:24:0"
SET DIR("A")="Enter ENDING hour"
SET DIR("?")="Enter a number between 1-24"
+22 DO ^DIR
+23 IF Y=""!(Y="^")
SET AMERRTRN=-1
QUIT AMERRTRN
+24 IF '$TEST
Begin DoDot:1
+25 SET Y=Y-1
+26 IF Y=0
SET Y="00"
+27 SET AMERRTRN=AMERRTRN_"^"_Y
+28 SET AMERTEMP=Y_"59"
IF $LENGTH(AMERTEMP)=3
SET AMERTEMP="0"_AMERTEMP
+29 SET AMERSHOW=AMERSHOW_"^"_AMERTEMP
+30 QUIT
End DoDot:1
+31 SET AMERRTRN=AMERRTRN_"^0"
+32 DO EN^DDIOL("Reporting from: "_$PIECE(AMERSHOW,U,1)_" to: "_$PIECE(AMERSHOW,U,2),"","!!")
+33 QUIT AMERRTRN