core.medplumclient.searchone | Medplum

MedplumClient.searchOne() method

Sends a FHIR search request for a single resource.

This is a convenience method for search() that returns the first resource rather than a Bundle.

Signature:

searchOne<RT extends ResourceType>(resourceType: RT, query?: QueryTypes, options?: MedplumRequestOptions): ReadablePromise<WithId<ExtractResource<RT>> | undefined>;

Parameters

Parameter Type Description
resourceType RT The FHIR resource type.
query QueryTypes (Optional) Optional FHIR search query or structured query object. Can be any valid input to the URLSearchParams() constructor.
options MedplumRequestOptions (Optional) Optional fetch options.

Returns:

ReadablePromise < WithId <ExtractResource> | undefined

Promise to the first search result.

Example

Example using a FHIR search string:

const patient = await client.searchOne('Patient', 'identifier=123');

console.log(patient);

The return value is the resource, if available; otherwise, undefined.

See FHIR search for full details.