> ## Documentation Index
> Fetch the complete documentation index at: https://docs.ferrum.thalamiq.io/llms.txt
> Use this file to discover all available pages before exploring further.

# System-Level Search

> Search across all resource types

## System-Level Search

Search across all resource types in the system.

## Endpoint

```
GET /fhir/_search
POST /fhir/_search
```

Use `GET` for simple searches with query parameters, or `POST` for complex searches with a search body.

## GET Request

Search using query parameters:

<CodeGroup>
  ```bash cURL theme={null}
  curl "https://your-server.com/fhir/_search?_count=10&_sort=-_lastUpdated"
  ```

  ```bash HTTP theme={null}
  GET /fhir/_search?_count=10&_sort=-_lastUpdated HTTP/1.1
  Host: your-server.com
  ```
</CodeGroup>

## POST Request

Search using a search body for complex queries:

```json theme={null}
POST /fhir/_search
Content-Type: application/x-www-form-urlencoded

_count=10&_sort=-_lastUpdated&_type=Patient,Observation
```

## Search Parameters

### Common Parameters

* `_count` - Maximum number of results (default: 10)
* `_sort` - Sort order (e.g., `-_lastUpdated` for descending)
* `_summary` - Summary mode (`true`, `text`, `data`, `count`)
* `_total` - Include total count (`none`, `estimate`, `accurate`)
* `_type` - Filter by resource types (comma-separated)
* `_lastUpdated` - Filter by last updated date

### Example

```bash theme={null}
GET /fhir/_search?_type=Patient,Observation&_count=20&_sort=-_lastUpdated&_lastUpdated=ge2024-01-01
```

## Response

### Success (200 OK)

Returns a `Bundle` containing search results:

```json theme={null}
{
  "resourceType": "Bundle",
  "type": "searchset",
  "total": 42,
  "link": [
    {
      "relation": "self",
      "url": "https://your-server.com/fhir/_search?_count=10"
    },
    {
      "relation": "next",
      "url": "https://your-server.com/fhir/_search?_count=10&_offset=10"
    }
  ],
  "entry": [
    {
      "fullUrl": "https://your-server.com/fhir/Patient/123",
      "resource": {
        "resourceType": "Patient",
        "id": "123",
        ...
      }
    }
  ]
}
```

## Pagination

Use `_offset` and `_count` for pagination:

```
GET /fhir/_search?_offset=0&_count=10
GET /fhir/_search?_offset=10&_count=10
```

The response includes `next` and `previous` links when available.

## Notes

* System-level search can be resource-intensive
* Use `_type` to limit the search to specific resource types
* Results are sorted by relevance or the specified `_sort` parameter
* The `total` count may be an estimate for performance reasons


## OpenAPI

````yaml GET /
openapi: 3.1.0
info:
  title: Ferrum API
  description: >-
    FHIR R4 RESTful API implementation. All endpoints are prefixed with `/fhir`
    and follow the FHIR specification.
  version: 1.0.0
  contact:
    name: Ferrum
    url: https://github.com/thalamiq/ferrum
  license:
    name: MIT
servers:
  - url: http://localhost:8080/fhir
    description: Local development server (default port 8080)
  - url: https://your-server.com/fhir
    description: Production server (replace with your actual server URL)
  - url: https://api.example.com/fhir
    description: Example production server
security:
  - bearerAuth: []
paths:
  /:
    get:
      tags:
        - Search
      summary: System-Level Search
      description: Search across all resource types in the system.
      operationId: searchSystem
      parameters:
        - $ref: '#/components/parameters/Count'
        - $ref: '#/components/parameters/Sort'
        - $ref: '#/components/parameters/Summary'
        - $ref: '#/components/parameters/Total'
        - $ref: '#/components/parameters/Type'
        - $ref: '#/components/parameters/LastUpdated'
      responses:
        '200':
          description: Search results
          content:
            application/fhir+json:
              schema:
                $ref: '#/components/schemas/Bundle'
            application/fhir+xml:
              schema:
                $ref: '#/components/schemas/Bundle'
        '400':
          $ref: '#/components/responses/BadRequest'
components:
  parameters:
    Count:
      name: _count
      in: query
      description: Maximum number of results to return
      schema:
        type: integer
        minimum: 0
        default: 10
    Sort:
      name: _sort
      in: query
      description: Sort order (prefix with - for descending)
      schema:
        type: string
    Summary:
      name: _summary
      in: query
      description: Summary mode
      schema:
        type: string
        enum:
          - 'true'
          - text
          - data
          - count
    Total:
      name: _total
      in: query
      description: Include total count
      schema:
        type: string
        enum:
          - none
          - estimate
          - accurate
    Type:
      name: _type
      in: query
      description: Filter by resource types (comma-separated)
      schema:
        type: string
    LastUpdated:
      name: _lastUpdated
      in: query
      description: Filter by last updated date
      schema:
        type: string
  schemas:
    Bundle:
      type: object
      description: A container for a collection of resources
      required:
        - resourceType
        - type
      properties:
        resourceType:
          type: string
          enum:
            - Bundle
          description: Resource type
        type:
          type: string
          enum:
            - document
            - message
            - transaction
            - transaction-response
            - batch
            - batch-response
            - history
            - searchset
            - collection
          description: Indicates the purpose of this bundle
        total:
          type: integer
          description: If search, the total number of matches
        link:
          type: array
          items:
            $ref: '#/components/schemas/BundleLink'
          description: Links related to this Bundle
        entry:
          type: array
          items:
            $ref: '#/components/schemas/BundleEntry'
          description: Entry in the bundle
    BundleLink:
      type: object
      description: A link to another resource
      properties:
        relation:
          type: string
          description: >-
            See
            http://www.iana.org/assignments/link-relations/link-relations.xhtml#link-relations-1
        url:
          type: string
          format: uri
          description: Reference details for the link
    BundleEntry:
      type: object
      description: An entry in a bundle resource
      properties:
        fullUrl:
          type: string
          format: uri
          description: URI for resource
        resource:
          $ref: '#/components/schemas/Resource'
        request:
          $ref: '#/components/schemas/BundleEntryRequest'
        response:
          $ref: '#/components/schemas/BundleEntryResponse'
    OperationOutcome:
      type: object
      description: >-
        A collection of error, warning or information messages that result from
        a system action
      required:
        - resourceType
      properties:
        resourceType:
          type: string
          enum:
            - OperationOutcome
          description: Resource type
        issue:
          type: array
          items:
            $ref: '#/components/schemas/OperationOutcomeIssue'
          description: A list of issues associated with the operation
    Resource:
      type: object
      description: A FHIR resource. All resources have resourceType, id, and meta fields.
      required:
        - resourceType
      properties:
        resourceType:
          type: string
          description: The type of resource
        id:
          type: string
          description: Logical id of this artifact
        meta:
          $ref: '#/components/schemas/Meta'
      additionalProperties: true
    BundleEntryRequest:
      type: object
      description: Additional information about how this entry should be processed
      properties:
        method:
          type: string
          enum:
            - GET
            - POST
            - PUT
            - PATCH
            - DELETE
          description: HTTP verb for the operation
        url:
          type: string
          description: URL for HTTP equivalent of this entry
    BundleEntryResponse:
      type: object
      description: Indicates the results of processing the corresponding 'request' entry
      properties:
        status:
          type: string
          description: Status response code
        location:
          type: string
          description: The location (if the operation returns a location)
        etag:
          type: string
          description: The etag for the resource (if relevant)
        lastModified:
          type: string
          format: date-time
          description: Server's date time modified
        outcome:
          $ref: '#/components/schemas/OperationOutcome'
    OperationOutcomeIssue:
      type: object
      description: An issue associated with the operation
      required:
        - severity
        - code
      properties:
        severity:
          type: string
          enum:
            - fatal
            - error
            - warning
            - information
          description: Severity of the issue
        code:
          type: string
          enum:
            - invalid
            - structure
            - required
            - value
            - invariant
            - security
            - login
            - unknown
            - expired
            - forbidden
            - suppressed
            - processing
            - not-supported
            - duplicate
            - multiple-matches
            - not-found
            - deleted
            - too-long
            - code-invalid
            - extension
            - too-costly
            - business-rule
            - conflict
            - transient
            - lock-error
            - no-store
            - exception
            - timeout
            - incomplete
            - throttled
            - informational
          description: Error or warning code
        details:
          $ref: '#/components/schemas/CodeableConcept'
        diagnostics:
          type: string
          description: Additional diagnostic information about the issue
        location:
          type: array
          items:
            type: string
          description: XPath or JSONPath expression describing the location of the issue
    Meta:
      type: object
      description: Metadata about a resource
      properties:
        versionId:
          type: string
          description: Version specific identifier
        lastUpdated:
          type: string
          format: date-time
          description: When the resource version last changed
        profile:
          type: array
          items:
            type: string
            format: uri
          description: Profiles this resource claims to conform to
        tag:
          type: array
          items:
            $ref: '#/components/schemas/Coding'
          description: Tags applied to this resource
        security:
          type: array
          items:
            $ref: '#/components/schemas/Coding'
          description: Security labels applied to this resource
    CodeableConcept:
      type: object
      description: >-
        A concept that may be defined by a formal reference to a terminology or
        ontology
      properties:
        coding:
          type: array
          items:
            $ref: '#/components/schemas/Coding'
        text:
          type: string
          description: Plain text representation of the concept
    Coding:
      type: object
      description: A reference to a code defined by a terminology system
      properties:
        system:
          type: string
          format: uri
          description: Identity of the terminology system
        version:
          type: string
          description: Version of the system - if relevant
        code:
          type: string
          description: Symbol in syntax defined by the system
        display:
          type: string
          description: Representation defined by the system
  responses:
    BadRequest:
      description: Bad request - validation error or invalid input
      content:
        application/fhir+json:
          schema:
            $ref: '#/components/schemas/OperationOutcome'
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      bearerFormat: JWT
      description: Bearer token authentication

````