Changelog Azalea Kit UI 101 Usage Customizing Utilities Form controls Laravel Vue FHIR Types Accessibility Icons Actions Button Button group Layout and structure Card Card section Care summary Care timeline Divider Empty state Footer Header Layout Stack Table Selection and input Calendar Checkbox Checkbox group Color picker Combobox Combobox option Input Input mask Memorable date Number input Option Phone input Radio Radio button Radio group Range Select SSN input Tag Textarea Toggle ZIP code input Images and icons Avatar Icon Icon button Logo Feedback indicators Badge Banner Progress bar Skeleton Skeleton body text Skeleton display text Skeleton thumbnail Spinner Typography Text Navigation Breadcrumb Breadcrumb item Dropdown Menu Menu item Menu label Navigation Nav group Nav item Nav toggle Pagination Tab Tab group Tab panel Top bar Tree Tree item User menu Overlays Dialog Popover Tooltip Utilities Collapsible FHIR address FHIR human name FHIR quantity FHIR questionnaire Format bytes Format date Format number Relative time Resize observer Split panel Tooltip Border Color Shadow Spacing Transition Typography Z-index Contributing Visual Tests Light Dark System

FHIR Types

Azalea Kit UI also provides TypeScript definitions for FHIR R4 resources, complex data types, and finite value sets.

Usage

The FHIR types are split up into a few different files, resources, datatypes, metadatatypes, valuesets, and extensions.

Resources Data types Metadata types Value sets Extensions

resources exports some of the resources listed in the FHIR Resources index.

import type {...} from '@azaleahealth/azalea-kit-ui/fhir/resources';

Resource types can also be imported from their individual files, as well as any extensions that resource has defined.

import type Communication, {
  CommunicationExtensionReadFlag
} from '@azaleahealth/azalea-kit-ui/fhir/resources/Communication';

datatypes exports all general-purpose complex data types as described in the FHIR data types documentation (with a few exceptions, see Quantity Variants), as well as some of the special purpose data types.

import type {...} from '@azaleahealth/azalea-kit-ui/fhir/datatypes';

metadatatypes exports all metadata types as described in the FHIR metadata types documentation.

import type {...} from '@azaleahealth/azalea-kit-ui/fhir/metadatatypes';

valuesets exports a namespace called ValueSets that contains some of the value sets listed in the FHIR value sets index as string unions.

import type { ValueSets } from '@azaleahealth/azalea-kit-ui/fhir/valuesets';

extensions exports all extension types that are used across multiple resources.

import type { TextExtension } from '@azaleahealth/azalea-kit-ui/fhir/extensions';

Example

import type { Bundle, DocumentReference } from '@azaleahealth/azalea-kit-ui/fhir/resources';
import type { ValueSets } from '@azaleahealth/azalea-kit-ui/fhir/valuesets';

// We can use the DocumentReferenceStatus value set here to make sure only valid statuses are used
async function getDocuments(status: ValueSets.DocumentReferenceStatus): Promise<Bundle<DocumentReference>> {
  const documentsResponse = await fetch(
    'example.com/my/fhir/server/DocumentReference?' + new URLSearchParams({ status }).toString(),
    {
      method: 'GET',
      headers: {
        Accept: 'application/fhir+json',
        Authorization: 'your-auth-token-here'
      }
    }
  );

  const documentBundle = await documentsResponse.json();

  // We know that the endpoint we fetched should return a Bundle of DocumentReferences
  return documentBundle as Bundle<DocumentReference>;
}

Generic Types

Some of our types are defined as generic for ease of use.

Bundle

The Bundle resource can take a type argument to define the expected resource type contained in its entries.

// allergies-api.ts
import { AllergyIntolerance, Bundle } from './fhir/resources';

function searchAllergies(): Bundle<AllergyIntolerance> {
  //...
}

// Will be typed as AllergyIntolerance
const firstAllergy = searchAllergies().entry?.[0]?.resource;

Parameters

The Parameters resource can take a type argument to define the expected value[x] key and type.

import type { Address } from '@azaleahealth/azalea-kit-ui/fhir/datatypes';
import type { Parameters } from '@azaleahealth/azalea-kit-ui/fhir/resources';

const param: Parameters<{ valueAddress: Address }> = {
  parameter: [
    {
      name: 'address',
      valueAddress: {/* ... */}
    }
  ]
};

Coding and CodeableConcept

The Coding datatype can take a type argument to define the expected possible values of Coding.code. CodeableConcept will pass its type argument on to its code property (which is of type Coding[]).

import { CodeableConcept, Coding } from '@azaleahealth/azalea-kit-ui/fhir/datatypes';
import { ValueSets } from '@azaleahealth/azalea-kit-ui/fhir/valuesets';

const appointmentStatusCoding: Coding<ValueSets.AppointmentStatus> = { code: 'arrived' };

const bundleTypeCodeable: CodeableConcept<ValueSets.BundleType> = { coding: [] };

// type error here!
bundleTypeCodeable.coding?.push(appointmentStatusCoding);

Choice-of Properties

Choice-of properties (notated as nnn[x] in the FHIR documentation) at the top level cannot be perfectly implemented due to the limitations of TypeScript. Instead, they have been implemented as optional properties regardless of the cardinality of the choice-of property they represent and are documented with the name and cardinality of said property.

For example, the Annotation datatype has a property author[x] and is defined as

export interface Annotation extends Element {
  /** author[x] 0..1 Reference(Practitioner | Patient | RelatedPerson | Organization) */
  authorReference: Reference;
  /** author[x] 0..1 */
  authorString: string;
  /** dateTime */
  time?: string;
  /** markdown */
  text: string;
}

For choice-of properties not at the top level, such as Dosage.dosageAndRate[0].rate[x] we are able to properly represent the mutual exclusivity of the properties in TypeScript.

Quantity Variants

The Quantity data type has a few variants that cannot be meaningfully represented in TypeScript, and as such we have elected not to include them. These are Distance, Age, Count, and Duration. Instead we have treated properties of these types as we do primitive types, by typing them as Quantity and including a doc comment with the more specific type.

Reporting Issues and Requesting Features

If you have found an issue with the FHIR types or would like to request a missing type be added, please open a ticket in JIRA in the Azalea Kit UI project assigned to Connor Dooley. Please include a link to the relevant FHIR documentation and a description of what you would like added or the discrepancy between the official documentation and the TypeScript implementation.