import { IBackboneElement, IBackboneType, IDataType, IDomainResource, IExtension, IResource } from '../base-models/library-interfaces'; import * as JSON from './json-helpers'; import { Base64BinaryType } from '../data-types/primitive/Base64BinaryType'; import { BooleanType } from '../data-types/primitive/BooleanType'; import { CanonicalType } from '../data-types/primitive/CanonicalType'; import { CodeType } from '../data-types/primitive/CodeType'; import { DateTimeType } from '../data-types/primitive/DateTimeType'; import { DateType } from '../data-types/primitive/DateType'; import { DecimalType } from '../data-types/primitive/DecimalType'; import { IdType } from '../data-types/primitive/IdType'; import { InstantType } from '../data-types/primitive/InstantType'; import { Integer64Type } from '../data-types/primitive/Integer64Type'; import { IntegerType } from '../data-types/primitive/IntegerType'; import { MarkdownType } from '../data-types/primitive/MarkdownType'; import { OidType } from '../data-types/primitive/OidType'; import { PositiveIntType } from '../data-types/primitive/PositiveIntType'; import { StringType } from '../data-types/primitive/StringType'; import { TimeType } from '../data-types/primitive/TimeType'; import { UnsignedIntType } from '../data-types/primitive/UnsignedIntType'; import { UriType } from '../data-types/primitive/UriType'; import { UrlType } from '../data-types/primitive/UrlType'; import { UuidType } from '../data-types/primitive/UuidType'; import { XhtmlType } from '../data-types/primitive/XhtmlType'; /** * Represents a parsable data type that can be constructed and includes a static parse method * to create an instance from JSON data. * * This type is used to encapsulate a class-like structure where instances can be created using the `new` operator, * and the class itself has additional functionality for parsing JSON input into an instance of the data type. * * @typeParam T - Extends the base `DataType` to specify the structure of the object created by this type. * * `parse` - A static method available on the type that accepts JSON data, parses it, and returns an instance * of the type T. Optionally, a specific field of the JSON data can be targeted by providing * `optSourceField` as a parameter. * * @category Utilities: FHIR Parsers */ export type ParsableDataType = { new (...args: any[]): T; parse: (sourceJson: JSON.Value, optSourceField?: string) => T | undefined; }; /** * Represents a parsable resource that can be constructed and includes a static parse method * to create an instance from JSON data. * * This type is used to encapsulate a class-like structure where instances can be created using the `new` operator, * and the class itself has additional functionality for parsing JSON input into an instance of the resource. * * @typeParam T - Extends the base `Resource` to specify the structure of the object created by this type. * * `parse` - A static method available on the type that accepts JSON data, parses it, and returns an instance * of the type T. Optionally, a specific field of the JSON data can be targeted by providing * `optSourceField` as a parameter. * * @category Utilities: FHIR Parsers */ export type ParsableResource = { new (...args: any[]): T; parse: (sourceJson: JSON.Value, optSourceField?: string) => T | undefined; }; /** * Represents a JSON structure that contains a primitive value and an associated sibling object. * * This interface is designed to encapsulate the handling of JSON primitive data types along with a related Element JSON object. * * - `dtJson`: Represents a primitive JSON value, which can be one of string, number, boolean, null, or undefined. * - `dtSiblingJson`: Represents a JSON object associated with `dtJson` to provide the related Element. * * @interface * @category Utilities: FHIR Parsers */ export interface PrimitiveTypeJson { dtJson: JSON.Value | undefined; dtSiblingJson: JSON.Object | undefined; } /** * A utility class for parsing and processing FHIR data types from JSON objects. * This class manages the conversion of JSON representations into FHIR-compliant complex and primitive data types, * supports handling extensions and backbone elements, and integrates datatype-specific parsing logic. * * @category Utilities: FHIR Parsers */ export declare class FhirParser { /** * A map that associates a string key with a specific ParsableDataType instance. * * The `parsableDataTypeMap` serves as a lookup table where keys represent * identifiable strings corresponding to specific data types, and values * are the associated ParsableDataType objects that define the parsing logic * and behavior for the respective data type. * * Key Value Structure: * - `string`: A unique identifier representing the associated data type. * - `ParsableDataType`: An instance of ParsableDataType that * encapsulates the parsing functionality and metadata for the specific data type. */ private readonly parsableDataTypeMap; /** * A map that associates a string key with a specific ParsableResource instance. * * The `parsableResourceMap` serves as a lookup table where keys represent * identifiable strings corresponding to specific resources, and values * are the associated ParsableResource objects that define the parsing logic * and behavior for the respective resource. * * Key Value Structure: * - `string`: A unique identifier representing the associated resource. * - `ParsableResource`: An instance of ParsableResource that * encapsulates the parsing functionality and metadata for the specific resource. */ private readonly parsableResourceMap; constructor(parsableDataTypeMap: Map>, parsableResourceMap: Map>); /** * Parses the provided JSON source into an instance of the specified data type. * * @template {string} T - the specific complex data type * @param {ParsableDataType} className - The class defining the data type to which the JSON should be parsed. * @param {JSON.Value} sourceJson - The JSON value that serves as the source for parsing. * @param {string} [optSourceField] - An optional source field name to identify the data model source field. * @returns {T | undefined} The parsed data as an instance of the specified type, or undefined if parsing fails. */ parseDataType(className: ParsableDataType, sourceJson: JSON.Value, optSourceField?: string): T | undefined; /** * Parses the provided JSON source into an instance of the specified resource. * * @template {string} T - the specific resource * @param {ParsableResource} className - The class defining the resource to which the JSON should be parsed. * @param {JSON.Value} sourceJson - The JSON value that serves as the source for parsing. * @param {string} [optSourceField] - An optional source field name to identify the data model source field. * @returns {T | undefined} The parsed data as an instance of the specified resource, or undefined if parsing fails. */ parseResource(className: ParsableResource, sourceJson: JSON.Value, optSourceField?: string): T | undefined; /** * Parses a given JSON object to create an Extension instance, handling nested extensions and value[x] types. * * @param {JSON.Object | undefined} json - The JSON object representing the FHIR Extension. * If undefined or does not contain valid FHIR data, returns undefined. * @returns {Extension | undefined} The initialized Extension instance derived from the JSON object, or undefined if input is invalid. * Throws an error if required properties are missing. * @throws {@link FhirError} If the Extension.url property is not provided. */ parseExtension(json: JSON.Object | undefined): IExtension | undefined; /** * Processes the given JSON representation of a FHIR element and updates the provided instance accordingly. * * @param instance - The DataType instance to populate with processed values. * @param dataTypeJson - The JSON representation of the FHIR element. If undefined, the method will return without processing. */ processElementJson(instance: IDataType, dataTypeJson: JSON.Value | undefined): void; /** * Processes a JSON representation of a `BackboneElement` and updates the provided instance with the parsed data. * * @param {IBackboneElement} instance - The `BackboneElement` instance to be populated with data. * @param {JSON.Value | undefined} dataJson - The JSON data containing the attributes of the `BackboneElement`. It can be undefined if no data is provided. */ processBackboneElementJson(instance: IBackboneElement, dataJson: JSON.Value | undefined): void; /** * Processes a BackboneType JSON object and populates the given BackboneType instance with its data. * * @param {IBackboneType} instance - The BackboneType instance to populate. Must not be null or undefined. * @param {JSON.Value | undefined} dataJson - The JSON structure containing the BackboneType data. If undefined or not containing valid FHIR data, the method exits without modifying the instance. */ processBackboneTypeJson(instance: IBackboneType, dataJson: JSON.Value | undefined): void; /** * Parses a polymorphic data type from a given JSON object based on a provided field name, source field, * and associated metadata, returning the corresponding data type if applicable. * * @param {JSON.Object} jsonObj - The JSON object containing the data to parse. * @param {string} sourceField - The original field name as it appears in the source. * @param {string} fieldName - The normalized or expected field name to use for parsing. * @param {DecoratorMetadataObject | null} metadata - Metadata object providing decorator information, or null if not applicable. * @returns {IDataType | undefined} - The parsed data type if successful, or undefined if parsing cannot be performed. */ parsePolymorphicDataType(jsonObj: JSON.Object, sourceField: string, fieldName: string, metadata: DecoratorMetadataObject | null): IDataType | undefined; /** * Parses the specified field from a JSON object and returns its corresponding data type if valid. * * @param {JSON.Object} jsonObj - The JSON object to parse the field data from. * @param {string} sourceField - The name of the source field for error messaging. * @param {string} fieldName - The specific field name to check and parse from jsonObj. * @param {string[]} supportedFieldNames - A list of valid field names that are supported for parsing. * @returns {IDataType | undefined} The parsed data type if valid, or undefined if parsing fails or the field is not present. * @throws {@link FhirError} If the field name exists directly in the JSON or if multiple matching fields are found. * @throws {@link JsonError} If an error occurs while parsing the data type. */ private getParsedDataType; /** * Retrieves and parses a specific data type value from the provided JSON object * based on the specified field name. This method handles both primitive and * complex data types, as well as their corresponding sibling values for primitives. * * @param {JSON.Object} jsonObj - The JSON object containing the data to be parsed. * @param {string} fieldName - The field name used to identify the specific data type key in the JSON object. * @returns {IDataType | undefined} - The parsed data as an instance of the specified type, or undefined if the key is not found or cannot be parsed. */ private getFhirDataTypeParseResults; /** * Verifies if the provided JSON object contains the expected resourceType. * * @param {JSON.Object} classJsonObj - JSON object representing the resource to be validated. * @param {string} resourceType - The expected resource type as a string. * @throws {@link FhirError} If the 'resourceType' field is missing, or its value does not match the expected resource type. */ verifyResourceType(classJsonObj: JSON.Object, resourceType: string): void; /** * Processes the given JSON data and updates the provided Resource instance accordingly. * * @param {IResource} instance - The data model instance that extends Resource to be updated. Must be defined. * @param {JSON.Value | undefined} dataJson - The JSON data object containing the resource properties to process. * Can be undefined. */ processResourceJson(instance: IResource, dataJson: JSON.Value | undefined): void; /** * Processes the given JSON data and updates the provided DomainResource instance accordingly. * * @param {IDomainResource} instance - The data model instance that extends DomainResource to be updated. Must be defined. * @param {JSON.Value | undefined} dataJson - The JSON data used to populate the DomainResource instance. * Can be undefined. */ processDomainResourceJson(instance: IDomainResource, dataJson: JSON.Value | undefined): void; /** * Parses the contained resources from a given JSON array and adds them to the provided DomainResource instance. * * @param {IDomainResource} instance - The DomainResource instance to which the parsed resources will be added. This parameter is required. * @param {JSON.Array} containedJsonArray - The JSON array containing the resources to be parsed. This parameter is required. * @param {string} sourceField - The source field used for tracking resource provenance during parsing. This parameter is required. */ parseContainedResources(instance: IDomainResource, containedJsonArray: JSON.Array, sourceField: string): void; /** * Parses an inline JSON resource and returns a Resource object if parsing is successful. * * @param {JSON.Value | undefined} json - The JSON object representing the resource to parse. Can be undefined or empty. * @param {string} sourceField - The field name or reference for identifying the source of the JSON data, used for error reporting. * @returns {IResource | undefined} The parsed Resource object if the JSON conforms to a valid resource structure, otherwise undefined. * @throws {@link FhirError} If the JSON is missing the 'resourceType' property. */ parseInlineResource(json: JSON.Value | undefined, sourceField: string): IResource | undefined; /** * Parses a JSON object input to create and populate an instance of `Base64BinaryType`. * * @param {JSON.Value | undefined} json - The JSON object to be parsed. * @param {JSON.Value} [siblingJson] - An optional sibling JSON object representing the inherited Element. * @returns {Base64BinaryType | undefined} - Returns an instance of `Base64BinaryType` if parsing is successful and valid; otherwise, returns undefined. */ parseBase64BinaryType(json: JSON.Value | undefined, siblingJson?: JSON.Value): Base64BinaryType | undefined; /** * Parses a JSON object input to create and populate an instance of `BooleanType`. * * @param {JSON.Value | undefined} json - The JSON object to be parsed. * @param {JSON.Value} [siblingJson] - An optional sibling JSON object representing the inherited Element. * @returns {BooleanType | undefined} Returns an instance of `BooleanType` if parsing is successful and valid; otherwise, returns undefined. */ parseBooleanType(json: JSON.Value | undefined, siblingJson?: JSON.Value): BooleanType | undefined; /** * Parses a JSON object input to create and populate an instance of `CanonicalType`. * * @param {JSON.Value | undefined} json - The JSON object to be parsed. * @param {JSON.Value} [siblingJson] - An optional sibling JSON object representing the inherited Element. * @returns {CanonicalType | undefined} Returns an instance of `CanonicalType` if parsing is successful and valid; otherwise, returns undefined. */ parseCanonicalType(json: JSON.Value | undefined, siblingJson?: JSON.Value): CanonicalType | undefined; /** * Parses a JSON object input to create and populate an instance of `CodeType`. * * @param {JSON.Value | undefined} json - The JSON object to be parsed. * @param {JSON.Value} [siblingJson] - An optional sibling JSON object representing the inherited Element. * @returns {CodeType | undefined} Returns an instance of `CodeType` if parsing is successful and valid; otherwise, returns undefined. */ parseCodeType(json: JSON.Value | undefined, siblingJson?: JSON.Value): CodeType | undefined; /** * Parses a JSON object input to create and populate an instance of `DateTimeType`. * * @param {JSON.Value | undefined} json - The JSON object to be parsed. * @param {JSON.Value} [siblingJson] - An optional sibling JSON object representing the inherited Element. * @returns {DateTimeType | undefined} Returns an instance of `DateTimeType` if parsing is successful and valid; otherwise, returns undefined. */ parseDateTimeType(json: JSON.Value | undefined, siblingJson?: JSON.Value): DateTimeType | undefined; /** * Parses a JSON object input to create and populate an instance of `DateType`. * * @param {JSON.Value | undefined} json - The JSON object to be parsed. * @param {JSON.Value} [siblingJson] - An optional sibling JSON object representing the inherited Element. * @returns {DateType | undefined} Returns an instance of `DateType` if parsing is successful and valid; otherwise, returns undefined. */ parseDateType(json: JSON.Value | undefined, siblingJson?: JSON.Value): DateType | undefined; /** * Parses a JSON object input to create and populate an instance of `DecimalType`. * * @param {JSON.Value | undefined} json - The JSON object to be parsed. * @param {JSON.Value} [siblingJson] - An optional sibling JSON object representing the inherited Element. * @returns {DecimalType | undefined} Returns an instance of `DecimalType` if parsing is successful and valid; otherwise, returns undefined. */ parseDecimalType(json: JSON.Value | undefined, siblingJson?: JSON.Value): DecimalType | undefined; /** * Parses a JSON object input to create and populate an instance of `IdType`. * * @param {JSON.Value | undefined} json - The JSON object to be parsed. * @param {JSON.Value} [siblingJson] - An optional sibling JSON object representing the inherited Element. * @returns {IdType | undefined} Returns an instance of `IdType` if parsing is successful and valid; otherwise, returns undefined. */ parseIdType(json: JSON.Value | undefined, siblingJson?: JSON.Value): IdType | undefined; /** * Parses a JSON object input to create and populate an instance of `InstantType`. * * @param {JSON.Value | undefined} json - The JSON object to be parsed. * @param {JSON.Value} [siblingJson] - An optional sibling JSON object representing the inherited Element. * @returns {InstantType | undefined} Returns an instance of `InstantType` if parsing is successful and valid; otherwise, returns undefined. */ parseInstantType(json: JSON.Value | undefined, siblingJson?: JSON.Value): InstantType | undefined; /** * Parses a JSON object input to create and populate an instance of `IntegerType`. * * @param {JSON.Value | undefined} json - The JSON object to be parsed. * @param {JSON.Value} [siblingJson] - An optional sibling JSON object representing the inherited Element. * @returns {IntegerType | undefined} Returns an instance of `IntegerType` if parsing is successful and valid; otherwise, returns undefined. */ parseIntegerType(json: JSON.Value | undefined, siblingJson?: JSON.Value): IntegerType | undefined; /** * Parses a JSON object input to create and populate an instance of `Integer64Type`. * * @param {JSON.Value | undefined} json - The JSON object to be parsed. * @param {JSON.Value} [siblingJson] - An optional sibling JSON object representing the inherited Element. * @returns {Integer64Type | undefined} Returns an instance of `Integer64Type` if parsing is successful and valid; otherwise, returns undefined. */ parseInteger64Type(json: JSON.Value | undefined, siblingJson?: JSON.Value): Integer64Type | undefined; /** * Parses a JSON object input to create and populate an instance of `MarkdownType`. * * @param {JSON.Value | undefined} json - The JSON object to be parsed. * @param {JSON.Value} [siblingJson] - An optional sibling JSON object representing the inherited Element. * @returns {MarkdownType | undefined} Returns an instance of `MarkdownType` if parsing is successful and valid; otherwise, returns undefined. */ parseMarkdownType(json: JSON.Value | undefined, siblingJson?: JSON.Value): MarkdownType | undefined; /** * Parses a JSON object input to create and populate an instance of `OidType`. * * @param {JSON.Value | undefined} json - The JSON object to be parsed. * @param {JSON.Value} [siblingJson] - An optional sibling JSON object representing the inherited Element. * @returns {OidType | undefined} Returns an instance of `OidType` if parsing is successful and valid; otherwise, returns undefined. */ parseOidType(json: JSON.Value | undefined, siblingJson?: JSON.Value): OidType | undefined; /** * Parses a JSON object input to create and populate an instance of `PositiveIntType`. * * @param {JSON.Value | undefined} json - The JSON object to be parsed. * @param {JSON.Value} [siblingJson] - An optional sibling JSON object representing the inherited Element. * @returns {PositiveIntType | undefined} Returns an instance of `PositiveIntType` if parsing is successful and valid; otherwise, returns undefined. */ parsePositiveIntType(json: JSON.Value | undefined, siblingJson?: JSON.Value): PositiveIntType | undefined; /** * Parses a JSON object input to create and populate an instance of `StringType`. * * @param {JSON.Value | undefined} json - The JSON object to be parsed. * @param {JSON.Value} [siblingJson] - An optional sibling JSON object representing the inherited Element. * @returns {StringType | undefined} Returns an instance of `StringType` if parsing is successful and valid; otherwise, returns undefined. */ parseStringType(json: JSON.Value | undefined, siblingJson?: JSON.Value): StringType | undefined; /** * Parses a JSON object input to create and populate an instance of `TimeType`. * * @param {JSON.Value | undefined} json - The JSON object to be parsed. * @param {JSON.Value} [siblingJson] - An optional sibling JSON object representing the inherited Element. * @returns {TimeType | undefined} Returns an instance of `TimeType` if parsing is successful and valid; otherwise, returns undefined. */ parseTimeType(json: JSON.Value | undefined, siblingJson?: JSON.Value): TimeType | undefined; /** * Parses a JSON object input to create and populate an instance of `UnsignedIntType`. * * @param {JSON.Value | undefined} json - The JSON object to be parsed. * @param {JSON.Value} [siblingJson] - An optional sibling JSON object representing the inherited Element. * @returns {UnsignedIntType | undefined} Returns an instance of `UnsignedIntType` if parsing is successful and valid; otherwise, returns undefined. */ parseUnsignedIntType(json: JSON.Value | undefined, siblingJson?: JSON.Value): UnsignedIntType | undefined; /** * Parses a JSON object input to create and populate an instance of `UriType`. * * @param {JSON.Value | undefined} json - The JSON object to be parsed. * @param {JSON.Value} [siblingJson] - An optional sibling JSON object representing the inherited Element. * @returns {UriType | undefined} Returns an instance of `UriType` if parsing is successful and valid; otherwise, returns undefined. */ parseUriType(json: JSON.Value | undefined, siblingJson?: JSON.Value): UriType | undefined; /** * Parses a JSON object input to create and populate an instance of `UrlType`. * * @param {JSON.Value | undefined} json - The JSON object to be parsed. * @param {JSON.Value} [siblingJson] - An optional sibling JSON object representing the inherited Element. * @returns {UrlType | undefined} Returns an instance of `UrlType` if parsing is successful and valid; otherwise, returns undefined. */ parseUrlType(json: JSON.Value | undefined, siblingJson?: JSON.Value): UrlType | undefined; /** * Parses a JSON object input to create and populate an instance of `UuidType`. * * @param {JSON.Value | undefined} json - The JSON object to be parsed. * @param {JSON.Value} [siblingJson] - An optional sibling JSON object representing the inherited Element. * @returns {UuidType | undefined} Returns an instance of `UuidType` if parsing is successful and valid; otherwise, returns undefined. */ parseUuidType(json: JSON.Value | undefined, siblingJson?: JSON.Value): UuidType | undefined; /** * Parses a JSON object input to create and populate an instance of `XhtmlType`. * * @param {JSON.Value | undefined} json - The JSON object to be parsed. * @param {JSON.Value} [siblingJson] - An optional sibling JSON object representing the inherited Element. * @returns {XhtmlType | undefined} Returns an instance of `XhtmlType` if parsing is successful and valid; otherwise, returns undefined. */ parseXhtmlType(json: JSON.Value | undefined, siblingJson?: JSON.Value): XhtmlType | undefined; } /** * Returns the primitive data type's value and its sibling Element, if any. * * @param datatypeJsonObj - source JSON object * @param sourceField - source data type name * @param primitiveFieldName - primitive's field name in datatypeJsonObj * @param jsonType - type of expected field's data * @returns object containing the primitive data plus its Element data, if any * * @category Utilities: FHIR Parsers */ export declare function getPrimitiveTypeJson(datatypeJsonObj: JSON.Object, sourceField: string, primitiveFieldName: string, jsonType: 'boolean' | 'number' | 'string'): PrimitiveTypeJson; /** * Returns an array containing the primitive data type's value and its sibling Element, if any. * * @param datatypeJsonObj - source JSON object * @param sourceField - source data type name * @param primitiveFieldName - primitive's field name in datatypeJsonObj * @param jsonType - type of expected field's data * @returns array containing objects of the primitive data plus its Element data, if any * * @category Utilities: FHIR Parsers */ export declare function getPrimitiveTypeListJson(datatypeJsonObj: JSON.Object, sourceField: string, primitiveFieldName: string, jsonType: 'boolean' | 'number' | 'string'): PrimitiveTypeJson[]; //# sourceMappingURL=FhirParser.d.ts.map