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

BDWRDR.m

Go to the documentation of this file.
BDWRDR ; IHS/CMI/LAB - MAIN DRIVER DW EXPORT ;
 ;;1.0;IHS DATA WAREHOUSE;**1,2,4**;JAN 23, 2006;Build 24
 ;
START ;EP - called from option
 K BDWDDR
 I $D(ZTQUEUED) S BDWO("SCHEDULED")=""
 S BDWO("RUN")="NEW" ;      Let BDWDRI know this is a new run.
 D ^BDWRDRI ;           Do initialization
 I $D(BDWO("QUEUE")) D EOJ W !!,"Okay, request queued!!",!! Q
 I BDW("QFLG")=99 D EOJ W !!,"Bye",!! Q
 I BDW("QFLG")=4 W:'$D(ZTQUEUED) !,"Contact your site manager.  ^BDWTMP still exists." D  D EOJ Q
 .S DIR(0)="EO",DIR("A")="Press any key to continue" K DA D ^DIR K DIR
 I BDW("QFLG") D ABORT Q
DRIVER ;EP called from TSKMN+2
 S BDW("BT")=$H
 D NOW^%DTC S BDW("RUN START")=%,BDW("MAIN TX DATE")=$P(%,".") K %,%H,%I
 S DIE="^BDWXLOG(",DA=BDW("RUN LOG"),DR=".15///R"_";.03////"_BDW("RUN START")_";.23////GDW" D ^DIE K DA,DIE,DR
 I BDW("QFLG") D ABORT Q
 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
 ;maw TODO uncomment this when ready to try the other messages
 D ALPMR^BDWRDR2  ;generate ALPMR patient centric messages
 I BDW("QFLG") D ABORT Q
 D LOG ;                Update Log
 I BDW("QFLG") D ABORT Q
 S BDWMSGT=$$DW1TRLR^BHLEVENT(90213,BDW("RUN LOG"))
 S ^BDWTMP(BDWIEDST,BDWMSGT)=""
 D PURGE ;              Purge ADW xref entries
 D RUNTIME
 S DA=BDW("RUN LOG"),DIE="^BDWXLOG(",DR=".13////"_BDWRUN_";.14////"_BDWMSGT_";.15////C" D ^DIE
 I BDW("QFLG") D ABORT Q
 D:'$D(ZTQUEUED) CHKLOG ;             See if Log needs cleaning
 I '$D(ZTQUEUED) S DIR(0)="EO",DIR("A")="DONE -- Press ENTER to Continue" K DA D ^DIR K DIR
 D EOJ
 Q
 ;
PROCESS ;
 D GIS^BDW1VBLI
 K ^TMP($J,"BDWTRAILER")
 I '$D(ZTQUEUED) W !,"Generating Registration HL7 messages (1)"
 S BDWMSGH=$$DW1HDR^BHLEVENT(90213,BDW("RUN LOG"))
 S ^BDWTMP(BDWIEDST,BDWMSGH)=""
 K DIE,DR,DA S DIE="^BDWXLOG(",DA=BDW("RUN LOG"),DR=".12////"_BDWMSGH D ^DIE K DIE,DA,DR
 S ^XTMP("BDWDR",0)=$$FMADD^XLFDT(DT,14)_U_DT_"DATA WAREHOUSE EXPORT"
 ;do patient registration first
 S (BDWDFN,BDWCNTR)=0 F  S BDWDFN=$O(^AUPNDWAF(BDWDFN)) Q:BDWDFN'=+BDWDFN  D  I '$D(ZTQUEUED) X BDWCNT
 .K INA("DELETE"),BDWDELF,BDWDELT
 .S INA=0  ;not backload
 .I '$D(^AUPNPAT(BDWDFN,0)) S DA=BDWDFN,DIK="^AUPNDWAF(" D ^DIK K DA,DIK Q
 .I '$D(^DPT(BDWDFN,0)) S DA=BDWDFN,DIK="^AUPNDWAF(" D ^DIK K DA,DIK Q
 .I $P(^DPT(BDWDFN,0),U)["DEMO,PATIENT" S DA=BDWDFN,DIK="^AUPNDWAF(" D ^DIK K DA,DIK Q
 .S BDWDELF=$P(^AUPNDWAF(BDWDFN,0),U,13),BDWDELT=$P(^DPT(BDWDFN,0),U,19)
 .I 'BDWDELF,'$$ORF^BDWUTIL1(BDWDFN) S DA=BDWDFN,DIK="^AUPNDWAF(" D ^DIK K DA,DIK Q  ;no originating facility hrn
 .K BDWR S BDWR("BASE")=$P(^AUPNDWAF(BDWDFN,0),U,2),BDWR("DEMO")=$P(^AUPNDWAF(BDWDFN,0),U,4),BDWR("ALIAS")=$P(^AUPNDWAF(BDWDFN,0),U,6),BDWR("CHART")=$P(^AUPNDWAF(BDWDFN,0),U,8),BDWR("ELIG")=$P(^AUPNDWAF(BDWDFN,0),U,11)
 .; set original flags for 4 segments
 .S BDWZRBFL=$$FLG^BDWBHL("ZRB",BDWDFN)
 .S BDWZRLFL=$$FLG^BDWBHL("ZRL",BDWDFN)
 .S BDWZRCFL=$$FLG^BDWBHL("ZRC",BDWDFN)
 .S BDWZRDFL=$$FLG^BDWBHL("ZRD",BDWDFN)
 .S BDWZINFL=$$FLG^BDWBHL("ZIN",BDWDFN)
 .I BDWDELF D
 ..S INA("DELETE")=BDWDFN
 ..S BDWRMSG=$$DW1MRG^BHLEVENT(BDWDELT,.INA)
 .I 'BDWDELF D
 ..S BDWRMSG=$$DW1REG^BHLEVENT(BDWDFN,.INA)
 .S ^BDWTMP(BDWIEDST,BDWRMSG)=""
 .S BDW("REG")=BDW("REG")+1
 .S ^XTMP("BDWDR","PATIENT REG",BDWDFN)=""
 .S:'$D(^BDWXLOG(BDW("RUN LOG"),41,0)) ^BDWXLOG(BDW("RUN LOG"),41,0)="^90213.4101PA^^"
 .S X=^AUPNDWAF(BDWDFN,0),^BDWXLOG(BDW("RUN LOG"),41,BDWDFN,0)=BDWDFN_U_$P(X,U,2)_U_$P(X,U,4)_U_$P(X,U,6)_U_$P(X,U,8)_U_$P(X,U,11)_U_BDWRMSG
 .S $P(^BDWXLOG(BDW("RUN LOG"),41,BDWDFN,0),U,13)=BDWDELF
 .S $P(^BDWXLOG(BDW("RUN LOG"),41,BDWDFN,0),U,8)=BDWZRBFL
 .S $P(^BDWXLOG(BDW("RUN LOG"),41,BDWDFN,0),U,9)=BDWZRLFL
 .S $P(^BDWXLOG(BDW("RUN LOG"),41,BDWDFN,0),U,10)=BDWZRCFL
 .S $P(^BDWXLOG(BDW("RUN LOG"),41,BDWDFN,0),U,11)=BDWZRDFL
 .S $P(^BDWXLOG(BDW("RUN LOG"),41,BDWDFN,0),U,12)=BDWZINFL
 .S $P(^BDWXLOG(BDW("RUN LOG"),41,0),U,3)=BDWDFN,$P(^(0),U,4)=$P(^(0),U,4)+1
 .K INA("DELETE"),BDWDELT,BDWDELF
 K BDWC,BDW("X"),BDWDFN,BDWRMSG
 W:'$D(ZTQUEUED) !!,"Generating transactions.  Counting encounters.  (1)"
 S BDWCNTR=0,BDW("CONTROL DATE")=BDW("RUN BEGIN")-1
 F  S BDW("CONTROL DATE")=$O(^AUPNVSIT("ADWO",BDW("CONTROL DATE"))) Q:BDW("CONTROL DATE")=""!(BDW("CONTROL DATE")>BDW("RUN END"))  D PROCESS2 Q:BDW("QFLG")
 Q
PROCESS2 ;
 S BDW("V DFN")="" F  S BDW("V DFN")=$O(^AUPNVSIT("ADWO",BDW("CONTROL DATE"),BDW("V DFN"))) Q:BDW("V DFN")=""  D PROCESS3 Q:BDW("QFLG")
 Q
PROCESS3 ;
 K BDWT,BDWV,BDWE
 D KILL^AUPNPAT
 Q:$D(^BDWXLOG(BDW("RUN LOG"),21,BDW("V DFN")))
 I '$D(^AUPNVSIT(BDW("V DFN"),0)) K ^AUPNVSIT("ADWO",BDW("CONTROL DATE"),BDW("V DFN")) Q
 S BDWV("TX GENERATED")=0,^XTMP("BDWDR",BDW("CONTROL DATE"),BDW("V DFN"))="",^XTMP("BDWDR","MAIN TX",BDW("V DFN"))=""
 S BDW("VPROC")=$G(BDW("VPROC"))+1
 X BDWCNT
 S BDWV("V REC")=^AUPNVSIT(BDW("V DFN"),0)
 I BDWO("RUN")="NEW",$P(BDWV("V REC"),U,11),$P($G(^AUPNVSIT(BDW("V DFN"),11)),U,6)="" D  G SET
 .K ^AUPNVSIT("ADWO",BDW("CONTROL DATE"),BDW("V DFN")) S BDWE("ERROR")=100,BDW("DEL")=BDW("DEL")+1 D ^BDWRERR
 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
 K BDWVMSG D ^BDWRDR2
SET S:'$D(^BDWXLOG(BDW("RUN LOG"),21,0)) ^BDWXLOG(BDW("RUN LOG"),21,0)="^90213.2101PA^^"
 S ^BDWXLOG(BDW("RUN LOG"),21,BDW("V DFN"),0)=BDW("V DFN")_U_BDWV("TX GENERATED")_U_$G(BDWVMSG)
 S $P(^BDWXLOG(BDW("RUN LOG"),21,0),U,3)=BDW("V DFN"),$P(^(0),U,4)=$P(^(0),U,4)+1
 K DIE,DR,DIC
 Q
 ;
PURGE ; PURGE 'ADW' XREF FOR VISITS JUST DONE
 W:'$D(ZTQUEUED) !,"Deleting cross-reference entries. (1)"
 S BDWCNTR=0,BDWV("V DATE")=0
 F  S BDWV("V DATE")=$O(^XTMP("BDWDR",BDWV("V DATE"))) Q:BDWV("V DATE")'=+BDWV("V DATE")  D PURGE2
 K ^XTMP("BDWDR")
 Q
PURGE2 ;
 S BDW("V DFN")="" F  S BDW("V DFN")=$O(^XTMP("BDWDR",BDWV("V DATE"),BDW("V DFN"))) Q:BDW("V DFN")=""  D RESET
 Q
 ;
RESET ; kill ADW xref and set flag if tx 23 or 24 generated
 K ^AUPNVSIT("ADWO",BDWV("V DATE"),BDW("V DFN"))
 I ^XTMP("BDWDR","MAIN TX",BDW("V DFN"))]"" S DIE="^AUPNVSIT(",DA=BDW("V DFN"),DR="1106///"_^XTMP("BDWDR","MAIN TX",BDW("V DFN")) D ^DIE K DA,DIE,DR
 X BDWCNT
 Q
 ;
RST4AF(BDWLOG) ;EP
 S BDWX=0 F  S BDWX=$O(^BDWXLOG(BDWLOG,41,BDWX)) Q:BDWX'=+BDWX  D
 .Q:'$D(^AUPNPAT(BDWX,0))
 .Q:'$D(^DPT(BDWX,0))
 .I '$P(^DPT(BDWX,0),U,19) D
 ..S Y=^AUPNDWAF(BDWX,0),DA=BDWX,DIE="^AUPNPAT(",DR=".41///"_$P(Y,U,2)_";.42////"_$P(Y,U,4)_";.43////"_$P(Y,U,6)_";.44////"_$P(Y,U,8)_";.45////"_$P(Y,U,11)
 ..D ^DIE K DA,DIE,DR
 .S DA=BDWX,DIK="^AUPNDWAF(" D ^DIK K DA,DIK
 Q
CHKLOG ; CHECK LOG FILE
 S BDW("X")=0 F BDW("I")=BDW("RUN LOG"):-1:1 Q:'$D(^BDWXLOG(BDW("I")))  I $O(^BDWXLOG(BDW("I"),21,0)) S BDW("X")=BDW("X")+1
 I BDW("X")>25 W !,"-->There are more than 25 generations of ENCOUNTERs stored in the LOG file.",!,"-->Time to do a purge."
 Q
 ;
ABORT ; ABNORMAL TERMINATION
 I $D(BDW("RUN LOG")) S BDW("QFLG1")=$O(^BDWERRC("B",BDW("QFLG"),"")),DA=BDW("RUN LOG"),DIE="^BDWXLOG(",DR=".15///F;.16////"_BDW("QFLG1")
 I $D(ZTQUEUED) D ERRBULL^BDWRDRI2,EOJ Q
 W !!,"Abnormal termination!!  QFLG=",BDW("QFLG")
 S DIR(0)="EO",DIR("A")="Press any key to continue" K DA D ^DIR K DIR
 D EOJ
 Q
 ;
LOG ; UPDATE LOG
 S BDW("COUNT")=BDW("REG")+BDW("VISITS")+$G(BDW("ALPMR")) W:'$D(ZTQUEUED) !!,BDW("COUNT")," HL7 Messages were generated."
 W:'$D(ZTQUEUED) !,"Updating log entry."
 D NOW^%DTC S BDW("RUN STOP")=%
 S DA=BDW("RUN LOG"),DIE="^BDWXLOG(",DR=".04////"_BDW("RUN STOP")_";.05////"_BDW("SKIP")_";.06////"_BDW("COUNT")_";.08///"_BDW("VPROC") D ^DIE I $D(Y) S BDW("QFLG")=26 Q
 K DIE,DA,DR
 S DA=BDW("RUN LOG"),DIE="^BDWXLOG(",DR=".11////"_BDW("REG")_";.12////"_BDWMSGH_";.18////"_$G(BDW("VISITS"))_";.19////"_$G(BDW("ALPMR")) D ^DIE I $D(Y) S BDW("QFLG")=26 Q
 K DR,DIE,DA,DIV,DIU
 S DIE="^BDWXLOG(",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")_";3111////"_BDW("MFI")
 D ^DIE I $D(Y) S BDW("QFLG")=26 Q
 K DR,DIE,DA,DIV,DIU
 S DIE="^BDWXLOG(",DA=BDW("RUN LOG"),DR="3108////"_BDW("ADDS")_";3109////"_BDW("MODS")_";3110////"_BDW("DELS")
 D ^DIE I $D(Y) S BDW("QFLG")=26 Q
TR ;trailer report
 S BDWLOC=0,BDWLOCC=0,BDWTYPE="",BDWMODE="",BDWDATE="",BDWLC=0
 S X="EXPORT SITE: "_$$VAL^XBDIQ1(90213,BDW("RUN LOG"),.09) D S
 S X="DATE OF EXPORT: "_$$FMTE^XLFDT($P($P(^BDWXLOG(BDW("RUN LOG"),0),U,3),".")) D S
 S X="TOTAL NUMBER OF ENCOUNTERS EXPORTED: "_$P(^BDWXLOG(BDW("RUN LOG"),0),U,18) D S
 S X="TOTAL NUMBER OF ADDS: "_$$VAL^XBDIQ1(90213,BDW("RUN LOG"),3108) D S
 S X="TOTAL NUMBER OF MODS: "_$$VAL^XBDIQ1(90213,BDW("RUN LOG"),3109) D S
 S X="TOTAL NUMBER OF DELETES: "_$$VAL^XBDIQ1(90213,BDW("RUN LOG"),3110) D S
 ;cmi/maw alpmr follows
 S X="TOTAL NUMBER OF PATIENT RECORDS EXPORTED: "_$$VAL^XBDIQ1(90213,BDW("RUN LOG"),.19) D S
 S X="" D S
 S X="" D S
 F  S BDWLOC=$O(^TMP($J,"BDWTRAILER",BDWLOC)) Q:BDWLOC'=+BDWLOC  D
 .S BDWLC=BDWLC+1,BDWLOCC=BDWLOCC+1
 .S X=BDWLOCC_".  Location of Encounter "_$P(^AUTTLOC(BDWLOC,0),U,10) D S
 .S X="" D S
 .S X="Type/Cat",$E(X,30)="TOTAL COUNT",$E(X,49)="ADDS",$E(X,58)="DELETES",$E(X,70)="CHANGES" D S
 .S X="---------------------------------------------------------------------------" D S
 .S BDWTYPE="" F  S BDWTYPE=$O(^TMP($J,"BDWTRAILER",BDWLOC,"TYPE",BDWTYPE)) Q:BDWTYPE=""  D
 ..S X=BDWTYPE,$E(X,33)=$$C($G(^TMP($J,"BDWTRAILER",BDWLOC,"TYPE",BDWTYPE,"TOT")),0,9),$E(X,46)=$$C($G(^TMP($J,"BDWTRAILER",BDWLOC,"TYPE",BDWTYPE,"A")),0,9)
 ..S $E(X,58)=$$C($G(^TMP($J,"BDWTRAILER",BDWLOC,"TYPE",BDWTYPE,"D")),0,9),$E(X,70)=$$C($G(^TMP($J,"BDWTRAILER",BDWLOC,"TYPE",BDWTYPE,"M")),0,9)
 ..D S
 .S X="" D S
 .S X="" D S
 .S X="COUNT BY DATE OF ENCOUNTERS" D S
 .S X="TYPE/CAT",$E(X,33)="MONTH/YR",$E(X,49)="TOTAL" D S
 .S X="---------------------------------------------------------------------------" D S
 .S BDWTYPE="" F  S BDWTYPE=$O(^TMP($J,"BDWTRAILER",BDWLOC,"DATE",BDWTYPE)) Q:BDWTYPE=""  D
 ..S BDWDATE=0 F  S BDWDATE=$O(^TMP($J,"BDWTRAILER",BDWLOC,"DATE",BDWTYPE,BDWDATE)) Q:BDWDATE=""  D
 ...S X=BDWTYPE,$E(X,33)=$$FMTE^XLFDT(BDWDATE),$E(X,46)=$$C(^TMP($J,"BDWTRAILER",BDWLOC,"DATE",BDWTYPE,BDWDATE),0,9) D S
 ...Q
 ..Q
 .S X="" D S
 .S X="" D S
 .Q
 S ^BDWXLOG(BDW("RUN LOG"),99,0)="^^"_BDWLC_"^"_BDWLC_"^"_DT
 S DA=BDW("RUN LOG"),DIK="^BDWXLOG(" D IX1^DIK K DA,DIK
 D ^XBFMK
 ;
 Q
C(X,X2,X3) ;
 I X="" Q ""
 D COMMA^%DTC
 Q X
S ;
 S BDWLC=BDWLC+1
 S ^BDWXLOG(BDW("RUN LOG"),99,BDWLC,0)=X
 K X
 Q
EOJ ; EOJ
 K ^TMP($J)
 K AUPNVSIT
 K DIADD,DLAYGO
 D ^XBFMK
 D KILL^AUPNPAT
 D EN^XBVK("BDW"),EN^XBVK("APCD")
 I $D(ZTQUEUED) S ZTREQ="@"
 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 BDWRUN=H_"."_M_"."_S
 K B,E,H,M,S,T
 Q
QUEUE ;EP - called from option that can be scheduled to run automatically
 K BDWDDR
 I $D(ZTQUEUED) S BDWO("SCHEDULED")=""
 S BDWO("RUN")="NEW" ;      Let BDWDRI know this is a new run.
 D ^BDWRDRI ;           Do initialization
 I BDW("QFLG") D ABORT Q
 D DRIVER
 Q