Skip to main content

@medplum/core

Classes

Interfaces

Enumerations

Functions

formatAddress

formatAddress(address, options?): string

Parameters

NameType
addressAddress
options?AddressFormatOptions

Returns

string

Defined in

packages/core/src/format.ts:16


formatHumanName

formatHumanName(name, options?): string

Parameters

NameType
nameHumanName
options?HumanNameFormatOptions

Returns

string

Defined in

packages/core/src/format.ts:42


formatGivenName

formatGivenName(name): string

Parameters

NameType
nameHumanName

Returns

string

Defined in

packages/core/src/format.ts:68


formatFamilyName

formatFamilyName(name): string

Parameters

NameType
nameHumanName

Returns

string

Defined in

packages/core/src/format.ts:76


isValidDate

isValidDate(date): boolean

Parameters

NameType
dateDate

Returns

boolean

Defined in

packages/core/src/format.ts:80


formatDate

formatDate(date, options?): string

Parameters

NameType
dateundefined | string
options?DateTimeFormatOptions

Returns

string

Defined in

packages/core/src/format.ts:84


formatTime

formatTime(time, options?): string

Parameters

NameType
timeundefined | string
options?DateTimeFormatOptions

Returns

string

Defined in

packages/core/src/format.ts:95


formatDateTime

formatDateTime(dateTime, options?): string

Parameters

NameType
dateTimeundefined | string
options?DateTimeFormatOptions

Returns

string

Defined in

packages/core/src/format.ts:106


formatPeriod

formatPeriod(period): string

Parameters

NameType
periodundefined | Period

Returns

string

Defined in

packages/core/src/format.ts:117


formatTiming

formatTiming(timing): string

Parameters

NameType
timingundefined | Timing

Returns

string

Defined in

packages/core/src/format.ts:154


parseJWTPayload

parseJWTPayload(token): Record<string, number | string>

Parses the JWT payload.

Parameters

NameTypeDescription
tokenstringJWT token

Returns

Record<string, number | string>

Defined in

packages/core/src/jwt.ts:31


badRequest

badRequest(details, expression?): OperationOutcome

Parameters

NameType
detailsstring
expression?string

Returns

OperationOutcome

Defined in

packages/core/src/outcomes.ts:124


isOk

isOk(outcome): boolean

Parameters

NameType
outcomeOperationOutcome

Returns

boolean

Defined in

packages/core/src/outcomes.ts:140


isNotFound

isNotFound(outcome): boolean

Parameters

NameType
outcomeOperationOutcome

Returns

boolean

Defined in

packages/core/src/outcomes.ts:144


isGone

isGone(outcome): boolean

Parameters

NameType
outcomeOperationOutcome

Returns

boolean

Defined in

packages/core/src/outcomes.ts:148


getStatus

getStatus(outcome): number

Parameters

NameType
outcomeOperationOutcome

Returns

number

Defined in

packages/core/src/outcomes.ts:152


assertOk

assertOk<T>(outcome, resource): asserts resource is T

Asserts that the operation completed successfully and that the resource is defined.

Type parameters

Name
T

Parameters

NameTypeDescription
outcomeOperationOutcomeThe operation outcome.
resourceundefined | TThe resource that may or may not have been returned.

Returns

asserts resource is T

Defined in

packages/core/src/outcomes.ts:179


normalizeErrorString

normalizeErrorString(error): string

Normalizes an error object into a displayable error string.

Parameters

NameTypeDescription
errorunknownThe error value which could be a string, Error, OperationOutcome, or other unknown type.

Returns

string

A display string for the error.

Defined in

packages/core/src/outcomes.ts:199


parseSearchDefinition

parseSearchDefinition(url): SearchRequest

Parses a URL into a SearchRequest.

See the FHIR search spec: http://hl7.org/fhir/r4/search.html

Parameters

NameTypeDescription
urlstringThe URL to parse.

Returns

SearchRequest

Parsed search definition.

Defined in

packages/core/src/search.ts:98


formatSearchQuery

formatSearchQuery(definition): string

Formats a search definition object into a query string. Note: The return value does not include the resource type.

Parameters

NameTypeDescription
definitionSearchRequestThe search definition.

Returns

string

Formatted URL.

Defined in

packages/core/src/search.ts:204


getSearchParameterDetails

getSearchParameterDetails(resourceType, searchParam): SearchParameterDetails

Returns the type details of a SearchParameter.

The SearchParameter resource has a "type" parameter, but that is missing some critical information.

For example: 1) The "date" type includes "date", "datetime", and "period". 2) The "token" type includes enums and booleans. 3) Arrays/multiple values are not reflected at all.

Parameters

NameTypeDescription
resourceTypestringThe root resource type.
searchParamSearchParameterThe search parameter.

Returns

SearchParameterDetails

The search parameter type details.

Defined in

packages/core/src/searchparams.ts:37


getExpressionForResourceType

getExpressionForResourceType(resourceType, expression): string | undefined

Parameters

NameType
resourceTypestring
expressionstring

Returns

string | undefined

Defined in

packages/core/src/searchparams.ts:146


createSchema

createSchema(): IndexedStructureDefinition

Creates a new empty IndexedStructureDefinition.

Deprecated

Use globalSchema

Returns

IndexedStructureDefinition

The empty IndexedStructureDefinition.

Defined in

packages/core/src/types.ts:138


indexStructureDefinitionBundle

indexStructureDefinitionBundle(bundle): void

Indexes a bundle of StructureDefinitions for faster lookup.

Parameters

NameTypeDescription
bundleBundle<Resource>A FHIR bundle StructureDefinition resources.

Returns

void

Defined in

packages/core/src/types.ts:160


indexStructureDefinition

indexStructureDefinition(structureDefinition): void

Indexes a StructureDefinition for fast lookup. See comments on IndexedStructureDefinition for more details.

Parameters

NameTypeDescription
structureDefinitionStructureDefinitionThe original StructureDefinition.

Returns

void

Defined in

packages/core/src/types.ts:174


indexSearchParameter

indexSearchParameter(searchParam): void

Indexes a SearchParameter resource for fast lookup. Indexes by SearchParameter.code, which is the query string parameter name.

Parameters

NameTypeDescription
searchParamSearchParameterThe SearchParameter resource.

Returns

void

Defined in

packages/core/src/types.ts:235


buildTypeName

buildTypeName(components): string

Parameters

NameType
componentsstring[]

Returns

string

Defined in

packages/core/src/types.ts:267


getPropertyDisplayName

getPropertyDisplayName(path): string

Parameters

NameType
pathstring

Returns

string

Defined in

packages/core/src/types.ts:274


getElementDefinition

getElementDefinition(typeName, propertyName): ElementDefinition | undefined

Returns an element definition by type and property name. Handles content references.

Parameters

NameTypeDescription
typeNamestringThe type name.
propertyNamestringThe property name.

Returns

ElementDefinition | undefined

The element definition if found.

Defined in

packages/core/src/types.ts:306


createReference

createReference<T>(resource): Reference<T>

Creates a reference resource.

Type parameters

NameType
Textends Resource

Parameters

NameTypeDescription
resourceTThe FHIR reesource.

Returns

Reference<T>

A reference resource.

Defined in

packages/core/src/utils.ts:31


getReferenceString

getReferenceString(resource): string

Returns a reference string for a resource.

Parameters

NameTypeDescription
resourceResourceThe FHIR resource.

Returns

string

A reference string of the form resourceType/id.

Defined in

packages/core/src/utils.ts:42


resolveId

resolveId(reference): string | undefined

Returns the ID portion of a reference.

Parameters

NameTypeDescription
referenceundefined | Reference<Resource>A FHIR reference.

Returns

string | undefined

The ID portion of a reference.

Defined in

packages/core/src/utils.ts:51


isProfileResource

isProfileResource(resource): boolean

Returns true if the resource is a "ProfileResource".

Parameters

NameTypeDescription
resourceResourceThe FHIR resource.

Returns

boolean

True if the resource is a "ProfileResource".

Defined in

packages/core/src/utils.ts:60


getDisplayString

getDisplayString(resource): string

Returns a display string for the resource.

Parameters

NameTypeDescription
resourceResourceThe input resource.

Returns

string

Human friendly display string.

Defined in

packages/core/src/utils.ts:73


getImageSrc

getImageSrc(resource): string | undefined

Returns an image URL for the resource, if one is available.

Parameters

NameTypeDescription
resourceResourceThe input resource.

Returns

string | undefined

The image URL for the resource or undefined.

Defined in

packages/core/src/utils.ts:133


getDateProperty

getDateProperty(date): Date | undefined

Returns a Date property as a Date. When working with JSON objects, Dates are often serialized as ISO-8601 strings. When that happens, we need to safely convert to a proper Date object.

Parameters

NameTypeDescription
dateundefined | stringThe date property value, which could be a string or a Date object.

Returns

Date | undefined

A Date object.

Defined in

packages/core/src/utils.ts:168


calculateAge

calculateAge(birthDateStr, endDateStr?): Object

Calculates the age in years from the birth date.

Parameters

NameTypeDescription
birthDateStrstringThe birth date or start date in ISO-8601 format YYYY-MM-DD.
endDateStr?stringOptional end date in ISO-8601 format YYYY-MM-DD. Default value is today.

Returns

Object

The age in years, months, and days.

NameType
yearsnumber
monthsnumber
daysnumber

Defined in

packages/core/src/utils.ts:178


calculateAgeString

calculateAgeString(birthDateStr, endDateStr?): string | undefined

Calculates the age string for display using the age appropriate units. If the age is greater than or equal to 2 years, then the age is displayed in years. If the age is greater than or equal to 1 month, then the age is displayed in months. Otherwise, the age is displayed in days.

Parameters

NameTypeDescription
birthDateStrstringThe birth date or start date in ISO-8601 format YYYY-MM-DD.
endDateStr?stringOptional end date in ISO-8601 format YYYY-MM-DD. Default value is today.

Returns

string | undefined

The age string.

Defined in

packages/core/src/utils.ts:220


getQuestionnaireAnswers

getQuestionnaireAnswers(response): Record<string, QuestionnaireResponseItemAnswer>

Returns all questionnaire answers as a map by link ID.

Parameters

NameTypeDescription
responseQuestionnaireResponseThe questionnaire response resource.

Returns

Record<string, QuestionnaireResponseItemAnswer>

Questionnaire answers mapped by link ID.

Defined in

packages/core/src/utils.ts:236


getIdentifier

getIdentifier(resource, system): string | undefined

Returns the resource identifier for the given system.

If multiple identifiers exist with the same system, the first one is returned.

If the system is not found, then returns undefined.

Parameters

NameTypeDescription
resourceResourceThe resource to check.
systemstringThe identifier system.

Returns

string | undefined

The identifier value if found; otherwise undefined.

Defined in

packages/core/src/utils.ts:274


getExtensionValue

getExtensionValue(resource, ...urls): string | undefined

Returns an extension value by extension URLs.

Parameters

NameTypeDescription
resourceanyThe base resource.
...urlsstring[]Array of extension URLs. Each entry represents a nested extension.

Returns

string | undefined

The extension value if found; undefined otherwise.

Defined in

packages/core/src/utils.ts:294


stringify

stringify(value, pretty?): string

FHIR JSON stringify. Removes properties with empty string values. Removes objects with zero properties. See: https://www.hl7.org/fhir/json.html

Parameters

NameTypeDescription
valueanyThe input value.
pretty?booleanOptional flag to pretty-print the JSON.

Returns

string

The resulting JSON string.

Defined in

packages/core/src/utils.ts:315


isEmpty

isEmpty(v): boolean

Returns true if the value is empty (null, undefined, empty string, or empty object).

Parameters

NameTypeDescription
vanyAny value.

Returns

boolean

True if the value is an empty string or an empty object.

Defined in

packages/core/src/utils.ts:344


deepEquals

deepEquals(object1, object2, path?): boolean

Resource equality. Ignores meta.versionId and meta.lastUpdated.

Parameters

NameTypeDescription
object1unknownThe first object.
object2unknownThe second object.
path?string-

Returns

boolean

True if the objects are equal.

Defined in

packages/core/src/utils.ts:359


deepClone

deepClone<T>(input): T

Creates a deep clone of the input value.

Limitations:

  • Only supports JSON primitives and arrays.
  • Does not support Functions, lambdas, etc.
  • Does not support circular references.

See: https://web.dev/structured-clone/ See: https://stackoverflow.com/questions/40488190/how-is-structured-clone-algorithm-different-from-deep-copy

Type parameters

Name
T

Parameters

NameTypeDescription
inputTThe input to clone.

Returns

T

A deep clone of the input.

Defined in

packages/core/src/utils.ts:433


isUUID

isUUID(input): boolean

Returns true if the input string is a UUID.

Parameters

NameTypeDescription
inputstringThe input string.

Returns

boolean

True if the input string matches the UUID format.

Defined in

packages/core/src/utils.ts:442


isObject

isObject(obj): obj is Record<string, unknown>

Returns true if the input is an object.

Parameters

NameType
objunknown

Returns

obj is Record<string, unknown>

True if the input is a non-null non-undefined object.

Defined in

packages/core/src/utils.ts:451


isStringArray

isStringArray(arr): arr is string[]

Returns true if the input array is an array of strings.

Parameters

NameTypeDescription
arrany[]Input array.

Returns

arr is string[]

True if the input array is an array of strings.

Defined in

packages/core/src/utils.ts:460


arrayBufferToHex

arrayBufferToHex(arrayBuffer): string

Converts an ArrayBuffer to hex string. See: https://stackoverflow.com/a/55200387

Parameters

NameTypeDescription
arrayBufferArrayBufferThe input array buffer.

Returns

string

The resulting hex string.

Defined in

packages/core/src/utils.ts:477


arrayBufferToBase64

arrayBufferToBase64(arrayBuffer): string

Converts an ArrayBuffer to a base-64 encoded string.

Parameters

NameTypeDescription
arrayBufferArrayBufferThe input array buffer.

Returns

string

The base-64 encoded string.

Defined in

packages/core/src/utils.ts:491


capitalize

capitalize(word): string

Parameters

NameType
wordstring

Returns

string

Defined in

packages/core/src/utils.ts:500


isLowerCase

isLowerCase(c): boolean

Parameters

NameType
cstring

Returns

boolean

Defined in

packages/core/src/utils.ts:504


getCodeBySystem

getCodeBySystem(concept, system): string | undefined

Tries to find a code string for a given system within a given codeable concept.

Parameters

NameTypeDescription
conceptCodeableConceptThe codeable concept.
systemstringThe system string.

Returns

string | undefined

The code if found; otherwise undefined.

Defined in

packages/core/src/utils.ts:514


setCodeBySystem

setCodeBySystem(concept, system, code): void

Sets a code for a given system within a given codeable concept.

Parameters

NameTypeDescription
conceptCodeableConceptThe codeable concept.
systemstringThe system string.
codestringThe code value.

Returns

void

Defined in

packages/core/src/utils.ts:524


findObservationInterval

findObservationInterval(definition, patient, value, category?): ObservationDefinitionQualifiedInterval | undefined

Tries to find an observation interval for the given patient and value.

Parameters

NameTypeDescription
definitionObservationDefinitionThe observation definition.
patientPatientThe patient.
valuenumberThe observation value.
category?"reference" | "critical" | "absolute"-

Returns

ObservationDefinitionQualifiedInterval | undefined

The observation interval if found; otherwise undefined.

Defined in

packages/core/src/utils.ts:543


findObservationReferenceRange

findObservationReferenceRange(definition, patient, names): ObservationDefinitionQualifiedInterval | undefined

Tries to find an observation reference range for the given patient and condition names.

Parameters

NameTypeDescription
definitionObservationDefinitionThe observation definition.
patientPatientThe patient.
namesstring[]The condition names.

Returns

ObservationDefinitionQualifiedInterval | undefined

The observation interval if found; otherwise undefined.

Defined in

packages/core/src/utils.ts:564


matchesRange

matchesRange(value, range, precision?): boolean

Returns true if the value is in the range accounting for precision.

Parameters

NameTypeDescription
valuenumberThe numeric value.
rangeRangeThe numeric range.
precision?numberOptional precision in number of digits.

Returns

boolean

True if the value is within the range.

Defined in

packages/core/src/utils.ts:629


preciseEquals

preciseEquals(a, b, precision?): boolean

Returns true if the two numbers are equal to the given precision.

Parameters

NameTypeDescription
anumberThe first number.
bnumberThe second number.
precision?numberOptional precision in number of digits.

Returns

boolean

True if the two numbers are equal to the given precision.

Defined in

packages/core/src/utils.ts:643


preciseLessThan

preciseLessThan(a, b, precision?): boolean

Returns true if the first number is less than the second number to the given precision.

Parameters

NameTypeDescription
anumberThe first number.
bnumberThe second number.
precision?numberOptional precision in number of digits.

Returns

boolean

True if the first number is less than the second number to the given precision.

Defined in

packages/core/src/utils.ts:658


preciseGreaterThan

preciseGreaterThan(a, b, precision?): boolean

Returns true if the first number is greater than the second number to the given precision.

Parameters

NameTypeDescription
anumberThe first number.
bnumberThe second number.
precision?numberOptional precision in number of digits.

Returns

boolean

True if the first number is greater than the second number to the given precision.

Defined in

packages/core/src/utils.ts:673


preciseLessThanOrEquals

preciseLessThanOrEquals(a, b, precision?): boolean

Returns true if the first number is less than or equal to the second number to the given precision.

Parameters

NameTypeDescription
anumberThe first number.
bnumberThe second number.
precision?numberOptional precision in number of digits.

Returns

boolean

True if the first number is less than or equal to the second number to the given precision.

Defined in

packages/core/src/utils.ts:688


preciseGreaterThanOrEquals

preciseGreaterThanOrEquals(a, b, precision?): boolean

Returns true if the first number is greater than or equal to the second number to the given precision.

Parameters

NameTypeDescription
anumberThe first number.
bnumberThe second number.
precision?numberOptional precision in number of digits.

Returns

boolean

True if the first number is greater than or equal to the second number to the given precision.

Defined in

packages/core/src/utils.ts:699

Variables

SEGMENT_SEPARATOR

Const SEGMENT_SEPARATOR: "\r"

Defined in

packages/core/src/hl7.ts:3


FIELD_SEPARATOR

Const FIELD_SEPARATOR: "|"

Defined in

packages/core/src/hl7.ts:4


COMPONENT_SEPARATOR

Const COMPONENT_SEPARATOR: "^"

Defined in

packages/core/src/hl7.ts:5


allOk

Const allOk: OperationOutcome

Defined in

packages/core/src/outcomes.ts:12


created

Const created: OperationOutcome

Defined in

packages/core/src/outcomes.ts:26


notModified

Const notModified: OperationOutcome

Defined in

packages/core/src/outcomes.ts:40


notFound

Const notFound: OperationOutcome

Defined in

packages/core/src/outcomes.ts:54


unauthorized

Const unauthorized: OperationOutcome

Defined in

packages/core/src/outcomes.ts:68


forbidden

Const forbidden: OperationOutcome

Defined in

packages/core/src/outcomes.ts:82


gone

Const gone: OperationOutcome

Defined in

packages/core/src/outcomes.ts:96


tooManyRequests

Const tooManyRequests: OperationOutcome

Defined in

packages/core/src/outcomes.ts:110


DEFAULT_SEARCH_COUNT

Const DEFAULT_SEARCH_COUNT: 20

Defined in

packages/core/src/search.ts:3


globalSchema

Const globalSchema: IndexedStructureDefinition

Global schema singleton.

Defined in

packages/core/src/types.ts:332

Type Aliases

ProfileResource

Ƭ ProfileResource: Patient | Practitioner | RelatedPerson

Defined in

packages/core/src/utils.ts:24