npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@synanetics/fhir-obj

v3.0.0

Published

Object wrappers with utility functions for FHIR objects.

Downloads

622

Readme

@synanetics/fhir-obj

A collection of object wrappers around FHIR resources providing utility functions.

Example Usage

const {
  FhirObj, FhirVersion
} = require('@synanetics/fhir-obj');
// or
import {
  FhirObj, FhirVersion
} from '@synanetics/fhir-obj';

const patient = FhirObj.fromObj({
  resourceType: 'Patient',
  ...
}, FhirVersion.R3);
const nhsNumber = patient.getNHSNumber();
const {
  Patient, FhirVersion
} = require('@synanetics/fhir-obj');
// or
import {
  Patient, FhirVersion
} from '@synanetics/fhir-obj';

const patient = new Patient({
  resourceType: 'Patient',
  ...
} as fhir3.Patient, FhirVersion.R3);
const nhsNumber = patient.getNHSNumber();

API

FhirObj

FhirObj contains a couple of static methods to create an object wrapper instance from the supplied FHIR resource data.

fromObj(resource: object, fhirVersion: FhirVersion)

Takes an input FHIR object and returns an object wrapping instance. The type of the instance is based on the resourceType of the supplied resource. If a resource type has a specific object implementation, otherwise a base Resource object will be returned.

The supported resources are currently:

  • Bundle
  • DomainResource
  • Organization
  • Patient

fromJson(resource: string, fhirVersion: FhirVersion)

Takes an input FHIR object as a JSON string. Calls fromObj() internally to then return the object wrapper.

Resource

The base resource. All other resource inherit from this resource.

constructor(resource: object, fhirVersion: FhirVersion)

Create a Resource instance from a FHIR JavaScript object.

.resource (getter/setter)

Access the underlying FHIR resource directly.

toJSON()

Implemented to support JSON.stringify() being called on the object. Returns the base FHIR object to be stringified.

asJson()

Returns the base FHIR resource as JSON.

isType(type: string)

Return true if the resourceType matches the provided type, otherwise false.

isNotType(type: string)

Return true if the resourceType does not match the provided type, otherwise false.

getLastUpdated()

Returns meta.lastUpdated as a Date object if set, otherwise returns undefined.

setLastUpdated(lastUpdated: Date)

Sets meta.lastUpdated as an ISO8601 date/time string. Returns the Resource object to enable function chaining.

setLastUpdatedFromString(lastUpdated: string)

Sets meta.lastUpdated as an ISO8601 date/time string from a string that Date can parse. Returns the Resource object to enable function chaining.

getVersionId()

Returns meta.versionId if set, otherwise returns undefined.

incrementVersionId()

Increments the value of meta.versionId or sets it to '1' if not previously set. Returns the Resource object to enable function chaining.

getIdentifierBySystem(system: string)

Note Strictly, by the FHIR specification, identifer is not an attribute on Resource, but this method is on the Resource object as identifier is widely used across other FHIR resource types. Depending on the resource type, identifier can have a cardinality of 0..1 or 0..* which this method supports.

Returns an identifier with a matching system, otherwise returns undefined.

getIdentifierValueBySystem(system: string)

Returns the value for an identifier with a matching system, otherwise returns undefined.

getTagBySystem(system: string)

Returns a tag with a matching system, otherwise returns undefined.

getTagCodeBySystem(system: string)

Returns the code for a tag with a matching system, otherwise returns undefined.

DomainResource

Inherits from Resource. All other resources (not Resource) inherit from this resource.

addExtension(extension: Extension)

Will add an extension to a resource as provider. It will replace any extension with a matching Extension.system attribute.

Bundle

getEntryResourcesByType(type: string)

Returns an array of resources of the type provided from entry. Returns an empty array if there are no resources of the type provided.

getEntryResourceById(id: string)

Returns a resource from entry with a matching id, otherwise returns undefined.

OperationOutcome

issueCount(filter?: IssueFilter)

Returns the count of issues matching the filter. If no filter is applied, returns the count of all issues. IssueFilter is an object containing one or both of severity and code properties.

hasIssues(filter?: IssueFilter)

Returns true if issues match the filter. If no filter is applied, returns true if there is at least 1 issue. IssueFilter is an object containing one or both of severity and code properties.

Organization

getODSCode()

Returns the ODS code for an Organization. This is the value of an identifier with a system of https://fhir.nhs.uk/Id/ods-organization-code.

isActive()

Returns true if the Organization is active, otherwise false.

Patient

getNHSNumber()

Returns the NHS number for a Patient. This is the value of an identifier with a system of https://fhir.nhs.uk/Id/nhs-number.

hasNHSNumber(nhsNumber: string)

Returns true if the patient NHS number matches the one provided, otherwise false.

isActive()

Returns true if the Patient is active, otherwise false.

Guards

Objects returned from FhirObj.fromObj() and FhirObj.fromJson() could be any supported object or the base Resource object. To aid TypeScript in knowing what functions exist on the object, isX(obj): bool guards are exported to check the object type:

  • isBundle()
  • isDomainResource()
  • isOperationOutcome()
  • isOrganization()
  • isPatient()
  • isResource()

Interweave

Interweave specific resources and functions are under the Interweave namespace.

DataProvider

getParticipantId()

Returns the participant id. This is the value of an identifier with a system of https://yhcr.nhs.uk/Id/participant-id.

isActive()

Returns true if the status is active, otherwise false.

supportsResource(resource: string, status?: string)

Returns true if the resource is a supported resource type with the provided status, otherwise false. If no status is provided it defaults to public.

allowsRole(role: InterweaveUserRole)

Returns true if the supplied role has permission to access data from this DataProvider, otherwise false.

allowsAccessReason(reason: InterweaveAccessReason)

Returns true if the supplied reason has permission to access data from this DataProvider, otherwise false.

getSyncEndpoint()

Returns the endpoint with type of sync if present, otherwise undefined.

getSyncEndpointUrl()

Returns the endpoint URL for an endpoint with type of sync if present, otherwise undefined.

getAsyncEndpoint()

Returns the endpoint with type of async if present, otherwise undefined.

getAsyncEndpointUrl()

Returns the endpoint URL for an endpoint with type of async if present, otherwise undefined.

ScheduleDefinition

getScheduleIdentifier(system: string)

Returns scheduleIdentifier from the resource matching the provided system.

setScheduleIdentifier(identifier: Idenitifer, replaceMatchingSystem = true)

Returns the ScheduleIdentifier instance. Takes an input identifier and adds it to the scheduleIdentifier property. If an identifier with a matching system is already present it will replace it by default. A second boolean parameter can be provided to prevent it replacing an existing identifier.

setTotalSlots(total: number)

Returns the ScheduleIdentifier instance. Sets an extension https://yhcr.nhs.uk/StructureDefinition/Extension-Schedule-TotalSlots with a valueInteger presented by the provided argument.

Guards

  • isDataProvider()
  • isScheduleDefinition()