Skip to main content

FHIR Resources

The Resources module is a set of TypeScript objects representing FHIR Resources. They are 100% compatible with these FHIR types. If a resource object does not exist in Resources, you can use the FHIR types in the linked library instead.

The Resources in this package provide:

  • Constructor methods to help when constructing new instances of a resource
  • Static methods that are useful when working with a resource (string formatting, filtering, etc.)
import { Resources } from "@plasmahealth/plasma-fhir-client";

The Resources module is scoped by FHIR version. For example, Resources.r4.HumanName.

Constructing Resource Objects​

When building the objects to use for creating new resources, you can construct any JSON object as long as it adheres to the specifications of that resource.

As a shortcut, the Resources package has constructor methods for some resources to make it easier to create a resource. For instance, the resourceType property (which is required) will be set automatically for you.

const familyMember = new Resources.r4.FamilyMemberHistory(patientId, "Father");

Resource-Specific APIs​

Address​

// Get the address(es) that corresponds to the given "use"...
const addr = Resources.r4.Address.getAddressesByUse(patient.address, "home");
// Get a displayable string...
const s = Resources.r4.Address.toString(address);
// Extracts the city from the address...
const city = Resources.r4.Address.getCity(address);
// Extracts the state from the address...
const state = Resources.r4.Address.getState(address);

Age​

// Construct an Age from a given quantity...
const age = Resources.r4.Age.fromQuantity(quantity);
// Construct an Age from a given number of years...
const age = Resources.r4.Age.fromYears(25);

Annotation​

// Constructor
const annotation = new Resources.r4.Annotation("My Annotation");

Attachment​

// Convert to displayable string...
const s = Resources.r4.toString(attachment);
// Determine the content type of the attachment...
Resources.r4.isPdf(attachment);
Resources.r4.isImage(attachment);
Resources.r4.isText(attachment);
Resources.r4.isHtml(attachment);
Resources.r4.isVideo(attachment);

Bundle​

// Start a bundle...
let bundle = Resources.r4.Bundle.startBundle("batch");
// Add a write to a bundle...
bundle = Resources.r4.Bundle.addWriteToBundle(bundle, "create", myResource);
// Add a read to a bundle...
bundle = Resources.r4.Bundle.addReadToBundle(bundle, "Observation", { category: "laboratory" });
// Filter a bundle by resource type
const observations = Resources.r4.Bundle.filterBundleByResourceType<r4.Observation>(bundle, "Observation");
// Get all bundle resources in a dictionary with keys like "{resourceType}/{id}"
const dict = Resources.r4.Bundle.bundleEntriesToDictionary(bundle);

CapabilityStatement​

// Get token/auth URLs...
const tokenUrl = Resources.r4.CapabilityStatement.getTokenUrl(capabilityStatement);
const authUrl = Resources.r4.CapabilityStatement.getAuthorizeUrl(capabilityStatement);
// Get data about a given resource...
const resourceData = Resources.r4.CapabilityStatement.getResourceData(capabilityStatement, "AllergyIntolerance");
// Check if a FHIR Server supports a given resource...
const supportsResource = Resources.r4.CapabilityStatement.supportsResource(capabilityStatement, "AllergyIntolerance");
// Check if a FHIR Server supports a given search parameter for a resource...
const supportsSearchParam = Resources.r4.CapabilityStatement.supportsResource(capabilityStatement, "Patient", "general-practitioner");

CodeableConcept​

// Create a CodeableConcept from a single Coding resource...
const cc = Resources.r4.CodeableConcept.fromSingleCoding(coding);
// Get a displayable string for this CodeableConcept...
const onlyFirstCode = true;
const sCC = Resources.r4.CodeableConcept.getDisplayText(cc, onlyFirstCode);
let cc = [....];

// Sort a CodeableConcept by the display text
cc = cc.sort(Resources.r4.CodeableConcept.sortByDisplayText);

Coding​

// Constructor
const coding = new Resources.r4.Coding("system", "code", "display");
// Display as string
const s = Resources.r4.Coding.toString(coding);
// Filter codings by system or code...
const codes1 = Resources.r4.Coding.getCodingsBySystem(codings, "http://my-system");
const codes2 = Resources.r4.Coding.getCodingsByCode(codings, "12345-1");

ContactPoint​

// Display as string...
const s = Resources.r4.ContactPoint.toString(contactPoint);
// Get contact by system/use...
const contact = Resources.r4.ContactPoint.getContactPointBySystem(patient.telecom, "phone");
const contact = Resources.r4.ContactPoint.getContactPointByUse(patient.telecom, "home");

DeviceDeviceName​

// Constructor...
const = new Resources.r4.DeviceDeviceName("name", "model-name");
// Get a displayable string...
const s = Resources.r4.DeviceDeviceName.toString(deviceName);

DocumentReference​

// Create a document reference from the given text
const doc = Resources.r4.DocumentReference.createDocumentReferenceFromText(
"hello", patientId, "patient, name",
"final", "current", type, context
);
// Get all documents by the given status...
const d = Resources.r4.DocumentReference.getDocumentReferencesByStatus(docs, "current");

Dosage​

// Get instructions...
const instructions = Resources.r4.Dosage.getDosageInstructions(dosage);
// Get dose and rate in as a string...
const doseAndRate = Resources.r4.Dosage.getDoseAndRateDisplay(dosage);

DosageDoseAndRate​

// Convert to string...
const s = Resources.r4.DosageDoseAndRate.toString(dosageDoseAndRate);
// Get all where the type code matches..
const ddrs = Resources.r4.DosageDoseAndRate.getDosageDoseAndRateByTypeCode(dosageDoseAndRates, "ordered");

Encounter​

let encounters = [...];

// Sort encounters by start date...
encounters = encounters.sort(Resources.r4.Encounter.sort);

Extension​

// Given a resource, searches for all extensions with the matching url...
const ext = Resources.r4.Extension.getExtensionByUrl(extensions, "http://...");
// Create an extension from a CodeableConcept...
const myCodeableConcept: r4.CodeableConcept = { ... }
const ext = Resources.r4.Extension.fromCodeableConcept("http://myurl", myCodeableConcept);
// Create a CodeableConcept extension from Coding Information...
const ext = Resources.r4.Extension.fromSingleCoding("http://myurl", "system", "code", "display");

FamilyMemberHistory​

AdministrativeGender​

Set of values for use as "Administrative Gender"

FamilyMemberHistory_Relationship​

Set of values to be used for the relationship property in a FamilyMemberHistory

FamilyMemberHistoryCondition​

// Get a FamilyMemberHistoryCondition from a SNOMED code...
const c = Resources.r4.FamilyMemberHistoryCondition(code, display, text, ageOfOnset);

Flag​

// Constructor
const flag = new Resources.r4.Flag(code, subject, "active");
// Get all flags with a given status...
const f = Resources.r4.Flag.getFlagsByStatus(flags, "active");

HumanName​

// Gets all names based on the given "use"...
const names = Resources.r4.HumanName.getNamesByUse(patient.name, "maiden");
const officialName = Resources.r4.Patient.getOfficialName(patient);

// Convert a name to a displayable string...
const options: HumanNameToStringOptions = {
includePrefix: true,
includeSuffix: false,
includeUse: false
};
const sName = Resources.r4.HumanName.toString(officialName, options);

Identifier​

// Get identifier by system...
const id = Resources.r4.Identifier.getIdentifierBySystem(patient.identifier, "urn:...");
// Get a displayable string...
const display = Resources.r4.Identifier.toString(patient.identifier[0]);

MedicationRequest​

// Get displayable string...
const s = Resources.r4.MedicationRequest.getDisplayableText(medicationRequest);
// Get number of refills
const numRefills: number | null = Resources.r4.MedicationRequest.getNumRefills(medicationRequest);

Money​

// Convert to string...
const s = Resources.r4.Money.toString(money);

Observation​

// Convert to string...
const s = Resources.r4.Observation.toString(observation);
// Convert component to string...
const s = Resources.r4.Observation.getComponentValueDisplay(component);

OperationOutcome​

// Convert to string...
const s = Resources.r4.OperationOutcome.toString(operationOutcome);

Patient​

// Get the patient's "official" name...
const officialName = Resources.r4.Patient.getOfficialName(patient);
// Get the patient's "home" address...
const addrHome = Resources.r4.Patient.getHomeAddress(patient);
// Get patient's birthdate as a Date object
const birthDate = Resources.r4.Patient.getBirthDate(patient);
// Get patient's gender identity...
const genderIdentity = Resources.r4.Patient.getGenderIdentity(patient);
const genderIdentity = Resources.r4.Patient.patientGenderToGenderIdentity(patient.gender);

GenderIdentity​

Set of values for use as "Gender Identity"

Period​

// Construct a Period from two strings...
const period = new Resources.r4.Period("2000-01-01", "2010-12-31");
// Get the start/end dates of the given Period...
const startDate = Resources.r4.Period.getStartDate(period);
const endDate = Resources.r4.Period.getEndDate(period);
// Construct a Period from a Range that represents an age...
const dobPeriod = Resources.r4.Period.fromAgeRange(age);
// Construct a Period from an age string...
const dobPeriod = Resources.r4.Period.fromAgeString("20's");
// Get a displayable string...
const s = Resources.r4.Period.toString(period);

Quantity​

// Constructor...
const q = new Resources.r4.Quantity(3, "mg", "system", "code", ">");
// Get displayable string...
const sQuantity = Resources.r4.Quantity.toString(quantity);
// Get a quantity from a string...
const q = Resources.r4.Quantity.fromString("> 50 mg");
// Sort quantities...
let quantities = [...]
quantities = quantities.sort(Resources.r4.Quantity.sortByValueAscending);

Range​

// Construct a Range from a set of numbers...
const range = Resources.r4.Range.fromNumbers(25, 30);
// Construct a Range from a string...
const range = Resources.r4.Range.fromString("25 - 30");
// Construct a Range from an age string...
const r1 = Resources.r4.Range.fromAgeString("20's");
const r2 = Resources.r4.Range.fromAgeString("25-30");
// Get a displayable string...
const s = Resources.r4.Range.toString(range); // 25-30
// Get a displayabe string for a Range that represents an Age...
const s = Resources.r4.Range.toAgeString(range); // 25-30y
// Sort ranges
let ranges = [...]

ranges = ranges.sort(Resources.r4.Range.sortByLowValue);
ranges = ranges.sort(Resources.r4.Range.sortByHighValue);

Ratio​

// Constructor...
const r = new Resources.r4.Ratio(1, 2);
// Get a displayable string...
const s = Resources.r4.Ratio.toString(ratio);

Reference​

// Constructor
const ref = new Resources.r4.Reference("Patient/123", "John Smith");
// Create a reference to a resource
const patientRef = Resources.r4.Reference.createReference("Patient", "123", "John Smith");
// Convert to string...
const s = Resources.r4.Reference.toString(ref);
// Extract the resource type from the reference...
const resourceType = Resources.r4.Reference.getResourceFromReferenceString("Patient/123");
// Extract the ID from the reference...
const id = Resources.r4.Reference.getIdFromReferenceString("Patient/123");
// Determine if a given reference matches a given resource (if that Reference is a reference to the resource)
let r1: r4.Reference = new Resources.Reference("Patient/1");
let p1: r4.Patient = { resourceType: "Patient", id: "1" };
const isReference = Resources.r4.Reference.isReferenceToResource(r1, p1);
// Parse a reference string into parts (resource type, resource ID, version)
// Example formats:
// - Patient/123
// - https://smart-on-fhir.com/fhir/R4/Patient/123
// - https://smart-on-fhir.com/fhir/R4/Patient/123/_history/1
const parts = Resources.r4.Reference.parse(s);