Turns FHIR R4 Patient, AllergyIntolerance, Condition and Observation resources, or a Bundle of them, into the props of the patient banner, allergy list, problem list and lab results table.
BRENNAN, Tom (Mr)
- Born
- 03-Jun-1979 (47 years)
- Sex
- Male
- NHS number
- 999 100 2014
| Substance | Reaction | Severity |
|---|---|---|
| CodeineIntoleranceRecorded Feb 20, 2019 | Vomiting | Mild |
| Problem | Dates |
|---|---|
| Active · 1 | |
| AsthmaSNOMED CT 195967001 | Since Childhood |
| Past · 1 | |
| Fracture of left wrist | Dec 4, 2021 – Feb 10, 2022 |
Installation
bunx shadcn@4.22.1 add https://organui.com/r/fhir.jsonThis adds lib/fhir.ts, with no dependencies.
Usage
import {
allergiesFromFhir,
labResultsFromFhir,
patientFromFhir,
problemsFromFhir,
fhirResources,
type FhirBundle,
type FhirPatient,
} from "@/lib/fhir"
import { AllergyList, allergySummary } from "@/components/ui/allergy-list"
import { PatientBanner } from "@/components/ui/patient-banner"
// A Bundle from your FHIR server, such as $everything on a Patient.
export function Record({ bundle }: { bundle: FhirBundle }) {
const [patient] = fhirResources<FhirPatient>(bundle, "Patient")
const allergies = allergiesFromFhir(bundle)
return (
<>
<PatientBanner
patient={patientFromFhir(patient!)}
allergies={allergySummary(allergies)}
/>
<AllergyList allergies={allergies} />
</>
)
}API Reference
| Export | Description |
|---|---|
patientFromFhir(patient) | The patient banner's patient: the official name, else the first still in use; date of birth; administrative gender; identifiers with the NHS number first and spaced 3-3-4; and any date of death. |
allergiesFromFhir(resources | bundle) | The allergy list's allergies: substance, type, every reaction, the worst severity, verification, status and date. "No known allergy" (SNOMED CT 716186003) alone becomes "none-known"; no records stay undefined, as not recorded. |
problemsFromFhir(resources | bundle) | The problem list's problems: the name, its SNOMED CT code (else another), active or past status, and onset and resolution as dates or text. |
labResultsFromFhir(resources | bundle) | The lab results table's results: one row per test code, the latest result with its unit, range and the laboratory's interpretation as the flag, and the earlier numeric results as its history. |
fhirResources(resources | bundle, resourceType) | The resources of one type, from a list or a Bundle's entries. |
conceptText(concept) | A CodeableConcept's text, or its first coding's display. |
Notes
Records entered in error or refuted, and cancelled observations, are left out, as they are not part of the record.
Only the elements read are typed, so it works with resources from any FHIR R4 server or library. The results match the components' props by shape, so the file depends on none of them.
It reads FHIR R4 and the UK Core NHS number system. It does not fetch, validate or reconcile resources; check the mapping against your server's profiles.