UNPKG

fhirbuilder

Version:
56 lines (55 loc) 2.14 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.BundleValidator = BundleValidator; const definitions_1 = require("../base/definitions"); const base_1 = require("../base"); const utils_1 = require("../../../commons/utils"); const models_1 = require("../../../../r4/models"); /** * @description The model fields for the Bundle model */ const modelFields = (0, definitions_1.createResourceDefinition)([ { name: 'identifier', type: 'Identifier', isArray: false, isRequired: false }, { name: 'type', type: 'code', isArray: false, isRequired: true, enumValues: [ 'document', 'message', 'transaction', 'transaction-response', 'batch', 'batch-response', 'history', 'searchset', 'collection', ], }, { name: '_type', type: 'Element', isArray: false, isRequired: false }, { name: 'timestamp', type: 'instant', isArray: false, isRequired: false }, { name: '_timestamp', type: 'Element', isArray: false, isRequired: false }, { name: 'total', type: 'unsignedInt', isArray: false, isRequired: false }, { name: '_total', type: 'Element', isArray: false, isRequired: false }, { name: 'link', type: 'BundleLink', isArray: true, isRequired: false }, { name: 'entry', type: 'BundleEntry', isArray: true, isRequired: false }, { name: 'signature', type: 'Signature', isArray: false, isRequired: false }, ]); /** * @description Validates the Bundle model * @param dataToValidate - the Bundle model to validate * @param path - the path to the model * @param errors - the errors array */ function BundleValidator(dataToValidate, path = 'Bundle', errors = []) { // Ensure that the model fields match the attributes of the model (0, utils_1.AssertModelFieldsMatchAttributes)(modelFields, new models_1.Bundle()); // Validate the model and add any errors to the errors array (0, base_1.ModelValidator)({ dataToValidate, modelDefinition: modelFields, path, errors, }); }