Home   Package List   Routine Alphabetical List   Global Alphabetical List   FileMan Files List   FileMan Sub-Files List   Package Component Lists   Package-Namespace Mapping  
Routine: DDMP

DDMP.m

Go to the documentation of this file.
  1. DDMP ;SFISC/DPC-IMPORT ASCII DATA ;9/23/96 14:58
  1. ;;22.0;VA FileMan;;Mar 30, 1999
  1. ;Per VHA Directive 10-93-142, this routine should not be modified.
  1. FILE(DDMPF,DDMPFLDS,DDMPFLG,DDMPFSRC,DDMPFMT) ;
  1. ;API for import tool.
  1. ;DDMPF - file# of primary import file.
  1. ;DDMPFLDS (by ref or value) - 1) name of import template (in [])
  1. ; 2) ;-delimited fields array. Primary file in top element.
  1. ; Other nodes subscripted by subfile#.
  1. ;DDMPFLG (by ref.) - ("FLAGS"): 'E'xternal; 'F'ile contains specs
  1. ; ("MSGS"): Root to contain error messages.
  1. ; ("MAXERR"): Maximum # of errors allowed.
  1. ; ("IOP"): Device for report printing.
  1. ; ("QTIME"): Queue import time.
  1. ;DDMPFSRC (by ref.) -("PATH"): Path to source file
  1. ; ("FILE"): Source file name.
  1. ;DDMPFMT (by value or ref.) - 1) top node = foreign format.
  1. ; 2) ("FDELIM"): Field delimiter.
  1. ; ("FIXED"): YES if fixed format.
  1. ; ("QUOTED"): YES if delimited fields quoted.
  1. ;
  1. I '$D(DIQUIET) N DIQUIET S DIQUIET=1
  1. I '$D(DIFM) N DIFM S DIFM=1 D INIZE^DIEFU
  1. N DDMPNCNT
  1. S DDMPFLG=$G(DDMPFLG("FLAGS"),$G(DDMPFLG)) I '$$VERFLG^DIEFU(DDMPFLG,"FE") G OUT
  1. S DDMPFLG("MAXERR")=$G(DDMPFLG("MAXERR"),1000)
  1. S DDMPFSRC("PATH")=$G(DDMPFSRC("PATH"))
  1. I $G(DDMPFSRC("FILE"))="" D BLD^DIALOG(202,"host source file","host source file") G OUT
  1. D GETFMT^DDMP1(.DDMPFMT) G:$G(DIERR) OUT
  1. D GETSRC^DDMP1(.DDMPFSRC) G:'$D(^TMP($J,"DDMP")) OUT
  1. S DDMPNCNT=$O(^TMP($J,"DDMP",""))
  1. I DDMPFLG["F" D G:$G(DIERR) OUT
  1. . I $G(DDMPF)'=""!($D(DDMPFLDS)&($G(DDMPFLDS)'="")) D BLD^DIALOG(1833) Q
  1. . D INFILE^DDMP1("^TMP($J,""DDMP"")",.DDMPFMT,.DDMPF,.DDMPFLDS,.DDMPNCNT)
  1. E I $G(DDMPF)=""!('$D(DDMPFLDS)) D BLD^DIALOG(202,"file or the fields","file or the fields") G OUT
  1. I DDMPNCNT="" D BLD^DIALOG(1812,DDMPFSRC("FILE"),DDMPFSRC("FILE")) G OUT
  1. I $E($G(DDMPFLDS))="[" N DDMPERR D G:DDMPERR'=$G(DIERR) OUT ;import template processing
  1. . S DDMPERR=$G(DIERR)
  1. . D TMPL2DR^DDMP1(DDMPF,.DDMPFLDS)
  1. S DDMPFLDS(DDMPF)=$G(DDMPFLDS(DDMPF),$G(DDMPFLDS))
  1. I '$$RQIDOK^DDMP1(.DDMPFLDS) G OUT
  1. N DDMPSQ,DDMPFIEN S (DDMPSQ,DDMPFIEN)=0
  1. D FLDBLD(DDMPF,.DDMPFLDS,.DDMPSQ,.DDMPFIEN,1) G:$G(DIERR) OUT
  1. N DDMPIOP,ZTSK,POP ;Device and queuing setup.
  1. D DEV^DDMP2(.DDMPFLG,.DDMPIOP)
  1. I $G(DDMPIOP("NG")) D BLD^DIALOG(1850) G OUT
  1. I $G(DDMPIOP("Q")) D QUE^DDMP2(.DDMPIOP) G OUT
  1. TASK ;Entry point for queued imports. If not queued, processing continues.
  1. N DDMPRPSB,DDMPLN,DDMPSTAT,POP
  1. D REP1^DDMP2(.DDMPRPSB,.DDMPLN)
  1. S DDMPSTAT("BEG")=$H,(DDMPSTAT("TOT"),DDMPSTAT("NG"))=0
  1. D PUTDRVR(.DDMPSQ,.DDMPFMT,.DDMPFLG,DDMPNCNT,.DDMPSTAT)
  1. D REP2^DDMP2(DDMPRPSB,DDMPLN,.DDMPSTAT)
  1. OUT I $D(ZTQUEUED) D
  1. . S ZTREQ="@"
  1. . D CLEAN^DIEFU
  1. E I $G(DDMPFLG("MSGS"))]"" D CALLOUT^DIEFU(DDMPFLG("MSGS"))
  1. K ^TMP($J,"DDMP")
  1. ;K ^XTMP(DDMPRPSB) ;Deletes the report from XTMP
  1. Q
  1. ;
  1. FLDBLD(DDMPF,DDMPFLDS,DDMPSQ,DDMPFIEN,DDMPTFIX) ;
  1. N DDMPI,DDMPNFLD,DDMPNIEN,DDMPINFD
  1. S DDMPFIEN=DDMPFIEN+1
  1. S DDMPNIEN="+"_DDMPFIEN_","_$G(DDMPFIEN("UP",DDMPF))
  1. F DDMPI=1:1 S DDMPINFD=$P(DDMPFLDS(DDMPF),";",DDMPI) Q:DDMPINFD="" D Q:$G(DIERR)
  1. . I DDMPINFD'["[" S DDMPNFLD=DDMPINFD
  1. . E N DDMPOFIX S DDMPNFLD=+DDMPINFD,DDMPOFIX=$P($P(DDMPINFD,"]"),"[",2)
  1. . I '$$VFIELD^DIEFU(DDMPF,DDMPNFLD,"D") Q
  1. . N DDMP0P2
  1. . S DDMP0P2=$P($G(^DD(DDMPF,DDMPNFLD,0)),U,2)
  1. . I +DDMP0P2 D Q
  1. . . N DDMPDWF
  1. . . I $P($G(^DD(+DDMP0P2,.01,0)),U,2)["W" D Q
  1. . . . N DDMPE S DDMPE(1)="word processing",DDMPE("FILE")=DDMPF,DDMPE("FIELD")=DDMPNFLD
  1. . . . D BLD^DIALOG(520,"word processing",.DDMPE)
  1. . . S DDMPDWF=+DDMP0P2
  1. . . S DDMPFIEN("UP",DDMPDWF)=DDMPNIEN
  1. . . I '$D(DDMPFLDS(DDMPDWF)) D Q
  1. . . . N DDMPP S DDMPP("FILE")=DDMPDWF
  1. . . . D BLD^DIALOG(525,.DDMPP,.DDMPP)
  1. . . D FLDBLD(DDMPDWF,.DDMPFLDS,.DDMPSQ,.DDMPFIEN,DDMPTFIX)
  1. . S DDMPSQ=DDMPSQ+1
  1. . I DDMPFMT("FIXED")="YES",'$G(DDMPOFIX) D BLD^DIALOG(1822)
  1. . S DDMPSQ(DDMPSQ)=DDMPF_"~"_DDMPNIEN_"~"_DDMPNFLD_"~"_$G(DDMPOFIX)
  1. Q
  1. ;
  1. PUTDRVR(DDMPSQ,DDMPFMT,DDMPFLG,DDMPNODE,DDMPSTAT) ;
  1. ;Sets up FDA and files data.
  1. ;DDMPSQ (by reference): Contains specs for each field.
  1. ;DDMPFMT (by reference): Format of imcoming data
  1. ;DDMPFLG (by reference): Import control info.
  1. ;DDMPNODE (by value): Number of first node containing data.
  1. N DDMPTPAR,DDMPNDCT,DDMPUPFG,DDMPREF
  1. I DDMPFLG["E" S DDMPUPFG="E"
  1. S DDMPNDCT=1
  1. S DDMPREF=$NA(^TMP($J,"DDMP",DDMPNODE))
  1. S DDMPTPAR(1)=^TMP($J,"DDMP",DDMPNODE)
  1. F S DDMPREF=$Q(@DDMPREF) Q:DDMPREF'[($J_",""DDMP""") D Q:$G(DDMPSTAT("ABORT"))
  1. . I DDMPREF'["OVF" D
  1. . . D RECPROC
  1. . . K DDMPTPAR S DDMPNDCT=0
  1. . S DDMPNDCT=DDMPNDCT+1
  1. . S DDMPTPAR(DDMPNDCT)=@DDMPREF
  1. I $G(DDMPSTAT("ABORT")) Q
  1. D RECPROC
  1. Q
  1. ;
  1. RECPROC ; Files a record from DDMPTPAR()
  1. N DDMPIENS
  1. K ^TMP($J,"DDMPFDA")
  1. D TOT(.DDMPSTAT) Q:$G(DDMPSTAT("ABORT"))
  1. D PARSE(.DDMPSQ,.DDMPTPAR,DDMPNDCT)
  1. I '$D(^TMP($J,"DDMPFDA")) D RECERR Q
  1. D UPDATE^DIE($G(DDMPUPFG),"^TMP($J,""DDMPFDA"")","DDMPIENS")
  1. I $G(DIERR) D
  1. . D RECERR
  1. E I DDMPSTAT("TOT")-DDMPSTAT("NG")>1 S DDMPSTAT("LIEN")=DDMPIENS(1)
  1. E S (DDMPSTAT("FIEN"),DDMPSTAT("LIEN"))=DDMPIENS(1)
  1. Q
  1. ;
  1. TOT(DDMPSTAT) ;
  1. S DDMPSTAT("TOT")=DDMPSTAT("TOT")+1
  1. I '$D(ZTQUEUED) W "."
  1. E I DDMPSTAT("TOT")#10=0,$$S^%ZTLOAD D
  1. . S DDMPSTAT("ABORT")=2
  1. . S ZTSTOP=1
  1. Q
  1. ;
  1. RECERR ;
  1. N DDMPERLN,DDMPERR
  1. S DDMPSTAT("NG")=DDMPSTAT("NG")+1
  1. D LDXTMP^DDMP2("Record #"_DDMPSTAT("TOT")_" Rejected:")
  1. D MSG^DIALOG("AEB",.DDMPERR,$S($D(IOM):IOM-5,1:75))
  1. S DDMPERLN=0
  1. F S DDMPERLN=$O(DDMPERR(DDMPERLN)) Q:'DDMPERLN D LDXTMP^DDMP2(" "_DDMPERR(DDMPERLN))
  1. D CLEAN^DIEFU
  1. I DDMPSTAT("NG")'<DDMPFLG("MAXERR") S DDMPSTAT("ABORT")=1
  1. Q
  1. ;
  1. PARSE(DDMPSQ,DDMPTPAR,DDMPNDCT) ;
  1. N DDMPQ,DDMPHOLD,DDMPIN,DDMPI,DDMPTVAL,DDMPVAL
  1. I DDMPTPAR(1)="" D BLD^DIALOG(1860) Q
  1. S DDMPQ="""",DDMPSQ=0
  1. F DDMPI=1:1:DDMPNDCT S DDMPIN=DDMPTPAR(DDMPI) F Q:DDMPIN=""!($G(DIERR)) D
  1. . I $G(DDMPFMT("QUOTED"))="YES",($E(DDMPIN)=DDMPQ!($E($G(DDMPHOLD))=DDMPQ)) D
  1. . . I $G(DDMPHOLD)]"" D
  1. . . . I DDMPHOLD'=DDMPQ,$E(DDMPHOLD,$L(DDMPHOLD))=DDMPQ D
  1. . . . . S DDMPVAL=DDMPHOLD,DDMPHOLD=""
  1. . . . . S DDMPIN=$P(DDMPIN,DDMPFMT("FDELIM"),2,99)
  1. . . . E D
  1. . . . . S DDMPVAL=DDMPHOLD_$P(DDMPIN,DDMPQ)_DDMPQ,DDMPHOLD=""
  1. . . . . S DDMPIN=$P($P(DDMPIN,DDMPQ,2,99),DDMPFMT("FDELIM"),2,99)
  1. . . E D
  1. . . . S DDMPTVAL=$P(DDMPIN,DDMPQ,1,2)_$S($L(DDMPIN,DDMPQ)>2:DDMPQ,1:"")
  1. . . . S DDMPIN=$P(DDMPIN,DDMPTVAL,2)
  1. . . . I DDMPIN=DDMPFMT("FDELIM") S DDMPIN="",DDMPVAL=DDMPTVAL Q
  1. . . . S DDMPIN=$P(DDMPIN,DDMPFMT("FDELIM"),2,99)
  1. . . . I DDMPIN="",DDMPI'=DDMPNDCT S DDMPHOLD=DDMPTVAL Q
  1. . . . S DDMPVAL=DDMPTVAL
  1. . E I $G(DDMPFMT("FDELIM"))'="" D
  1. . . S DDMPTVAL=$P(DDMPIN,DDMPFMT("FDELIM"))
  1. . . I $L(DDMPIN,DDMPFMT("FDELIM"))=2,$P(DDMPIN,DDMPFMT("FDELIM"),2)="" S DDMPIN="",DDMPVAL=$G(DDMPHOLD)_DDMPTVAL,DDMPHOLD="" Q
  1. . . S DDMPIN=$P(DDMPIN,DDMPFMT("FDELIM"),2,99)
  1. . . I $G(DDMPHOLD)]"" S DDMPVAL=DDMPHOLD_DDMPTVAL,DDMPHOLD="" Q
  1. . . I DDMPIN="",DDMPI'=DDMPNDCT S DDMPHOLD=DDMPTVAL Q
  1. . . S DDMPVAL=DDMPTVAL
  1. . E D
  1. . . N DDMPLEN,DDMPLAST
  1. . . I '$D(DDMPSQ(DDMPSQ+1)) D BLD^DIALOG(1862) Q
  1. . . S DDMPLEN=$P(DDMPSQ(DDMPSQ+1),"~",4)
  1. . . I $G(DDMPHOLD)]"" D
  1. . . . S DDMPVAL=DDMPHOLD_$E(DDMPIN,1,DDMPLEN-$L(DDMPHOLD))
  1. . . . S DDMPIN=$E(DDMPIN,DDMPLEN-$L(DDMPHOLD)+1,255)
  1. . . . S DDMPHOLD=""
  1. . . E D
  1. . . . S DDMPTVAL=$E(DDMPIN,1,DDMPLEN)
  1. . . . S DDMPIN=$E(DDMPIN,DDMPLEN+1,255)
  1. . . . I DDMPIN="",DDMPI'=DDMPNDCT S DDMPHOLD=DDMPTVAL Q
  1. . . . S DDMPVAL=DDMPTVAL
  1. . . I $D(DDMPVAL) F S DDMPLAST=$L(DDMPVAL) Q:$E(DDMPVAL,DDMPLAST)'=" " S DDMPVAL=$E(DDMPVAL,1,DDMPLAST-1)
  1. . I $D(DDMPVAL) D K DDMPVAL
  1. . . S DDMPSQ=DDMPSQ+1
  1. . . I '$D(DDMPSQ(DDMPSQ)) D BLD^DIALOG(1862) Q
  1. . . I $G(DDMPFMT("QUOTED"))="YES" S DDMPVAL=$TR(DDMPVAL,DDMPQ)
  1. . . D FDASET(DDMPVAL,DDMPSQ(DDMPSQ))
  1. I $G(DDMPFMT("FIXED"))="YES" F DDMPSQ=DDMPSQ+1:1 Q:'$D(DDMPSQ(DDMPSQ)) S DDMPVAL="" D FDASET(DDMPVAL,DDMPSQ(DDMPSQ))
  1. Q
  1. ;
  1. FDASET(DDMPVAL,DDMPSPEC) ;
  1. S ^TMP($J,"DDMPFDA",$P(DDMPSPEC,"~"),$P(DDMPSPEC,"~",2),$P(DDMPSPEC,"~",3))=DDMPVAL
  1. Q
  1. ;