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

HMPJSON.m

Go to the documentation of this file.
  1. HMPJSON ;SLC/KCM,ASMR/RRB - Decode/Encode JSON;9/25/2015 10:15
  1. ;;2.0;ENTERPRISE HEALTH MANAGEMENT PLATFORM;**;Sep 01, 2011;Build 63
  1. ;Per VA Directive 6402, this routine should not be modified.
  1. ;
  1. Q
  1. ;
  1. ; Note: Since the routines use closed array references, VVROOT and VVERR
  1. ; are used to reduce risk of naming conflicts on the closed array.
  1. ;
  1. DECODE(VVJSON,VVROOT,VVERR) ; Set JSON object into closed array ref VVROOT
  1. ; Examples: D DECODE^HMPJSON("MYJSON","LOCALVAR","LOCALERR")
  1. ; D DECODE^HMPJSON("^MYJSON(1)","^GLO(99)","^TMP($J)")
  1. ;
  1. ; VVJSON: string/array containing serialized JSON object
  1. ; VVROOT: closed array reference for M representation of object
  1. ; VVERR: contains error messages, defaults to ^TMP("HMPJERR",$J)
  1. ;
  1. ; VVIDX: points to next character in JSON string to process
  1. ; VVSTACK: manages stack of subscripts
  1. ; VHMPOP: true if next string is property name, otherwise treat as value
  1. ;
  1. G DIRECT^HMPJSOND
  1. ;
  1. ENCODE(VVROOT,VVJSON,VVERR) ; VVROOT (M structure) --> VVJSON (array of strings)
  1. ; Examples: D ENCODE^HMPJSON("^GLO(99,2)","^TMP($J)")
  1. ; D ENCODE^HMPJSON("LOCALVAR","MYJSON","LOCALERR")
  1. ;
  1. ; VVROOT: closed array reference for M representation of object
  1. ; VVJSON: destination variable for the string array formatted as JSON
  1. ; VVERR: contains error messages, defaults to ^TMP("HMPJERR",$J)
  1. ;
  1. G DIRECT^HMPJSONE
  1. ;
  1. ;
  1. ESC(X) ; Escape string for JSON
  1. Q $$ESC^HMPJSONE(X)
  1. ;
  1. UES(X) ; Unescape JSON string
  1. Q $$UES^HMPJSOND(X)
  1. ;
  1. ERRX(ID,VAL) ; Set the appropriate error message
  1. ; switch (ID) -- XERRX ends statement
  1. N ERRMSG
  1. ;
  1. ; Decode Error Messages
  1. ;
  1. I ID="STL{" S ERRMSG="Stack too large for new object." G XERRX
  1. I ID="SUF}" S ERRMSG="Stack Underflow - extra } found" G XERRX
  1. I ID="STL[" S ERRMSG="Stack too large for new array." G XERRX
  1. I ID="SUF]" S ERRMSG="Stack Underflow - extra ] found." G XERRX
  1. I ID="OBM" S ERRMSG="Array mismatch - expected ] got }." G XERRX
  1. I ID="ARM" S ERRMSG="Object mismatch - expected } got ]." G XERRX
  1. I ID="MPN" S ERRMSG="Missing property name." G XERRX
  1. I ID="EXT" S ERRMSG="Expected true, got "_VAL G XERRX
  1. I ID="EXF" S ERRMSG="Expected false, got "_VAL G XERRX
  1. I ID="EXN" S ERRMSG="Expected null, got "_VAL G XERRX
  1. I ID="TKN" S ERRMSG="Unable to identify type of token, value was "_VAL G XERRX
  1. I ID="SCT" S ERRMSG="Stack mismatch - exit stack level was "_VAL G XERRX
  1. I ID="EIQ" S ERRMSG="Close quote not found before end of input." G XERRX
  1. I ID="EIU" S ERRMSG="Unexpected end of input while unescaping." G XERRX
  1. I ID="RSB" S ERRMSG="Reverse search for \ past beginning of input." G XERRX
  1. I ID="ORN" S ERRMSG="Overrun while scanning name." G XERRX
  1. I ID="OR#" S ERRMSG="Overrun while scanning number." G XERRX
  1. I ID="ORB" S ERRMSG="Overrun while scanning boolean." G XERRX
  1. I ID="ESC" S ERRMSG="Escaped character not recognized"_VAL G XERRX
  1. ;
  1. ; Encode Error Messages
  1. ;
  1. I ID="SOB" S ERRMSG="Unable to serialize node as object, value was "_VAL G XERRX
  1. I ID="SAR" S ERRMSG="Unable to serialize node as array, value was "_VAL G XERRX
  1. S ERRMSG="Unspecified error "_ID_" "_$G(VAL)
  1. XERRX ; end switch
  1. S @VVERR@(0)=$G(@VVERR@(0))+1
  1. S @VVERR@(@VVERR@(0))=ERRMSG
  1. S VVERRORS=VVERRORS+1
  1. Q