core.medplumclient.searchresourcepages | Medplum

MedplumClient.searchResourcePages() method

Creates an async generator over a series of FHIR search requests for paginated search results. Each iteration of the generator yields the array of resources on each page. Searches using _offset based pagination are limited to 10,000 records. For larger result sets, _cursor based pagination should be used instead.

See the docs for more information.

Signature:

searchResourcePages<RT extends ResourceType>(resourceType: RT, query?: QueryTypes, options?: MedplumRequestOptions): AsyncGenerator<ResourceArray<WithId<ExtractResource<RT>>>>;

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:

AsyncGenerator< ResourceArray < WithId <ExtractResource>>>

Example

for await (const page of medplum.searchResourcePages('Patient', { _count: 10 })) {

for (const patient of page) {

console.log(`Processing Patient resource with ID: ${patient.id}`);

}
}