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

MAGUTL02.m

Go to the documentation of this file.
MAGUTL02 ;WOIFO/SG - PARAMETERS AND VALIDATION UTILITIES ; 3/9/09 12:53pm
 ;;3.0;IMAGING;**93**;Dec 02, 2009;Build 163
 ;; Per VHA Directive 2004-038, this routine should not be modified.
 ;; +---------------------------------------------------------------+
 ;; | Property of the US Government.                                |
 ;; | No permission to copy or redistribute this software is given. |
 ;; | Use of unreleased versions of this software requires the user |
 ;; | to execute a written test agreement with the VistA Imaging    |
 ;; | Development Office of the Department of Veterans Affairs,     |
 ;; | telephone (301) 734-0100.                                     |
 ;; |                                                               |
 ;; | The Food and Drug Administration classifies this software as  |
 ;; | a medical device.  As such, it may not be changed in any way. |
 ;; | Modifications to this software may result in an adulterated   |
 ;; | medical device under 21CFR820, the use of which is considered |
 ;; | to be a violation of US Federal Statutes.                     |
 ;; +---------------------------------------------------------------+
 ;;
 Q
 ;
 ;+++++ RETURNS THE PSEUDO-NAME (FOR ERROR MESSAGES) OF THE PARAMETER
PNAME(PNODE) ;
 Q "["_$E(PNODE,$F(PNODE,"("),$L(PNODE)-1)_"]"
 ;
 ;##### PARSES MAGMSC PARAMETER LIST INTO MAGMISC PARAMETER TREE
 ;
 ; .MAGMSC(      Reference to a local variable that stores misc.
 ;               RPC parameters as a "flat" list.
 ;
 ;   i)          Parameter
 ;                 ^01: Parameter name
 ;                 ^02: Seq# - sequential number for multi-value
 ;                      parameters. It can also contain the "R"
 ;                      suffix to indicate a record boundary.
 ;                 ^03: Parameter value
 ;                 ^04: Additional values associated with the
 ;                 ...  parameter.
 ;
 ; .MAGMISC(     Reference to a local variable where miscellaneous
 ;               parameters are returned as nodes.
 ;
 ;   PName,      Original value of the parameter PName.
 ;     "E")      External and internal values of the parameter
 ;     "I")      (if validation/conversion is performed)
 ;
 ;   MName,
 ;     Seq#)     Item of the list MName or the line of text (word-
 ;               processing) parameter MName.
 ;       "E")    External and internal values of the parameter
 ;       "I")    (if validation/conversion is performed)
 ;   RName,
 ;     Seq#,
 ;       FName,  Original value of the FName field of a parameter
 ;               record of the type RName.
 ;         "E")  External and internal values of the parameter
 ;         "I")  (if validation/conversion is performed)
 ;
 ; [.MAGMSPDS]   Reference to a local variable that stores the
 ;               parameter definition tree generated by the
 ;               $$LDMPDEFS^MAGUTL01. If this parameter is provided,
 ;               then automatic validation/conversion is performed.
 ;
 ; [MAGFLAGS]    Flags that control the execution (can be comnined):
 ;
 ;                 U  Return an error (-10) if an unknown/unsupported
 ;                    parameter value (there is no definition for
 ;                    this parameter in the MAGMSPDS) is found in the
 ;                    MAGMSC list.
 ;
 ;                    By default or if the MAGMSPDS parameter is
 ;                    not defined, all values are copied to the
 ;                    destination tree "as is".
 ;
 ;                 V  Perform additional validation using the CHK^DIE
 ;                    for those parameters that have associated file
 ;                    and field numbers.
 ;
 ; Return Values
 ; =============
 ;           <0  Error descriptor (see $$ERROR^MAGUERR)
 ;            0  Success
 ;
 ; Notes
 ; =====
 ;
 ; During the validation/conversion of pointers, pure numeric values
 ; are always treated as IENs.
 ;
 ; During the validation/conversion of sets of codes, the API checks
 ; for internal values first. So, if there is an ambiguity between
 ; internal and external values, the parameter value will be treated
 ; as the internal one.
 ;
RPCMISC(MAGMSC,MAGMISC,MAGMSPDS,MAGFLAGS) ;
 N MAGSRCI,RC  K MAGMISC
 S MAGFLAGS=$G(MAGFLAGS),MAGSRCI=""
 Q:$TR(MAGFLAGS,"UV")'="" $$IPVE^MAGUERR("MAGFLAGS")
 S RC=$$RPCMISCZ("MAGMSPDS","MAGMISC")
 Q $S(RC<0:RC,1:0)
 ;
 ;+++++ RECURSIVE PARSER OF MAGMSC RECORDS
 ;
 ; MSPDNODE      Node in the parameter definition tree (MAGMSPDS)
 ;
 ; DSTNODE       Node of the MAGMISC where values will be stored.
 ;
 ; [RECNAME]     Tag name and index of the current record. They are
 ; [RECNDX]      used to detect the record boundaries.
 ;
 ; Input Variables
 ; ===============
 ;   MAGFLAGS, MAGMSC, MAGSRCI
 ;
 ; Output Variables
 ; ================
 ;   MAGSRCI
 ;
 ; Return Values
 ; =============
 ;           <0  Error descriptor (see $$ERROR^MAGUERR)
 ;            0  Success
 ;            1  End of the list
 ;
 ; Notes
 ; =====
 ;
 ; This is an internal entry point. Do not call it from outside
 ; of this routine.
 ;
RPCMISCZ(MSPDNODE,DSTNODE,RECNAME,RECNDX) ;
 N FILE,FIELD,NAME,NDX,PNODE,RC,SRCVAL,TMP,TYPE,VAL,VALIDATE
 S RC=0
 ;
 ;===
 F  S MAGSRCI=$O(MAGMSC(MAGSRCI))  Q:MAGSRCI=""  D  Q:RC
 . S NAME=$TR($P(MAGMSC(MAGSRCI),U)," ")  Q:NAME=""
 . ;
 . ;=== Load the parameter descriptor
 . S TMP=$G(@MSPDNODE@("N",NAME))
 . S FILE=+TMP,FIELD=+$P(TMP,U,2),TYPE=$P(TMP,U,3)
 . ;
 . ;=== Check multiplicity of the parameter
 . S TMP=$TR($P(MAGMSC(MAGSRCI),U,2)," "),NDX=+TMP
 . I TMP["R"  S:TYPE'["R" TYPE=TYPE_"R"
 . I NDX>0  D
 . . S PNODE=$NA(@DSTNODE@(NAME,NDX))
 . . S:$D(@PNODE) RC=$$ERROR^MAGUERR(-18,,NDX,$$PNAME(PNODE))
 . . Q
 . E  D
 . . S PNODE=$NA(@DSTNODE@(NAME))
 . . S:$D(@PNODE)#2 RC=$$ERROR^MAGUERR(-17,,$$PNAME(PNODE))
 . . Q
 . Q:RC<0
 . ;
 . ;=== Check if parameter is supported
 . I '$D(@MSPDNODE@("N",NAME)),MAGFLAGS["U"  D  Q
 . . S RC=$$ERROR^MAGUERR(-10,,$$PNAME(PNODE))
 . . Q
 . ;
 . ;=== Check for record start/end
 . I TYPE["R"  D  Q
 . . ;--- If the name is the same as that of the current record, then
 . . ;    this either the end of the current record or a beginning of
 . . ;--- the next record of the same kind (and on the same level).
 . . I NAME=$G(RECNAME)  D:NDX'=$G(RECNDX)  S RC=2  Q
 . . . ;--- If the index is different from that of the current record,
 . . . ;    then this is a beginning of the next record. Let the
 . . . ;--- source line be re-processed on the upper execution level.
 . . . S MAGSRCI=$O(MAGMSC(MAGSRCI),-1)
 . . . Q
 . . ;--- Start processing field values of the record
 . . S RC=$$RPCMISCZ($NA(@MSPDNODE@("N",NAME)),PNODE,NAME,NDX)
 . . Q
 . ;
 . ;=== Copy the original value "as is"
 . S @PNODE=$P(MAGMSC(MAGSRCI),U,3,99999)
 . ;
 . ;=== Special processing of the parameter value
 . S VALIDATE=$S(MAGFLAGS["V":(FILE>0)&(FIELD>0),1:0)
 . S (SRCVAL,VAL)=$P(MAGMSC(MAGSRCI),U,3)
 . I '(VAL?.1"@")  D  Q:RC<0
 . . ;--- Convert the date/time value
 . . I TYPE["D"  D  Q
 . . . ;--- HL7 timestamp (TS)
 . . . I TYPE["H"  S VAL=$$HL7TFM^XLFDT(VAL)  I VAL'>0  D  Q
 . . . . S RC=$$IPVE^MAGUERR("SRCVAL",$$PNAME(PNODE))
 . . . ;--- If validation is requested, then the conversion
 . . . ;--- will be performed at the same time.
 . . . Q:VALIDATE
 . . . ;--- Otherwise, calculate the internal and external values
 . . . S VAL=$$DTI^MAGUTL03(VAL,"PST")
 . . . I VAL<0  S RC=$$IPVE^MAGUERR("SRCVAL",$$PNAME(PNODE))  Q
 . . . S @PNODE@("I")=VAL,@PNODE@("E")=$$FMTE^XLFDT(VAL)
 . . . Q
 . . ;--- Pointer
 . . I TYPE["P"  D:VALIDATE  Q
 . . . ;--- Construct the pseudo-external value for validation
 . . . S:+VAL=VAL VAL="`"_VAL
 . . . Q
 . . ;--- Set of codes
 . . I TYPE["S"  D:VALIDATE  Q
 . . . N MAGMSG
 . . . S TMP=$$EXTERNAL^DILFD(FILE,FIELD,,VAL,"MAGMSG")
 . . . S:TMP'="" VAL=TMP
 . . . Q
 . . Q
 . E  S (@PNODE@("I"),@PNODE@("E"),VAL)=""
 . ;
 . ;=== Validate the value if requested
 . I VALIDATE,VAL'=""  D  Q:RC<0
 . . N MAGMSG,MAGRES
 . . D CHK^DIE(FILE,FIELD,"E",VAL,.MAGRES,"MAGMSG")
 . . I MAGRES="^"  S RC=$$IPVE^MAGUERR("SRCVAL",$$PNAME(PNODE))  Q
 . . S @PNODE@("I")=MAGRES,@PNODE@("E")=MAGRES(0)
 . . Q
 . Q
 Q:RC<0 RC
 ;
 ;=== Check the required parameters
 S NAME=""
 F  S NAME=$O(@MSPDNODE@("Q",NAME))  Q:NAME=""  D  Q:RC<0
 . S PNODE=$NA(@DSTNODE@(NAME))
 . S:'$D(@PNODE) RC=$$ERROR^MAGUERR(-8,,$$PNAME(PNODE))
 . Q
 ;
 ;===
 Q $S(RC>1:0,'RC:1,1:RC)