FHORD72 ; HISC/NCA - Diet Order Utilities (cont) ;12/4/00 10:36
;;5.5;DIETETICS;;Jan 28, 2005
ADD ; Add diet associated Standing Orders and Supplemental Feeding Menu
S PDFLG=0 Q:'X1 I $D(FHYES) Q:FHYES
N FHOR S FHOR=$P($G(^FHPT(FHDFN,"A",ADM,"DI",X1,0)),"^",2,6)
S X3="" F NX=0:0 S NX=$O(^FHPT(FHDFN,"A",ADM,"AC",NX)) Q:NX<1!(NX'<A1) S X3=$P(^(NX,0),"^",2)
G:X3=X1 KIL G:X3="" A1
I FHOR=$P($G(^FHPT(FHDFN,"A",ADM,"DI",X3,0)),"^",2,6) D IND
K N,P S LN=0
F K=0:0 S K=$O(^FHPT("ASP",FHDFN,ADM,K)) Q:K<1 S X=^FHPT(FHDFN,"A",ADM,"SP",K,0) I $P(X,"^",9)="Y" S M=$P(X,"^",3),M=$S(M="BNE":"A",1:$E(M,1)),N(M,K)=$P(X,"^",2,3)_"^"_$P(X,"^",8),LN=LN+1,P(LN,+N(M,K))=K_"^"_N(M,K)
F LN=1:1 Q:'$D(P(LN)) F Z=0:0 S Z=$O(P(LN,Z)) Q:Z<1 S SP=+Z D EN3^FHSPED
A1 S DPAT=$O(^FH(111.1,"AB",FHOR,0)) G:'DPAT A2 S LS=""
F M1="BS","NS","ES" F L=0:0 S L=$O(^FH(111.1,DPAT,M1,L)) Q:L<1 S X=$G(^(L,0)),SP=+$P(X,"^",1),MEAL=$E(M1,1),NUM=$S($P(X,"^",2):$P(X,"^",2),1:1)_"^Y" D SO
A2 S SF=$P($G(^FHPT(FHDFN,"A",ADM,0)),"^",7) G:'SF A3 S X=$G(^FHPT(FHDFN,"A",ADM,"SF",SF,0))
I $P(X,"^",4)=1!($P(X,"^",34)'="Y") G A4
D CAN^FHNO5
A3 G:'DPAT A4
S NM=$P($G(^FH(111.1,DPAT,0)),"^",8) G:'NM A4
S PNO=$G(^FH(118.1,NM,1)) G:PNO="" A4
S PNN="^"_NOW_"^"_DUZ_"^"_NM_"^"_PNO,NO="" D SF
A4 D UPD^FHMTK7
KIL K COM,DPAT,EVT,FP,L,LN,LP,LS,M,M1,M2,MEAL,N,NM,NO,NUM,NX,OPAT,P,PP,PNN,PNO,R1,SF,SP,X3,^TMP($J),Z
Q
SO ; Add Standing Order
L +^FHPT(FHDFN,"A",ADM,"SP",0)
I '$D(^FHPT(FHDFN,"A",ADM,"SP",0)) S ^FHPT(FHDFN,"A",ADM,"SP",0)="^115.08^^"
S X=^FHPT(FHDFN,"A",ADM,"SP",0),NO=$P(X,"^",3)+1,^(0)=$P(X,"^",1,2)_"^"_NO_"^"_($P(X,"^",4)+1)
L -^FHPT(FHDFN,"A",ADM,"SP",0) I $D(^FHPT(FHDFN,"A",ADM,"SP",NO)) G SO
S ^FHPT(FHDFN,"A",ADM,"SP",NO,0)=NO_"^"_SP_"^"_MEAL_"^"_NOW_"^"_DUZ_"^^^"_NUM,^FHPT("ASP",FHDFN,ADM,NO)="",LS=LS_NO_","
S EVT="S^O^"_NO D ^FHORX Q
SF ; Add Supplemental Feeding
L +^FHPT(FHDFN,"A",ADM,"SF",0)
I '$D(^FHPT(FHDFN,"A",ADM,"SF",0)) S ^FHPT(FHDFN,"A",ADM,"SF",0)="^115.07^^"
S X=^FHPT(FHDFN,"A",ADM,"SF",0),NO=$P(X,"^",3)+1,^(0)=$P(X,"^",1,2)_"^"_NO_"^"_($P(X,"^",4)+1)
L -^FHPT(FHDFN,"A",ADM,"SF",0) I $D(^FHPT(FHDFN,"A",ADM,"SF",NO)) G SF
S ^FHPT(FHDFN,"A",ADM,"SF",NO,0)=NO_"^"_$P(PNN,"^",2,99)
S $P(^FHPT(FHDFN,"A",ADM,0),"^",7)=NO
I NO'="" S EVT="F^O^"_NO D ^FHORX ;file event, P30
UPD S:NO $P(^FHPT(FHDFN,"A",ADM,"SF",NO,0),"^",30,31)=NOW_"^"_DUZ
S:NO $P(^FHPT(FHDFN,"A",ADM,"SF",NO,0),"^",34)="Y" Q
IND ; Restore Individual Pattern
Q:'$D(^FHPT(FHDFN,"A",ADM,"DI",X3,2))
S ^FHPT(FHDFN,"A",ADM,"DI",X1,2)=$G(^FHPT(FHDFN,"A",ADM,"DI",X3,2))
S $P(^FHPT(FHDFN,"A",ADM,"DI",X1,3),"^",1,2)=DUZ_"^"_NOW
I $P(^FHPT(FHDFN,"A",ADM,"DI",X3,0),"^",13) S $P(^FHPT(FHDFN,"A",ADM,"DI",X1,0),"^",13)=$P(^FHPT(FHDFN,"A",ADM,"DI",X3,0),"^",13),PDFLG=1
Q
FHORD72 ; HISC/NCA - Diet Order Utilities (cont) ;12/4/00 10:36
+1 ;;5.5;DIETETICS;;Jan 28, 2005
ADD ; Add diet associated Standing Orders and Supplemental Feeding Menu
+1 SET PDFLG=0
IF 'X1
QUIT
IF $DATA(FHYES)
IF FHYES
QUIT
+2 NEW FHOR
SET FHOR=$PIECE($GET(^FHPT(FHDFN,"A",ADM,"DI",X1,0)),"^",2,6)
+3 SET X3=""
FOR NX=0:0
SET NX=$ORDER(^FHPT(FHDFN,"A",ADM,"AC",NX))
IF NX<1!(NX'<A1)
QUIT
SET X3=$PIECE(^(NX,0),"^",2)
+4 IF X3=X1
GOTO KIL
IF X3=""
GOTO A1
+5 IF FHOR=$PIECE($GET(^FHPT(FHDFN,"A",ADM,"DI",X3,0)),"^",2,6)
DO IND
+6 KILL N,P
SET LN=0
+7 FOR K=0:0
SET K=$ORDER(^FHPT("ASP",FHDFN,ADM,K))
IF K<1
QUIT
SET X=^FHPT(FHDFN,"A",ADM,"SP",K,0)
IF $PIECE(X,"^",9)="Y"
SET M=$PIECE(X,"^",3)
SET M=$SELECT(M="BNE":"A",1:$EXTRACT(M,1))
SET N(M,K)=$PIECE(X,"^",2,3)_"^"_$PIECE(X,"^",8)
SET LN=LN+1
SET P(LN,+N(M,K))=K_"^"_N(M,K)
+8 FOR LN=1:1
IF '$DATA(P(LN))
QUIT
FOR Z=0:0
SET Z=$ORDER(P(LN,Z))
IF Z<1
QUIT
SET SP=+Z
DO EN3^FHSPED
A1 SET DPAT=$ORDER(^FH(111.1,"AB",FHOR,0))
IF 'DPAT
GOTO A2
SET LS=""
+1 FOR M1="BS","NS","ES"
FOR L=0:0
SET L=$ORDER(^FH(111.1,DPAT,M1,L))
IF L<1
QUIT
SET X=$GET(^(L,0))
SET SP=+$PIECE(X,"^",1)
SET MEAL=$EXTRACT(M1,1)
SET NUM=$SELECT($PIECE(X,"^",2):$PIECE(X,"^",2),1:1)_"^Y"
DO SO
A2 SET SF=$PIECE($GET(^FHPT(FHDFN,"A",ADM,0)),"^",7)
IF 'SF
GOTO A3
SET X=$GET(^FHPT(FHDFN,"A",ADM,"SF",SF,0))
+1 IF $PIECE(X,"^",4)=1!($PIECE(X,"^",34)'="Y")
GOTO A4
+2 DO CAN^FHNO5
A3 IF 'DPAT
GOTO A4
+1 SET NM=$PIECE($GET(^FH(111.1,DPAT,0)),"^",8)
IF 'NM
GOTO A4
+2 SET PNO=$GET(^FH(118.1,NM,1))
IF PNO=""
GOTO A4
+3 SET PNN="^"_NOW_"^"_DUZ_"^"_NM_"^"_PNO
SET NO=""
DO SF
A4 DO UPD^FHMTK7
KIL KILL COM,DPAT,EVT,FP,L,LN,LP,LS,M,M1,M2,MEAL,N,NM,NO,NUM,NX,OPAT,P,PP,PNN,PNO,R1,SF,SP,X3,^TMP($JOB),Z
+1 QUIT
SO ; Add Standing Order
+1 LOCK +^FHPT(FHDFN,"A",ADM,"SP",0)
+2 IF '$DATA(^FHPT(FHDFN,"A",ADM,"SP",0))
SET ^FHPT(FHDFN,"A",ADM,"SP",0)="^115.08^^"
+3 SET X=^FHPT(FHDFN,"A",ADM,"SP",0)
SET NO=$PIECE(X,"^",3)+1
SET ^(0)=$PIECE(X,"^",1,2)_"^"_NO_"^"_($PIECE(X,"^",4)+1)
+4 LOCK -^FHPT(FHDFN,"A",ADM,"SP",0)
IF $DATA(^FHPT(FHDFN,"A",ADM,"SP",NO))
GOTO SO
+5 SET ^FHPT(FHDFN,"A",ADM,"SP",NO,0)=NO_"^"_SP_"^"_MEAL_"^"_NOW_"^"_DUZ_"^^^"_NUM
SET ^FHPT("ASP",FHDFN,ADM,NO)=""
SET LS=LS_NO_","
+6 SET EVT="S^O^"_NO
DO ^FHORX
QUIT
SF ; Add Supplemental Feeding
+1 LOCK +^FHPT(FHDFN,"A",ADM,"SF",0)
+2 IF '$DATA(^FHPT(FHDFN,"A",ADM,"SF",0))
SET ^FHPT(FHDFN,"A",ADM,"SF",0)="^115.07^^"
+3 SET X=^FHPT(FHDFN,"A",ADM,"SF",0)
SET NO=$PIECE(X,"^",3)+1
SET ^(0)=$PIECE(X,"^",1,2)_"^"_NO_"^"_($PIECE(X,"^",4)+1)
+4 LOCK -^FHPT(FHDFN,"A",ADM,"SF",0)
IF $DATA(^FHPT(FHDFN,"A",ADM,"SF",NO))
GOTO SF
+5 SET ^FHPT(FHDFN,"A",ADM,"SF",NO,0)=NO_"^"_$PIECE(PNN,"^",2,99)
+6 SET $PIECE(^FHPT(FHDFN,"A",ADM,0),"^",7)=NO
+7 ;file event, P30
IF NO'=""
SET EVT="F^O^"_NO
DO ^FHORX
UPD IF NO
SET $PIECE(^FHPT(FHDFN,"A",ADM,"SF",NO,0),"^",30,31)=NOW_"^"_DUZ
+1 IF NO
SET $PIECE(^FHPT(FHDFN,"A",ADM,"SF",NO,0),"^",34)="Y"
QUIT
IND ; Restore Individual Pattern
+1 IF '$DATA(^FHPT(FHDFN,"A",ADM,"DI",X3,2))
QUIT
+2 SET ^FHPT(FHDFN,"A",ADM,"DI",X1,2)=$GET(^FHPT(FHDFN,"A",ADM,"DI",X3,2))
+3 SET $PIECE(^FHPT(FHDFN,"A",ADM,"DI",X1,3),"^",1,2)=DUZ_"^"_NOW
+4 IF $PIECE(^FHPT(FHDFN,"A",ADM,"DI",X3,0),"^",13)
SET $PIECE(^FHPT(FHDFN,"A",ADM,"DI",X1,0),"^",13)=$PIECE(^FHPT(FHDFN,"A",ADM,"DI",X3,0),"^",13)
SET PDFLG=1
+5 QUIT