DIEFU ;SF/DPC-FILER UTILITIES ;06:42 PM  9 Aug 2002
 ;;22.0;VA FileMan;**85,999**;Mar 30, 1999
INIZE ;
 N %,X,%H,DIE,DICS,DIC,%DT,DIK,%Y,%X,%D,%M,%I
 D DTNOLF^DICRW
 D CLEAN
 Q
CLEAN ;
 K DIRUT,DIROUT,DUOUT,DTOUT
 K ^TMP("DIERR",$J),^TMP("DIMSG",$J),^TMP("DIHELP",$J)
 K DIERR,DIHELP,DIMSG
 Q
 ;
CALLOUT(DIOUTAR) ;
 I '$$VROOT(DIOUTAR) Q
 I $D(DIERR) D
 . S @DIOUTAR@("DIERR")=DIERR
 . M @DIOUTAR@("DIERR")=^TMP("DIERR",$J)
 . K ^TMP("DIERR",$J)
 . Q
 I $D(DIHELP) D
 . S @DIOUTAR@("DIHELP")=DIHELP
 . M @DIOUTAR@("DIHELP")=^TMP("DIHELP",$J)
 . K ^TMP("DIHELP",$J)
 . Q
 I $D(DIMSG) D
 . S @DIOUTAR@("DIMSG")=DIMSG
 . M @DIOUTAR@("DIMSG")=^TMP("DIMSG",$J)
 . K ^TMP("DIMSG",$J)
 . Q
 Q
 ;
IEN(DIEFDA) ;
IENX ;
 I '$D(DIEFDA) Q 0
 N I,DIEFIEN S (I,DIEFIEN)="",DIEFDA(0)=$G(DIEFDA)
 F  S I=$O(DIEFDA(I)) Q:I=""  S DIEFIEN=DIEFIEN_DIEFDA(I)_","
 K DIEFDA(0)
 Q DIEFIEN
 ;
DA(DAIEN,DATARG) ;
DAX ;
 K DATARG N I
 F I=1:1:$L(DAIEN,",")-1 S DATARG(I-1)=$P(DAIEN,",",I)
 I $D(DATARG(0)) S DATARG=DATARG(0) K DATARG(0)
 Q
 ;
VROOT(DIEFAR) ;
 I DIEFAR'["(" Q 1
 I $E(DIEFAR,$L(DIEFAR))=")",$F(DIEFAR,")")>($F(DIEFAR,"(")+1) Q 1
 D BLD^DIALOG(202,"array root")
 Q 0
 ;
VFILE(F,FLAG) ;
VFILEX ;
 I $P($G(^DD(F,.01,0)),U,2)]"",$P(^(0),U,2)'["W" Q 1
 I $G(FLAG)["D" N P S P("FILE")=F D BLD^DIALOG(401,.P,.P)
 Q 0
 ;
VENTRY(DIEFF,DIEFIEN,DIEFFLG) ;
 N DIEFROOT,DIEFDA
 S DIEFFLG=$G(DIEFFLG),DIEFDA=$P(DIEFIEN,",")
 S DIEFROOT=$$ROOT^DIQGU(DIEFF,DIEFIEN,1,$S(DIEFFLG["D":1,1:0)) Q:DIEFROOT="" 0
 I $P($G(@DIEFROOT@(DIEFDA,0)),"^",1)="" D  Q 0
 . I DIEFFLG["D" N DIEFP S DIEFP("FILE")=DIEFF,DIEFP("IENS")=DIEFIEN D BLD^DIALOG(601,"",.DIEFP)
 I DIEFFLG["9" Q:'$$VMINUS9(DIEFF,DIEFIEN,DIEFFLG) 0
 Q 1
 ;
VMINUS9(DIEFF,DIEFIEN,DIEFFLG) ;
 N DIEFTOP,DIEFROOT S DIEFFLG=$G(DIEFFLG)
 S DIEFTOP=$P(DIEFIEN,",",$L(DIEFIEN,",")-1),DIEFROOT=$$ROOT^DIQGU($$FNO^DILIBF(DIEFF),.DIEFTOP,1,$S(DIEFFLG["D":1,1:0))
 Q:DIEFROOT="" 0
 I $D(@DIEFROOT@(DIEFTOP,-9)) D  Q 0
 . I DIEFFLG["D" N DIEFP S DIEFP("FILE")=DIEFF,DIEFP("IENS")=DIEFIEN D BLD^DIALOG(602,"",.DIEFP)
 Q 1
 ;
CHKFLD(DIEFF,DIEFFLD) ;
 I DIEFFLD'=+DIEFFLD S DIEFFLD=$$FLDNUM^DIEF1(DIEFF,DIEFFLD) Q:'DIEFFLD 0
 I '$$VFIELD(DIEFF,DIEFFLD,"D") Q 0
 Q DIEFFLD
 ;
VFIELD(F,FLD,FLAG) ;
VFIELDX ;
 I $D(^DD(F,FLD)) Q 1
 I $G(FLAG)["D" N P S (P(1),P("FIELD"))=FLD,P("FILE")=F D BLD^DIALOG(501,.P,.P)
 Q 0
 ;
DT(DIEFDT,DIEFX,DIEFY,DIEFDT0,DIOUTAR) ;
DTX ;
 I '$D(DIQUIET) N DIQUIET S DIQUIET=1
 I '$D(DIFM) N DIFM S DIFM=1 D INIZE
 N %DT,X,Y
 S DIEFDT=$G(DIEFDT)
 I $G(DIEFX)="" D BLD^DIALOG(202,"date being converted") G DTOUT
 I '$$VERFLG^DIEFU(DIEFDT,"FMNPRSTXEeI") G DTOUT
 I DIEFX?."?" D DT^DIEH1(DIEFDT) S DIEFY=-1 G DTOUT
 S %DT=DIEFDT,X=DIEFX S:$G(DIEFDT0)]"" %DT(0)=DIEFDT0 D ^%DT S DIEFY=Y
 I DIEFY=-1 D:DIEFDT'["e"  G DTOUT
 . N DIEFP
 . S DIEFP(1)=DIEFX,DIEFP(2)="date/time"
 . D BLD^DIALOG(330,.DIEFP,.DIEFP)
 I DIEFDT["E" D DD^%DT S DIEFY(0)=Y
DTOUT I $G(DIOUTAR)]"" D CALLOUT^DIEFU(DIOUTAR)
 Q
 ;
VERFLG(FLG,GDFLGS) ;
 N EI
 S EI=$TR(FLG,GDFLGS,"")
 I EI="" Q 1
 D BLD^DIALOG(301,EI,EI)
 Q 0
 ;
XA(DIEFF,DIEFIEN,DIEFFLD,DIEFNVAL,DIEFOVAL) ;
 N DA,DIEFCNOD,DOREPL
 S DIEFNVAL=$G(DIEFNVAL),DIEFOVAL=$G(DIEFOVAL)
 Q:DIEFNVAL=DIEFOVAL
 D DA(DIEFIEN,.DA)
 D XRFAUD^DIEF
 Q
 ;
FILENM(F) ;
 N NM
 S NM=$$FILENAME^DIALOGZ($$FNO^DILIBF(F)) ;**CCO/NI GET FILE NAME
 ;I NM="" <DO ERROR>
 Q NM
 ;
FLDNM(F,FLD) ;
 N NM,UP
 S NM=$$LABEL^DIALOGZ(F,FLD) ;**CCO/NI GET FIELD LABEL
 F  S UP=$G(^DD(F,0,"UP")) Q:'UP  D
 . S NM=NM_" in "_$P($G(^DD(F,0)),U,1)
 . S F=UP
 . Q
 ;I NM="" <DO ERROR>
 Q NM
