Skip to content

Evaluate Template

The template mapping function is used to evaluate a template and replace embedded node tags with the data (nodes, cached values, etc) that they represent.

Template

A template is a string of text which contains embedded node tags (see Node Paths and Node Tags for more information). When QIE evaluates the template, the node tags are replaced with the data values they represent.

Escape node tag values for

When embedded node tags are replaced with the values they represent, those values can be escaped based on the format of the template they are being used with. QIE supports escaping values for the following formats:

Escape for Description
CSV Values are escaped for use in a CSV formatted message
HTML Values are escaped for use in an HTML formatted message
SQL Values are escaped for use in an SQL statement
XML Values are escaped for use in an XML formatted message

Calling qie.evaluateTemplate() from a script

The mapping function above is a UI wrapper around the qie.evaluateTemplate() script binding. Scripts that build content dynamically (for example, FHIR resources assembled from system-variable templates) call the binding directly. The positional signature is:

qie.evaluateTemplate(
   template,           // required - String containing node tags
   parameters,         // optional - Map; values used by {p:name} tags
   escapeFor,          // optional - 'csv' | 'html' | 'sql' | 'xml' | null
   isJSON,             // optional - true when the template is JSON (escapes for JSON)
   endpointURL,        // optional - replaces %%ENDPOINT_URL%% in the template
   alternateMessages   // optional - Message Model or array; populates {alt:...} and {alt-N:...} tags
);

All parameters after template are optional, but because the API is positional, intermediate parameters must be supplied (typically as null or false) when a later parameter is set. The most common shapes are:

// JSON template with parameter map
var json = qie.evaluateTemplate(jsonTemplate, params, null, true);

// SQL template with values escaped for safe interpolation
var sql = qie.evaluateTemplate(sqlTemplate, params, 'sql');

// JSON template, no parameters - just substitutes {s:...} / {m:...} from the current source/message
var json = qie.evaluateTemplate(qie.getVariable('Patient'), null, null, true);

Common node-tag prefixes inside the template are listed under Node Tags. See the Alternate Message Model subsection below for the {alt:...} tag and the trailing alternateMessages parameter.

Alternate Message Model

The {alt:nodePath} tag available in a template allows access to data from one or more alternate Message Models passed as the final argument to qie.evaluateTemplate(). These alternate messages are not the original source message or Message Models but instead are user defined data objects (such as database query results, web service query results, or other content from external systems) that you want to include in your output.

To use alternate messages, follow these steps:

  1. Obtain or create the data: This could come from a database query, a web service response, a file read from disk, or even a manually constructed string.

  2. Parse the data into Message Models: The raw string must be parsed using the qie parse string functions (e.g. qie.parseCSVString(), qie.parseHL7String(), qie.parseJSONString(), qie.parseXMLString(), etc.). This creates structured Message Models.

  3. Store the parsed Message Models in variables: Each parsed Message Model should be stored in a separate variable, which later be used as the alternate message input.

  4. Pass the variables to qie.evaluateTemplate(): The qie.evaluateTemplate() function takes several parameters, but the two most relevant for working with alternate messages are:

    • template (first parameter): A string containing node tags (e.g. {s:nodePath}, {m:nodePath}, {alt:nodePath}) that is replaced with actual values during evaluation.

    • alternateMessages (last parameter): The parsed Message Model(s) from step 3 that are not part of QIE's predefined objects (like Source, Message, or MessageCache). This argument accepts a single parsed Message Model, an array of Message Models, or a List of Message Models.

    Because qie.evaluateTemplate() takes positional arguments, the four parameters between template and alternateMessages (parameters, escapeFor, isJSON, endpointURL) must be supplied (typically as null or false) when supplying alternateMessages. For example:

    var altMessage = qie.parseJSONString('{"weight":"275lb"}');
    
    var result = qie.evaluateTemplate(
       "Primary weight={m:weight}, Alternate weight={alt:weight}",  // template
       null,                                                        // parameters
       null,                                                        // escapeFor
       false,                                                       // isJSON
       null,                                                        // endpointURL
       altMessage                                                   // alternateMessages
    );
    

    When passing more than one alternate Message Model, reference each by its position using the numbered form: {alt-1:...} is the first (equivalent to {alt:...}), {alt-2:...} is the second, {alt-3:...} is the third, and so on. The alternates are supplied as an array (or List) of Message Models. The example below combines a JSON Message Model and a CSV Message Model:

    // Parse a JSON string into a Message Model
    var jsonMessageModel = qie.parseJSONString(
       '{"patientId":"12345","firstName":"John","lastName":"Smith"}'
    );
    
    // Parse a CSV string (with a header row) into a Message Model
    var csvMessageModel = qie.parseCSVString(
       "memberId,plan,group\nABC9876,PPO Gold,GRP001",
       true,   // quoteValues
       '"',    // quoteChar
       ",",    // separator
       true    // headerRow
    );
    
    var template =
       "Patient: {alt-1:firstName} {alt-1:lastName} (ID {alt-1:patientId}); " +
       "Insurance: {alt-2:plan[1]} (Member {alt-2:memberId[1]}, Group {alt-2:group[1]})";
    
    var result = qie.evaluateTemplate(
       template,                                  // template
       null,                                      // parameters
       null,                                      // escapeFor
       false,                                     // isJSON
       null,                                      // endpointURL
       [jsonMessageModel, csvMessageModel]        // alternateMessages (array of Message model variables)
    );
    

Node tags are placeholders inside the template string. They define where the value should come from, using prefixes like:

  • {s:nodePath}: from the Source object. A tag written with no prefix at all, such as {nodePath}, reads the Source object as well.

  • {m:nodePath}: from the Message object

  • {mc:nodePath}: from the messageCache

  • {cc:nodePath}: from the channelCache

  • {sc:nodePath}: from the sharedCache

  • {v:variableName}: from a System Variable

  • {p:parameterName}: from the parameters map passed as the second argument

  • {alt:nodePath}, {alt-1:nodePath}, {alt-2:nodePath}, etc.: access data from one or more alternate messages passed in as the final parameter of qie.evaluateTemplate(). {alt:nodePath} and {alt-1:nodePath} both reference the first alternate message, {alt-2:nodePath} references the second, {alt-3:nodePath} the third, and so on.

Node Tags lists every prefix, along with the format indicators that Base64-encode a value, format a date, mark a tag required, or parse the value as another message format.