Search Resource Type
The FHIR search operation allows you to search for resources of a specific type that match certain search criteria. This is done using an HTTP GET request to the endpoint corresponding to the resource type with query parameters.
- CLI
- TypeScript
- cURL
Search for Patient resources using the Haste Health CLI:
haste-health api search-type Patient "name=Smith&birthdate=ge1980-01-01"
This command searches for Patient resources with family name "Smith" born on or after January 1, 1980.
You can also search without parameters to get all resources of a type:
haste-health api search-type Patient
Search for Patient resources using the TypeScript client:
import { AsynchronousClient } from '@haste-health/client';
import { R4 } from '@haste-health/fhir-types/versions';
import { Patient } from '@haste-health/fhir-types/r4/types';
// Assuming you have a configured client
const client: AsynchronousClient<{}> = /* ... */;
const searchResults = await client.search_type<typeof R4, 'Patient'>(
{},
R4,
'Patient',
'name=Smith&birthdate=ge1980-01-01'
);
console.log('Total matches:', searchResults.total);
console.log('Patients found:', searchResults.resources);
// You can also use parsed parameters
import { parseQuery } from '@haste-health/client/url';
const searchWithParsed = await client.search_type<typeof R4, 'Patient'>(
{},
R4,
'Patient',
parseQuery('name=Smith&birthdate=ge1980-01-01')
);
Search for Patient resources using cURL:
curl -X GET "https://api.haste.health/w/[tenant]/[project]/api/v1/fhir/r4/Patient?name=Smith&birthdate=ge1980-01-01" \
-H "Content-Type: application/fhir+json" \
-H "Authorization: Bearer YOUR_ACCESS_TOKEN"
Replace [tenant] with your tenant name and [project] with your project ID.
Error Handling
If there are any issues with the request (e.g., invalid search parameters), the server will respond with an appropriate error status code and include an OperationOutcome resource in the response body.
HTTP/1.1 400 Bad Request
Content-Type: application/fhir+json
{
"resourceType": "OperationOutcome",
"issue": [
{
"severity": "error",
"code": "invalid",
"diagnostics": "Invalid search parameter: unknown_param"
}
]
}