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.

import React from "react";
import { Patient, HumanName, date } from "@commure/fhir-types/r4/types";
import { FhirHumanName, FhirDateTime } from "@commure/components-core";
interface Props {
patient: Patient;
}
const MyPatientInfo = ({ patient }: Props) => {
const patientName: HumanName | undefined = patient.name && patient.name[0];
const patientBirthDate: date | undefined = patient.birthDate;
return (
<div>
<FhirHumanName value={patientName} />
<FhirDateTime value={patientBirthDate} />
</div>
);
};

PropTypes Usage

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

import React from "react";
import { Patient } from "@commure/fhir-types/r4/proptypes";
const MyPatientCard = ({ patient }) => {
const patientName = patient.name && patient.name[0];
const patientBirthDate = patient.birthDate;
return (
<div>
<FhirHumanName value={patientName} />
<FhirDateTime value={patientBirthDate} />
</div>
);
};
MyPatientCard.propTypes = {
patient: Patient.isRequired,
};

Related Reading

Getting Started
PatientCard Component
FhirDateTime
FhirHumanName