{
  "openapi": "3.1.0",
  "info": {
    "title": "Qualiphy API",
    "version": "1.0.0",
    "description": "Qualiphy telemedicine API for Good Faith Exams, Rx prescriptions (partner pharmacy and custom pharmacy), and exam lifecycle management.\n\nAuthentication: outside `/api/v1/`, every request body MUST include an `api_key` field, and those endpoints take no header-based auth, no query-param auth, and no OAuth. The `api_key` is a JSON property in the POST body, alongside the other fields.\n\nOutside `/api/v1/`, all endpoints are POST with `Content-Type: application/json`.\n\nThe External APIs (every path under `/api/v1/`, tagged External APIs; built for integration partners such as the Quidget middleware) are GET (plus PATCH on `/api/v1/settings/notifications`, with a JSON body), take the same API key only as `Authorization: Bearer YOUR_API_KEY` (a key in the body or query string is rejected with 401), and return real HTTP status codes with a `{success, data}` or `{success: false, error}` body and no `http_code`. Base URL: `https://staging-api.qualiphy.me`."
  },
  "servers": [
    {
      "url": "https://staging-api.qualiphy.me"
    }
  ],
  "tags": [
    { "name": "Exam", "description": "Patient exam invites and lifecycle." },
    { "name": "Pharmacy", "description": "Partner and custom pharmacy discovery." },
    { "name": "External APIs", "description": "Endpoints under /api/v1/, built for integration partners such as the Quidget middleware. They follow their own conventions: GET (Notification Settings also takes PATCH with a JSON body), the API key only as Authorization: Bearer, real HTTP status codes, a {success, data} or {success: false, error} body, and rate limits. The core API's rules (POST, api_key in the JSON body, HTTP 200 with http_code) do not apply to them." },
    { "name": "Webhook", "description": "Inbound webhooks Qualiphy posts to your endpoint." }
  ],
  "paths": {
    "/api/exam_list": {
      "post": {
        "tags": ["Exam"],
        "summary": "List all exams configured on your clinic",
        "description": "Returns every exam configured on your clinic. Use this to discover the `id` values you pass to `/exam_invite`. Each exam record tells you whether it is a GFE or an Rx (`rx_type`), what attachments the patient must upload, and any preset price.",
        "operationId": "examList",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": { "$ref": "#/components/schemas/ApiKeyOnlyRequest" },
              "example": { "api_key": "YOUR_API_KEY" }
            }
          }
        },
        "responses": {
          "200": {
            "description": "List of exams.",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/ExamListResponse" },
                "example": {
                  "clinic_id": 1234,
                  "exams": [
                    {
                      "id": 2228,
                      "title": "Embrace Aging GFE (Dermal Fillers, Botox, PDO, Microneedling PRP)",
                      "rx_type": 1,
                      "price": null,
                      "attachments_required": 1,
                      "attachments": []
                    },
                    {
                      "id": 1822,
                      "title": "Clinical Evaluation for Injectables & Lifting",
                      "rx_type": 1,
                      "price": "27.99",
                      "attachments_required": 1,
                      "attachments": []
                    },
                    {
                      "id": 2769,
                      "title": "3 Month Supply: Semaglutide with Medication Shipping (No Labwork Required)",
                      "rx_type": 2,
                      "price": null,
                      "attachments_required": 2,
                      "attachments": ["ID"]
                    },
                    {
                      "id": 3702,
                      "title": "3 Month Supply: Semaglutide with Medication Shipping (With Lab-work Upload)",
                      "rx_type": 2,
                      "price": null,
                      "attachments_required": 2,
                      "attachments": ["ID", "Lab"]
                    },
                    {
                      "id": 1486,
                      "title": "Urgent Care - Acne (Doxycycline, Clindamycin, Benzoyl Peroxide) Treatment",
                      "rx_type": 2,
                      "price": null,
                      "attachments_required": 2,
                      "attachments": ["ID"]
                    }
                  ]
                }
              }
            }
          }
        }
      }
    },
    "/api/exam_invite": {
      "post": {
        "tags": ["Exam"],
        "summary": "Create a patient exam invite",
        "description": "The core endpoint. Creates a patient exam invite, returns a meeting URL, and (by default) emails and texts the patient. Supports four distinct scenarios via parameter combinations, all hitting this same endpoint:\n\n1. **Good Faith Exam (GFE)** - non-Rx clearance for in-clinic procedures. Pass `exams` + identity fields only. No pharmacy fields. Use a `rx_type: 1` exam from `/exam_list`.\n2. **QualiphyRx Packages** (Partner Pharmacy) - prescription fulfilled through Qualiphy's compounding-pharmacy network with shipping included. Pass `pharmacy_id` (from `/partner_pharmacy_list`) and `order_set_id` (from `/partner_pharmacy_treatment_packages`). Use a `rx_type: 2` exam. Pickup not supported. Webhook events 1, 2, and 3 all fire.\n3. **Urgent Care Visit** - prescription sent to a retail pharmacy for same-day pickup/delivery. Pass `custom_pharmacy: 2`, `ncpdpid`, and the `pharmacy_*` address fields. Webhook events 1 and 2 fire (no event 3 — retail pharmacy handles fulfillment).\n4. **Choose Your Own Pharmacy** - same field set as Urgent Care, used for non-urgent meds. The `ncpdpid` and `pharmacy_*` fields come from `/custom_pharmacy_search`.\n\n**Watch the `custom_pharmacy` mapping**: `2` means custom (retail), `1` means partner. Inverted from how it reads. For test mode, set both `state` and `tele_state` to `TE` and use names like `Test Approve` / `Test Prescription Approve` to steer the test provider's verdict. Two things to know before a test run: the exam you are calling must itself be enabled for the Test state on your account, and test state does not exempt an exam from billing -- the charge fires on approval exactly as a live exam would. The one exception is exam 5359, Qualiphy's dedicated no-charge test exam, which the Good Faith Exam example here uses. The other examples send real exams and are billed. For any other exam, arrange credits with your Qualiphy representative up front.",
        "operationId": "examInvite",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": { "$ref": "#/components/schemas/ExamInviteRequest" },
              "examples": {
                "scenarioGFE": {
                  "summary": "Scenario 1 - Good Faith Exam (non-Rx)",
                  "value": {
                    "api_key": "YOUR_API_KEY",
                    "exams": [5359],
                    "first_name": "Test",
                    "last_name": "Approve",
                    "email": "test@example.com",
                    "dob": "1985-03-12",
                    "phone_number": "+15555550100",
                    "state": "TE",
                    "tele_state": "TE",
                    "webhook_url": "https://yourstore.com/webhooks/qualiphy",
                    "additional_data": "{\"order_id\":\"WC-12847\"}",
                    "redirect_approve": "https://yourstore.com/cleared",
                    "redirect_reject": "https://yourstore.com/needs-followup"
                  }
                },
                "scenarioPartnerPharmacy": {
                  "summary": "Scenario 2 - QualiphyRx Packages (partner pharmacy)",
                  "value": {
                    "api_key": "YOUR_API_KEY",
                    "exams": [1292],
                    "first_name": "Test",
                    "last_name": "Prescription Approve",
                    "email": "test@example.com",
                    "dob": "1982-09-04",
                    "phone_number": "+15555550100",
                    "state": "TE",
                    "tele_state": "TE",
                    "pharmacy_id": 16,
                    "order_set_id": 610,
                    "webhook_url": "https://yourapp.com/webhooks/qualiphy",
                    "additional_data": "{\"subscription_id\":\"SUB-9912\"}"
                  }
                },
                "scenarioMultiRx": {
                  "summary": "Scenario 2b - QualiphyRx Packages, object form (Multi-Rx)",
                  "value": {
                    "api_key": "YOUR_API_KEY",
                    "exams": [
                      { "exam_id": 73, "order_set_ids": [12, 15], "provider_note": "Start at 2.5mg." },
                      { "exam_id": 88, "order_set_ids": [31] }
                    ],
                    "first_name": "Test",
                    "last_name": "Prescription Approve",
                    "email": "test@example.com",
                    "dob": "1990-06-30",
                    "phone_number": "+15555550100",
                    "state": "TE",
                    "tele_state": "TE",
                    "provider_note": "Follow-up from last visit."
                  }
                },
                "scenarioUrgentOrCustom": {
                  "summary": "Scenario 3/4 - Urgent Care or Choose Your Own Pharmacy",
                  "value": {
                    "api_key": "YOUR_API_KEY",
                    "exams": [3104],
                    "first_name": "Test",
                    "last_name": "Prescription Approve",
                    "email": "test@example.com",
                    "dob": "1991-02-18",
                    "phone_number": "+15555550100",
                    "state": "TE",
                    "tele_state": "TE",
                    "custom_pharmacy": 2,
                    "ncpdpid": "1234567",
                    "pharmacy_name": "CVS Pharmacy #5821",
                    "pharmacy_address_line_1": "1500 Main St",
                    "pharmacy_city": "Austin",
                    "pharmacy_state": "TX",
                    "pharmacy_zip_code": "78701",
                    "pharmacy_phone": "+15125550000",
                    "webhook_url": "https://yourapp.com/webhooks/qualiphy"
                  }
                },
                "visitTypeAsync": {
                  "summary": "Ask for an async review (visit_type), in Test mode on the no-charge exam",
                  "value": {
                    "api_key": "YOUR_API_KEY",
                    "exams": [5359],
                    "visit_type": "async",
                    "first_name": "Test",
                    "last_name": "Approve",
                    "email": "test@example.com",
                    "dob": "1985-03-12",
                    "phone_number": "+15555550100",
                    "state": "TE",
                    "tele_state": "TE"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Invite created. `patient_exam_id` is the per-patient instance ID — use it for cancel, resend, submit-answers, attachment upload, and to correlate webhook payloads. `exam_id` is the catalog ID you passed in.",
            "content": {
              "application/json": {
                "schema": { "oneOf": [ { "$ref": "#/components/schemas/ExamInviteResponse" }, { "$ref": "#/components/schemas/ExamInviteResponseMultiRx" } ] },
                "examples": {
                "scenarioGFE": { "summary": "Answer to Scenario 1", "value": {
                    "http_code": 200,
                    "meeting_url": "https://staging-app.qualiphy.me/meeting/...",
                    "meeting_uuid": "abc-123-def-456",
                    "patient_exams": [
                      { "patient_exam_id": 4844, "exam_title": "GFE Aesthetic", "exam_id": 5359 }
                    ]
                  } },
                "scenarioPartnerPharmacy": { "summary": "Answer to Scenario 2", "value": {
                    "http_code": 200,
                    "meeting_url": "https://staging-app.qualiphy.me/meeting/...",
                    "meeting_uuid": "abc-123-def-456",
                    "patient_exams": [
                      { "patient_exam_id": 4844, "exam_title": "GLP-1 Weight Loss", "exam_id": 1292 }
                    ]
                  } },
                "scenarioMultiRx": { "summary": "Answer to Scenario 2b -- the object form answers with `exams`, not `patient_exams`", "value": {
                    "http_code": 200,
                    "meeting_url": "https://staging-app.qualiphy.me/meeting/...",
                    "meeting_uuid": "abc-123-def-456",
                    "exams": [
                      { "index": 0, "exam_id": 73, "patient_exam_id": 4844, "rx_type": 2, "pharmacy_id": 4501, "order_set_ids": [12, 15] },
                      { "index": 1, "exam_id": 88, "patient_exam_id": 4845, "rx_type": 2, "pharmacy_id": 4501, "order_set_ids": [31] }
                    ]
                  } },
                "scenarioUrgentOrCustom": { "summary": "Answer to Scenario 3/4", "value": {
                    "http_code": 200,
                    "meeting_url": "https://staging-app.qualiphy.me/meeting/...",
                    "meeting_uuid": "abc-123-def-456",
                    "patient_exams": [
                      { "patient_exam_id": 4844, "exam_title": "Urgent Care Visit", "exam_id": 3104 }
                    ]
                  } },
                "visitTypeAsync": { "summary": "Answer to the async review request: Test mode (TE) is not a state Compliance sets, so the invite is a video visit", "value": {
                    "http_code": 200,
                    "meeting_url": "https://staging-app.qualiphy.me/meeting/...",
                    "meeting_uuid": "abc-123-def-456",
                    "visit": { "requested": "async", "visit_type": "video", "reason_code": "not_reviewed", "reason": "The patient's state isn't one Compliance sets, so it stays video." },
                    "patient_exams": [
                      { "patient_exam_id": 4844, "exam_title": "GFE Aesthetic", "exam_id": 5359, "visit_type": "video", "reason_code": "not_reviewed" }
                    ]
                  } }
              }
              }
            }
          },
          "400": {
            "description": "Bad request. Typically a missing required field, malformed `dob` (must be YYYY-MM-DD) or `phone_number`, or an invalid `tele_state` (use a two-letter uppercase abbreviation, `DC` for D.C., or `TE` for test mode). The response body specifies which field failed. `Invalid visit type.` means `visit_type` was something other than `async`, `video` or `null`; nothing was created. It arrives with HTTP status 200 and the 400 only in `http_code`: `{ \"http_code\": 400, \"error_message\": \"Invalid visit type.\" }`. Leaving `visit_type` off (or `null`) is not an error: the invite is exactly as today."
          },
          "401": {
            "description": "Unauthorized. Possible response messages and what each means:\n- `Unauthorized access.` - api_key missing or invalid.\n- `Need to add Patient Care Provider via Qualiphy Portal!` - no provider configured for the patient's `tele_state`. Add one in Portal -> Operators.\n- `You need to signed docusign and signed rx` - onboarding agreements incomplete.\n- `Need to sign Prescriptive Services Contract via Qualiphy Portal!` - required before any Rx exam (GFE works without it)."
          },
          "422": {
            "description": "Validation failed and NOTHING was created -- no meeting, no exams -- so the request is safe to correct and retry. Field-validation failures carry an `errors` array; `index` and `exam_id` point at the offending entry and are null for invitation-level problems.\n\nCodes: `MIXED_EXAMS_FORM`, `MIXED_REQUEST_SHAPE` (object form sent with top-level Rx scalars; the detail names them), `PACKAGE_NOT_AVAILABLE` (exam not available to this clinic or state), `DUPLICATE_EXAM`, `DUPLICATE_MED`, `PACKAGE_LIMIT_EXCEEDED` (more than 3 Rx exams), `MED_LIMIT_EXCEEDED` (more than 3 order sets), `NOTE_TOO_LONG`, `INVALID_SKIP_INTAKE` (skip_intake is not a boolean), `ORDER_SETS_ON_NON_RX`, `MED_NOT_IN_PACKAGE` (carries an extra `order_set_id`), `MED_PHARMACY_MISMATCH`, `PHARMACY_UNRESOLVED`, `NO_EXAMS`.\n\nMost are specific to the object form. `MIXED_EXAMS_FORM`, `MED_LIMIT_EXCEEDED` and `NOTE_TOO_LONG` also reach a request sending an ID array. ENG-1823: `invalid_webhook_url` (now) \u2014 the webhook_url could never be a partner endpoint; `webhook_url_not_registered` (after the rollout) \u2014 register it with POST /api/webhook_destination_register or omit it to use the clinic's configured URL. After the rollout an unregistered plain http:// URL that is not the clinic profile URL gets `invalid_webhook_url` instead (registration refuses it, so it must use https://). After the rollout, the clinic profile URL -- supplied as webhook_url, or used because webhook_url is omitted -- is accepted only when it is https:// or the partner registered it through POST /api/webhook_destination_register, and not when its registration was removed (`webhook_url_not_registered`; register it again); a plain http:// profile URL that is NOT registered then refuses the invite with `invalid_webhook_url` (must use https:// or be registered first), even when the invite sends no webhook_url. After the rollout a registry lookup failure answers 503 `webhook_registry_unavailable` (see 503). Webhook-URL rejections use the flat shape `{ http_code, error_code, error_message }` (see the webhook_url_refused example), not errors[], and answer with the real HTTP status 422 (503 for webhook_registry_unavailable). Every other code on this response arrives with HTTP status 200 and the 422 only in http_code.",
            "content": {
              "application/json": {
                "examples": {
                  "validation": {
                    "summary": "Field validation (errors[] shape)",
                    "value": {
                      "http_code": 422,
                      "error_message": "Invitation not created.",
                      "errors": [
                        {
                          "index": 0,
                          "exam_id": 73,
                          "code": "DUPLICATE_EXAM",
                          "detail": "The same exam appears more than once in this invite."
                        }
                      ]
                    }
                  },
                  "webhook_url_refused": {
                    "summary": "ENG-1823 webhook_url refused (flat shape, no errors[])",
                    "value": {
                      "http_code": 422,
                      "error_code": "invalid_webhook_url",
                      "error_message": "webhook_url is invalid: webhook_url must point at a public host"
                    }
                  }
                }
              }
            }
          },
          "503": {
            "description": "ENG-1823, after the rollout only (phase 2 logs and delivers instead): the webhook destination registry could not be read while the invite's webhook URL was checked. NOTHING was created; retry shortly. Flat shape `{ http_code, error_code, error_message }`. Real HTTP status 503, mirrored as http_code.",
            "content": {
              "application/json": {
                "example": {
                  "http_code": 503,
                  "error_code": "webhook_registry_unavailable",
                  "error_message": "The webhook destination registry is temporarily unavailable. Please retry the request shortly."
                }
              }
            }
          }
        }
      }
    },
    "/api/exam_upload_attachment": {
      "post": {
        "tags": ["Exam"],
        "summary": "Upload an attachment to a patient exam",
        "description": "Attach a document to a patient exam (ID photos, lab results, prior records). The provider sees attachments during the screening.\n\n**Spec note:** the public docs section for this endpoint contains only a one-line description and does not enumerate request fields, document a curl example, or show a response shape. The schema below is a best-effort reconstruction (api_key + patient_exam_id + file payload). Before going live, confirm the exact field names (especially how the file is encoded — multipart vs base64 JSON) directly with Qualiphy support; the rest of the API uses `application/json`, so base64 inside JSON is the most likely shape.",
        "operationId": "examUploadAttachment",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": { "$ref": "#/components/schemas/ExamUploadAttachmentRequest" },
              "example": {
                "api_key": "YOUR_API_KEY",
                "patient_exam_id": 4844,
                "file_name": "id-front.jpg",
                "file_type": "ID",
                "file_base64": "<base64-encoded-bytes>"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Attachment received. Response shape is not documented; the example below is a best-effort acknowledgment shape consistent with the other side-effect endpoints (`/exam_invite_resend`, `/exam_submit_answers`).",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/GenericOk" },
                "example": { "http_code": 200, "status": "ok" }
              }
            }
          }
        }
      }
    },
    "/api/exam_questions": {
      "post": {
        "tags": ["Exam"],
        "summary": "Get the screening question schema for an exam",
        "description": "Returns the screening question schema for a given exam ID. Use to build pre-fill UI on your own intake form, or to map your existing intake fields onto the Qualiphy question set.",
        "operationId": "examQuestions",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": { "$ref": "#/components/schemas/ExamQuestionsRequest" },
              "example": {
                "api_key": "YOUR_API_KEY",
                "exam_id": 5359
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Question schema for the requested exam. Note: the public docs do not include a sample response body for this endpoint; the example below mirrors the `{ no, question }` shape used by `/exam_submit_answers` and the webhook `questions_answers` array. Confirm exact fields against a live call.",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/ExamQuestionsResponse" },
                "example": {
                  "exam_id": 5359,
                  "questions": [
                    { "no": 1, "question": "Are you currently taking any medications?" },
                    { "no": 2, "question": "Have you had any reactions to anesthesia?" },
                    { "no": 3, "question": "Are you pregnant or breastfeeding?" }
                  ]
                }
              }
            }
          }
        }
      }
    },
    "/api/exam_submit_answers": {
      "post": {
        "tags": ["Exam"],
        "summary": "Submit answers on behalf of the patient",
        "description": "Submits answers on behalf of the patient. Send both `meeting_uuid` and `patient_exam_id` from the `/exam_invite` response; omitting `meeting_uuid` returns 400 \"Invalid meeting id\". Works for all question types: free-text answers send `answer` only, while single-select and multi-select answers send `exam_question_response_id` (repeat the same `question_id` once per selection for multi-select). Weight is a number of pounds in `answer` (e.g. `\"212\"` or `\"212 lbs\"`); any other weight is stored as sent but does not update the profile. Height may be sent as feet and inches in `answer` (`\"5' 11\\\"\"`, `5'11'`, `5 ft 11 in`, `5'-11\"`, `5' 11 1/2\"`, `5 11`, `5-11`, or feet alone with a unit such as `6 ft`); as feet in `answer` with `height_inches` 0-11 for the inches part (`\"5\"` and `11`); as total inches, in `height_inches` (12 or more, with `answer` empty or the matching feet) or in `answer` (`\"71 in\"`, or a bare `\"71\"` from 24 to 84; send a unit for anything taller); or metric in `answer` (`\"180 cm\"`, `\"1.8 m\"`, or a bare `\"180\"` from 120 to 250, rounded to the nearest inch). Heights from 2' 0\" to 8' 11\" are accepted. Height is stored as `5' 11\"`, and weight and height update the patient profile and BMI. A height that can't be read in any of these forms is not stored; the rest of the request is, and the response is 200 with a `warnings` array of `{ question_id, message }` naming each skipped question. A skipped height leaves that question as it was: a height stored by an earlier call is kept, and the exam can reach a provider with it. If no height was stored before, the question counts as unanswered, so an asynchronous exam stays in `prefill_only_patient_ready` until that height is resubmitted or the patient answers it. An empty `answer` with no `height_inches` (or 0) is stored as sent, with no warning. Pair with `/exam_questions` to pre-fill the screening from your own intake data so patients are not answering the same questions twice. Submit answers for every question to skip the questionnaire entirely.",
        "operationId": "examSubmitAnswers",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": { "$ref": "#/components/schemas/ExamSubmitAnswersRequest" },
              "example": {
                "api_key": "YOUR_API_KEY",
                "meeting_uuid": "MEETING_UUID_FROM_EXAM_INVITE",
                "patient_exam_id": 149784,
                "answers": [
                  { "question_id": 4457, "answer": "No previous complications" },
                  { "question_id": 4458, "answer": "Yes", "exam_question_response_id": 5011, "answer_text": "Occasionally" },
                  { "question_id": 4459, "answer": "Heart issues", "exam_question_response_id": 5013 },
                  { "question_id": 4459, "answer": "Memory Loss", "exam_question_response_id": 5014 },
                  { "question_id": 4460, "answer": "212" },
                  { "question_id": 4461, "answer": "5", "height_inches": 11 }
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Answers accepted: `{ \"http_code\": 200 }`. When a height could not be read, it is not stored, and the response also has `warnings`: an array of `{ question_id, message }`, one per skipped height.",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/ExamSubmitAnswersOk" },
                "examples": {
                  "stored": { "summary": "Every answer stored", "value": { "http_code": 200 } },
                  "height_skipped": {
                    "summary": "A height could not be read and was not stored",
                    "value": { "http_code": 200, "warnings": [ { "question_id": 4461, "message": "Height not stored: couldn't read {\"answer\":\"5\"} as a height. Send e.g. answer 5' 11\", or answer \"5\" with height_inches 11, or height_inches 71." } ] }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/api/exam_invite_resend": {
      "post": {
        "tags": ["Exam"],
        "summary": "Resend invite email and SMS",
        "description": "Re-sends the invite email and SMS to the patient. Use when a patient says they did not receive their original invite.",
        "operationId": "examInviteResend",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": { "$ref": "#/components/schemas/PatientExamIdRequest" },
              "example": {
                "api_key": "YOUR_API_KEY",
                "patient_exam_id": 4844
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Invite resent. Response shape is not documented; the example below is a best-effort acknowledgment.",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/GenericOk" },
                "example": { "http_code": 200, "status": "ok" }
              }
            }
          }
        }
      }
    },
    "/api/exam_invite_cancel": {
      "post": {
        "tags": ["Exam"],
        "summary": "Cancel a patient exam invite",
        "description": "Cancel a previously created patient exam invite. Useful when a patient cancels their order or you need to clean up a duplicate invite. Cancellation is only valid before the provider has acted on the exam. Pass `patient_exam_id` (not `exam_id`).",
        "operationId": "examInviteCancel",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": { "$ref": "#/components/schemas/PatientExamIdRequest" },
              "example": {
                "api_key": "YOUR_API_KEY",
                "patient_exam_id": 4844
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Cancelled.",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/ExamCancelResponse" },
                "example": {
                  "http_code": 200,
                  "patient_exam_id": 55322,
                  "status": "cancelled",
                  "cancelled_at": "2026-04-22T19:08:29.680Z"
                }
              }
            }
          },
          "400": {
            "description": "Cannot cancel. Possible messages: `Exam status is already approved.`, `Exam status is already rejected.`, `Exam status is already Deferred to Medical Director.`. Idempotency: calling cancel twice on a cancelled exam returns 400 with the relevant status — treat as success."
          }
        }
      }
    },
    "/api/patient_exam_status": {
      "post": {
        "tags": ["Exam"],
        "summary": "Read the current status of a patient exam",
        "description": "Where one of your clinic's patient exams has reached in provider review, and the prescription outcome where one applies. Poll this after creating an invite. Authenticates on `api_key` alone; only exams belonging to your clinic are readable.\n\nThe `status` strings are this endpoint's own vocabulary. They are NOT the webhook's `exam_status` values -- see `/api/patient_exam_webhook_payload`.",
        "operationId": "patientExamStatus",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": { "$ref": "#/components/schemas/PatientExamIdRequest" },
              "example": {
                "api_key": "YOUR_API_KEY",
                "patient_exam_id": 1234567
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Current status.",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/PatientExamStatusResponse" },
                "example": {
                  "http_code": 200,
                  "status": "approved"
                }
              }
            }
          },
          "401": {
            "description": "`Unauthorized: api_key did not resolve a clinic` - the `api_key` is wrong, or the clinic is inactive."
          },
          "403": {
            "description": "`Forbidden: patient exam does not belong to this clinic` - the exam exists but belongs to another clinic. You can only read your own clinic's exams."
          },
          "404": {
            "description": "`Patient exam not found.` - no exam exists with that `patient_exam_id`."
          },
          "400": {
            "description": "An unexpected processing error. The body carries the underlying message in `error_message`."
          }
        }
      }
    },
    "/api/patient_exam_status_set": {
      "post": {
        "tags": ["Exam"],
        "summary": "Cancel a patient exam by setting its status",
        "description": "Set the status of one of your clinic's patient exams. Authenticates on `api_key` alone; only exams belonging to your clinic can be modified, and the exam's recorded provider is preserved.\n\nA partner may only cancel its own exam, so `6` is the only accepted `status`. Approving, rejecting and marking n/a are clinical determinations a provider makes, and cannot be set through this endpoint.\n\n**Prefer `/exam_invite_cancel`.** This endpoint has no active-session or terminal guard, so `status: 6` will overwrite an already-approved exam to cancelled; `/exam_invite_cancel` refuses in those cases. Use this one only for exams you know are still pending.",
        "operationId": "patientExamStatusSet",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": { "$ref": "#/components/schemas/PatientExamStatusSetRequest" },
              "example": {
                "api_key": "YOUR_API_KEY",
                "patient_exam_id": 1234567,
                "status": 6
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Status updated.",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/PatientExamStatusSetResponse" },
                "example": {
                  "http_code": 200,
                  "success_message": "Status updated"
                }
              }
            }
          },
          "401": {
            "description": "`Unauthorized: api_key did not resolve a clinic` - the `api_key` is wrong, or the clinic is inactive."
          },
          "403": {
            "description": "Two cases, checked in this order. `Forbidden: patient exam does not belong to this clinic` - the exam exists but is another clinic's. `Forbidden: only 'cancelled' (6) may be set via this endpoint` - the exam is yours, but the requested status is not one a partner may set. Ownership is checked first, so a `patient_exam_id` you do not own never reveals whether that exam exists."
          },
          "400": {
            "description": "An unexpected processing error. The body carries the underlying message in `error_message`."
          }
        }
      }
    },
    "/api/patient_exam_webhook_payload": {
      "post": {
        "tags": ["Exam"],
        "summary": "Rebuild the completion webhook payload for a missed delivery",
        "description": "Returns the same completion webhook JSON (event 1 or 2) Qualiphy would POST to your `webhook_url`, rebuilt from current exam data. Use it when a delivery was missed: the senders never replay a failed delivery, so this is the recovery path. Authenticates on `api_key` alone; only exams belonging to your clinic are readable.\n\nIt does NOT re-send the webhook, and it answers only for exams that already reached a terminal status (`Approved`, `Deferred to Medical Director` or `N/A`). A cancelled or still-pending exam returns 400.\n\n**Two senders, and they diverge at event 2.** This returns the completion sender's payload. Its event-1 fields match `WebhookEvent1ConsultationComplete` one for one, so an event-1 handler written for either works for both. Event 2 is where they part: this sender keys prescriptions as `prescriptions` (plural, a narrow per-drug set) and sends no `prescribed_os_id`, while the `examLifecycleWebhook` schemas describe the result-document sender's singular `prescription` with a much wider field set. Do not generate an event-2 handler for one from the other.\n\nResponses carry PHI: HTTPS only, and do not log bodies in plaintext.",
        "operationId": "patientExamWebhookPayload",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": { "$ref": "#/components/schemas/PatientExamIdRequest" },
              "example": {
                "api_key": "YOUR_API_KEY",
                "patient_exam_id": 1234567
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The completion webhook payload, with `http_code` added. `event` is `1` for an exam with no prescriptions and `2` when `prescriptions[]` is present.",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/CompletionSenderPayload" },
                "examples": {
                  "event1": {
                    "summary": "Event 1 - consultation complete, no prescriptions",
                    "value": {
                      "http_code": 200,
                      "event": 1,
                      "exam_status": "Approved",
                      "rx_status": "",
                      "patient_exam_id": 272,
                      "exam_id": 106,
                      "exam_name": "General Health Check",
                      "exam_url": null,
                      "clinic_id": 1042,
                      "clinic_name": "Downtown Medical Center",
                      "provider_name": "NP Liza",
                      "reason": "Initial consultation complete",
                      "patient_email": "patient@example.com",
                      "patient_phone_number": "5551234567",
                      "additional_data": "{\"order_id\":\"WC-12847\"}",
                      "questions_answers": [
                        { "no": 1, "question": "How are you feeling?", "answer": "Good." }
                      ]
                    }
                  },
                  "event2": {
                    "summary": "Event 2 - the same exam with prescriptions",
                    "value": {
                      "http_code": 200,
                      "event": 2,
                      "exam_status": "Approved",
                      "rx_status": "approved",
                      "patient_exam_id": 149784,
                      "exam_id": 1292,
                      "exam_name": "GLP-1 Weight Loss",
                      "exam_url": null,
                      "clinic_id": 1042,
                      "clinic_name": "Downtown Medical Center",
                      "provider_name": "NP Liza",
                      "reason": "Initial consultation complete",
                      "patient_email": "patient@example.com",
                      "patient_phone_number": "5551234567",
                      "additional_data": null,
                      "questions_answers": [],
                      "prescriptions": [
                        {
                          "prescription_id": 3320,
                          "drug_name": "Semaglutide",
                          "directions": "Inject 0.25mg subcutaneously weekly.",
                          "quantity": 2,
                          "quantity_units": "each",
                          "refill_amount": 2,
                          "prescription_date": "2025-03-19T18:42:27.000Z"
                        }
                      ]
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Two cases. `patient_exam_id is required and must be a positive integer.` - the id was missing or malformed. `Completion webhook payload is not available until the exam reaches a terminal status.` - the exam exists but has not been decided yet, so poll `/api/patient_exam_status` and retry; this is not a bad id. An unexpected processing error answers `Unable to retrieve completion webhook payload.`"
          },
          "401": {
            "description": "`Unauthorized: api_key did not resolve a clinic` - the `api_key` is wrong, or the clinic is inactive."
          },
          "403": {
            "description": "`Forbidden: patient exam does not belong to this clinic` - the exam exists but belongs to another clinic."
          },
          "404": {
            "description": "`Patient exam not found.` - no exam exists with that `patient_exam_id`."
          }
        }
      }
    },
    "/api/partner_pharmacy_list": {
      "post": {
        "tags": ["Pharmacy"],
        "summary": "List partner compounding pharmacies",
        "description": "Lists the partner compounding pharmacies that can fulfill the given Rx exam(s) for a patient in the given state. Returns each pharmacy's `pharmacy_id`, which you pass into `/exam_invite` and `/partner_pharmacy_treatment_packages`.\n\n**Gotcha**: omitting `exam_ids` returns 400 with `\"Cannot convert undefined or null to object\"`. An empty-array response usually means no partner pharmacy / order sets are attached to those exams yet, or the `patient_state` isn't covered.",
        "operationId": "partnerPharmacyList",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": { "$ref": "#/components/schemas/PartnerPharmacyListRequest" },
              "example": { "api_key": "YOUR_API_KEY", "exam_ids": [4279], "patient_state": "NY" }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Partner pharmacies available for the given exams and state.",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/PartnerPharmacyListResponse" },
                "example": [
                  { "pharmacy_id": 16, "pharmacy_name": "Greenwich Pharmacy" }
                ]
              }
            }
          }
        }
      }
    },
    "/api/partner_pharmacy_treatment_packages": {
      "post": {
        "tags": ["Pharmacy"],
        "summary": "List treatment packages for partner pharmacies",
        "description": "Lists treatment packages (drug + dosage combinations + pricing) available at the given partner pharmacies for the given Rx exam(s). Returns `order_set_id` values for use with `/exam_invite`. Legacy `exam_pos_id` is still returned for older integrations.\n\n**Gotcha**: the parameter is `pharmacy_ids` (plural) — passing `pharmacy_id` returns an empty array, not an error. An empty array with correct parameters means no order sets are attached to those exams for those pharmacies yet.",
        "operationId": "partnerPharmacyTreatmentPackages",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": { "$ref": "#/components/schemas/PartnerPharmacyPackagesRequest" },
              "example": {
                "api_key": "YOUR_API_KEY",
                "pharmacy_ids": [16],
                "exam_ids": [4279],
                "patient_state": "NY"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Treatment packages.",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/PartnerPharmacyPackagesResponse" },
                "example": [
                  {
                    "exam_pos_id": 27708,
                    "order_set_id": 610,
                    "title": "Semaglutide + B12 + Zofran (add-on) - Injection - Dose 1: 0.25mg/weekly - 1mg/05mg Total - 30 Days Supply",
                    "pharmacy_id": 16,
                    "turnaround_time": "3-4",
                    "pharmacy_name": "Greenwich Pharmacy",
                    "integration_partner": 8,
                    "qualiphy_total_price": "125.00"
                  }
                ]
              }
            }
          }
        }
      }
    },
    "/api/v1/pharmacies": {
      "get": {
        "tags": ["External APIs"],
        "summary": "List every pharmacy your clinic can route to, with the states each ships to",
        "description": "Returns every pharmacy your clinic can route to in one call, each with `states` (two-letter codes where an invite will succeed for at least one of your exams).\n\n**Canonical name:** `pharmacy_name` is the canonical pharmacy name across the v1 API; `/api/v1/packages` returns the same value for the same `pharmacy_id`.\n\n**Active:** `active` is always `true` today; it is there so a future on/off switch does not change the format.\n\n**Auth:** `Authorization: Bearer YOUR_API_KEY` only; a key in the query string or body is rejected with 401.\n\n**Polling:** send the last `ETag` as `If-None-Match` on every poll; 304 means nothing changed.\n\n**Rate limit:** 120 requests per minute per clinic, per server worker, separate from /api/v1/packages, /api/v1/locations and /api/v1/settings/notifications; plus 60 failed authentications (401s) per minute per IP, per server worker, shared with them and checked before the key is. Every response carries `X-RateLimit-Limit`, `X-RateLimit-Remaining`, `X-RateLimit-Reset`, and 429 carries `Retry-After`. A pharmacy missing from an unfiltered response (no `state`, no `active`) has been removed.",
        "operationId": "listPharmaciesV1",
        "security": [{ "ClinicApiKeyBearer": [] }],
        "parameters": [
          { "name": "state", "in": "query", "required": false, "description": "Two-letter state code; only pharmacies that ship there.", "schema": { "type": "string" }, "example": "TX" },
          { "name": "active", "in": "query", "required": false, "description": "true or false; omit for every pharmacy.", "schema": { "type": "string", "enum": ["true", "false"] } },
          { "name": "If-None-Match", "in": "header", "required": false, "description": "The ETag from your last response.", "schema": { "type": "string" } }
        ],
        "responses": {
          "200": {
            "description": "The pharmacies your clinic can route to.",
            "headers": { "ETag": { "description": "Send it back as If-None-Match on the next poll.", "schema": { "type": "string" } }, "X-RateLimit-Limit": { "$ref": "#/components/headers/PharmaciesV1RateLimitLimit" }, "X-RateLimit-Remaining": { "$ref": "#/components/headers/PharmaciesV1RateLimitRemaining" }, "X-RateLimit-Reset": { "$ref": "#/components/headers/PharmaciesV1RateLimitReset" } },
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/PharmaciesV1Response" },
                "example": {
                  "success": true,
                  "data": {
                    "environment": "production",
                    "count": 1,
                    "pharmacies": [
                      {
                        "pharmacy_id": 6,
                        "pharmacy_name": "Example Pharmacy",
                        "active": true,
                        "states": ["CA", "NY", "TX"],
                        "integration_partner": 1
                      }
                    ]
                  }
                }
              }
            }
          },
          "304": { "description": "Not modified: If-None-Match matched the current ETag. Empty body.", "headers": { "ETag": { "schema": { "type": "string" } }, "X-RateLimit-Limit": { "$ref": "#/components/headers/PharmaciesV1RateLimitLimit" }, "X-RateLimit-Remaining": { "$ref": "#/components/headers/PharmaciesV1RateLimitRemaining" }, "X-RateLimit-Reset": { "$ref": "#/components/headers/PharmaciesV1RateLimitReset" } } },
          "400": { "description": "Invalid query parameters.", "headers": { "X-RateLimit-Limit": { "$ref": "#/components/headers/PharmaciesV1RateLimitLimit" }, "X-RateLimit-Remaining": { "$ref": "#/components/headers/PharmaciesV1RateLimitRemaining" }, "X-RateLimit-Reset": { "$ref": "#/components/headers/PharmaciesV1RateLimitReset" } }, "content": { "application/json": { "schema": { "$ref": "#/components/schemas/PackagesV1Error" } } } },
          "401": { "description": "Missing or invalid API key, or a key sent in the query string or body.", "headers": { "X-RateLimit-Limit": { "$ref": "#/components/headers/PharmaciesV1RateLimitLimit" }, "X-RateLimit-Remaining": { "$ref": "#/components/headers/PharmaciesV1RateLimitRemaining" }, "X-RateLimit-Reset": { "$ref": "#/components/headers/PharmaciesV1RateLimitReset" } }, "content": { "application/json": { "schema": { "$ref": "#/components/schemas/PackagesV1Error" } } } },
          "429": { "description": "Rate limited; retry after Retry-After seconds. Two budgets, both per server worker: 120 requests per minute per clinic (separate from /api/v1/packages, /api/v1/locations and /api/v1/settings/notifications), and 60 failed authentications (401s) per minute per IP (shared by every /api/v1/ endpoint).", "headers": { "Retry-After": { "description": "Seconds to wait before retrying.", "schema": { "type": "integer" } }, "X-RateLimit-Limit": { "$ref": "#/components/headers/PharmaciesV1RateLimitLimit" }, "X-RateLimit-Remaining": { "$ref": "#/components/headers/PharmaciesV1RateLimitRemaining" }, "X-RateLimit-Reset": { "$ref": "#/components/headers/PharmaciesV1RateLimitReset" } }, "content": { "application/json": { "schema": { "$ref": "#/components/schemas/PackagesV1Error" } } } },
          "500": { "description": "Unexpected server error; the error body carries a correlation_id to quote to support.", "headers": { "X-RateLimit-Limit": { "$ref": "#/components/headers/PharmaciesV1RateLimitLimit" }, "X-RateLimit-Remaining": { "$ref": "#/components/headers/PharmaciesV1RateLimitRemaining" }, "X-RateLimit-Reset": { "$ref": "#/components/headers/PharmaciesV1RateLimitReset" } }, "content": { "application/json": { "schema": { "$ref": "#/components/schemas/PackagesV1Error" } } } }
        }
      }
    },
    "/api/v1/packages": {
      "get": {
        "tags": ["External APIs"],
        "summary": "List every package for up to 20 exams, with the states each is available in",
        "description": "Returns every treatment package for the given exams in one call, each with `states` (two-letter codes where an invite will succeed: the pharmacy serves the state and the exam is offered there). No patient state is needed.\n\n**Auth:** `Authorization: Bearer YOUR_API_KEY` only; a key in the query string or body is rejected with 401.\n\n**Stable key:** `(exam_id, pharmacy_id, order_set_id)`. `exam_pos_id` and `exam_version_id` change when an exam is re-versioned.\n\n**Polling:** send the last `ETag` as `If-None-Match` on every poll; 304 means nothing changed.\n\n**Rate limit:** 120 requests per minute per clinic, per server worker, shared by /api/v1/packages, /api/v1/locations and /api/v1/settings/notifications, plus 60 failed authentications (401s) per minute per IP, shared by every /api/v1/ endpoint; every response carries `X-RateLimit-Limit`, `X-RateLimit-Remaining`, `X-RateLimit-Reset`, and 429 carries `Retry-After`. At most 20 exam ids per call. Treat a missing package as removed only with `availability=all`.",
        "operationId": "listPackagesV1",
        "security": [{ "ClinicApiKeyBearer": [] }],
        "parameters": [
          { "name": "exam_id", "in": "query", "required": true, "description": "Comma-separated exam ids from /exam_list, at most 20.", "schema": { "type": "string" }, "example": "12345,67890" },
          { "name": "pharmacy_id", "in": "query", "required": false, "description": "Only packages from this pharmacy.", "schema": { "type": "integer" } },
          { "name": "state", "in": "query", "required": false, "description": "Two-letter state code; only packages an invite will succeed for in that state.", "schema": { "type": "string" }, "example": "NY" },
          { "name": "availability", "in": "query", "required": false, "description": "active (default) or all; all includes inactive packages marked inactive.", "schema": { "type": "string", "enum": ["active", "all"], "default": "active" } },
          { "name": "cursor", "in": "query", "required": false, "description": "next_cursor from the previous page.", "schema": { "type": "string" } },
          { "name": "limit", "in": "query", "required": false, "description": "Packages per page.", "schema": { "type": "integer", "default": 200, "minimum": 1, "maximum": 1000 } },
          { "name": "If-None-Match", "in": "header", "required": false, "description": "The ETag from your last response.", "schema": { "type": "string" } }
        ],
        "responses": {
          "200": {
            "description": "Packages for the visible exams.",
            "headers": { "ETag": { "description": "Send it back as If-None-Match on the next poll.", "schema": { "type": "string" } }, "X-RateLimit-Limit": { "description": "Requests allowed per window, per clinic, per server worker.", "schema": { "type": "integer" } }, "X-RateLimit-Remaining": { "description": "Requests left in the current window.", "schema": { "type": "integer" } }, "X-RateLimit-Reset": { "description": "When the window resets (epoch seconds).", "schema": { "type": "integer" } } },
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/PackagesV1Response" },
                "example": {
                  "success": true,
                  "data": {
                    "environment": "production",
                    "count": 1,
                    "next_cursor": null,
                    "exam_ids_not_found": [],
                    "packages": [
                      {
                        "exam_id": 12345,
                        "exam_version_id": 67890,
                        "exam_pos_id": 1234,
                        "order_set_id": 55,
                        "pharmacy_id": 6,
                        "pharmacy_name": "Example Pharmacy",
                        "integration_partner": 1,
                        "title": "Package Title",
                        "consult_price": "45.00",
                        "medication_price": "125.50",
                        "total_price": "170.50",
                        "currency": "USD",
                        "states": ["CA", "NY", "TX"],
                        "availability": "active",
                        "updated_at": "2026-09-01T12:00:00.000Z"
                      }
                    ]
                  }
                }
              }
            }
          },
          "304": { "description": "Not modified: If-None-Match matched the current ETag. Empty body.", "headers": { "ETag": { "schema": { "type": "string" } }, "X-RateLimit-Limit": { "description": "Requests allowed per window, per clinic, per server worker.", "schema": { "type": "integer" } }, "X-RateLimit-Remaining": { "description": "Requests left in the current window.", "schema": { "type": "integer" } }, "X-RateLimit-Reset": { "description": "When the window resets (epoch seconds).", "schema": { "type": "integer" } } } },
          "400": { "description": "Invalid query parameters.", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/PackagesV1Error" } } } },
          "401": { "description": "Missing or invalid API key, or a key sent in the query string or body.", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/PackagesV1Error" } } } },
          "429": { "description": "Rate limit exceeded; retry after Retry-After seconds. The per-clinic budget is shared by /api/v1/packages, /api/v1/locations and /api/v1/settings/notifications; the failed-authentication budget by every /api/v1/ endpoint.", "headers": { "Retry-After": { "description": "Seconds to wait before retrying.", "schema": { "type": "integer" } }, "X-RateLimit-Limit": { "description": "Requests allowed per window, per clinic, per server worker.", "schema": { "type": "integer" } }, "X-RateLimit-Remaining": { "description": "Requests left in the current window.", "schema": { "type": "integer" } }, "X-RateLimit-Reset": { "description": "When the window resets (epoch seconds).", "schema": { "type": "integer" } } }, "content": { "application/json": { "schema": { "$ref": "#/components/schemas/PackagesV1Error" } } } },
          "500": { "description": "Unexpected server error; the error body carries a correlation_id to quote to support.", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/PackagesV1Error" } } } }
        }
      }
    },
    "/api/v1/locations": {
      "get": {
        "tags": ["External APIs"],
        "summary": "List your active locations (same account and organization as the key) with their ids",
        "description": "Returns the active locations under the same account and organization as the location whose API key you send, including that location itself. Each location is a clinic: its `id` is the same value as `clinic_id` in /api/exam_list and in webhooks. Ids and names only: no address, status or API key.\n\n**Auth:** `Authorization: Bearer YOUR_API_KEY` only; a key in the query string or body is rejected with 401.\n\n**Paging:** default 200 locations per page, maximum 1000. Pass `next_cursor` back as `cursor`; it is null on the last page.",
        "operationId": "listLocationsV1",
        "security": [{ "ClinicApiKeyBearer": [] }],
        "parameters": [
          { "name": "cursor", "in": "query", "required": false, "description": "next_cursor from the previous page.", "schema": { "type": "string" } },
          { "name": "limit", "in": "query", "required": false, "description": "Locations per page.", "schema": { "type": "integer", "default": 200, "minimum": 1, "maximum": 1000 } }
        ],
        "responses": {
          "200": {
            "description": "Your locations.",
            "headers": { "X-RateLimit-Limit": { "$ref": "#/components/headers/LocationsV1RateLimitLimit" }, "X-RateLimit-Remaining": { "$ref": "#/components/headers/LocationsV1RateLimitRemaining" }, "X-RateLimit-Reset": { "$ref": "#/components/headers/LocationsV1RateLimitReset" } },
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/LocationsV1Response" },
                "example": {
                  "success": true,
                  "data": {
                    "environment": "production",
                    "count": 2,
                    "next_cursor": null,
                    "locations": [
                      { "id": 1201, "name": "Main Street Clinic" },
                      { "id": 1202, "name": "Downtown Clinic" }
                    ]
                  }
                }
              }
            }
          },
          "400": { "description": "Malformed cursor or limit.", "headers": { "X-RateLimit-Limit": { "$ref": "#/components/headers/LocationsV1RateLimitLimit" }, "X-RateLimit-Remaining": { "$ref": "#/components/headers/LocationsV1RateLimitRemaining" }, "X-RateLimit-Reset": { "$ref": "#/components/headers/LocationsV1RateLimitReset" } }, "content": { "application/json": { "schema": { "$ref": "#/components/schemas/PackagesV1Error" } } } },
          "401": { "description": "Missing or invalid API key, or a key sent in the query string or body.", "headers": { "X-RateLimit-Limit": { "$ref": "#/components/headers/LocationsV1RateLimitLimit" }, "X-RateLimit-Remaining": { "$ref": "#/components/headers/LocationsV1RateLimitRemaining" }, "X-RateLimit-Reset": { "$ref": "#/components/headers/LocationsV1RateLimitReset" } }, "content": { "application/json": { "schema": { "$ref": "#/components/schemas/PackagesV1Error" } } } },
          "429": { "description": "Rate limited; retry after Retry-After seconds. Two budgets, both per server worker: 120 requests per minute per clinic, shared by /api/v1/packages, /api/v1/locations and /api/v1/settings/notifications, and 60 failed authentications (401s) per minute per IP, shared by every /api/v1/ endpoint. The failed-authentication budget is checked before the key, so once an IP passes it every request from that IP gets 429 until the window resets, valid keys included.", "headers": { "Retry-After": { "description": "Seconds to wait before retrying.", "schema": { "type": "integer" } }, "X-RateLimit-Limit": { "$ref": "#/components/headers/LocationsV1RateLimitLimit" }, "X-RateLimit-Remaining": { "$ref": "#/components/headers/LocationsV1RateLimitRemaining" }, "X-RateLimit-Reset": { "$ref": "#/components/headers/LocationsV1RateLimitReset" } }, "content": { "application/json": { "schema": { "$ref": "#/components/schemas/PackagesV1Error" } } } },
          "500": { "description": "Unexpected server error; the error body carries a correlation_id to quote to support.", "headers": { "X-RateLimit-Limit": { "$ref": "#/components/headers/LocationsV1RateLimitLimit" }, "X-RateLimit-Remaining": { "$ref": "#/components/headers/LocationsV1RateLimitRemaining" }, "X-RateLimit-Reset": { "$ref": "#/components/headers/LocationsV1RateLimitReset" } }, "content": { "application/json": { "schema": { "$ref": "#/components/schemas/PackagesV1Error" } } } }
        }
      }
    },
    "/api/v1/locations/{location_id}": {
      "get": {
        "tags": ["External APIs"],
        "summary": "Read one of your locations",
        "description": "Returns one location that GET /api/v1/locations would return for your API key. A location on another account returns the same 404 as one that does not exist.\n\n**Auth:** `Authorization: Bearer YOUR_API_KEY` only; a key in the query string or body is rejected with 401.",
        "operationId": "getLocationV1",
        "security": [{ "ClinicApiKeyBearer": [] }],
        "parameters": [
          { "name": "location_id", "in": "path", "required": true, "description": "A location id from GET /api/v1/locations.", "schema": { "type": "integer", "minimum": 1 }, "example": 1202 }
        ],
        "responses": {
          "200": {
            "description": "The location.",
            "headers": { "X-RateLimit-Limit": { "$ref": "#/components/headers/LocationsV1RateLimitLimit" }, "X-RateLimit-Remaining": { "$ref": "#/components/headers/LocationsV1RateLimitRemaining" }, "X-RateLimit-Reset": { "$ref": "#/components/headers/LocationsV1RateLimitReset" } },
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/LocationV1Response" },
                "example": { "success": true, "data": { "environment": "production", "location": { "id": 1202, "name": "Downtown Clinic" } } }
              }
            }
          },
          "400": { "description": "location_id is not a positive integer.", "headers": { "X-RateLimit-Limit": { "$ref": "#/components/headers/LocationsV1RateLimitLimit" }, "X-RateLimit-Remaining": { "$ref": "#/components/headers/LocationsV1RateLimitRemaining" }, "X-RateLimit-Reset": { "$ref": "#/components/headers/LocationsV1RateLimitReset" } }, "content": { "application/json": { "schema": { "$ref": "#/components/schemas/PackagesV1Error" } } } },
          "401": { "description": "Missing or invalid API key, or a key sent in the query string or body.", "headers": { "X-RateLimit-Limit": { "$ref": "#/components/headers/LocationsV1RateLimitLimit" }, "X-RateLimit-Remaining": { "$ref": "#/components/headers/LocationsV1RateLimitRemaining" }, "X-RateLimit-Reset": { "$ref": "#/components/headers/LocationsV1RateLimitReset" } }, "content": { "application/json": { "schema": { "$ref": "#/components/schemas/PackagesV1Error" } } } },
          "404": { "description": "No such location among yours.", "headers": { "X-RateLimit-Limit": { "$ref": "#/components/headers/LocationsV1RateLimitLimit" }, "X-RateLimit-Remaining": { "$ref": "#/components/headers/LocationsV1RateLimitRemaining" }, "X-RateLimit-Reset": { "$ref": "#/components/headers/LocationsV1RateLimitReset" } }, "content": { "application/json": { "schema": { "$ref": "#/components/schemas/PackagesV1Error" } } } },
          "429": { "description": "Rate limited; retry after Retry-After seconds. Two budgets, both per server worker: 120 requests per minute per clinic, shared by /api/v1/packages, /api/v1/locations and /api/v1/settings/notifications, and 60 failed authentications (401s) per minute per IP, shared by every /api/v1/ endpoint. The failed-authentication budget is checked before the key, so once an IP passes it every request from that IP gets 429 until the window resets, valid keys included.", "headers": { "Retry-After": { "description": "Seconds to wait before retrying.", "schema": { "type": "integer" } }, "X-RateLimit-Limit": { "$ref": "#/components/headers/LocationsV1RateLimitLimit" }, "X-RateLimit-Remaining": { "$ref": "#/components/headers/LocationsV1RateLimitRemaining" }, "X-RateLimit-Reset": { "$ref": "#/components/headers/LocationsV1RateLimitReset" } }, "content": { "application/json": { "schema": { "$ref": "#/components/schemas/PackagesV1Error" } } } },
          "500": { "description": "Unexpected server error; the error body carries a correlation_id to quote to support.", "headers": { "X-RateLimit-Limit": { "$ref": "#/components/headers/LocationsV1RateLimitLimit" }, "X-RateLimit-Remaining": { "$ref": "#/components/headers/LocationsV1RateLimitRemaining" }, "X-RateLimit-Reset": { "$ref": "#/components/headers/LocationsV1RateLimitReset" } }, "content": { "application/json": { "schema": { "$ref": "#/components/schemas/PackagesV1Error" } } } }
        }
      }
    },
    "/api/v1/settings/notifications": {
      "get": {
        "tags": ["External APIs"],
        "summary": "Read whether Qualiphy sends your patients exam invitation emails and text messages",
        "description": "Returns your location's setting for Qualiphy's exam invitation emails (`email`) and text messages (`sms`) to your patients. A location that has never changed the setting reads back true for both.\n\n**Scope:** the setting applies only to the location (clinic) whose API key you send. Other locations on your account keep their own setting.\n\n**What it controls:** Qualiphy's exam invitation emails and text messages to your patients, including invitation resends. Follow-up exam emails and texts always send, whatever this setting says: they carry information patients need after their exam. The text that tells a waiting patient a provider is now available also sends whatever this setting says, unless the exam has text messages turned off.\n\nIt is the same setting Qualiphy support can change for you; changes made either way show here.\n\n**Auth:** `Authorization: Bearer YOUR_API_KEY` only; a key in the query string or body is rejected with 401.",
        "operationId": "getNotificationSettingsV1",
        "security": [{ "ClinicApiKeyBearer": [] }],
        "responses": {
          "200": {
            "description": "The location's notification setting.",
            "headers": { "X-RateLimit-Limit": { "$ref": "#/components/headers/LocationsV1RateLimitLimit" }, "X-RateLimit-Remaining": { "$ref": "#/components/headers/LocationsV1RateLimitRemaining" }, "X-RateLimit-Reset": { "$ref": "#/components/headers/LocationsV1RateLimitReset" } },
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/NotificationSettingsV1Response" },
                "example": { "success": true, "data": { "environment": "production", "notifications": { "email": true, "sms": true } } }
              }
            }
          },
          "401": { "description": "Missing or invalid API key, or a key sent in the query string or body.", "headers": { "X-RateLimit-Limit": { "$ref": "#/components/headers/LocationsV1RateLimitLimit" }, "X-RateLimit-Remaining": { "$ref": "#/components/headers/LocationsV1RateLimitRemaining" }, "X-RateLimit-Reset": { "$ref": "#/components/headers/LocationsV1RateLimitReset" } }, "content": { "application/json": { "schema": { "$ref": "#/components/schemas/PackagesV1Error" } } } },
          "429": { "description": "Rate limited; retry after Retry-After seconds. Two budgets, both per server worker: 120 requests per minute per clinic, shared by /api/v1/packages, /api/v1/locations and /api/v1/settings/notifications, and 60 failed authentications (401s) per minute per IP, shared by every /api/v1/ endpoint. The failed-authentication budget is checked before the key, so once an IP passes it every request from that IP gets 429 until the window resets, valid keys included.", "headers": { "Retry-After": { "description": "Seconds to wait before retrying.", "schema": { "type": "integer" } }, "X-RateLimit-Limit": { "$ref": "#/components/headers/LocationsV1RateLimitLimit" }, "X-RateLimit-Remaining": { "$ref": "#/components/headers/LocationsV1RateLimitRemaining" }, "X-RateLimit-Reset": { "$ref": "#/components/headers/LocationsV1RateLimitReset" } }, "content": { "application/json": { "schema": { "$ref": "#/components/schemas/PackagesV1Error" } } } },
          "500": { "description": "Unexpected server error; the error body carries a correlation_id to quote to support.", "headers": { "X-RateLimit-Limit": { "$ref": "#/components/headers/LocationsV1RateLimitLimit" }, "X-RateLimit-Remaining": { "$ref": "#/components/headers/LocationsV1RateLimitRemaining" }, "X-RateLimit-Reset": { "$ref": "#/components/headers/LocationsV1RateLimitReset" } }, "content": { "application/json": { "schema": { "$ref": "#/components/schemas/PackagesV1Error" } } } }
        }
      },
      "patch": {
        "tags": ["External APIs"],
        "summary": "Turn Qualiphy's exam invitation emails or text messages to your patients on or off",
        "description": "Turns Qualiphy's exam invitation emails or text messages to your patients on or off. Send `email`, `sms` or both, each a JSON boolean; any other field (for example `admin_email`) is rejected with 400, not ignored. Returns the setting after the change.\n\n**Scope:** the setting applies only to the location (clinic) whose API key you send. Other locations on your account keep their own setting.\n\n**What it controls:** Qualiphy's exam invitation emails and text messages to your patients, including invitation resends. Follow-up exam emails and texts always send, whatever this setting says: they carry information patients need after their exam. The text that tells a waiting patient a provider is now available also sends whatever this setting says, unless the exam has text messages turned off.\n\n**Administrator notice:** turning patient email off sends a notice to the administrator email address on file for the location. This endpoint cannot change that address. If there is no address on file, the call fails with 422 `admin_email_missing`; if the notice cannot be sent, it fails with 503 `notice_failed`. Either way nothing was changed.\n\nEvery change made through this endpoint is recorded in an audit log. It is the same setting Qualiphy support can change for you; changes made either way show here.\n\n**Auth:** `Authorization: Bearer YOUR_API_KEY` only; a key in the query string or body is rejected with 401.",
        "operationId": "updateNotificationSettingsV1",
        "security": [{ "ClinicApiKeyBearer": [] }],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": { "$ref": "#/components/schemas/NotificationSettingsV1Update" },
              "example": { "sms": false }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The location's notification setting after the change.",
            "headers": { "X-RateLimit-Limit": { "$ref": "#/components/headers/LocationsV1RateLimitLimit" }, "X-RateLimit-Remaining": { "$ref": "#/components/headers/LocationsV1RateLimitRemaining" }, "X-RateLimit-Reset": { "$ref": "#/components/headers/LocationsV1RateLimitReset" } },
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/NotificationSettingsV1Response" },
                "example": { "success": true, "data": { "environment": "production", "notifications": { "email": true, "sms": false } } }
              }
            }
          },
          "400": { "description": "invalid_request: the body is not a JSON object, has no fields, has a value that is not a JSON boolean, or has a field other than email and sms. Each problem is listed in field_errors. An api_key in the body is a 401, not a 400 (see Authentication).", "headers": { "X-RateLimit-Limit": { "$ref": "#/components/headers/LocationsV1RateLimitLimit" }, "X-RateLimit-Remaining": { "$ref": "#/components/headers/LocationsV1RateLimitRemaining" }, "X-RateLimit-Reset": { "$ref": "#/components/headers/LocationsV1RateLimitReset" } }, "content": { "application/json": { "schema": { "$ref": "#/components/schemas/PackagesV1Error" } } } },
          "401": { "description": "Missing or invalid API key, or a key sent in the query string or body.", "headers": { "X-RateLimit-Limit": { "$ref": "#/components/headers/LocationsV1RateLimitLimit" }, "X-RateLimit-Remaining": { "$ref": "#/components/headers/LocationsV1RateLimitRemaining" }, "X-RateLimit-Reset": { "$ref": "#/components/headers/LocationsV1RateLimitReset" } }, "content": { "application/json": { "schema": { "$ref": "#/components/schemas/PackagesV1Error" } } } },
          "409": { "description": "conflict: the setting changed while your request was running. Nothing was changed; retry.", "headers": { "X-RateLimit-Limit": { "$ref": "#/components/headers/LocationsV1RateLimitLimit" }, "X-RateLimit-Remaining": { "$ref": "#/components/headers/LocationsV1RateLimitRemaining" }, "X-RateLimit-Reset": { "$ref": "#/components/headers/LocationsV1RateLimitReset" } }, "content": { "application/json": { "schema": { "$ref": "#/components/schemas/PackagesV1Error" } } } },
          "422": { "description": "channel_required: a channel you asked to turn off cannot be turned off for your clinic; field_errors[].message gives the reason (no channel is restricted today). admin_email_missing: turning email off needs an administrator email address on file for the location, and there is none. Nothing was changed.", "headers": { "X-RateLimit-Limit": { "$ref": "#/components/headers/LocationsV1RateLimitLimit" }, "X-RateLimit-Remaining": { "$ref": "#/components/headers/LocationsV1RateLimitRemaining" }, "X-RateLimit-Reset": { "$ref": "#/components/headers/LocationsV1RateLimitReset" } }, "content": { "application/json": { "schema": { "$ref": "#/components/schemas/PackagesV1Error" } } } },
          "429": { "description": "Rate limited; retry after Retry-After seconds. Two budgets, both per server worker: 120 requests per minute per clinic, shared by /api/v1/packages, /api/v1/locations and /api/v1/settings/notifications, and 60 failed authentications (401s) per minute per IP, shared by every /api/v1/ endpoint. The failed-authentication budget is checked before the key, so once an IP passes it every request from that IP gets 429 until the window resets, valid keys included.", "headers": { "Retry-After": { "description": "Seconds to wait before retrying.", "schema": { "type": "integer" } }, "X-RateLimit-Limit": { "$ref": "#/components/headers/LocationsV1RateLimitLimit" }, "X-RateLimit-Remaining": { "$ref": "#/components/headers/LocationsV1RateLimitRemaining" }, "X-RateLimit-Reset": { "$ref": "#/components/headers/LocationsV1RateLimitReset" } }, "content": { "application/json": { "schema": { "$ref": "#/components/schemas/PackagesV1Error" } } } },
          "500": { "description": "Unexpected server error; the error body carries a correlation_id to quote to support.", "headers": { "X-RateLimit-Limit": { "$ref": "#/components/headers/LocationsV1RateLimitLimit" }, "X-RateLimit-Remaining": { "$ref": "#/components/headers/LocationsV1RateLimitRemaining" }, "X-RateLimit-Reset": { "$ref": "#/components/headers/LocationsV1RateLimitReset" } }, "content": { "application/json": { "schema": { "$ref": "#/components/schemas/PackagesV1Error" } } } },
          "503": { "description": "notice_failed: turning email off sends a notice to your administrator email address, and that notice could not be sent. Nothing was changed; retry.", "headers": { "X-RateLimit-Limit": { "$ref": "#/components/headers/LocationsV1RateLimitLimit" }, "X-RateLimit-Remaining": { "$ref": "#/components/headers/LocationsV1RateLimitRemaining" }, "X-RateLimit-Reset": { "$ref": "#/components/headers/LocationsV1RateLimitReset" } }, "content": { "application/json": { "schema": { "$ref": "#/components/schemas/PackagesV1Error" } } } }
        }
      }
    },
    "/api/custom_pharmacy_search": {
      "post": {
        "tags": ["Pharmacy"],
        "summary": "Search any U.S. pharmacy",
        "description": "Look up any U.S. pharmacy by name, location, or NCPDPID. Returns full address and identifier fields needed for `/exam_invite` when using custom pharmacy routing.",
        "operationId": "customPharmacySearch",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": { "$ref": "#/components/schemas/CustomPharmacySearchRequest" },
              "example": {
                "api_key": "YOUR_API_KEY",
                "search": "CVS",
                "zip_code": "10001"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Matching pharmacies.",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/CustomPharmacySearchResponse" },
                "example": {
                  "pharmacies": [
                    {
                      "ncpdpid": "3318547",
                      "name": "CVS Pharmacy #4382",
                      "address_line_1": "342 W 23rd St",
                      "city": "New York",
                      "state": "NY",
                      "zip_code": "10011",
                      "phone": "2127757582"
                    }
                  ]
                }
              }
            }
          }
        }
      }
    },
    "/api/webhook_destination_register": {
      "post": {
        "tags": [
          "Webhook"
        ],
        "summary": "Register a webhook destination and receive its signing secret",
        "operationId": "webhookDestinationRegister",
        "description": "ENG-1823. Register a URL as a destination for your clinic's exam webhooks. Every delivery to a registered destination carries X-Qualiphy-Signature (v1= + hex HMAC-SHA256 over `<timestamp>.<raw body>`, keyed with signing_secret) and X-Qualiphy-Timestamp (Unix seconds). The clinic profile's https URL is registered for you; a plain http profile URL is not, and may be registered here (the one case where http is accepted). Idempotent: re-registering an existing URL answers 200 without the secret unless rotate_secret is true, or the secret has never been handed out (URLs registered for you at rollout). At most 10 active destinations per clinic. Registering a URL that was removed reactivates it with a NEW signing_secret, returned once: HTTP 200, created: false, reactivated: true. The old secret is never revived. Changing the clinic's webhook URL in the portal deregisters the old profile URL only if it was registered for you (at rollout or on its first delivery) and you never collected its secret; a URL you registered yourself, or whose secret you collected, stays registered.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/WebhookDestinationRegisterRequest"
              },
              "example": {
                "api_key": "YOUR_API_KEY",
                "webhook_url": "https://store2.example.com/qualiphy/webhook"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Already registered: no signing_secret unless rotate_secret was sent, or it is the first time a pre-registered URL's secret is handed out. Also the answer to re-registering a removed URL (created: false, reactivated: true, with a NEW signing_secret, returned once). HTTP status 200, mirrored as http_code.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/WebhookDestinationRegisterResponse"
                },
                "example": {
                  "http_code": 200,
                  "created": false,
                  "reactivated": false,
                  "destination": {
                    "id": 9,
                    "webhook_url": "https://store2.example.com/qualiphy/webhook",
                    "is_clinic_default": false,
                    "signing_secret_hint": "\u2026b21c",
                    "created_at": "2026-10-02 14:58:21"
                  },
                  "message": "Already registered. Send rotate_secret: true to issue a new signing secret."
                }
              }
            }
          },
          "201": {
            "description": "Created. `destination.signing_secret` is present and shown ONCE. HTTP status 201, mirrored as http_code.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/WebhookDestinationRegisterResponse"
                },
                "example": {
                  "http_code": 201,
                  "created": true,
                  "reactivated": false,
                  "destination": {
                    "id": 9,
                    "webhook_url": "https://store2.example.com/qualiphy/webhook",
                    "is_clinic_default": false,
                    "signing_secret_hint": "\u2026b21c",
                    "created_at": "2026-10-02 14:58:21",
                    "signing_secret": "<64 hex characters>"
                  },
                  "message": "Store signing_secret now; it is not shown again. Send rotate_secret: true to issue a new one."
                }
              }
            }
          },
          "401": {
            "description": "`Unauthorized access.` \u2014 api_key missing or invalid. Answered by the API-key check every endpoint shares, which replies **HTTP 200** with body `{ \"http_code\": 401, \"error_message\": \"Unauthorized access.\" }` (no error_code), so read `http_code`, not the status. A key that passes that check but resolves to no clinic gets a real HTTP 401 with the same body. Every other error on this endpoint carries `http_code`, `error_code` and `error_message`, with the HTTP status mirroring `http_code`."
          },
          "422": {
            "description": "`invalid_webhook_url` \u2014 not https, not a public host, embedded credentials, longer than 500 characters, or a NEW plain-http destination; `too_many_webhook_destinations` \u2014 the clinic already has 10 active destinations. HTTP status 422, mirrored as `http_code`, with `error_code` and `error_message`."
          },
          "409": {
            "description": "`registration_conflict` \u2014 a concurrent registration of the same URL was undone (it would have exceeded the 10-destination cap). Nothing was issued; retry the request. HTTP status 409, mirrored as `http_code`, with `error_code` and `error_message`."
          },
          "429": {
            "description": "`rate_limited` \u2014 too many registration calls in the window; slow down."
          }
        }
      }
    },
    "/api/webhook_destination_list": {
      "post": {
        "tags": [
          "Webhook"
        ],
        "summary": "List the clinic's active webhook destinations",
        "operationId": "webhookDestinationList",
        "description": "ENG-1823. Full secrets are never listed; signing_secret_hint is the last four characters.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "api_key"
                ],
                "properties": {
                  "api_key": {
                    "type": "string"
                  }
                }
              },
              "example": {
                "api_key": "YOUR_API_KEY"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/WebhookDestinationListResponse"
                },
                "example": {
                  "http_code": 200,
                  "clinic_webhook_url": "https://partner.example.com/qualiphy/webhook",
                  "destinations": [
                    {
                      "id": 1,
                      "webhook_url": "https://partner.example.com/qualiphy/webhook",
                      "is_clinic_default": true,
                      "signing_secret_hint": "\u20263f9a",
                      "created_at": "2026-09-30 09:12:00"
                    },
                    {
                      "id": 9,
                      "webhook_url": "https://store2.example.com/qualiphy/webhook",
                      "is_clinic_default": false,
                      "signing_secret_hint": "\u2026b21c",
                      "created_at": "2026-10-02 14:58:21"
                    }
                  ]
                }
              }
            }
          },
          "401": {
            "description": "`Unauthorized access.` \u2014 api_key missing or invalid. Answered by the API-key check every endpoint shares, which replies **HTTP 200** with body `{ \"http_code\": 401, \"error_message\": \"Unauthorized access.\" }` (no error_code), so read `http_code`, not the status. A key that passes that check but resolves to no clinic gets a real HTTP 401 with the same body. Every other error on this endpoint carries `http_code`, `error_code` and `error_message`, with the HTTP status mirroring `http_code`."
          },
          "429": {
            "description": "`rate_limited` \u2014 too many calls in the window; slow down."
          }
        }
      }
    },
    "/api/webhook_destination_remove": {
      "post": {
        "tags": [
          "Webhook"
        ],
        "summary": "Remove a webhook destination",
        "operationId": "webhookDestinationRemove",
        "description": "ENG-1823. Deactivates a destination. The clinic's configured URL cannot be removed here (409 destination_is_clinic_default): change it in the portal first. Registering a removed URL again reactivates it with a NEW signing_secret, returned once (HTTP 200, created: false, reactivated: true); the old secret is never revived. Error bodies: 404 destination_not_found, 422 invalid_destination_id.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/WebhookDestinationRemoveRequest"
              },
              "example": {
                "api_key": "YOUR_API_KEY",
                "destination_id": 9
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Removed.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/WebhookDestinationRemoveResponse"
                },
                "example": {
                  "http_code": 200,
                  "removed": true,
                  "destination_id": 9
                }
              }
            }
          },
          "401": {
            "description": "`Unauthorized access.` \u2014 api_key missing or invalid. Answered by the API-key check every endpoint shares, which replies **HTTP 200** with body `{ \"http_code\": 401, \"error_message\": \"Unauthorized access.\" }` (no error_code), so read `http_code`, not the status. A key that passes that check but resolves to no clinic gets a real HTTP 401 with the same body. Every other error on this endpoint carries `http_code`, `error_code` and `error_message`, with the HTTP status mirroring `http_code`."
          },
          "404": {
            "description": "`destination_not_found` \u2014 no active destination with that id for this clinic: already removed, mistyped, or another clinic's. Not proof of removal; confirm with /webhook_destination_list that the URL is gone."
          },
          "409": {
            "description": "`destination_is_clinic_default` \u2014 the URL is the clinic's configured webhook URL; change it in the portal first."
          },
          "422": {
            "description": "`invalid_destination_id` \u2014 destination_id must be a positive integer."
          },
          "429": {
            "description": "`rate_limited` \u2014 too many calls in the window; slow down."
          }
        }
      }
    }
  },
  "webhooks": {
    "examLifecycleWebhook": {
      "post": {
        "parameters": [
          {
            "name": "X-Qualiphy-Timestamp",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Send time in Unix seconds. Present on every delivery to a registered destination. Reject deliveries more than 300 seconds from your clock."
          },
          {
            "name": "X-Qualiphy-Signature",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string",
              "pattern": "^v1=[0-9a-f]{64}$"
            },
            "description": "v1= + hex HMAC-SHA256 over `<X-Qualiphy-Timestamp>.<raw request body>`, keyed with the destination's signing_secret (POST /api/webhook_destination_register). Hash the raw bytes received; compare in constant time. Absent on deliveries to a URL you have not registered."
          }
        ],
        "tags": ["Webhook"],
        "summary": "Inbound webhook from Qualiphy",
        "description": "Qualiphy POSTs lifecycle events to the `webhook_url` you supplied to `/exam_invite`. Always dispatch on the `event` integer \u2014 treating the webhook as a single payload type is the most common integration mistake:\n- `1` = Consultation Complete. Fires for every exam (GFE, Rx, Urgent Care) when the provider finishes the consultation. Carries the verdict in `exam_status` (Approved, Deferred to Medical Director, N/A -- and, from environments that predate ENG-101 (production today), the lower-case enum keys approved, rejected, na. Compare case-insensitively and treat rejected as Deferred to Medical Director) and the screening Q&A.\n- `2` = Prescription Confirmed. Fires only for Rx exams, after event 1, when the treatment order is written and confirmed at the pharmacy. Carries the full `prescription[]` array.\n- `3` = Prescription Tracking. Fires only for **partner-pharmacy** Rx shipments when the package ships. Custom-pharmacy / urgent-care exams do NOT receive event 3 \u2014 the retail pharmacy is the source of truth for fulfillment.\n\nRespond 200 immediately (under 100ms) and process asynchronously. Treat `patient_exam_id` as the idempotency key. ENG-1823: deliveries to a REGISTERED destination (POST /api/webhook_destination_register) carry X-Qualiphy-Signature and X-Qualiphy-Timestamp; verify them before trusting the body. For a URL you have not registered, deliveries are unsigned during the rollout: IP-allowlist if possible and ensure HTTPS. The common pattern there is a secret token embedded in the webhook URL and validated on receipt; keep that token to letters, numbers and dashes, because a token containing `&` or `#` is truncated wherever the URL is handled unencoded and delivery silently stops.\n\n**Where the URL comes from.** The `webhook_url` on each `/exam_invite` call is the primary method and needs no portal access. A clinic-level URL saved in the portal acts as an account-level default, used when an invite arrives without one. When both are set the invite wins, so keep them identical or use only the invite value \u2014 a stale invite URL against a newer portal value produces deliveries that arrive but fail the receiver's token check, which reads like an outage on our side. The clinic-level URL is also the only way to receive events for exams created by hand in the portal, since those have no invite to carry a URL.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": { "$ref": "#/components/schemas/WebhookEvent" },
              "examples": {
                "event1Approved": {
                  "summary": "Event 1 - Consultation Complete (Approved)",
                  "value": {
                    "event": 1,
                    "reason": "Initial consultation complete",
                    "exam_id": 106,
                    "exam_url": "https://d29tu1ox8kfrdk.cloudfront.net/pdfs/...",
                    "exam_name": "General Health Check",
                    "exam_status": "Approved",
                    "rx_status": "",
                    "clinic_id": 1042,
                    "clinic_name": "Downtown Medical Center",
                    "patient_email": "patient@example.com",
                    "patient_phone_number": "5551234567",
                    "patient_exam_id": 272,
                    "provider_name": "NP Liza",
                    "additional_data": "{\"order_id\":\"WC-12847\"}",
                    "questions_answers": [
                      { "no": 1, "question": "How are you feeling?", "answer": "Good." }
                    ]
                  }
                },
                "event2Prescription": {
                  "summary": "Event 2 - Prescription Confirmed",
                  "value": {
                    "event": 2,
                    "exam_id": 1292,
                    "exam_name": "GLP-1 Weight Loss",
                    "exam_status": "Approved",
                    "exam_url": "https://d29tu1ox8kfrdk.cloudfront.net/pdfs/...",
                    "rx_status": "Pharmacy Confirmed",
                    "clinic_id": 1042,
                    "clinic_name": "Downtown Medical Center",
                    "patient_email": "patient@example.com",
                    "patient_phone_number": "5551234567",
                    "patient_exam_id": 149784,
                    "provider_name": "NP Liza",
                    "prescribed_os_id": 486,
                    "prescription": [
                      {
                        "prescription_id": 3320,
                        "drug_name": "Semaglutide",
                        "dosage_form_type": "Inj",
                        "strength": "2mg",
                        "size": "2mL",
                        "quantity": "2",
                        "quantity_units": "",
                        "directions": "Inject 0.25mg subcutaneously weekly.",
                        "duration_days": 30,
                        "refill_amount": 2,
                        "ndc_number": "",
                        "gpi_number": "",
                        "schedule_code": "",
                        "active_ingredient": "",
                        "inactive_ingredient": "",
                        "pharmacy_name": "Choose Your Pharmacy",
                        "pharmacy_contacts": [
                          { "full_name": null, "email": null, "phone_number": null, "role": null }
                        ],
                        "prescription_tracking": [
                          { "rx_number": null, "tracking_number": null, "ship_carrier": null, "delivery_service": null, "pharmacy_location": null }
                        ],
                        "created_at": "2025-03-19T18:42:27.000Z"
                      }
                    ],
                    "questions_answers": [
                      { "no": 1, "question": "How are you feeling?", "answer": "Good." }
                    ]
                  }
                },
                "event3Tracking": {
                  "summary": "Event 3 - Prescription Tracking",
                  "value": {
                    "event": 3,
                    "clinic_id": 4188,
                    "patient_exam_id": "patient-exam-789",
                    "prescription_id": "12345",
                    "tracking_number": "123ABC456DEF",
                    "delivery_service": "Overnight",
                    "pharmacy_location": "Main Street Location",
                    "order_id": "1234567890"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Acknowledge receipt. Respond 200 fast; process the payload asynchronously."
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "ClinicApiKeyBearer": { "type": "http", "scheme": "bearer", "description": "Your clinic API key as a Bearer token (GET /api/v1/packages, GET /api/v1/pharmacies, GET /api/v1/locations, GET and PATCH /api/v1/settings/notifications)." }
    },
    "headers": {
      "LocationsV1RateLimitLimit": { "description": "Requests allowed per window. On authenticated responses: the per-clinic budget, 120 per minute per clinic, per server worker. On a 401 or a failed-authentication 429: the failed-authentication budget, 60 per minute per IP, per server worker. The per-clinic budget is shared by /api/v1/packages, /api/v1/locations and /api/v1/settings/notifications; the failed-authentication budget is shared by every /api/v1/ endpoint.", "schema": { "type": "integer" } },
      "LocationsV1RateLimitRemaining": { "description": "Requests left in the current window of the budget X-RateLimit-Limit reports.", "schema": { "type": "integer" } },
      "LocationsV1RateLimitReset": { "description": "When that window resets (epoch seconds).", "schema": { "type": "integer" } },
      "PharmaciesV1RateLimitLimit": { "description": "Requests allowed per window. On authenticated responses: this endpoint's per-clinic budget, 120 per minute per clinic, per server worker, separate from /api/v1/packages, /api/v1/locations and /api/v1/settings/notifications. On a 401 or a failed-authentication 429: the failed-authentication budget, 60 per minute per IP, per server worker, shared with them.", "schema": { "type": "integer" } },
      "PharmaciesV1RateLimitRemaining": { "description": "Requests left in the current window of the budget X-RateLimit-Limit reports.", "schema": { "type": "integer" } },
      "PharmaciesV1RateLimitReset": { "description": "When that window resets (epoch seconds).", "schema": { "type": "integer" } }
    },
    "schemas": {
      "PharmaciesV1Pharmacy": {
        "type": "object",
        "properties": {
          "pharmacy_id": { "type": "integer" },
          "pharmacy_name": { "type": ["string", "null"], "description": "Canonical pharmacy name across the v1 API; null if none is recorded." },
          "active": { "type": "boolean", "description": "Always true today; kept so a future on/off switch does not change the format." },
          "states": { "type": "array", "items": { "type": "string" } },
          "integration_partner": { "type": ["integer", "null"] }
        }
      },
      "PharmaciesV1Response": {
        "type": "object",
        "properties": {
          "success": { "type": "boolean" },
          "data": {
            "type": "object",
            "properties": {
              "environment": { "type": "string" },
              "count": { "type": "integer" },
              "pharmacies": { "type": "array", "items": { "$ref": "#/components/schemas/PharmaciesV1Pharmacy" } }
            }
          }
        }
      },
      "PackagesV1Package": {
        "type": "object",
        "properties": {
          "exam_id": { "type": "integer", "description": "The requested exam id (stable)." },
          "exam_version_id": { "type": "integer", "description": "Current exam version; changes on re-version." },
          "exam_pos_id": { "type": "integer", "description": "Package id for exam_invite; changes on re-version." },
          "order_set_id": { "type": "integer" },
          "pharmacy_id": { "type": "integer" },
          "pharmacy_name": { "type": ["string", "null"], "description": "Canonical pharmacy name, the same as in /api/v1/pharmacies; null if none is recorded." },
          "integration_partner": { "type": ["integer", "null"] },
          "title": { "type": ["string", "null"] },
          "consult_price": { "type": "string", "description": "USD, 2 decimals." },
          "medication_price": { "type": "string", "description": "USD, 2 decimals." },
          "total_price": { "type": "string", "description": "consult_price + medication_price; equals qualiphy_total_price." },
          "currency": { "type": "string", "enum": ["USD"] },
          "states": { "type": "array", "items": { "type": "string" } },
          "availability": { "type": "string", "enum": ["active", "inactive"] },
          "updated_at": { "type": ["string", "null"], "format": "date-time" }
        }
      },
      "PackagesV1Response": {
        "type": "object",
        "properties": {
          "success": { "type": "boolean" },
          "data": {
            "type": "object",
            "properties": {
              "environment": { "type": "string" },
              "count": { "type": "integer" },
              "next_cursor": { "type": ["string", "null"] },
              "exam_ids_not_found": { "type": "array", "items": { "type": "integer" } },
              "packages": { "type": "array", "items": { "$ref": "#/components/schemas/PackagesV1Package" } }
            }
          }
        }
      },
      "PackagesV1Error": {
        "type": "object",
        "properties": {
          "success": { "type": "boolean", "enum": [false] },
          "error": {
            "type": "object",
            "properties": {
              "code": { "type": "string" },
              "message": { "type": "string" },
              "field_errors": { "type": "array", "items": { "type": "object", "properties": { "field": { "type": "string" }, "message": { "type": "string" } } } },
              "correlation_id": { "type": "string" }
            }
          }
        }
      },
      "LocationV1": {
        "type": "object",
        "properties": {
          "id": { "type": "integer", "description": "The location id." },
          "name": { "type": ["string", "null"] }
        }
      },
      "LocationsV1Response": {
        "type": "object",
        "properties": {
          "success": { "type": "boolean" },
          "data": {
            "type": "object",
            "properties": {
              "environment": { "type": "string" },
              "count": { "type": "integer" },
              "next_cursor": { "type": ["string", "null"] },
              "locations": { "type": "array", "items": { "$ref": "#/components/schemas/LocationV1" } }
            }
          }
        }
      },
      "LocationV1Response": {
        "type": "object",
        "properties": {
          "success": { "type": "boolean" },
          "data": {
            "type": "object",
            "properties": {
              "environment": { "type": "string" },
              "location": { "$ref": "#/components/schemas/LocationV1" }
            }
          }
        }
      },
      "NotificationSettingsV1": {
        "type": "object",
        "properties": {
          "email": { "type": "boolean", "description": "Your location's setting for exam invitation emails: true is on, false is off." },
          "sms": { "type": "boolean", "description": "Your location's setting for exam invitation text messages: true is on, false is off." }
        }
      },
      "NotificationSettingsV1Response": {
        "type": "object",
        "properties": {
          "success": { "type": "boolean" },
          "data": {
            "type": "object",
            "properties": {
              "environment": { "type": "string" },
              "notifications": { "$ref": "#/components/schemas/NotificationSettingsV1" }
            }
          }
        }
      },
      "NotificationSettingsV1Update": {
        "type": "object",
        "minProperties": 1,
        "additionalProperties": false,
        "description": "At least one of email and sms. Any other field is rejected with 400 invalid_request.",
        "properties": {
          "email": { "type": "boolean", "description": "Your location's setting for exam invitation emails: true turns it on, false turns it off. Turning it off sends a notice to the administrator email address on file for the location." },
          "sms": { "type": "boolean", "description": "Your location's setting for exam invitation text messages: true turns it on, false turns it off." }
        }
      },
      "ApiKeyOnlyRequest": {
        "type": "object",
        "required": ["api_key"],
        "properties": {
          "api_key": { "type": "string", "description": "Your location's API key." }
        }
      },
      "PatientExamIdRequest": {
        "type": "object",
        "required": ["api_key", "patient_exam_id"],
        "properties": {
          "api_key": { "type": "string" },
          "patient_exam_id": { "type": "integer", "description": "From the `patient_exams[]` array in the original `/exam_invite` response. Not the `exam_id`." }
        }
      },
      "Exam": {
        "type": "object",
        "properties": {
          "id": { "type": "integer", "description": "Exam ID. Pass this to `/exam_invite` in the `exams` array." },
          "title": { "type": "string", "description": "Human-readable exam name as configured in the Qualiphy portal." },
          "rx_type": { "type": "integer", "description": "1 = non-Rx (GFE). 2 = Rx (covers QualiphyRx Packages, Urgent Care, and Choose-Your-Own-Pharmacy — there is no separate \"urgent\" rx_type; distinguish those by `title`)." },
          "price": { "type": ["string", "null"], "description": "Preset price as a decimal string (e.g. \"27.99\") when one is configured, otherwise null." },
          "attachments_required": { "type": "integer", "description": "Number of files the patient must upload before the consultation. Always at least 1. (Note: the docs glossary treats this as an inverted flag — 1=not required, 2=required — while the endpoint param table describes it as a count. Treat the value as a count of required files; if you see 1 with an empty `attachments` array, only the standard ID upload is required.)" },
          "attachments": { "type": "array", "items": { "type": "string" }, "description": "Names of required attachments beyond the default ID upload, e.g. `[\"ID\"]`, `[\"ID\", \"Lab\"]`, or `[\"Picture of hair loss area\"]`. Empty array means only the standard ID is required." }
        }
      },
      "ExamListResponse": {
        "type": "object",
        "properties": {
          "clinic_id": { "type": "integer" },
          "exams": { "type": "array", "items": { "$ref": "#/components/schemas/Exam" } }
        }
      },
      "ExamInviteRequest": {
        "type": "object",
        "required": [
          "api_key",
          "exams",
          "first_name",
          "last_name",
          "email",
          "dob",
          "phone_number",
          "tele_state"
        ],
        "description": "The `/exam_invite` request body. Required fields are the same across all scenarios; the optional fields vary:\n- **GFE** (rx_type 1 exam): identity fields only, no pharmacy fields.\n- **Partner Pharmacy**: add `pharmacy_id` and (optionally) `order_set_id`.\n- **Urgent Care / Custom Pharmacy**: add `custom_pharmacy: 2`, `ncpdpid`, and the `pharmacy_*` address fields.\n- **Preselected fixed pharmacy (no patient step)**: on Choose-Your-Pharmacy exams, send `pharmacy_id` + `order_set_id` + `ncpdpid` + the `pharmacy_*` fields + `custom_pharmacy_patient_choice: 1` + `skip_pharmacy_confirmation: 2`, and no `custom_pharmacy` at all: you are supplying the destination outright and removing the patient's pharmacy step, so the flag has nothing left to decide. These exams offer both routings, so it would not be rejected either -- it simply has no effect worth relying on.\nWARNING: an Rx invite with no pharmacy destination at all is accepted (200) but the prescription strands at prescribe time with nowhere to transmit - always include the destination if you route fulfillment yourself.\nFor test mode, set both `state` and `tele_state` to `TE`.",
        "properties": {
          "api_key": { "type": "string", "description": "Your location's API key." },
          "exams": { "description": "The exams to run. Two shapes are accepted and they cannot be mixed -- a mixed array returns 422 MIXED_EXAMS_FORM. Stack non-Rx exams freely. The ID array carries at most one Rx exam; more than one Rx exam requires the object form. That form is available to any partner and sets per-exam options, including skip_intake. A partner pharmacy uses it for up to 3 Rx exams and their order sets.", "oneOf": [ { "type": "array", "minItems": 1, "description": "Exam IDs from `/exam_list`.", "items": { "type": "integer" } }, { "type": "array", "minItems": 1, "description": "Per-exam options, including skip_intake. Any partner can use this shape. order_set_ids is the partner-pharmacy field.", "items": { "type": "object", "required": ["exam_id"], "properties": { "exam_id": { "type": "integer", "description": "The same static ID the ID array takes." }, "order_set_ids": { "type": "array", "items": { "type": "integer" }, "description": "Up to 3 order sets for this exam. Rx exams only." }, "provider_note": { "type": "string", "description": "Note stored against this exam. Max 500 characters. Separate from the invite-level provider_note." }, "skip_intake": { "type": "boolean", "default": false, "description": "Set true when you already collected the patient's intake: this exam's pre-fill questionnaire is not offered and the patient goes from consent to the waiting room. Per exam, object form only. A skip_intake key at the top of the request, or beside a list of exam IDs, is ignored and the questionnaire is still offered. Must be a boolean; any other value returns 422 INVALID_SKIP_INTAKE and nothing is created, including on an asynchronous exam where a real boolean is otherwise ignored. That 422 is HTTP 200 with http_code 422 and an errors[] entry carrying this exam's index and exam_id. A boolean true has no effect on an asynchronous exam. Answers already submitted with `/exam_submit_answers` still reach the provider." } } } } ] },

          "order_set_ids": { "type": "array", "items": { "type": "integer" }, "description": "Request-level order sets, for the ID array shape. Max 3; more returns 422 MED_LIMIT_EXCEEDED with index null. Must not be sent with the object form, which takes order_set_ids per entry." },
          "first_name": { "type": "string", "description": "Patient first name. In test mode, use `Test` plus an outcome keyword (`Approve`, `Reject`, `N/A`, `Prescription Approve`, `Prescription Reject`) — the test provider reads the name to decide how to process the exam." },
          "last_name": { "type": "string", "description": "Patient last name." },
          "email": { "type": "string", "description": "Patient email. Used for invite delivery and as the patient identifier." },
          "dob": { "type": "string", "description": "Date of birth as YYYY-MM-DD.", "example": "1990-06-30" },
          "phone_number": { "type": "string", "description": "Patient phone. Two formats accepted: `+15552223232` or `1234567890`." },
          "tele_state": { "type": "string", "description": "Two-letter UPPERCASE state abbreviation of the **patient** (not your clinic). Determines provider matching and is the most common source of integration bugs. Use `DC` for Washington D.C., or `TE` for test mode." },
          "webhook_url": { "type": "string", "description": "Where to POST the lifecycle webhook events. Highly recommended \u2014 without it, you have no way to know when the exam completes. Applies to this exam only. A clinic-level URL can also be saved in the portal (Clinics > three-dot menu on the clinic > Edit, a view that sits on the clinic owner account) and is used when an invite arrives without a webhook_url. When both are set, the value on the invite wins \u2014 keep them identical or send only this one. ENG-1823: register the URL first (POST /api/webhook_destination_register) to receive signed deliveries (X-Qualiphy-Signature / X-Qualiphy-Timestamp). A URL that is not parseable, embeds credentials, uses a non-http scheme or points at a private, loopback or cloud-metadata host is refused with http_code 422 / error_code invalid_webhook_url. An unregistered URL is logged and still delivered to during the rollout; afterwards it is refused with 422 / webhook_url_not_registered (a plain http:// URL that is not the clinic profile URL with 422 / invalid_webhook_url, since it must use https://). After the rollout, the clinic profile URL -- supplied here or used because this field is omitted -- is accepted only when it is https:// or you registered it, and not when its registration was removed (422 / webhook_url_not_registered; register it again); a plain http:// profile URL you have not registered then refuses the invite with 422 / invalid_webhook_url (must use https:// or be registered first). After the rollout a registry lookup failure answers 503 / webhook_registry_unavailable (nothing created; retry shortly)." },
          "provider_note": { "type": "string", "maxLength": 500, "description": "A note for the provider, carried with the consultation. This one applies to the WHOLE invitation and is stored on the meeting; longer than 500 characters returns `422 NOTE_TOO_LONG`. Accepted with both shapes of `exams`. Separate from the per-exam `provider_note` inside the object form, which is stored against that exam." },
          "additional_data": { "type": "string", "description": "Stringified JSON. Returned unchanged in the webhook payload. Use it to round-trip your internal IDs (order ID, subscription ID, etc.). One reserved key: if this JSON has a `provider` key naming an EMR handled by Qualiphy's integration hub (for example `zenoti`), the partner webhook for that exam is SUPPRESSED and the result is delivered through that integration instead. Do not use `provider` for your own data." },
          "redirect_approve": { "type": "string", "description": "URL the patient is sent to after an Approved verdict." },
          "redirect_reject": { "type": "string", "description": "URL the patient is sent to when the provider declines and escalates (the `Deferred to Medical Director` outcome)." },
          "redirect_na": { "type": "string", "description": "URL the patient is sent to on an `N/A` outcome -- no decision was possible." },
          "redirect_missed": { "type": "string", "description": "URL the patient is sent to when no provider becomes available. Fires after a 3-minute timeout; this is a patient-flow redirect, not a webhook `exam_status` value." },
          "gender": { "type": "integer", "description": "Integer, not string. 1=Male, 2=Female, 3=Prefer not to say." },
          "dmv_license_number": { "type": "string", "description": "Patient's DMV license number for ID verification." },
          "address_line_1": { "type": "string", "description": "Patient's home address line 1." },
          "address_line_2": { "type": "string", "description": "Patient's home address line 2." },
          "city": { "type": "string", "description": "Patient's home address city." },
          "state": { "type": "string", "description": "Patient's home **address** state (two-letter abbreviation). Conceptually different from `tele_state`, which drives provider matching — they are often the same value. Set to `TE` for test mode (along with `tele_state`)." },
          "zip_code": { "type": "string", "description": "Patient's home ZIP." },
          "shipping_address_line_1": { "type": "string", "description": "Where to ship Rx treatments. Different from home address when shipping to clinic, P.O. box, or alternate location." },
          "shipping_address_line_2": { "type": "string" },
          "shipping_city": { "type": "string" },
          "shipping_state": { "type": "string" },
          "shipping_zip_code": { "type": "string" },
          "pharmacy_id": { "type": "integer", "description": "Partner pharmacy ID from `/partner_pharmacy_list`. Used for the QualiphyRx Packages (Partner Pharmacy) scenario." },
          "order_set_id": { "type": "integer", "description": "Preselect a specific drug + dosage package from `/partner_pharmacy_treatment_packages`. Optional even on partner-pharmacy invites; omit to let the provider choose." },
          "exam_pos_id": { "type": "integer", "description": "Legacy fallback for `order_set_id`, still accepted for older integrations. It identifies an exam/pharmacy/order-set pairing rather than the order set itself, so its value differs from `order_set_id` on the same package. Prefer `order_set_id` for new work." },
          "custom_pharmacy": { "type": "integer", "description": "Inverted from how it reads. 2=Custom Pharmacy (retail like CVS, Walgreens). 1=Partner Pharmacy (Qualiphy's compounding network), following the platform's internal 1=false / 2=true convention. Used to flag the Urgent Care / Choose Your Own Pharmacy scenarios. Must match the exam's configured routing: a custom-only exam rejects 1 with 401 \"Only custom pharmacies available for this exam!\", and a partner-only exam rejects 2 with 401 \"Only partner pharmacies available for this exam!\". Where only one kind is available the server selects it, so the flag decides nothing unless the exam offers both. To preselect a retail destination without the flag, use ncpdpid + custom_pharmacy_patient_choice: 1 instead." },
          "ncpdpid": { "type": "string", "description": "Custom pharmacy's NCPDPID from `/custom_pharmacy_search`. Required when `custom_pharmacy: 2`. Saved on the exam record as the e-Rx (SureScripts) destination; a pass-through value — no registration or allowlisting of the pharmacy is needed on Qualiphy's side — and it can accompany `pharmacy_id` + `order_set_id` on Choose-Your-Pharmacy exams." },
          "pharmacy_name": { "type": "string", "description": "Custom pharmacy name. Used with `custom_pharmacy: 2`." },
          "pharmacy_address_line_1": { "type": "string", "description": "Custom pharmacy street address line 1." },
          "pharmacy_address_line_2": { "type": "string", "description": "Custom pharmacy street address line 2." },
          "pharmacy_city": { "type": "string", "description": "Custom pharmacy city." },
          "pharmacy_state": { "type": "string", "description": "Custom pharmacy state (two-letter)." },
          "pharmacy_zip_code": { "type": "string", "description": "Custom pharmacy ZIP." },
          "pharmacy_phone": { "type": "string", "description": "Custom pharmacy phone." },
          "pharmacy_type": { "type": "string", "description": "Custom pharmacy type label, when applicable." },
          "provider_pos_selection": { "type": "integer", "description": "\"POS\" = Pharmacy / Order Set. 1=Provider does not choose (you've fully specified both). 2=Provider picks order set only (you specified pharmacy). 3=Provider picks both pharmacy and order set (most flexible)." },
          "custom_pharmacy_patient_choice": { "type": "integer", "description": "1=Custom pharmacy is preselected by you in this request. 2=Patient picks their own custom pharmacy during the meeting. If omitted, defaults to 2 even when an ncpdpid was supplied — the patient still gets a pharmacy step and their pick overrides the preset destination. For fully automatic routing with no patient step, always send 1 (requires ncpdpid)." },
          "skip_pharmacy_confirmation": { "type": "integer", "description": "1=Show pharmacy confirmation screen. 2=Skip it. Only actually skips when all pharmacy fields are present in the payload." },
          "visit_type": { "type": ["string", "null"], "enum": ["async", "video", null], "description": "Ask for an asynchronous review (`async`) or a video visit (`video`) of the exams on this invite. Your existing ASYNC exams run as async whatever you send (`not_in_conversion`), even when another exam on the invite has to be a video visit. Leave it off (or null) and the invite is exactly as today. Where the rules (your clinic's async rollout, the exam, the patient's state) don't allow async, the invite is still created, as a video visit, and the response's `visit` says why. The partner sets the visit type; the patient can't switch it. An async review is charged at the exam's own price, less any async discount Qualiphy has set up for your account on that exam; a video visit is the exam's usual price. Any other value returns HTTP 200 with http_code 400 `Invalid visit type.` and nothing is created." },
          "custom_pharmacy_patient_billing": { "type": "integer", "description": "1=Clinic is billed by the pharmacy. 2=Patient is billed." },
          "custom_pharmacy_clinic_billing": { "type": "string", "description": "Clinic identifier for pharmacy billing. Required when `custom_pharmacy_patient_billing: 1`." },
          "custom_pharmacy_delivery_method": { "type": "integer", "description": "1=Patient picks up at pharmacy. 2=Ship to patient or clinic." }
        }
      },
      "ExamInviteResponseMultiRx": {
        "type": "object",
        "required": ["exams"],
        "description": "The object form's answer. Keyed `exams`, not `patient_exams`.",
        "properties": {
          "http_code": { "type": "integer" },
          "meeting_url": { "type": "string" },
          "meeting_uuid": { "type": "string" },
          "exams": { "type": "array", "items": { "type": "object", "properties": { "index": { "type": "integer", "description": "Position in the exams[] you sent." }, "exam_id": { "type": "integer" }, "patient_exam_id": { "type": "integer" }, "rx_type": { "type": "integer", "description": "1 non-Rx, 2 Rx." }, "pharmacy_id": { "type": ["integer", "null"], "description": "Null when none was resolved." }, "order_set_ids": { "type": "array", "items": { "type": "integer" } }, "visit_type": { "type": "string", "enum": ["async", "video"], "description": "Only when the request sent visit_type: the visit type this exam got." }, "reason_code": { "type": "string", "description": "Only when the request sent visit_type: why this exam got that visit type. See InviteVisit.reason_code." } } } },
          "visit": { "$ref": "#/components/schemas/InviteVisit" }
        }
      },
      "ExamInviteResponse": {
        "type": "object",
        "required": ["patient_exams"],
        "properties": {
          "http_code": { "type": "integer" },
          "meeting_url": { "type": "string" },
          "meeting_uuid": { "type": "string" },
          "patient_exams": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "patient_exam_id": { "type": "integer" },
                "exam_title": { "type": "string" },
                "exam_id": { "type": "integer" },
                "visit_type": { "type": "string", "enum": ["async", "video"], "description": "Only when the request sent visit_type: the visit type this exam got." }, "reason_code": { "type": "string", "description": "Only when the request sent visit_type: why this exam got that visit type. See InviteVisit.reason_code." }
              }
            }
          },
          "visit": { "$ref": "#/components/schemas/InviteVisit" }
        }
      },
      "InviteVisit": {
        "type": "object",
        "description": "Returned only when the request sent visit_type: the visit type the invite got and why. Where the rules don't allow async the invite is still created, as a video visit. patient_exam_status and the webhooks don't carry this yet, so keep it from this response.",
        "required": ["requested", "visit_type", "reason_code", "reason"],
        "properties": {
          "requested": { "type": "string", "enum": ["async", "video"], "description": "The visit_type you sent." },
          "visit_type": { "type": "string", "enum": ["async", "video"], "description": "What the invite got." },
          "reason_code": { "type": "string", "description": "Why, as a stable code. One of: `api_pick` (as asked, the rules allow it), `clinic_not_enabled` (async review not switched on for your clinic yet), `exam_not_ready`, `exam_video`, `controlled_substance`, `urgent_care`, `first_visit_video`, `exam_video_here`, `video_only`, `not_reviewed`, `no_video_visit`, `treatment_period_over`, `video_visit_too_long_ago`, `other_exam_video`, `native_video`, `not_in_conversion` (an exam that always runs as it does today, such as an existing ASYNC exam), `rules_unavailable`. More may be added; for an unknown one, read the reason field." },
          "reason": { "type": "string", "description": "The same reason in words. Its wording can change; branch on reason_code." }
        }
      },
      "ExamUploadAttachmentRequest": {
        "type": "object",
        "required": ["api_key", "patient_exam_id"],
        "description": "The public docs section for `/api/exam_upload_attachment` does not enumerate request fields. The shape below is a best-effort reconstruction (api_key + patient_exam_id + file payload). Confirm exact field names with Qualiphy before going live.",
        "properties": {
          "api_key": { "type": "string" },
          "patient_exam_id": { "type": "integer", "description": "From the `patient_exams[]` array in the original `/exam_invite` response." },
          "file_name": { "type": "string", "description": "Original filename including extension, e.g. `id-front.jpg`." },
          "file_type": { "type": "string", "description": "Attachment kind. Match the strings shown in `/exam_list` `attachments[]` for the exam, e.g. `ID`, `Lab`." },
          "file_base64": { "type": "string", "description": "Base64-encoded file contents. (Most likely encoding; the rest of the API is JSON-only.)" }
        }
      },
      "ExamQuestionsRequest": {
        "type": "object",
        "required": ["api_key", "exam_id"],
        "properties": {
          "api_key": { "type": "string" },
          "exam_id": { "type": "integer" }
        }
      },
      "ExamQuestionsResponse": {
        "type": "object",
        "description": "Schema not fully documented; questions are returned as numbered objects matching the `{ no, question, answer }` shape used by `/exam_submit_answers` and the webhook `questions_answers` array.",
        "properties": {
          "exam_id": { "type": "integer" },
          "questions": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "no": { "type": "integer" },
                "question": { "type": "string" }
              }
            }
          }
        }
      },
      "Answer": {
        "type": "object",
        "description": "One answer. `answer` (the response label/text) is required. For single-select and multi-select questions also send `exam_question_response_id`; for multi-select, repeat the same `question_id` once per selected response. Use `answer_text` for the supplemental free text on options that include a text box.",
        "required": ["question_id", "answer"],
        "properties": {
          "question_id": { "type": "integer", "description": "From /exam_questions for this exam." },
          "answer": { "type": "string", "description": "The response label/text (e.g. \"Yes\", or the option text)." },
          "exam_question_response_id": { "type": "integer", "description": "Required for single-select and multi-select questions; the chosen response option's ID." },
          "answer_text": { "type": "string", "description": "Supplemental free text for options that include a text box." },
          "height_inches": { "type": "integer", "description": "Height questions only. 0-11: the inches part, with feet in `answer` (`\"5\"` + `11` = 5' 11\"). 12 or more: total inches (`71` = 5' 11\"), with `answer` empty or the matching feet. Ignored when `answer` already holds the whole height (`5' 11\"`, `71 in`, `180 cm`)." }
        }
      },
      "ExamSubmitAnswersRequest": {
        "type": "object",
        "required": ["api_key", "meeting_uuid", "patient_exam_id", "answers"],
        "properties": {
          "api_key": { "type": "string" },
          "meeting_uuid": { "type": "string", "description": "Required. From the /exam_invite response. Omitting it returns 400 \"Invalid meeting id\"." },
          "patient_exam_id": { "type": "integer", "description": "From the /exam_invite response." },
          "answers": { "type": "array", "items": { "$ref": "#/components/schemas/Answer" } }
        }
      },
      "ExamCancelResponse": {
        "type": "object",
        "properties": {
          "http_code": { "type": "integer" },
          "patient_exam_id": { "type": "integer" },
          "status": { "type": "string", "example": "cancelled" },
          "cancelled_at": { "type": "string", "format": "date-time" }
        }
      },
      "PatientExamStatusResponse": {
        "type": "object",
        "description": "The polling vocabulary of `/api/patient_exam_status`. Distinct from the webhook's `exam_status` -- see `CompletionSenderPayloadEvent1`.",
        "properties": {
          "http_code": { "type": "integer", "description": "Mirrors the HTTP status in the body, for clients that read only the payload." },
          "status": { "type": "string", "enum": ["pending", "approved", "rejected", "na", "cancelled", "prescribed", "rejected_prescription", "expired"], "description": "Where the exam has got to. `pending` - awaiting provider review, and also while attachments or a prefill are still outstanding. `approved` / `rejected` / `na` / `cancelled` - the exam's own outcome. `prescribed` - a prescription was approved. `rejected_prescription` - the prescription was rejected. `expired` - the exam is past its window. The prescription outcomes are evaluated first, so they win when both apply." }
        }
      },
      "PatientExamStatusSetRequest": {
        "type": "object",
        "required": ["api_key", "patient_exam_id", "status"],
        "properties": {
          "api_key": { "type": "string", "description": "Your location's API key." },
          "patient_exam_id": { "type": "integer", "description": "The patient exam to update. Must belong to your clinic." },
          "status": { "type": "integer", "enum": [6], "description": "The status to set. `6` (cancelled) is the only value a partner may set; anything else returns 403." }
        }
      },
      "PatientExamStatusSetResponse": {
        "type": "object",
        "properties": {
          "http_code": { "type": "integer" },
          "success_message": { "type": "string", "example": "Status updated" }
        }
      },
      "Pharmacy": {
        "type": "object",
        "properties": {
          "pharmacy_id": { "type": "integer" },
          "pharmacy_name": { "type": "string", "example": "Greenwich Pharmacy" }
        }
      },
      "PartnerPharmacyListRequest": {
        "type": "object",
        "required": ["api_key", "exam_ids", "patient_state"],
        "properties": {
          "api_key": { "type": "string" },
          "exam_ids": { "type": "array", "items": { "type": "integer" }, "description": "Rx exam IDs from /exam_list (rx_type: 2)." },
          "patient_state": { "type": "string", "description": "Two-letter state code, e.g. \"NY\". Filters to pharmacies that can ship to the patient's state. Omitting it returns an empty array." }
        }
      },
      "PartnerPharmacyListResponse": {
        "type": "array",
        "items": { "$ref": "#/components/schemas/Pharmacy" }
      },
      "PartnerPharmacyPackagesRequest": {
        "type": "object",
        "required": ["api_key", "pharmacy_ids", "exam_ids", "patient_state"],
        "properties": {
          "api_key": { "type": "string" },
          "pharmacy_ids": {
            "oneOf": [
              { "type": "integer" },
              { "type": "array", "items": { "type": "integer" } }
            ],
            "description": "Pharmacy ID(s) from /partner_pharmacy_list. Accepts a single integer or an array. Note the plural key — `pharmacy_id` is silently ignored."
          },
          "exam_ids": { "type": "array", "items": { "type": "integer" }, "description": "Rx exam IDs from /exam_list." },
          "patient_state": { "type": "string", "description": "Two-letter state code, e.g. \"NY\". Omitting it returns an empty array." }
        }
      },
      "TreatmentPackage": {
        "type": "object",
        "properties": {
          "exam_pos_id": { "type": "integer", "description": "Legacy ID, returned for older integrations." },
          "order_set_id": { "type": "integer", "description": "Pass to /exam_invite to preselect this package." },
          "title": { "type": "string", "description": "Full package description: drug, route, dosing, supply." },
          "pharmacy_id": { "type": "integer" },
          "turnaround_time": { "type": "string", "example": "3-4" },
          "pharmacy_name": { "type": "string" },
          "integration_partner": { "type": "integer" },
          "qualiphy_total_price": { "type": "string", "description": "Price in dollars, e.g. \"125.00\"." }
        }
      },
      "PartnerPharmacyPackagesResponse": {
        "type": "array",
        "items": { "$ref": "#/components/schemas/TreatmentPackage" }
      },
      "CustomPharmacySearchRequest": {
        "type": "object",
        "required": ["api_key"],
        "description": "At least one of search, zip_code, or ncpdpid should be supplied.",
        "properties": {
          "api_key": { "type": "string" },
          "search": { "type": "string", "description": "Pharmacy name fragment, e.g. \"CVS\"." },
          "zip_code": { "type": "string", "description": "Five-digit ZIP for proximity filtering." },
          "ncpdpid": { "type": "string", "description": "Direct NCPDPID lookup." }
        }
      },
      "CustomPharmacy": {
        "type": "object",
        "properties": {
          "ncpdpid": { "type": "string" },
          "name": { "type": "string" },
          "address_line_1": { "type": "string" },
          "city": { "type": "string" },
          "state": { "type": "string" },
          "zip_code": { "type": "string" },
          "phone": { "type": "string" }
        }
      },
      "CustomPharmacySearchResponse": {
        "type": "object",
        "properties": {
          "pharmacies": { "type": "array", "items": { "$ref": "#/components/schemas/CustomPharmacy" } }
        }
      },
      "ExamSubmitAnswersOk": {
        "type": "object",
        "required": ["http_code"],
        "properties": {
          "http_code": { "type": "integer", "example": 200 },
          "warnings": {
            "type": "array",
            "description": "Present only when a height could not be read. Each skipped height was not stored; a height stored for that question by an earlier call is kept.",
            "items": {
              "type": "object",
              "required": ["question_id", "message"],
              "properties": {
                "question_id": { "type": ["integer", "string"], "description": "The eq_static_id or question_id for that answer, exactly as you sent it (a number or a string)." },
                "message": { "type": "string" }
              }
            }
          }
        }
      },
      "GenericOk": {
        "type": "object",
        "properties": {
          "http_code": { "type": "integer" },
          "status": { "type": "string" }
        }
      },
      "PharmacyContact": {
        "type": "object",
        "properties": {
          "full_name": { "type": ["string", "null"] },
          "email": { "type": ["string", "null"] },
          "phone_number": { "type": ["string", "null"] },
          "role": { "type": ["string", "null"] }
        }
      },
      "PrescriptionTracking": {
        "type": "object",
        "properties": {
          "rx_number": { "type": ["string", "null"] },
          "tracking_number": { "type": ["string", "null"] },
          "ship_carrier": { "type": ["string", "null"] },
          "delivery_service": { "type": ["string", "null"] },
          "pharmacy_location": { "type": ["string", "null"] }
        }
      },
      "PrescriptionItem": {
        "type": "object",
        "properties": {
          "prescription_id": { "type": "integer" },
          "drug_name": { "type": "string" },
          "dosage_form_type": { "type": "string" },
          "strength": { "type": "string" },
          "size": { "type": "string" },
          "quantity": { "type": "string" },
          "quantity_units": { "type": "string" },
          "directions": { "type": "string" },
          "duration_days": { "type": "integer" },
          "refill_amount": { "type": "integer" },
          "ndc_number": { "type": "string" },
          "gpi_number": { "type": "string" },
          "schedule_code": { "type": "string", "description": "DEA controlled-substance schedule when applicable." },
          "active_ingredient": { "type": "string" },
          "inactive_ingredient": { "type": "string" },
          "pharmacy_name": { "type": "string" },
          "pharmacy_contacts": { "type": "array", "items": { "$ref": "#/components/schemas/PharmacyContact" } },
          "prescription_tracking": { "type": "array", "items": { "$ref": "#/components/schemas/PrescriptionTracking" } },
          "created_at": { "type": "string", "format": "date-time" }
        }
      },
      "WebhookAnswer": {
        "type": "object",
        "description": "One screening question and its stored answer, as the webhook sends it. NOT the `/exam_submit_answers` request item -- that is `Answer`, a different shape with a required `question_id`.",
        "properties": {
          "no": { "type": "integer", "description": "1-based position in the questionnaire." },
          "question": { "type": "string" },
          "answer": { "type": "string", "description": "Always a string. Sanitized: control characters removed, length-capped." }
        }
      },
      "WebhookEvent1ConsultationComplete": {
        "type": "object",
        "description": "Fires for every exam (GFE, Rx, Urgent Care) when the provider finishes the consultation. Carries the verdict and the patient's Q&A.",
        "properties": {
          "event": { "type": "integer", "enum": [1] },
          "reason": { "type": "string", "description": "Free-text reason from the provider. For Approved: typically a generic completion note. For Deferred to Medical Director or N/A: usually describes why." },
          "exam_id": { "type": "integer", "description": "Catalog exam template id -- the `exam_id` you sent on `/exam_invite`." },
          "exam_url": { "type": ["string", "null"], "description": "CloudFront-hosted PDF of the consultation record. The signed URL expires 24 hours after the webhook fires — download and mirror the file to your own storage on receipt if you need long-term access. `null` when no result document exists at send time -- the common case on the first delivery, because the PDF is produced on demand. This is not tied to the outcome." },
          "exam_name": { "type": "string" },
          "clinic_id": { "type": "integer", "description": "The clinic (location) the exam belongs to -- the same id `/exam_list` returns. Present on events 1, 2 and 3. Key on this rather than `clinic_name`, which is free text." },
          "exam_status": { "type": "string", "enum": ["Approved", "Deferred to Medical Director", "N/A", "approved", "rejected", "na"], "description": "The terminal outcome. Only three exist: Approved, Deferred to Medical Director (a provider declined and escalated) and N/A (no decision was possible, e.g. the patient never attended). Environments that predate ENG-101 -- including production today -- send the lower-case enum keys `approved`, `rejected`, `na` for the same three; `rejected` is the Deferred to Medical Director case. Compare case-insensitively. There is no `Rejected`, `NA` or `Missed` value." },
          "rx_status": { "type": "string", "description": "Empty string on event 1. A good-faith exam has no prescription component, and a pharmacy confirmation makes the delivery event 2 -- both result-document senders set the event and this field on the same branch. Never `null` and never a pharmacy value here." },
          "clinic_name": { "type": "string" },
          "patient_email": { "type": "string" },
          "patient_phone_number": { "type": "string" },
          "patient_exam_id": { "type": "integer", "description": "Per-patient exam instance id, as `/exam_invite` returned it. Key idempotency on (`patient_exam_id`, `event`)." },
          "provider_name": { "type": ["string", "null"], "description": "Provider who handled the exam. `null` for N/A outcomes where no provider acted." },
          "additional_data": { "type": "string", "description": "Echoed unchanged from `/exam_invite` (stringified JSON). One reserved key: if this JSON has a `provider` key naming an EMR handled by Qualiphy's integration hub (for example `zenoti`), the partner webhook for that exam is SUPPRESSED and the result is delivered through that integration instead. Do not use `provider` for your own data." },
          "questions_answers": { "type": "array", "items": { "$ref": "#/components/schemas/WebhookAnswer" }, "description": "Screening Q&A. Empty array where the patient never started (an N/A outcome)." }
        }
      },
      "WebhookEvent2PrescriptionConfirmed": {
        "type": "object",
        "description": "Fires only for Rx exams, after event 1, when the treatment order has been written and confirmed at the pharmacy. `prescription` is an array — an exam can include multiple treatment items (e.g. HRT often returns 2+).",
        "properties": {
          "event": { "type": "integer", "enum": [2] },
          "exam_id": { "type": "integer", "description": "Catalog exam template id -- the `exam_id` you sent on `/exam_invite`." },
          "exam_name": { "type": "string" },
          "exam_status": { "type": "string", "enum": ["Approved", "Deferred to Medical Director", "N/A", "approved", "rejected", "na"], "description": "The terminal outcome. Only three exist: Approved, Deferred to Medical Director (a provider declined and escalated) and N/A (no decision was possible, e.g. the patient never attended). Environments that predate ENG-101 -- including production today -- send the lower-case enum keys `approved`, `rejected`, `na` for the same three; `rejected` is the Deferred to Medical Director case. Compare case-insensitively. There is no `Rejected`, `NA` or `Missed` value." },
          "exam_url": { "type": "string", "description": "CloudFront-hosted PDF of the consultation record. The signed URL expires 24 hours after the webhook fires." },
          "rx_status": { "type": "string", "description": "Completion sender: `approved`, `rejected` or `pending`. Result-document sender: `Prescribed`, `Pharmacy Confirmed`, `Prescription Denied` or `Prescription On Hold`." },
          "clinic_id": { "type": "integer", "description": "The clinic (location) the exam belongs to -- the same id `/exam_list` returns. Present on events 1, 2 and 3. Key on this rather than `clinic_name`, which is free text." },
          "clinic_name": { "type": "string" },
          "patient_email": { "type": "string" },
          "patient_phone_number": { "type": "string" },
          "patient_exam_id": { "type": "integer", "description": "Per-patient exam instance id, as `/exam_invite` returned it. Key idempotency on (`patient_exam_id`, `event`)." },
          "provider_name": { "type": "string" },
          "prescribed_os_id": { "type": "integer", "description": "Order set ID the provider prescribed." },
          "prescription": { "type": "array", "items": { "$ref": "#/components/schemas/PrescriptionItem" }, "description": "One entry per drug. May include controlled substances (`schedule_code` set, e.g. `C3`) — storage of these fields is regulated." },
          "questions_answers": { "type": "array", "items": { "$ref": "#/components/schemas/WebhookAnswer" }, "description": "Same Q&A shape as event 1." }
        }
      },
      "WebhookEvent3PrescriptionTracking": {
        "type": "object",
        "description": "Fires when the partner pharmacy ships the treatment. Does NOT fire for custom-pharmacy / urgent-care exams — those pharmacies handle their own tracking outside Qualiphy.",
        "properties": {
          "event": { "type": "integer", "enum": [3] },
          "patient_exam_id": { "oneOf": [{ "type": "string" }, { "type": "integer" }], "description": "Relayed verbatim from the pharmacy's shipment notice, so it arrives as whatever that partner sent -- a string or a number, where events 1 and 2 always send integers. Compare with `Number()`." },
          "clinic_id": { "type": "integer", "description": "The clinic (location) the exam belongs to -- the same id `/exam_list` returns. Present on events 1, 2 and 3. Key on this rather than `clinic_name`, which is free text. Event 3 carries no `clinic_name` at all." },
          "prescription_id": { "oneOf": [{ "type": "string" }, { "type": "integer" }], "description": "Matches a `prescription[].prescription_id` from event 2. Relayed from the pharmacy like `patient_exam_id`, so it may arrive as a string; present only when the pharmacy supplies one." },
          "tracking_number": { "type": "string" },
          "delivery_service": { "type": "string", "description": "e.g. `Overnight`, `Standard`." },
          "pharmacy_location": { "type": "string" },
          "order_id": { "type": "string" }
        }
      },
      "WebhookEvent": {
        "oneOf": [
          { "$ref": "#/components/schemas/WebhookEvent1ConsultationComplete" },
          { "$ref": "#/components/schemas/WebhookEvent2PrescriptionConfirmed" },
          { "$ref": "#/components/schemas/WebhookEvent3PrescriptionTracking" }
        ],
        "discriminator": {
          "propertyName": "event"
        }
      },
      "CompletionSenderPayloadBase": {
        "type": "object",
        "description": "Every field a completion-sender body carries. `/api/patient_exam_webhook_payload` returns this shape, and Qualiphy POSTs it to your `webhook_url`. Modeled separately from `WebhookEvent1ConsultationComplete`, which describes the result-document sender. The two agree field for field on event 1 today and diverge at event 2, so they are kept apart rather than shared -- one sender changing must not silently rewrite the other's contract. `event` is pinned by the two variants below rather than here, so neither can contradict the other.",
        "properties": {
          "http_code": { "type": "integer", "description": "Present only on the `/api/patient_exam_webhook_payload` response. The delivered webhook has no such field." },
          "exam_status": { "type": "string", "enum": ["Approved", "Deferred to Medical Director", "N/A", "approved", "rejected", "na"], "description": "The terminal outcome, in the completion sender's vocabulary. Environments that predate ENG-101 emit the lower-case enum keys `approved` / `rejected` / `na` for the same three, so compare case-insensitively. This is NOT the `/api/patient_exam_status` polling vocabulary." },
          "rx_status": { "type": "string", "enum": ["approved", "rejected", "pending", ""], "description": "Empty string when the exam has no prescription component, which is the event 1 case." },
          "patient_exam_id": { "type": "integer", "description": "Per-patient exam instance id, as `/exam_invite` returned it." },
          "exam_id": { "type": ["integer", "null"], "description": "Catalog exam template id -- the `exam_id` you sent on `/exam_invite`." },
          "exam_name": { "type": ["string", "null"] },
          "exam_url": { "type": ["string", "null"], "description": "Usually `null`, because the result PDF is produced on demand. Where one already exists you may get a time-limited link." },
          "clinic_id": { "type": ["integer", "null"], "description": "The clinic (location) the exam belongs to -- the same id `/exam_list` returns. Read from the exam rather than the clinic lookup, so it is still present when `clinic_name` comes back null. Key on this, not on the display name." },
          "clinic_name": { "type": ["string", "null"], "description": "Free-text display name: neither stable nor unique, so a partner pointing several clinics at one `webhook_url` cannot tell deliveries apart with it. Key on `clinic_id`." },
          "provider_name": { "type": ["string", "null"], "description": "`null` where no provider acted." },
          "reason": { "type": ["string", "null"], "description": "The operator's note on the exam, where one exists." },
          "patient_email": { "type": ["string", "null"], "description": "PHI." },
          "patient_phone_number": { "type": ["string", "null"], "description": "PHI." },
          "additional_data": { "type": ["string", "null"], "description": "The string you passed on the invite, echoed back verbatim. One reserved key: if it is JSON whose `provider` names an EMR handled by Qualiphy's integration hub (for example `zenoti`), the partner webhook for that exam is SUPPRESSED and the result is delivered through that integration instead. Do not use `provider` for your own data." },
          "questions_answers": { "type": "array", "items": { "$ref": "#/components/schemas/WebhookAnswer" }, "description": "Screening Q&A, empty where the patient never started. PHI." }
        }
      },
      "CompletionSenderPayloadEvent1": {
        "allOf": [
          { "$ref": "#/components/schemas/CompletionSenderPayloadBase" },
          {
            "type": "object",
            "description": "A completed exam with no prescription component.",
            "required": ["event"],
            "properties": {
              "event": { "type": "integer", "enum": [1], "description": "1 = the exam completed with no prescriptions." }
            }
          }
        ]
      },
      "CompletionSenderPayloadEvent2": {
        "allOf": [
          { "$ref": "#/components/schemas/CompletionSenderPayloadBase" },
          {
            "type": "object",
            "description": "The same fields plus `prescriptions`. Note the plural key and the narrow field set -- the result-document sender's `WebhookEvent2PrescriptionConfirmed` uses a singular `prescription` with different fields. Composed over the shared base rather than over event 1: inheriting event 1 would pin `event` to 1 and 2 at once and admit no payload at all.",
            "required": ["event"],
            "properties": {
              "event": { "type": "integer", "enum": [2], "description": "2 = the exam completed with at least one prescription." },
              "prescriptions": { "type": "array", "items": { "$ref": "#/components/schemas/CompletionSenderPrescription" }, "description": "One entry per prescription written for the exam. Present only on event 2." }
            }
          }
        ]
      },
      "CompletionSenderPrescription": {
        "type": "object",
        "description": "One prescription as the completion sender reports it. Deliberately narrower than `PrescriptionItem`, which belongs to the result-document sender.",
        "properties": {
          "prescription_id": { "type": ["integer", "null"] },
          "drug_name": { "type": ["string", "null"] },
          "directions": { "type": ["string", "null"] },
          "quantity": { "type": ["integer", "null"] },
          "quantity_units": { "type": ["string", "null"] },
          "refill_amount": { "type": ["integer", "null"] },
          "prescription_date": { "type": ["string", "null"], "format": "date-time", "description": "The prescription's `created_at`. The column is a TIMESTAMP, which the driver returns as a date object rather than a string, so it serialises ISO-8601 in UTC -- not a bare `YYYY-MM-DD`." }
        }
      },
      "CompletionSenderPayload": {
        "description": "The body `/api/patient_exam_webhook_payload` returns. Dispatch on `event`: `1` has no `prescriptions`, `2` has it. Carries no OpenAPI `discriminator` on purpose -- `event` is an integer, and a 3.0 discriminator resolves its value as a schema name, so `1` would be looked up as a schema called \"1\". `event` is required and enum-pinned on both variants instead, which leaves exactly one branch matching any payload.",
        "oneOf": [
          { "$ref": "#/components/schemas/CompletionSenderPayloadEvent1" },
          { "$ref": "#/components/schemas/CompletionSenderPayloadEvent2" }
        ]
      },
      "WebhookDestination": {
        "type": "object",
        "properties": {
          "id": {
            "type": "integer"
          },
          "webhook_url": {
            "type": "string"
          },
          "is_clinic_default": {
            "type": "boolean",
            "description": "True when this is the URL configured on the clinic profile."
          },
          "signing_secret_hint": {
            "type": "string",
            "description": "Last four characters of the signing secret, prefixed with an ellipsis."
          },
          "created_at": {
            "type": "string"
          },
          "signing_secret": {
            "type": "string",
            "description": "64 hex characters. Present ONLY on creation, on rotate_secret, on reactivating a removed URL (always a new secret), or the first time a pre-registered URL's secret is handed out. Store it; it is not shown again."
          }
        }
      },
      "WebhookDestinationRegisterRequest": {
        "type": "object",
        "required": [
          "api_key",
          "webhook_url"
        ],
        "properties": {
          "api_key": {
            "type": "string"
          },
          "webhook_url": {
            "type": "string",
            "description": "https URL to a public host, max 500 chars, no embedded credentials. Plain http is accepted only for the clinic's already-configured URL."
          },
          "rotate_secret": {
            "type": "boolean",
            "description": "On an existing destination, mint and return a new signing_secret. It replaces the old one immediately and exists only in this response, so deploy it right away: deliveries signed before your receiver has it fail verification (the completion sender retries for only about 2.5 s; the result-document sender does not retry a 4xx), so rotate at a quiet time and keep accepting the previous secret briefly for deliveries signed just before the rotation."
          }
        }
      },
      "WebhookDestinationRegisterResponse": {
        "type": "object",
        "properties": {
          "http_code": {
            "type": "integer",
            "enum": [
              200,
              201
            ]
          },
          "created": {
            "type": "boolean"
          },
          "reactivated": {
            "type": "boolean",
            "description": "True when the URL had been removed and this call reactivated it (HTTP 200, created: false). Always present (false otherwise). The destination then carries a NEW signing_secret, returned once; the old secret is never revived."
          },
          "destination": {
            "$ref": "#/components/schemas/WebhookDestination"
          },
          "message": {
            "type": "string"
          }
        }
      },
      "WebhookDestinationListResponse": {
        "type": "object",
        "properties": {
          "http_code": {
            "type": "integer"
          },
          "clinic_webhook_url": {
            "type": ["string", "null"]
          },
          "destinations": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/WebhookDestination"
            }
          }
        }
      },
      "WebhookDestinationRemoveRequest": {
        "type": "object",
        "required": [
          "api_key",
          "destination_id"
        ],
        "properties": {
          "api_key": {
            "type": "string"
          },
          "destination_id": {
            "type": "integer"
          }
        }
      },
      "WebhookDestinationRemoveResponse": {
        "type": "object",
        "properties": {
          "http_code": {
            "type": "integer"
          },
          "removed": {
            "type": "boolean"
          },
          "destination_id": {
            "type": "integer"
          }
        }
      }
    }
  }
}
