JavaScript Validation

Javascript Validation

After a task is executed, you can validate the task result with different validation types. One of them is Javascript Validation, which allows you to code multiple validation rules using Javascript.

By using the callback() method, you can notify the task when an error has occurred during one of the validations. You can provide callback() with an error message as a string.

All your Validation Rules are executed independently.

 

Task Validation Context

The Javascript validation context object allows you to access the task result, as well as a map that is shared between different validations in the same task.

Poperties

The context object contains the following properties.

taskResult: string

The result returned by the task. Using the task result, you can use the HL7, XML, or JSON parser to parse the text result as a queryable object and build sophisticated validations with it.

var result = context.taskResult;

map: Map

A Map that is shared between different validations in the same task.

context.map.set("PID.5.1", "Smith");
callback("PID.5.1: " + context.map.get("PID.5.1"));
// PID.5.1: Smith

 

Map

The Map object is a collection of key-value (string-object) pairs that can be added and updated.

Methods

The Map object exposes the following methods.

set(key: string, value: object): void

Updates the key’s value to the provided value. If the key does not exist in the map, adds the key-value pair to the map.

get(key: string): object

Returns the value associated with the key in the map. If the key does not exist in the map, returns null.

map.set("PID.5", { family: "Smith", given: "John" });
callback("PID.5 Given: " + context.map.get("PID.5").given);
// PID.5 Given: John

has(key: string): bool

Returns whether or not the key exists in the map.

map.set("PID.5", { family: "Smith", given: "John" });
callback("Contains PID.5: " + map.has("PID.5"));
// Contains PID.5: true