UNPKG

fhirbuilder

Version:
59 lines (58 loc) 3.58 kB
import { AttributeDefinition } from './definitions'; import { IReference, ResourceTypesType } from 'fhirtypes/dist/r4'; import type { BackboneElementType, DataTypeType } from 'fhirtypes/dist/r4/types'; export type fhirR4Types = DataTypeType | ResourceTypesType | BackboneElementType | 'EpisodeOfCareStatusHistory' | 'EpisodeOfCareDiagnosis' | 'Repeat' | 'CoverageClass' | 'CoverageCostToBeneficiary' | 'CoverageException'; export declare const InternalValidator: Record<string, any>; export interface ValidationError { error?: string; message?: string; path?: string; value?: any; [key: string]: any; } /** * @description Validates a model based on the model definition * @param data - the model to validate * @param definitions - the model definition * @param path - the path to the model * @param errors - the errors array * @returns {void} */ export declare const BaseValidator: <T extends Record<string, any>>(data: T | T[], definitions: readonly AttributeDefinition<T>[], path: string, errors: ValidationError[]) => void; export declare const validateAdditionalFields: <T>(data: any, definitions: readonly AttributeDefinition<T>[], path: string, errors: ValidationError[]) => void; export declare const validateRequiredFieldByDefinition: <T>(data: T, definitions: readonly AttributeDefinition<T>[], path: string, errors: ValidationError[]) => void; /** * Validates if the data contains valid enum values according to the definition. * @param data - The data to be validated. * @param definition - The attribute definition to validate against. * @param path - The path to the data being validated (used for error messages). * @param errors * @throws Error if the data does not match the allowed enum values. */ export declare const validateEnumValues: <T>(data: string, definition: AttributeDefinition<T>, path: string, errors: ValidationError[]) => void; /** * Validates if the data is an array when the definition requires it to be an array. * @param data - The data to be validated. * @param definition - The attribute definition to validate against. * @param path - The path to the data being validated (used for error messages). * @param errors * @throws Error if the data is not an array when it should be. */ export declare const validateArray: <T>(data: any, definition: AttributeDefinition<T>, path: string, errors: ValidationError[]) => void; export declare const validateObject: <T>(data: T | T[], definition: AttributeDefinition<T>, path: string, errors: ValidationError[]) => void; /** * @description Validates the format of a reference field. * @param value - The reference value to be validated. * @param resources - The list of valid resource params-types or 'all' to allow all resource params-types. * @param path - The path to the data being validated (used for error messages). * @param errors * @throws ReferenceException if the reference format is invalid or the resource type is not allowed. */ export declare const ValidateReferenceFormat: (value: IReference | IReference[], resources: (ResourceTypesType | "Any")[] | null | undefined, path: string, errors: ValidationError[]) => void; /** * @description Checks if a value is not null, undefined, an empty string, an empty array, or an empty object. * @param value - The value to be checked. * @returns True if the value is valid (not null, undefined, or empty), otherwise false. */ export declare function hasValue(value: any): boolean; export declare function parseValidator(name: fhirR4Types): (value: any, path: string, errors: any[]) => void;