FHIR Types
All FHIR resources and data types typescript typings are included in the core package. We currently support R4B and R5 - just use the right import path.
Official FHIR documentation is included as JSDoc, with links back to the FHIR documentation.
import { Patient, Practionner, Claim, HumanName } from "@bonfhir/core/r4b";
declare const patient: Patient;
patient.name; // HumanName
Builder and Narrative generator
The build
function can build any FHIR Resource, and generate the appropriate narrative.
Narratives are generated using resources elements that are marked with the
Σ (isSummary
) element definition.
import { build, narrative } from "@bonfhir/core/r4b";
const patient = build("Patient", {
name: [
{
given: ["John"],
family: "Doe",
},
],
});
console.log(patient.text);
// {status: 'generated', div: '<div xmlns="http://www.w3.org/1999/xhtml"><ul><li>…</span><ul><li>John Doe</li></ul></li></ul></div>'}
// The narrative function can also be invoked on its own
const generatedNarrative = narrative(patient);
References and ids
The reference
function builds FHIR literal references to other resources.
When possible, it also infers a proper display
attribute automatically, based on the targeted resource.
import { Patient, Organization, reference, Retrieved } from "@bonfhir/core/r4b";
declare const organization: Retrieved<Organization>;
declare const patient: Patient;
organization.name = "Acme, Inc";
patient.managingOrganization = reference(organization);
console.log(patient.managingOrganization);
// {reference: 'Organization/cce73d99-068c-4d12-9d69-60e2d2ef9ae7', type: 'Organization', display: 'Acme, Inc'}
Conversely, the id
function can return a resource id
for a resource or a reference to a resource.
import { id } from "@bonfhir/core/r4b";
console.log(id(organization));
// cce73d99-068c-4d12-9d69-60e2d2ef9ae7
console.log(id(patient.managingOrganization));
// cce73d99-068c-4d12-9d69-60e2d2ef9ae7
The canonical
function can build Canonical URLs for resources that
support this pattern.
import { build, canonical } from "@bonfhir/core/r4b";
const questionnaire = build("Questionnaire", {
url: "https://example.com/questionnaire",
version: "2.1",
});
console.log(canonical(questionnaire));
// https://example.com/questionnaire|2.1
Finally, there is a nifty codeableConcept
helper that builds a CodeableConcept
from a Coding
.
import { codeableConcept } from "@bonfhir/core/r4b";
codeableConcept({ code: "M", display: "Married" });
{
coding: [{ code: "M", display: "Married" }],
text: "Married",
};