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

RORERR.m

Go to the documentation of this file.
  1. RORERR ;HCIOFO/SG - ERROR PROCESSING ; 11/7/05 10:29am
  1. ;;1.5;CLINICAL CASE REGISTRIES;;Feb 17, 2006
  1. ;
  1. Q
  1. ;
  1. ;***** INITIALIZES THE ERROR STACK
  1. ;
  1. ; [DEFLOC] Default error location
  1. ; [ENABLE] Enable extended error processing
  1. ;
  1. ; Do not forget to NEW the RORERRDL variable before calling
  1. ; this procedure!
  1. ;
  1. CLEAR(DEFLOC,ENABLE) ;
  1. S:$D(ENABLE) RORPARM("ERR")=+$G(ENABLE)
  1. I $G(RORPARM("ERR")) K RORERROR("ES") S:$D(DEFLOC) RORERRDL=DEFLOC
  1. D CLEAN^DILF
  1. Q
  1. ;
  1. ;***** CHECKS THE ERRORS AFTER A FILEMAN DBS CALL
  1. ;
  1. ; ROR8MSG Closed reference of the error messages array
  1. ; (from DBS calls)
  1. ; [ERRCODE] Error code to assign
  1. ; [PLACE] Location of the error (see the $$ERROR)
  1. ; [PATIEN] Patient IEN
  1. ; [FILE] File number used in the DBS call
  1. ; [IENS] IENS used in the DBS call
  1. ;
  1. ; The $$DBS^RORERR function checks the DIERR and @ROR8MSG variables
  1. ; for errors after a FileMan DBS call.
  1. ;
  1. ; Return Values:
  1. ;
  1. ; If there are no errors found, it returns an empty string.
  1. ; In case of errors, the result depends on value of the ERRCODE
  1. ; parameter:
  1. ;
  1. ; If ERRCODE is omitted or equals 0, the function returns a string
  1. ; containing the list of error codes separated by comma.
  1. ;
  1. ; If ERRCODE is not zero, the $$ERROR^RORERR function is called and
  1. ; its return value is returned.
  1. ;
  1. ; NOTE: This entry point can also be called as a procedure:
  1. ; D DBS^RORERR(...) if you do not need its return value.
  1. ;
  1. DBS(ROR8MSG,ERRCODE,PLACE,PATIEN,FILE,IENS) ;
  1. K RORERROR("DBS")
  1. I '$G(DIERR) Q:$QUIT "" Q
  1. N ERRLST,ERRNODE,I,MSGTEXT
  1. S ERRNODE=$S($G(ROR8MSG)'="":$NA(@ROR8MSG@("DIERR")),1:$NA(^TMP("DIERR",$J)))
  1. I $D(@ERRNODE)<10 Q:$QUIT "" Q
  1. ;--- Get a list of errors
  1. S I=0
  1. F S I=$O(@ERRNODE@("E",I)) Q:'I S RORERROR("DBS",I)=""
  1. ;--- Return a list of errors
  1. I '$G(ERRCODE) D Q:$QUIT $P(ERRLST,",",2,99) Q
  1. . S ERRLST="",I=0
  1. . F S I=$O(RORERROR("DBS",I)) Q:'I S ERRLST=ERRLST_","_I
  1. . D CLEAN^DILF
  1. ;--- Record/display the error message
  1. D MSG^DIALOG("AE",.MSGTEXT,,,$G(ROR8MSG)),CLEAN^DILF
  1. S I=$S($G(FILE):"; File #"_FILE,1:"")
  1. S:$G(IENS)'="" I=I_"; IENS: """_IENS_""""
  1. S I=$$ERROR(ERRCODE,.PLACE,.MSGTEXT,.PATIEN,I)
  1. Q:$QUIT I Q
  1. ;
  1. ;***** SETS DEFAULT ERROR LOCATION
  1. ;
  1. ; DEFLOC Default error location
  1. ;
  1. ; Do not forget to NEW the RORERRDL variable before calling
  1. ; this procedure!
  1. ;
  1. DFLTLOC(DEFLOC) ;
  1. I $G(RORPARM("ERR")) S RORERRDL=DEFLOC
  1. D CLEAN^DILF
  1. Q
  1. ;
  1. ;***** DISPLAYS CONTENT OF THE ERROR STACK
  1. DSPSTK() ;
  1. Q:'$G(RORPARM("ERR"))!($D(RORERROR("ES"))<10)
  1. N EPTR,I,TMP
  1. D DSPSTKL("Err Message Text",1)
  1. D DSPSTKL(" Additional info")
  1. S EPTR=""
  1. F S EPTR=$O(RORERROR("ES",EPTR)) Q:EPTR="" D
  1. . S TMP=RORERROR("ES",EPTR)
  1. . D DSPSTKL($J(+TMP,4)_" "_$P(TMP,U,2),1)
  1. . S TMP=$G(RORERROR("ES",EPTR,1))
  1. . D:TMP'="" DSPSTKL(" Location: "_TMP)
  1. . S I=""
  1. . F S I=$O(RORERROR("ES",EPTR,2,I)) Q:I="" D
  1. . . D DSPSTKL(" "_RORERROR("ES",EPTR,2,I))
  1. Q
  1. ;
  1. ; MSG Message to display
  1. ; [SKIP] Skip a line before the output
  1. ;
  1. DSPSTKL(MSG,SKIP) ;
  1. I '$G(RORPARM("KIDS")) W:$G(SKIP) ! W MSG,! Q
  1. I $G(SKIP) D BMES^XPDUTL(MSG) Q
  1. D MES^XPDUTL(MSG)
  1. Q
  1. ;
  1. ;***** PUTS THE ERROR IN THE ERROR STACK AND LOG FILE
  1. ;
  1. ; ERRCODE Error code. Debug messages, information messages,
  1. ; data quality warnings and warnings are not placed
  1. ; into the stack. However, they are logged and
  1. ; displayed if this is enabled.
  1. ;
  1. ; [PLACE] Location of the error (TAG^ROUTINE).
  1. ;
  1. ; If the parameter is undefined then the location is
  1. ; extracted from the stack (see description of the
  1. ; $STACK function for more details).
  1. ;
  1. ; If an empty string is used as a value of the
  1. ; parameter then the default location is used
  1. ; (that has been set by CLEAR or DFLTLOC).
  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. ; [PATIEN] Patient IEN
  1. ;
  1. ; [ARG2-ARG5] Optional parameters as for $$MSG^RORERR20
  1. ; (|1| is substituted by the value of the PATIEN)
  1. ;
  1. ; Return Values:
  1. ; <0 Error code (value of the ERRCODE)
  1. ; 0 Ok (if ERRCOCE'<0)
  1. ;
  1. ; NOTE: This entry point can also be called as a procedure:
  1. ; D ERROR^RORERR(...) if you do not need its return value.
  1. ;
  1. ERROR(ERRCODE,PLACE,RORINFO,PATIEN,ARG2,ARG3,ARG4,ARG5) ;
  1. I ERRCODE'<0 Q:$QUIT 0 Q
  1. N IR,SL,MSG,TOP,TYPE
  1. D:'$D(PLACE)
  1. . S SL=$STACK(-1)-1
  1. . F Q:SL'>0 D Q:'(PLACE["^RORERR") S SL=SL-1
  1. . . S PLACE=$P($STACK(SL,"PLACE")," ")
  1. S:$G(PLACE)="" PLACE=$G(RORERRDL)
  1. I $D(RORINFO)=1 S IR=RORINFO K RORINFO S RORINFO(1)=IR,IR=1
  1. E S IR=$O(RORINFO(""),-1)
  1. S MSG=$$MSG^RORERR20(+ERRCODE,.TYPE,.PATIEN,.ARG2,.ARG3,.ARG4,.ARG5)
  1. ;--- Put the error to the error stack
  1. D:$G(RORPARM("ERR"))&(TYPE>4)
  1. . S (RORERROR("ES"),TOP)=$G(RORERROR("ES"))+1
  1. . S RORERROR("ES",TOP)=+ERRCODE_U_MSG
  1. . S RORERROR("ES",TOP,1)=PLACE
  1. . M:$D(RORINFO) RORERROR("ES",TOP,2)=RORINFO
  1. ;--- Log the message
  1. S:PLACE'="" IR=IR+1,RORINFO(IR)="Location: "_PLACE
  1. D LOG^RORLOG(TYPE,MSG,$G(PATIEN),.RORINFO),CLEAN^DILF
  1. Q:$QUIT ERRCODE Q
  1. ;
  1. ;***** CHECKS FOR INVALID POINTER ERROR
  1. ;
  1. ; FILE Number of the 'pointed from' file
  1. ; IENS IENS of the record of the file
  1. ; FIELD Number of the pointer field
  1. ; [PLACE] Location of the error (see the $$ERROR)
  1. ; [PATIEN] Patient IEN
  1. ; [ERRCODE] Error code to assign (-79 by default)
  1. ;
  1. ; The $$INVLDPTR^RORERR function checks the list of latest FileMan
  1. ; DBS error codes for the pointer errors.
  1. ;
  1. ; Return Values:
  1. ;
  1. ; If there are no pointer errors found, the function returns zero.
  1. ; Otherwise, the $$ERROR^RORERR function is called and its value
  1. ; is returned (a negative value of the ERRCODE or -79 by default).
  1. ;
  1. INVLDPTR(FILE,IENS,FIELD,PLACE,PATIEN,ERRCODE) ;
  1. Q:$D(RORERROR("DBS"))<10 0
  1. N EC,TMP
  1. F EC=601,0 Q:$D(RORERROR("DBS",EC))
  1. Q:'EC 0
  1. S TMP="File #"_FILE_"; IENS: """_IENS_"""; Field: "_FIELD
  1. Q $$ERROR($S($G(ERRCODE)<0:ERRCODE,1:-79),$G(PLACE),.TMP,.PATIEN)
  1. ;
  1. ;***** RECORDS THE ERROR MESSAGE INTO THE LOG FILE
  1. ;
  1. ; ERRCODE Error code.
  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. ; [PATIEN] Patient IEN
  1. ;
  1. ; [ARG2-ARG5] Optional parameters as for $$MSG^RORERR20
  1. ; (|1| is substituted by the value of the PATIEN)
  1. ;
  1. LOG(ERRCODE,RORINFO,PATIEN,ARG2,ARG3,ARG4,ARG5) ;
  1. Q:ERRCODE'<0
  1. N MSG,TYPE
  1. S MSG=$$MSG^RORERR20(+ERRCODE,.TYPE,.PATIEN,.ARG2,.ARG3,.ARG4,.ARG5)
  1. D LOG^RORLOG(TYPE,MSG,$G(PATIEN),.RORINFO)
  1. Q
  1. ;
  1. ;***** RETURNS THE ERROR STACK FOR A REMOTE PROCEDURE
  1. ;
  1. ; .RESULT Reference to a local variable where the error
  1. ; descriptors are returned to.
  1. ;
  1. ; LASTERR The last error code
  1. ;
  1. ; Return Values:
  1. ;
  1. ; RESULT(0) Result descriptor
  1. ; ^01: The last error code (LASTERR)
  1. ; ^02: Number of the error descriptors
  1. ;
  1. ; RESULT(i) Error descriptor
  1. ; ^01: Error code
  1. ; ^02: Message
  1. ; ^03: Place of the error
  1. ; RESULT(j) Line of the additional info
  1. ; ^01: ""
  1. ; ^02: Text
  1. ;
  1. ; Error descriptors are returned in reverse chronological order
  1. ; (most recent first).
  1. ;
  1. RPCSTK(RESULT,LASTERR) ;
  1. N CNT,ECNT,EPTR,I,TMP
  1. K RESULT S RESULT(0)=(+LASTERR)_U_"0"
  1. S TMP=$$RTRNFMT^XWBLIB(2,1)
  1. Q:$D(RORERROR("ES"))<10
  1. ;
  1. S EPTR="",(CNT,ECNT)=0
  1. F S EPTR=$O(RORERROR("ES",EPTR),-1) Q:EPTR="" D
  1. . S TMP=$G(RORERROR("ES",EPTR)),CNT=CNT+1,ECNT=ECNT+1
  1. . S RESULT(CNT)=(+TMP)_U_$TR($P(TMP,U,2,999),U,"~")
  1. . S TMP=$G(RORERROR("ES",EPTR,1))
  1. . S $P(RESULT(CNT),U,3)=$TR(TMP,U,"~")
  1. . S I=0
  1. . F S I=$O(RORERROR("ES",EPTR,2,I)) Q:I'>0 D
  1. . . S CNT=CNT+1,$P(RESULT(CNT),U,2)=RORERROR("ES",EPTR,2,I)
  1. ;
  1. S $P(RESULT(0),U,2)=ECNT
  1. K ^TMP("DILIST",$J)
  1. Q
  1. ;
  1. ;***** DUMPS LOCAL VARIABLES INTO THE LOG
  1. ;
  1. ; M1S2G Message code.
  1. ;
  1. ; V1A2R3S List of local variables separated by commas
  1. ;
  1. VARDUMP(M1S2G,V1A2R3S) ;
  1. Q