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

RORUPR.m

Go to the documentation of this file.
  1. RORUPR ;HCIOFO/SG - SELECTION RULES PREPARATION ;5/12/05 9:22am
  1. ;;1.5;CLINICAL CASE REGISTRIES;**19**;Feb 17, 2006;Build 43
  1. ;
  1. ;******************************************************************************
  1. ;******************************************************************************
  1. ; --- ROUTINE MODIFICATION LOG ---
  1. ;
  1. ;PKG/PATCH DATE DEVELOPER MODIFICATION
  1. ;----------- ---------- ----------- ----------------------------------------
  1. ;ROR*1.5*19 FEB 2012 K GUPTA Support for ICD-10 Coding System
  1. ;******************************************************************************
  1. ;******************************************************************************
  1. ;
  1. Q
  1. ;
  1. ;***** PREPARES SELECTION RULES AND OTHER DATA
  1. ;
  1. ; .REGLST Reference to a local array containing registry names
  1. ; as subscripts and optional registry IENs as values
  1. ;
  1. ; [LMODE] When stop looping through records of the patient:
  1. ; 0 always loop through all records
  1. ; 1 all top level rules have been triggered (deflt)
  1. ; 2 patient has been marked for addition to all
  1. ; registries being processed
  1. ;
  1. ; [DSBEG] Start date/time of the data scan (the earliest
  1. ; registry update date by default)
  1. ;
  1. ; [DSEND] End date/time of the data scan (NOW by default)
  1. ;
  1. ; Return Values:
  1. ; 0 Ok
  1. ; <0 Error code
  1. ;
  1. PREPARE(REGLST,LMODE,DSBEG,DSEND) ;
  1. N FILE,I,RC
  1. ;--- Clear loop control lists
  1. K RORUPD("LM") S RORUPD("LM")=+$G(LMODE,1)
  1. ;--- Load registry parameters
  1. S RC=$$PREPARE1(.REGLST,$G(DSBEG),$G(DSEND)) Q:RC<0 RC
  1. ;--- Load selection rules
  1. S RC=$$LOAD^RORUPR1(.REGLST) Q:RC<0 $$ERROR^RORERR(-19)
  1. ;--- Load and prepare Lab search data
  1. S RC=$$LABSRCH^RORUPR1() Q:RC<0 $$ERROR^RORERR(-12)
  1. ;--- Sort loaded rules
  1. S RC=$$SORT() Q:RC<0 $$ERROR^RORERR(-20)
  1. ;--- Load and prepare metadata
  1. S RC=$$METADATA^RORUPR1() Q:RC<0 RC
  1. Q 0
  1. ;
  1. ;***** LOADS REGISTRY PARAMETERS
  1. ;
  1. ; .REGLST Reference to a local array containing
  1. ; registry names as subscripts
  1. ;
  1. ; [DSBEG] Start date of the data scan (the earliest registry
  1. ; update date by default). Time part of the parameter
  1. ; value is ignored.
  1. ;
  1. ; [DSEND] End date/time of the data scan (NOW by default).
  1. ;
  1. ; Return Values:
  1. ; 0 Ok
  1. ; <0 Error code
  1. ;
  1. PREPARE1(REGLST,DSBEG,DSEND) ;
  1. N DATE,EVTPROT,I,RC,REGIEN,REGNAME,RORBUF,TMP,UPDSTART
  1. K RORUPD("LD"),RORUPD("LM2"),RORUPD("UPD")
  1. S DSBEG=$G(DSBEG)\1,DSEND=+$G(DSEND)
  1. S UPDSTART=$$DT^XLFDT,EVTPROT=0
  1. ;---
  1. S REGNAME="",RC=0
  1. F S REGNAME=$O(REGLST(REGNAME)) Q:REGNAME="" D Q:RC<0
  1. . S TMP="1I;6.1;6.2;15.1;25I;26I"
  1. . S REGIEN=$$REGIEN^RORUTL02(REGNAME,TMP,.RORBUF)
  1. . I REGIEN'>0 S RC=$$ERROR^RORERR(-46,,REGNAME) Q
  1. . ;--- Add an item to the static list of registries
  1. . S RORUPD("LM2",REGIEN)=U_$G(RORBUF("DILIST","ID",1,26))
  1. . ;--- Load and verify update entry points
  1. . S RC=0
  1. . F I=1,2 D Q:RC<0
  1. . . S TMP=$G(RORBUF("DILIST","ID",1,+("6."_I)))
  1. . . S TMP=$$TRIM^XLFSTR(TMP) Q:TMP=""
  1. . . S RC=$$VERIFYEP^RORUTL01(TMP)
  1. . . S:RC'<0 RORUPD("UPD",REGIEN,I)=TMP
  1. . I RC<0 S RC=$$ERROR^RORERR(-6,,REGNAME,,TMP) Q
  1. . ;--- Calculate the earliest update date for the registries
  1. . ; being processed
  1. . S DATE=$G(RORBUF("DILIST","ID",1,1))\1
  1. . I DATE S:DATE<UPDSTART UPDSTART=DATE
  1. . ;--- Calculate the longest lag interval
  1. . S TMP=$G(RORBUF("DILIST","ID",1,15.1))
  1. . S:TMP>$G(RORUPD("LD",1)) RORUPD("LD",1)=TMP
  1. . ;--- Check if event references should be used
  1. . S:$G(RORBUF("DILIST","ID",1,25)) EVTPROT=1
  1. Q:RC<0 RC
  1. ;--- Check the lag interval
  1. S:$G(RORUPD("LD",1))'>0 RORUPD("LD",1)=1
  1. ;--- Define data scan period
  1. S RORUPD("DT")=$$NOW^XLFDT
  1. S RORUPD("DSBEG")=$S(DSBEG:DSBEG,1:UPDSTART)
  1. S RORUPD("DSEND")=$S(DSEND:DSEND,1:RORUPD("DT"))
  1. ;--- Check if we have event references in the file #798.3
  1. S RORUPD("EETS")=$O(^RORDATA(798.3,"AT",""))
  1. S:'RORUPD("EETS") EVTPROT=0
  1. ;--- Check the control flags
  1. S:'EVTPROT RORUPD("FLAGS")=$TR($G(RORUPD("FLAGS")),"E")
  1. Q 0
  1. ;
  1. ;***** PUTS THE RULE INTO THE LIST
  1. ;
  1. ; RULENAME Name of the rule
  1. ; MODE "A" (process after subfiles) or
  1. ; "B" (process before subfiles)
  1. ; PARENT Name of the parent rule
  1. ;
  1. ; Return Values:
  1. ; 0 Ok
  1. ; <0 Error code
  1. ;
  1. PUTRULE(RULENAME,MODE,PARENT) ;
  1. N CODE,DSTNODE,DEPNAME,HDR,FILE,IR,IC
  1. S HDR=$G(@RORUPDPI@(3,RULENAME)),FILE=+$P(HDR,U,2)
  1. ;--- If the rule has already been processed, try to remove it from
  1. ; the dependency list of the parent rule
  1. I $P(HDR,U,3) D REMOVE(RULENAME,FILE,MODE,$G(PARENT)) Q 0
  1. ;--- If the rule is in the list of parent rules already, it has been
  1. ; mentioned ; somewhere above in the current processing path.
  1. ; So, we have "cirle refrenece" (the rule directly or inderectly
  1. ; depends on itself)
  1. Q:$D(LSTRUL(RULENAME)) $$ERROR^RORERR(-5,,RULENAME)
  1. ;--- Put the rule into the list of parent rules
  1. S LSTRUL(RULENAME)=""
  1. ;--- Process the rules that this one depends on
  1. S DEPNAME=""
  1. F S DEPNAME=$O(@RORUPDPI@(3,RULENAME,3,DEPNAME)) Q:DEPNAME="" D Q:RC<0
  1. . S RC=$$PUTRULE(DEPNAME,MODE,RULENAME)
  1. ;--- Remove the rule from the list of parent rules
  1. K LSTRUL(RULENAME) Q:RC<0 RC
  1. ;--- Process the rule (put it in the sorted list of rules) if there
  1. ; are no rules left in its dependency list
  1. D:$D(@RORUPDPI@(3,RULENAME,3))<10
  1. . S IR=$O(RORUPD("SR",FILE,MODE,""),-1)+1
  1. . S DSTNODE=$NA(RORUPD("SR",FILE,MODE,IR))
  1. . S @DSTNODE=RULENAME_U_+HDR_U_$P(HDR,U,4)
  1. . S @DSTNODE@(1)=@RORUPDPI@(3,RULENAME,1)
  1. . M @DSTNODE@(2)=@RORUPDPI@(3,RULENAME,2)
  1. . S @DSTNODE@(3)=@RORUPDPI@(3,RULENAME,4) ;store coding system
  1. . S $P(@RORUPDPI@(3,RULENAME),U,3)=1
  1. . ;--- Try to remove the rule from the dependency list of
  1. . ; the parent rule
  1. . D REMOVE(RULENAME,FILE,MODE,$G(PARENT))
  1. Q 0
  1. ;
  1. ;***** REMOVES THE RULE FROM THE DEPENDENCY LIST OF THE PARENT RULE
  1. ;
  1. ; RULENAME Name of the rule
  1. ; FILE File number
  1. ; MODE "A" (process after subfiles) or
  1. ; "B" (process before subfiles)
  1. ; PARENT Name of the parent rule
  1. ;
  1. ; During the first pass of the sort ("before" rules) a rule is
  1. ; removed from the parent's dependency list only if the rule is
  1. ; associated with the same file as its parent.
  1. ;
  1. ; Rules are always removed from the dependency list during
  1. ; the second sort pass ("after" rules").
  1. ;
  1. REMOVE(RULENAME,FILE,MODE,PARENT) ;
  1. Q:$G(PARENT)=""
  1. K:(+$P($G(@RORUPDPI@(3,PARENT)),U,2)=FILE)!(MODE="A") @RORUPDPI@(3,PARENT,3,RULENAME)
  1. Q
  1. ;
  1. ;***** SORTS SELECTION RULES
  1. ;
  1. ; Return Values:
  1. ; 0 Ok
  1. ; <0 Error code
  1. ;
  1. SORT() ;
  1. N LSTRUL ; List of names of the parent rules above in the path
  1. ;
  1. N FILE,MODE,RC,RULENAME
  1. S RC=0 K RORUPD("SR")
  1. ;--- Process "before" selection rules first and then process
  1. ; "after" rules
  1. F MODE="B","A" D Q:RC
  1. . S FILE="" ; Loop through affected files
  1. . F S FILE=$O(@RORUPDPI@(1,FILE)) Q:FILE="" D Q:RC
  1. . . S RULENAME="" ; Loop through top level rules
  1. . . F S RULENAME=$O(@RORUPDPI@(1,FILE,"S",RULENAME)) Q:RULENAME="" D Q:RC<0
  1. . . . S RC=$$PUTRULE(RULENAME,MODE)
  1. ;---
  1. Q $S(RC<0:RC,1:0)