Starting with QIE 26.2.1, qie.createJSONMessage(), qie.parseJSONString() and message.setJSONObject() accept a JavaScript object or array directly. You no longer need to call JSON.stringify() first.
Before QIE 26.2.1, each value had to be converted to a string first:
message = qie.createJSONMessage(JSON.stringify({patientId: "12345", status: "active"}));
var lookup = qie.parseJSONString(JSON.stringify({mrn: "A100", visits: [1, 2, 3]}));
message.setJSONObject('/', JSON.stringify({patientId: "12345", status: "active"}));
In QIE 26.2.1 and later, pass the value directly:
message = qie.createJSONMessage({patientId: "12345", status: "active"});
var lookup = qie.parseJSONString({mrn: "A100", visits: [1, 2, 3]});
message.setJSONObject('/', {patientId: "12345", status: "active"});JSON strings still work, so existing scripts do not need to change.
WHAT YOU CAN PASS
- JavaScript objects: {id: 1, name: "test"}
- JavaScript arrays: ["x", "y", "z"]
- JavaScript Map objects: new Map()
- Java maps, collections and arrays, such as java.util.HashMap, java.util.ArrayList, or an array returned by a Java call
- A JSON string, as before
For example, an array becomes a JSON array message:
var codes = qie.parseJSONString(["A01", "A04", "A08"]);
qie.debug(codes.getNode('/[2]')); // A04A JavaScript Map passed directly becomes a JSON object:
var values = new Map();
values.set("mrn", "A100");
values.set("visitCount", 3);
var lookup = qie.parseJSONString(values);
qie.debug(lookup.getNode('/mrn')); // A100REPLACING THE WHOLE MESSAGE
Use message.setJSONObject() with the node path '/' to replace the whole message with an object:
message.setJSONObject('/', {resourceType: "Patient", id: "12345", active: true});
Calling message.setJSONObject('/') with no value resets the message to an empty object, {}.
To set an object or array at a specific node instead of the root, give that node's path:
message.setJSONObject('/patient/identifiers', [{system: "MRN", value: "A100"}]);USE setJSONObject(), NOT setNode(), FOR OBJECTS
message.setNode() sets text values. If you pass it a JavaScript object, QIE stops the script with this error:
Use message.setJSONObject() to set node to native JSON.
Change the call to message.setJSONObject() with the same node path and value.
Arrays do not raise this error. message.setNode('/codes', ["A01", "A04"]) stores the text "A01,A04" instead of a JSON array, so always use message.setJSONObject() for arrays too.
A Map INSIDE AN OBJECT IS NOT CONVERTED
QIE converts a Map that you pass directly, but not a Map nested inside another object or array. JavaScript converts a nested Map to an empty object {}, so its entries are lost. Convert the nested Map to a plain object with Object.fromEntries():
var identifiers = new Map();
identifiers.set("MRN", "A100");
message = qie.createJSONMessage({
patientId: "12345",
identifiers: Object.fromEntries(identifiers)
});