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

RAMAGU09.m

Go to the documentation of this file.
RAMAGU09 ;HCIOFO/SG - ORDERS/EXAMS API (RAMISC VALIDATION) ; 2/24/09 3:10pm
 ;;5.0;Radiology/Nuclear Medicine;**90**;Mar 16, 1998;Build 20
 ;
 ;
 ; NOTE: All entry points in this routine are internal ones. Do not
 ;       call it from outside of routines that validate miscellaneous 
 ;       exam parameters (^RAMAGU08, ^RAMAGU10, ^RAMAGU14, etc.).
 ;
 Q
 ;
 ;+++++ CHECKS THE FIELD VALUE
 ;
 ; PNODE         Name of the parameter
 ; VALUE         Parameter value
 ;
 ; FILE          File number
 ; FIELD         Field number
 ;
 ; [[.]IENS]     IENS of the record. If this parameter is not defined
 ;               or empty, a new IENS is automatically generated by
 ;               the $$IENS^RAMAGU09.
 ;
 ; [REQUIRED]    If this parameter is defined and not zero, then "@"
 ;               or an empty string (deletion) are not allowed.
 ;
 ; Input variables:
 ;   RAFDA
 ;
 ; Output variables:
 ;   RAFDA
 ;
 ; Return values:
 ;       <0  Error descriptor (see $$ERROR^RAERR)
 ;        0  Ok
 ;
CHECKFLD(PNODE,VALUE,FILE,FIELD,IENS,REQUIRED) ;
 N RAMSG,RESULT
 I $G(REQUIRED)  Q:VALUE?.1"@" $$IPVE^RAERR(PNODE)
 S:$G(IENS)="" IENS=$$IENS
 D VAL^DIE(FILE,IENS,FIELD,"F",VALUE,.RESULT,"RAFDA","RAMSG")
 Q:$G(DIERR) $$DBS^RAERR("RAMSG",-9)
 Q $S(RESULT="^":$$IPVE^RAERR(PNODE),1:0)
 ;
 ;+++++ GENERATES IENS FOR ADDING A RECORD TO A MULTIPLE
 ;
 ; Input variables:
 ;   RAFDA
 ;
 ; Output variables:
 ;   RAFDA
 ;
IENS() ;
 S RAFDA("RACNT")=$G(RAFDA("RACNT"))+1
 Q "+"_RAFDA("RACNT")_","_RAFDA("RAIENS")
 ;
 ;+++++ VALIDATES EXAM CATEGORY SPECIFIC PARAMETERS
 ;
 ; RACAT         Exam category
 ;
 ; Input variables:
 ;   RAIENS, RAMISC
 ;
 ; Output variables:
 ;   RAFDA, RAMISC
 ;
 ; Return values:
 ;       <0  Error code
 ;        0  Parameters are valid
 ;
VALECPRM(RACAT) ;
 N ERRCNT,PNODE,RC,TMP
 S (ERRCNT,RC)=0
 ;---
 I RACAT="I"  D  ;--- Inpatient
 . ;--- Bedsection
 . S PNODE=$NA(RAMISC("BEDSECT"))
 . I $D(@PNODE)#10  D
 . . S TMP=$$VI($P(@PNODE,U))
 . . S:$$CHECKFLD(PNODE,TMP,70.03,19,RAIENS)<0 ERRCNT=ERRCNT+1
 . ;--- Service
 . S PNODE=$NA(RAMISC("SERVICE"))
 . I $D(@PNODE)#10  D
 . . S TMP=$$VI($P(@PNODE,U))
 . . S:$$CHECKFLD(PNODE,TMP,70.03,7,RAIENS)<0 ERRCNT=ERRCNT+1
 . ;--- Ward
 . S PNODE=$NA(RAMISC("WARD"))
 . I $D(@PNODE)#10  D
 . . S TMP=$$VI($P(@PNODE,U))
 . . S:$$CHECKFLD(PNODE,TMP,70.03,6,RAIENS)<0 ERRCNT=ERRCNT+1
 . ;---
 . K RAMISC("PRINCLIN")
 E  D            ;--- Other categories
 . ;--- Principal Clinic
 . S PNODE=$NA(RAMISC("PRINCLIN"))
 . I $D(@PNODE)#10  S RC=0  D
 . . S TMP=$$VI($P(@PNODE,U))
 . . S:$$CHECKFLD(PNODE,TMP,70.03,8,RAIENS,1)<0 ERRCNT=ERRCNT+1
 . ;---
 . F I="BEDSECT","SERVICE","WARD"  K RAMISC(I)
 ;---
 Q $S(ERRCNT>0:-11,1:0)
 ;
 ;+++++ VALIDATES THE PARAMETER
 ;
 ; NAME          Parameter name
 ;
 ; [SEQ]         Sequential number of the parameter value. If this
 ;               parameter is greater than 0, then the parameter
 ;               value is loaded from the @NODE@(NAME,SEQ) node.
 ;               Otherwise, the parameter value is loaded from the
 ;               @NODE@(NAME) node.
 ;
 ; [[.]IENS]     IENS of the record. If this parameter is not defined
 ;               or empty, a new IENS is automatically generated by
 ;               the $$IENS^RAMAGU09.
 ;
 ; [NODE]        Base node in the RAMISC arrays. By default
 ;               ($G(NODE)=""), the RAMISC variable is assumed.
 ;
 ; [FLAGS]       Flags that control the execution (can be combined):
 ;
 ;                 C  Perform the checks but do not record errors.
 ;
 ;                 O  If this flag is defined, then the validated
 ;                    parameter is considered 'optional' regardless
 ;                    of requirements stored in the RAMSPSDEFS.
 ;
 ;                 R  If this flag is defined, then the validated
 ;                    parameter is considered 'required' regardless
 ;                    of requirements stored in the RAMSPSDEFS.
 ;
 ; Input variables:
 ;   RAFDA, RAMISC, RAMSPSDEFS
 ;
 ; Output variables:
 ;   RAFDA
 ;
 ; Return values:
 ;       <0  Error descriptor (see $$ERROR^RAERR)
 ;        0  Ok (parameter is not defined)
 ;       >0  Ok (parameter is defined)
 ;
VALPRM(NAME,SEQ,IENS,NODE,FLAGS) ;
 N FILE,FIELD,LSTPRM,PNODE,PRMDEF,RAMSG,RARES,RC,REQUIRED,TMP,TYPE,VALUE
 S:$G(NODE)="" NODE="RAMISC"
 S PNODE=$S($G(SEQ)>0:$NA(@NODE@(NAME,SEQ)),1:$NA(@NODE@(NAME)))
 ;
 ;=== Check the flags
 S FLAGS=$G(FLAGS),TMP=0
 S:FLAGS["O" REQUIRED=0,TMP=TMP+1
 S:FLAGS["R" REQUIRED=1,TMP=TMP+1
 Q:TMP>1 $$IPVE^RAERR("FLAGS")
 ;
 ;=== Get the parameter definition
 S PRMDEF=$G(RAMSPSDEFS("N",NAME))
 S FILE=+$P(PRMDEF,U),FIELD=+$P(PRMDEF,U,2),TYPE=$P(PRMDEF,U,3)
 S LSTPRM=(TYPE["M")&($G(SEQ)'>0)  ; "List" mode
 Q:(FILE'>0)!('LSTPRM&(FIELD'>0)) $$ERROR^RAERR(-58,,NAME)
 S:$G(IENS)="" IENS=$$IENS
 ;
 ;=== Preserve the error stack so that errors are not recorded
 I FLAGS["C"  N RAERROR
 ;
 ;=== Unless overridden by the caller, determine
 ;=== if the field value is required
 D:$G(REQUIRED)=""
 . ;--- .01 fields are required
 . I FIELD=.01,'LSTPRM  S REQUIRED=1  Q
 . ;--- Ignore missing required values if the flag is set
 . I $G(RAMISC("FLAGS"))["F"  S REQUIRED=0  Q
 . ;--- Check the parameter definition
 . S TMP=+$P(PRMDEF,U,4)
 . S REQUIRED=$S(TMP>0:+$P($G(RAMSPSDEFS("R")),U,TMP),1:0)
 ;
 ;=== If the API is called in "list" mode, check if the parameter
 ;    list is provided. If it is not but the values are required
 ;    for the new exam status, check if the corresponding multiple
 ;=== has any records already.
 I LSTPRM  S RC=0  D:$D(@PNODE)<10  Q $S(RC<0:RC,1:$D(@PNODE)>0)
 . N ROOT
 . ;--- Check for data deletion request
 . I $D(@PNODE)#10  D  Q
 . . ;--- Deletion of required data is not allowed
 . . I REQUIRED  S RC=$$IPVE^RAERR(PNODE)  Q
 . . ;--- Mark the multiple for deletion
 . . K RAFDA(FILE)  S RAFDA(FILE)=""
 . ;--- Check if the multiple field has any records
 . Q:'REQUIRED
 . S TMP=","_RAFDA("RAIENS"),ROOT=$$ROOT^DILFD(FILE,TMP,1)
 . I ROOT=""  S RC=$$ERROR^RAERR(-50,,FILE,TMP)  Q
 . S:$O(@ROOT@(0))'>0 RC=$$ERROR^RAERR(-8,,PNODE)
 ;
 ;=== If the parameter is not provided but the value is required
 ;    for the new exam status, check if the corresponding field
 ;=== has a non-empty value already.
 I '$D(@PNODE)  S RC=0  D:REQUIRED  Q $S(RC<0:RC,1:0)
 . ;--- If the IENS starts with a placeholder, then there is no data
 . S TMP=$P($G(IENS),",")
 . I 'TMP!(+TMP'=TMP)  S RC=$$ERROR^RAERR(-8,,PNODE)  Q
 . ;--- Word processing field
 . I TYPE["W"  D  Q
 . . N I,RABUF
 . . S TMP=$$GET1^DIQ(FILE,IENS,FIELD,,"RABUF","RAMSG")
 . . I $G(DIERR)  S RC=$$DBS^RAERR("RAMSG",-9,FILE,IENS)  Q
 . . S I=0,RC=1
 . . F  S I=$O(RABUF(I))  Q:I'>0  I RABUF(I)'?." "  S RC=0  Q
 . . S:RC RC=$$ERROR^RAERR(-8,,PNODE)
 . ;--- Other field types
 . S TMP=$$GET1^DIQ(FILE,IENS,FIELD,"I",,"RAMSG")
 . I $G(DIERR)  S RC=$$DBS^RAERR("RAMSG",-9,FILE,IENS)  Q
 . S:TMP="" RC=$$ERROR^RAERR(-8,,PNODE)
 ;
 ;=== Validate the word-processing parameter
 I TYPE["W"  S RC=0  D  Q $S(RC<0:RC,1:1)
 . N I
 . ;--- Check for data deletion request
 . I $D(@PNODE)<10  D  Q
 . . I REQUIRED!(@PNODE'?.1"@")  S RC=$$IPVE^RAERR(PNODE)  Q
 . . S RAFDA(FILE,IENS,FIELD)="@"
 . ;--- Check if the value is not empty
 . S I=0,RC=1
 . F  S I=$O(@PNODE@(I))  Q:I'>0  I @PNODE@(I)'?." "  S RC=0  Q
 . I RC  S RC=$$IPVE^RAERR(-8,,PNODE)  Q
 . S RAFDA(FILE,IENS,FIELD)=PNODE
 ;
 ;=== Pre-process the parameter value according to the field type.
 ;=== Deletion of required field values is never allowed.
 S VALUE=$P($G(@PNODE),U)
 I VALUE'?.1"@"  D
 . ;--- Pre-process the parameter value according to the field type
 . I TYPE["P"  S VALUE=$$VI(VALUE)  Q
 . I TYPE["D"  S VALUE=$$FMTE^XLFDT(VALUE)   Q
 E  Q:REQUIRED $$IPVE^RAERR(PNODE)
 ;
 ;=== Let the FileMan validate the parameter value
 D VAL^DIE(FILE,IENS,FIELD,"F",VALUE,.RARES,"RAFDA","RAMSG")
 Q:$G(DIERR) $$DBS^RAERR("RAMSG",-9)
 Q $S(RARES="^":$$IPVE^RAERR(PNODE),1:1)
 ;
 ;+++++ RETURNS PSEUDO-EXTERNAL VALUE OF THE IEN
VI(IEN) ;
 Q $S(IEN?.1"@":IEN,1:"`"_IEN)