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

# Verify Existing Patient via Morf Forms

> Use Morf's verify endpoint to check if a Morf Forms user is an existing patient based on email and date of birth.

## Setup

### 1. Create hidden fields

* `verify_patient`
* `morf_token`

### 2. Set `morf_token` in your Environment logic rule

Add `morf_token` to your existing **Set Environment Variables** logic rule. Reach out to your Morf POC to generate the token values.

> [accordion] View code
>
> ```jsx theme={null}
> if (feathery.isTestForm()) {
>   morf_token.value = 'morf_sandbox....';
> } else {
>   morf_token.value = 'morf_production....';
> }
> ```

### 3. Create logic rule: Existing Patient Check

* **Trigger:** when **DOB** or **email** fields are changed

> [accordion] View code
>
> ```jsx theme={null}
> /* -------- Build the payload for Morf's verify patient endpoint -------- */
> const params = {
>   lookup_type: 'LOOKUP_TYPE_PATIENT',
>   email_address: email_address.value,
>   'property_assertions.date_of_birth': dob.value,
>   multiple_profiles_action: 'MULTIPLE_PROFILES_ACTION_CHOOSE_PATIENT'
> };
>
> /* -------- Convert params to query string -------- */
> const queryString = new URLSearchParams(params).toString();
> const url = `https://api.morf.healthcare/v1/profiles/verify?${queryString}`;
>
> console.log('verify patient url:', url);
>
> /* -------- Call Morf's verify profile API -------- */
> const response = await feathery.http.get(url);
> const data = response.data;
> console.log('verify patient response: ', data);
> console.log('customer id: ', data?.customer?.id);
>
> /* -------- Store customer ID to verify_patient variable -------- */
> verify_patient.value = data?.customer?.id;
> ```

### 4. Create an API Connector

Add an API connector for `https://api.morf.healthcare/v1/profiles/verify` with method **GET**.

### 5. Add step logic based on `verify_patient`

On the step where DOB and email are entered, create a connection based on whether `verify_patient` is filled or empty. The specifics depend on your use case.

*Example: if you want to prevent existing patients from booking through a sign-up form, navigate them to a step indicating they already have an account.*

## Testing

Test both as a new lead and as an existing patient.

**Test as a new lead**

1. Start a new form (use an incognito window or clear cookies).
2. Enter a new email and DOB.
3. Validate you are directed through the form as a new lead.

**Test as an existing patient**

1. Find a patient profile in the Morf dashboard. Confirm the profile has both a DOB and email.
   \[!TIP] It's important this is a **patient** profile, not a lead.
2. Start a new form (use an incognito window or clear cookies).
3. Enter the email and DOB from that patient profile.
4. Validate you are directed through the form as an existing patient.


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