# Search for patient records

> **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).

To search for patient records, you first need to identify organizations that have seen your patient. If you want to know where you can get patient records from, [explore a list of active Carequality participants](https://carequality.org/active-sites-search/). 

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

## Options for patient search

You have a few options for finding a patient’s record: 

![The flowchart outlines 3 possible routes: 1) Use Redox to find patients, 2A) Do your own location with the facility code, 2B) Do your own location search without the facility code.](https://images.ctfassets.net/cl3wt5ehhnlv/yswBLSUWSVGp3Yq3GIe2F/8fe6ecdf06b8ef919f8a6a4e7bafb5f0/Search_for_patient_records_diagram.png)

*Possible workflows for finding patient records*

1. <u>**Perform a broad patient search**</u>: If you don’t know where the patient is located or if the patient exists in multiple locations, Redox can provide a list of possibilities with our record locator service. 
_This is the most common option since it allows you to identify all of the organizations where a patient’s record may exist._ 
2. <u>**Perform a narrow patient search**</u>: There are two ways to perform a narrow search. The option you use depends on whether you already have the Carequailty participant facility codes(s) to query with. 
   1. <u>**With a facility code**</u>: If you have a static list of locations you wish to search or know exactly which Carequality participants have records for the patient, you can search those specific Carequality organizations or locations directly. For this option, you must already know the facility code(s). Also, keep in mind that you can only search one organization at a time.  
   2. <u>**Without a facility code**</u>: If you don’t know where the patient’s records exist, you could search for relevant organizations first. You could use parameters like ZIP code or radius around the patient’s address to find a list of options. The response returns a list of matching Carequality organization(s) with their facility code(s). Then, you can perform a patient search like in the first option. 

> **Different destination IDs**
>
> Though options 1 and 2 use the same `PatientSearch.Query`, you must use a different destination ID (see the destination ID table below). 
>
> Specifically, option 1 uses the destination ID for a specific organization, while option 2 uses the destination ID for Redox.

> **Redox patient ID**
>
> For every patient, your system assigns a <u>local patient ID</u>, which may or may not be unique.
>
> Redox also assigns a unique <u>network patient ID</u> for the same patient, which is used to identify the patient within Carequality.
>
> As a result, the patient ID in the data on demand repository isn’t the same as the patient ID in Carequality. To find the network ID for a patient, send a `PatientSearch.Query` with the patient demographics to the Redox gateway: `2.16.840.1.113883.3.6147.458.2`.

> **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)

For context on our code examples for your own testing, [check out our test patient data](/how-to-use-redox/interact-with-clinical-networks/onramp-to-carequality/test-sandbox-for-onramp-to-Carequality).

## Meta fields for queries

Regardless of the patient search option you use, each query contains required metadata fields that identify the requesting user and their organization, specify the purpose of use, and direct the request to the target organization. These fields exist within the `Meta` section of the query.

<details>
<summary>Metadata for data models</summary>

This table contains the common metadata fields you should use for Carequality queries. Any extension fields are add-on fields you can add to enhance your Carequality data exchange. [Learn more about Redox extensions](/api-reference/redox-data-model-api/extensions-for-data-models).

| **Field** | **Description** | **Notes** |
| --- | --- | --- |
| `Meta.Destinations.ID` | A universally unique identifier (UUID) for the destination you wish to search.  This ID is different for staging and production environments. Check out the destination ID table for specifics. | For most patient searches, this is a Redox destination within record locator service.  For document searches, this is a Carequality destination.  For responding with information about your patients, this is your own document repository. |
| `Meta.FacilityCode` | The OID of the organization you wish to query. | This isn’t necessary for patient searches with record locator service. |
| `Meta.Extensions.organization-name` | The name of the organization running the query. | This optional extension is generally the name of your organization or the covered entity that you are providing services for. |
| `Meta.Extensions.sender-organization-id` | The organization OID to identify your organization as the one sending the request.  You can use a top-level OID, but if there are multiple levels, it helps to be specific. | This optional extension is used for audit purposes and for search logic. Redox’s record locator service uses this to base a patient search within a 100-mile radius of the querying organization. |
| `Meta.Extensions.user-id` | Either the name of the user sending the request or the relevant provider.  This should be a human-readable name, not an ID, and should change per query based on the initiating user. When used, this field is typically required for audit purposes. | With this optional extension, the provider’s name should still be populated when an automated process runs the query. For example, a provider may have an automated process triggered after completing a patient visit. In that case, the query runs in the background on the provider’s behalf. |
| `Meta.Extensions.user-role` | The role of the user sending the query. | This is an optional extension that requires a SNOMED value. [See SNOMED codes](https://www.hl7.org/fhir/valueset-practitioner-role.html). |
| `Meta.Extensions.purpose-of-use` | Identifies the purpose of the query, which is almost always <u>**Treatment**</u>. If you specify a different <u>**Purpose of Use**</u>, other clinical network participants likely won’t respond. | This is an optional extension. You must qualify for a “Treatment” purpose of use when using <u>**Network Onramps**</u>. |

</details>

### Destination IDs

You must populate any test requests with the appropriate destination ID in the `Meta.Destinations` array based on the environment and type of requests:  

| Request purpose | Development ID | Production ID |
| --------------- | ---------- | ------------- |
| Perform a broad patient search | `adf917b5-1496-4241-87e2-ed20434b1fdb` | `97f2dc1d-c71b-43a7-a436-9b789d44c804` |
| Perform a patient search within a specific organization | `1ca254a8-8d42-4593-abb4-b21399d9de57` | `6391b961-55ae-430b-a789-cf575f03fca0` |
| Query for/create/update/delete an organization | `a07afe3b-d247-4415-827f-6837707e1b8b` | `5d0fd248-6c52-4ad9-b907-ae10bf2dcc39` |
| Search for a clinical summary/document | `ec745338-8849-43ad-a7ce-4bc5bf1d8b89` | `628cbf79-1156-4923-b9d0-285906160ed6` |
| Save patient details and documents to your data on demand repository | This is specific to your organization. Redox provides the destination ID for data on demand. | This is specific to your organization. Redox provides the destination ID for data on demand. |

## Option 1: Perform a broad search

This popular option relies on Redox’s record locator service to do the heavy lifting for you. Record locator service looks for your patient’s record at Carequality participant facilities within the same areas as your organization and the patient’s home address (if supplied). Record locator service also leverages results from other Redox client searches so we can go beyond the search area, if possible. 

> **Search identifiers: Social Security numbers**
>
> Aside from the network patient ID, the only other patient identifier that Redox searches is the Social Security number (SSN). Any other patient identifiers in a search request are ignored. 

### Step 1: PatientSearch.Query

If you already have the <u>**network patient ID**</u>, you can skip to step 2. 

If you don’t have the network patient ID, using Postman or `curl`, send `PatientSearch.Query` with the patient’s demographics to the Redox gateway (`2.16.840.1.113883.3.6147.458.2`).

- For production queries, set the `Test` value to `false`.
- For supported patient demographics, [review the PatientSearch schema](https://docs.redoxengine.com/permalink/patient-search). The values below are examples only and should change for your individual queries. 


> **What demographic information to include**
>
> Include as much demographic information as possible when searching for a patient. Most Carequality participants use advanced matching algorithms that require additional data elements beyond the minimum.
>
> At a minimum, Carequality participants must support searches with these data points:
>
> - given name
> - family name
> - birthdate
> - gender
>
> However, you shouldn’t expect results if you only use the minimum data points. You should also include what you have of these:
>
> - Social Security number (SSN)
> - address
> - email address
> - phone number(s)



**Example: Search for a patient in 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": "{{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": "PatientSearch",
        "EventType": "Query",
        "Test": true,
        "Destinations": [
            {
                "ID": "adf917b5-1496-4241-87e2-ed20434b1fdb"
            }
        ]
    },
    "Patient": {
        "Demographics": {
            "FirstName": "Lacy523",
            "LastName": "Waelchi213",
            "DOB": "2014-05-19",
            "Sex": "Male",
            "Address": {
                "StreetAddress": "418 Rice Ranch Apt 17",
                "City": "Easton",
                "State": "Massachusetts"
            }
        }
    }
}'
```

Record locator service takes the patient’s demographics and returns the <u>**network patient ID**</u>. 

### Step 2: PatientSearch.LocationQuery

Using Postman or `curl`, send `PatientSearch.LocationQuery` with the <u>**network patient ID**</u> to the Redox record locator destination.

- Remember that the `sender-organization-id` extension represents the organization sending the query. You can use a top-level OID, but if there are multiple levels, it helps to be specific.
- The destination ID changes based on environment type:
  - <u>**Development destination ID**</u>: `adf917b5-1496-4241-87e2-ed20434b1fdb`
  - <u>**Production destination ID**</u>: `97f2dc1d-c71b-43a7-a436-9b789d44c804`
- For production queries, set the `Test` value to `false`.
- The `Patient.Identifiers.ID` and `Patient.Identifiers.IDType` values change based on the search response from Step 1. The location search only ever expects one ID and ID type. 
  - The `IDType` used below is the OID for the Redox Gateway.

**Example: Search for locations**

```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": "PatientSearch",
        "EventType": "LocationQuery",
        "Test": true,
        "Destinations": [
            {
                "ID": "adf917b5-1496-4241-87e2-ed20434b1fdb"
            }
        ]
    },
    "Patient": {
        "Identifiers": [
            {
                "IDType": "2.16.840.1.113883.3.6147.458.2",
                "ID": "9ab85b7b-3946-4cfa-977f-5fbc84334ac8"
            }
        ]
    }
}'
```

> **API reference**
>
> [Review the PatientSearch schema](https://docs.redoxengine.com/permalink/patient-search) for more technical details. Or, [review extensions details](https://docs.redoxengine.com/datamodels/extensions/) for any included extensions.  

### Step 3: PatientSearch.LocationQueryResponse

The response returns a list of locations where the patient exists—along with the patient’s localized IDs at each location, which we validate. 

**Example: Successful response for location search in Carequality **

```json
{
    "Meta": {
        "DataModel": "PatientSearch",
        "EventType": "LocationQuery",
        "Extensions": {
            "sender-organization-id": {
                "url": "https://api.redoxengine.com/extensions/sender-organization-id",
                "string": "2.16.840.1.113883.3.6147.458.5420.1.1.2"
            },
            "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"
                }
            },
            "task-id": {
                "url": "https://api.redoxengine.com/extensions/task-id",
                "string": "6cd7a70d-024f-4239-898a-5a3745242948"
            },
            "task-status": {
                "url": "https://api.redoxengine.com/extensions/task-status",
                "string": "Success"
            }
        },
        "EventDateTime": "2021-12-08T21:47:05.931Z",
        "Message": {
            "ID": 12672017218
        },
        "Source": {
            "ID": "7f296bb4-83fd-498d-92f3-a76960648788"
        },
        "Destinations": [
            {
                "ID": "adf917b5-1496-4241-87e2-ed20434b1fdb",
                "Name": "Outbound RLS"
            }
        ],
        "Logs": [
            {
                "ID": "c7addcc6-8206-4d3d-986b-1ce0bd1002e0",
                "AttemptID": "754b8cdd-3022-4fdc-8613-cdba52db4ff0"
            }
        ]
    },
    "Patients": [
        {
            "Identifiers": [
                {
                    "ID": "d5a61983-5ef8-4d31-a1ce-9a92b1f098f9",
                    "IDType": "2.16.840.1.113883.3.6147.458.2"
                }
            ],
            "Organization": {
                "Identifiers": [
                    {
                        "ID": "2.16.840.1.113883.3.6147.458.2",
                        "IDType": "OID"
                    }
                ]
            }
        }
    ]
}
```

#### Notes about the location search response

The `Meta.Extensions.task-status.string` field contains a status of either `Active` or `Success`.

| **Status** | **Definition** | **Results** |
| --- | --- | --- |
| `Active` | The process is asynchronously collecting locations. | The `Patients` array populates with any partial results as they become available. |
| `Success` | The process has finished and all possible locations have been found. | Any available results have been returned.  If the `Patients` array is empty, it means no patients were found. |
| `Failure` | The query has failed to execute. | No results are returned.  [Submit a Help Center request](http://redoxengine.zendesk.com) if you repeatedly see this result. |

The response waits up to 10 seconds to reach a `Success` state. If unable to reach `Success` in that time, the response retains an `Active` status. You can retry the exact request repeatedly until it reaches a `Success` state. 

> **Review your search results later**
>
> To review the results of your search again, you can provide the value returned in `Meta.Extensions.task-id.string` on later queries.

> **Same demographics, same results**
>
> If you run a new search with the same patient demographics within a 24-hour period, you’ll see the same results. The record locator service doesn’t trigger a new search unless you have new or modified patient demographics.

## Option 2A: Perform a narrow search

If you know exactly where a patient was seen previously, you can search for a patient at an individual organization. If you want to search multiple organizations, you must search them one at a time.

### Step 1: PatientSearch.Query

Since you have the facility code for the organization you want to search, send the `PatientSearch.Query` request with the patient's demographics to see if that organization has your patient’s records. You must use the organization’s facility code (i.e., organization OID) in each request. 

- Remember that the `sender-organization-id` extension represents the organization sending the query. You can use a top-level OID, but if there are multiple levels, it helps to be specific.  
- For this example, the `user-role` is set to the default code (i.e., `112247003`), but this should change if the sending user has a different SNOMED role.
- For production queries, set the `Test` value to `false`.
- The destination ID changes based on environment type:
  - <u>**Development destination ID**</u>: `1ca254a8-8d42-4593-abb4-b21399d9de57`
  - <u>**Production destination ID**</u>: `6391b961-55ae-430b-a789-cf575f03fca0`
- For the `Facility.Code`, enter the organization OID of the organization you want to search. If there are four organizations you want to search, you must send four different queries to find the patient at each location. However, watch out for duplicates by checking the destination values to see if they have the same gateway. We use the Redox facility code in the example below.
- For supported patient demographics, [review the PatientSearch schema](https://docs.redoxengine.com/permalink/patient-search). The values below are examples only and should change for your individual queries. 


> **What demographic information to include**
>
> Include as much demographic information as possible when searching for a patient. Most Carequality participants use advanced matching algorithms that require additional data elements beyond the minimum.
>
> At a minimum, Carequality participants must support searches with these data points:
>
> - given name
> - family name
> - birthdate
> - gender
>
> However, you shouldn’t expect results if you only use the minimum data points. You should also include what you have of these:
>
> - Social Security number (SSN)
> - address
> - email address
> - phone number(s)



**Data model example: Search for a patient within one organization**

```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": "PatientSearch",
        "EventType": "Query",
        "Test": true,
        "Destinations": [
            {
                "ID": "1ca254a8-8d42-4593-abb4-b21399d9de57"
            }
        ],
        "FacilityCode": "2.16.840.1.113883.3.6147.458.2"
    },
    "Patient": {
        "Demographics": {
            "FirstName": "Adolfo",
            "LastName": "Kessler",
            "DOB": "2002-10-31",
            "SSN": "999-55-2115",
            "Sex": "Male",
            "Address": {
                "City": "Madison",
                "State": "Wisconsin",
                "ZIP": "53711"
            }
        }
    }
}
```

> **API reference**
>
> [Review the PatientSearch schema](https://docs.redoxengine.com/permalink/patient-search) for more technical details. Or, [review extensions details](https://docs.redoxengine.com/datamodels/extensions/) for any included extensions.  

### Step 2: PatientSearch.QueryResponse

If your search matches a patient at the given organization, the response returns the patient’s identifier and additional details. 

**Data model example: Successful response for a patient search within one organization**

```json
{
    "Patient": {
        "Demographics": {
            "Address": {
                "County": null,
                "Country": null,
                "ZIP": "53711",
                "State": "wisconsin",
                "City": "madison",
                "StreetAddress": "602 schiller junction suite 68"
            },
            "EmailAddresses": [],
            "PhoneNumber": {
                "Work": null,
                "Mobile": "+15556533376",
                "Home": "+15556533376"
            },
            "Sex": null,
            "DOB": "2002-10-31",
            "LastName": "kessler",
            "FirstName": "adolfo",
            "SSN": ""
        },
        "Identifiers": [
            {
                "IDType": "2.16.840.1.113883.3.6147.458.2",
                "ID": "45e5fadd-0496-4e48-be26-a06d78f8e950"
            }
        ]
    },
    "Meta": {
        "DataModel": "PatientSearch",
        "EventType": "Query",
        "Message": {
            "ID": 12721022314
        },
        "Source": {
            "ID": "d9c19117-7778-47fd-9f55-b3bccc4055f8"
        },
        "Destinations": [
            {
                "ID": "1ca254a8-8d42-4593-abb4-b21399d9de57",
                "Name": "Carequality Sandbox - XCPD"
            }
        ],
        "Logs": [
            {
                "ID": "0a4eb252-cb7a-4349-b0a5-5ccc53be2e37",
                "AttemptID": "95f2c3bd-8660-45b4-a73b-a3543908d4c2"
            }
        ]
    }
}
```

If a patient isn’t found, the response returns an empty array.

Repeat this step for every organization you want to search. 

## Option 2B: Perform a narrow search

If you know exactly where a patient was seen previously, you can search for a patient at an individual organization. If you want to search multiple organizations, you must search them one at a time.

### Step 1: Organization.Query

If you don’t have an OID for the organization you want to search, send `Organization.Query`. With this query, you search by ZIP code radius or organization name. 

- The destination ID changes based on environment type:
  - <u>**Development destination ID**</u>: `1ca254a8-8d42-4593-abb4-b21399d9de57`
  - <u>**Production destination ID**</u>: `6391b961-55ae-430b-a789-cf575f03fca0`
- Use the available search parameters to refine your search (searches by most exact match). Otherwise, you can set these to `null`: 
  - `Identifier`: Set to `null` unless you know the exact organization OID you want to search. 
  - `SearchType`: Supported types are `exact` and `contains`. Use this with the `Value` field to narrow your search.
  - `Value`: Specify the value you want to search. Used in conjunction with `SearchType`.
  - `State`: Use this parameter to search by a specific state. Can’t be used with `RadiusSearch`. 
  - `RadiusSearch`:  Use this parameter to search by ZIP code. Can’t be used with `State`. 
  - `Index` and `limit`: Use these to page search results, if needed.

**Example: Search for organizations**

```bash
curl \
-X POST https://api.redoxengine.com/endpoint \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $API_TOKEN" \
-d '{
    "Meta": {
        "DataModel": "Organization",
        "EventType": "Query",
        "Destinations": [
            {
                "ID": "1ca254a8-8d42-4593-abb4-b21399d9de57",
                "Name": "Redox Carequality - Organization Directory (XML)"
            }
        ]
    },
    "Directory": "Carequality",
    "Identifier": {
        "ID": null,
        "IDType": "OID"
    },
    "NameSearch": {
        "SearchType": null,
        "Value": null
    },
    "State": null,
    "RadiusSearch": {
        "ZipCode": null,
        "Radius": null
    },
    "Index": null,
    "Limit": 20
}'
```

> **API reference**
>
> [Review the Organization data model](https://docs.redoxengine.com/permalink/organization-new) schema for more technical details.

### Step 2: Organization.QueryResponse

If the request is successful, you receive a synchronous `Organization.QueryResponse` with the relevant organization results.

**Example: Successful response for organization search**

```json
{
    "Meta": {
        "DataModel": "Organization",
        "EventType": "Query",
        "Source": {
            "ID": "7f296bb4-83fd-498d-92f3-a76960648788"
        },
        "Message": {
            "ID": 12693372849
        },
        "Destinations": [
            {
                "ID": "5de9d0e0-91f6-4b89-9bfb-461a6966d93a",
                "Name": "Carequality Organizational Directory"
            }
        ],
        "Logs": [
            {
                "ID": "e6e74f98-ff08-4b1a-aedb-b0e53226948b",
                "AttemptID": "15c2375b-fdf7-420e-ab92-29b2676981b9"
            }
        ]
    },
    "Directory": "Carequality",
    "Organizations": {
        "Identifiers": [
            {
                "ID": "2.16.840.1.113883.3.6147.458.2",
                "IDType": "OID"
            }
        ]
    }
}
```

### Step 3: PatientSearch.Query

From the `Organization.Query` results list, select one or all of these organizations to run a patient search. You must search one organization at a time.

Send the `PatientSearch.Query` request with the patient's demographics to see if the selected organization has your patient’s records. You must use the facility code (i.e, organization OID) in each query. 

> **Where to find the OID**
>
> The OID is found in the `FacilityCode` field of the `Organization.QueryResponse` that you received in the previous step.

**Data model example: Search for a patient within one organization**

```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": "PatientSearch",
        "EventType": "Query",
        "Test": true,
        "Destinations": [
            {
                "ID": "1ca254a8-8d42-4593-abb4-b21399d9de57"
            }
        ],
        "FacilityCode": "2.16.840.1.113883.3.6147.458.2"
    },
    "Patient": {
        "Demographics": {
            "FirstName": "Adolfo",
            "LastName": "Kessler",
            "DOB": "2002-10-31",
            "SSN": "999-55-2115",
            "Sex": "Male",
            "Address": {
                "City": "Madison",
                "State": "Wisconsin",
                "ZIP": "53711"
            }
        }
    }
}
```

> **API reference**
>
> [Review the PatientSearch schema](https://docs.redoxengine.com/permalink/patient-search) for more technical details. Or, [review extensions details](https://docs.redoxengine.com/datamodels/extensions/) for any included extensions.  

### Step 4: PatientSearch.QueryResponse

If your search matches a patient at the given organization, the response returns the patient’s identifier and additional details. 

**Data model example: Successful response for a patient search within one organization**

```json
{
    "Patient": {
        "Demographics": {
            "Address": {
                "County": null,
                "Country": null,
                "ZIP": "53711",
                "State": "wisconsin",
                "City": "madison",
                "StreetAddress": "602 schiller junction suite 68"
            },
            "EmailAddresses": [],
            "PhoneNumber": {
                "Work": null,
                "Mobile": "+15556533376",
                "Home": "+15556533376"
            },
            "Sex": null,
            "DOB": "2002-10-31",
            "LastName": "kessler",
            "FirstName": "adolfo",
            "SSN": ""
        },
        "Identifiers": [
            {
                "IDType": "2.16.840.1.113883.3.6147.458.2",
                "ID": "45e5fadd-0496-4e48-be26-a06d78f8e950"
            }
        ]
    },
    "Meta": {
        "DataModel": "PatientSearch",
        "EventType": "Query",
        "Message": {
            "ID": 12721022314
        },
        "Source": {
            "ID": "d9c19117-7778-47fd-9f55-b3bccc4055f8"
        },
        "Destinations": [
            {
                "ID": "1ca254a8-8d42-4593-abb4-b21399d9de57",
                "Name": "Carequality Sandbox - XCPD"
            }
        ],
        "Logs": [
            {
                "ID": "0a4eb252-cb7a-4349-b0a5-5ccc53be2e37",
                "AttemptID": "95f2c3bd-8660-45b4-a73b-a3543908d4c2"
            }
        ]
    }
}
```

If a patient isn’t found, the response returns an empty array.

## Next steps

- [Request patient documents](/how-to-use-redox/interact-with-clinical-networks/onramp-to-carequality/request-patient-documents)

> **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)
