# Request patient documents

> **Who can use this how-to**
>
> - Existing customers using <u>**Network Onramps**</u> to connect to the <u>**Carequality Interoperability Framework**</u>.
> - Existing customers with a direct connection to the <u>**Carequality Interoperability Framework**</u> (i.e., without Redox).

After you successfully [search and locate patient records](/how-to-use-redox/interact-with-clinical-networks/onramp-to-carequality/search-for-patient-records) at a given organization, you can request patient documents. There are two options for this step. 

![The flowchart outlines 2 possible routes: 1) Use Redox to find the latest clinical summary, or 2) Run your own document query and pick documents from the returned list.](https://images.ctfassets.net/cl3wt5ehhnlv/17Mj9Q1I8WHhhBnHyazAgG/a59e622ca0ad327519662ea56a3e811f/Request_patient_docs_diagram.png)

*Possible workflows for requesting patient documents*

1. <u>**Use Redox to request the latest patient summary**</u>: Typically, the simplest option is to request a generic patient summary directly via Redox. 
2. <u>**Pick your own docs**</u>**:** If you can select documents of interest within your own UI, you can retrieve a full list of available documents and select the specific documents that are of interest. 

The returned documents from either option follow a standard format (Consolidated-Clinical Document Architecture, or C-CDA) and include several sections of information related to the patient’s demographics, encounters, medications, diagnoses, allergies, and more. [Check out required C-CDA elements](https://docs.redoxengine.com/permalink/1ldmpAmaxAriJ7Ei0zYn3Q/#what-data-is-exchanged).

> **Different organization, different data**
>
> Different organizations may include varying amounts of information or specificity, or they may use different code sets to represent the data. We simply pass the data as we receive it from the responding organization.

> **FHIR option**
>
> Did you know you can also do this workflow with Redox FHIR? [Learn how to request patient documents with FHIR](/how-to-use-redox/interact-with-clinical-networks/onramp-to-carequality/request-patient-documents-with-fhir).

> **Use curl for technical validation**
>
> You can copy our code examples and send the test requests with `curl` ([learn more about curl](https://curl.haxx.se/docs/manpage.html)) instead of Postman. If you do, remember to:
>
> - Replace any variables with your specific data (e.g., your organization's OID) before sending the request. 
>   - `$VARIABLE`: An environment variable you can set in your terminal before running the command.
>   - `{{variable here}}`: A placeholder for your specific data. 
> - Add the `source-id` if you have multiple sources. We don’t include `{{source-id}}` in the code examples, so you’ll have to add them yourself. [Learn about including source details](/basics/data-exchange-with-redox/Managing-source-details-in-outgoing-requests).
> - Make sure you have a full request for your own use since some of the code examples are abbreviated.
>
> Check out these troubleshooting guides if you run into errors:
>
> - [Troubleshoot Carequality errors](/troubleshooting/troubleshoot-carequality-interoperability-framework-errors)
> - [Troubleshoot OAuth API key errors](/troubleshooting/troubleshoot-oauth-api-key-errors)

## Option 1: Use Redox to request latest patient summary

Choose this option if you only want CDA documents, and you want to automatically get the most recent CDA for a patient. You receive the data back in a nice Redox-parsed view. 

### Step 1: ClinicalSummary.PatientQuery

Using Postman or `curl`, send a `ClinicalSummary.PatientQuery` request with the relevant metadata:

- For production queries, set the `Test` value to `false`.
- The destination ID changes based on environment type:
  - <u>**Development destination ID**</u>: `ec745338-8849-43ad-a7ce-4bc5bf1d8b89`
  - <u>**Production destination ID**</u>: `628cbf79-1156-4923-b9d0-285906160ed6`
- The `FacilityCode` represents the OID of the Carequality participant to query.
  - For a broad search, use the `Organization.Identifiers.ID` from the [PatientSearch.LocationQuery response](https://docs.redoxengine.com/permalink/7vkqqC6BJejJqcCd5Ud7g7/#step-3-patient-search-location-query-response). 
  - For a narrow search, use the `Organization.Identifiers.ID` from the [Organization.Query response](https://docs.redoxengine.com/permalink/7vkqqC6BJejJqcCd5Ud7g7/#step-2-organization-query-response). 
  - The example below represents Redox.
- Use the `Patient.Identifiers.ID` and `Patient.Identifiers.IDType` from the `PatientSearch.Query` response ([from whichever patient search option you used](/how-to-use-redox/interact-with-clinical-networks/onramp-to-carequality/search-for-patient-records)).

**Example: Request a patient summary**

```bash
curl \
-X POST https://api.redoxengine.com/endpoint \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $API_TOKEN" \
-d '{
    "Meta": {
        "Extensions": {
            "sender-organization-id": {
                "url": "https://api.redoxengine.com/extensions/sender-organization-id",
                "string": "{{YOUR-ORGANIZATION-OID}}"
            },
            "user-id": {
                "url": "https://api.redoxengine.com/extensions/user-id",
                "string": "{{SENDING-USER-NAME}}"
            },
            "user-role": {
                "url": "https://api.redoxengine.com/extensions/user-role",
                "coding": {
                    "code": "{{SNOMED-USER-ROLE}}",
                    "display": "{{HUMAN-READABLE-NAME-FOR-CODE}}"
                }
            },
            "purpose-of-use": {
                "url": "https://api.redoxengine.com/extensions/purpose-of-use",
                "coding": {
                    "code": "TREATMENT",
                    "display": "Treatment"
                }
            }
        },
        "DataModel": "Clinical Summary",
        "EventType": "PatientQuery",
        "Test": true,
        "Destinations": [
            {
                "ID": "ec745338-8849-43ad-a7ce-4bc5bf1d8b89"
            }
        ],
        "FacilityCode": "2.16.840.1.113883.3.6147.458.2"
    },
    "Patient": {
        "Identifiers": [
            {
                "ID": "{{PATIENT-ID-FROM-PATIENT-SEARCH-QUERY-RESPONSE}}",
                "IDType": "{{PATIENT-ID-TYPE-FROM-PATIENT-SEARCH-QUERY-RESPONSE}}"
            }
        ]
    }
}
```

> **API reference**
>
> [Review the Clinical Summary data model](https://docs.redoxengine.com/permalink/clinical-summary) schema for more technical details.

### Step 2: ClinicalSummary.PatientQueryResponse

If the request is successful, you receive a synchronous `ClinicalSummary.PatientQueryResponse` with the latest patient summary document (i.e., a snapshot of the patient’s current chart).

**Example: Successful response for a patient summary**

```json
{
    "InsurancesText": "",
    "Insurances": [],
    "Header": {
        "Document": {
            "Visit": {
                "Location": null,
                "VisitNumber": "",
                "EndDateTime": "",
                "StartDateTime": ""
            },
            "Author": {
                "Location": {
                    "Facility": "MADISON ANESTHESIOLOGY CONSULTANTS, LLP"
                }
            },
            "ID": "2.16.840.1.113883.19.5^92cce54a-3a9f-634a-4d20-7e566ecc32ab",
            "TypeCode": {
                "AltCodes": [],
                "CodeSystemName": "LOINC",
                "CodeSystem": "2.16.840.1.113883.6.1",
                "Name": "Summarization of episode note",
                "Code": "34133-9"
            },
            "Type": "Summarization of episode note",
            "DateTime": "2020-12-10T17:09:50.000Z",
            "Title": "C-CDA R2.1 Patient Record: Adolfo Kessler",
            "Locale": "US"
        },
        "Patient": {
            "Demographics": {
                "MaritalStatus": "",
                "Religion": "",
                "Ethnicity": "Not hispanic or latino",
                "Race": "White",
                "Address": {
                    "County": "",
                    "ZIP": "53711",
                    "Country": "",
                    "State": "Wisconsin",
                    "City": "Madison",
                    "StreetAddress": "602 Schiller Junction Suite 68"
                },
                "Sex": "Male",
                "SSN": "",
                "DOB": "2002-10-31T17:09:50.000Z",
                "EmailAddresses": [],
                "PhoneNumber": {
                    "Mobile": "",
                    "Office": "",
                    "Home": ""
                },
                "LastName": "Kessler",
                "FirstName": "Adolfo"
            },
            "Identifiers": [
                {
                    "IDType": "2.16.840.1.113883.19.5",
                    "ID": "j8p2NtTbAL7rTWRRhe7kSK"
                }
            ]
        }
    }
```

## Option 2: Pick your own docs

Choose this option if you want to receive a full list of documents related to the patient. Then, query for any document from the list. You receive the document in both raw XML—which is useful if you have your own document renderer—and in a Redox-parsed view for any data that we can parse. 

For this option, use the `DocumentQuery` and `DocumentGet` event types of `ClinicalSummary`. The response returns PDFs or any other documents that are attached to the patient record. 

### Step 1: ClinicalSummary.DocumentQuery

Using Postman or `curl`, send the `ClinicalSummary.DocumentQuery` request with the relevant metadata:

- The destination ID changes based on environment type:
  - <u>**Development destination ID**</u>: `ec745338-8849-43ad-a7ce-4bc5bf1d8b89`
  - <u>**Production destination ID**</u>: `628cbf79-1156-4923-b9d0-285906160ed6`
- The `FacilityCode` represents the OID of the Carequality participant to query.
  - For a broad search, use the `Organization.Identifiers.ID` from the [PatientSearch.LocationQuery response](https://docs.redoxengine.com/permalink/7vkqqC6BJejJqcCd5Ud7g7/#step-3-patient-search-location-query-response). 
  - For a narrow search, use the `Organization.Identifiers.ID` from the [Organization.Query response](https://docs.redoxengine.com/permalink/7vkqqC6BJejJqcCd5Ud7g7/#step-2-organization-query-response). 
  - The example below represents Redox.
- Use the `Patient.Identifiers.ID` and `Patient.Identifiers.IDType` from the `PatientSearch.Query` response ([from whichever patient search option you used](/how-to-use-redox/interact-with-clinical-networks/onramp-to-carequality/search-for-patient-records)).

> **Which documents to request**
>
> It’s possible to get lots of documents that may or may not be useful to you. We recommend requesting the patient’s most recent CCD (i.e., LOINC 34133-9) and progress notes (LOINC 11506-3) from the last three months.
>
> Be aware that responders may have different names for progress notes, like “telephone,” “office visit,” or “emergency.” You can find the document’s LOINC value in the `Documents[].Type.Code` for each document returned in the `ClinicalSummary.documentQueryResponse`.

**Example: Search for a document list from Carequality**

```bash
curl \
-X POST https://api.redoxengine.com/endpoint \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $API_TOKEN" \
-d '{
    "Meta": {
        "Extensions": {
            "sender-organization-id": {
                "url": "https://api.redoxengine.com/extensions/sender-organization-id",
                "string": "{{YOUR-ORGANIZATION-OID}}"
            },
            "user-id": {
                "url": "https://api.redoxengine.com/extensions/user-id",
                "string": "{{SENDING-USER-NAME}}"
            },
            "user-role": {
                "url": "https://api.redoxengine.com/extensions/user-role",
                "coding": {
                    "code": "112247003",
                    "display": "Medical Doctor"
                }
            },
            "purpose-of-use": {
                "url": "https://api.redoxengine.com/extensions/purpose-of-use",
                "coding": {
                    "code": "TREATMENT",
                    "display": "Treatment"
                }
            }
        },
        "DataModel": "Clinical Summary",
        "EventType": "DocumentQuery",
        "Test": true,
        "Destinations": [
            {
                "ID": "ec745338-8849-43ad-a7ce-4bc5bf1d8b89"
            }
        ],
        "FacilityCode": "2.16.840.1.113883.3.6147.458.2"
    },
    "Patient": {
        "Identifiers": [
            {
                "ID": "{{PATIENT-ID-FROM-PATIENT-SEARCH-QUERY-RESPONSE}}",
                "IDType": "{{PATIENT-ID-TYPE-FROM-PATIENT-SEARCH-QUERY-RESPONSE}}"
            }
        ]
    }
}
```

> **API reference**
>
> [Review the Clinical Summary data model](https://docs.redoxengine.com/permalink/clinical-summary) schema for more technical details.

### Step 2: ClinicalSummary.DocumentQueryResponse

If the request is successful, you receive a synchronous `ClinicalSummary.DocumentQueryResponse` with a document list with an identifier, type, and date for each document so that you can identify the most relevant documents.

**Example: Successful response for a document list from Carequality**

```json
{
    "Documents": [
        {
            "Author": {
                "Location": {
                    "Type": "General Medicine",
                    "Department": "Health Encounter Site",
                    "Facility": "Cool.io"
                },
                "Type": "",
                "Credentials": [],
                "FirstName": null,
                "LastName": null,
                "IDType": null,
                "ID": null
            },
            "Location": {
                "Department": "Health Encounter Site"
            },
            "Visit": {
                "Type": "Summarization of episode note",
                "EndDateTime": "2020-12-10T17:09:50.000Z",
                "StartDateTime": "2020-12-10T17:09:50.000Z"
            },
            "Type": {
                "Name": "Summarization of episode note",
                "Codeset": "2.16.840.1.113883.6.1",
                "Code": "34133-9"
            },
            "FileType": "text/xml",
            "HCID": "urn:oid:2.16.840.1.113883.3.6147.458.8080.2.2.1",
            "RepositoryUniqueId": "2.16.840.1.113883.3.6147.458.8080.2.2.1",
            "DateTime": null,
            "Locale": "en-US",
            "Title": "Summarization of episode note",
            "ID": "Mi4xNi44NDAuMS4xMTM4ODMuMTkuNV45MmNjZTU0YS0zYTlmLTYzNGEtNGQyMC03ZTU2NmVjYzMyYWI=^Mi4xNi44NDAuMS4xMTM4ODMuMy42MTQ3LjQ1OC44MDgwLjIuMi4x^dXJuOm9pZDoyLjE2Ljg0MC4xLjExMzg4My4zLjYxNDcuNDU4LjgwODAuMi4yLjE="
        }
    ],
    "Patient": {
        "Identifiers": [
            {
                "ID": "45e5fadd-0496-4e48-be26-a06d78f8e950",
                "IDType": "2.16.840.1.113883.3.6147.458.2"
            }
        ]
    },
    "Meta": {
        "DataModel": "Clinical Summary",
        "EventType": "DocumentQuery",
        "Message": {
            "ID": 12720346889
        },
        "Source": {
            "ID": "d9c19117-7778-47fd-9f55-b3bccc4055f8"
        },
        "Destinations": [
            {
                "ID": "ec745338-8849-43ad-a7ce-4bc5bf1d8b89",
                "Name": "Carequality Sandbox - XCA"
            }
        ],
        "Logs": [
            {
                "ID": "f30fbf24-5e3f-4503-b899-1fc247f0f996",
                "AttemptID": "2a215fde-a385-4f5a-bfb1-28a14e7a9605"
            }
        ]
    }
}
```

### Step 3: ClinicalSummary.DocumentGet

Using Postman or `curl`, send the `ClinicalSummary.DocumentGet` request with the relevant metadata:

- The destination ID changes based on environment type:
  - <u>**Development destination ID**</u>: `ec745338-8849-43ad-a7ce-4bc5bf1d8b89`
  - <u>**Production destination ID**</u>: `628cbf79-1156-4923-b9d0-285906160ed6`
- The `FacilityCode` represents the OID of the Carequality participant to query.
  - For a broad search, use the `Organization.Identifiers.ID` from the [PatientSearch.LocationQuery response](https://docs.redoxengine.com/permalink/7vkqqC6BJejJqcCd5Ud7g7/#step-3-patient-search-location-query-response). 
  - For a narrow search, use the `Organization.Identifiers.ID` from the [Organization.Query response](https://docs.redoxengine.com/permalink/7vkqqC6BJejJqcCd5Ud7g7/#step-2-organization-query-response). 
  - The example below represents Redox.
- Use a `Document.ID` from the step 2 response. 


> **Less is more**
>
> Documents can only be retrieved one at a time. We recommend retrieving only the most relevant documents, not every document on the list. 



**Example: Retrieve a document from Carequality**

```bash
curl \
-X POST https://api.redoxengine.com/endpoint \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $API_TOKEN" \
-d '{
    "Meta": {
        "Extensions": {
            "sender-organization-id": {
                "url": "https://api.redoxengine.com/extensions/sender-organization-id",
                "string": "{{YOUR-ORGANIZATION-OID}}"
            },
            "user-id": {
                "url": "https://api.redoxengine.com/extensions/user-id",
                "string": "{{SENDING-USER-NAME}}"
            },
            "user-role": {
                "url": "https://api.redoxengine.com/extensions/user-role",
                "coding": {
                    "code": "112247003",
                    "display": "Medical Doctor"
                }
            },
            "purpose-of-use": {
                "url": "https://api.redoxengine.com/extensions/purpose-of-use",
                "coding": {
                    "code": "TREATMENT",
                    "display": "Treatment"
                }
            }
        },
        "DataModel": "Clinical Summary",
        "EventType": "DocumentGet",
        "EventDateTime": "2019-08-02T20:09:22.089Z",
        "Test": true,
        "Destinations": [
            {
                "ID": "ec745338-8849-43ad-a7ce-4bc5bf1d8b89"
            }
        ],
        "FacilityCode": "2.16.840.1.113883.3.6147.458.2"
    },
    "Document": {
        "ID": "{{DOCUMENT-ID-FROM-STEP-2}}"
    }
}
```

### Step 4: ClinicalSummary.DocumentGetResponse

If the request is successful, you receive a synchronous `ClinicalSummary.DocumentGetResponse` with the relevant document of interest. 

The raw content is present in the `Data` field and the type of content in `FileType` field. 

- For CDA content, `FileType` is always `text`/`xml`, and `Data` is `UTF-8` text content. In this case, we translate the JSON to match the `ClinicalSummary.VisitQueryResponse` data model ([see the response format](https://docs.redoxengine.com/permalink/clinical-summary-visit-query-response)). 
- For non-CDA content, `FileType` is whatever the clinical network sends, and `Data` is always base64-encoded content. This is to support file types like `application`/`pdf` or XML content that isn’t CDA.

**Example (abbreviated): Successful document retrieval from Carequality**

```json
{
"Meta": {
        "DataModel": "Clinical Summary",
        "EventType": "DocumentGet",
        "Message": {
            "ID": 12720346936
        },
        "Source": {
            "ID": "d9c19117-7778-47fd-9f55-b3bccc4055f8"
        },
        "Destinations": [
            {
                "ID": "ec745338-8849-43ad-a7ce-4bc5bf1d8b89",
                "Name": "Carequality Sandbox - XCA"
            }
        ],
        "Logs": [
            {
                "ID": "8ebf45b3-3c60-4d35-8f93-a1b754eded73",
                "AttemptID": "62dc89d4-6d59-418b-95b1-131fae7a721d"
            }
        ]
    },
      "Header": {
        "Document": {
            "Title": "C-CDA R2.1 Patient Record: Adolfo Kessler",
            "Visit": {
                "Location": null,
                "VisitNumber": "",
                "EndDateTime": "",
                "StartDateTime": ""
            },
            "Author": {
                "Location": {
                    "Facility": "MADISON ANESTHESIOLOGY CONSULTANTS, LLP"
                }
            },
            "ID": "2.16.840.1.113883.19.5^92cce54a-3a9f-634a-4d20-7e566ecc32ab",
            "TypeCode": {
                "AltCodes": [],
                "CodeSystemName": "LOINC",
                "CodeSystem": "2.16.840.1.113883.6.1",
                "Name": "Summarization of episode note",
                "Code": "34133-9"
            },
            "Type": "Summarization of episode note",
            "DateTime": "2020-12-10T17:09:50.000Z",
            "Locale": "US"
        },
        "Patient": {
            "Demographics": {
                "MaritalStatus": "",
                "Religion": "",
                "Ethnicity": "Not hispanic or latino",
                "Race": "White",
                "Address": {
                    "County": "",
                    "ZIP": "53711",
                    "Country": "",
                    "State": "Wisconsin",
                    "City": "Madison",
                    "StreetAddress": "602 Schiller Junction Suite 68"
                },
                "Sex": "Male",
                "SSN": "",
                "DOB": "2002-10-31T17:09:50.000Z",
                "EmailAddresses": [],
                "PhoneNumber": {
                    "Mobile": "",
                    "Office": "",
                    "Home": ""
                },
                "LastName": "Kessler",
                "FirstName": "Adolfo"
            },
            "Identifiers": [
                {
                    "IDType": "2.16.840.1.113883.19.5",
                    "ID": "j8p2NtTbAL7rTWRRhe7kSK"
                }
            ]
        }
    },
  "Data": "",
  "FileType": "text/xml",
  ...
}
```

## Next steps

- [Maintain your Redox repository](/how-to-use-redox/interact-with-clinical-networks/onramp-to-carequality/maintain-your-redox-repository-for-carequality)

> **Onramp to Carequality resources**
>
> **Basic information**
>
> - [Interact with clinical networks](/how-to-use-redox/interact-with-clinical-networks)
> - [Carequality identity and organization structure](/how-to-use-redox/interact-with-clinical-networks/onramp-to-carequality/carequality-identity-and-organization-structure)
> - [Carequality FAQ](/how-to-use-redox/interact-with-clinical-networks/onramp-to-carequality/carequality-interoperability-framework-faq)
> - [Carequality test patients](/how-to-use-redox/interact-with-clinical-networks/onramp-to-carequality/test-sandbox-for-onramp-to-Carequality) (contains patient data to use when testing)
>
> **How-to**
>
> - [Set up your onramp to Carequality](/how-to-use-redox/interact-with-clinical-networks/onramp-to-carequality/set-up-your-onramp-to-carequality)
> - [Create and maintain an organization record](/how-to-use-redox/interact-with-clinical-networks/onramp-to-carequality/create-a-carequality-organization-record)
> - [Search for patient records](/how-to-use-redox/interact-with-clinical-networks/onramp-to-carequality/search-for-patient-records)
> - [Request patient documents](/how-to-use-redox/interact-with-clinical-networks/onramp-to-carequality/request-patient-documents)
> - [Maintain your Redox repository](/how-to-use-redox/interact-with-clinical-networks/onramp-to-carequality/maintain-your-redox-repository-for-carequality)
>
> **Troubleshooting**
>
> - [Common Carequality errors](/troubleshooting/troubleshoot-carequality-interoperability-framework-errors)
