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

HLUOPT1.m

Go to the documentation of this file.
  1. HLUOPT1 ;AISC/SAW - Purging Entries in file #772 and #773 ;02/04/2004 09:58
  1. ;;1.6;HEALTH LEVEL SEVEN;**10,13,21,36,19,47,62,109,108**;Oct 13, 1995
  1. ;
  1. ; Purge data of the HL7 message in file #772 and #773.
  1. ;
  1. ; Patch 47 - For Purging Option scheduled on a recurring basis,
  1. ; numbers of days kept for various Status of message are stored
  1. ; in file #869.3, fields 41, 42, and 43. Default values for these
  1. ; fields are 7, 30, and 90, respectively.
  1. ;
  1. ; Patch 36 - a message will never be purged if the new field, "Don't
  1. ; Purge" (#772,15), is set to 1.
  1. ;
  1. PURGE ;
  1. ; HLPDT("COMP") - 'completed' status cutoff date
  1. ; HLPDT("WAIT") - 'awaiting ack' status cutoff date
  1. ; HLPDT("ERR") - 'error' status cutoff date
  1. ; (=0 means don't delete msgs in 'error' status)
  1. ; HLPDT("ALL") - all other status (except 'error') cutoff date
  1. N HLPDT,HLTASK,HLEXIT
  1. ;
  1. S (HLTASK,HLEXIT)=0
  1. D INIT(.HLPDT,.HLTASK,.HLEXIT) Q:HLEXIT
  1. ;
  1. ; HL*1.6*109 lock logic...
  1. L +^HL("HLUOPT1"):2 I '$T D:'$D(ZTQUEUED) LOCKTELL^HLUOPT4 QUIT ;->
  1. L -^HL("HLUOPT1") ; Locked again at the top of DQ
  1. ;
  1. ; HL*1.6*109
  1. I '$D(ZTQUEUED) I $$BTE^HLCSMON("Press RETURN to "_$S(HLTASK:"queue job",1:"start purging")_", or enter '^' to exit... ",1) D QUIT ;->
  1. . I HLTASK W " no task started..."
  1. . I 'HLTASK W " exiting..."
  1. ;
  1. I HLTASK D TASKIT Q
  1. K HLTASK,HLEXIT ; not needed
  1. D DQ
  1. ;
  1. Q
  1. ;
  1. INIT(HLPDT,HLTASK,HLEXIT) ; Get data from file #869.3
  1. D INIT^HLUOPT4 ; HL*1.6*109
  1. Q
  1. ;
  1. TASKIT ; Queue task to run in the background
  1. N ZTDESC,ZTDTH,ZTIO,ZTRTN,ZTSAVE
  1. S ZTRTN="DQ^HLUOPT1",ZTIO="",ZTSAVE("HLPDT(")="",ZTDTH=$H
  1. S ZTDESC="Purge HL7 message text on or before "_$$FMTE^XLFDT(HLPDT("COMP"),"5D")
  1. D ^%ZTLOAD
  1. I $D(ZTSK) W !," Task #",ZTSK," queued to run now...",! Q ; HL*1.6*109
  1. W !," Queuing of Purge task failed.",! ; HL*1.6*109
  1. Q
  1. DQ ; Entry point for running purge of HL7 message text
  1. N HLDELCNT,HLEXIT,HLOOPCT
  1. ;
  1. S HLOOPCT=0
  1. ;
  1. ; HL*1.6*109
  1. N XTMP D XTMPBEGN^HLUOPT4
  1. ;
  1. ; Lock to ensures no other purge job can run...
  1. L +^HL("HLUOPT1"):10 I '$T D QUIT ;->
  1. . D XTMPUPD^HLUOPT4(.XTMP,"NO-LOCK","DONE")
  1. . I $D(ZTQUEUED) S ZTREQ="@"
  1. ;
  1. ; Purge 773s...
  1. S (HLDELCNT,HLEXIT)=0
  1. D CHK773(.HLPDT,.HLDELCNT,.HLEXIT)
  1. ;
  1. ; Update piece 4 of file's zero node...
  1. D UPDP4(773)
  1. ;
  1. ; Purge 772s...
  1. I 'HLEXIT D CHK772(.HLPDT,.HLDELCNT,.HLEXIT)
  1. ;
  1. ; Update piece 4 of file's zero node...
  1. D UPDP4(772)
  1. ;
  1. ; HL*1.6*109
  1. L -^HL("HLUOPT1")
  1. ;
  1. D XTMPUPD^HLUOPT4(.XTMP,"FINISHED","DONE")
  1. I $D(ZTQUEUED) S ZTREQ="@" Q
  1. ;
  1. W !!," #",HLDELCNT," entries purged...",! ; HL*1.6*109
  1. ;
  1. Q
  1. ;
  1. UPDP4(FNO) ; Update piece 4 of file's zero node...
  1. N GBL,NODE,NODEL,P4
  1. S GBL=$S(+FNO=772:"^HL(772,0)",+FNO=773:"^HLMA(0)",1:"") QUIT:GBL']"" ;->
  1. S NODEL=$G(XTMP(+FNO,"DEL")) QUIT:NODEL'>0 ;->
  1. L +@GBL:30 ; If don't get lock, update piece 4 anyway...
  1. S NODE=$G(@GBL) ; Get node...
  1. S P4=$P(NODE,U,4)-NODEL,P4=$S(P4>0:+P4,1:"") ; Recalc piece 4...
  1. S $P(NODE,U,4)=P4 ; Reset node's piece 4...
  1. S @GBL=NODE ; Store in file's zero node...
  1. L -@GBL
  1. Q
  1. ;
  1. CHK773(HLPDT,HLDELCNT,HLEXIT) ; Check file 773
  1. N FPDATE,HLIEN,HLPTR,HLMADT,HLY,HLMADT1,HLLT773
  1. ;
  1. ; HL*1.6*109
  1. I '$G(HLTASK) W !,"Looping through file 773..."
  1. D XTMPUPD^HLUOPT4(.XTMP,"RUNNING","START-773")
  1. ;
  1. ;calculate cuttoff date for records reserved by Fast Purge - records with a more recent FAST PURGE DT/TM then this should be left to the Fast Purge to delete
  1. S FPDATE=$$FMADD^XLFDT(DT,-2)
  1. ;
  1. S HLLT773=$O(^HLMA(";"),-1) ; last ien for 773
  1. S HLIEN=0
  1. F S HLIEN=$O(^HLMA(HLIEN)) Q:'HLIEN D Q:HLEXIT Q:$$FAIL(773) ;HL*1.6*109
  1. . D CHK4STOP(.HLEXIT) Q:HLEXIT
  1. . S XTMP(773,"REV")=$G(XTMP(773,"REV"))+1,XTMP(773,"LAST")=HLIEN,XTMP(773,"FAIL")=$G(XTMP(773,"FAIL"))+1 ; HL*1.6*109
  1. . ;
  1. . ;check if the record is reserved for FAST PURGE
  1. . I ($P($G(^HLMA(HLIEN,2)),"^",2)\1)>FPDATE Q
  1. . ;
  1. . S HLPTR=+$G(^HLMA(HLIEN,0)) Q:'HLPTR
  1. . S HLMADT=+$G(^HL(772,HLPTR,0))
  1. . ;HLY=status, HLMADT1=processed date
  1. . S HLY=+$G(^HLMA(HLIEN,"P")),HLMADT1=+$G(^("S"))
  1. . ;error status, quit if flag set to no
  1. . I HLY>3,HLY<8,'HLPDT("ERR") Q
  1. . ;check if date entered is less than purge all date
  1. . I HLMADT<HLPDT("ALL") D KILL773(HLIEN,HLLT773,.HLDELCNT) Q
  1. . ;pending, being generated, awaiting processing, or no processed date
  1. . I HLY=1!(HLY>7)!('HLMADT1) Q
  1. . ;awaiting ack, no purge date or date>purge date
  1. . I HLY=2,HLMADT1>HLPDT("WAIT") Q
  1. . ;successfully transmitted
  1. . I HLY=3,HLMADT1>HLPDT("COMP") Q
  1. . ;error status
  1. . I HLY>3,HLY<8,HLMADT1>HLPDT("ERR") Q
  1. . D KILL773(HLIEN,HLLT773,.HLDELCNT)
  1. D XTMPUPD^HLUOPT4(.XTMP,"RUNNING","END-773") ; HL*1.6*109
  1. Q
  1. KILL773(HLIEN,HLLT773,HLDELCNT) ; delete in file 773
  1. ;
  1. ; quit if don't purge flag is set or the entry is the last one
  1. Q:$G(^HLMA(HLIEN,2))!(HLIEN=HLLT773)
  1. ;
  1. S X=$G(^HLMA(+HLIEN,0)),X=+$G(^HL(772,+X,0)),XTMP(773,"LAST","TIME")=$S(X?7N1"."1.N:+X,1:"")
  1. ;
  1. D DEL773^HLUOPT3(HLIEN) ; Purge w/direct kills...
  1. ;
  1. S HLDELCNT=HLDELCNT+1
  1. ;
  1. S XTMP(773,"DEL")=$G(XTMP(773,"DEL"))+1,XTMP(773,"FAIL")=0
  1. ;
  1. Q
  1. ;
  1. CHK772(HLPDT,HLDELCNT,HLEXIT) ; Check file 772 for parents and children
  1. N FPDATE,HLOOP2,HLPTR,HLINK,HLIEN,HLMADT,HLY,HLLT772
  1. ;
  1. ; HL*1.6*109
  1. I '$G(HLTASK) W !,"Looping through file 772..."
  1. D XTMPUPD^HLUOPT4(.XTMP,"RUNNING","START-772")
  1. ;
  1. ;calculate cuttoff date for records reserved by Fast Purge - records with a more recent FAST PURGE DT/TM then this should be left to the Fast Purge to delete
  1. S FPDATE=$$FMADD^XLFDT(DT,-2)
  1. ;
  1. S HLLT772=$O(^HL(772,";"),-1) ; last ien for 772
  1. F HLOOP2=1:1:2 D Q:HLEXIT ; Kill children first, then parents
  1. . S XTMP(772,"FAIL")=0 ; HL*1.6*109
  1. . S HLPTR=0
  1. . F S HLPTR=$O(^HL(772,"B",HLPTR)) Q:HLPTR'>0 D Q:HLEXIT Q:$$FAIL(772) ; HL*1.6*109
  1. . . D CHK4STOP(.HLEXIT) Q:HLEXIT
  1. . . S HLIEN=0
  1. . . F S HLIEN=$O(^HL(772,"B",HLPTR,HLIEN)) Q:'HLIEN D
  1. . . . S XTMP(772,"REV")=$G(XTMP(772,"REV"))+1,XTMP(772,"LAST")=HLIEN,XTMP(772,"FAIL")=$G(XTMP(772,"FAIL"))+1 ; HL*1.6*109
  1. ... ;
  1. ... ;check if the record is reserved for FAST PURGE
  1. ... I ($P($G(^HL(772,+HLIEN,2)),"^",2)\1)>FPDATE Q
  1. ... ;
  1. . . . S HLMADT=+$G(^HL(772,+HLIEN,0)) Q:'HLMADT
  1. . . . I HLMADT>HLPDT("COMP") Q
  1. . . . S HLY=$P($G(^HL(772,HLIEN,"P")),U)
  1. . . . I HLY?1U S HLY=$TR(HLY,"PASE",1234)
  1. . . . I HLY>3,HLY<8,'HLPDT("ERR") Q
  1. . . . I HLMADT<HLPDT("ALL") D KILL772(HLIEN,HLLT772,.HLDELCNT) Q
  1. . . . I HLY=3,HLMADT>HLPDT("COMP") Q
  1. . . . I HLY=2,HLMADT>HLPDT("WAIT") Q
  1. . . . I HLY>3,HLY<8,HLMADT>HLPDT("ERR") Q
  1. . . . I HLY=1!(HLY>7) Q
  1. . . . I $O(^HL(772,"AI",HLIEN,HLIEN)) Q
  1. . . . D KILL772(HLIEN,HLLT772,.HLDELCNT)
  1. D XTMPUPD^HLUOPT4(.XTMP,"RUNNING","END-772") ; HL*1.6*109
  1. S HLINK=0
  1. F S HLINK=$O(^HL(772,"A-XMIT-OUT",HLINK)) Q:'HLINK D
  1. . S HLIEN=0
  1. . F S HLIEN=$O(^HL(772,"A-XMIT-OUT",HLINK,HLIEN)) Q:'HLIEN D
  1. . . I '$D(^HL(772,HLIEN)) K ^HL(772,"A-XMIT-OUT",HLINK,HLIEN)
  1. Q
  1. KILL772(HLIEN,HLLT772,HLDELCNT) ;
  1. ;
  1. ; quit if the corresponding entry in #773 exists
  1. I $O(^HLMA("B",HLIEN,0)) Q
  1. ;
  1. ; quit if don't purge flag is set or the entry is the last one
  1. Q:+$G(^HL(772,HLIEN,2))!(HLIEN=HLLT772)
  1. ;
  1. N XMDUZ,XMK,XMZ,DIK,DA,HLX
  1. ;
  1. S HLX=$G(^HL(772,HLIEN,0))
  1. S XMZ=$P(HLX,U,5)
  1. I XMZ S XMK=1,XMDUZ=.5 D KLQ^XMA1B
  1. ;
  1. S XTMP(772,"LAST","TIME")=$S(+HLX?7N1"."1.N:+HLX,1:"")
  1. ;
  1. D DEL772^HLUOPT3(+HLIEN)
  1. ;
  1. S HLDELCNT=HLDELCNT+1
  1. S XTMP(772,"DEL")=$G(XTMP(772,"DEL"))+1,XTMP(772,"FAIL")=0 ; HL*1.6*109
  1. ;
  1. Q
  1. ;
  1. CHK4STOP(HLEXIT) ;
  1. ; HL*1.6*109 modified from 60 to 120...
  1. ;
  1. S HLOOPCT=HLOOPCT+1
  1. I '$D(ZTQUEUED) W:'(HLOOPCT#2000) "."
  1. ;
  1. S:$G(HLEXIT("LASTCHK"))']"" HLEXIT("LASTCHK")=$H
  1. ;
  1. Q:$$HDIFF^XLFDT($H,$G(HLEXIT("LASTCHK")),2)<120
  1. ;
  1. ; HL*1.6*109 modified...
  1. I $$S^%ZTLOAD D Q
  1. . S HLEXIT=1
  1. . D XTMPUPD^HLUOPT4(.XTMP,"ABORTED-TASKMAN","CHK4STOP")
  1. ;
  1. S HLEXIT("LASTCHK")=$H
  1. ;
  1. D XTMPUPD^HLUOPT4(.XTMP,"RUNNING","CHK4STOP") ; HL*1.6*109
  1. ;
  1. Q
  1. ;
  1. FAIL(FILE) ; Has number entries w/o purging any been exceeded?
  1. QUIT $S($G(XTMP(FILE,"FAIL"))>200000:1,1:"")
  1. ;