XBARRAY ; IHS/ADC/GTH - BUILD AN ARRAY ; [ 07/08/1999 3:54 PM ]
;;3.0;IHS/VA UTILITIES;**7**;JULY 9, 1999
;
; Thanks to Paul Wesley, DSD/OIRM, for the original
; routine.
;
; This utility provides a word processing format of free
; text and local variable references to build an array.
;
; A file is necessary that has a .01 field for the form
; name and a WP field to hold the WP form.
;
; Please refer to routine XBFORM0 for documentation.
;
Q
;
GEN(XBFORM,XBWPDIC,XBWPFLD,XBREF,XBFMT,XBLAST) ;EP ** generate array
NEW XBLLINE
S XBLLINE=$G(XBLAST)
I $D(XBFORM(XBFORM)) D ZBUILD,REFBUILD,EXIT Q XBLLINE
D WPGET,BUILD,ZBUILD
D REFBUILD
D EXIT
Q XBLLINE
;
EDIT(XBFORM,XBWPDIC,XBWPFLD) ;EP Edit a Form
EDIT2 ;
KILL XBFORM(XBFORM)
S XBLLINE=0,XBFMT=1
D EDITWP,WPGET,BUILD,ZBUILD
D ARRAY^XBLM("XBZ(",XBFORM)
I $$DIR^XBDIR("S^R:Re-Edit;Q:Quit")="R" KILL XBZ G EDIT2
D EXIT
KILL XBLLINE
Q
;
EDITWP ;** edit WP array
KILL DIE,DIC,DA,DR
S DIC=XBWPDIC,DR=XBWPFLD,DIC(0)="AEQMLZ"
I $L($G(XBFORM)) S X=XBFORM,DIC(0)="XL"
D ^DIC
I Y'>0 S XBQUIT=1 Q
S DIE=$$DIC^XBDIQ1(XBWPDIC),DA=+Y,DR=XBWPFLD
D ^DIE
Q
;
WPGET ;** get WP array
KILL XBWP,XBL,XBOUT,XBVAR,XBWWP,DIC,DR,DIE,DA
S X=XBFORM,DIC=XBWPDIC,DR=XBWPFLD,DIC(0)="X"
D ^DIC
I Y'>0 S XBWP(1)=XBFORM_" NOT FOUND",XBQUIT=1
S DA=+Y
D ENP^XBDIQ1(XBWPDIC,DA,XBWPFLD,"XBWWP(")
S %X="XBWWP("_XBWPFLD_",",%Y="XBWP("
D %XY^%RCR
KILL XBWWP
Q
;
BUILD ;** scan WP array to build XBL
S XBWPL="",XBLINE=0
Q:$D(XBFORM(XBFORM))
F S XBWPL=$O(XBWP(XBWPL)) Q:XBWPL'>0 D LINE
Q
;
LINE ;** process one line of the WP array
S Z=XBWP(XBWPL)
S XBLINE=XBLINE+1
F I=1:1:$L(Z) S A=$E(Z,I) D Q:$G(XBQUIT)
. I I=1,A="#" D MAP S I=$L(Z),XBLINE=XBLINE-1,XBQUIT=1 Q
. I I=1,A="*" D OUT S I=$L(Z),XBLINE=XBLINE-1,XBQUIT=1 Q
. I I=1,A=";" S I=$L(Z),XBLINE=XBLINE-1,XBQUIT=1 Q
. I A'=" ",A'="~" D TEXT Q
. I A="~" D VAR Q
.Q
KILL XBQUIT
Q
;
ZBUILD ;** build Z array from XBL
KILL Z
I '$G(XBFMT) F XBL=1:1 D Q:('$O(XBFORM(XBFORM,XBL)))
. I '$D(XBFORM(XBFORM,XBL)),$O(XBFORM(XBFORM,XBL)) S XBZ(XBL+XBLLINE)=" " Q
. D FILL
.Q
I $G(XBFMT)=1 F XBL=1:1 D Q:('$O(XBFORM(XBFORM,XBL)))
. I '$D(XBFORM(XBFORM,XBL)),$O(XBFORM(XBFORM,XBL)) S XBZ(XBL+XBLLINE,0)=" " Q
. D FILL
.Q
Q
;
REFBUILD ; %RCR BACK TO CALL
S %Y=XBREF,%X="XBZ("
D %XY^%RCR
S XBLLINE=XBLLINE+XBL
Q
;
FILL ;** fill one line
S XBCOL=0,T=""
F S XBCOL=$O(XBFORM(XBFORM,XBL,XBCOL)) Q:XBCOL'>0 D
. S X=XBFORM(XBFORM,XBL,XBCOL),XBCOLX=XBCOL
. I XBCOL#1 S XBCOLX=XBCOL\1,X="S X="_X X X
. S XBXL=$L(X)
. Q:X=""
. S T=$$SETSTR^VALM1(X,T,XBCOLX,XBXL)
.Q
I T="" S XBLLINE=$G(XBLLINE)-1 Q
S:'$G(XBFMT) XBZ(XBL+XBLLINE)=T
S:($G(XBFMT)=1) XBZ(XBL+XBLLINE,0)=T
Q
;
TEXT ;**
NEW W
S XBCOL=I
F W=I:1:$L(Z) S A=$E(Z,W) Q:A="~"
I W'=$L(Z) S W=W-1
S XBT=$E(Z,I,W),XBFORM(XBFORM,XBLINE,XBCOL)=XBT,I=W
Q
;
VAR ;** add .5 to column count to indicate a variable vs text
S XBCOL=I
F W=I+1:1:$L(Z) S A=$E(Z,W) I A="~" Q
S XBT=$E(Z,I+1,W-1),XBFORM(XBFORM,XBLINE,XBCOL+.5)=XBT,I=W
I XBT'["|" D Q
. Q:'$D(XBOUT(XBT))
. S O=XBOUT(XBT),XBT=$P(O,"X")_XBT_$P(O,"X",2)
. S XBFORM(XBFORM,XBLINE,XBCOL+.5)=XBT
.Q
S XBV=$P(XBT,"|"),XBV=XBVAR(XBV),XBS=$P(XBT,"|",2)
I $L(XBS) S XBS="("_XBS_")"
S XBFORM(XBFORM,XBLINE,XBCOL+.5)=XBV_XBS
I $D(XBOUT(XBT)) D
. S O=XBOUT(XBT),XBT=XBV_XBS,XBT=$P(O,"X")_XBT_$P(O,"X",2)
. S XBFORM(XBFORM,XBLINE,XBCOL+.5)=XBT
.Q
Q
;
MAP ;** map shorthand for variables
;#xx1|yyy1*xx2|yyy2*
S Z=$E(Z,2,999)
I Z'["*" S XBVSUB=$P(Z,"|"),XBVAL=$P(Z,"|",2),XBVAR(XBVSUB)=XBVAL Q
F I=1:1 S P=$P(Z,"*",I) Q:P="" S XBVSUB=$P(P,"|"),XBVAL=$P(P,"|",2),XBVAR(XBVSUB)=XBVAL
Q
;
OUT ;** output tranform of data field
;*field|mumps output transform f(x)*
S Z=$E(Z,2,999)
I Z'["*" S XBVSUB=$P(Z,"!"),XBVAL=$P(Z,"!",2),XBOUT(XBVSUB)=XBVAL Q
F I=1:1 S P=$P(Z,"*",I) Q:P="" S XBVSUB=$P(P,"!"),XBVAL=$P(P,"!",2),XBOUT(XBVSUB)=XBVAL
Q
;
TABS ;
W #
F %=0:1:7 W ?%*10,%*10
F %=1:1:66 W !?1,%,?3,"..^...." F X=1:1:7 W "|....^...."
Q
;
EXIT ;
KILL %X,%Y,A,I,L,O,P,T,W,X
KILL XBZ,XBFMT,XBCOL,XBCOLX,XBF,XBL,XBLINE,XBLN,XBLOAD,XBOUT,XBQUIT,XBROU,XBS,XBT,XBTAG,XBTAGE,XBV,XBVAL,XBVAR,XBVSUB,XBWP,XBWPDA,XBWPDIC,XBWPFLD,XBWPL,XBWPNODE,XBWPSUB,XBWWP,XBX,XBXL
Q
;
MDY(X) ;external date to mm/dd/yy x :: var or ~"NOW"~ or ~"TODAY"~
S %DT="TS"
D ^%DT
;begin Y2K fix block
;Q $E(Y,4,5)_"/"_$E(Y,6,7)_"/"_$E(Y,2,3)
Q $E(Y,4,5)_"/"_$E(Y,6,7)_"/"_($E(Y,1,3)+1700) ;Y2000
;end Y2K fix block
;
WP(X) ;build wp entry X #:: WP(FLD,n)=TEXTn
NEW I,W
S XBLWP=$G(XBLLINE),W=$P(X,")")
F I=0:1 S X=$Q(@X) Q:X="" Q:(W'=$P(X,",")) D
. S T=@X,XBLLINE=XBLWP+I
. S:'$G(XBFMT) XBZ(XBL+XBLLINE)=T
. S:($G(XBFMT)=1) XBZ(XBL+XBLLINE,0)=T
Q ""
;
XBARRAY ; IHS/ADC/GTH - BUILD AN ARRAY ; [ 07/08/1999 3:54 PM ]
+1 ;;3.0;IHS/VA UTILITIES;**7**;JULY 9, 1999
+2 ;
+3 ; Thanks to Paul Wesley, DSD/OIRM, for the original
+4 ; routine.
+5 ;
+6 ; This utility provides a word processing format of free
+7 ; text and local variable references to build an array.
+8 ;
+9 ; A file is necessary that has a .01 field for the form
+10 ; name and a WP field to hold the WP form.
+11 ;
+12 ; Please refer to routine XBFORM0 for documentation.
+13 ;
+14 QUIT
+15 ;
GEN(XBFORM,XBWPDIC,XBWPFLD,XBREF,XBFMT,XBLAST) ;EP ** generate array
+1 NEW XBLLINE
+2 SET XBLLINE=$GET(XBLAST)
+3 IF $DATA(XBFORM(XBFORM))
DO ZBUILD
DO REFBUILD
DO EXIT
QUIT XBLLINE
+4 DO WPGET
DO BUILD
DO ZBUILD
+5 DO REFBUILD
+6 DO EXIT
+7 QUIT XBLLINE
+8 ;
EDIT(XBFORM,XBWPDIC,XBWPFLD) ;EP Edit a Form
EDIT2 ;
+1 KILL XBFORM(XBFORM)
+2 SET XBLLINE=0
SET XBFMT=1
+3 DO EDITWP
DO WPGET
DO BUILD
DO ZBUILD
+4 DO ARRAY^XBLM("XBZ(",XBFORM)
+5 IF $$DIR^XBDIR("S^R:Re-Edit;Q:Quit")="R"
KILL XBZ
GOTO EDIT2
+6 DO EXIT
+7 KILL XBLLINE
+8 QUIT
+9 ;
EDITWP ;** edit WP array
+1 KILL DIE,DIC,DA,DR
+2 SET DIC=XBWPDIC
SET DR=XBWPFLD
SET DIC(0)="AEQMLZ"
+3 IF $LENGTH($GET(XBFORM))
SET X=XBFORM
SET DIC(0)="XL"
+4 DO ^DIC
+5 IF Y'>0
SET XBQUIT=1
QUIT
+6 SET DIE=$$DIC^XBDIQ1(XBWPDIC)
SET DA=+Y
SET DR=XBWPFLD
+7 DO ^DIE
+8 QUIT
+9 ;
WPGET ;** get WP array
+1 KILL XBWP,XBL,XBOUT,XBVAR,XBWWP,DIC,DR,DIE,DA
+2 SET X=XBFORM
SET DIC=XBWPDIC
SET DR=XBWPFLD
SET DIC(0)="X"
+3 DO ^DIC
+4 IF Y'>0
SET XBWP(1)=XBFORM_" NOT FOUND"
SET XBQUIT=1
+5 SET DA=+Y
+6 DO ENP^XBDIQ1(XBWPDIC,DA,XBWPFLD,"XBWWP(")
+7 SET %X="XBWWP("_XBWPFLD_","
SET %Y="XBWP("
+8 DO %XY^%RCR
+9 KILL XBWWP
+10 QUIT
+11 ;
BUILD ;** scan WP array to build XBL
+1 SET XBWPL=""
SET XBLINE=0
+2 IF $DATA(XBFORM(XBFORM))
QUIT
+3 FOR
SET XBWPL=$ORDER(XBWP(XBWPL))
IF XBWPL'>0
QUIT
DO LINE
+4 QUIT
+5 ;
LINE ;** process one line of the WP array
+1 SET Z=XBWP(XBWPL)
+2 SET XBLINE=XBLINE+1
+3 FOR I=1:1:$LENGTH(Z)
SET A=$EXTRACT(Z,I)
Begin DoDot:1
+4 IF I=1
IF A="#"
DO MAP
SET I=$LENGTH(Z)
SET XBLINE=XBLINE-1
SET XBQUIT=1
QUIT
+5 IF I=1
IF A="*"
DO OUT
SET I=$LENGTH(Z)
SET XBLINE=XBLINE-1
SET XBQUIT=1
QUIT
+6 IF I=1
IF A=";"
SET I=$LENGTH(Z)
SET XBLINE=XBLINE-1
SET XBQUIT=1
QUIT
+7 IF A'=" "
IF A'="~"
DO TEXT
QUIT
+8 IF A="~"
DO VAR
QUIT
+9 QUIT
End DoDot:1
IF $GET(XBQUIT)
QUIT
+10 KILL XBQUIT
+11 QUIT
+12 ;
ZBUILD ;** build Z array from XBL
+1 KILL Z
+2 IF '$GET(XBFMT)
FOR XBL=1:1
Begin DoDot:1
+3 IF '$DATA(XBFORM(XBFORM,XBL))
IF $ORDER(XBFORM(XBFORM,XBL))
SET XBZ(XBL+XBLLINE)=" "
QUIT
+4 DO FILL
+5 QUIT
End DoDot:1
IF ('$ORDER(XBFORM(XBFORM,XBL)))
QUIT
+6 IF $GET(XBFMT)=1
FOR XBL=1:1
Begin DoDot:1
+7 IF '$DATA(XBFORM(XBFORM,XBL))
IF $ORDER(XBFORM(XBFORM,XBL))
SET XBZ(XBL+XBLLINE,0)=" "
QUIT
+8 DO FILL
+9 QUIT
End DoDot:1
IF ('$ORDER(XBFORM(XBFORM,XBL)))
QUIT
+10 QUIT
+11 ;
REFBUILD ; %RCR BACK TO CALL
+1 SET %Y=XBREF
SET %X="XBZ("
+2 DO %XY^%RCR
+3 SET XBLLINE=XBLLINE+XBL
+4 QUIT
+5 ;
FILL ;** fill one line
+1 SET XBCOL=0
SET T=""
+2 FOR
SET XBCOL=$ORDER(XBFORM(XBFORM,XBL,XBCOL))
IF XBCOL'>0
QUIT
Begin DoDot:1
+3 SET X=XBFORM(XBFORM,XBL,XBCOL)
SET XBCOLX=XBCOL
+4 IF XBCOL#1
SET XBCOLX=XBCOL\1
SET X="S X="_X
XECUTE X
+5 SET XBXL=$LENGTH(X)
+6 IF X=""
QUIT
+7 SET T=$$SETSTR^VALM1(X,T,XBCOLX,XBXL)
+8 QUIT
End DoDot:1
+9 IF T=""
SET XBLLINE=$GET(XBLLINE)-1
QUIT
+10 IF '$GET(XBFMT)
SET XBZ(XBL+XBLLINE)=T
+11 IF ($GET(XBFMT)=1)
SET XBZ(XBL+XBLLINE,0)=T
+12 QUIT
+13 ;
TEXT ;**
+1 NEW W
+2 SET XBCOL=I
+3 FOR W=I:1:$LENGTH(Z)
SET A=$EXTRACT(Z,W)
IF A="~"
QUIT
+4 IF W'=$LENGTH(Z)
SET W=W-1
+5 SET XBT=$EXTRACT(Z,I,W)
SET XBFORM(XBFORM,XBLINE,XBCOL)=XBT
SET I=W
+6 QUIT
+7 ;
VAR ;** add .5 to column count to indicate a variable vs text
+1 SET XBCOL=I
+2 FOR W=I+1:1:$LENGTH(Z)
SET A=$EXTRACT(Z,W)
IF A="~"
QUIT
+3 SET XBT=$EXTRACT(Z,I+1,W-1)
SET XBFORM(XBFORM,XBLINE,XBCOL+.5)=XBT
SET I=W
+4 IF XBT'["|"
Begin DoDot:1
+5 IF '$DATA(XBOUT(XBT))
QUIT
+6 SET O=XBOUT(XBT)
SET XBT=$PIECE(O,"X")_XBT_$PIECE(O,"X",2)
+7 SET XBFORM(XBFORM,XBLINE,XBCOL+.5)=XBT
+8 QUIT
End DoDot:1
QUIT
+9 SET XBV=$PIECE(XBT,"|")
SET XBV=XBVAR(XBV)
SET XBS=$PIECE(XBT,"|",2)
+10 IF $LENGTH(XBS)
SET XBS="("_XBS_")"
+11 SET XBFORM(XBFORM,XBLINE,XBCOL+.5)=XBV_XBS
+12 IF $DATA(XBOUT(XBT))
Begin DoDot:1
+13 SET O=XBOUT(XBT)
SET XBT=XBV_XBS
SET XBT=$PIECE(O,"X")_XBT_$PIECE(O,"X",2)
+14 SET XBFORM(XBFORM,XBLINE,XBCOL+.5)=XBT
+15 QUIT
End DoDot:1
+16 QUIT
+17 ;
MAP ;** map shorthand for variables
+1 ;#xx1|yyy1*xx2|yyy2*
+2 SET Z=$EXTRACT(Z,2,999)
+3 IF Z'["*"
SET XBVSUB=$PIECE(Z,"|")
SET XBVAL=$PIECE(Z,"|",2)
SET XBVAR(XBVSUB)=XBVAL
QUIT
+4 FOR I=1:1
SET P=$PIECE(Z,"*",I)
IF P=""
QUIT
SET XBVSUB=$PIECE(P,"|")
SET XBVAL=$PIECE(P,"|",2)
SET XBVAR(XBVSUB)=XBVAL
+5 QUIT
+6 ;
OUT ;** output tranform of data field
+1 ;*field|mumps output transform f(x)*
+2 SET Z=$EXTRACT(Z,2,999)
+3 IF Z'["*"
SET XBVSUB=$PIECE(Z,"!")
SET XBVAL=$PIECE(Z,"!",2)
SET XBOUT(XBVSUB)=XBVAL
QUIT
+4 FOR I=1:1
SET P=$PIECE(Z,"*",I)
IF P=""
QUIT
SET XBVSUB=$PIECE(P,"!")
SET XBVAL=$PIECE(P,"!",2)
SET XBOUT(XBVSUB)=XBVAL
+5 QUIT
+6 ;
TABS ;
+1 WRITE #
+2 FOR %=0:1:7
WRITE ?%*10,%*10
+3 FOR %=1:1:66
WRITE !?1,%,?3,"..^...."
FOR X=1:1:7
WRITE "|....^...."
+4 QUIT
+5 ;
EXIT ;
+1 KILL %X,%Y,A,I,L,O,P,T,W,X
+2 KILL XBZ,XBFMT,XBCOL,XBCOLX,XBF,XBL,XBLINE,XBLN,XBLOAD,XBOUT,XBQUIT,XBROU,XBS,XBT,XBTAG,XBTAGE,XBV,XBVAL,XBVAR,XBVSUB,XBWP,XBWPDA,XBWPDIC,XBWPFLD,XBWPL,XBWPNODE,XBWPSUB,XBWWP,XBX,XBXL
+3 QUIT
+4 ;
MDY(X) ;external date to mm/dd/yy x :: var or ~"NOW"~ or ~"TODAY"~
+1 SET %DT="TS"
+2 DO ^%DT
+3 ;begin Y2K fix block
+4 ;Q $E(Y,4,5)_"/"_$E(Y,6,7)_"/"_$E(Y,2,3)
+5 ;Y2000
QUIT $EXTRACT(Y,4,5)_"/"_$EXTRACT(Y,6,7)_"/"_($EXTRACT(Y,1,3)+1700)
+6 ;end Y2K fix block
+7 ;
WP(X) ;build wp entry X #:: WP(FLD,n)=TEXTn
+1 NEW I,W
+2 SET XBLWP=$GET(XBLLINE)
SET W=$PIECE(X,")")
+3 FOR I=0:1
SET X=$QUERY(@X)
IF X=""
QUIT
IF (W'=$PIECE(X,","))
QUIT
Begin DoDot:1
+4 SET T=@X
SET XBLLINE=XBLWP+I
+5 IF '$GET(XBFMT)
SET XBZ(XBL+XBLLINE)=T
+6 IF ($GET(XBFMT)=1)
SET XBZ(XBL+XBLLINE,0)=T
End DoDot:1
+7 QUIT ""
+8 ;