> ## 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.

# Resource History

> Get history of a specific resource instance

## Resource History

Retrieve the complete history of a specific resource instance, showing all versions and changes.

<ParamField path="resource_type" type="string" required>
  The FHIR resource type (e.g., `Patient`, `Observation`, `Encounter`)
</ParamField>

<ParamField path="id" type="string" required>
  The logical ID of the resource
</ParamField>

## Endpoint

```
GET /fhir/:resource_type/:id/_history
```

## Query Parameters

* `_count` - Maximum number of results (default: 10)
* `_since` - Only return versions created since this date/time
* `_at` - Return the version that existed at a specific point in time

## Example Request

<CodeGroup>
  ```bash cURL theme={null}
  curl "https://your-server.com/fhir/Patient/123/_history?_count=10"
  ```

  ```bash HTTP theme={null}
  GET /fhir/Patient/123/_history?_count=10 HTTP/1.1
  Host: your-server.com
  ```
</CodeGroup>

## Response

### Success (200 OK)

Returns a `Bundle` containing all versions of the resource:

```json theme={null}
{
  "resourceType": "Bundle",
  "type": "history",
  "total": 3,
  "entry": [
    {
      "fullUrl": "https://your-server.com/fhir/Patient/123/_history/3",
      "resource": {
        "resourceType": "Patient",
        "id": "123",
        "meta": {
          "versionId": "3",
          "lastUpdated": "2024-01-01T14:00:00Z"
        },
        "name": [{"family": "Doe", "given": ["Jane", "Marie"]}],
        ...
      },
      "request": {
        "method": "PUT",
        "url": "Patient/123"
      }
    },
    {
      "fullUrl": "https://your-server.com/fhir/Patient/123/_history/2",
      "resource": {
        "resourceType": "Patient",
        "id": "123",
        "meta": {
          "versionId": "2",
          "lastUpdated": "2024-01-01T13:00:00Z"
        },
        "name": [{"family": "Doe", "given": ["Jane"]}],
        ...
      },
      "request": {
        "method": "PUT",
        "url": "Patient/123"
      }
    },
    {
      "fullUrl": "https://your-server.com/fhir/Patient/123/_history/1",
      "resource": {
        "resourceType": "Patient",
        "id": "123",
        "meta": {
          "versionId": "1",
          "lastUpdated": "2024-01-01T12:00:00Z"
        },
        "name": [{"family": "Doe", "given": ["John"]}],
        ...
      },
      "request": {
        "method": "POST",
        "url": "Patient"
      }
    }
  ]
}
```

## History Entry Structure

Each entry in the history bundle includes:

* `fullUrl` - The versioned URL of the resource
* `resource` - The resource at that version
* `request` - Information about the request that created this version
  * `method` - HTTP method (POST, PUT, PATCH, DELETE)
  * `url` - Resource URL

## Filtering by Date

### Since Parameter

Get versions created since a specific date/time:

```bash theme={null}
GET /fhir/Patient/123/_history?_since=2024-01-01T13:00:00Z
```

### At Parameter

Get the version that existed at a specific point in time:

```bash theme={null}
GET /fhir/Patient/123/_history?_at=2024-01-01T13:30:00Z
```

## Deleted Resources

If a resource was deleted, the history includes the deletion:

```json theme={null}
{
  "fullUrl": "https://your-server.com/fhir/Patient/123/_history/4",
  "resource": {
    "resourceType": "Patient",
    "id": "123",
    "meta": {
      "versionId": "4",
      "lastUpdated": "2024-01-01T15:00:00Z"
    }
  },
  "request": {
    "method": "DELETE",
    "url": "Patient/123"
  }
}
```

## Pagination

Use `_count` and `_offset` for pagination:

```bash theme={null}
GET /fhir/Patient/123/_history?_count=10&_offset=0
GET /fhir/Patient/123/_history?_count=10&_offset=10
```

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

## Notes

* Resource history shows all versions of a specific resource
* History entries are ordered by version ID (most recent first)
* Deleted resources remain in history
* Use `_since` to get incremental updates for a resource
* The first entry is the original creation (version 1)


## OpenAPI

````yaml GET /{resourceType}/{id}/_history
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:
  /{resourceType}/{id}/_history:
    get:
      tags:
        - History
      summary: Resource History
      description: Get the complete history of a specific resource.
      operationId: resourceHistory
      parameters:
        - $ref: '#/components/parameters/ResourceType'
        - $ref: '#/components/parameters/Id'
        - $ref: '#/components/parameters/Count'
        - $ref: '#/components/parameters/Since'
        - $ref: '#/components/parameters/At'
      responses:
        '200':
          description: History bundle
          content:
            application/fhir+json:
              schema:
                $ref: '#/components/schemas/Bundle'
components:
  parameters:
    ResourceType:
      name: resourceType
      in: path
      required: true
      description: The FHIR resource type (e.g., Patient, Observation, Encounter)
      schema:
        type: string
    Id:
      name: id
      in: path
      required: true
      description: The logical ID of the resource
      schema:
        type: string
    Count:
      name: _count
      in: query
      description: Maximum number of results to return
      schema:
        type: integer
        minimum: 0
        default: 10
    Since:
      name: _since
      in: query
      description: Only return resources modified since this date/time
      schema:
        type: string
        format: date-time
    At:
      name: _at
      in: query
      description: Return resources as they were at a specific point in time
      schema:
        type: string
        format: date-time
  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'
    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'
    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
    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
    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
    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
    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
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      bearerFormat: JWT
      description: Bearer token authentication

````