UNPKG

fhirbuilder

Version:
53 lines (52 loc) 2.65 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.QuestionnaireResponseItemValidator = QuestionnaireResponseItemValidator; const definitions_1 = require("../base/definitions"); const base_1 = require("../base"); const utils_1 = require("../../../commons/utils"); const models_1 = require("../../../../r4/models"); const operation_outcome_exception_1 = require("../../../commons/exceptions/operation-outcome.exception"); /** * @description The model fields for the QuestionnaireResponseItem model */ const modelFields = (0, definitions_1.createBackboneDefinition)([ { name: 'linkId', type: 'string', isArray: false, isRequired: false }, { name: '_linkId', type: 'Element', isArray: false, isRequired: false }, { name: 'definition', type: 'uri', isArray: false, isRequired: false }, { name: '_definition', type: 'Element', isArray: false, isRequired: false }, { name: 'text', type: 'string', isArray: false, isRequired: false }, { name: '_text', type: 'Element', isArray: false, isRequired: false }, { name: 'answer', type: 'QuestionnaireResponseAnswer', isArray: true, isRequired: false }, { name: 'item', type: 'QuestionnaireResponseItem', isArray: true, isRequired: false }, ]); function validateConformance(dataToValidate, path, errors) { // + qrs-1 Rule QuestionnaireResponse.item Nested item can't be beneath both item and answer (answer.exists() and item.exists()).not() if (dataToValidate.answer && dataToValidate.item) { errors.push(new operation_outcome_exception_1.OperationOutcomeIssueException({ severity: 'error', code: 'invalid', details: { text: `Path: ${path}.`, }, diagnostics: "[qrs-1] Rule: Nested item can't be beneath both item and answer (answer.exists() and item.exists()).not()", })); } } /** * @description Validates the QuestionnaireResponseItem model * @param dataToValidate - the QuestionnaireResponseItem model to validate * @param path - the path to the model * @param errors - the errors array */ function QuestionnaireResponseItemValidator(dataToValidate, path = 'QuestionnaireResponseItem', errors = []) { // Ensure that the model fields match the attributes of the model (0, utils_1.AssertModelFieldsMatchAttributes)(modelFields, new models_1.QuestionnaireResponseItem()); // Validate the model and add any errors to the errors array (0, base_1.ModelValidator)({ dataToValidate, modelDefinition: modelFields, path, errors, additionalValidation: [validateConformance], }); }