Skip to content

Search Examples

Practical examples for FHIR search operations in TestScripts.

How params is applied

FHIR Frog forwards operation.params as the query string for search, with ${variable} substitution applied first, the same as read, delete, and history. A leading ? is optional — write "?family=Smith" or "family=Smith", either works. If params is absent or blank, the search is bare and unparameterized (GET [base]/Patient), with no query string at all.

{
  "operation": {
    "type": { "code": "search" },
    "resource": "Patient",
    "params": "?family=Smith",
    "responseId": "searchResponse"
  }
}

Search by Identifier

{
  "operation": {
    "type": { "code": "search" },
    "resource": "Patient",
    "params": "?identifier=http://ns.electronichealth.net.au/id/medicare-number|32788511952",
    "responseId": "searchByMedicare"
  }
}

Assert the bundle contains at least one result:

{
  "assert": {
    "description": "Search returns results",
    "expression": "Bundle.total > 0",
    "warningOnly": false
  }
}

Multiple Parameters

Combine search parameters with &:

{
  "operation": {
    "type": { "code": "search" },
    "resource": "Patient",
    "params": "?family=Smith&birthdate=1975-03-15",
    "responseId": "searchResponse"
  }
}

Search with Variable Substitution

Use a variable extracted from an earlier operation:

{
  "operation": {
    "type": { "code": "search" },
    "resource": "Observation",
    "params": "?subject=Patient/${patientId}",
    "responseId": "observationsResponse"
  }
}

_include and _revinclude

{
  "operation": {
    "type": { "code": "search" },
    "resource": "MedicationRequest",
    "params": "?patient=${patientId}&_include=MedicationRequest:medication",
    "responseId": "medRequestsWithMeds"
  }
}
{
  "operation": {
    "type": { "code": "search" },
    "resource": "Observation",
    "params": "?subject=Patient/${patientId}&date=ge2024-01-01&date=le2024-12-31",
    "responseId": "yearObservations"
  }
}

Assert Specific Entry

Use FHIRPath to assert a specific entry in the search bundle:

{
  "assert": {
    "description": "Patient with correct identifier found",
    "expression": "Bundle.entry.resource.ofType(Patient).identifier.where(system='http://ns.electronichealth.net.au/id/medicare-number').value = '32788511952'",
    "warningOnly": false
  }
}

Assert a search returns no results:

{
  "assert": {
    "description": "No results for unknown identifier",
    "expression": "Bundle.total = 0",
    "warningOnly": false
  }
}

Next Steps