# How documents are returned

Source: https://www.flexpa.com/docs/guides/documents
Description: Where clinical documents like pathology reports and visit notes show up in Flexpa data, what format they come in, and what "original" means.

Clinical documents (pathology reports, visit notes, discharge summaries, lab reports) reach you as the file the source system stored, wrapped in a FHIR resource that describes it. This page covers where to look for them, what format they arrive in, and how to think about whether you have the "original".

## Where documents show up

A document can arrive on either of two resource types. Which one depends on the health system, not on Flexpa, so check both:

| Resource | Where the file is | Typical use |
| --- | --- | --- |
| [DiagnosticReport](https://www.flexpa.com/docs/fhir/diagnostic-report) | `presentedForm[]` | Pathology, imaging and lab reports, often with a signed PDF |
| [DocumentReference](https://www.flexpa.com/docs/fhir/document-reference) | `content[].attachment` | Visit notes, discharge summaries, C-CDA documents, scanned records |

The resource itself is metadata: what the document is, its date, who authored or signed it. The document's content is an **attachment**, which carries the bytes inline (`data`, base64), points to a **Binary** (the raw file), or occasionally points to a URL on an external host that Flexpa leaves unchanged. See [URL attachments](https://www.flexpa.com/docs/fhir/document-reference#url-attachments) for how to tell these apart and handle external URLs safely.

## What format the file is in

Whatever the source system saved. The attachment's `contentType` tells you which:

- `application/pdf`: a rendered or signed report
- C-CDA (an XML clinical document standard, often `application/xml` or `text/xml`)
- `text/html` or `text/plain`
- An image such as `image/jpeg` or `image/tiff`, usually a scanned page

The same kind of report can arrive in different formats from different health systems, so branch on `contentType` rather than assuming a PDF. If you want C-CDA documents converted to structured FHIR resources, see [C-CDA to FHIR conversion](https://www.flexpa.com/docs/fhir/document-reference#c-cda-to-fhir-conversion).

## How you download it

When an attachment points to a Binary on the source's FHIR server, Flexpa fetches that file from the source and replaces the URL with a short-lived signed link on `binary.flexpa.com`. Download it promptly and store the bytes, not the link: the link expires. The [DocumentReference](https://www.flexpa.com/docs/fhir/document-reference#url-attachments) page covers fetching, expiry and safe handling of signed links. The same applies to `DiagnosticReport.presentedForm`.

## Is this the original document?

It is the file the source system sent, passed through as received. There is no separate "original" copy held by the issuing hospital or by Flexpa to compare it against, so Flexpa cannot provide a reference file or a reference hash.

If you need an integrity record, compute your own hash when you download:

```bash
openssl dgst -sha256 downloaded-report.pdf
```

Store that hash with the file. It proves the file has not changed since you received it.

**Note:**
**Test mode documents are synthetic.** The [YourChart](https://www.flexpa.com/docs/test-mode#medical-record-systems) test patients carry documents that are representative of what a provider connection returns, but no test document can prove how a specific health system formats its reports. If you need a test patient with a particular kind of document, such as a signed pathology report, [ask us](https://www.flexpa.com/docs/support) and we will add one.
