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

# AdvancedMD Get EHR Document

> Downloads one document from an AdvancedMD patient chart and stores it as a task file.

`advancedmd_get_ehr_document` downloads a document filed on a patient's AdvancedMD EHR chart, such as a form staff uploaded against a visit, and stores it in the task.
It returns a `file_url` that a file-reading tool takes by its task variable reference.
Find the document with the catalog operations `advancedmd_op_ehr_list_documents`, or `advancedmd_op_ehr_list_encounters`, where a type 9 child of an encounter is a document filed on that visit.

## Authentication and enablement

Uses the workspace's AdvancedMD connection (office code, username, password are bound from it and hidden from the model).
Off by default: enable it on the agent.

## Inputs

| Field | Required | Notes |
| - | - | - |
| `document_id` | yes | Numeric AdvancedMD EHR document id. |

## Output

```json theme={null}
{
  "status": "success",
  "document_id": "555",
  "file_url": "${VAR_7}",
  "file_id": "5d0c…",
  "file_name": "REMS Form.pdf",
  "content_type": "application/pdf",
  "size_bytes": 182344,
  "metadata": { "id": 555, "name": "REMS Form", "date": "…", "status": "…", "documentType": "…" }
}
```

`metadata` is AdvancedMD's record as sent, without the file content. When AdvancedMD holds no content for the document, `file_url` is empty and nothing is stored.

## Limits and side effects

* Reads AdvancedMD's ehr-api `files/documents/{id}`. Read-only against AdvancedMD.
* Stores the file in the task's files, like an upload. Files over 25 MB are refused.
* The file name is the document's AdvancedMD name plus its extension (AdvancedMD's `fileExtension`, else the type sniffed from the content).

## Errors

* `document_id must be a numeric AdvancedMD EHR document id` — the id has no digits.
* `file storage is not available, so the document cannot be stored` — the surface running the tool has no file storage; AdvancedMD is not called.
* `AdvancedMD EHR documents call failed (HTTP …)` — AdvancedMD's own status, for example an unknown document.
* `could not store document …` — the content was over 25 MB or could not be written.
* An AdvancedMD-not-connected result when the workspace has no AdvancedMD connection.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.