JavaScript Validation

HL7 Message JavaScript Engine API

The JavaScript engine allows you to create custom validation rules, which will be used during the conformance validation of your HL7 messages.

You can add custom javascript validation rules at the profile, trigger-event, segment and data-type levels. The javascript rules will be evaluated during the HL7 message validation, depending on the element of the message being validated.

Profile: Validation rules added at the Profile level will be evaluated first and only once per message.

Trigger-Event: Validation rules added at the Trigger-Event level will be evaluated only once per message and will only be evaluated for matching messages. The MSH.9 – Message Type is used to match messages and trigger-events.

Segment: Validation rules added at the Segment level will be evaluated for each instances of the segment in a message.

Data-Type: Validation rules added at the Data-Type level will be evaluated for each instances of the data-type in a message.

By using the callback() method, you can notify the message validator when an error has occurred. You can provide callback() with an error message as a string, or with a ValidationError object.

 

HL7 Message Validation Context

During HL7 message validation, the JavaScript engine context is updated, allowing you to access the current element being validated.  The context has the following properties you can refer to:

  • profile: Allows you to fetch data from profile. See the Profile object definition.
  • message: Allows you to access the message being validated and any of its properties or methods. See the Message object definition
  • segment: Allows you to access the current segment being validated and any of its properties or methods. See the Segment object definition.
  • field: Allows you to access the current field being validated and any of its properties or methods. See the Field object definition.
  • component: Allows you to access the current component being validated and any of its properties or methods. See the Component object definition.
  • subComponent: Allows you to access the current sub-component being validated. See the SubComponent object definition.
  • dataType: Allows you to access the current data-type instance being validated. The dataType can be any Field, Component or SubComponent.

 

ValidationError

The ValidationError allows you to return a customized validation error in the callback method. The ValidationError object exposes the following properties and methods:

Constructors

ValidationError()

Returns a new, empty ValidationError.

var validationError = new ValidationError();
callback(validationError);
// Returns a new ValidationError object in the callback method.

Properties

summary: string

A summary of the error.

var validationError = new ValidationError();
validationError.summary = 'Invalid Medical Number';
// The validation error's summary should be 'Invalid Medical Number'

description: string

A detailed description of the error.

var validationError = new ValidationError();
validationError.description = 'PID.3 does not contain a valid MR - Medical Number for the patient';
// The validation error's description should be 'PID.3 does not contain a valid MR - Medical Number for
// the patient'

Methods

toString(): string

Returns the JSON string value of the ValidationError.

var validationError = new ValidationError();
validationError.description = 'PID.3 does not contain a valid MR - Medical Number for the patient';
var validationErrorString = validationError.toString();
// validationErrorString should be '{ "description":"PID.3 does not contain a valid MR - Medical Number for the patient"}'