Skip to main content

FHIR Typescript Types

Typescript types generated off of FHIR StructureDefinitions.

Usage

import { Observation, Patient, id } from "@iguhealth/fhir-types/r4/types";

const patient: Patient = {
name: [
{
use: "official",
given: ["Eve"],
family: "Williams",
},
],
active: true,
gender: "female",
address: [
{
use: "home",
line: ["2222 Home Street"],
},
],
telecom: [
{
use: "work",
value: "555-555-2003",
system: "phone",
},
],
birthDate: "1973-05-31",
identifier: [
{
type: {
coding: [
{
code: "SS",
system: "http://terminology.hl7.org/CodeSystem/v2-0203",
},
],
},
value: "444222222",
system: "http://hl7.org/fhir/sid/us-ssn",
},
],
resourceType: "Patient",
managingOrganization: {
reference: "Organization/hl7",
},
};

Sets

Sets can be used to determine whether a type is a resource, primitive or complex type. These are utilities that can be useful

namedescription
resourceTypesString set of FHIR resource types
complexTypesString set of FHIR complex types (HumanName, Identifier etc...).
primitiveTypesString set of FHIR primitive types (string, id, decimal etc...).

Usage

import { primitiveTypes, resourceTypes } from "@iguhealth/fhir-types/r4/sets";

function isPrimitiveType(type: string) {
returnprimitiveTypes.has(type);
}
function isResourceType(type: string) {
returnresourceTypes.has(type);
}

Utility Types

Various utility types generally used for Typescript generic functions.

NameDescription
ResourceTypeOne of the resourcetypes, ie "Patient", "Observation".
AResourceGeneric type with an argument of ResourceType, when passed in, returns an instance of ResourceType IE AResource<"Patient"> = Patient
ResourceAn instance of one of the resource types

Example

Pulled from @iguhealth/client this example passes in an argument of ResourceType which is a string of only allowed ResourceTypes and using AResource returns an object in conformance with the type passed in.

read<T extends ResourceType>(
ctx: CTX,
resourceType: T,
id: id
): Promise<AResource<T> | undefined>;