For AI agents: the documentation index is at /docs/aidbox/llms.txt. A Markdown version of this page is available at /docs/aidbox/api/rest-api/everything-on-patient.md or by requesting it with the Accept: text/markdown header.
Aidbox Docs

$everything on Patient

This operation returns all the information related to one or more patients described in the resource or context on which this operation is invoked. The response is a bundle. Returns resources that the server has that are related to the patient

Run Patient-everything:

GET [base]/fhir/Patient/[id]/$everything

Patient-everything supported parameters

Query parameter
_sinceInclude resources updated after the specified timestamp.
_timeoutSet timeout for every internal search.
_countLimits return of each resource type. Partial support without pagination.

Examples

Get all resources directly linked to the patient pt-1:

GET /fhir/Patient/pt-1/$everything

Get all resources directly linked to the patient pt-1 that were created or updated after Jan 1st 2021:

GET /fhir/Patient/pt-1/$everything?_since=2021-01-01T00:00:00Z

Performance note

$everything is a heavy operation that performs several SQL requests. If one of the request's duration is too long, the operation will fail due to timeout.

This can be fixed in two ways:

  • Add _timeout=<n-seconds> search parameter;
  • Optimize the request by adding an index.

Aidbox finds everything about the patient with the search parameters listed in the Patient compartment. To see them, read the FHIR core Patient compartment:

GET /fhir/CompartmentDefinition?url=http://hl7.org/fhir/CompartmentDefinition/patient

If you uploaded your own CompartmentDefinition with code: Patient, Aidbox uses it instead. See Compartments API.

For example, we suspect, that $everything operation is slow because we have a lot of Observations. The internal search for Observations that refer Patient is:

- code: Observation
  param:
    - subject
    - performer

It will be transformed into:

GET /fhir/Observation?_filter=(subject eq Patient/pt1) or (performer eq Patient/pt1)

To debug this, we can query using _explain search parameter:

GET /fhir/Observation?_filter=(subject eq Patient/pt1) or (performer eq Patient/pt1)&_explain=plan

And now we see the SQL and the PostgreSQL plan:

query:
  - >-
    SELECT "observation".* FROM "observation" WHERE (("observation".resource @>
    ?) OR ("observation".resource @> ?)) LIMIT ? OFFSET ? 
  - '{"subject":{"id":"Patient"}}'
  - '{"performer":[{"id":"Patient"}]}'
  - 100
  - 0
plan: >-
  <slow plan here>
  Planning Time: 0.045 ms
  Execution Time: 130.015 ms

The next step is to optimize the request.

See:

Last updated: