FHSEL2 ; HISC/REL/NCA/FAI - Tabulate Patient Preferences ;10/29/04 7:19
;;5.5;DIETETICS;**5**;Jan 28, 2005;Build 53
;patch #5 - screen for cancelled guest meals.
S X="T",%DT="X" D ^%DT S DT=+Y
S FHP=$O(^FH(119.72,0)) I FHP'<1,$O(^FH(119.72,FHP))<1 S FHP=0 G D1
D0 R !!,"Select SERVICE POINT (or ALL): ",X:DTIME G:'$T!("^"[X) KIL D:X="all" TR^FH I X="ALL" S FHP=0
E K DIC S DIC="^FH(119.72,",DIC(0)="EMQ" D ^DIC G:Y<1 D0 S FHP=+Y
D1 R !!,"Tabulate By Menu Specific? N// ",D3:DTIME G:'$T!(D3="^") KIL
S:D3="" D3="N" S X=D3 D TR^FH S D3=X I $P("YES",D3,1)'="",$P("NO",D3,1)'="" W *7," Answer YES or NO" G D1
S D3=$E(D3,1) S:D3="Y" D3=D3="Y" I 'D3 S (D1,FHCY,FHDA)="" G R1
F1 S %DT("A")="Select Date: ",%DT="AEX" W ! D ^%DT G KIL:"^"[X!$D(DTOUT),F1:Y<1 S (X1,D1)=+Y
I D1
0)!(FHK1>D1) D
.F FHDFN=0:0 S FHDFN=$O(^FHPT("RM",FHK1,FHDFN)) Q:FHDFN'>0 D
..F FHKD=0:0 S FHKD=$O(^FHPT("RM",FHK1,FHDFN,FHKD)) Q:FHKD'>0 D
...S FHKDAT=^FHPT(FHDFN,"OP",FHKD,0)
...S (W1,FHW1)=$P(FHKDAT,U,3)
...S FHDIET=$P(FHKDAT,U,2),FHMEAL=$P(FHKDAT,U,4),FHSTAT=$P(FHKDAT,U,15)
...S:FHDIET="" FHDIET=$P(FHKDAT,U,7) S:FHDIET="" FHDIET=$P(FHKDAT,U,8)
...S:FHDIET="" FHDIET=$P(FHKDAT,U,9) S:FHDIET="" FHDIET=$P(FHKDAT,U,10)
...S:FHDIET="" FHDIET=$P(FHKDAT,U,11)
...I (FHMLSAV'="A"),(FHMEAL'=FHMLSAV) Q
...I FHSTAT="C" Q
...Q:'$D(^FH(119.6,FHW1,0))
...D W44
;next guest
F FHKD=D1:0 S FHKD=$O(^FHPT("GM",FHKD)) Q:(FHKD'>0)!(FHKD>(D1+1)) D
.F FHDFN=0:0 S FHDFN=$O(^FHPT("GM",FHKD,FHDFN)) Q:FHDFN'>0 D
..S FHKDAT=^FHPT(FHDFN,"GM",FHKD,0)
..S (W1,FHW1)=$P(FHKDAT,U,5)
..S FHDIET=$P(FHKDAT,U,6),FHMEAL=$P(FHKDAT,U,3)
..I $P(FHKDAT,U,9)="C" Q
..I (FHMLSAV'="A"),(FHMEAL'=FHMLSAV) Q
..Q:'$D(^FH(119.6,FHW1,0))
..D W44
;next SPECIAL
F FHKD=D1:0 S FHKD=$O(^FHPT("SM",FHKD)) Q:(FHKD'>0)!(FHKD>(D1+1)) D
.F FHDFN=0:0 S FHDFN=$O(^FHPT("SM",FHKD,FHDFN)) Q:FHDFN'>0 D
..S FHKDAT=^FHPT(FHDFN,"SM",FHKD,0)
..S (W1,FHW1)=$P(FHKDAT,U,3)
..S FHDIET=$P(FHKDAT,U,4),FHMEAL=$P(FHKDAT,U,9),FHSTAT=$P(FHKDAT,U,2)
..I (FHMLSAV'="A"),(FHMEAL'=FHMLSAV) Q
..I (FHSTAT="C")!(FHSTAT="D") Q
..Q:'$D(^FH(119.6,FHW1,0))
..D W44
;print report
G ^FHSEL3
KIL K ^TMP($J) G KILL^XUSCLEAN
W2 I $O(^FHPT("AW",WRD,0))<1 Q
F DFN=0:0 S DFN=$O(^FHPT("AW",WRD,DFN)) Q:DFN<1 S ADM=^(DFN) I ADM>0 D W3
Q
W3 S K2=0 Q:'$D(^FHPT(DFN,"A",ADM,0)) S X0=^(0)
S FHORD=$P(X0,"^",2),X1=$P(X0,"^",3) I FHORD<1 S A1=$O(^FHPT(DFN,"A",ADM,"AC",0)) Q:A1=""!(A1>NOW) D U1 Q:'FHORD G W4
I X1>1,X1'>TIM D U1 Q:'FHORD
I '$D(^FHPT(DFN,"A",ADM,"DI",FHORD,0)) D U1 Q:'FHORD
W4 S X=$G(^FHPT(DFN,"A",ADM,"DI",FHORD,0))
S TC=$P(X,"^",8) Q:TC="" S PD=$P(X,"^",13) Q:PD="" S:TC="D" TC="T" Q:'$D(S(TC)) S:D2[TC K2=1 S:K2 SP=S(TC)
S PD=$S('PD:"",$D(^FH(116.2,+PD,0)):$P(^(0),"^",2),1:"") Q:PD=""
I K2 F K=0:0 S K=$O(^FHPT(DFN,"P",K)) Q:K<1 S Z=^(K,0) D
.S FHMLZ2=$P(Z,U,2)
.I FHMLZ2'[MEAL Q
.S QTY=$P(Z,"^",3),Z=+Z
.Q:'$G(Z)
.S:'$D(^TMP($J,"P",Z,PD,SP)) ^TMP($J,"P",Z,PD,SP)=0 S ^(SP)=^(SP)+$S(QTY:QTY,1:1)
Q
;sets tmp global for outpatient data.
W44 S X=^FH(119.6,FHW1,0)
S (PD,TC)=""
S TC=$P(X,"^",5) S:TC="" TC=$P(X,U,6) Q:TC=""
I FHP,TC'=FHP Q
I $D(^FH(119.72,TC,0)) S SP=TC,TC=$P(^FH(119.72,TC,0),U,2)
S:$D(^FH(111,FHDIET,0)) PD=$P(^FH(111,FHDIET,0),U,5) Q:PD=""
S PD=$S('PD:"",$D(^FH(116.2,+PD,0)):$P(^(0),"^",2),1:"") Q:PD=""
F K=0:0 S K=$O(^FHPT(FHDFN,"P",K)) Q:K<1 S Z=^(K,0) D
.S FHMLZ2=$P(Z,U,2)
.I FHMLZ2'[MEAL Q
.S QTY=$P(Z,"^",3),Z=+Z
.Q:'$G(Z)
.S:'$D(^TMP($J,"P",Z,PD,SP)) ^TMP($J,"P",Z,PD,SP)=0 S ^(SP)=^(SP)+$S(QTY:QTY,1:1)
Q
D2 K S S D2=""
F L=5,6 S XX=$P(X,"^",L) I XX=FHP!('FHP) S:XX S($E("TC",L-4))=XX,D(XX)="",D2=D2_$E("TC",L-4)
Q
U1 S (A1,FHORD)=0 F K=0:0 S K=$O(^FHPT(DFN,"A",ADM,"AC",K)) Q:K<1!(K>TIM) S A1=K
Q:'A1 S X1=$P(^FHPT(DFN,"A",ADM,"AC",A1,0),"^",2) G U2:X1<1,U2:'$D(^FHPT(DFN,"A",ADM,"DI",X1,0)) S FHORD=X1 Q
U2 S X1="",A1=0
U3 S A1=$O(^FHPT(DFN,"A",ADM,"AC",A1)) G:A1="" U1 S X2=$P(^(A1,0),"^",2)
I X2<1 K ^FHPT(DFN,"A",ADM,"AC",A1) G U3
I '$D(^FHPT(DFN,"A",ADM,"DI",X2,0)) K ^FHPT(DFN,"A",ADM,"AC",A1) G U3
G U3