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

RORLOG.m

Go to the documentation of this file.
  1. RORLOG ;HCIOFO/SG - LOG FILE MANAGEMENT ; 1/17/06 10:10am
  1. ;;1.5;CLINICAL CASE REGISTRIES;;Feb 17, 2006
  1. ;
  1. ; RORLOG -------------- CONSTANT & VARIABLES OF THE LOG SUSBSYSTEM
  1. ;
  1. ; RORLOG("IEN") IEN of the main record in the ROR LOG file
  1. ;
  1. ; This routine uses the following IAs:
  1. ;
  1. ; #10060 Read-only (DBS API) access to the NEW PERSON file
  1. ;
  1. Q
  1. ;
  1. ;***** RECORDS THE ACCESS VIOLATION EVENT
  1. ;
  1. ; MSG Either a negative code of the message or a message
  1. ; text that will be recorded in the log.
  1. ;
  1. ; [REGISTRY] Either a registry name or a registry IEN
  1. ; (the log will be associated with this registry)
  1. ;
  1. ; [ARG2-ARG5] Optional parameters as for $$MSG^RORERR20
  1. ;
  1. ACVIOLTN(MSG,REGISTRY,ARG2,ARG3,ARG4,ARG5) ;
  1. N INFO,RORLOG,RORMSG,RORPARM
  1. S REGISTRY=$G(REGISTRY)
  1. ;--- Make sure that event recording is enabled
  1. S RORPARM("LOG")=1
  1. ;--- Get the registry name
  1. I (+REGISTRY)=REGISTRY D:REGISTRY>0
  1. . S REGISTRY=$P($G(^ROR(798.1,+REGISTRY,0)),U)
  1. ;--- Get the text of the message (if a code is provided)
  1. S:(+MSG)=MSG MSG=$$MSG^RORERR20(+MSG,,,.ARG2,.ARG3,.ARG4,.ARG5)
  1. ;--- Send an alert to the registry coordinators
  1. D:REGISTRY'=""
  1. . S INFO=$G(DUZ)_U_$$NOW^XLFDT
  1. . D ALERT^RORUTL01(REGISTRY,MSG,"ACLRTN^RORLOG01",INFO)
  1. ;--- Create a new log and record the message
  1. I $$OPEN(REGISTRY,6)'<0 D D CLOSE()
  1. . D:$G(DUZ)>0
  1. . . S INFO="Violator: "_$$GET1^DIQ(200,DUZ_",",.01,,,"RORMSG")
  1. . . S INFO=INFO_" (DUZ="_DUZ_")"
  1. . D LOG(6,MSG,,.INFO)
  1. Q
  1. ;
  1. ;***** CLOSES THE CURRENT LOG
  1. ;
  1. ; [MESSAGE] Text of the final message
  1. ; [COUNTERS] Statistic counters
  1. ; ^1: Total number of processed patients
  1. ; ^2: Number of patients processed with errors
  1. ;
  1. CLOSE(MESSAGE,COUNTERS) ;
  1. Q:$G(RORLOG("IEN"))'>0
  1. N BDT,EDT,IENS,RATE,RORFDA,RORINFO,RORMSG,TMP
  1. S EDT=$$NOW^XLFDT
  1. S IENS=RORLOG("IEN")_","
  1. ;--- Prepare statistic data
  1. D:$G(COUNTERS)>0
  1. . S RORINFO(1)="Patients: "_+$P(COUNTERS,U)
  1. . S RORINFO(2)="Errors: "_+$P(COUNTERS,U,2)
  1. . S BDT=$$GET1^DIQ(798.7,IENS,.01,"I",,"RORMSG")
  1. . Q:$G(BDT)'>0
  1. . S TMP=$$FMDIFF^XLFDT(EDT,BDT,2)
  1. . S RATE=$S(TMP>0:$J(COUNTERS/TMP,0,3),1:"")
  1. . S RORINFO(3)="Time (sec): "_TMP
  1. . S:RATE RORINFO(4)="Patients/sec: "_RATE
  1. . ;--- Data for the log header
  1. . S RORFDA(798.7,IENS,6.01)=$P(COUNTERS,U,1)
  1. . S RORFDA(798.7,IENS,6.02)=$P(COUNTERS,U,2)
  1. . S:RATE RORFDA(798.7,IENS,6.03)=RATE
  1. ;--- Store data in the header and log the final message
  1. S RORFDA(798.7,IENS,5)=EDT
  1. D FILE^DIE("K","RORFDA","RORMSG")
  1. D:$G(MESSAGE)'="" LOG^RORLOG(,MESSAGE,,.RORINFO)
  1. K RORLOG
  1. Q
  1. ;
  1. ;***** PUTS MESSAGE IN THE LOG
  1. ;
  1. ; [TYPE] Type of the event:
  1. ; 1 Debug
  1. ; 2 Information
  1. ; 3 Data quality
  1. ; 4 Warning
  1. ; 5 Database error
  1. ; 6 Error
  1. ;
  1. ; If value of the parameter is omitted or equals 0, the message
  1. ; is logged as "information" (if log is enabled). This mode is
  1. ; intended for log headers and separators.
  1. ;
  1. ; MESSAGE Message text
  1. ; [PATIEN] Patient IEN
  1. ;
  1. ; [[.]RORINFO] Optional additional information (either a string or
  1. ; a reference to a local array that contains strings
  1. ; prepared for storing in a word processing field)
  1. ;
  1. LOG(TYPE,MESSAGE,PATIEN,RORINFO) ;
  1. ;--- Do not do anything if log is disabled
  1. Q:'$G(RORPARM("LOG"))
  1. ;--- Check if collection of this kind of event is enabled.
  1. ; Debug messages could be enabled only explicitly.
  1. I '$G(TYPE) S TYPE=2
  1. E I ($D(RORPARM("LOG"))>1)!(TYPE=1) Q:'$G(RORPARM("LOG",+TYPE))
  1. ;---
  1. N CURRIO,DATETIME,I,IENS,RC,RORFDA,RORMSG,TMP
  1. I $D(RORINFO)=1 S TMP=RORINFO K RORINFO S RORINFO(1)=TMP K TMP
  1. S DATETIME=$$NOW^XLFDT
  1. ;--- Add a new record to the log (if it has been open)
  1. D:$G(RORLOG("IEN"))>0
  1. . S IENS="+1,"_RORLOG("IEN")_","
  1. . S RORFDA(798.74,IENS,.01)=DATETIME
  1. . S RORFDA(798.74,IENS,1)=+TYPE
  1. . S RORFDA(798.74,IENS,2)=$E(MESSAGE,1,70)
  1. . S:$G(PATIEN) RORFDA(798.74,IENS,3)=+PATIEN
  1. . S:$D(RORINFO)>1 RORFDA(798.74,IENS,4)="RORINFO"
  1. . D UPDATE^DIE(,"RORFDA",,"RORMSG")
  1. ;--- Display message (if debug mode 2 is enabled)
  1. I $G(RORPARM("DEBUG"))>1 U $G(IO(0)) D U IO
  1. . W !,$P($$FMTE^XLFDT(DATETIME,"2FS"),"@",2)_" "_$E(MESSAGE,1,70),!
  1. . S I=""
  1. . F S I=$O(RORINFO(I)) Q:I="" D W ?9,TMP,!
  1. . . S TMP=$G(RORINFO(I)) S:TMP="" TMP=$G(RORINFO(I,0))
  1. . W:$G(PATIEN) ?9,"Patient IEN: "_PATIEN,!
  1. Q
  1. ;
  1. ;***** RETURNS AN IEN OF THE CURRENT LOG
  1. LOGIEN() ;
  1. Q +$G(RORLOG("IEN"))
  1. ;
  1. ;***** OPENS A NEW LOG
  1. ;
  1. ; [[.]REGLST] Either name of the registry or reference to a local
  1. ; array containing registry names as subscripts and
  1. ; optional registry IENs as values
  1. ;
  1. ; [ACTIVITY] Type of the activity:
  1. ; 0 Other (default)
  1. ; 1 Registry update
  1. ; 2 Data Extract
  1. ; 3 Acknowledgement
  1. ; 4 Hist. Extraction
  1. ; 5 Report
  1. ; 6 Access Violation
  1. ; 7 ROR TASK
  1. ; 8 Registry Setup
  1. ;
  1. ; [MESSAGE] Text of the first message
  1. ;
  1. ; [[.]ADDINFO] Optional additional information (either a string or
  1. ; a reference to a local array that contains strings
  1. ; prepared for storing in a word processing field).
  1. ; This text is appended after the list of registries
  1. ; associated with the log.
  1. ;
  1. ; Return Values:
  1. ; <0 Error code
  1. ; 0 Ok
  1. ;
  1. OPEN(REGLST,ACTIVITY,MESSAGE,ADDINFO) ;
  1. Q:'$G(RORPARM("LOG")) 0
  1. N I,IENS,IPTR,RC,REGIEN,REGNAME,RORFDA,RORIEN,RORINFO,RORMSG,TMP
  1. K RORLOG
  1. ;=== Prepare the list of registries
  1. I $D(REGLST)=1 S:REGLST'="" REGLST(REGLST)=""
  1. S REGNAME="",(IPTR,RC)=0
  1. F S REGNAME=$O(REGLST(REGNAME)) Q:REGNAME="" D Q:RC<0
  1. . S REGIEN=+$G(REGLST(REGNAME))
  1. . I REGIEN'>0 D I REGIEN'>0 S RC=REGIEN Q
  1. . . S REGIEN=$$REGIEN^RORUTL02(REGNAME)
  1. . S IPTR=IPTR+1,RORINFO(IPTR)=REGNAME
  1. . S RORFDA(798.73,"+"_(IPTR+10)_",+1,",.01)=REGIEN
  1. . S RORIEN(IPTR+10)=REGIEN
  1. Q:RC<0 RC
  1. ;=== Create a log header (main record) in the ROR LOG file
  1. S IENS="+1,"
  1. S RORFDA(798.7,IENS,.01)=$$NOW^XLFDT
  1. S:$G(ACTIVITY)>0 RORFDA(798.7,IENS,1)=ACTIVITY
  1. S RORFDA(798.7,IENS,2)=$J
  1. S RORFDA(798.7,IENS,7)=$S($G(DUZ)>0:+DUZ,1:"")
  1. S TMP=$S($D(ZTQUEUED):+$G(ZTSK),1:0)
  1. S RORFDA(798.7,IENS,8)=$S(TMP>0:TMP,1:"")
  1. D UPDATE^DIE(,"RORFDA","RORIEN","RORMSG")
  1. S RC=$$DBS^RORERR("RORMSG",-9) Q:RC<0 RC
  1. S RORLOG("IEN")=RORIEN(1)
  1. ;=== Add the header message (if any)
  1. D:$G(MESSAGE)'=""
  1. . ;--- Append the additional text to list of registries
  1. . I $D(ADDINFO)=1 D
  1. . . S IPTR=IPTR+1,RORINFO(IPTR)=ADDINFO
  1. . E S I="" D
  1. . . F S I=$O(ADDINFO(I)) Q:I="" D
  1. . . . S TMP=$G(ADDINFO(I)),IPTR=IPTR+1
  1. . . . S RORINFO(IPTR)=$S(TMP'="":TMP,1:$G(ADDINFO(I,0)))
  1. . ;---
  1. . D LOG(,MESSAGE,,.RORINFO)
  1. ;=== Success
  1. Q 0
  1. ;
  1. ;***** REPLACES LIST OF REGISTRIES ASSOCIATED WITH THE CURRENT LOG
  1. ;
  1. ; [.]REGLST Either name of the registry or a reference to a local
  1. ; array containing registry names as subscripts and
  1. ; optional registry IENs as values.
  1. ;
  1. ; [NOLP] If this parameter is defined and non-zero, the log
  1. ; subsystem parameters will not be updated according
  1. ; to the new list of associated registries.
  1. ;
  1. ; Return Values:
  1. ; <0 Error code
  1. ; 0 Ok
  1. ;
  1. SETRGLST(REGLST,NOLP) ;
  1. N I,IENS,RC,REGIEN,RILST,RORBUF,RORFDA,RORIEN,RORMSG
  1. S IENS=$$LOGIEN()_","
  1. Q:'$G(RORPARM("LOG"))!(IENS'>0) 0
  1. ;--- Compile a list of registry IENs (as subscripts)
  1. S:$D(REGLST)=1 REGLST(REGLST)=""
  1. S I="",RC=0
  1. F S I=$O(REGLST(I)) Q:I="" D Q:RC<0
  1. . S REGIEN=+$G(REGLST(I))
  1. . I REGIEN'>0 D I REGIEN'>0 S RC=REGIEN Q
  1. . . S REGIEN=$$REGIEN^RORUTL02(I)
  1. . S RILST(REGIEN)=""
  1. Q:RC<0 RC
  1. ;--- Delete old registries from the multiple of the log record
  1. D LIST^DIC(798.73,","_IENS,"@;.01I","U",,,,"B",,,"RORBUF","RORMSG")
  1. S RC=$$DBS^RORERR("RORMSG",-9) Q:RC<0 RC
  1. S I=""
  1. F S I=$O(RORBUF("DILIST",2,I)) Q:I="" D
  1. . S REGIEN=RORBUF("DILIST","ID",I,.01)
  1. . I $D(RILST(REGIEN)) K RILST(REGIEN) Q
  1. . S RORFDA(798.73,RORBUF("DILIST",2,I)_","_IENS,.01)="@"
  1. I $D(RORFDA)>1 D Q:RC<0 RC
  1. . D FILE^DIE("K","RORFDA","RORMSG")
  1. . S RC=$$DBS^RORERR("RORMSG",-9)
  1. ;--- Add new registries to the multiple
  1. S REGIEN=""
  1. F I=1:1 S REGIEN=$O(RILST(REGIEN)) Q:REGIEN="" D
  1. . S RORFDA(798.73,"+"_I_","_IENS,.01)=REGIEN
  1. . S RORIEN(I)=REGIEN
  1. I $D(RORFDA)>1 D Q:RC<0 RC
  1. . D UPDATE^DIE(,"RORFDA","RORIEN","RORMSG")
  1. . S RC=$$DBS^RORERR("RORMSG",-9)
  1. ;--- Reload parameters (if necessary)
  1. I '$G(NOLP) D Q:RC<0 RC
  1. . K RORPARM("LOG") S RC=$$PARAMS^RORLOG01(.REGLST)
  1. Q 0
  1. ;
  1. ;***** INITIALIZES THE LOG SUBSYSTEM
  1. ;
  1. ; [[.]REGLST] Either a reference to a local array containing names
  1. ; of the registries to process (as subscripts) or a
  1. ; string that contains a name of the single registry.
  1. ;
  1. ; Return Values:
  1. ; <0 Error code
  1. ; 0 Ok
  1. ;
  1. SETUP(REGLST) ;
  1. K RORPARM("LOG"),RORLOG
  1. S:$D(REGLST)=1 REGLST(REGLST)=""
  1. Q $$PARAMS^RORLOG01(.REGLST)