DIEV ;SFISC/DPC-DATA VALIDATOR ;22SEP2009
 ;;22.0;VA FileMan;**55,160**;Mar 30, 1999;Build 11
 ;Per VHA Directive 2004-038, this routine should not be modified.
VAL(DIEVF,DIEVIEN,DIEVFLD,DIEVFLG,DIEVAL,DIEVANS,DIEVFAR,DIOUTAR) ;
VALX ;
 N DIEV0,DIEVP2,DA,D,I,C,G K DIEVANS
 I '$D(DIQUIET) N DIQUIET S DIQUIET=1
 I '$D(DIFM) N DIFM S DIFM=1 D INIZE^DIEFU
 S DIEVFLG=$G(DIEVFLG) I '$$VERFLG^DIEFU(DIEVFLG,"HFERYUK") G OUT
 D FLDVAL G:$G(DIEVAL)=U OUT
IENS S G=$G(DIEVIEN) I G]"" S:G'?.E1"," G=G_"," S C=$L(G,",")-1 F I=1:1:C S D="D"_(C-I) N @D S @D=$P(G,",",I) I @D="" D BLD^DIALOG(308,$G(DIEVIEN)) G OUT
 S DIEVIEN=G D DA^DIEFU(G,.DA)
 D AUXVAL(DIEVF,DIEVIEN,DIEVFLD,DIEVFLG,DIEVAL,.DIEVANS,.DIEV0,.DIEVP2)
 I $G(DIEVANS)=U!("@"[DIEVAL) G OUT
MINVAL ;
 D INT(DIEVF,DIEVFLD,DIEVFLG,DIEVAL,.DIEVANS,$G(DIEV0),$G(DIEVP2))
 I DIEVANS=U D ERR G OUT
 I DIEVFLG'["U",$G(DIEVIEN)'?."," D KEY(DIEVF,DIEVIEN,DIEVFLD,DIEVFLG,DIEVANS,.DIEVANS)
OUT S DIEVANS=$G(DIEVANS,U)
 I DIEVFLG["F",DIEVANS'=U D FDA
 I $G(DIOUTAR)]"" D CALLOUT^DIEFU(DIOUTAR)
 Q
 ;
FLDVAL ;
 N DIEVOUT S DIEVOUT=0
 I '$$VFILE^DIEFU(DIEVF,"D") S DIEVAL=U Q
 I '$$VFIELD^DIEFU(DIEVF,DIEVFLD,"D") S DIEVAL=U Q
 S DIEV0=^DD(DIEVF,DIEVFLD,0),DIEVP2=$P(DIEV0,U,2)
 D DTYPE
 I DIEVOUT=1 S DIEVAL=U
 Q
 ;
AUXVAL(DIEVF,DIEVIEN,DIEVFLD,DIEVFLG,DIEVAL,DIEVANS,DIEV0,DIEVP2) ;
 N DIEVOUT S DIEVOUT=0
 I '$D(DIOVRD),$P($G(^DD($$FNO^DILIBF(DIEVF),0,"DI")),U,2)="Y",DIEVFLG'["Y" D  G AUXERR
 . N INT,EXT S INT(1)=$$FILENM^DIEFU(DIEVF),EXT("FILE")=DIEVF
 . D BLD^DIALOG(405,.INT,.EXT)
 I $P(DIEV0,U,5,99)["DINUM","@"'[DIEVAL D  G AUXERR
 . N EXT,INT S EXT("FILE")=DIEVF,EXT("FIELD")=DIEVFLD,(INT(1),EXT(1))="DINUMed"
 . D BLD^DIALOG(520,.INT,.EXT)
 I $E(DIEVAL)="?"!(DIEVP2["V"&(DIEVAL[".?")) N P S P(1)=DIEVF,P(2)=DIEVFLD D BLD^DIALOG(1610,"",.P) G AUXERR
 I DIEVFLG["R" G:'$$VENTRY^DIEFU(DIEVF,DIEVIEN,"D9") AUXERR
 I DIEVP2["I",$$DATA(DIEVF,DIEVFLD) N P S P("FIELD")=DIEVFLD,P("FILE")=DIEVF D BLD^DIALOG(710,.P,.P) G AUXERR
 I "@"[DIEVAL D DELETE G:DIEVOUT AUXERR Q
 I DIEVFLG["I" D
 . S DIEVANS=DIEVAL
 . I DIEVFLG["E" S DIEVANS(0)=$$EXTERNAL^DILFD(DIEVF,DIEVFLD,"",DIEVAL)
 Q
AUXERR S DIEVANS=U
 Q
 ;
DTYPE ;
 I DIEVP2 D  S DIEVOUT=1 Q
 . N T,INT,EXT D DTYP^DIOU(DIEVF,DIEVFLD,.T)
 . I T=5 S INT(1)="word-processing",EXT("FIELD")=DIEVFLD,EXT("FILE")=DIEVF D BLD^DIALOG(520,.INT,.EXT) Q
 . S INT(1)="multi-valued",EXT("FIELD")=DIEVFLD,EXT("FILE")=DIEVF D BLD^DIALOG(520,.INT,.EXT)
 I DIEVP2["C" N INT,EXT S INT(1)="computed",EXT("FIELD")=DIEVFLD,EXT("FILE")=DIEVF D BLD^DIALOG(520,.INT,.EXT) S DIEVOUT=1 Q
 Q
 ;
DELETE ;
 I $D(^DD(DIEVF,DIEVFLD,"DEL")) D
 . N DIEVECNT S DIEVECNT=$G(DIERR)
 . N I S I="" F  S I=$O(^DD(DIEVF,DIEVFLD,"DEL",I)) Q:I=""  X $G(^(I,0)) I  S DIEVOUT=1
 . I DIEVECNT'=$G(DIERR) S DIEVOUT=1 D HKERR^DILIBF(DIEVF,$G(DIEVIEN),DIEVFLD,"DEL node")
 I DIEVP2["R" D
 . I DIEVFLD'=.01 S DIEVOUT=1 Q
 . I '$D(^DD(DIEVF,0,"UP")) Q
 . I $P($G(@$$ROOT^DILFD(DIEVF,DIEVIEN,1)@(0)),U,4)=1 S DIEVOUT=1
 I 'DIEVOUT,DIEVFLG'["U",DIEVFLD'=.01 D  Q:DIEVOUT
 . N DIEVKEY
 . S DIEVKEY=0
 . F  S DIEVKEY=$O(^DD("KEY","F",DIEVF,DIEVFLD,DIEVKEY)) Q:'DIEVKEY  D
 . . Q:$D(^DD("KEY",DIEVKEY,0))[0
 . . D ERR742^DIEVK1(DIEVF,DIEVFLD,DIEVKEY,DIEVIEN)
 . . S DIEVOUT=1
 I 'DIEVOUT S DIEVANS="" S:DIEVFLG["E" DIEVANS(0)=""
 E  D
 . N INT,EXT
 . S INT(1)=$$FLDNM^DIEFU(DIEVF,DIEVFLD),INT(2)=$$FILENM^DIEFU(DIEVF)
 . S EXT("FILE")=DIEVF,EXT("FIELD")=DIEVFLD
 . D BLD^DIALOG(712,.INT,.EXT)
 Q
 ;
DATA(DIEVF,DIEVFLD) ;
 N DIEVNODE,DIEVSPOT,N S DIEVSPOT=" ",N=0
 D GLRF^DIOU(DIEVF,DIEVFLD,.DIEVNODE,.DIEVSPOT)
 I +DIEVSPOT D
 . I $P($G(@DIEVNODE),U,DIEVSPOT)'="" S N=1
 E  I $E(DIEVSPOT)="E" D
 . N F,T
 . S F=$P($P(DIEVSPOT,"E",2),",",1),T=$P(DIEVSPOT,",",2)
 . I $TR($E($G(@DIEVNODE),F,T)," ")'="" S N=1
 Q N
 ;
INT(%B1,%B2,DIEVFLG,X,DIEVANS,%B3,%B) ;
 N %A,%E,%C,DIR,DIC,Y,DIE,%J,%T,%BA,DP,DIFLD,DDH,%BU,%I,%K,DQ,DIFILE,C,DIEVECNT,DIRDINUM
 I $G(%B3)="" S %B3=^DD(%B1,%B2,0),%B=$P(%B3,U,2)
 I %B["V" D VP^DIEV1(%B1,%B2,DIEVFLG,X,%B3,.DIEVANS) Q
 I %B["N" D  Q:$G(DIEVANS)=U
 . I $L($P(X,"."))>24 S DIEVANS=U Q
 I %B["S" S X=$$UP^DILIBF(X)
 S %A=%B1_","_%B2_",V",%E=0,DIR("V")="",%T=$E(%B1)
 S DIEVECNT=$G(DIERR)
 S:DIEVFLG["N" DIRDINUM=1 D 1^DIR1 ;input transform to 52,3 KILLs off "Y" variable!
 I DIEVECNT'=$G(DIERR) S DIEVANS=U D HKERR^DILIBF(%B1,$G(DIEVIEN),%B2,"screen on a pointer or set of codes or in an input transform") K:$G(DIRDINUM) DINUM Q
 I %E S DIEVANS=U K:$G(DIRDINUM) DINUM Q
 S DIEVANS=$S(%B'["P":Y,1:$P(Y,U))
 I DIEVFLG["E" D
 . I %B["S"!(%B["D") S DIEVANS(0)=$P(Y(0),U)
 . E  I %B["P" S DIEVANS(0)=Y(0,0)
 . E  I %B["O" D
 . . S DIEVECNT=$G(DIERR)
 . . X $G(^DD(%B1,%B2,2))
 . . I DIEVECNT'=$G(DIERR) D HKERR^DILIBF(%B1,$G(DIEVIEN),%B2,"output transform") Q
 . . S DIEVANS(0)=Y
 . . Q
 . E  S DIEVANS(0)=Y
 . Q
 Q
 ;
KEY(DIEVF,DIEVIEN,DIEVFLD,DIEVFLG,DIEVAL,DIEVANS) ;checks Key integrity for a value
 N DIEVKEY,DIEVFDA S DIEVKEY=""
 S DIEVFDA(DIEVF,DIEVIEN,DIEVFLD)=DIEVAL
 I '$$KEYVAL^DIEVK($E("K",DIEVFLG["K"),"DIEVFDA") K DIEVANS S DIEVANS=U
 Q
 ;
FDA ;
 I $G(DIEVFAR)="" D BLD^DIALOG(202,"FDA") Q
 D LOAD^DIEF1(DIEVF,DIEVIEN,DIEVFLD,"",DIEVANS,DIEVFAR)
 Q
 ;
ERR ;
 N INT,EXT
 S INT(1)=$$FLDNM^DIEFU(DIEVF,DIEVFLD),INT(2)=$$FILENM^DIEFU(DIEVF),(INT(3),EXT(3))=DIEVAL
 S EXT("FILE")=DIEVF,EXT("FIELD")=DIEVFLD,EXT("IENS")=$G(DIEVIEN)
 D BLD^DIALOG(701,.INT,.EXT)
 I DIEVFLG["H" D GET^DIEH(DIEVF,"",DIEVFLD,"?b") ;DA() and D0,D1,etc. passed thru symbol table
 Q
 ;
CHKX ;
 N DIEV0,DIEVP2 K DIEVANS
 I '$D(DIQUIET) N DIQUIET S DIQUIET=1
 I '$D(DIFM) N DIFM S DIFM=1 D INIZE^DIEFU
 S DIEVFLG=$G(DIEVFLG) I '$$VERFLG^DIEFU(DIEVFLG,"HEN") G OUT
 D FLDVAL I $G(DIEVAL)=U D OUT Q
 D MINVAL
 Q
