npm package: @paq-ts-fhir/r4-datamodels
Description: Generated FHIR R4 data model package
Author: Joe Paquette
Latest version: 1.2.0

# FHIR R4 Data Model Library

The TypeScript data models in this package were generated for all FHIR R4 resources and complex types.
TypeScript classes were generated for each [FHIR R4 resource](https://hl7.org/fhir/R4/resourcelist.html) and
[FHIR R4 complex type](https://hl7.org/fhir/R4/datatypes.html#complex) as defined by their corresponding
FHIR `StructureDefinition`.

## Background

The [HAPI FHIR](https://hapifhir.io/hapi-fhir/docs/model/working_with_resources.html) ecosystem (implemented in Java)
includes data model classes representing FHIR resources and data types.
These data model classes include a number of getters and setters for the basic properties of that data model along with
many convenience methods.
These HAPI FHIR data models provided the inspiration for the design of the TypeScript data models generated for this
project.

A proof-of-concept (POC) project was undertaken to arrive at a design for TypeScript that could easily be applied to
generated data models.
This POC project resulted in contents for a core library that contains the base data models, implementations of the FHIR
primitive data types, and various utilities required by the data models.
These are implemented in the `@paq-ts-fhir/fhir-core` library.
This generated data model project takes this library as its sole dependency.
Additionally, a set of implementation patterns were identified to facilitate code generation of data models for
resources and complex data types.

## Getting Started

This `@paq-ts-fhir/r4-datamodels` package is intended to be installed as a dependency in your TypeScript/JavaScript
project for use within a [Node.js](https://nodejs.org/en) environment.
The minimum supported version of Node.js is **v22.11.0 (LTS)**.
To install this package, run the following command in your project directory:

```shell
> npm install @paq-ts-fhir/r4-datamodels -P
```

This package's only dependency is the `@paq-ts-fhir/fhir-core` library whose only dependencies are the
[Luxon](https://moment.github.io/luxon/#/?id=luxon-3x) and [Zod](https://zod.dev/) libraries.

## Data Model Classes

The FHIR data model class hierarchy is based on the [FHIR Type Framework](https://hl7.org/fhir/types.html).
All FHIR resource data models extend either `Resource` or `DomainResource`.
According to the FHIR specification, only `DomainResource`, `Bundle`, `Parameters`, and `Binary` extend `Resource`.
All other FHIR resources extend `DomainResource`.
All FHIR complex data types extend either `DataType` or `BackboneType`.
All FHIR primitive data types extend `PrimitiveType<T>` where `T` represents the FHIR primitive as defined in the
[FHIR Specification](https://www.hl7.org/fhir/datatypes.html#primitive) and implemented in the `@paq-ts-fhir/fhir-core`
library.

Additional "component" classes are also generated for each `BackboneElement` defined in a resource.
While generated as separate classes, these "component" classes have no meaning on their own and should only be used
as a special data type defined within a resource.

Finally, "pseudo-enumeration" classes based on a FHIR `CodeSystem` were generated for each primitive `code` element
defined in a resource or complex type.
These are generated when the `code` element has a `binding.strength` of `required` with a `binding.valueSet` URL.
These classes are used to represent the values of `code` elements that are defined in the FHIR specification.

## Additional Information

[Release Notes](https://paqrat76.github.io/ts-fhir-datamodels/documents/Common_Documentation.Release_Notes.html)
are available for all published FHIR data model libraries.

For more information on the data models generated by this package, refer to the
[API Documentation](https://paqrat76.github.io/ts-fhir-datamodels/modules/_paq-ts-fhir_r4-datamodels.html) and the
[User Guide](https://paqrat76.github.io/ts-fhir-datamodels/documents/Common_Documentation.User_Guide.html).

For background information on the generation of these data models, refer to content
in [dev-docs](https://github.com/Paqrat76/ts-fhir-datamodels/tree/main/dev-docs).