core.medplumclient.search | Medplum

MedplumClient.search() method

Sends a FHIR search request.

Signature:

search<RT extends ResourceType>(resourceType: RT, query?: QueryTypes, options?: MedplumRequestOptions): ReadablePromise<Bundle<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:

ReadablePromise <Bundle< WithId <ExtractResource>>>

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.