DG53829P ; ALB/LBD - DG*5.3*829 POST INSTALL CLEAN-UP ROUTINE ; 4/11/11 9:37am
;;5.3;PIMS;**1016**;JUN 30, 2012;Build 20
;
EN ; Entry point for post installation routine DG*5.3*829
N ZTDESC,ZTDTH,ZTRTN,ZTSK,ZTIO
S ZTRTN="CLUP^DG53829P"
S ZTDESC="DG*5.3*829 Clean Up Merged Pt Recs in File #38.5"
S ZTIO="",ZTDTH=$$NOW^XLFDT
D ^%ZTLOAD
D BMES^XPDUTL("Clean Up Merged Patient Recs in File #38.5 started - task #"_$G(ZTSK))
Q
;
CLUP ; entry for deleting merged patient records from the
; INCONSISTENT DATA file (#38.5)
N DGNOW,DGCNT,DGREC,DFN,Z
I '$D(^XTMP("DG53829")) D
. S ^XTMP("DG53829",0)=$$FMADD^XLFDT(DT,180)_U_DT_U_"CLEAN UP MERGED PATIENT RECS IN FILE #38.5",^XTMP("DG53829","PARAMS")=""
S Z=$G(^XTMP("DG53829","PARAMS"))
I $P(Z,U,4)="RUNNING" D Q
. S DGNOW=$O(^XTMP("DG53829","RUNNING",""))
. D BULL(,,DGNOW,"RUNNING")
. S ^XTMP("DG53829","RUNNING",$$NOW^XLFDT)="CLEANUP ALREADY RUNNING"
I $P(Z,U,4)="DONE" D Q
. S DGNOW=$O(^XTMP("DG53829","RUNNING",""))
. D BULL(,,DGNOW,"DONE")
. S ^XTMP("DG53829","RUNNING",$$NOW^XLFDT)="CLEANUP ALREADY COMPLETED"
S $P(^XTMP("DG53829","PARAMS"),U,4)="RUNNING"
S DGNOW=$$NOW^XLFDT,^XTMP("DG53829","RUNNING",DGNOW)="",^XTMP("DG53829","RUNNING",DGNOW,+$G(ZTSK))=""
S DGCNT=+Z,DFN=+$P(Z,U,2),DGREC=+$P(Z,U,3)
; Loop through the INCONSISTENT DATA file (#38.5)
F S DFN=$O(^DGIN(38.5,DFN)) Q:'DFN Q:$$STOP(DGREC) D
. S DGREC=DGREC+1,$P(^XTMP("DG53829","PARAMS"),U,2,3)=DFN_U_DGREC
. ; If record is pointing to a merged patient in the PATIENT file (#2), delete it
. I $D(^DPT(DFN,-9)) D
.. N DA,DIK
.. S DIK="^DGIN(38.5,",DA=DFN D ^DIK
.. S DGCNT=DGCNT+1,$P(^XTMP("DG53829","PARAMS"),U,1)=DGCNT
.. S ^XTMP("DG53829","REC_DELETED",DFN)=""
S $P(^XTMP("DG53829","PARAMS"),U,4)=$S('$G(ZTSTOP):"DONE",1:"STOPPED"),^XTMP("DG53829","RUNNING",DGNOW)=$$NOW^XLFDT
D BULL(DGCNT,DGREC,DGNOW,'$G(ZTSTOP))
Q
;
BULL(DELETED,READ,WHEN,DONE) ; Send bulletin
N LN,TMP,XMDUZ,XMSUB,XMTEXT,XMY
S XMY(DUZ)="",XMY("G.DGEN ELIGIBILITY ALERT")="",XMDUZ=.5,XMTEXT="TMP("""_"DG53829"_""","
; Set up copay test 'links' deleted bulletin
S XMSUB="DG*5.3*829 - INCONSISTENT DATA FILE CLEANUP RESULTS"
S LN=1
S TMP("DG53829",LN)=""
I DONE="RUNNING" D Q
. S LN=LN+1
. S TMP("DG53829",LN)="Sorry, the INCONSISTENT DATA file (#38.5) clean up is already running."
. S LN=LN+1
. S TMP("DG53829",LN)=""
. S LN=LN+1
. S TMP("DG53829",LN)="Date/Time Started: "_WHEN
. S LN=LN+1
. S TMP("DG53829",LN)=""
. D ^XMD
I DONE="DONE" D Q
. S LN=LN+1
. S TMP("DG53829",LN)="Sorry, the INCONSISTENT DATA file (#38.5) clean up has already completed."
. S LN=LN+1
. S TMP("DG53829",LN)=""
. S LN=LN+1
. S TMP("DG53829",LN)="Date/Time Completed: "_$$FMTE^XLFDT($G(^XTMP("DG53829","RUNNING",WHEN)))
. D ^XMD
S LN=LN+1
S TMP("DG53829",LN)="This message contains the results of the job to clean up records in"
S LN=LN+1
S TMP("DG53829",LN)="the INCONSISTENT DATA file (#38.5). Patient records that pointed to"
S LN=LN+1
S TMP("DG53829",LN)="merged patients in the PATIENT file (#2) were deleted."
S LN=LN+1
S TMP("DG53829",LN)=""
S LN=LN+1
S TMP("DG53829",LN)="The cleanup has "_$S(DONE:"run to completion",1:"finished a partial run")_". Here are the results"_$S(DONE:"",1:" to date")_":"
S LN=LN+1
S TMP("DG53829",LN)=""
S LN=LN+1
S TMP("DG53829",LN)=" Start Date/Time: "_$$FMTE^XLFDT(WHEN)
S LN=LN+1
S TMP("DG53829",LN)=" End Date/Time: "_$$FMTE^XLFDT($G(^XTMP("DG53829","RUNNING",WHEN)))
S LN=LN+1
S TMP("DG53829",LN)=""
S LN=LN+1
S TMP("DG53829",LN)=" Total File #38.5 Records Processed: "_READ
S LN=LN+1
S TMP("DG53829",LN)="Total Merged Patient Records Deleted: "_DELETED
S LN=LN+1
S TMP("DG53829",LN)=""
S LN=LN+1
S TMP("DG53829",LN)="Deleted records are referenced in the global ^XTMP("""_"DG53829"_""",""REC_DELETED"""
S LN=LN+1
S TMP("DG53829",LN)=""
D ^XMD
Q
;
STOP(DGREC) ; Check if asked to stop
; Only check if tasked and every 1000 records read
Q:$S('$G(ZTSK):1,1:DGREC#1000) 0
N X
S X=$$S^%ZTLOAD
I X S ZTSTOP=1
Q $G(ZTSTOP)
;
;
RESTART ; Restart copay test invalid link
N ZTDESC,ZTDTH,ZTRTN,ZTSK,ZTIO
S $P(^XTMP("DG53829","PARAMS"),U,4)=""
S ZTRTN="CLUP^DG53829P"
S ZTDESC="DG*5.3*829 Clean Up Merged Pt Recs in File #38.5 Restart"
S ZTIO="",ZTDTH=$$NOW^XLFDT
D ^%ZTLOAD
W !,"TASK # IS: ",$G(ZTSK)
Q
;
DG53829P ; ALB/LBD - DG*5.3*829 POST INSTALL CLEAN-UP ROUTINE ; 4/11/11 9:37am
+1 ;;5.3;PIMS;**1016**;JUN 30, 2012;Build 20
+2 ;
EN ; Entry point for post installation routine DG*5.3*829
+1 NEW ZTDESC,ZTDTH,ZTRTN,ZTSK,ZTIO
+2 SET ZTRTN="CLUP^DG53829P"
+3 SET ZTDESC="DG*5.3*829 Clean Up Merged Pt Recs in File #38.5"
+4 SET ZTIO=""
SET ZTDTH=$$NOW^XLFDT
+5 DO ^%ZTLOAD
+6 DO BMES^XPDUTL("Clean Up Merged Patient Recs in File #38.5 started - task #"_$GET(ZTSK))
+7 QUIT
+8 ;
CLUP ; entry for deleting merged patient records from the
+1 ; INCONSISTENT DATA file (#38.5)
+2 NEW DGNOW,DGCNT,DGREC,DFN,Z
+3 IF '$DATA(^XTMP("DG53829"))
Begin DoDot:1
+4 SET ^XTMP("DG53829",0)=$$FMADD^XLFDT(DT,180)_U_DT_U_"CLEAN UP MERGED PATIENT RECS IN FILE #38.5"
SET ^XTMP("DG53829","PARAMS")=""
End DoDot:1
+5 SET Z=$GET(^XTMP("DG53829","PARAMS"))
+6 IF $PIECE(Z,U,4)="RUNNING"
Begin DoDot:1
+7 SET DGNOW=$ORDER(^XTMP("DG53829","RUNNING",""))
+8 DO BULL(,,DGNOW,"RUNNING")
+9 SET ^XTMP("DG53829","RUNNING",$$NOW^XLFDT)="CLEANUP ALREADY RUNNING"
End DoDot:1
QUIT
+10 IF $PIECE(Z,U,4)="DONE"
Begin DoDot:1
+11 SET DGNOW=$ORDER(^XTMP("DG53829","RUNNING",""))
+12 DO BULL(,,DGNOW,"DONE")
+13 SET ^XTMP("DG53829","RUNNING",$$NOW^XLFDT)="CLEANUP ALREADY COMPLETED"
End DoDot:1
QUIT
+14 SET $PIECE(^XTMP("DG53829","PARAMS"),U,4)="RUNNING"
+15 SET DGNOW=$$NOW^XLFDT
SET ^XTMP("DG53829","RUNNING",DGNOW)=""
SET ^XTMP("DG53829","RUNNING",DGNOW,+$GET(ZTSK))=""
+16 SET DGCNT=+Z
SET DFN=+$PIECE(Z,U,2)
SET DGREC=+$PIECE(Z,U,3)
+17 ; Loop through the INCONSISTENT DATA file (#38.5)
+18 FOR
SET DFN=$ORDER(^DGIN(38.5,DFN))
IF 'DFN
QUIT
IF $$STOP(DGREC)
QUIT
Begin DoDot:1
+19 SET DGREC=DGREC+1
SET $PIECE(^XTMP("DG53829","PARAMS"),U,2,3)=DFN_U_DGREC
+20 ; If record is pointing to a merged patient in the PATIENT file (#2), delete it
+21 IF $DATA(^DPT(DFN,-9))
Begin DoDot:2
+22 NEW DA,DIK
+23 SET DIK="^DGIN(38.5,"
SET DA=DFN
DO ^DIK
+24 SET DGCNT=DGCNT+1
SET $PIECE(^XTMP("DG53829","PARAMS"),U,1)=DGCNT
+25 SET ^XTMP("DG53829","REC_DELETED",DFN)=""
End DoDot:2
End DoDot:1
+26 SET $PIECE(^XTMP("DG53829","PARAMS"),U,4)=$SELECT('$GET(ZTSTOP):"DONE",1:"STOPPED")
SET ^XTMP("DG53829","RUNNING",DGNOW)=$$NOW^XLFDT
+27 DO BULL(DGCNT,DGREC,DGNOW,'$GET(ZTSTOP))
+28 QUIT
+29 ;
BULL(DELETED,READ,WHEN,DONE) ; Send bulletin
+1 NEW LN,TMP,XMDUZ,XMSUB,XMTEXT,XMY
+2 SET XMY(DUZ)=""
SET XMY("G.DGEN ELIGIBILITY ALERT")=""
SET XMDUZ=.5
SET XMTEXT="TMP("""_"DG53829"_""","
+3 ; Set up copay test 'links' deleted bulletin
+4 SET XMSUB="DG*5.3*829 - INCONSISTENT DATA FILE CLEANUP RESULTS"
+5 SET LN=1
+6 SET TMP("DG53829",LN)=""
+7 IF DONE="RUNNING"
Begin DoDot:1
+8 SET LN=LN+1
+9 SET TMP("DG53829",LN)="Sorry, the INCONSISTENT DATA file (#38.5) clean up is already running."
+10 SET LN=LN+1
+11 SET TMP("DG53829",LN)=""
+12 SET LN=LN+1
+13 SET TMP("DG53829",LN)="Date/Time Started: "_WHEN
+14 SET LN=LN+1
+15 SET TMP("DG53829",LN)=""
+16 DO ^XMD
End DoDot:1
QUIT
+17 IF DONE="DONE"
Begin DoDot:1
+18 SET LN=LN+1
+19 SET TMP("DG53829",LN)="Sorry, the INCONSISTENT DATA file (#38.5) clean up has already completed."
+20 SET LN=LN+1
+21 SET TMP("DG53829",LN)=""
+22 SET LN=LN+1
+23 SET TMP("DG53829",LN)="Date/Time Completed: "_$$FMTE^XLFDT($GET(^XTMP("DG53829","RUNNING",WHEN)))
+24 DO ^XMD
End DoDot:1
QUIT
+25 SET LN=LN+1
+26 SET TMP("DG53829",LN)="This message contains the results of the job to clean up records in"
+27 SET LN=LN+1
+28 SET TMP("DG53829",LN)="the INCONSISTENT DATA file (#38.5). Patient records that pointed to"
+29 SET LN=LN+1
+30 SET TMP("DG53829",LN)="merged patients in the PATIENT file (#2) were deleted."
+31 SET LN=LN+1
+32 SET TMP("DG53829",LN)=""
+33 SET LN=LN+1
+34 SET TMP("DG53829",LN)="The cleanup has "_$SELECT(DONE:"run to completion",1:"finished a partial run")_". Here are the results"_$SELECT(DONE:"",1:" to date")_":"
+35 SET LN=LN+1
+36 SET TMP("DG53829",LN)=""
+37 SET LN=LN+1
+38 SET TMP("DG53829",LN)=" Start Date/Time: "_$$FMTE^XLFDT(WHEN)
+39 SET LN=LN+1
+40 SET TMP("DG53829",LN)=" End Date/Time: "_$$FMTE^XLFDT($GET(^XTMP("DG53829","RUNNING",WHEN)))
+41 SET LN=LN+1
+42 SET TMP("DG53829",LN)=""
+43 SET LN=LN+1
+44 SET TMP("DG53829",LN)=" Total File #38.5 Records Processed: "_READ
+45 SET LN=LN+1
+46 SET TMP("DG53829",LN)="Total Merged Patient Records Deleted: "_DELETED
+47 SET LN=LN+1
+48 SET TMP("DG53829",LN)=""
+49 SET LN=LN+1
+50 SET TMP("DG53829",LN)="Deleted records are referenced in the global ^XTMP("""_"DG53829"_""",""REC_DELETED"""
+51 SET LN=LN+1
+52 SET TMP("DG53829",LN)=""
+53 DO ^XMD
+54 QUIT
+55 ;
STOP(DGREC) ; Check if asked to stop
+1 ; Only check if tasked and every 1000 records read
+2 IF $SELECT('$GET(ZTSK)
QUIT 0
+3 NEW X
+4 SET X=$$S^%ZTLOAD
+5 IF X
SET ZTSTOP=1
+6 QUIT $GET(ZTSTOP)
+7 ;
+8 ;
RESTART ; Restart copay test invalid link
+1 NEW ZTDESC,ZTDTH,ZTRTN,ZTSK,ZTIO
+2 SET $PIECE(^XTMP("DG53829","PARAMS"),U,4)=""
+3 SET ZTRTN="CLUP^DG53829P"
+4 SET ZTDESC="DG*5.3*829 Clean Up Merged Pt Recs in File #38.5 Restart"
+5 SET ZTIO=""
SET ZTDTH=$$NOW^XLFDT
+6 DO ^%ZTLOAD
+7 WRITE !,"TASK # IS: ",$GET(ZTSK)
+8 QUIT
+9 ;