FHIR-Native Type Safety

Commure provides a package of statically-defined FHIR types to allow developers to easily make their applications usage of FHIR data type-safe.

Why is Type-Safety Important?

Using a type-checker can help detect or eliminate a large swath of bugs that are common in software development.

@commure/fhir-types

This library contains statically-defined types for both PropTypes and TypeScript. It includes all FHIR R4 Resources as well as all primitive and complex datatypes.

TypeScript Usage

This example creates a component specifying it takes one required prop, patient, and that patient should be an object in the shape of a Patient.

1import React from "react";
2import { Patient, HumanName, date } from "@commure/fhir-types/r4/types";
3import { FhirHumanName, FhirDateTime } from "@commure/components-core";
4
5interface Props {
6 patient: Patient;
7}
8
9const MyPatientInfo = ({ patient }: Props) => {
10 const patientName: HumanName | undefined = patient.name && patient.name[0];
11 const patientBirthDate: date | undefined = patient.birthDate;
12 return (
13 <div>
14 <FhirHumanName value={patientName} />
15 <FhirDateTime value={patientBirthDate} />
16 </div>
17 );
18};

PropTypes Usage

This example does the same thing but with PropTypes instead of TypeScript.

1import React from "react";
2import { Patient } from "@commure/fhir-types/r4/proptypes";
3
4const MyPatientCard = ({ patient }) => {
5 const patientName = patient.name && patient.name[0];
6 const patientBirthDate = patient.birthDate;
7 return (
8 <div>
9 <FhirHumanName value={patientName} />
10 <FhirDateTime value={patientBirthDate} />
11 </div>
12 );
13};
14
15MyPatientCard.propTypes = {
16 patient: Patient.isRequired
17};

Related Reading

Getting Started
PatientCard Component
FhirDateTime
FhirHumanName