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