core.medplumclient.searchresourcepages
Home > @medplum/core > MedplumClient > searchResourcePages
MedplumClient.searchResourcePages() method
Creates an [async generator](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global\_Objects/AsyncGenerator) 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: https://www.medplum.com/docs/search/paginated-search\#cursor-based-pagination
Signature:
searchResourcePages<K extends ResourceType>(resourceType: K, query?: QueryTypes, options?: MedplumRequestOptions): AsyncGenerator<ResourceArray<ExtractResource<K>>>;
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:
AsyncGenerator<ResourceArray<ExtractResource<K>>>
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}`);
}
}