@synanetics/fhir-obj
v3.0.0
Published
Object wrappers with utility functions for FHIR objects.
Downloads
403
Maintainers
Keywords
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()