Skip to main content

core.medplumclient.search

Home > @medplum/core > MedplumClient > search

MedplumClient.search() method

Sends a FHIR search request.

Signature:

search<K extends ResourceType>(resourceType: K, query?: QueryTypes, options?: RequestInit): ReadablePromise<Bundle<ExtractResource<K>>>;

Parameters

ParameterTypeDescription
resourceTypeKThe FHIR resource type.
queryQueryTypes(Optional) Optional FHIR search query or structured query object. Can be any valid input to the URLSearchParams() constructor.
optionsRequestInit(Optional) Optional fetch options.

Returns:

ReadablePromise<Bundle<ExtractResource<K>>>

Promise to the search result bundle.

Example 1

Example using a FHIR search string:

const bundle = await client.search('Patient', 'name=Alice');
console.log(bundle);

Example 2

The return value is a FHIR bundle:

{
"resourceType": "Bundle",
"type": "searchset",
"entry": [
{
"resource": {
"resourceType": "Patient",
"name": [
{
"given": [
"George"
],
"family": "Washington"
}
],
}
}
]
}

Example 3

To query the count of a search, use the summary feature like so:

const patients = medplum.search('Patient', '_summary=count');

See FHIR search for full details: https://www.hl7.org/fhir/search.html