# Ingest and Query a Patient

URL: https://docs.clinia.com/docs/get-started/ingest-and-query-a-patient

> Full walkthrough: ingest a FHIR bundle and a CDA document, browse the virtual file system, and read a condition story end-to-end.

In this tutorial you will:

1. Ingest a FHIR R4 bundle for a patient
2. Ingest a CDA document for the same patient
3. Check ingest status and confirm entity resolution ran
4. Browse the virtual file system to discover what was extracted
5. Read a condition story

By the end you will have a working Clinia Context Engine workflow and understand how source records become a navigable clinical graph.

**Time:** ~15 minutes.

## Prerequisites [#prerequisites]

- A Clinia Context Engine workspace with a workspace ID and an OAuth access token. See [Authentication and Credentials](https://docs.clinia.com/docs/platform/authentication-and-credentials) for how to obtain one. Replace `<workspace-id>` and `<access-token>` in the commands below.

## Steps [#steps]

---

<Steps>
<Step>

### Ingest a FHIR R4 bundle [#ingest-a-fhir-r4-bundle]

Pick a patient ID. It does not need to match `Patient.id` inside the bundle, as described in [Patient Records and Identifiers](https://docs.clinia.com/docs/patients/patient-records-and-identifiers#identifiers-inside-a-record).

Create the patient before the first ingest:

```bash
curl -X PUT "https://<workspace-id>.w.clinia.cloud/v1/patients/demo-patient" \
  -H "Authorization: Bearer <access-token>"
```

This call is idempotent, as described in [Create and Manage Patients](https://docs.clinia.com/docs/patients/create-and-manage-patients#create-a-patient).

<Callout type="info" title="No PHI? Use the synthetic bundle">
  Download the{" "}
  <a href="/samples/fhir-bundle.json" target="_blank" rel="noopener noreferrer">
    Jeanne Tremblay synthetic FHIR R4 bundle
    <svg
      xmlns="http://www.w3.org/2000/svg"
      width="12"
      height="12"
      viewBox="0 0 24 24"
      fill="none"
      stroke="currentColor"
      strokeWidth="2"
      strokeLinecap="round"
      strokeLinejoin="round"
      style={{ display: "inline", marginLeft: "3px", verticalAlign: "middle" }}
    >
      <path d="M15 3h6v6" />
      <path d="M10 14 21 3" />
      <path d="M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6" />
    </svg>
  </a>{" "}
  to follow along without real patient data. It covers 10 encounters spanning 2017–2026: COPD GOLD
  stage 3, hypertension, dyslipidemia, knee osteoarthritis, and an acute COPD exacerbation.
</Callout>

```bash
curl -X POST "https://<workspace-id>.w.clinia.cloud/v1/patients/demo-patient/ingestions/fhir/r4" \
  -H "Authorization: Bearer <access-token>" \
  -H "Content-Type: application/json" \
  -d @fhir-bundle.json
```

The call answers `202` with a receipt:

```json
{
  "ingestionId": "c1m2k3n4p5q6r7s8t9u0v1w2",
  "source": "fhir/r4",
  "mimeType": "application/json",
  "receivedAt": "2026-09-10T14:22:31.004Z",
  "status": "pending",
  "staged": { "facts": 12, "events": 8, "narratives": 1, "messages": 0 },
  "intake": [
    {
      "unit": "resource",
      "received": 42,
      "entries": [
        { "kind": "Condition", "count": 4, "outcome": "structured" },
        { "kind": "Observation", "count": 30, "outcome": "structured" },
        { "kind": "DocumentReference", "count": 1, "outcome": "text_only" },
        { "kind": "ImagingStudy", "count": 7, "outcome": "ignored", "reason": "unsupported" }
      ]
    }
  ],
  "startedAt": null,
  "completedAt": null,
  "failure": null
}
```

**`202` means accepted, not finished** — extraction continues after the response, so nothing is queryable yet. Keep the `ingestionId`; you will poll it in a moment.

`intake` accounts for all 42 resources you sent. Nothing is discarded silently: an `ignored` entry names the kind and says why, and it does not fail the submission.

</Step>
<Step>

### Ingest a CDA document [#ingest-a-cda-document]

Multiple ingest calls for the same patient ID accumulate sources. Entity resolution re-runs after each one, merging what it can across all sources.

```bash
curl -X POST "https://<workspace-id>.w.clinia.cloud/v1/patients/demo-patient/ingestions/cda/r2" \
  -H "Authorization: Bearer <access-token>" \
  -H "Content-Type: application/cda+xml" \
  --data-binary @summary.xml
```

```json
{
  "ingestionId": "d2n3l4o5q6r7s8t9u0v1w2x3",
  "source": "cda/r2",
  "mimeType": "application/cda+xml",
  "receivedAt": "2026-09-10T14:23:07.512Z",
  "status": "pending",
  "staged": { "facts": 9, "events": 4, "narratives": 3, "messages": 0 },
  "intake": [
    {
      "unit": "section",
      "received": 12,
      "entries": [
        { "kind": "10160-0", "label": "Medications", "count": 1, "outcome": "structured" },
        { "kind": "11348-0", "label": "Past Medical History", "count": 1, "outcome": "structured" },
        { "kind": "8648-8", "label": "Hospital Course", "count": 1, "outcome": "text_only" }
      ]
    }
  ],
  "startedAt": null,
  "completedAt": null,
  "failure": null
}
```

A second submission, so a second receipt — each one is the handle to its own request. CDA receipts carry `intake` too, counted in sections rather than resources. Patient demographics (`id`, `name`) are resolved from whichever source contains a `Patient` resource or CDA `recordTarget`.

</Step>
<Step>

### Wait for both submissions to settle [#wait-for-both-submissions-to-settle]

Both calls returned before their work finished, so ask what is still outstanding:

```bash
curl "https://<workspace-id>.w.clinia.cloud/v1/patients/demo-patient/ingestions?status=pending,processing" \
  -H "Authorization: Bearer <access-token>"
```

`meta.total` is the number of submissions still to settle. Poll until it reaches zero:

```json
{
  "data": [],
  "meta": { "total": 0, "page": 0, "perPage": 100 }
}
```

To watch one submission instead, read its receipt by id — `GET …/ingestions/{ingestionId}` — and wait for `status` to leave `pending` and `processing`. It settles at `succeeded`, `partial` (searchable, but some content is missing) or `failed`. [Track an Ingestion](https://docs.clinia.com/docs/get-started/track-an-ingestion) explains what each outcome means and when a resend is the right response.

The two submissions staged 21 facts between them (12 + 9), but the resolved graph holds fewer: entity resolution recognised duplicate pairs across the FHIR and CDA sources and merged them into single nodes. `staged` counts what each request contributed, so it never shows that merge — the [graph](https://docs.clinia.com/docs/get-started/patient-graph) is where the merged facts and the decisions behind them are read — see [Audit the Patient Graph](https://docs.clinia.com/docs/trust-and-governance/audit-the-graph).

</Step>
<Step>

### Browse the virtual file system [#browse-the-virtual-file-system]

Navigate the resolved graph through the VFS. Start at the root to see what categories were populated:

```bash
curl "https://<workspace-id>.w.clinia.cloud/v1/patients/demo-patient/vfs?path=/" \
  -H "Authorization: Bearer <access-token>"
```

Then drill into active conditions:

```bash
curl "https://<workspace-id>.w.clinia.cloud/v1/patients/demo-patient/vfs?path=/conditions/active" \
  -H "Authorization: Bearer <access-token>"
```

```json
{
  "path": "/conditions/active",
  "type": "directory",
  "children": [
    {
      "name": "fct_m4t8z1q6c3x9v2k7b5w0r3n8",
      "display": "Chronic obstructive lung disease",
      "type": "directory",
      "preview": "status: active | onset: 2014-03-10"
    },
    {
      "name": "fct_p8d4w1n6y3t9s2f7j5g0c8m3",
      "display": "Hypertension",
      "type": "directory",
      "preview": "status: active | onset: 2011-06-02"
    },
    {
      "name": "fct_q1y5g8n2d6k9s3v7c4x0b6m2",
      "display": "Dyslipidemia",
      "type": "directory",
      "preview": "status: active | onset: 2013-11-20"
    }
  ]
}
```

Each condition is named by an id, and its `display` holds the readable name. If the same condition appeared in both the FHIR bundle and the CDA document, it is a single entry here, not two.

Inspect what files are available under a condition:

```bash
curl "https://<workspace-id>.w.clinia.cloud/v1/patients/demo-patient/vfs?path=/conditions/active/fct_m4t8z1q6c3x9v2k7b5w0r3n8" \
  -H "Authorization: Bearer <access-token>"
```

```json
{
  "path": "/conditions/active/fct_m4t8z1q6c3x9v2k7b5w0r3n8",
  "type": "directory",
  "children": [
    { "name": "_story.md", "type": "file", "preview": "status: active | onset: 2014-03-10" },
    { "name": "_narratives", "type": "directory", "preview": "0 narratives" }
  ]
}
```

</Step>
<Step>

### Read a condition story [#read-a-condition-story]

Read the full narrative for the condition. The story assembles onset, current medications, monitoring labs, and complications from the merged entity graph:

```bash
curl "https://<workspace-id>.w.clinia.cloud/v1/patients/demo-patient/read?path=/conditions/active/fct_m4t8z1q6c3x9v2k7b5w0r3n8/_story.md" \
  -H "Authorization: Bearer <access-token>"
```

```json
{
  "content": "# Chronic obstructive lung disease\n\n**Status:** active\n**Onset:** 2014-03-10\n**Codes:** 13645005 (http://snomed.info/sct: Chronic obstructive lung disease), J44.1 (http://hl7.org/fhir/sid/icd-10-cm)\n\n## Progression\n\n| Date | Event |\n|------|-------|\n| 2014-03-10 | Initial documentation: Chronic obstructive lung disease |\n\n## Active Medications\n\n- **Tiotropium 18 mcg inhalation capsule** -- 18 mcg once daily\n..."
}
```

For a shorter summary, pass `format=compact`:

```bash
curl "https://<workspace-id>.w.clinia.cloud/v1/patients/demo-patient/read?path=/conditions/active/fct_m4t8z1q6c3x9v2k7b5w0r3n8/_story.md&format=compact" \
  -H "Authorization: Bearer <access-token>"
```

</Step>
</Steps>

## What you built [#what-you-built]

You ingested two sources for the same patient, let the engine resolve and merge duplicate entities across them, and retrieved a unified clinical narrative, without writing any custom parsing logic.

The key concepts at play:

- **Patient ID** (`demo-patient`) is the identifier you choose. It addresses the patient in every REST route, VFS path and MCP tool
- **Entity resolution** merged duplicate conditions, medications, and labs across sources
- **Entry ids** name each condition in its path, and the `display` next to each one tells you which is which
- **Condition stories** assemble cross-entity context (medications, labs, complications) into a single readable document

## Next steps [#next-steps]

- [Connect an AI Agent](https://docs.clinia.com/docs/context-assembly/connect-an-ai-agent) to let a language model query this patient through MCP tools
- [The Patient Graph](https://docs.clinia.com/docs/get-started/patient-graph#how-the-engine-merges-records-into-facts) to understand how the engine decides what to merge
- [Audit the patient graph](https://docs.clinia.com/docs/trust-and-governance/audit-the-graph) for focused recipes on tracing a fact back to the records behind it
