DICATT3 ;SFISC/COMPUTED FIELDS ;11:27 AM 24 May 2001 [ 12/09/2003 4:25 PM ]
;;22.0;VA FileMan;**76,1002**;Mar 30, 1999
;Per VHA Directive 10-93-142, this routine should not be modified.
K DIRUT,DTOUT D COMP I $P(^DD(A,DA,0),U,2)["C" G N^DICATT
S DTOUT=1 G CHECK^DICATT
;
COMP N DIR,DICOMPX,DISPEC,DICMIN,DIL,DIJ,DIE,DIDEC
S DISPEC=$P($G(^DD(A,DA,0)),U,2)
S DIR(0)="FU",DIR("A")="'COMPUTED-FIELD' EXPRESSION"
I O,$D(^DD(A,DA,9.1)) S DIR("B")=^(9.1)
S DIR("?")="^D DICATT3^DIQQ"
D ^DIR Q:$D(DIRUT)
I $D(DIR("B")),DIR("B")=Y G GETTYPE
K DICOMPX S DICOMPX=""
S DICMIN=Y,DQI="Y("_A_","_DA_",",DICMX="X DICMX",DICOMP="?I"
D ^DICOMP I '$D(X) W $C(7)," ...??" G 6
I DUZ(0)="@" W !,"TRANSLATES TO THE FOLLOWING CODE:",!,X,!
I Y["m" W !,"FIELD IS 'MULTIPLE-VALUED'!",!
I O,$D(^DD(A,DA,9.01))!(DICOMPX]"") D ACOMP
S DISPEC=$E("D",Y["D")_$E("B",Y["B")_"C"_$S(Y'["m":"",1:"m"_$E("w",Y["w"))_$S(Y["p":"p"_$S($P(Y,"p",2):+$P(Y,"p",2),1:""),1:"")_$S(Y'["B":"",1:"J1")
S ^DD(A,DA,0)=F_U_DISPEC_"^^ ; ^"_X,^(9)=U,^(9.1)=DICMIN,^(9.01)=DICOMPX
F Y=9.2:0 Q:'$D(X(Y)) S ^(Y)=X(Y),Y=$O(X(Y))
K X,DICOMPX
GETTYPE K DIR S DIR(0)="SBA^S:STRING;N:NUMERIC;B:BOOLEAN;D:DATE;m:MULTIPLE;p:POINTER;mp:MULTIPLE POINTER"
S DIR("A")="TYPE OF RESULT: "
S DIR("B")=$P($E(DIR(0),$F(DIR(0),$$TYPE(DISPEC)_":"),99),";")
D ^DIR I $D(DIRUT) G END
S DISPEC=$TR(Y,"SN") I Y="B"!(Y="D") D P(Y) G END
I Y["p" D POINT G END
S DIJ="",DIE=$P($P(O,U,2),"J",2) F J=0:0 S N=$E(DIE) Q:N?.A S DIE=$E(DIE,2,99),DIJ=DIJ_N
S DIDEC=$P(DIJ,",",2),DIL=$S(DIJ:+DIJ,1:8)
I DISPEC'["m" D DEC:Y="N" I '$D(DIRUT) D LEN
END I O S DI=A D PZ^DIU0 Q
D SDIK^DICATT22
6 Q ;leave this here
;
;
DEC N DG,O,M
FRAC K DIR S DIR("A")="NUMBER OF FRACTIONAL DIGITS TO OUTPUT: "
I DIDEC]"" S DIR("B")=DIDEC
S DIR("?")="Enter the number of decimal digits that should normally appear in the result."
S DIR(0)="NAO^0:14:0" D ^DIR Q:$D(DIRUT) S DIDEC=Y
S DG=" S X=$J(X,0,",M=$P(^DD(A,DA,0),DG),%=M_DG_DIDEC_")"'=^(0)+1
W !,"SHOULD VALUE ALWAYS BE INTERNALLY ROUNDED TO ",DIDEC," DECIMAL PLACE",$E("S",DIDEC'=1)
D YN^DICN G FRAC:'% Q:%'>0 S ^DD(A,DA,0)=M_$P(DG_DIDEC_")",U,%)
S S DQI="Y(",O=$D(^(9.02)),X=^(9.1) K DICOMPX,^(9.02) Q:'$D(^(9.01))
F Y=1:1 S M=$P(^(9.01),";",Y) Q:M="" S DICOMPX(1,+M,+$P(M,U,2))="S("""_M_""")",DICOMPX=""
Q:Y<2 I X'["/",X'["\" Q:X'["*" Q:Y<3
D ^DICOMP Q:$D(X)-1
S %=2-O W !,"WHEN TOTALLING THIS FIELD, SHOULD THE SUM BE COMPUTED FROM",!?7,"THE SUMS OF THE COMPONENT FIELDS" D YN^DICN
I %=1 S ^DD(A,DA,9.02)=X_" S Y=X"
S:%<1 DIRUT=1
Q
;
LEN K DIR
S DIR(0)="NAO^1::0",DIR("A")="LENGTH OF FIELD: ",DIR("B")=DIL
S DIR("?")="Maximum number of character expected to be output."
D ^DIR Q:$D(DIRUT)
D P($P(DISPEC,"J")_"J"_Y_$E(",",DIDEC]"")_DIDEC_DIE) Q
;
POINT K DIR
S DIR(0)="P^1:QEF",DIR("A")="POINT TO WHAT FILE"
S DIR("S")="I $$OKFILE^DICOMPX(Y,""W"")"
S X=$P($P(^DD(A,DA,0),U,2),"p",2) I 'X S X=$P($P(O,U,2),"p",2)
I X,$D(^DIC(+X,0)) S DIR("B")=$P(^(0),U)
D ^DIR I '$D(DIRUT) S $P(DISPEC,"p",2)=+Y D P(DISPEC)
Q
;
P(C) S $P(^DD(A,DA,0),U,2)="C"_$TR(C,"C^") Q
;
ACOMP ;SET/KILL ACOMP NODES
N X,I I $G(^DD(A,DA,9.01))]"" S X=^(9.01) X ^DD(0,9.01,1,1,2)
I DICOMPX]"" S X=DICOMPX X ^DD(0,9.01,1,1,1)
Q
;
TYPE(S) ;
Q $S(S["D":"D",S["B":"B",S["mp":"mp",S["m":"m",S["p":"p",S'["J":"S",S[",":"N",1:"S") ;figure out TYPE OF RESULT
DICATT3 ;SFISC/COMPUTED FIELDS ;11:27 AM 24 May 2001 [ 12/09/2003 4:25 PM ]
+1 ;;22.0;VA FileMan;**76,1002**;Mar 30, 1999
+2 ;Per VHA Directive 10-93-142, this routine should not be modified.
+3 KILL DIRUT,DTOUT
DO COMP
IF $PIECE(^DD(A,DA,0),U,2)["C"
GOTO N^DICATT
+4 SET DTOUT=1
GOTO CHECK^DICATT
+5 ;
COMP NEW DIR,DICOMPX,DISPEC,DICMIN,DIL,DIJ,DIE,DIDEC
+1 SET DISPEC=$PIECE($GET(^DD(A,DA,0)),U,2)
+2 SET DIR(0)="FU"
SET DIR("A")="'COMPUTED-FIELD' EXPRESSION"
+3 IF O
IF $DATA(^DD(A,DA,9.1))
SET DIR("B")=^(9.1)
+4 SET DIR("?")="^D DICATT3^DIQQ"
+5 DO ^DIR
IF $DATA(DIRUT)
QUIT
+6 IF $DATA(DIR("B"))
IF DIR("B")=Y
GOTO GETTYPE
+7 KILL DICOMPX
SET DICOMPX=""
+8 SET DICMIN=Y
SET DQI="Y("_A_","_DA_","
SET DICMX="X DICMX"
SET DICOMP="?I"
+9 DO ^DICOMP
IF '$DATA(X)
WRITE $CHAR(7)," ...??"
GOTO 6
+10 IF DUZ(0)="@"
WRITE !,"TRANSLATES TO THE FOLLOWING CODE:",!,X,!
+11 IF Y["m"
WRITE !,"FIELD IS 'MULTIPLE-VALUED'!",!
+12 IF O
IF $DATA(^DD(A,DA,9.01))!(DICOMPX]"")
DO ACOMP
+13 SET DISPEC=$EXTRACT("D",Y["D")_$EXTRACT("B",Y["B")_"C"_$SELECT(Y'["m":"",1:"m"_$EXTRACT("w",Y["w"))_$SELECT(Y["p":"p"_$SELECT($PIECE(Y,"p",2):+$PIECE(Y,"p",2),1:""),1:"")_$SELECT(Y'["B":"",1:"J1")
+14 SET ^DD(A,DA,0)=F_U_DISPEC_"^^ ; ^"_X
SET ^(9)=U
SET ^(9.1)=DICMIN
SET ^(9.01)=DICOMPX
+15 FOR Y=9.2:0
IF '$DATA(X(Y))
QUIT
SET ^(Y)=X(Y)
SET Y=$ORDER(X(Y))
+16 KILL X,DICOMPX
GETTYPE KILL DIR
SET DIR(0)="SBA^S:STRING;N:NUMERIC;B:BOOLEAN;D:DATE;m:MULTIPLE;p:POINTER;mp:MULTIPLE POINTER"
+1 SET DIR("A")="TYPE OF RESULT: "
+2 SET DIR("B")=$PIECE($EXTRACT(DIR(0),$FIND(DIR(0),$$TYPE(DISPEC)_":"),99),";")
+3 DO ^DIR
IF $DATA(DIRUT)
GOTO END
+4 SET DISPEC=$TRANSLATE(Y,"SN")
IF Y="B"!(Y="D")
DO P(Y)
GOTO END
+5 IF Y["p"
DO POINT
GOTO END
+6 SET DIJ=""
SET DIE=$PIECE($PIECE(O,U,2),"J",2)
FOR J=0:0
SET N=$EXTRACT(DIE)
IF N?.A
QUIT
SET DIE=$EXTRACT(DIE,2,99)
SET DIJ=DIJ_N
+7 SET DIDEC=$PIECE(DIJ,",",2)
SET DIL=$SELECT(DIJ:+DIJ,1:8)
+8 IF DISPEC'["m"
IF Y="N"
DO DEC
IF '$DATA(DIRUT)
DO LEN
END IF O
SET DI=A
DO PZ^DIU0
QUIT
+1 DO SDIK^DICATT22
6 ;leave this here
QUIT
+1 ;
+2 ;
DEC NEW DG,O,M
FRAC KILL DIR
SET DIR("A")="NUMBER OF FRACTIONAL DIGITS TO OUTPUT: "
+1 IF DIDEC]""
SET DIR("B")=DIDEC
+2 SET DIR("?")="Enter the number of decimal digits that should normally appear in the result."
+3 SET DIR(0)="NAO^0:14:0"
DO ^DIR
IF $DATA(DIRUT)
QUIT
SET DIDEC=Y
+4 SET DG=" S X=$J(X,0,"
SET M=$PIECE(^DD(A,DA,0),DG)
SET %=M_DG_DIDEC_")"'=^(0)+1
+5 WRITE !,"SHOULD VALUE ALWAYS BE INTERNALLY ROUNDED TO ",DIDEC," DECIMAL PLACE",$EXTRACT("S",DIDEC'=1)
+6 DO YN^DICN
IF '%
GOTO FRAC
IF %'>0
QUIT
SET ^DD(A,DA,0)=M_$PIECE(DG_DIDEC_")",U,%)
S SET DQI="Y("
SET O=$DATA(^(9.02))
SET X=^(9.1)
KILL DICOMPX,^(9.02)
IF '$DATA(^(9.01))
QUIT
+1 FOR Y=1:1
SET M=$PIECE(^(9.01),";",Y)
IF M=""
QUIT
SET DICOMPX(1,+M,+$PIECE(M,U,2))="S("""_M_""")"
SET DICOMPX=""
+2 IF Y<2
QUIT
IF X'["/"
IF X'["\"
IF X'["*"
QUIT
IF Y<3
QUIT
+3 DO ^DICOMP
IF $DATA(X)-1
QUIT
+4 SET %=2-O
WRITE !,"WHEN TOTALLING THIS FIELD, SHOULD THE SUM BE COMPUTED FROM",!?7,"THE SUMS OF THE COMPONENT FIELDS"
DO YN^DICN
+5 IF %=1
SET ^DD(A,DA,9.02)=X_" S Y=X"
+6 IF %<1
SET DIRUT=1
+7 QUIT
+8 ;
LEN KILL DIR
+1 SET DIR(0)="NAO^1::0"
SET DIR("A")="LENGTH OF FIELD: "
SET DIR("B")=DIL
+2 SET DIR("?")="Maximum number of character expected to be output."
+3 DO ^DIR
IF $DATA(DIRUT)
QUIT
+4 DO P($PIECE(DISPEC,"J")_"J"_Y_$EXTRACT(",",DIDEC]"")_DIDEC_DIE)
QUIT
+5 ;
POINT KILL DIR
+1 SET DIR(0)="P^1:QEF"
SET DIR("A")="POINT TO WHAT FILE"
+2 SET DIR("S")="I $$OKFILE^DICOMPX(Y,""W"")"
+3 SET X=$PIECE($PIECE(^DD(A,DA,0),U,2),"p",2)
IF 'X
SET X=$PIECE($PIECE(O,U,2),"p",2)
+4 IF X
IF $DATA(^DIC(+X,0))
SET DIR("B")=$PIECE(^(0),U)
+5 DO ^DIR
IF '$DATA(DIRUT)
SET $PIECE(DISPEC,"p",2)=+Y
DO P(DISPEC)
+6 QUIT
+7 ;
P(C) SET $PIECE(^DD(A,DA,0),U,2)="C"_$TRANSLATE(C,"C^")
QUIT
+1 ;
ACOMP ;SET/KILL ACOMP NODES
+1 NEW X,I
IF $GET(^DD(A,DA,9.01))]""
SET X=^(9.01)
XECUTE ^DD(0,9.01,1,1,2)
+2 IF DICOMPX]""
SET X=DICOMPX
XECUTE ^DD(0,9.01,1,1,1)
+3 QUIT
+4 ;
TYPE(S) ;
+1 ;figure out TYPE OF RESULT
QUIT $SELECT(S["D":"D",S["B":"B",S["mp":"mp",S["m":"m",S["p":"p",S'["J":"S",S[",":"N",1:"S")