DICE2 ;SFISC/GFT-TRIGGER LOGIC ;09:41 AM  10 Jul 1999
 ;;22.0;VA FileMan;**6**;Mar 30, 1999
 ;Per VHA Directive 10-93-142, this routine should not be modified.
 Q:$D(DTOUT)  W !!!,"---",$P("SET^KILL",U,DIK)," LOGIC---" S DA="^DD("_DI_","_DL_",1,"_DQ_","_(DIK+3)
C K DICOMPX,DATE S:DOLD=DNEW DNEW="TRIGGERED "_DNEW S DNEW=$E(DNEW,1,30),DICOMPX(DNEW)="DIU",DICOMPX(DNEW,U)=DIN_U_DENEW,DCOND="SET" S:$P(^DD(DIN,DENEW,0),U,2)["D" DICOMPX(DNEW,"DATE")=1
 W !!,"IN ANSWERING THE FOLLOWING QUESTION, '"_DNEW_"'",!?2,"CAN BE USED TO REFER TO THE EXISTING TRIGGERED FIELD VALUE.",!
 S DICOMP="?",DICOMPX="",%=DIN S:DIK=1 DICOMPX(1,DI,DL)="DIV"
 D OLD W "PLEASE ENTER AN EXPRESSION WHICH WILL BECOME THE VALUE OF THE",! S %F=DENEW D WR^DIDH
 D GET Q:U[X  I X="""@""" K X G DICE2^DIQQ
 I X="@" S X="S X="""""
 E  D ^DICOMP G DICE2^DIQQ:'$D(X) F %=9.2:.1 Q:'$D(X(%))  S ^UTILITY("DICE",$J,DIK+3*10+%)=X(%)
 K DICOMPX(DNEW) I X="S X=""""" S DE=X,DCOND="DELE" D DEL^DICE3 G Q:X=U,^DICE4:DENEW-.01 F X=0:1 G D01:'$D(J(X)) I J(X)=DIN W $C(7),!,"BUT THE TRIGGERING FIELD DEPENDS ON THE TRIGGERED FIELD!" S X=U G Q
 S DE="S X=DIV "_X,%=$P(^DD(DIN,DENEW,0),U,2) I %["D",'Y["D" W $C(7),!,"WARNING -- THIS SHOULD PRODUCE A DATE VALUE, AND IT MAY NOT!"
 S V=$P(%,"P",2) I V,DICOMPX-V!($P(DICOMPX,U,2)-.001) W !,$C(7),"WARNING -- THIS MUST BE '",$P(^DIC(+V,0),U)," NUMBER'!"
 I Y["B" W $C(7),!,"WARNING--THIS TRUTH-VALUED EXPRESSION WILL PRODUCE ONLY VALUES OF '0' OR '1'"
 I %'["D",Y["D" W $C(7),!,"WARNING -- THIS MAY PRODUCE A 'DATE', AND IT SHOULDN'T!"
 D ^DICE3 G ^DICE4:X'=U
Q Q
 ;
OLD ;
 I DIK=2 S X=$E("OLD "_DOLD,1,30),DICOMPX(X)="X",DICOMPX(X,U)=DI_U_DL W ?2,"NOTE: '"_X_"' CAN BE USED TO REFER TO THE VALUE OF THE",!?2,DOLD_" FIELD BEFORE ITS CHANGE OR DELETION.",! S:$P(^DD(DI,DL,0),U,2)["D" DICOMPX(X,"DATE")=1
 Q
 ;
D01 S V=DREF,X=$L(V)-1 F %=X:-1 I "(,"[$E(V,%) S DHI=$E(V,%+1,X) I DHI'?1N1")" S V=$E(V,1,%),X=0 Q
DQ S X=$F(V,"""",X) I X>0 S V=$E(V,1,X-1)_""""_$E(V,X,999),X=X+2 G DQ
 S X="I "_DHI_">0 N DIK S DIK(0)=DA,",V="DIK="""_V_""",",DHI="DA="_DHI_" D ^DIK",DTAG="S DA=DIK(0)"
 F %=1:1:N S X=X_"DIK("_%_")=DA("_%_"),",DTAG=DTAG_",DA("_%_")=DIK("_%_")"
 F %=1:1:A#100 S DHI="DA("_%_")=DIV("_(A#100-%)_"),"_DHI
 S X=X_V_DHI,^UTILITY("DICE",$J,"DIK")="DELETE" G F^DICE4
 ;
GET ;
 W !," WHENEVER THE '"_DOLD_"' FIELD IS "_$P("ENTERED OR CHANGED^CHANGED OR DELETED",U,DIK)
 R ": ",X:DTIME S:'$T X=U S Y=X I X="" S Y="NO EFFECT",^UTILITY("DICE",$J,DIK)="Q" W "  ",Y I DIK=2,^UTILITY("DICE",$J,1)="Q" W $C(7),"??" S X=U
 S ^UTILITY("DICE",$J,$P("CREA^DELE",U,DIK)_"TE VALUE")=Y
