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

BDW1VBL.m

Go to the documentation of this file.
BDW1VBL ; IHS/CMI/LAB - MAIN DRIVER DW VISIT BACKLOAD ;
 ;;1.0;IHS DATA WAREHOUSE;**2**;JAN 23, 2006
 ;
START ;EP - called from option
 I $O(^BDWDATA(0)) W !!,"Last run not finished., BDWDATA exists." K DIR S DIR(0)="E" D ^DIR K DIR Q
 S X=$O(^INRHD("B","HL IHS DW1 IE",0))
 I $D(^BDWTMP(X)) W !!,"previous DW export not written to host file" K DIR S DIR(0)="E" D ^DIR K DIR Q
 K ^BDWTMP(X)
 K ^BDWDATA
 D EN^XBVK("BDW")
 D ^BDW1VBLI
 I BDW("QFLG") D EOJ W !!,"Bye",!! Q
 I $D(BDWO("QUEUE")) D EOJ W !!,"Okay, request queued!!",!! Q
 I BDW("QFLG")=99 D EOJ W !!,"Bye",!! Q
DRIVER ;EP called from TSKMN+2
 D JRNL
 S BDW("BT")=$H
 D NOW^%DTC S BDW("RUN START")=%,BDW("MAIN TX DATE")=$P(%,".") K %,%H,%I
 S BDWX=$$DW1HDR^BHLEVENT(90214,BDW("RUN LOG"))
 S ^BDWTMP(BDWIEDST,BDWX)=""
 S DIE="^BDWBLOG(",DA=BDW("RUN LOG"),DR=".15////R"_";.03////"_BDW("RUN START")_";.12////"_$G(BDWX) D ^DIE K DA,DIE,DR
 S BDWCNT=$S('$D(ZTQUEUED):"X BDWCNT1  X BDWCNT2",1:"S BDWCNTR=BDWCNTR+1"),BDWCNT1="F BDWCNTL=1:1:$L(BDWCNTR)+1 W @BDWBS",BDWCNT2="S BDWCNTR=BDWCNTR+1 W BDWCNTR,"")"""
 D PROCESS ;            Generate trasactions
 I BDW("QFLG") D ABORT Q
 D LOGEND ;                Update Log
 S X=$$WRITE^BDW1VBLI
 I BDW("QFLG") D ABORT Q
 I '$D(ZTQUEUED) S DIR(0)="EO",DIR("A")="DONE -- Press ENTER to Continue" K DA D ^DIR K DIR
 D EOJ
 Q
 ;
PROCESS ;
 W:'$D(ZTQUEUED) !,"Generating transactions.  Counting visits.  (1)"
 S BDWCNTR=0,BDW("CONTROL DATE")=BDW("RUN BEGIN")-1,BDW("CONTROL DATE")=BDW("CONTROL DATE")_".9999"
 F  S BDW("CONTROL DATE")=$O(^AUPNVSIT("B",BDW("CONTROL DATE"))) Q:BDW("CONTROL DATE")=""!($P(BDW("CONTROL DATE"),".")>BDW("RUN END"))  D PROCESS2 Q:BDW("QFLG")
 I BDW("RUN END")=$P(^BDWSITE(1,0),U,2) S $P(^BDWSITE(1,0),U,6)=DT
 Q
PROCESS2 ;
 S BDW("V DFN")="" F  S BDW("V DFN")=$O(^AUPNVSIT("B",BDW("CONTROL DATE"),BDW("V DFN"))) Q:BDW("V DFN")=""  D PROCESS3 Q:BDW("QFLG")
 Q
PROCESS3 ;
 K BDWT,BDWV,BDWE
 D KILL^AUPNPAT
 I '$D(^AUPNVSIT(BDW("V DFN"),0)) K ^AUPNVSIT("B",BDW("CONTROL DATE"),BDW("V DFN")) Q
 S BDW("VPROC")=$G(BDW("VPROC"))+1
 X BDWCNT
 S BDWV("V REC")=^AUPNVSIT(BDW("V DFN"),0)
 I $P(BDWV("V REC"),U,11) S BDW("DEL")=BDW("DEL")+1,BDWE("ERROR")=100 D ^BDW1VBLE Q
 I '$P(BDWV("V REC"),U,9) S BDW("ZERO")=BDW("ZERO")+1,BDWE("ERROR")=102 D ^BDW1VBLE Q
 S X=$P(BDWV("V REC"),U,6)
 I 'X S BDWE("ERROR")="111",BDW("NO LOC")=BDW("NO LOC")+1 D ^BDW1VBLE Q
 I '$D(^AUTTLOC(X,0)) S BDWE("ERROR")="111",BDW("NO LOC")=BDW("NO LOC")+1 D ^BDW1VBLE Q
 S X=$P($G(^AUTTLOC(X,0)),U,10) I $E(X,1)=3,$P(BDWV("V REC"),U,23)=.5 S BDW("MFI")=BDW("MFI")+1,BDWE("ERROR")=140 D ^BDW1VBLE Q
 I $P($G(^AUPNVSIT(BDW("V DFN"),11)),U,4)="" D ^XBFMK S DIE="^AUPNVSIT(",DA=BDW("V DFN"),DR="1104////"_$$UID^AUPNVSIT(BDW("V DFN")) D ^DIE,^XBFMK
 I $P($G(^AUPNVSIT(BDW("V DFN"),11)),U,4)="" D ^XBFMK S DIE="^AUPNVSIT(",DA=BDW("V DFN"),DR="1114////"_$$UIDV^BDWAID(BDW("V DFN")) D ^DIE,^XBFMK  ;cmi/anch/maw 9/6/2007 patch 2
 S BDWV("V DATE")=+BDWV("V REC")\1
 D ^BDW1VBL2
 Q
 ;
LOGEND ;
 W:'$D(ZTQUEUED) !!,BDW("VISITS")," transactions were generated."
 W:'$D(ZTQUEUED) !,"Updating log entry."
 D NOW^%DTC S BDW("RUN STOP")=%
 D RUNTIME
 S DA=BDW("RUN LOG"),DIE="^BDWBLOG(",DR=".04////"_BDW("RUN STOP")_";.05////"_BDW("SKIP")_";.06////"_BDW("VISITS")_";.08///"_BDW("VPROC") D ^DIE I $D(Y) S BDW("QFLG")=26 Q
 S DA=BDW("RUN LOG"),DIE="^BDWBLOG(",DR=".18////"_$G(BDW("VISITS"))_";.15///C;.13///"_BDWRT D ^DIE I $D(Y) S BDW("QFLG")=26 Q
 K DR,DIE,DA,DIV,DIU
 S DIE="^BDWBLOG(",DA=BDW("RUN LOG"),DR="3101////"_BDW("DEMO")_";3102////"_BDW("ZERO")_";3103////"_BDW("DEL")_";3104////"_BDW("NO PAT")_";3105////"_BDW("NO LOC")_";3106////"_BDW("NO TYPE")_";3107////"_BDW("NO CAT")_";3108////"_BDW("MFI")
 D ^DIE I $D(Y) S BDW("QFLG")=26 Q
 S DA=BDW("RUN LOG"),DIK="^BDWBLOG(" D IX1^DIK K DA,DIK
 D ^XBFMK
 ;
 S BDWTM=$$DW1TRLR^BHLEVENT(90214,BDW("RUN LOG"))
 S ^BDWTMP(BDWIEDST,BDWTM)=""
 S DIE="^BDWBLOG(",DR=".14////"_$G(BDWTM),DA=BDW("RUN LOG") D ^DIE
 D ^XBFMK
 Q
 ;
 ;
JRNL ;
 N (DT,U,ZTQUEUED) S %=$$NOJOURN^ZIBGCHAR("BDWBLOG"),%=$$NOJOURN^ZIBGCHAR("BDWDATA")
 Q
RESET ;EP - kill ADW xref and set flag
 S X=$P(^AUPNVSIT(BDW("V DFN"),0),U,13) I X]"",$D(^AUPNVSIT("ADWO",X,BDW("V DFN"))) K ^AUPNVSIT("ADWO",X,BDW("V DFN"))
 S DIE="^AUPNVSIT(",DA=BDW("V DFN"),DR="1106///"_DT D ^DIE K DA,DIE,DR
 S DA=BDW("RUN LOG"),DIE="^BDWBLOG(",DR=".04////"_$$NOW^XLFDT_";.05////"_BDW("SKIP")_";.06////"_BDW("VISITS")_";.08///"_BDW("VPROC")_";.18////"_$G(BDW("VISITS"))_";.19////"_BDW("V DFN") D ^DIE
 K DR,DIE,DA,DIV,DIU
 S DIE="^BDWBLOG(",DA=BDW("RUN LOG"),DR="3101////"_BDW("DEMO")_";3102////"_BDW("ZERO")_";3103////"_BDW("DEL")_";3104////"_BDW("NO PAT")_";3105////"_BDW("NO LOC")_";3106////"_BDW("NO TYPE")_";3107////"_BDW("NO CAT")_";3108////"_BDW("MFI")
 D ^DIE I $D(Y) S BDW("QFLG")=26 Q
 K DIE,DA,DR,DIU,DIV
 ;S DA=BDW("RUN LOG"),DIK="^BDWBLOG(" D IX1^DIK K DA,DIK
 ;X BDWCNT
 Q
 ;
EOJ ; EOJ
 K ^BDWDATA
 K ^XTMP("BDWBLOG")
 K DIADD
 D ^XBFMK
 D KILL^AUPNPAT
 D EN^XBVK("BDW"),EN^XBVK("APCD")
 I $D(ZTQUEUED) S ZTREQ="@"
 Q
ABORT ; ABNORMAL TERMINATION
 D EOJ
 Q
 ;
RUNTIME ;EP - SHOW RUN 
 S B=BDW("BT")
 S E=$HOROLOG
 S T=(86400*($P(E,",")-$P(B,",")))+($P(E,",",2)-$P(B,",",2)),H=$P(T/3600,".")
 S:H="" H=0
 S T=T-(H*3600),M=$P(T/60,".")
 S:M="" M=0
 S T=T-(M*60),S=T
 W:'$D(ZTQUEUED) !!,"RUN TIME (H.M.S): ",H,".",M,".",S
 S BDWRT=H_"."_M_"."_S
 K B,E,H,M,S,T
 Q