Skip to main content
GET
/
{compartmentType}
/
{compartmentId}
/
{resourceType}
Compartment Search
curl --request GET \
  --url http://localhost:8080/fhir/{compartmentType}/{compartmentId}/{resourceType} \
  --header 'Authorization: Bearer <token>'
{
  "resourceType": "Bundle",
  "type": "document",
  "total": 123,
  "link": [
    {
      "relation": "<string>",
      "url": "<string>"
    }
  ],
  "entry": [
    {
      "fullUrl": "<string>",
      "resource": {
        "resourceType": "<string>",
        "id": "<string>",
        "meta": {
          "versionId": "<string>",
          "lastUpdated": "2023-11-07T05:31:56Z",
          "profile": [
            "<string>"
          ],
          "tag": [
            {
              "system": "<string>",
              "version": "<string>",
              "code": "<string>",
              "display": "<string>"
            }
          ],
          "security": [
            {
              "system": "<string>",
              "version": "<string>",
              "code": "<string>",
              "display": "<string>"
            }
          ]
        }
      },
      "request": {
        "method": "GET",
        "url": "<string>"
      },
      "response": {
        "status": "<string>",
        "location": "<string>",
        "etag": "<string>",
        "lastModified": "2023-11-07T05:31:56Z",
        "outcome": {
          "resourceType": "OperationOutcome",
          "issue": [
            {
              "severity": "fatal",
              "code": "invalid",
              "details": {
                "coding": [
                  {
                    "system": "<string>",
                    "version": "<string>",
                    "code": "<string>",
                    "display": "<string>"
                  }
                ],
                "text": "<string>"
              },
              "diagnostics": "<string>",
              "location": [
                "<string>"
              ]
            }
          ]
        }
      }
    }
  ]
}
Search for resources within a specific compartment. Compartments group related resources together (e.g., all resources related to a specific patient).
compartment_type
string
required
The compartment type (Patient, Encounter, RelatedPerson, Practitioner, Device)
compartment_id
string
required
The ID of the compartment resource
resource_type
string
Optional: Filter to a specific resource type within the compartment

Endpoint

GET /fhir/:compartment_type/:compartment_id/:resource_type
GET /fhir/:compartment_type/:compartment_id/_search
POST /fhir/:compartment_type/:compartment_id/_search
POST /fhir/:compartment_type/:compartment_id/:resource_type/_search

Patient Compartment

Search all resources related to a specific patient:
curl "https://your-server.com/fhir/Patient/123/Observation?code=http://loinc.org|29463-7"

Encounter Compartment

Search all resources related to a specific encounter:
GET /fhir/Encounter/456/Observation

All Resources in Compartment

Search all resource types in a compartment:
GET /fhir/Patient/123/_search
Or using POST:
POST /fhir/Patient/123/_search
Content-Type: application/x-www-form-urlencoded

_type=Observation,MedicationRequest&_count=20

Search Parameters

You can combine compartment search with type-specific search parameters:
GET /fhir/Patient/123/Observation?code=http://loinc.org|29463-7&date=ge2024-01-01&_sort=-date

Response

Success (200 OK)

Returns a Bundle containing resources in the compartment:
{
  "resourceType": "Bundle",
  "type": "searchset",
  "total": 15,
  "entry": [
    {
      "fullUrl": "https://your-server.com/fhir/Observation/789",
      "resource": {
        "resourceType": "Observation",
        "id": "789",
        "subject": {
          "reference": "Patient/123"
        },
        ...
      }
    }
  ]
}

Standard Compartments

Patient Compartment

Includes resources that reference the patient:
  • Observation
  • Condition
  • Procedure
  • MedicationRequest
  • Encounter
  • DiagnosticReport
  • And more…

Encounter Compartment

Includes resources that reference the encounter:
  • Observation
  • Procedure
  • MedicationRequest
  • DiagnosticReport
  • And more…

RelatedPerson Compartment

Includes resources related to a related person.

Practitioner Compartment

Includes resources related to a practitioner.

Device Compartment

Includes resources related to a device.

Examples

All Observations for a Patient

GET /fhir/Patient/123/Observation

Observations with Specific Code

GET /fhir/Patient/123/Observation?code=http://loinc.org|29463-7

All Resources in Patient Compartment

GET /fhir/Patient/123/_search
GET /fhir/Patient/123/Observation?status=final&date=ge2024-01-01&_count=50

Notes

  • Compartment membership is determined by resource references
  • Not all resources belong to compartments
  • Compartment search is more efficient than filtering by reference
  • Use compartment search when you know the compartment resource ID
  • The compartment ID must exist for the search to work

Authorizations

Authorization
string
header
required

Bearer token authentication

Path Parameters

compartmentType
string
required

The compartment type (Patient, Encounter, etc.)

compartmentId
string
required

The compartment resource ID

resourceType
string
required

The FHIR resource type (e.g., Patient, Observation, Encounter)

Query Parameters

_count
integer
default:10

Maximum number of results to return

Required range: x >= 0
_sort
string

Sort order (prefix with - for descending)

Response

Search results

A container for a collection of resources

resourceType
enum<string>
required

Resource type

Available options:
Bundle
type
enum<string>
required

Indicates the purpose of this bundle

Available options:
document,
message,
transaction,
transaction-response,
batch,
batch-response,
history,
searchset,
collection
total
integer

If search, the total number of matches

Links related to this Bundle

entry
object[]

Entry in the bundle