core.medplumclient.searchone
Home > @medplum/core > MedplumClient > searchOne
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<K extends ResourceType>(resourceType: K, query?: QueryTypes, options?: MedplumRequestOptions): ReadablePromise<ExtractResource<K> | undefined>;
Parameters
Parameter  | Type  | Description  | 
|---|---|---|
resourceType  | K  | The FHIR resource type.  | 
query  | (Optional) Optional FHIR search query or structured query object. Can be any valid input to the URLSearchParams() constructor.  | |
options  | (Optional) Optional fetch options.  | 
Returns:
ReadablePromise<ExtractResource<K> | 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: https://www.hl7.org/fhir/search.html