UNPKG

fhirbuilder

Version:
47 lines (46 loc) 2.03 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.CoverageCostToBeneficiaryValidator = CoverageCostToBeneficiaryValidator; 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 CoverageCostToBeneficiary model */ const modelFields = (0, definitions_1.createBackboneDefinition)([ { name: 'type', type: 'CodeableConcept', isArray: false, isRequired: false }, { name: 'valueQuantity', type: 'Quantity', isArray: false, isRequired: false }, { name: 'valueMoney', type: 'Money', isArray: false, isRequired: false }, { name: 'exception', type: 'CoverageException', isArray: true, isRequired: false }, ]); /** * @description Validates the CoverageCostToBeneficiary model * @param dataToValidate - the CoverageCostToBeneficiary model to validate * @param path - the path to the model * @param errors - the errors array */ function CoverageCostToBeneficiaryValidator(dataToValidate, path = 'CoverageCostToBeneficiary', errors = []) { // Ensure that the model fields match the attributes of the model (0, utils_1.AssertModelFieldsMatchAttributes)(modelFields, new models_1.CoverageCostToBeneficiary()); // Validate the model and add any errors to the errors array (0, base_1.ModelValidator)({ dataToValidate, modelDefinition: modelFields, path, errors, additionalValidation: [ValidateConformance], }); } function ValidateConformance(dataToValidate, path = 'Conformance', errors = []) { if (!dataToValidate.valueQuantity && !dataToValidate.valueMoney) { errors.push({ severity: 'error', code: 'required', details: { text: `Path: ${path}`, }, diagnostics: `The CoverageCostToBeneficiary must have either a valueQuantity or valueMoney`, }); } }