{
  "openapi": "3.1.0",
  "info": {
    "title": "MedAppz Public API",
    "version": "1.0.0",
    "description": "The routes a machine credential can call: an `mza_` API key, scoped to named permissions, or an `mzv_` device key for voice ingest. Generated from the controllers that serve these routes (apps/api/scripts/openapi-build.ts) — a route this document lists is a route the code actually opens to a key, and one that opened since has to appear here before the next release."
  },
  "servers": [{ "url": "https://medappz.com/v1", "description": "Production" }],
  "tags": [
    { "name": "Admissions funnel" },
    { "name": "Appointments and availability" },
    { "name": "Billing" },
    { "name": "Calldesk" },
    { "name": "Dataport" },
    { "name": "Dispensedesk" },
    { "name": "Fhirbridge" },
    { "name": "Imaging bridge" },
    { "name": "Lab analysers" },
    { "name": "Leads and CRM" },
    { "name": "Patientcare" },
    { "name": "Patients" },
    { "name": "Voice ingest" }
  ],
  "paths": {
    "/v1/admitline/board": {
      "get": {
        "operationId": "getAdmitlineBoard",
        "summary": "Board: admitline board",
        "description": "Requires scope: admitline.read.",
        "tags": ["Admissions funnel"],
        "parameters": [
          { "name": "doctor", "in": "query", "required": false, "schema": { "type": "string" } },
          { "name": "mine", "in": "query", "required": false, "schema": { "type": "string" } },
          { "name": "owner", "in": "query", "required": false, "schema": { "type": "string" } },
          { "name": "patientId", "in": "query", "required": false, "schema": { "type": "string" } },
          { "name": "payer", "in": "query", "required": false, "schema": { "type": "string" } },
          { "name": "q", "in": "query", "required": false, "schema": { "type": "string" } },
          { "name": "stage", "in": "query", "required": false, "schema": { "type": "string" } }
        ],
        "responses": {
          "200": {
            "description": "Success.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": ["data", "meta"],
                  "properties": {
                    "data": {},
                    "meta": {
                      "type": "object",
                      "required": ["requestId"],
                      "properties": {
                        "requestId": { "type": "string" },
                        "version": { "type": "integer" },
                        "nextCursor": { "type": ["string", "null"] },
                        "hasMore": { "type": "boolean" },
                        "total": { "type": "integer" }
                      }
                    }
                  }
                }
              }
            }
          },
          "401": { "$ref": "#/components/responses/Unauthenticated" },
          "403": { "$ref": "#/components/responses/Forbidden" },
          "429": { "$ref": "#/components/responses/RateLimited" }
        },
        "security": [{ "ApiKeyAuth": [] }],
        "x-medappz-scopes": ["admitline.read"]
      }
    },
    "/v1/admitline/cases/{id}": {
      "get": {
        "operationId": "getAdmitlineCasesById",
        "summary": "Detail: admitline cases (one record)",
        "description": "Requires scope: admitline.read.",
        "tags": ["Admissions funnel"],
        "parameters": [
          { "name": "id", "in": "path", "required": true, "schema": { "type": "string" } }
        ],
        "responses": {
          "200": {
            "description": "Success.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": ["data", "meta"],
                  "properties": {
                    "data": {},
                    "meta": {
                      "type": "object",
                      "required": ["requestId"],
                      "properties": {
                        "requestId": { "type": "string" },
                        "version": { "type": "integer" },
                        "nextCursor": { "type": ["string", "null"] },
                        "hasMore": { "type": "boolean" },
                        "total": { "type": "integer" }
                      }
                    }
                  }
                }
              }
            }
          },
          "401": { "$ref": "#/components/responses/Unauthenticated" },
          "403": { "$ref": "#/components/responses/Forbidden" },
          "429": { "$ref": "#/components/responses/RateLimited" }
        },
        "security": [{ "ApiKeyAuth": [] }],
        "x-medappz-scopes": ["admitline.read"]
      }
    },
    "/v1/admitline/doctors": {
      "get": {
        "operationId": "getAdmitlineDoctors",
        "summary": "The \"advised by\" picker. Names only — no privileges, no rota.",
        "description": "Requires scope: admitline.read.",
        "tags": ["Admissions funnel"],
        "parameters": [],
        "responses": {
          "200": {
            "description": "Success.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": ["data", "meta"],
                  "properties": {
                    "data": {},
                    "meta": {
                      "type": "object",
                      "required": ["requestId"],
                      "properties": {
                        "requestId": { "type": "string" },
                        "version": { "type": "integer" },
                        "nextCursor": { "type": ["string", "null"] },
                        "hasMore": { "type": "boolean" },
                        "total": { "type": "integer" }
                      }
                    }
                  }
                }
              }
            }
          },
          "401": { "$ref": "#/components/responses/Unauthenticated" },
          "403": { "$ref": "#/components/responses/Forbidden" },
          "429": { "$ref": "#/components/responses/RateLimited" }
        },
        "security": [{ "ApiKeyAuth": [] }],
        "x-medappz-scopes": ["admitline.read"]
      }
    },
    "/v1/admitline/funnel": {
      "get": {
        "operationId": "getAdmitlineFunnel",
        "summary": "Funnel: admitline funnel",
        "description": "Requires scope: admitline.read.",
        "tags": ["Admissions funnel"],
        "parameters": [
          { "name": "by", "in": "query", "required": false, "schema": { "type": "string" } },
          { "name": "from", "in": "query", "required": false, "schema": { "type": "string" } },
          { "name": "to", "in": "query", "required": false, "schema": { "type": "string" } }
        ],
        "responses": {
          "200": {
            "description": "Success.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": ["data", "meta"],
                  "properties": {
                    "data": {},
                    "meta": {
                      "type": "object",
                      "required": ["requestId"],
                      "properties": {
                        "requestId": { "type": "string" },
                        "version": { "type": "integer" },
                        "nextCursor": { "type": ["string", "null"] },
                        "hasMore": { "type": "boolean" },
                        "total": { "type": "integer" }
                      }
                    }
                  }
                }
              }
            }
          },
          "401": { "$ref": "#/components/responses/Unauthenticated" },
          "403": { "$ref": "#/components/responses/Forbidden" },
          "429": { "$ref": "#/components/responses/RateLimited" }
        },
        "security": [{ "ApiKeyAuth": [] }],
        "x-medappz-scopes": ["admitline.read"]
      }
    },
    "/v1/admitline/summary": {
      "get": {
        "operationId": "getAdmitlineSummary",
        "summary": "Counts of admission cases by stage, for a dashboard.",
        "description": "Requires scope: admitline.read.",
        "tags": ["Admissions funnel"],
        "parameters": [],
        "responses": {
          "200": {
            "description": "Success.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": ["data", "meta"],
                  "properties": {
                    "data": {},
                    "meta": {
                      "type": "object",
                      "required": ["requestId"],
                      "properties": {
                        "requestId": { "type": "string" },
                        "version": { "type": "integer" },
                        "nextCursor": { "type": ["string", "null"] },
                        "hasMore": { "type": "boolean" },
                        "total": { "type": "integer" }
                      }
                    }
                  }
                }
              }
            }
          },
          "401": { "$ref": "#/components/responses/Unauthenticated" },
          "403": { "$ref": "#/components/responses/Forbidden" },
          "429": { "$ref": "#/components/responses/RateLimited" }
        },
        "security": [{ "ApiKeyAuth": [] }],
        "x-medappz-scopes": ["admitline.read"]
      }
    },
    "/v1/appointments/availability": {
      "get": {
        "operationId": "getAppointmentsAvailability",
        "summary": "Availability: appointments availability",
        "description": "Requires scope: appointment.read.",
        "tags": ["Appointments and availability"],
        "parameters": [
          { "name": "from", "in": "query", "required": false, "schema": { "type": "string" } },
          {
            "name": "schedulableId",
            "in": "query",
            "required": false,
            "schema": { "type": "string" }
          },
          {
            "name": "serviceType",
            "in": "query",
            "required": false,
            "schema": { "type": "string" }
          },
          { "name": "to", "in": "query", "required": false, "schema": { "type": "string" } }
        ],
        "responses": {
          "200": {
            "description": "Success.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": ["data", "meta"],
                  "properties": {
                    "data": {},
                    "meta": {
                      "type": "object",
                      "required": ["requestId"],
                      "properties": {
                        "requestId": { "type": "string" },
                        "version": { "type": "integer" },
                        "nextCursor": { "type": ["string", "null"] },
                        "hasMore": { "type": "boolean" },
                        "total": { "type": "integer" }
                      }
                    }
                  }
                }
              }
            }
          },
          "401": { "$ref": "#/components/responses/Unauthenticated" },
          "403": { "$ref": "#/components/responses/Forbidden" },
          "429": { "$ref": "#/components/responses/RateLimited" }
        },
        "security": [{ "ApiKeyAuth": [] }],
        "x-medappz-scopes": ["appointment.read"]
      }
    },
    "/v1/appointments/day": {
      "get": {
        "operationId": "getAppointmentsDay",
        "summary": "Appointment day: appointments day",
        "description": "Requires scope: appointment.read.",
        "tags": ["Appointments and availability"],
        "parameters": [
          { "name": "date", "in": "query", "required": false, "schema": { "type": "string" } },
          {
            "name": "schedulableId",
            "in": "query",
            "required": false,
            "schema": { "type": "string" }
          }
        ],
        "responses": {
          "200": {
            "description": "Success.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": ["data", "meta"],
                  "properties": {
                    "data": {},
                    "meta": {
                      "type": "object",
                      "required": ["requestId"],
                      "properties": {
                        "requestId": { "type": "string" },
                        "version": { "type": "integer" },
                        "nextCursor": { "type": ["string", "null"] },
                        "hasMore": { "type": "boolean" },
                        "total": { "type": "integer" }
                      }
                    }
                  }
                }
              }
            }
          },
          "401": { "$ref": "#/components/responses/Unauthenticated" },
          "403": { "$ref": "#/components/responses/Forbidden" },
          "429": { "$ref": "#/components/responses/RateLimited" }
        },
        "security": [{ "ApiKeyAuth": [] }],
        "x-medappz-scopes": ["appointment.read"]
      }
    },
    "/v1/benchlink/device/results": {
      "post": {
        "operationId": "postBenchlinkDeviceResults",
        "summary": "Post an analyser’s results for a sample; they wait for verification.",
        "description": "Requires scope: benchlink.post.",
        "tags": ["Lab analysers"],
        "parameters": [
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": false,
            "description": "A key you generate per attempt; a retried request with the same key is a no-op.",
            "schema": { "type": "string" }
          }
        ],
        "responses": {
          "201": {
            "description": "Success.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": ["data", "meta"],
                  "properties": {
                    "data": {},
                    "meta": {
                      "type": "object",
                      "required": ["requestId"],
                      "properties": {
                        "requestId": { "type": "string" },
                        "version": { "type": "integer" },
                        "nextCursor": { "type": ["string", "null"] },
                        "hasMore": { "type": "boolean" },
                        "total": { "type": "integer" }
                      }
                    }
                  }
                }
              }
            }
          },
          "400": { "$ref": "#/components/responses/ValidationFailed" },
          "401": { "$ref": "#/components/responses/Unauthenticated" },
          "403": { "$ref": "#/components/responses/Forbidden" },
          "429": { "$ref": "#/components/responses/RateLimited" }
        },
        "security": [{ "ApiKeyAuth": [] }],
        "x-medappz-scopes": ["benchlink.post"],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "analyzerId": {
                    "type": "string",
                    "format": "uuid",
                    "pattern": "^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$"
                  },
                  "messageUid": { "type": "string", "minLength": 1, "maxLength": 120 },
                  "kind": { "type": "string", "enum": ["result", "qc"] },
                  "raw": { "type": "string", "maxLength": 8000 },
                  "lines": {
                    "minItems": 1,
                    "maxItems": 60,
                    "type": "array",
                    "items": {
                      "type": "object",
                      "properties": {
                        "barcode": { "type": "string", "minLength": 1, "maxLength": 64 },
                        "code": { "type": "string", "minLength": 1, "maxLength": 40 },
                        "valueNum": { "type": "number" },
                        "valueText": { "type": "string", "minLength": 1, "maxLength": 120 },
                        "unit": { "type": "string", "minLength": 1, "maxLength": 24 },
                        "flag": { "type": "string", "enum": ["normal", "low", "high", "critical"] },
                        "instrumentFlags": {
                          "maxItems": 10,
                          "type": "array",
                          "items": { "type": "string", "minLength": 1, "maxLength": 24 }
                        },
                        "observedAt": {
                          "type": "string",
                          "format": "date-time",
                          "pattern": "^(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))T(?:(?:[01]\\d|2[0-3]):[0-5]\\d:[0-5]\\d(?:\\.\\d+)?(?:Z|([+-](?:[01]\\d|2[0-3]):[0-5]\\d)))$"
                        },
                        "qcLevel": { "type": "string", "enum": ["low", "normal", "high"] },
                        "qcLot": { "type": "string", "minLength": 1, "maxLength": 60 }
                      },
                      "required": ["barcode", "code"],
                      "additionalProperties": false
                    }
                  }
                },
                "required": ["analyzerId", "messageUid", "kind", "lines"],
                "additionalProperties": false
              }
            }
          }
        }
      }
    },
    "/v1/benchlink/device/worklist": {
      "get": {
        "operationId": "getBenchlinkDeviceWorklist",
        "summary": "The host query: which tests are ordered on this sample barcode.",
        "description": "Requires scope: benchlink.post.",
        "tags": ["Lab analysers"],
        "parameters": [
          {
            "name": "analyzerId",
            "in": "query",
            "required": false,
            "schema": { "type": "string" }
          },
          { "name": "barcode", "in": "query", "required": false, "schema": { "type": "string" } }
        ],
        "responses": {
          "200": {
            "description": "Success.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": ["data", "meta"],
                  "properties": {
                    "data": {},
                    "meta": {
                      "type": "object",
                      "required": ["requestId"],
                      "properties": {
                        "requestId": { "type": "string" },
                        "version": { "type": "integer" },
                        "nextCursor": { "type": ["string", "null"] },
                        "hasMore": { "type": "boolean" },
                        "total": { "type": "integer" }
                      }
                    }
                  }
                }
              }
            }
          },
          "401": { "$ref": "#/components/responses/Unauthenticated" },
          "403": { "$ref": "#/components/responses/Forbidden" },
          "429": { "$ref": "#/components/responses/RateLimited" }
        },
        "security": [{ "ApiKeyAuth": [] }],
        "x-medappz-scopes": ["benchlink.post"]
      }
    },
    "/v1/billing/feed/bills": {
      "get": {
        "operationId": "getBillingFeedBills",
        "summary": "Bills finalised in a period, with totals, paid and balance; paged by `after`.",
        "description": "Requires scope: billing.read.",
        "tags": ["Billing"],
        "parameters": [
          { "name": "after", "in": "query", "required": false, "schema": { "type": "string" } },
          { "name": "from", "in": "query", "required": false, "schema": { "type": "string" } },
          { "name": "limit", "in": "query", "required": false, "schema": { "type": "string" } },
          { "name": "patientId", "in": "query", "required": false, "schema": { "type": "string" } },
          { "name": "status", "in": "query", "required": false, "schema": { "type": "string" } },
          { "name": "to", "in": "query", "required": false, "schema": { "type": "string" } }
        ],
        "responses": {
          "200": {
            "description": "Success.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": ["data", "meta"],
                  "properties": {
                    "data": {},
                    "meta": {
                      "type": "object",
                      "required": ["requestId"],
                      "properties": {
                        "requestId": { "type": "string" },
                        "version": { "type": "integer" },
                        "nextCursor": { "type": ["string", "null"] },
                        "hasMore": { "type": "boolean" },
                        "total": { "type": "integer" }
                      }
                    }
                  }
                }
              }
            }
          },
          "401": { "$ref": "#/components/responses/Unauthenticated" },
          "403": { "$ref": "#/components/responses/Forbidden" },
          "429": { "$ref": "#/components/responses/RateLimited" }
        },
        "security": [{ "ApiKeyAuth": [] }],
        "x-medappz-scopes": ["billing.read"]
      }
    },
    "/v1/billing/feed/bills/{id}": {
      "get": {
        "operationId": "getBillingFeedBillsById",
        "summary": "One bill: totals, its lines (service, quantity, price, tax) and its payments.",
        "description": "Requires scope: billing.read.",
        "tags": ["Billing"],
        "parameters": [
          { "name": "id", "in": "path", "required": true, "schema": { "type": "string" } }
        ],
        "responses": {
          "200": {
            "description": "Success.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": ["data", "meta"],
                  "properties": {
                    "data": {},
                    "meta": {
                      "type": "object",
                      "required": ["requestId"],
                      "properties": {
                        "requestId": { "type": "string" },
                        "version": { "type": "integer" },
                        "nextCursor": { "type": ["string", "null"] },
                        "hasMore": { "type": "boolean" },
                        "total": { "type": "integer" }
                      }
                    }
                  }
                }
              }
            }
          },
          "401": { "$ref": "#/components/responses/Unauthenticated" },
          "403": { "$ref": "#/components/responses/Forbidden" },
          "429": { "$ref": "#/components/responses/RateLimited" }
        },
        "security": [{ "ApiKeyAuth": [] }],
        "x-medappz-scopes": ["billing.read"]
      }
    },
    "/v1/billing/feed/outstanding": {
      "get": {
        "operationId": "getBillingFeedOutstanding",
        "summary": "What each patient still owes on finalised bills, optionally for bills from a period.",
        "description": "Requires scope: billing.read.",
        "tags": ["Billing"],
        "parameters": [
          { "name": "after", "in": "query", "required": false, "schema": { "type": "string" } },
          { "name": "from", "in": "query", "required": false, "schema": { "type": "string" } },
          { "name": "limit", "in": "query", "required": false, "schema": { "type": "string" } },
          { "name": "patientId", "in": "query", "required": false, "schema": { "type": "string" } },
          { "name": "to", "in": "query", "required": false, "schema": { "type": "string" } }
        ],
        "responses": {
          "200": {
            "description": "Success.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": ["data", "meta"],
                  "properties": {
                    "data": {},
                    "meta": {
                      "type": "object",
                      "required": ["requestId"],
                      "properties": {
                        "requestId": { "type": "string" },
                        "version": { "type": "integer" },
                        "nextCursor": { "type": ["string", "null"] },
                        "hasMore": { "type": "boolean" },
                        "total": { "type": "integer" }
                      }
                    }
                  }
                }
              }
            }
          },
          "401": { "$ref": "#/components/responses/Unauthenticated" },
          "403": { "$ref": "#/components/responses/Forbidden" },
          "429": { "$ref": "#/components/responses/RateLimited" }
        },
        "security": [{ "ApiKeyAuth": [] }],
        "x-medappz-scopes": ["billing.read"]
      }
    },
    "/v1/billing/feed/payments": {
      "get": {
        "operationId": "getBillingFeedPayments",
        "summary": "Payments received in a period, with method, amount, status and receipt number.",
        "description": "Requires scope: billing.read.",
        "tags": ["Billing"],
        "parameters": [
          { "name": "after", "in": "query", "required": false, "schema": { "type": "string" } },
          { "name": "from", "in": "query", "required": false, "schema": { "type": "string" } },
          { "name": "limit", "in": "query", "required": false, "schema": { "type": "string" } },
          { "name": "patientId", "in": "query", "required": false, "schema": { "type": "string" } },
          { "name": "to", "in": "query", "required": false, "schema": { "type": "string" } }
        ],
        "responses": {
          "200": {
            "description": "Success.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": ["data", "meta"],
                  "properties": {
                    "data": {},
                    "meta": {
                      "type": "object",
                      "required": ["requestId"],
                      "properties": {
                        "requestId": { "type": "string" },
                        "version": { "type": "integer" },
                        "nextCursor": { "type": ["string", "null"] },
                        "hasMore": { "type": "boolean" },
                        "total": { "type": "integer" }
                      }
                    }
                  }
                }
              }
            }
          },
          "401": { "$ref": "#/components/responses/Unauthenticated" },
          "403": { "$ref": "#/components/responses/Forbidden" },
          "429": { "$ref": "#/components/responses/RateLimited" }
        },
        "security": [{ "ApiKeyAuth": [] }],
        "x-medappz-scopes": ["billing.read"]
      }
    },
    "/v1/booking-offers": {
      "get": {
        "operationId": "getBookingOffers",
        "summary": "List: booking offers",
        "description": "Requires scope: appointment.read.",
        "tags": ["Appointments and availability"],
        "parameters": [
          {
            "name": "exceptionId",
            "in": "query",
            "required": false,
            "schema": { "type": "string" }
          },
          { "name": "status", "in": "query", "required": false, "schema": { "type": "string" } }
        ],
        "responses": {
          "200": {
            "description": "Success.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": ["data", "meta"],
                  "properties": {
                    "data": {},
                    "meta": {
                      "type": "object",
                      "required": ["requestId"],
                      "properties": {
                        "requestId": { "type": "string" },
                        "version": { "type": "integer" },
                        "nextCursor": { "type": ["string", "null"] },
                        "hasMore": { "type": "boolean" },
                        "total": { "type": "integer" }
                      }
                    }
                  }
                }
              }
            }
          },
          "401": { "$ref": "#/components/responses/Unauthenticated" },
          "403": { "$ref": "#/components/responses/Forbidden" },
          "429": { "$ref": "#/components/responses/RateLimited" }
        },
        "security": [{ "ApiKeyAuth": [] }],
        "x-medappz-scopes": ["appointment.read"]
      }
    },
    "/v1/booking-offers/exceptions/{exceptionId}": {
      "get": {
        "operationId": "getBookingOffersExceptionsByExceptionId",
        "summary": "Affected: booking offers exceptions (one record)",
        "description": "Requires scope: appointment.read.",
        "tags": ["Appointments and availability"],
        "parameters": [
          { "name": "exceptionId", "in": "path", "required": true, "schema": { "type": "string" } }
        ],
        "responses": {
          "200": {
            "description": "Success.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": ["data", "meta"],
                  "properties": {
                    "data": {},
                    "meta": {
                      "type": "object",
                      "required": ["requestId"],
                      "properties": {
                        "requestId": { "type": "string" },
                        "version": { "type": "integer" },
                        "nextCursor": { "type": ["string", "null"] },
                        "hasMore": { "type": "boolean" },
                        "total": { "type": "integer" }
                      }
                    }
                  }
                }
              }
            }
          },
          "401": { "$ref": "#/components/responses/Unauthenticated" },
          "403": { "$ref": "#/components/responses/Forbidden" },
          "429": { "$ref": "#/components/responses/RateLimited" }
        },
        "security": [{ "ApiKeyAuth": [] }],
        "x-medappz-scopes": ["appointment.read"]
      }
    },
    "/v1/booking-policy/deposits": {
      "get": {
        "operationId": "getBookingPolicyDeposits",
        "summary": "Deposits: booking policy deposits",
        "description": "Requires scope: appointment.read.",
        "tags": ["Appointments and availability"],
        "parameters": [
          { "name": "status", "in": "query", "required": false, "schema": { "type": "string" } }
        ],
        "responses": {
          "200": {
            "description": "Success.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": ["data", "meta"],
                  "properties": {
                    "data": {},
                    "meta": {
                      "type": "object",
                      "required": ["requestId"],
                      "properties": {
                        "requestId": { "type": "string" },
                        "version": { "type": "integer" },
                        "nextCursor": { "type": ["string", "null"] },
                        "hasMore": { "type": "boolean" },
                        "total": { "type": "integer" }
                      }
                    }
                  }
                }
              }
            }
          },
          "401": { "$ref": "#/components/responses/Unauthenticated" },
          "403": { "$ref": "#/components/responses/Forbidden" },
          "429": { "$ref": "#/components/responses/RateLimited" }
        },
        "security": [{ "ApiKeyAuth": [] }],
        "x-medappz-scopes": ["appointment.read"]
      }
    },
    "/v1/booking-policy/late": {
      "get": {
        "operationId": "getBookingPolicyLate",
        "summary": "Late: booking policy late",
        "description": "Requires scope: appointment.read.",
        "tags": ["Appointments and availability"],
        "parameters": [],
        "responses": {
          "200": {
            "description": "Success.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": ["data", "meta"],
                  "properties": {
                    "data": {},
                    "meta": {
                      "type": "object",
                      "required": ["requestId"],
                      "properties": {
                        "requestId": { "type": "string" },
                        "version": { "type": "integer" },
                        "nextCursor": { "type": ["string", "null"] },
                        "hasMore": { "type": "boolean" },
                        "total": { "type": "integer" }
                      }
                    }
                  }
                }
              }
            }
          },
          "401": { "$ref": "#/components/responses/Unauthenticated" },
          "403": { "$ref": "#/components/responses/Forbidden" },
          "429": { "$ref": "#/components/responses/RateLimited" }
        },
        "security": [{ "ApiKeyAuth": [] }],
        "x-medappz-scopes": ["appointment.read"]
      }
    },
    "/v1/booking-series": {
      "get": {
        "operationId": "getBookingSeries",
        "summary": "List: booking series",
        "description": "Requires scope: appointment.read.",
        "tags": ["Appointments and availability"],
        "parameters": [
          { "name": "patientId", "in": "query", "required": false, "schema": { "type": "string" } },
          { "name": "status", "in": "query", "required": false, "schema": { "type": "string" } }
        ],
        "responses": {
          "200": {
            "description": "Success.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": ["data", "meta"],
                  "properties": {
                    "data": {},
                    "meta": {
                      "type": "object",
                      "required": ["requestId"],
                      "properties": {
                        "requestId": { "type": "string" },
                        "version": { "type": "integer" },
                        "nextCursor": { "type": ["string", "null"] },
                        "hasMore": { "type": "boolean" },
                        "total": { "type": "integer" }
                      }
                    }
                  }
                }
              }
            }
          },
          "401": { "$ref": "#/components/responses/Unauthenticated" },
          "403": { "$ref": "#/components/responses/Forbidden" },
          "429": { "$ref": "#/components/responses/RateLimited" }
        },
        "security": [{ "ApiKeyAuth": [] }],
        "x-medappz-scopes": ["appointment.read"]
      }
    },
    "/v1/booking-series/{id}": {
      "get": {
        "operationId": "getBookingSeriesById",
        "summary": "Get: booking series (one record)",
        "description": "Requires scope: appointment.read.",
        "tags": ["Appointments and availability"],
        "parameters": [
          { "name": "id", "in": "path", "required": true, "schema": { "type": "string" } }
        ],
        "responses": {
          "200": {
            "description": "Success.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": ["data", "meta"],
                  "properties": {
                    "data": {},
                    "meta": {
                      "type": "object",
                      "required": ["requestId"],
                      "properties": {
                        "requestId": { "type": "string" },
                        "version": { "type": "integer" },
                        "nextCursor": { "type": ["string", "null"] },
                        "hasMore": { "type": "boolean" },
                        "total": { "type": "integer" }
                      }
                    }
                  }
                }
              }
            }
          },
          "401": { "$ref": "#/components/responses/Unauthenticated" },
          "403": { "$ref": "#/components/responses/Forbidden" },
          "429": { "$ref": "#/components/responses/RateLimited" }
        },
        "security": [{ "ApiKeyAuth": [] }],
        "x-medappz-scopes": ["appointment.read"]
      }
    },
    "/v1/booking-series/plan": {
      "post": {
        "operationId": "postBookingSeriesPlan",
        "summary": "Plan: booking series plan",
        "description": "Requires scope: appointment.read.",
        "tags": ["Appointments and availability"],
        "parameters": [
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": false,
            "description": "A key you generate per attempt; a retried request with the same key is a no-op.",
            "schema": { "type": "string" }
          }
        ],
        "responses": {
          "201": {
            "description": "Success.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": ["data", "meta"],
                  "properties": {
                    "data": {},
                    "meta": {
                      "type": "object",
                      "required": ["requestId"],
                      "properties": {
                        "requestId": { "type": "string" },
                        "version": { "type": "integer" },
                        "nextCursor": { "type": ["string", "null"] },
                        "hasMore": { "type": "boolean" },
                        "total": { "type": "integer" }
                      }
                    }
                  }
                }
              }
            }
          },
          "400": { "$ref": "#/components/responses/ValidationFailed" },
          "401": { "$ref": "#/components/responses/Unauthenticated" },
          "403": { "$ref": "#/components/responses/Forbidden" },
          "429": { "$ref": "#/components/responses/RateLimited" }
        },
        "security": [{ "ApiKeyAuth": [] }],
        "x-medappz-scopes": ["appointment.read"],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "source": {
                    "type": "string",
                    "enum": ["scheduling", "dialysisdesk", "chemochair"]
                  },
                  "patientId": {
                    "type": "string",
                    "format": "uuid",
                    "pattern": "^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$"
                  },
                  "schedulableId": {
                    "type": "string",
                    "format": "uuid",
                    "pattern": "^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$"
                  },
                  "chairId": {
                    "type": "string",
                    "format": "uuid",
                    "pattern": "^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$"
                  },
                  "serviceType": { "type": "string", "minLength": 1, "maxLength": 80 },
                  "slot": {
                    "type": "string",
                    "enum": ["morning", "afternoon", "evening", "night"]
                  },
                  "startsOn": { "type": "string", "pattern": "^\\d{4}-\\d{2}-\\d{2}$" },
                  "startTime": { "type": "string", "pattern": "^\\d{2}:\\d{2}$" },
                  "intervalDays": { "type": "integer", "minimum": 1, "maximum": 90 },
                  "skipWeekdays": {
                    "maxItems": 6,
                    "type": "array",
                    "items": { "type": "integer", "minimum": 0, "maximum": 6 }
                  },
                  "count": { "type": "integer", "minimum": 1, "maximum": 120 },
                  "onUnavailable": { "type": "string", "enum": ["refuse", "skip"] },
                  "note": { "type": "string", "maxLength": 500 }
                },
                "required": ["source", "patientId", "startsOn", "intervalDays", "count"],
                "additionalProperties": false
              }
            }
          }
        }
      }
    },
    "/v1/calls/centre/caller": {
      "get": {
        "operationId": "getCallsCentreCaller",
        "summary": "Caller: calls centre caller",
        "description": "Requires scopes: appointment.read, patient.read.",
        "tags": ["Calldesk"],
        "parameters": [
          { "name": "phone", "in": "query", "required": false, "schema": { "type": "string" } }
        ],
        "responses": {
          "200": {
            "description": "Success.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": ["data", "meta"],
                  "properties": {
                    "data": {},
                    "meta": {
                      "type": "object",
                      "required": ["requestId"],
                      "properties": {
                        "requestId": { "type": "string" },
                        "version": { "type": "integer" },
                        "nextCursor": { "type": ["string", "null"] },
                        "hasMore": { "type": "boolean" },
                        "total": { "type": "integer" }
                      }
                    }
                  }
                }
              }
            }
          },
          "401": { "$ref": "#/components/responses/Unauthenticated" },
          "403": { "$ref": "#/components/responses/Forbidden" },
          "429": { "$ref": "#/components/responses/RateLimited" }
        },
        "security": [{ "ApiKeyAuth": [] }],
        "x-medappz-scopes": ["appointment.read", "patient.read"]
      }
    },
    "/v1/calls/centre/slots": {
      "get": {
        "operationId": "getCallsCentreSlots",
        "summary": "Slots: calls centre slots",
        "description": "Requires scope: appointment.read.",
        "tags": ["Calldesk"],
        "parameters": [
          { "name": "days", "in": "query", "required": false, "schema": { "type": "string" } },
          { "name": "near", "in": "query", "required": false, "schema": { "type": "string" } },
          { "name": "q", "in": "query", "required": false, "schema": { "type": "string" } }
        ],
        "responses": {
          "200": {
            "description": "Success.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": ["data", "meta"],
                  "properties": {
                    "data": {},
                    "meta": {
                      "type": "object",
                      "required": ["requestId"],
                      "properties": {
                        "requestId": { "type": "string" },
                        "version": { "type": "integer" },
                        "nextCursor": { "type": ["string", "null"] },
                        "hasMore": { "type": "boolean" },
                        "total": { "type": "integer" }
                      }
                    }
                  }
                }
              }
            }
          },
          "401": { "$ref": "#/components/responses/Unauthenticated" },
          "403": { "$ref": "#/components/responses/Forbidden" },
          "429": { "$ref": "#/components/responses/RateLimited" }
        },
        "security": [{ "ApiKeyAuth": [] }],
        "x-medappz-scopes": ["appointment.read"]
      }
    },
    "/v1/calls/centre/today": {
      "get": {
        "operationId": "getCallsCentreToday",
        "summary": "Today: calls centre today",
        "description": "Requires scope: appointment.read.",
        "tags": ["Calldesk"],
        "parameters": [],
        "responses": {
          "200": {
            "description": "Success.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": ["data", "meta"],
                  "properties": {
                    "data": {},
                    "meta": {
                      "type": "object",
                      "required": ["requestId"],
                      "properties": {
                        "requestId": { "type": "string" },
                        "version": { "type": "integer" },
                        "nextCursor": { "type": ["string", "null"] },
                        "hasMore": { "type": "boolean" },
                        "total": { "type": "integer" }
                      }
                    }
                  }
                }
              }
            }
          },
          "401": { "$ref": "#/components/responses/Unauthenticated" },
          "403": { "$ref": "#/components/responses/Forbidden" },
          "429": { "$ref": "#/components/responses/RateLimited" }
        },
        "security": [{ "ApiKeyAuth": [] }],
        "x-medappz-scopes": ["appointment.read"]
      }
    },
    "/v1/crm/leads/scores": {
      "get": {
        "operationId": "getCrmLeadsScores",
        "summary": "Scores: crm leads scores",
        "description": "Requires scope: lead.read.",
        "tags": ["Leads and CRM"],
        "parameters": [],
        "responses": {
          "200": {
            "description": "Success.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": ["data", "meta"],
                  "properties": {
                    "data": {},
                    "meta": {
                      "type": "object",
                      "required": ["requestId"],
                      "properties": {
                        "requestId": { "type": "string" },
                        "version": { "type": "integer" },
                        "nextCursor": { "type": ["string", "null"] },
                        "hasMore": { "type": "boolean" },
                        "total": { "type": "integer" }
                      }
                    }
                  }
                }
              }
            }
          },
          "401": { "$ref": "#/components/responses/Unauthenticated" },
          "403": { "$ref": "#/components/responses/Forbidden" },
          "429": { "$ref": "#/components/responses/RateLimited" }
        },
        "security": [{ "ApiKeyAuth": [] }],
        "x-medappz-scopes": ["lead.read"]
      }
    },
    "/v1/crm/pipeline/report": {
      "get": {
        "operationId": "getCrmPipelineReport",
        "summary": "Report: crm pipeline report",
        "description": "Requires scope: lead.read.",
        "tags": ["Leads and CRM"],
        "parameters": [
          { "name": "from", "in": "query", "required": false, "schema": { "type": "string" } },
          { "name": "source", "in": "query", "required": false, "schema": { "type": "string" } },
          { "name": "to", "in": "query", "required": false, "schema": { "type": "string" } }
        ],
        "responses": {
          "200": {
            "description": "Success.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": ["data", "meta"],
                  "properties": {
                    "data": {},
                    "meta": {
                      "type": "object",
                      "required": ["requestId"],
                      "properties": {
                        "requestId": { "type": "string" },
                        "version": { "type": "integer" },
                        "nextCursor": { "type": ["string", "null"] },
                        "hasMore": { "type": "boolean" },
                        "total": { "type": "integer" }
                      }
                    }
                  }
                }
              }
            }
          },
          "401": { "$ref": "#/components/responses/Unauthenticated" },
          "403": { "$ref": "#/components/responses/Forbidden" },
          "429": { "$ref": "#/components/responses/RateLimited" }
        },
        "security": [{ "ApiKeyAuth": [] }],
        "x-medappz-scopes": ["lead.read"]
      }
    },
    "/v1/encounters/{id}/follow-up-slots": {
      "get": {
        "operationId": "getEncountersByIdFollowUpSlots",
        "summary": "Follow up slots: encounters follow up slots (one record)",
        "description": "Requires scope: appointment.read.",
        "tags": ["Appointments and availability"],
        "parameters": [
          { "name": "id", "in": "path", "required": true, "schema": { "type": "string" } },
          { "name": "days", "in": "query", "required": false, "schema": { "type": "string" } },
          {
            "name": "schedulableId",
            "in": "query",
            "required": false,
            "schema": { "type": "string" }
          }
        ],
        "responses": {
          "200": {
            "description": "Success.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": ["data", "meta"],
                  "properties": {
                    "data": {},
                    "meta": {
                      "type": "object",
                      "required": ["requestId"],
                      "properties": {
                        "requestId": { "type": "string" },
                        "version": { "type": "integer" },
                        "nextCursor": { "type": ["string", "null"] },
                        "hasMore": { "type": "boolean" },
                        "total": { "type": "integer" }
                      }
                    }
                  }
                }
              }
            }
          },
          "401": { "$ref": "#/components/responses/Unauthenticated" },
          "403": { "$ref": "#/components/responses/Forbidden" },
          "429": { "$ref": "#/components/responses/RateLimited" }
        },
        "security": [{ "ApiKeyAuth": [] }],
        "x-medappz-scopes": ["appointment.read"]
      }
    },
    "/v1/fhir/$export": {
      "post": {
        "operationId": "postFhirExport",
        "summary": "Start a bulk FHIR export of every patient: 202, with the status URL in Content-Location.",
        "description": "Requires scope: fhir.read.",
        "tags": ["Dataport"],
        "parameters": [
          {
            "name": "_outputFormat",
            "in": "query",
            "required": false,
            "schema": { "type": "string" }
          },
          { "name": "_since", "in": "query", "required": false, "schema": { "type": "string" } },
          { "name": "_type", "in": "query", "required": false, "schema": { "type": "string" } },
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": false,
            "description": "A key you generate per attempt; a retried request with the same key is a no-op.",
            "schema": { "type": "string" }
          }
        ],
        "responses": {
          "201": {
            "description": "Success.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": ["data", "meta"],
                  "properties": {
                    "data": {},
                    "meta": {
                      "type": "object",
                      "required": ["requestId"],
                      "properties": {
                        "requestId": { "type": "string" },
                        "version": { "type": "integer" },
                        "nextCursor": { "type": ["string", "null"] },
                        "hasMore": { "type": "boolean" },
                        "total": { "type": "integer" }
                      }
                    }
                  }
                }
              }
            }
          },
          "401": { "$ref": "#/components/responses/Unauthenticated" },
          "403": { "$ref": "#/components/responses/Forbidden" },
          "429": { "$ref": "#/components/responses/RateLimited" }
        },
        "security": [{ "ApiKeyAuth": [] }],
        "x-medappz-scopes": ["fhir.read"],
        "x-medappz-rate-limit": "10/hour"
      }
    },
    "/v1/fhir/$export/{jobId}": {
      "get": {
        "operationId": "getFhirExportByJobId",
        "summary": "Poll a bulk export: 202 while it works, then signed NDJSON links that expire.",
        "description": "Requires scope: fhir.read.",
        "tags": ["Dataport"],
        "parameters": [
          { "name": "jobId", "in": "path", "required": true, "schema": { "type": "string" } }
        ],
        "responses": {
          "200": {
            "description": "Success.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": ["data", "meta"],
                  "properties": {
                    "data": {},
                    "meta": {
                      "type": "object",
                      "required": ["requestId"],
                      "properties": {
                        "requestId": { "type": "string" },
                        "version": { "type": "integer" },
                        "nextCursor": { "type": ["string", "null"] },
                        "hasMore": { "type": "boolean" },
                        "total": { "type": "integer" }
                      }
                    }
                  }
                }
              }
            }
          },
          "401": { "$ref": "#/components/responses/Unauthenticated" },
          "403": { "$ref": "#/components/responses/Forbidden" },
          "429": { "$ref": "#/components/responses/RateLimited" }
        },
        "security": [{ "ApiKeyAuth": [] }],
        "x-medappz-scopes": ["fhir.read"]
      },
      "delete": {
        "operationId": "deleteFhirExportByJobId",
        "summary": "Cancel a bulk export and delete its files.",
        "description": "Requires scope: fhir.read.",
        "tags": ["Dataport"],
        "parameters": [
          { "name": "jobId", "in": "path", "required": true, "schema": { "type": "string" } },
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": false,
            "description": "A key you generate per attempt; a retried request with the same key is a no-op.",
            "schema": { "type": "string" }
          }
        ],
        "responses": {
          "200": {
            "description": "Success.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": ["data", "meta"],
                  "properties": {
                    "data": {},
                    "meta": {
                      "type": "object",
                      "required": ["requestId"],
                      "properties": {
                        "requestId": { "type": "string" },
                        "version": { "type": "integer" },
                        "nextCursor": { "type": ["string", "null"] },
                        "hasMore": { "type": "boolean" },
                        "total": { "type": "integer" }
                      }
                    }
                  }
                }
              }
            }
          },
          "401": { "$ref": "#/components/responses/Unauthenticated" },
          "403": { "$ref": "#/components/responses/Forbidden" },
          "429": { "$ref": "#/components/responses/RateLimited" }
        },
        "security": [{ "ApiKeyAuth": [] }],
        "x-medappz-scopes": ["fhir.read"]
      }
    },
    "/v1/fhir/Patient/{patientId}": {
      "get": {
        "operationId": "getFhirPatientByPatientId",
        "summary": "One patient as a FHIR Patient resource.",
        "description": "Requires scope: fhir.read.",
        "tags": ["Fhirbridge"],
        "parameters": [
          { "name": "patientId", "in": "path", "required": true, "schema": { "type": "string" } }
        ],
        "responses": {
          "200": {
            "description": "Success.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": ["data", "meta"],
                  "properties": {
                    "data": {},
                    "meta": {
                      "type": "object",
                      "required": ["requestId"],
                      "properties": {
                        "requestId": { "type": "string" },
                        "version": { "type": "integer" },
                        "nextCursor": { "type": ["string", "null"] },
                        "hasMore": { "type": "boolean" },
                        "total": { "type": "integer" }
                      }
                    }
                  }
                }
              }
            }
          },
          "401": { "$ref": "#/components/responses/Unauthenticated" },
          "403": { "$ref": "#/components/responses/Forbidden" },
          "429": { "$ref": "#/components/responses/RateLimited" }
        },
        "security": [{ "ApiKeyAuth": [] }],
        "x-medappz-scopes": ["fhir.read"]
      }
    },
    "/v1/fhir/Patient/{patientId}/$everything": {
      "get": {
        "operationId": "getFhirPatientByPatientIdEverything",
        "summary": "The patient's record as a searchset Bundle. `_type` narrows it. For an API key, DocumentReference entries are metadata only: their download link needs `file.read`, which no key can hold.",
        "description": "Requires scope: fhir.read.",
        "tags": ["Fhirbridge"],
        "parameters": [
          { "name": "patientId", "in": "path", "required": true, "schema": { "type": "string" } },
          { "name": "_type", "in": "query", "required": false, "schema": { "type": "string" } }
        ],
        "responses": {
          "200": {
            "description": "Success.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": ["data", "meta"],
                  "properties": {
                    "data": {},
                    "meta": {
                      "type": "object",
                      "required": ["requestId"],
                      "properties": {
                        "requestId": { "type": "string" },
                        "version": { "type": "integer" },
                        "nextCursor": { "type": ["string", "null"] },
                        "hasMore": { "type": "boolean" },
                        "total": { "type": "integer" }
                      }
                    }
                  }
                }
              }
            }
          },
          "401": { "$ref": "#/components/responses/Unauthenticated" },
          "403": { "$ref": "#/components/responses/Forbidden" },
          "429": { "$ref": "#/components/responses/RateLimited" }
        },
        "security": [{ "ApiKeyAuth": [] }],
        "x-medappz-scopes": ["fhir.read"],
        "x-medappz-rate-limit": "120/min"
      }
    },
    "/v1/imaging/archives": {
      "get": {
        "operationId": "getImagingArchives",
        "summary": "Archives: imaging archives",
        "description": "Requires scope: imaging.read.",
        "tags": ["Imaging bridge"],
        "parameters": [],
        "responses": {
          "200": {
            "description": "Success.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": ["data", "meta"],
                  "properties": {
                    "data": {},
                    "meta": {
                      "type": "object",
                      "required": ["requestId"],
                      "properties": {
                        "requestId": { "type": "string" },
                        "version": { "type": "integer" },
                        "nextCursor": { "type": ["string", "null"] },
                        "hasMore": { "type": "boolean" },
                        "total": { "type": "integer" }
                      }
                    }
                  }
                }
              }
            }
          },
          "401": { "$ref": "#/components/responses/Unauthenticated" },
          "403": { "$ref": "#/components/responses/Forbidden" },
          "429": { "$ref": "#/components/responses/RateLimited" }
        },
        "security": [{ "ApiKeyAuth": [] }],
        "x-medappz-scopes": ["imaging.read"]
      }
    },
    "/v1/imaging/archives/check": {
      "post": {
        "operationId": "postImagingArchivesCheck",
        "summary": "Test the connection to each imaging archive and record the result.",
        "description": "Requires scope: imaging.read.",
        "tags": ["Imaging bridge"],
        "parameters": [
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": false,
            "description": "A key you generate per attempt; a retried request with the same key is a no-op.",
            "schema": { "type": "string" }
          }
        ],
        "responses": {
          "201": {
            "description": "Success.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": ["data", "meta"],
                  "properties": {
                    "data": {},
                    "meta": {
                      "type": "object",
                      "required": ["requestId"],
                      "properties": {
                        "requestId": { "type": "string" },
                        "version": { "type": "integer" },
                        "nextCursor": { "type": ["string", "null"] },
                        "hasMore": { "type": "boolean" },
                        "total": { "type": "integer" }
                      }
                    }
                  }
                }
              }
            }
          },
          "401": { "$ref": "#/components/responses/Unauthenticated" },
          "403": { "$ref": "#/components/responses/Forbidden" },
          "429": { "$ref": "#/components/responses/RateLimited" }
        },
        "security": [{ "ApiKeyAuth": [] }],
        "x-medappz-scopes": ["imaging.read"]
      }
    },
    "/v1/imaging/poll": {
      "post": {
        "operationId": "postImagingPoll",
        "summary": "Ask the archive what it has now.",
        "description": "Requires scope: imaging.manage.",
        "tags": ["Imaging bridge"],
        "parameters": [
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": false,
            "description": "A key you generate per attempt; a retried request with the same key is a no-op.",
            "schema": { "type": "string" }
          }
        ],
        "responses": {
          "201": {
            "description": "Success.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": ["data", "meta"],
                  "properties": {
                    "data": {},
                    "meta": {
                      "type": "object",
                      "required": ["requestId"],
                      "properties": {
                        "requestId": { "type": "string" },
                        "version": { "type": "integer" },
                        "nextCursor": { "type": ["string", "null"] },
                        "hasMore": { "type": "boolean" },
                        "total": { "type": "integer" }
                      }
                    }
                  }
                }
              }
            }
          },
          "401": { "$ref": "#/components/responses/Unauthenticated" },
          "403": { "$ref": "#/components/responses/Forbidden" },
          "429": { "$ref": "#/components/responses/RateLimited" }
        },
        "security": [{ "ApiKeyAuth": [] }],
        "x-medappz-scopes": ["imaging.manage"]
      }
    },
    "/v1/imaging/studies": {
      "get": {
        "operationId": "getImagingStudies",
        "summary": "Studies: imaging studies",
        "description": "Requires scope: imaging.read.",
        "tags": ["Imaging bridge"],
        "parameters": [
          { "name": "patientId", "in": "query", "required": false, "schema": { "type": "string" } },
          { "name": "state", "in": "query", "required": false, "schema": { "type": "string" } },
          {
            "name": "worklistEntryId",
            "in": "query",
            "required": false,
            "schema": { "type": "string" }
          }
        ],
        "responses": {
          "200": {
            "description": "Success.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": ["data", "meta"],
                  "properties": {
                    "data": {},
                    "meta": {
                      "type": "object",
                      "required": ["requestId"],
                      "properties": {
                        "requestId": { "type": "string" },
                        "version": { "type": "integer" },
                        "nextCursor": { "type": ["string", "null"] },
                        "hasMore": { "type": "boolean" },
                        "total": { "type": "integer" }
                      }
                    }
                  }
                }
              }
            }
          },
          "401": { "$ref": "#/components/responses/Unauthenticated" },
          "403": { "$ref": "#/components/responses/Forbidden" },
          "429": { "$ref": "#/components/responses/RateLimited" }
        },
        "security": [{ "ApiKeyAuth": [] }],
        "x-medappz-scopes": ["imaging.read"]
      },
      "post": {
        "operationId": "postImagingStudies",
        "summary": "The bridge's way in, and the manual one.",
        "description": "Requires scope: imaging.manage.",
        "tags": ["Imaging bridge"],
        "parameters": [
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": false,
            "description": "A key you generate per attempt; a retried request with the same key is a no-op.",
            "schema": { "type": "string" }
          }
        ],
        "responses": {
          "201": {
            "description": "Success.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": ["data", "meta"],
                  "properties": {
                    "data": {},
                    "meta": {
                      "type": "object",
                      "required": ["requestId"],
                      "properties": {
                        "requestId": { "type": "string" },
                        "version": { "type": "integer" },
                        "nextCursor": { "type": ["string", "null"] },
                        "hasMore": { "type": "boolean" },
                        "total": { "type": "integer" }
                      }
                    }
                  }
                }
              }
            }
          },
          "400": { "$ref": "#/components/responses/ValidationFailed" },
          "401": { "$ref": "#/components/responses/Unauthenticated" },
          "403": { "$ref": "#/components/responses/Forbidden" },
          "429": { "$ref": "#/components/responses/RateLimited" }
        },
        "security": [{ "ApiKeyAuth": [] }],
        "x-medappz-scopes": ["imaging.manage"],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "studyInstanceUid": { "type": "string", "pattern": "^[0-9.]{1,64}$" },
                  "seriesUids": {
                    "maxItems": 500,
                    "type": "array",
                    "items": { "type": "string", "pattern": "^[0-9.]{1,64}$" }
                  },
                  "modality": { "type": "string", "minLength": 1, "maxLength": 32 },
                  "accessionNo": { "type": "string", "minLength": 1, "maxLength": 64 },
                  "description": { "type": "string", "minLength": 1, "maxLength": 200 },
                  "seriesCount": { "type": "integer", "minimum": 0, "maximum": 100000 },
                  "instanceCount": { "type": "integer", "minimum": 0, "maximum": 10000000 },
                  "studyLocalAt": {
                    "type": "string",
                    "pattern": "^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}$"
                  },
                  "metadata": {
                    "type": "object",
                    "propertyNames": { "type": "string" },
                    "additionalProperties": {
                      "type": "object",
                      "properties": {
                        "vr": { "type": "string", "maxLength": 8 },
                        "Value": { "type": "array", "items": {} }
                      },
                      "additionalProperties": false
                    }
                  }
                },
                "required": ["studyInstanceUid", "modality"],
                "additionalProperties": false
              }
            }
          }
        }
      }
    },
    "/v1/imaging/studies/{id}/discard": {
      "post": {
        "operationId": "postImagingStudiesByIdDiscard",
        "summary": "Discard: imaging studies discard (one record)",
        "description": "Requires scope: imaging.manage.",
        "tags": ["Imaging bridge"],
        "parameters": [
          { "name": "id", "in": "path", "required": true, "schema": { "type": "string" } },
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": false,
            "description": "A key you generate per attempt; a retried request with the same key is a no-op.",
            "schema": { "type": "string" }
          }
        ],
        "responses": {
          "201": {
            "description": "Success.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": ["data", "meta"],
                  "properties": {
                    "data": {},
                    "meta": {
                      "type": "object",
                      "required": ["requestId"],
                      "properties": {
                        "requestId": { "type": "string" },
                        "version": { "type": "integer" },
                        "nextCursor": { "type": ["string", "null"] },
                        "hasMore": { "type": "boolean" },
                        "total": { "type": "integer" }
                      }
                    }
                  }
                }
              }
            }
          },
          "400": { "$ref": "#/components/responses/ValidationFailed" },
          "401": { "$ref": "#/components/responses/Unauthenticated" },
          "403": { "$ref": "#/components/responses/Forbidden" },
          "429": { "$ref": "#/components/responses/RateLimited" }
        },
        "security": [{ "ApiKeyAuth": [] }],
        "x-medappz-scopes": ["imaging.manage"],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": { "reason": { "type": "string", "minLength": 3, "maxLength": 300 } },
                "required": ["reason"],
                "additionalProperties": false
              }
            }
          }
        }
      }
    },
    "/v1/imaging/studies/{id}/match": {
      "post": {
        "operationId": "postImagingStudiesByIdMatch",
        "summary": "Match: imaging studies match (one record)",
        "description": "Requires scope: imaging.manage.",
        "tags": ["Imaging bridge"],
        "parameters": [
          { "name": "id", "in": "path", "required": true, "schema": { "type": "string" } },
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": false,
            "description": "A key you generate per attempt; a retried request with the same key is a no-op.",
            "schema": { "type": "string" }
          }
        ],
        "responses": {
          "201": {
            "description": "Success.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": ["data", "meta"],
                  "properties": {
                    "data": {},
                    "meta": {
                      "type": "object",
                      "required": ["requestId"],
                      "properties": {
                        "requestId": { "type": "string" },
                        "version": { "type": "integer" },
                        "nextCursor": { "type": ["string", "null"] },
                        "hasMore": { "type": "boolean" },
                        "total": { "type": "integer" }
                      }
                    }
                  }
                }
              }
            }
          },
          "400": { "$ref": "#/components/responses/ValidationFailed" },
          "401": { "$ref": "#/components/responses/Unauthenticated" },
          "403": { "$ref": "#/components/responses/Forbidden" },
          "429": { "$ref": "#/components/responses/RateLimited" }
        },
        "security": [{ "ApiKeyAuth": [] }],
        "x-medappz-scopes": ["imaging.manage"],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "worklistEntryId": {
                    "type": "string",
                    "format": "uuid",
                    "pattern": "^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$"
                  }
                },
                "required": ["worklistEntryId"],
                "additionalProperties": false
              }
            }
          }
        }
      }
    },
    "/v1/imaging/studies/{id}/refresh": {
      "post": {
        "operationId": "postImagingStudiesByIdRefresh",
        "summary": "Refresh: imaging studies refresh (one record)",
        "description": "Requires scope: imaging.manage.",
        "tags": ["Imaging bridge"],
        "parameters": [
          { "name": "id", "in": "path", "required": true, "schema": { "type": "string" } },
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": false,
            "description": "A key you generate per attempt; a retried request with the same key is a no-op.",
            "schema": { "type": "string" }
          }
        ],
        "responses": {
          "201": {
            "description": "Success.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": ["data", "meta"],
                  "properties": {
                    "data": {},
                    "meta": {
                      "type": "object",
                      "required": ["requestId"],
                      "properties": {
                        "requestId": { "type": "string" },
                        "version": { "type": "integer" },
                        "nextCursor": { "type": ["string", "null"] },
                        "hasMore": { "type": "boolean" },
                        "total": { "type": "integer" }
                      }
                    }
                  }
                }
              }
            }
          },
          "401": { "$ref": "#/components/responses/Unauthenticated" },
          "403": { "$ref": "#/components/responses/Forbidden" },
          "429": { "$ref": "#/components/responses/RateLimited" }
        },
        "security": [{ "ApiKeyAuth": [] }],
        "x-medappz-scopes": ["imaging.manage"]
      }
    },
    "/v1/imaging/studies/{id}/unmatch": {
      "post": {
        "operationId": "postImagingStudiesByIdUnmatch",
        "summary": "Unmatch: imaging studies unmatch (one record)",
        "description": "Requires scope: imaging.manage.",
        "tags": ["Imaging bridge"],
        "parameters": [
          { "name": "id", "in": "path", "required": true, "schema": { "type": "string" } },
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": false,
            "description": "A key you generate per attempt; a retried request with the same key is a no-op.",
            "schema": { "type": "string" }
          }
        ],
        "responses": {
          "201": {
            "description": "Success.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": ["data", "meta"],
                  "properties": {
                    "data": {},
                    "meta": {
                      "type": "object",
                      "required": ["requestId"],
                      "properties": {
                        "requestId": { "type": "string" },
                        "version": { "type": "integer" },
                        "nextCursor": { "type": ["string", "null"] },
                        "hasMore": { "type": "boolean" },
                        "total": { "type": "integer" }
                      }
                    }
                  }
                }
              }
            }
          },
          "400": { "$ref": "#/components/responses/ValidationFailed" },
          "401": { "$ref": "#/components/responses/Unauthenticated" },
          "403": { "$ref": "#/components/responses/Forbidden" },
          "429": { "$ref": "#/components/responses/RateLimited" }
        },
        "security": [{ "ApiKeyAuth": [] }],
        "x-medappz-scopes": ["imaging.manage"],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": { "reason": { "type": "string", "minLength": 3, "maxLength": 300 } },
                "required": ["reason"],
                "additionalProperties": false
              }
            }
          }
        }
      }
    },
    "/v1/imaging/studies/unmatched": {
      "get": {
        "operationId": "getImagingStudiesUnmatched",
        "summary": "Studies the archive holds that are not yet matched to a patient.",
        "description": "Requires scope: imaging.read.",
        "tags": ["Imaging bridge"],
        "parameters": [],
        "responses": {
          "200": {
            "description": "Success.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": ["data", "meta"],
                  "properties": {
                    "data": {},
                    "meta": {
                      "type": "object",
                      "required": ["requestId"],
                      "properties": {
                        "requestId": { "type": "string" },
                        "version": { "type": "integer" },
                        "nextCursor": { "type": ["string", "null"] },
                        "hasMore": { "type": "boolean" },
                        "total": { "type": "integer" }
                      }
                    }
                  }
                }
              }
            }
          },
          "401": { "$ref": "#/components/responses/Unauthenticated" },
          "403": { "$ref": "#/components/responses/Forbidden" },
          "429": { "$ref": "#/components/responses/RateLimited" }
        },
        "security": [{ "ApiKeyAuth": [] }],
        "x-medappz-scopes": ["imaging.read"]
      }
    },
    "/v1/imaging/worklist": {
      "get": {
        "operationId": "getImagingWorklist",
        "summary": "Worklist: imaging worklist",
        "description": "Requires scope: imaging.read.",
        "tags": ["Imaging bridge"],
        "parameters": [
          { "name": "from", "in": "query", "required": false, "schema": { "type": "string" } },
          { "name": "patientId", "in": "query", "required": false, "schema": { "type": "string" } },
          { "name": "state", "in": "query", "required": false, "schema": { "type": "string" } },
          { "name": "station", "in": "query", "required": false, "schema": { "type": "string" } },
          { "name": "to", "in": "query", "required": false, "schema": { "type": "string" } }
        ],
        "responses": {
          "200": {
            "description": "Success.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": ["data", "meta"],
                  "properties": {
                    "data": {},
                    "meta": {
                      "type": "object",
                      "required": ["requestId"],
                      "properties": {
                        "requestId": { "type": "string" },
                        "version": { "type": "integer" },
                        "nextCursor": { "type": ["string", "null"] },
                        "hasMore": { "type": "boolean" },
                        "total": { "type": "integer" }
                      }
                    }
                  }
                }
              }
            }
          },
          "401": { "$ref": "#/components/responses/Unauthenticated" },
          "403": { "$ref": "#/components/responses/Forbidden" },
          "429": { "$ref": "#/components/responses/RateLimited" }
        },
        "security": [{ "ApiKeyAuth": [] }],
        "x-medappz-scopes": ["imaging.read"]
      },
      "post": {
        "operationId": "postImagingWorklist",
        "summary": "Schedule: imaging worklist",
        "description": "Requires scope: imaging.manage.",
        "tags": ["Imaging bridge"],
        "parameters": [
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": false,
            "description": "A key you generate per attempt; a retried request with the same key is a no-op.",
            "schema": { "type": "string" }
          }
        ],
        "responses": {
          "201": {
            "description": "Success.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": ["data", "meta"],
                  "properties": {
                    "data": {},
                    "meta": {
                      "type": "object",
                      "required": ["requestId"],
                      "properties": {
                        "requestId": { "type": "string" },
                        "version": { "type": "integer" },
                        "nextCursor": { "type": ["string", "null"] },
                        "hasMore": { "type": "boolean" },
                        "total": { "type": "integer" }
                      }
                    }
                  }
                }
              }
            }
          },
          "400": { "$ref": "#/components/responses/ValidationFailed" },
          "401": { "$ref": "#/components/responses/Unauthenticated" },
          "403": { "$ref": "#/components/responses/Forbidden" },
          "429": { "$ref": "#/components/responses/RateLimited" }
        },
        "security": [{ "ApiKeyAuth": [] }],
        "x-medappz-scopes": ["imaging.manage"],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "orderId": {
                    "type": "string",
                    "format": "uuid",
                    "pattern": "^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$"
                  },
                  "modality": { "type": "string", "enum": ["xray", "ct", "mri", "us", "mammo"] },
                  "procedureDescription": { "type": "string", "minLength": 2, "maxLength": 200 },
                  "stationAeTitle": { "type": "string", "pattern": "^[A-Za-z0-9._-]{1,16}$" },
                  "scheduledAt": {
                    "type": "string",
                    "format": "date-time",
                    "pattern": "^(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))T(?:(?:[01]\\d|2[0-3]):[0-5]\\d:[0-5]\\d(?:\\.\\d+)?(?:Z|([+-](?:[01]\\d|2[0-3]):[0-5]\\d)))$"
                  }
                },
                "required": ["orderId", "modality", "procedureDescription"],
                "additionalProperties": false
              }
            }
          }
        }
      }
    },
    "/v1/imaging/worklist/{id}/state": {
      "post": {
        "operationId": "postImagingWorklistByIdState",
        "summary": "Set state: imaging worklist state (one record)",
        "description": "Requires scope: imaging.manage.",
        "tags": ["Imaging bridge"],
        "parameters": [
          { "name": "id", "in": "path", "required": true, "schema": { "type": "string" } },
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": false,
            "description": "A key you generate per attempt; a retried request with the same key is a no-op.",
            "schema": { "type": "string" }
          }
        ],
        "responses": {
          "201": {
            "description": "Success.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": ["data", "meta"],
                  "properties": {
                    "data": {},
                    "meta": {
                      "type": "object",
                      "required": ["requestId"],
                      "properties": {
                        "requestId": { "type": "string" },
                        "version": { "type": "integer" },
                        "nextCursor": { "type": ["string", "null"] },
                        "hasMore": { "type": "boolean" },
                        "total": { "type": "integer" }
                      }
                    }
                  }
                }
              }
            }
          },
          "400": { "$ref": "#/components/responses/ValidationFailed" },
          "401": { "$ref": "#/components/responses/Unauthenticated" },
          "403": { "$ref": "#/components/responses/Forbidden" },
          "429": { "$ref": "#/components/responses/RateLimited" }
        },
        "security": [{ "ApiKeyAuth": [] }],
        "x-medappz-scopes": ["imaging.manage"],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "state": {
                    "type": "string",
                    "enum": ["arrived", "started", "completed", "discontinued"]
                  },
                  "reason": { "type": "string", "minLength": 2, "maxLength": 300 }
                },
                "required": ["state"],
                "additionalProperties": false
              }
            }
          }
        }
      }
    },
    "/v1/leads": {
      "get": {
        "operationId": "getLeads",
        "summary": "List: leads",
        "description": "Requires scope: lead.read.",
        "tags": ["Leads and CRM"],
        "parameters": [
          { "name": "due", "in": "query", "required": false, "schema": { "type": "string" } },
          { "name": "mine", "in": "query", "required": false, "schema": { "type": "string" } },
          { "name": "source", "in": "query", "required": false, "schema": { "type": "string" } },
          { "name": "status", "in": "query", "required": false, "schema": { "type": "string" } }
        ],
        "responses": {
          "200": {
            "description": "Success.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": ["data", "meta"],
                  "properties": {
                    "data": {},
                    "meta": {
                      "type": "object",
                      "required": ["requestId"],
                      "properties": {
                        "requestId": { "type": "string" },
                        "version": { "type": "integer" },
                        "nextCursor": { "type": ["string", "null"] },
                        "hasMore": { "type": "boolean" },
                        "total": { "type": "integer" }
                      }
                    }
                  }
                }
              }
            }
          },
          "401": { "$ref": "#/components/responses/Unauthenticated" },
          "403": { "$ref": "#/components/responses/Forbidden" },
          "429": { "$ref": "#/components/responses/RateLimited" }
        },
        "security": [{ "ApiKeyAuth": [] }],
        "x-medappz-scopes": ["lead.read"]
      },
      "post": {
        "operationId": "postLeads",
        "summary": "Record an enquiry.",
        "description": "Requires scope: lead.manage.",
        "tags": ["Leads and CRM"],
        "parameters": [
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": false,
            "description": "A key you generate per attempt; a retried request with the same key is a no-op.",
            "schema": { "type": "string" }
          }
        ],
        "responses": {
          "201": {
            "description": "Success.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": ["data", "meta"],
                  "properties": {
                    "data": {},
                    "meta": {
                      "type": "object",
                      "required": ["requestId"],
                      "properties": {
                        "requestId": { "type": "string" },
                        "version": { "type": "integer" },
                        "nextCursor": { "type": ["string", "null"] },
                        "hasMore": { "type": "boolean" },
                        "total": { "type": "integer" }
                      }
                    }
                  }
                }
              }
            }
          },
          "400": { "$ref": "#/components/responses/ValidationFailed" },
          "401": { "$ref": "#/components/responses/Unauthenticated" },
          "403": { "$ref": "#/components/responses/Forbidden" },
          "429": { "$ref": "#/components/responses/RateLimited" }
        },
        "security": [{ "ApiKeyAuth": [] }],
        "x-medappz-scopes": ["lead.manage"],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "name": { "type": "string", "minLength": 2, "maxLength": 120 },
                  "phone": {
                    "type": "string",
                    "minLength": 7,
                    "maxLength": 20,
                    "pattern": "^[+\\d][\\d\\s-]+$"
                  },
                  "source": {
                    "type": "string",
                    "enum": [
                      "call",
                      "missed_call",
                      "walk-in",
                      "website",
                      "whatsapp",
                      "google_ads",
                      "meta_ads",
                      "justdial",
                      "practo",
                      "referral",
                      "camp",
                      "corporate",
                      "campaign",
                      "other"
                    ]
                  },
                  "interest": { "type": "string", "maxLength": 200 },
                  "note": { "type": "string", "maxLength": 300 },
                  "ownerId": {
                    "type": "string",
                    "format": "uuid",
                    "pattern": "^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$"
                  },
                  "doctorId": {
                    "type": "string",
                    "format": "uuid",
                    "pattern": "^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$"
                  },
                  "campaignId": {
                    "type": "string",
                    "format": "uuid",
                    "pattern": "^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$"
                  },
                  "referrerId": {
                    "type": "string",
                    "format": "uuid",
                    "pattern": "^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$"
                  },
                  "campId": {
                    "type": "string",
                    "format": "uuid",
                    "pattern": "^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$"
                  },
                  "corporateId": {
                    "type": "string",
                    "format": "uuid",
                    "pattern": "^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$"
                  },
                  "externalRef": { "type": "string", "minLength": 1, "maxLength": 200 },
                  "utm": {
                    "type": "object",
                    "propertyNames": { "type": "string", "maxLength": 60 },
                    "additionalProperties": { "type": "string", "maxLength": 300 }
                  },
                  "nextAction": { "type": "string", "maxLength": 200 },
                  "nextActionAt": {
                    "type": "string",
                    "format": "date-time",
                    "pattern": "^(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))T(?:(?:[01]\\d|2[0-3]):[0-5]\\d:[0-5]\\d(?:\\.\\d+)?(?:Z|([+-](?:[01]\\d|2[0-3]):[0-5]\\d)))$"
                  },
                  "marketingOptIn": { "type": "boolean" }
                },
                "required": ["name", "phone"],
                "additionalProperties": false
              }
            }
          }
        }
      }
    },
    "/v1/leads/{id}": {
      "get": {
        "operationId": "getLeadsById",
        "summary": "Detail: leads (one record)",
        "description": "Requires scope: lead.read.",
        "tags": ["Leads and CRM"],
        "parameters": [
          { "name": "id", "in": "path", "required": true, "schema": { "type": "string" } }
        ],
        "responses": {
          "200": {
            "description": "Success.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": ["data", "meta"],
                  "properties": {
                    "data": {},
                    "meta": {
                      "type": "object",
                      "required": ["requestId"],
                      "properties": {
                        "requestId": { "type": "string" },
                        "version": { "type": "integer" },
                        "nextCursor": { "type": ["string", "null"] },
                        "hasMore": { "type": "boolean" },
                        "total": { "type": "integer" }
                      }
                    }
                  }
                }
              }
            }
          },
          "401": { "$ref": "#/components/responses/Unauthenticated" },
          "403": { "$ref": "#/components/responses/Forbidden" },
          "429": { "$ref": "#/components/responses/RateLimited" }
        },
        "security": [{ "ApiKeyAuth": [] }],
        "x-medappz-scopes": ["lead.read"]
      }
    },
    "/v1/leads/{id}/assign": {
      "post": {
        "operationId": "postLeadsByIdAssign",
        "summary": "Assign: leads assign (one record)",
        "description": "Requires scope: lead.manage.",
        "tags": ["Leads and CRM"],
        "parameters": [
          { "name": "id", "in": "path", "required": true, "schema": { "type": "string" } },
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": false,
            "description": "A key you generate per attempt; a retried request with the same key is a no-op.",
            "schema": { "type": "string" }
          }
        ],
        "responses": {
          "201": {
            "description": "Success.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": ["data", "meta"],
                  "properties": {
                    "data": {},
                    "meta": {
                      "type": "object",
                      "required": ["requestId"],
                      "properties": {
                        "requestId": { "type": "string" },
                        "version": { "type": "integer" },
                        "nextCursor": { "type": ["string", "null"] },
                        "hasMore": { "type": "boolean" },
                        "total": { "type": "integer" }
                      }
                    }
                  }
                }
              }
            }
          },
          "400": { "$ref": "#/components/responses/ValidationFailed" },
          "401": { "$ref": "#/components/responses/Unauthenticated" },
          "403": { "$ref": "#/components/responses/Forbidden" },
          "429": { "$ref": "#/components/responses/RateLimited" }
        },
        "security": [{ "ApiKeyAuth": [] }],
        "x-medappz-scopes": ["lead.manage"],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "ownerId": {
                    "anyOf": [
                      {
                        "type": "string",
                        "format": "uuid",
                        "pattern": "^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$"
                      },
                      { "type": "null" }
                    ]
                  }
                },
                "required": ["ownerId"],
                "additionalProperties": false
              }
            }
          }
        }
      }
    },
    "/v1/leads/{id}/booked": {
      "post": {
        "operationId": "postLeadsByIdBooked",
        "summary": "Booked: leads booked (one record)",
        "description": "Requires scope: lead.manage.",
        "tags": ["Leads and CRM"],
        "parameters": [
          { "name": "id", "in": "path", "required": true, "schema": { "type": "string" } },
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": false,
            "description": "A key you generate per attempt; a retried request with the same key is a no-op.",
            "schema": { "type": "string" }
          }
        ],
        "responses": {
          "201": {
            "description": "Success.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": ["data", "meta"],
                  "properties": {
                    "data": {},
                    "meta": {
                      "type": "object",
                      "required": ["requestId"],
                      "properties": {
                        "requestId": { "type": "string" },
                        "version": { "type": "integer" },
                        "nextCursor": { "type": ["string", "null"] },
                        "hasMore": { "type": "boolean" },
                        "total": { "type": "integer" }
                      }
                    }
                  }
                }
              }
            }
          },
          "400": { "$ref": "#/components/responses/ValidationFailed" },
          "401": { "$ref": "#/components/responses/Unauthenticated" },
          "403": { "$ref": "#/components/responses/Forbidden" },
          "429": { "$ref": "#/components/responses/RateLimited" }
        },
        "security": [{ "ApiKeyAuth": [] }],
        "x-medappz-scopes": ["lead.manage"],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "bookingId": {
                    "type": "string",
                    "format": "uuid",
                    "pattern": "^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$"
                  },
                  "note": { "type": "string", "maxLength": 300 }
                },
                "required": ["bookingId"],
                "additionalProperties": false
              }
            }
          }
        }
      }
    },
    "/v1/leads/{id}/contacted": {
      "post": {
        "operationId": "postLeadsByIdContacted",
        "summary": "Contacted: leads contacted (one record)",
        "description": "Requires scope: lead.manage.",
        "tags": ["Leads and CRM"],
        "parameters": [
          { "name": "id", "in": "path", "required": true, "schema": { "type": "string" } },
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": false,
            "description": "A key you generate per attempt; a retried request with the same key is a no-op.",
            "schema": { "type": "string" }
          }
        ],
        "responses": {
          "201": {
            "description": "Success.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": ["data", "meta"],
                  "properties": {
                    "data": {},
                    "meta": {
                      "type": "object",
                      "required": ["requestId"],
                      "properties": {
                        "requestId": { "type": "string" },
                        "version": { "type": "integer" },
                        "nextCursor": { "type": ["string", "null"] },
                        "hasMore": { "type": "boolean" },
                        "total": { "type": "integer" }
                      }
                    }
                  }
                }
              }
            }
          },
          "400": { "$ref": "#/components/responses/ValidationFailed" },
          "401": { "$ref": "#/components/responses/Unauthenticated" },
          "403": { "$ref": "#/components/responses/Forbidden" },
          "429": { "$ref": "#/components/responses/RateLimited" }
        },
        "security": [{ "ApiKeyAuth": [] }],
        "x-medappz-scopes": ["lead.manage"],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": { "note": { "type": "string", "maxLength": 300 } },
                "additionalProperties": false
              }
            }
          }
        }
      }
    },
    "/v1/leads/{id}/convert": {
      "post": {
        "operationId": "postLeadsByIdConvert",
        "summary": "Convert: leads convert (one record)",
        "description": "Requires scope: lead.manage.",
        "tags": ["Leads and CRM"],
        "parameters": [
          { "name": "id", "in": "path", "required": true, "schema": { "type": "string" } },
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": false,
            "description": "A key you generate per attempt; a retried request with the same key is a no-op.",
            "schema": { "type": "string" }
          }
        ],
        "responses": {
          "201": {
            "description": "Success.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": ["data", "meta"],
                  "properties": {
                    "data": {},
                    "meta": {
                      "type": "object",
                      "required": ["requestId"],
                      "properties": {
                        "requestId": { "type": "string" },
                        "version": { "type": "integer" },
                        "nextCursor": { "type": ["string", "null"] },
                        "hasMore": { "type": "boolean" },
                        "total": { "type": "integer" }
                      }
                    }
                  }
                }
              }
            }
          },
          "400": { "$ref": "#/components/responses/ValidationFailed" },
          "401": { "$ref": "#/components/responses/Unauthenticated" },
          "403": { "$ref": "#/components/responses/Forbidden" },
          "429": { "$ref": "#/components/responses/RateLimited" }
        },
        "security": [{ "ApiKeyAuth": [] }],
        "x-medappz-scopes": ["lead.manage"],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "patientId": {
                    "type": "string",
                    "format": "uuid",
                    "pattern": "^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$"
                  }
                },
                "required": ["patientId"],
                "additionalProperties": false
              }
            }
          }
        }
      }
    },
    "/v1/leads/{id}/lost": {
      "post": {
        "operationId": "postLeadsByIdLost",
        "summary": "Lost: leads lost (one record)",
        "description": "Requires scope: lead.manage.",
        "tags": ["Leads and CRM"],
        "parameters": [
          { "name": "id", "in": "path", "required": true, "schema": { "type": "string" } },
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": false,
            "description": "A key you generate per attempt; a retried request with the same key is a no-op.",
            "schema": { "type": "string" }
          }
        ],
        "responses": {
          "201": {
            "description": "Success.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": ["data", "meta"],
                  "properties": {
                    "data": {},
                    "meta": {
                      "type": "object",
                      "required": ["requestId"],
                      "properties": {
                        "requestId": { "type": "string" },
                        "version": { "type": "integer" },
                        "nextCursor": { "type": ["string", "null"] },
                        "hasMore": { "type": "boolean" },
                        "total": { "type": "integer" }
                      }
                    }
                  }
                }
              }
            }
          },
          "400": { "$ref": "#/components/responses/ValidationFailed" },
          "401": { "$ref": "#/components/responses/Unauthenticated" },
          "403": { "$ref": "#/components/responses/Forbidden" },
          "429": { "$ref": "#/components/responses/RateLimited" }
        },
        "security": [{ "ApiKeyAuth": [] }],
        "x-medappz-scopes": ["lead.manage"],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": { "reason": { "type": "string", "minLength": 3, "maxLength": 200 } },
                "required": ["reason"],
                "additionalProperties": false
              }
            }
          }
        }
      }
    },
    "/v1/leads/{id}/next": {
      "post": {
        "operationId": "postLeadsByIdNext",
        "summary": "Next: leads next (one record)",
        "description": "Requires scope: lead.manage.",
        "tags": ["Leads and CRM"],
        "parameters": [
          { "name": "id", "in": "path", "required": true, "schema": { "type": "string" } },
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": false,
            "description": "A key you generate per attempt; a retried request with the same key is a no-op.",
            "schema": { "type": "string" }
          }
        ],
        "responses": {
          "201": {
            "description": "Success.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": ["data", "meta"],
                  "properties": {
                    "data": {},
                    "meta": {
                      "type": "object",
                      "required": ["requestId"],
                      "properties": {
                        "requestId": { "type": "string" },
                        "version": { "type": "integer" },
                        "nextCursor": { "type": ["string", "null"] },
                        "hasMore": { "type": "boolean" },
                        "total": { "type": "integer" }
                      }
                    }
                  }
                }
              }
            }
          },
          "400": { "$ref": "#/components/responses/ValidationFailed" },
          "401": { "$ref": "#/components/responses/Unauthenticated" },
          "403": { "$ref": "#/components/responses/Forbidden" },
          "429": { "$ref": "#/components/responses/RateLimited" }
        },
        "security": [{ "ApiKeyAuth": [] }],
        "x-medappz-scopes": ["lead.manage"],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "text": {
                    "anyOf": [
                      { "type": "string", "minLength": 2, "maxLength": 200 },
                      { "type": "null" }
                    ]
                  },
                  "at": {
                    "anyOf": [
                      {
                        "type": "string",
                        "format": "date-time",
                        "pattern": "^(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))T(?:(?:[01]\\d|2[0-3]):[0-5]\\d:[0-5]\\d(?:\\.\\d+)?(?:Z|([+-](?:[01]\\d|2[0-3]):[0-5]\\d)))$"
                      },
                      { "type": "null" }
                    ]
                  }
                },
                "required": ["text", "at"],
                "additionalProperties": false
              }
            }
          }
        }
      }
    },
    "/v1/leads/attribution": {
      "get": {
        "operationId": "getLeadsAttribution",
        "summary": "AttributionDesk: enquiries credited to sources or campaigns under a model.",
        "description": "Requires scope: lead.read.",
        "tags": ["Leads and CRM"],
        "parameters": [
          { "name": "by", "in": "query", "required": false, "schema": { "type": "string" } },
          { "name": "from", "in": "query", "required": false, "schema": { "type": "string" } },
          { "name": "model", "in": "query", "required": false, "schema": { "type": "string" } },
          { "name": "to", "in": "query", "required": false, "schema": { "type": "string" } }
        ],
        "responses": {
          "200": {
            "description": "Success.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": ["data", "meta"],
                  "properties": {
                    "data": {},
                    "meta": {
                      "type": "object",
                      "required": ["requestId"],
                      "properties": {
                        "requestId": { "type": "string" },
                        "version": { "type": "integer" },
                        "nextCursor": { "type": ["string", "null"] },
                        "hasMore": { "type": "boolean" },
                        "total": { "type": "integer" }
                      }
                    }
                  }
                }
              }
            }
          },
          "401": { "$ref": "#/components/responses/Unauthenticated" },
          "403": { "$ref": "#/components/responses/Forbidden" },
          "429": { "$ref": "#/components/responses/RateLimited" }
        },
        "security": [{ "ApiKeyAuth": [] }],
        "x-medappz-scopes": ["lead.read"]
      }
    },
    "/v1/leads/package-funnel": {
      "get": {
        "operationId": "getLeadsPackageFunnel",
        "summary": "The package funnel branch by branch (Fold sweep 3: AestheticUpsell).",
        "description": "Requires scope: lead.read.",
        "tags": ["Leads and CRM"],
        "parameters": [
          { "name": "from", "in": "query", "required": false, "schema": { "type": "string" } },
          { "name": "to", "in": "query", "required": false, "schema": { "type": "string" } }
        ],
        "responses": {
          "200": {
            "description": "Success.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": ["data", "meta"],
                  "properties": {
                    "data": {},
                    "meta": {
                      "type": "object",
                      "required": ["requestId"],
                      "properties": {
                        "requestId": { "type": "string" },
                        "version": { "type": "integer" },
                        "nextCursor": { "type": ["string", "null"] },
                        "hasMore": { "type": "boolean" },
                        "total": { "type": "integer" }
                      }
                    }
                  }
                }
              }
            }
          },
          "401": { "$ref": "#/components/responses/Unauthenticated" },
          "403": { "$ref": "#/components/responses/Forbidden" },
          "429": { "$ref": "#/components/responses/RateLimited" }
        },
        "security": [{ "ApiKeyAuth": [] }],
        "x-medappz-scopes": ["lead.read"]
      }
    },
    "/v1/leads/sources": {
      "get": {
        "operationId": "getLeadsSources",
        "summary": "Where enquiries come from and what each source costs.",
        "description": "Requires scope: lead.read.",
        "tags": ["Leads and CRM"],
        "parameters": [
          { "name": "from", "in": "query", "required": false, "schema": { "type": "string" } },
          { "name": "to", "in": "query", "required": false, "schema": { "type": "string" } }
        ],
        "responses": {
          "200": {
            "description": "Success.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": ["data", "meta"],
                  "properties": {
                    "data": {},
                    "meta": {
                      "type": "object",
                      "required": ["requestId"],
                      "properties": {
                        "requestId": { "type": "string" },
                        "version": { "type": "integer" },
                        "nextCursor": { "type": ["string", "null"] },
                        "hasMore": { "type": "boolean" },
                        "total": { "type": "integer" }
                      }
                    }
                  }
                }
              }
            }
          },
          "401": { "$ref": "#/components/responses/Unauthenticated" },
          "403": { "$ref": "#/components/responses/Forbidden" },
          "429": { "$ref": "#/components/responses/RateLimited" }
        },
        "security": [{ "ApiKeyAuth": [] }],
        "x-medappz-scopes": ["lead.read"]
      }
    },
    "/v1/leads/spend": {
      "get": {
        "operationId": "getLeadsSpend",
        "summary": "Spend: leads spend",
        "description": "Requires scope: lead.read.",
        "tags": ["Leads and CRM"],
        "parameters": [],
        "responses": {
          "200": {
            "description": "Success.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": ["data", "meta"],
                  "properties": {
                    "data": {},
                    "meta": {
                      "type": "object",
                      "required": ["requestId"],
                      "properties": {
                        "requestId": { "type": "string" },
                        "version": { "type": "integer" },
                        "nextCursor": { "type": ["string", "null"] },
                        "hasMore": { "type": "boolean" },
                        "total": { "type": "integer" }
                      }
                    }
                  }
                }
              }
            }
          },
          "401": { "$ref": "#/components/responses/Unauthenticated" },
          "403": { "$ref": "#/components/responses/Forbidden" },
          "429": { "$ref": "#/components/responses/RateLimited" }
        },
        "security": [{ "ApiKeyAuth": [] }],
        "x-medappz-scopes": ["lead.read"]
      },
      "put": {
        "operationId": "putLeadsSpend",
        "summary": "Set spend: leads spend",
        "description": "Requires scope: lead.manage.",
        "tags": ["Leads and CRM"],
        "parameters": [
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": false,
            "description": "A key you generate per attempt; a retried request with the same key is a no-op.",
            "schema": { "type": "string" }
          }
        ],
        "responses": {
          "200": {
            "description": "Success.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": ["data", "meta"],
                  "properties": {
                    "data": {},
                    "meta": {
                      "type": "object",
                      "required": ["requestId"],
                      "properties": {
                        "requestId": { "type": "string" },
                        "version": { "type": "integer" },
                        "nextCursor": { "type": ["string", "null"] },
                        "hasMore": { "type": "boolean" },
                        "total": { "type": "integer" }
                      }
                    }
                  }
                }
              }
            }
          },
          "400": { "$ref": "#/components/responses/ValidationFailed" },
          "401": { "$ref": "#/components/responses/Unauthenticated" },
          "403": { "$ref": "#/components/responses/Forbidden" },
          "429": { "$ref": "#/components/responses/RateLimited" }
        },
        "security": [{ "ApiKeyAuth": [] }],
        "x-medappz-scopes": ["lead.manage"],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "source": {
                    "type": "string",
                    "enum": [
                      "call",
                      "missed_call",
                      "walk-in",
                      "website",
                      "whatsapp",
                      "google_ads",
                      "meta_ads",
                      "justdial",
                      "practo",
                      "referral",
                      "camp",
                      "corporate",
                      "campaign",
                      "other"
                    ]
                  },
                  "month": { "type": "string", "pattern": "^\\d{4}-\\d{2}-\\d{2}$" },
                  "rupees": { "type": "number", "minimum": 0, "maximum": 100000000 },
                  "note": { "type": "string", "maxLength": 200 }
                },
                "required": ["source", "month", "rupees"],
                "additionalProperties": false
              }
            }
          }
        }
      }
    },
    "/v1/patient-messages": {
      "get": {
        "operationId": "getPatientMessages",
        "summary": "Desk threads: patient messages",
        "description": "Requires scope: patient.read.",
        "tags": ["Patientcare"],
        "parameters": [],
        "responses": {
          "200": {
            "description": "Success.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": ["data", "meta"],
                  "properties": {
                    "data": {},
                    "meta": {
                      "type": "object",
                      "required": ["requestId"],
                      "properties": {
                        "requestId": { "type": "string" },
                        "version": { "type": "integer" },
                        "nextCursor": { "type": ["string", "null"] },
                        "hasMore": { "type": "boolean" },
                        "total": { "type": "integer" }
                      }
                    }
                  }
                }
              }
            }
          },
          "401": { "$ref": "#/components/responses/Unauthenticated" },
          "403": { "$ref": "#/components/responses/Forbidden" },
          "429": { "$ref": "#/components/responses/RateLimited" }
        },
        "security": [{ "ApiKeyAuth": [] }],
        "x-medappz-scopes": ["patient.read"]
      }
    },
    "/v1/patient-messages/{threadId}": {
      "get": {
        "operationId": "getPatientMessagesByThreadId",
        "summary": "Desk thread: patient messages (one record)",
        "description": "Requires scope: patient.read.",
        "tags": ["Patientcare"],
        "parameters": [
          { "name": "threadId", "in": "path", "required": true, "schema": { "type": "string" } }
        ],
        "responses": {
          "200": {
            "description": "Success.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": ["data", "meta"],
                  "properties": {
                    "data": {},
                    "meta": {
                      "type": "object",
                      "required": ["requestId"],
                      "properties": {
                        "requestId": { "type": "string" },
                        "version": { "type": "integer" },
                        "nextCursor": { "type": ["string", "null"] },
                        "hasMore": { "type": "boolean" },
                        "total": { "type": "integer" }
                      }
                    }
                  }
                }
              }
            }
          },
          "401": { "$ref": "#/components/responses/Unauthenticated" },
          "403": { "$ref": "#/components/responses/Forbidden" },
          "429": { "$ref": "#/components/responses/RateLimited" }
        },
        "security": [{ "ApiKeyAuth": [] }],
        "x-medappz-scopes": ["patient.read"]
      }
    },
    "/v1/patient-zara/messages": {
      "get": {
        "operationId": "getPatientZaraMessages",
        "summary": "Messages and red flags patients left with Rain: open first.",
        "description": "Requires scope: patient.read.",
        "tags": ["Patients"],
        "parameters": [],
        "responses": {
          "200": {
            "description": "Success.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": ["data", "meta"],
                  "properties": {
                    "data": {},
                    "meta": {
                      "type": "object",
                      "required": ["requestId"],
                      "properties": {
                        "requestId": { "type": "string" },
                        "version": { "type": "integer" },
                        "nextCursor": { "type": ["string", "null"] },
                        "hasMore": { "type": "boolean" },
                        "total": { "type": "integer" }
                      }
                    }
                  }
                }
              }
            }
          },
          "401": { "$ref": "#/components/responses/Unauthenticated" },
          "403": { "$ref": "#/components/responses/Forbidden" },
          "429": { "$ref": "#/components/responses/RateLimited" }
        },
        "security": [{ "ApiKeyAuth": [] }],
        "x-medappz-scopes": ["patient.read"]
      }
    },
    "/v1/patients/{patientId}": {
      "get": {
        "operationId": "getPatientsByPatientId",
        "summary": "The full record needs a care relationship, not just the permission. Holding `patient.read` lets you read *a* patient, never *this* one.",
        "description": "Requires scope: patient.read.",
        "tags": ["Patients"],
        "parameters": [
          { "name": "patientId", "in": "path", "required": true, "schema": { "type": "string" } }
        ],
        "responses": {
          "200": {
            "description": "Success.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": ["data", "meta"],
                  "properties": {
                    "data": {},
                    "meta": {
                      "type": "object",
                      "required": ["requestId"],
                      "properties": {
                        "requestId": { "type": "string" },
                        "version": { "type": "integer" },
                        "nextCursor": { "type": ["string", "null"] },
                        "hasMore": { "type": "boolean" },
                        "total": { "type": "integer" }
                      }
                    }
                  }
                }
              }
            }
          },
          "401": { "$ref": "#/components/responses/Unauthenticated" },
          "403": { "$ref": "#/components/responses/Forbidden" },
          "429": { "$ref": "#/components/responses/RateLimited" }
        },
        "security": [{ "ApiKeyAuth": [] }],
        "x-medappz-scopes": ["patient.read"]
      }
    },
    "/v1/patients/{patientId}/appointments": {
      "get": {
        "operationId": "getPatientsByPatientIdAppointments",
        "summary": "Patient appointments: patients appointments (one record)",
        "description": "Requires scope: appointment.read.",
        "tags": ["Appointments and availability"],
        "parameters": [
          { "name": "patientId", "in": "path", "required": true, "schema": { "type": "string" } }
        ],
        "responses": {
          "200": {
            "description": "Success.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": ["data", "meta"],
                  "properties": {
                    "data": {},
                    "meta": {
                      "type": "object",
                      "required": ["requestId"],
                      "properties": {
                        "requestId": { "type": "string" },
                        "version": { "type": "integer" },
                        "nextCursor": { "type": ["string", "null"] },
                        "hasMore": { "type": "boolean" },
                        "total": { "type": "integer" }
                      }
                    }
                  }
                }
              }
            }
          },
          "401": { "$ref": "#/components/responses/Unauthenticated" },
          "403": { "$ref": "#/components/responses/Forbidden" },
          "429": { "$ref": "#/components/responses/RateLimited" }
        },
        "security": [{ "ApiKeyAuth": [] }],
        "x-medappz-scopes": ["appointment.read"]
      }
    },
    "/v1/patients/{patientId}/chart": {
      "get": {
        "operationId": "getPatientsByPatientIdChart",
        "summary": "Chart: patients chart (one record)",
        "description": "Requires scope: patient.read.",
        "tags": ["Appointments and availability"],
        "parameters": [
          { "name": "patientId", "in": "path", "required": true, "schema": { "type": "string" } }
        ],
        "responses": {
          "200": {
            "description": "Success.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": ["data", "meta"],
                  "properties": {
                    "data": {},
                    "meta": {
                      "type": "object",
                      "required": ["requestId"],
                      "properties": {
                        "requestId": { "type": "string" },
                        "version": { "type": "integer" },
                        "nextCursor": { "type": ["string", "null"] },
                        "hasMore": { "type": "boolean" },
                        "total": { "type": "integer" }
                      }
                    }
                  }
                }
              }
            }
          },
          "401": { "$ref": "#/components/responses/Unauthenticated" },
          "403": { "$ref": "#/components/responses/Forbidden" },
          "429": { "$ref": "#/components/responses/RateLimited" }
        },
        "security": [{ "ApiKeyAuth": [] }],
        "x-medappz-scopes": ["patient.read"]
      }
    },
    "/v1/patients/by-mrn/{mrn}": {
      "get": {
        "operationId": "getPatientsByMrnByMrn",
        "summary": "By mrn: patients by mrn (one record)",
        "description": "Requires scope: patient.read.",
        "tags": ["Patients"],
        "parameters": [
          { "name": "mrn", "in": "path", "required": true, "schema": { "type": "string" } }
        ],
        "responses": {
          "200": {
            "description": "Success.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": ["data", "meta"],
                  "properties": {
                    "data": {},
                    "meta": {
                      "type": "object",
                      "required": ["requestId"],
                      "properties": {
                        "requestId": { "type": "string" },
                        "version": { "type": "integer" },
                        "nextCursor": { "type": ["string", "null"] },
                        "hasMore": { "type": "boolean" },
                        "total": { "type": "integer" }
                      }
                    }
                  }
                }
              }
            }
          },
          "401": { "$ref": "#/components/responses/Unauthenticated" },
          "403": { "$ref": "#/components/responses/Forbidden" },
          "429": { "$ref": "#/components/responses/RateLimited" }
        },
        "security": [{ "ApiKeyAuth": [] }],
        "x-medappz-scopes": ["patient.read"]
      }
    },
    "/v1/patients/duplicate-check": {
      "post": {
        "operationId": "postPatientsDuplicateCheck",
        "summary": "Called as the clerk types, before anything is created.",
        "description": "Requires scope: patient.read.",
        "tags": ["Patients"],
        "parameters": [
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": false,
            "description": "A key you generate per attempt; a retried request with the same key is a no-op.",
            "schema": { "type": "string" }
          }
        ],
        "responses": {
          "201": {
            "description": "Success.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": ["data", "meta"],
                  "properties": {
                    "data": {},
                    "meta": {
                      "type": "object",
                      "required": ["requestId"],
                      "properties": {
                        "requestId": { "type": "string" },
                        "version": { "type": "integer" },
                        "nextCursor": { "type": ["string", "null"] },
                        "hasMore": { "type": "boolean" },
                        "total": { "type": "integer" }
                      }
                    }
                  }
                }
              }
            }
          },
          "400": { "$ref": "#/components/responses/ValidationFailed" },
          "401": { "$ref": "#/components/responses/Unauthenticated" },
          "403": { "$ref": "#/components/responses/Forbidden" },
          "429": { "$ref": "#/components/responses/RateLimited" }
        },
        "security": [{ "ApiKeyAuth": [] }],
        "x-medappz-scopes": ["patient.read"],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "givenName": { "type": "string", "minLength": 1, "maxLength": 120 },
                  "familyName": { "type": "string", "minLength": 1, "maxLength": 120 },
                  "birthDate": {
                    "type": "string",
                    "format": "date",
                    "pattern": "^(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))$"
                  },
                  "sex": { "type": "string", "maxLength": 20 },
                  "locality": { "type": "string", "maxLength": 120 },
                  "phone": { "type": "string", "minLength": 6, "maxLength": 20 },
                  "identifiers": {
                    "maxItems": 10,
                    "type": "array",
                    "items": {
                      "type": "object",
                      "properties": {
                        "type": {
                          "type": "string",
                          "enum": [
                            "aadhaar",
                            "abha",
                            "pan",
                            "voter_id",
                            "ration_card",
                            "passport",
                            "driving_licence",
                            "insurance",
                            "other_mrn",
                            "national_id",
                            "mrn",
                            "ssn",
                            "nhs_number",
                            "nhif_number",
                            "nhis_number",
                            "medical_scheme",
                            "emirates_id",
                            "iqama",
                            "medicare_number",
                            "cpf"
                          ]
                        },
                        "value": { "type": "string", "minLength": 3, "maxLength": 60 }
                      },
                      "required": ["type", "value"],
                      "additionalProperties": false
                    }
                  }
                },
                "required": ["givenName", "familyName"],
                "additionalProperties": false
              }
            }
          }
        }
      }
    },
    "/v1/patients/intake": {
      "post": {
        "operationId": "postPatientsIntake",
        "summary": "Register a patient; a strong duplicate is refused until confirmedNotDuplicate is sent.",
        "description": "Requires scope: patient.intake.",
        "tags": ["Patients"],
        "parameters": [
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": false,
            "description": "A key you generate per attempt; a retried request with the same key is a no-op.",
            "schema": { "type": "string" }
          }
        ],
        "responses": {
          "201": {
            "description": "Success.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": ["data", "meta"],
                  "properties": {
                    "data": {},
                    "meta": {
                      "type": "object",
                      "required": ["requestId"],
                      "properties": {
                        "requestId": { "type": "string" },
                        "version": { "type": "integer" },
                        "nextCursor": { "type": ["string", "null"] },
                        "hasMore": { "type": "boolean" },
                        "total": { "type": "integer" }
                      }
                    }
                  }
                }
              }
            }
          },
          "400": { "$ref": "#/components/responses/ValidationFailed" },
          "401": { "$ref": "#/components/responses/Unauthenticated" },
          "403": { "$ref": "#/components/responses/Forbidden" },
          "429": { "$ref": "#/components/responses/RateLimited" }
        },
        "security": [{ "ApiKeyAuth": [] }],
        "x-medappz-scopes": ["patient.intake"],
        "x-medappz-rate-limit": "120/min",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "givenName": { "type": "string", "minLength": 1, "maxLength": 120 },
                  "familyName": { "type": "string", "minLength": 1, "maxLength": 120 },
                  "nameLocal": { "type": "string", "maxLength": 200 },
                  "preferredName": { "type": "string", "maxLength": 120 },
                  "birthDate": {
                    "type": "string",
                    "format": "date",
                    "pattern": "^(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))$"
                  },
                  "ageYears": { "type": "integer", "minimum": 0, "maximum": 130 },
                  "sex": { "type": "string", "enum": ["male", "female", "other", "unknown"] },
                  "phonePrimary": { "type": "string", "minLength": 6, "maxLength": 20 },
                  "phoneAlt": { "type": "string", "minLength": 6, "maxLength": 20 },
                  "email": {
                    "type": "string",
                    "maxLength": 200,
                    "format": "email",
                    "pattern": "^(?:[A-Za-z0-9_'+\\-]+\\.)*[A-Za-z0-9_'+\\-]*[A-Za-z0-9_+-]@(?:[A-Za-z0-9][A-Za-z0-9\\-]*\\.)+[A-Za-z]{2,}$"
                  },
                  "addressLine": { "type": "string", "maxLength": 300 },
                  "locality": { "type": "string", "maxLength": 120 },
                  "city": { "type": "string", "maxLength": 120 },
                  "state": { "type": "string", "maxLength": 120 },
                  "postalCode": { "type": "string", "maxLength": 12 },
                  "emergencyContactName": { "type": "string", "maxLength": 200 },
                  "emergencyContactPhone": { "type": "string", "maxLength": 20 },
                  "emergencyContactRelation": { "type": "string", "maxLength": 60 },
                  "identifiers": {
                    "maxItems": 10,
                    "type": "array",
                    "items": {
                      "type": "object",
                      "properties": {
                        "type": {
                          "type": "string",
                          "enum": [
                            "aadhaar",
                            "abha",
                            "pan",
                            "voter_id",
                            "ration_card",
                            "passport",
                            "driving_licence",
                            "insurance",
                            "other_mrn",
                            "national_id",
                            "mrn",
                            "ssn",
                            "nhs_number",
                            "nhif_number",
                            "nhis_number",
                            "medical_scheme",
                            "emirates_id",
                            "iqama",
                            "medicare_number",
                            "cpf"
                          ]
                        },
                        "value": { "type": "string", "minLength": 3, "maxLength": 60 }
                      },
                      "required": ["type", "value"],
                      "additionalProperties": false
                    }
                  },
                  "confirmedNotDuplicate": { "type": "boolean" },
                  "facilityId": {
                    "type": "string",
                    "format": "uuid",
                    "pattern": "^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$"
                  }
                },
                "required": ["givenName", "familyName"],
                "additionalProperties": false
              }
            }
          }
        }
      }
    },
    "/v1/patients/intake/duplicate-check": {
      "post": {
        "operationId": "postPatientsIntakeDuplicateCheck",
        "summary": "Look for an existing record before registering; phones come back masked.",
        "description": "Requires scope: patient.intake.",
        "tags": ["Patients"],
        "parameters": [
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": false,
            "description": "A key you generate per attempt; a retried request with the same key is a no-op.",
            "schema": { "type": "string" }
          }
        ],
        "responses": {
          "201": {
            "description": "Success.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": ["data", "meta"],
                  "properties": {
                    "data": {},
                    "meta": {
                      "type": "object",
                      "required": ["requestId"],
                      "properties": {
                        "requestId": { "type": "string" },
                        "version": { "type": "integer" },
                        "nextCursor": { "type": ["string", "null"] },
                        "hasMore": { "type": "boolean" },
                        "total": { "type": "integer" }
                      }
                    }
                  }
                }
              }
            }
          },
          "400": { "$ref": "#/components/responses/ValidationFailed" },
          "401": { "$ref": "#/components/responses/Unauthenticated" },
          "403": { "$ref": "#/components/responses/Forbidden" },
          "429": { "$ref": "#/components/responses/RateLimited" }
        },
        "security": [{ "ApiKeyAuth": [] }],
        "x-medappz-scopes": ["patient.intake"],
        "x-medappz-rate-limit": "120/min",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "givenName": { "type": "string", "minLength": 1, "maxLength": 120 },
                  "familyName": { "type": "string", "minLength": 1, "maxLength": 120 },
                  "birthDate": {
                    "type": "string",
                    "format": "date",
                    "pattern": "^(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))$"
                  },
                  "sex": { "type": "string", "maxLength": 20 },
                  "locality": { "type": "string", "maxLength": 120 },
                  "phone": { "type": "string", "minLength": 6, "maxLength": 20 },
                  "identifiers": {
                    "maxItems": 10,
                    "type": "array",
                    "items": {
                      "type": "object",
                      "properties": {
                        "type": {
                          "type": "string",
                          "enum": [
                            "aadhaar",
                            "abha",
                            "pan",
                            "voter_id",
                            "ration_card",
                            "passport",
                            "driving_licence",
                            "insurance",
                            "other_mrn",
                            "national_id",
                            "mrn",
                            "ssn",
                            "nhs_number",
                            "nhif_number",
                            "nhis_number",
                            "medical_scheme",
                            "emirates_id",
                            "iqama",
                            "medicare_number",
                            "cpf"
                          ]
                        },
                        "value": { "type": "string", "minLength": 3, "maxLength": 60 }
                      },
                      "required": ["type", "value"],
                      "additionalProperties": false
                    }
                  }
                },
                "required": ["givenName", "familyName"],
                "additionalProperties": false
              }
            }
          }
        }
      }
    },
    "/v1/patients/search": {
      "get": {
        "operationId": "getPatientsSearch",
        "summary": "Search: patients search",
        "description": "Requires scope: patient.read.",
        "tags": ["Patients"],
        "parameters": [
          { "name": "limit", "in": "query", "required": false, "schema": { "type": "string" } },
          { "name": "q", "in": "query", "required": false, "schema": { "type": "string" } }
        ],
        "responses": {
          "200": {
            "description": "Success.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": ["data", "meta"],
                  "properties": {
                    "data": {},
                    "meta": {
                      "type": "object",
                      "required": ["requestId"],
                      "properties": {
                        "requestId": { "type": "string" },
                        "version": { "type": "integer" },
                        "nextCursor": { "type": ["string", "null"] },
                        "hasMore": { "type": "boolean" },
                        "total": { "type": "integer" }
                      }
                    }
                  }
                }
              }
            }
          },
          "401": { "$ref": "#/components/responses/Unauthenticated" },
          "403": { "$ref": "#/components/responses/Forbidden" },
          "429": { "$ref": "#/components/responses/RateLimited" }
        },
        "security": [{ "ApiKeyAuth": [] }],
        "x-medappz-scopes": ["patient.read"]
      }
    },
    "/v1/pharmacy/feed/dispense-queue": {
      "get": {
        "operationId": "getPharmacyFeedDispenseQueue",
        "summary": "Prescriptions waiting to be dispensed: medicine and quantity per line, patient id and MRN.",
        "description": "Requires scope: pharmacy.feed.read.",
        "tags": ["Dispensedesk"],
        "parameters": [
          { "name": "limit", "in": "query", "required": false, "schema": { "type": "string" } }
        ],
        "responses": {
          "200": {
            "description": "Success.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": ["data", "meta"],
                  "properties": {
                    "data": {},
                    "meta": {
                      "type": "object",
                      "required": ["requestId"],
                      "properties": {
                        "requestId": { "type": "string" },
                        "version": { "type": "integer" },
                        "nextCursor": { "type": ["string", "null"] },
                        "hasMore": { "type": "boolean" },
                        "total": { "type": "integer" }
                      }
                    }
                  }
                }
              }
            }
          },
          "401": { "$ref": "#/components/responses/Unauthenticated" },
          "403": { "$ref": "#/components/responses/Forbidden" },
          "429": { "$ref": "#/components/responses/RateLimited" }
        },
        "security": [{ "ApiKeyAuth": [] }],
        "x-medappz-scopes": ["pharmacy.feed.read"]
      }
    },
    "/v1/pharmacy/feed/expiring": {
      "get": {
        "operationId": "getPharmacyFeedExpiring",
        "summary": "Batches on the shelf that expire within `withinDays` (default 60), or already have.",
        "description": "Requires scope: pharmacy.feed.read.",
        "tags": ["Dispensedesk"],
        "parameters": [
          { "name": "withinDays", "in": "query", "required": false, "schema": { "type": "string" } }
        ],
        "responses": {
          "200": {
            "description": "Success.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": ["data", "meta"],
                  "properties": {
                    "data": {},
                    "meta": {
                      "type": "object",
                      "required": ["requestId"],
                      "properties": {
                        "requestId": { "type": "string" },
                        "version": { "type": "integer" },
                        "nextCursor": { "type": ["string", "null"] },
                        "hasMore": { "type": "boolean" },
                        "total": { "type": "integer" }
                      }
                    }
                  }
                }
              }
            }
          },
          "401": { "$ref": "#/components/responses/Unauthenticated" },
          "403": { "$ref": "#/components/responses/Forbidden" },
          "429": { "$ref": "#/components/responses/RateLimited" }
        },
        "security": [{ "ApiKeyAuth": [] }],
        "x-medappz-scopes": ["pharmacy.feed.read"]
      }
    },
    "/v1/pharmacy/feed/stock": {
      "get": {
        "operationId": "getPharmacyFeedStock",
        "summary": "Stock per item — on hand, reorder level, low, expiring soon; filter `low` or `expiring`.",
        "description": "Requires scope: pharmacy.feed.read.",
        "tags": ["Dispensedesk"],
        "parameters": [
          { "name": "filter", "in": "query", "required": false, "schema": { "type": "string" } }
        ],
        "responses": {
          "200": {
            "description": "Success.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": ["data", "meta"],
                  "properties": {
                    "data": {},
                    "meta": {
                      "type": "object",
                      "required": ["requestId"],
                      "properties": {
                        "requestId": { "type": "string" },
                        "version": { "type": "integer" },
                        "nextCursor": { "type": ["string", "null"] },
                        "hasMore": { "type": "boolean" },
                        "total": { "type": "integer" }
                      }
                    }
                  }
                }
              }
            }
          },
          "401": { "$ref": "#/components/responses/Unauthenticated" },
          "403": { "$ref": "#/components/responses/Forbidden" },
          "429": { "$ref": "#/components/responses/RateLimited" }
        },
        "security": [{ "ApiKeyAuth": [] }],
        "x-medappz-scopes": ["pharmacy.feed.read"]
      }
    },
    "/v1/portal-access": {
      "get": {
        "operationId": "getPortalAccess",
        "summary": "Status: portal access",
        "description": "Requires scope: patient.read.",
        "tags": ["Patients"],
        "parameters": [
          { "name": "patientId", "in": "query", "required": false, "schema": { "type": "string" } }
        ],
        "responses": {
          "200": {
            "description": "Success.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": ["data", "meta"],
                  "properties": {
                    "data": {},
                    "meta": {
                      "type": "object",
                      "required": ["requestId"],
                      "properties": {
                        "requestId": { "type": "string" },
                        "version": { "type": "integer" },
                        "nextCursor": { "type": ["string", "null"] },
                        "hasMore": { "type": "boolean" },
                        "total": { "type": "integer" }
                      }
                    }
                  }
                }
              }
            }
          },
          "401": { "$ref": "#/components/responses/Unauthenticated" },
          "403": { "$ref": "#/components/responses/Forbidden" },
          "429": { "$ref": "#/components/responses/RateLimited" }
        },
        "security": [{ "ApiKeyAuth": [] }],
        "x-medappz-scopes": ["patient.read"]
      }
    },
    "/v1/quotes": {
      "get": {
        "operationId": "getQuotes",
        "summary": "List: quotes",
        "description": "Requires scope: quote.read.",
        "tags": ["Leads and CRM"],
        "parameters": [],
        "responses": {
          "200": {
            "description": "Success.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": ["data", "meta"],
                  "properties": {
                    "data": {},
                    "meta": {
                      "type": "object",
                      "required": ["requestId"],
                      "properties": {
                        "requestId": { "type": "string" },
                        "version": { "type": "integer" },
                        "nextCursor": { "type": ["string", "null"] },
                        "hasMore": { "type": "boolean" },
                        "total": { "type": "integer" }
                      }
                    }
                  }
                }
              }
            }
          },
          "401": { "$ref": "#/components/responses/Unauthenticated" },
          "403": { "$ref": "#/components/responses/Forbidden" },
          "429": { "$ref": "#/components/responses/RateLimited" }
        },
        "security": [{ "ApiKeyAuth": [] }],
        "x-medappz-scopes": ["quote.read"]
      }
    },
    "/v1/registration-requests": {
      "get": {
        "operationId": "getRegistrationRequests",
        "summary": "List: registration requests",
        "description": "Requires scope: patient.read.",
        "tags": ["Patients"],
        "parameters": [
          { "name": "status", "in": "query", "required": false, "schema": { "type": "string" } }
        ],
        "responses": {
          "200": {
            "description": "Success.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": ["data", "meta"],
                  "properties": {
                    "data": {},
                    "meta": {
                      "type": "object",
                      "required": ["requestId"],
                      "properties": {
                        "requestId": { "type": "string" },
                        "version": { "type": "integer" },
                        "nextCursor": { "type": ["string", "null"] },
                        "hasMore": { "type": "boolean" },
                        "total": { "type": "integer" }
                      }
                    }
                  }
                }
              }
            }
          },
          "401": { "$ref": "#/components/responses/Unauthenticated" },
          "403": { "$ref": "#/components/responses/Forbidden" },
          "429": { "$ref": "#/components/responses/RateLimited" }
        },
        "security": [{ "ApiKeyAuth": [] }],
        "x-medappz-scopes": ["patient.read"]
      }
    },
    "/v1/scheduling/bookings": {
      "get": {
        "operationId": "getSchedulingBookings",
        "summary": "Bookings: scheduling bookings",
        "description": "Requires scope: appointment.read.",
        "tags": ["Appointments and availability"],
        "parameters": [
          { "name": "limit", "in": "query", "required": false, "schema": { "type": "string" } },
          { "name": "subjectId", "in": "query", "required": false, "schema": { "type": "string" } },
          {
            "name": "subjectType",
            "in": "query",
            "required": false,
            "schema": { "type": "string" }
          }
        ],
        "responses": {
          "200": {
            "description": "Success.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": ["data", "meta"],
                  "properties": {
                    "data": {},
                    "meta": {
                      "type": "object",
                      "required": ["requestId"],
                      "properties": {
                        "requestId": { "type": "string" },
                        "version": { "type": "integer" },
                        "nextCursor": { "type": ["string", "null"] },
                        "hasMore": { "type": "boolean" },
                        "total": { "type": "integer" }
                      }
                    }
                  }
                }
              }
            }
          },
          "401": { "$ref": "#/components/responses/Unauthenticated" },
          "403": { "$ref": "#/components/responses/Forbidden" },
          "429": { "$ref": "#/components/responses/RateLimited" }
        },
        "security": [{ "ApiKeyAuth": [] }],
        "x-medappz-scopes": ["appointment.read"]
      }
    },
    "/v1/scheduling/bookings/{groupId}/card": {
      "get": {
        "operationId": "getSchedulingBookingsByGroupIdCard",
        "summary": "One appointment as a confirmation reads it: doctor, type, prep note, when.",
        "description": "Requires scope: appointment.read.",
        "tags": ["Appointments and availability"],
        "parameters": [
          { "name": "groupId", "in": "path", "required": true, "schema": { "type": "string" } }
        ],
        "responses": {
          "200": {
            "description": "Success.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": ["data", "meta"],
                  "properties": {
                    "data": {},
                    "meta": {
                      "type": "object",
                      "required": ["requestId"],
                      "properties": {
                        "requestId": { "type": "string" },
                        "version": { "type": "integer" },
                        "nextCursor": { "type": ["string", "null"] },
                        "hasMore": { "type": "boolean" },
                        "total": { "type": "integer" }
                      }
                    }
                  }
                }
              }
            }
          },
          "401": { "$ref": "#/components/responses/Unauthenticated" },
          "403": { "$ref": "#/components/responses/Forbidden" },
          "429": { "$ref": "#/components/responses/RateLimited" }
        },
        "security": [{ "ApiKeyAuth": [] }],
        "x-medappz-scopes": ["appointment.read"]
      }
    },
    "/v1/scheduling/bookings/{groupId}/ics": {
      "get": {
        "operationId": "getSchedulingBookingsByGroupIdIcs",
        "summary": "The same appointment as a calendar file for a phone.",
        "description": "Requires scope: appointment.read.",
        "tags": ["Appointments and availability"],
        "parameters": [
          { "name": "groupId", "in": "path", "required": true, "schema": { "type": "string" } }
        ],
        "responses": {
          "200": {
            "description": "Success.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": ["data", "meta"],
                  "properties": {
                    "data": {},
                    "meta": {
                      "type": "object",
                      "required": ["requestId"],
                      "properties": {
                        "requestId": { "type": "string" },
                        "version": { "type": "integer" },
                        "nextCursor": { "type": ["string", "null"] },
                        "hasMore": { "type": "boolean" },
                        "total": { "type": "integer" }
                      }
                    }
                  }
                }
              }
            }
          },
          "401": { "$ref": "#/components/responses/Unauthenticated" },
          "403": { "$ref": "#/components/responses/Forbidden" },
          "429": { "$ref": "#/components/responses/RateLimited" }
        },
        "security": [{ "ApiKeyAuth": [] }],
        "x-medappz-scopes": ["appointment.read"]
      }
    },
    "/v1/scheduling/diary": {
      "get": {
        "operationId": "getSchedulingDiary",
        "summary": "The calendar's read: a day or a week of bookings with the patient's name, the type and the state on each, for every resource at once.",
        "description": "Requires scope: appointment.read.",
        "tags": ["Appointments and availability"],
        "parameters": [
          {
            "name": "facilityId",
            "in": "query",
            "required": false,
            "schema": { "type": "string" }
          },
          { "name": "from", "in": "query", "required": false, "schema": { "type": "string" } },
          {
            "name": "schedulableId",
            "in": "query",
            "required": false,
            "schema": { "type": "string" }
          },
          { "name": "to", "in": "query", "required": false, "schema": { "type": "string" } }
        ],
        "responses": {
          "200": {
            "description": "Success.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": ["data", "meta"],
                  "properties": {
                    "data": {},
                    "meta": {
                      "type": "object",
                      "required": ["requestId"],
                      "properties": {
                        "requestId": { "type": "string" },
                        "version": { "type": "integer" },
                        "nextCursor": { "type": ["string", "null"] },
                        "hasMore": { "type": "boolean" },
                        "total": { "type": "integer" }
                      }
                    }
                  }
                }
              }
            }
          },
          "401": { "$ref": "#/components/responses/Unauthenticated" },
          "403": { "$ref": "#/components/responses/Forbidden" },
          "429": { "$ref": "#/components/responses/RateLimited" }
        },
        "security": [{ "ApiKeyAuth": [] }],
        "x-medappz-scopes": ["appointment.read"]
      }
    },
    "/v1/scheduling/intake/bookings": {
      "post": {
        "operationId": "postSchedulingIntakeBookings",
        "summary": "Book a patient of this clinic into an open slot.",
        "description": "Requires scope: appointment.intake.",
        "tags": ["Appointments and availability"],
        "parameters": [
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": false,
            "description": "A key you generate per attempt; a retried request with the same key is a no-op.",
            "schema": { "type": "string" }
          }
        ],
        "responses": {
          "201": {
            "description": "Success.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": ["data", "meta"],
                  "properties": {
                    "data": {},
                    "meta": {
                      "type": "object",
                      "required": ["requestId"],
                      "properties": {
                        "requestId": { "type": "string" },
                        "version": { "type": "integer" },
                        "nextCursor": { "type": ["string", "null"] },
                        "hasMore": { "type": "boolean" },
                        "total": { "type": "integer" }
                      }
                    }
                  }
                }
              }
            }
          },
          "400": { "$ref": "#/components/responses/ValidationFailed" },
          "401": { "$ref": "#/components/responses/Unauthenticated" },
          "403": { "$ref": "#/components/responses/Forbidden" },
          "429": { "$ref": "#/components/responses/RateLimited" }
        },
        "security": [{ "ApiKeyAuth": [] }],
        "x-medappz-scopes": ["appointment.intake"],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "slotId": {
                    "type": "string",
                    "format": "uuid",
                    "pattern": "^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$"
                  },
                  "patientId": {
                    "type": "string",
                    "format": "uuid",
                    "pattern": "^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$"
                  },
                  "serviceType": { "type": "string", "minLength": 1, "maxLength": 60 },
                  "appointmentTypeId": {
                    "type": "string",
                    "format": "uuid",
                    "pattern": "^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$"
                  },
                  "reference": { "type": "string", "minLength": 1, "maxLength": 120 }
                },
                "required": ["slotId", "patientId"],
                "additionalProperties": false
              }
            }
          }
        }
      }
    },
    "/v1/scheduling/intake/bookings/{groupId}/cancel": {
      "post": {
        "operationId": "postSchedulingIntakeBookingsByGroupIdCancel",
        "summary": "Cancel a patient's booking, with the reason the patient gave.",
        "description": "Requires scope: appointment.intake.",
        "tags": ["Appointments and availability"],
        "parameters": [
          { "name": "groupId", "in": "path", "required": true, "schema": { "type": "string" } },
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": false,
            "description": "A key you generate per attempt; a retried request with the same key is a no-op.",
            "schema": { "type": "string" }
          }
        ],
        "responses": {
          "201": {
            "description": "Success.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": ["data", "meta"],
                  "properties": {
                    "data": {},
                    "meta": {
                      "type": "object",
                      "required": ["requestId"],
                      "properties": {
                        "requestId": { "type": "string" },
                        "version": { "type": "integer" },
                        "nextCursor": { "type": ["string", "null"] },
                        "hasMore": { "type": "boolean" },
                        "total": { "type": "integer" }
                      }
                    }
                  }
                }
              }
            }
          },
          "400": { "$ref": "#/components/responses/ValidationFailed" },
          "401": { "$ref": "#/components/responses/Unauthenticated" },
          "403": { "$ref": "#/components/responses/Forbidden" },
          "429": { "$ref": "#/components/responses/RateLimited" }
        },
        "security": [{ "ApiKeyAuth": [] }],
        "x-medappz-scopes": ["appointment.intake"],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": { "reason": { "type": "string", "minLength": 3, "maxLength": 500 } },
                "required": ["reason"],
                "additionalProperties": false
              }
            }
          }
        }
      }
    },
    "/v1/scheduling/intake/bookings/{groupId}/reschedule": {
      "post": {
        "operationId": "postSchedulingIntakeBookingsByGroupIdReschedule",
        "summary": "Move a patient's booking to another open slot; the old one is released.",
        "description": "Requires scope: appointment.intake.",
        "tags": ["Appointments and availability"],
        "parameters": [
          { "name": "groupId", "in": "path", "required": true, "schema": { "type": "string" } },
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": false,
            "description": "A key you generate per attempt; a retried request with the same key is a no-op.",
            "schema": { "type": "string" }
          }
        ],
        "responses": {
          "201": {
            "description": "Success.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": ["data", "meta"],
                  "properties": {
                    "data": {},
                    "meta": {
                      "type": "object",
                      "required": ["requestId"],
                      "properties": {
                        "requestId": { "type": "string" },
                        "version": { "type": "integer" },
                        "nextCursor": { "type": ["string", "null"] },
                        "hasMore": { "type": "boolean" },
                        "total": { "type": "integer" }
                      }
                    }
                  }
                }
              }
            }
          },
          "400": { "$ref": "#/components/responses/ValidationFailed" },
          "401": { "$ref": "#/components/responses/Unauthenticated" },
          "403": { "$ref": "#/components/responses/Forbidden" },
          "429": { "$ref": "#/components/responses/RateLimited" }
        },
        "security": [{ "ApiKeyAuth": [] }],
        "x-medappz-scopes": ["appointment.intake"],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "slotId": {
                    "type": "string",
                    "format": "uuid",
                    "pattern": "^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$"
                  },
                  "reason": { "type": "string", "minLength": 3, "maxLength": 500 }
                },
                "required": ["slotId", "reason"],
                "additionalProperties": false
              }
            }
          }
        }
      }
    },
    "/v1/scheduling/intake/resources": {
      "get": {
        "operationId": "getSchedulingIntakeResources",
        "summary": "The doctors and services a patient can be booked with.",
        "description": "Requires scope: appointment.intake.",
        "tags": ["Appointments and availability"],
        "parameters": [
          { "name": "facilityId", "in": "query", "required": false, "schema": { "type": "string" } }
        ],
        "responses": {
          "200": {
            "description": "Success.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": ["data", "meta"],
                  "properties": {
                    "data": {},
                    "meta": {
                      "type": "object",
                      "required": ["requestId"],
                      "properties": {
                        "requestId": { "type": "string" },
                        "version": { "type": "integer" },
                        "nextCursor": { "type": ["string", "null"] },
                        "hasMore": { "type": "boolean" },
                        "total": { "type": "integer" }
                      }
                    }
                  }
                }
              }
            }
          },
          "401": { "$ref": "#/components/responses/Unauthenticated" },
          "403": { "$ref": "#/components/responses/Forbidden" },
          "429": { "$ref": "#/components/responses/RateLimited" }
        },
        "security": [{ "ApiKeyAuth": [] }],
        "x-medappz-scopes": ["appointment.intake"]
      }
    },
    "/v1/scheduling/intake/slots": {
      "get": {
        "operationId": "getSchedulingIntakeSlots",
        "summary": "Open appointment slots in a window of up to 62 days, with who they are with.",
        "description": "Requires scope: appointment.intake.",
        "tags": ["Appointments and availability"],
        "parameters": [
          {
            "name": "facilityId",
            "in": "query",
            "required": false,
            "schema": { "type": "string" }
          },
          { "name": "from", "in": "query", "required": false, "schema": { "type": "string" } },
          {
            "name": "schedulableId",
            "in": "query",
            "required": false,
            "schema": { "type": "string" }
          },
          {
            "name": "serviceType",
            "in": "query",
            "required": false,
            "schema": { "type": "string" }
          },
          { "name": "to", "in": "query", "required": false, "schema": { "type": "string" } }
        ],
        "responses": {
          "200": {
            "description": "Success.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": ["data", "meta"],
                  "properties": {
                    "data": {},
                    "meta": {
                      "type": "object",
                      "required": ["requestId"],
                      "properties": {
                        "requestId": { "type": "string" },
                        "version": { "type": "integer" },
                        "nextCursor": { "type": ["string", "null"] },
                        "hasMore": { "type": "boolean" },
                        "total": { "type": "integer" }
                      }
                    }
                  }
                }
              }
            }
          },
          "401": { "$ref": "#/components/responses/Unauthenticated" },
          "403": { "$ref": "#/components/responses/Forbidden" },
          "429": { "$ref": "#/components/responses/RateLimited" }
        },
        "security": [{ "ApiKeyAuth": [] }],
        "x-medappz-scopes": ["appointment.intake"]
      }
    },
    "/v1/scheduling/schedulables/{id}/day": {
      "get": {
        "operationId": "getSchedulingSchedulablesByIdDay",
        "summary": "One resource's list for one day — the clinic's working view.",
        "description": "Requires scope: appointment.read.",
        "tags": ["Appointments and availability"],
        "parameters": [
          { "name": "id", "in": "path", "required": true, "schema": { "type": "string" } },
          { "name": "date", "in": "query", "required": false, "schema": { "type": "string" } }
        ],
        "responses": {
          "200": {
            "description": "Success.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": ["data", "meta"],
                  "properties": {
                    "data": {},
                    "meta": {
                      "type": "object",
                      "required": ["requestId"],
                      "properties": {
                        "requestId": { "type": "string" },
                        "version": { "type": "integer" },
                        "nextCursor": { "type": ["string", "null"] },
                        "hasMore": { "type": "boolean" },
                        "total": { "type": "integer" }
                      }
                    }
                  }
                }
              }
            }
          },
          "401": { "$ref": "#/components/responses/Unauthenticated" },
          "403": { "$ref": "#/components/responses/Forbidden" },
          "429": { "$ref": "#/components/responses/RateLimited" }
        },
        "security": [{ "ApiKeyAuth": [] }],
        "x-medappz-scopes": ["appointment.read"]
      }
    },
    "/v1/surveypulse/carers": {
      "get": {
        "operationId": "getSurveypulseCarers",
        "summary": "Carers: surveypulse carers",
        "description": "Requires scope: survey.read.",
        "tags": ["Leads and CRM"],
        "parameters": [],
        "responses": {
          "200": {
            "description": "Success.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": ["data", "meta"],
                  "properties": {
                    "data": {},
                    "meta": {
                      "type": "object",
                      "required": ["requestId"],
                      "properties": {
                        "requestId": { "type": "string" },
                        "version": { "type": "integer" },
                        "nextCursor": { "type": ["string", "null"] },
                        "hasMore": { "type": "boolean" },
                        "total": { "type": "integer" }
                      }
                    }
                  }
                }
              }
            }
          },
          "401": { "$ref": "#/components/responses/Unauthenticated" },
          "403": { "$ref": "#/components/responses/Forbidden" },
          "429": { "$ref": "#/components/responses/RateLimited" }
        },
        "security": [{ "ApiKeyAuth": [] }],
        "x-medappz-scopes": ["survey.read"]
      }
    },
    "/v1/surveypulse/carers/reviews": {
      "get": {
        "operationId": "getSurveypulseCarersReviews",
        "summary": "Reviews: surveypulse carers reviews",
        "description": "Requires scope: survey.read.",
        "tags": ["Leads and CRM"],
        "parameters": [],
        "responses": {
          "200": {
            "description": "Success.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": ["data", "meta"],
                  "properties": {
                    "data": {},
                    "meta": {
                      "type": "object",
                      "required": ["requestId"],
                      "properties": {
                        "requestId": { "type": "string" },
                        "version": { "type": "integer" },
                        "nextCursor": { "type": ["string", "null"] },
                        "hasMore": { "type": "boolean" },
                        "total": { "type": "integer" }
                      }
                    }
                  }
                }
              }
            }
          },
          "401": { "$ref": "#/components/responses/Unauthenticated" },
          "403": { "$ref": "#/components/responses/Forbidden" },
          "429": { "$ref": "#/components/responses/RateLimited" }
        },
        "security": [{ "ApiKeyAuth": [] }],
        "x-medappz-scopes": ["survey.read"]
      }
    },
    "/v1/surveypulse/carers/rule": {
      "get": {
        "operationId": "getSurveypulseCarersRule",
        "summary": "Rule: surveypulse carers rule",
        "description": "Requires scope: survey.read.",
        "tags": ["Leads and CRM"],
        "parameters": [],
        "responses": {
          "200": {
            "description": "Success.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": ["data", "meta"],
                  "properties": {
                    "data": {},
                    "meta": {
                      "type": "object",
                      "required": ["requestId"],
                      "properties": {
                        "requestId": { "type": "string" },
                        "version": { "type": "integer" },
                        "nextCursor": { "type": ["string", "null"] },
                        "hasMore": { "type": "boolean" },
                        "total": { "type": "integer" }
                      }
                    }
                  }
                }
              }
            }
          },
          "401": { "$ref": "#/components/responses/Unauthenticated" },
          "403": { "$ref": "#/components/responses/Forbidden" },
          "429": { "$ref": "#/components/responses/RateLimited" }
        },
        "security": [{ "ApiKeyAuth": [] }],
        "x-medappz-scopes": ["survey.read"]
      }
    },
    "/v1/surveypulse/carers/to-rate": {
      "get": {
        "operationId": "getSurveypulseCarersToRate",
        "summary": "To rate: surveypulse carers to rate",
        "description": "Requires scope: survey.read.",
        "tags": ["Leads and CRM"],
        "parameters": [],
        "responses": {
          "200": {
            "description": "Success.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": ["data", "meta"],
                  "properties": {
                    "data": {},
                    "meta": {
                      "type": "object",
                      "required": ["requestId"],
                      "properties": {
                        "requestId": { "type": "string" },
                        "version": { "type": "integer" },
                        "nextCursor": { "type": ["string", "null"] },
                        "hasMore": { "type": "boolean" },
                        "total": { "type": "integer" }
                      }
                    }
                  }
                }
              }
            }
          },
          "401": { "$ref": "#/components/responses/Unauthenticated" },
          "403": { "$ref": "#/components/responses/Forbidden" },
          "429": { "$ref": "#/components/responses/RateLimited" }
        },
        "security": [{ "ApiKeyAuth": [] }],
        "x-medappz-scopes": ["survey.read"]
      }
    },
    "/v1/surveys": {
      "get": {
        "operationId": "getSurveys",
        "summary": "List: surveys",
        "description": "Requires scope: survey.read.",
        "tags": ["Leads and CRM"],
        "parameters": [],
        "responses": {
          "200": {
            "description": "Success.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": ["data", "meta"],
                  "properties": {
                    "data": {},
                    "meta": {
                      "type": "object",
                      "required": ["requestId"],
                      "properties": {
                        "requestId": { "type": "string" },
                        "version": { "type": "integer" },
                        "nextCursor": { "type": ["string", "null"] },
                        "hasMore": { "type": "boolean" },
                        "total": { "type": "integer" }
                      }
                    }
                  }
                }
              }
            }
          },
          "401": { "$ref": "#/components/responses/Unauthenticated" },
          "403": { "$ref": "#/components/responses/Forbidden" },
          "429": { "$ref": "#/components/responses/RateLimited" }
        },
        "security": [{ "ApiKeyAuth": [] }],
        "x-medappz-scopes": ["survey.read"]
      }
    },
    "/v1/surveys/summary": {
      "get": {
        "operationId": "getSurveysSummary",
        "summary": "Summary: surveys summary",
        "description": "Requires scope: survey.read.",
        "tags": ["Leads and CRM"],
        "parameters": [],
        "responses": {
          "200": {
            "description": "Success.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": ["data", "meta"],
                  "properties": {
                    "data": {},
                    "meta": {
                      "type": "object",
                      "required": ["requestId"],
                      "properties": {
                        "requestId": { "type": "string" },
                        "version": { "type": "integer" },
                        "nextCursor": { "type": ["string", "null"] },
                        "hasMore": { "type": "boolean" },
                        "total": { "type": "integer" }
                      }
                    }
                  }
                }
              }
            }
          },
          "401": { "$ref": "#/components/responses/Unauthenticated" },
          "403": { "$ref": "#/components/responses/Forbidden" },
          "429": { "$ref": "#/components/responses/RateLimited" }
        },
        "security": [{ "ApiKeyAuth": [] }],
        "x-medappz-scopes": ["survey.read"]
      }
    },
    "/v1/voice/ingest/sessions": {
      "post": {
        "operationId": "postVoiceIngestSessions",
        "summary": "Open a consultation. Refused without the patient's consent; idempotent on `externalId`.",
        "description": "Device key (mzv_…): Authorization: Bearer mzv_… or X-MedAppz-Key.",
        "tags": ["Voice ingest"],
        "parameters": [
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": false,
            "description": "A key you generate per attempt; a retried request with the same key is a no-op.",
            "schema": { "type": "string" }
          }
        ],
        "responses": {
          "201": {
            "description": "Success.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": ["data", "meta"],
                  "properties": {
                    "data": {},
                    "meta": {
                      "type": "object",
                      "required": ["requestId"],
                      "properties": {
                        "requestId": { "type": "string" },
                        "version": { "type": "integer" },
                        "nextCursor": { "type": ["string", "null"] },
                        "hasMore": { "type": "boolean" },
                        "total": { "type": "integer" }
                      }
                    }
                  }
                }
              }
            }
          },
          "400": { "$ref": "#/components/responses/ValidationFailed" },
          "401": { "$ref": "#/components/responses/Unauthenticated" },
          "403": { "$ref": "#/components/responses/Forbidden" },
          "429": { "$ref": "#/components/responses/RateLimited" }
        },
        "security": [{ "DeviceKeyBearer": [] }, { "DeviceKeyHeader": [] }],
        "x-medappz-rate-limit": "120/min",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "externalId": { "type": "string", "minLength": 1, "maxLength": 200 },
                  "patientRef": {
                    "type": "object",
                    "properties": {
                      "mrn": { "type": "string", "minLength": 1, "maxLength": 60 },
                      "phone": { "type": "string", "minLength": 6, "maxLength": 30 },
                      "patientId": {
                        "type": "string",
                        "format": "uuid",
                        "pattern": "^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$"
                      }
                    },
                    "additionalProperties": false
                  },
                  "encounterRef": { "type": "string", "minLength": 1, "maxLength": 200 },
                  "language": { "type": "string", "minLength": 2, "maxLength": 20 },
                  "consent": {
                    "type": "object",
                    "properties": {
                      "given": { "type": "boolean" },
                      "by": { "type": "string", "minLength": 2, "maxLength": 200 }
                    },
                    "required": ["given", "by"],
                    "additionalProperties": false
                  }
                },
                "required": ["externalId", "consent"],
                "additionalProperties": false
              }
            }
          }
        }
      }
    },
    "/v1/voice/ingest/sessions/{id}": {
      "get": {
        "operationId": "getVoiceIngestSessionsById",
        "summary": "Status and every proposal, with what became of it.",
        "description": "Device key (mzv_…): Authorization: Bearer mzv_… or X-MedAppz-Key.",
        "tags": ["Voice ingest"],
        "parameters": [
          { "name": "id", "in": "path", "required": true, "schema": { "type": "string" } }
        ],
        "responses": {
          "200": {
            "description": "Success.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": ["data", "meta"],
                  "properties": {
                    "data": {},
                    "meta": {
                      "type": "object",
                      "required": ["requestId"],
                      "properties": {
                        "requestId": { "type": "string" },
                        "version": { "type": "integer" },
                        "nextCursor": { "type": ["string", "null"] },
                        "hasMore": { "type": "boolean" },
                        "total": { "type": "integer" }
                      }
                    }
                  }
                }
              }
            }
          },
          "401": { "$ref": "#/components/responses/Unauthenticated" },
          "403": { "$ref": "#/components/responses/Forbidden" },
          "429": { "$ref": "#/components/responses/RateLimited" }
        },
        "security": [{ "DeviceKeyBearer": [] }, { "DeviceKeyHeader": [] }],
        "x-medappz-rate-limit": "600/min"
      }
    },
    "/v1/voice/ingest/sessions/{id}/close": {
      "post": {
        "operationId": "postVoiceIngestSessionsByIdClose",
        "summary": "Close it: extraction starts straight away.",
        "description": "Device key (mzv_…): Authorization: Bearer mzv_… or X-MedAppz-Key.",
        "tags": ["Voice ingest"],
        "parameters": [
          { "name": "id", "in": "path", "required": true, "schema": { "type": "string" } },
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": false,
            "description": "A key you generate per attempt; a retried request with the same key is a no-op.",
            "schema": { "type": "string" }
          }
        ],
        "responses": {
          "201": {
            "description": "Success.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": ["data", "meta"],
                  "properties": {
                    "data": {},
                    "meta": {
                      "type": "object",
                      "required": ["requestId"],
                      "properties": {
                        "requestId": { "type": "string" },
                        "version": { "type": "integer" },
                        "nextCursor": { "type": ["string", "null"] },
                        "hasMore": { "type": "boolean" },
                        "total": { "type": "integer" }
                      }
                    }
                  }
                }
              }
            }
          },
          "401": { "$ref": "#/components/responses/Unauthenticated" },
          "403": { "$ref": "#/components/responses/Forbidden" },
          "429": { "$ref": "#/components/responses/RateLimited" }
        },
        "security": [{ "DeviceKeyBearer": [] }, { "DeviceKeyHeader": [] }],
        "x-medappz-rate-limit": "120/min"
      }
    },
    "/v1/voice/ingest/sessions/{id}/events": {
      "get": {
        "operationId": "getVoiceIngestSessionsByIdEvents",
        "summary": "Server-sent events: `proposal.created`, `proposal.accepted`, `proposal.rejected`, `session.extracted`, `session.blocked`.",
        "description": "Device key (mzv_…): Authorization: Bearer mzv_… or X-MedAppz-Key.",
        "tags": ["Voice ingest"],
        "parameters": [
          { "name": "id", "in": "path", "required": true, "schema": { "type": "string" } },
          { "name": "after", "in": "query", "required": false, "schema": { "type": "string" } }
        ],
        "responses": {
          "200": {
            "description": "Success.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": ["data", "meta"],
                  "properties": {
                    "data": {},
                    "meta": {
                      "type": "object",
                      "required": ["requestId"],
                      "properties": {
                        "requestId": { "type": "string" },
                        "version": { "type": "integer" },
                        "nextCursor": { "type": ["string", "null"] },
                        "hasMore": { "type": "boolean" },
                        "total": { "type": "integer" }
                      }
                    }
                  }
                }
              }
            }
          },
          "401": { "$ref": "#/components/responses/Unauthenticated" },
          "403": { "$ref": "#/components/responses/Forbidden" },
          "429": { "$ref": "#/components/responses/RateLimited" }
        },
        "security": [{ "DeviceKeyBearer": [] }, { "DeviceKeyHeader": [] }],
        "x-medappz-rate-limit": "30/min"
      }
    },
    "/v1/voice/ingest/sessions/{id}/segments": {
      "post": {
        "operationId": "postVoiceIngestSessionsByIdSegments",
        "summary": "Append up to 200 segments. A segment id already stored is counted as a duplicate, not an error.",
        "description": "Device key (mzv_…): Authorization: Bearer mzv_… or X-MedAppz-Key.",
        "tags": ["Voice ingest"],
        "parameters": [
          { "name": "id", "in": "path", "required": true, "schema": { "type": "string" } },
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": false,
            "description": "A key you generate per attempt; a retried request with the same key is a no-op.",
            "schema": { "type": "string" }
          }
        ],
        "responses": {
          "201": {
            "description": "Success.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": ["data", "meta"],
                  "properties": {
                    "data": {},
                    "meta": {
                      "type": "object",
                      "required": ["requestId"],
                      "properties": {
                        "requestId": { "type": "string" },
                        "version": { "type": "integer" },
                        "nextCursor": { "type": ["string", "null"] },
                        "hasMore": { "type": "boolean" },
                        "total": { "type": "integer" }
                      }
                    }
                  }
                }
              }
            }
          },
          "400": { "$ref": "#/components/responses/ValidationFailed" },
          "401": { "$ref": "#/components/responses/Unauthenticated" },
          "403": { "$ref": "#/components/responses/Forbidden" },
          "429": { "$ref": "#/components/responses/RateLimited" }
        },
        "security": [{ "DeviceKeyBearer": [] }, { "DeviceKeyHeader": [] }],
        "x-medappz-rate-limit": "600/min",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "segments": {
                    "minItems": 1,
                    "maxItems": 200,
                    "type": "array",
                    "items": {
                      "type": "object",
                      "properties": {
                        "segmentId": { "type": "string", "minLength": 1, "maxLength": 200 },
                        "speaker": { "type": "string", "minLength": 1, "maxLength": 60 },
                        "startMs": { "type": "integer", "minimum": 0, "maximum": 86400000 },
                        "endMs": { "type": "integer", "minimum": 0, "maximum": 86400000 },
                        "text": { "type": "string", "minLength": 1, "maxLength": 4000 }
                      },
                      "required": ["segmentId", "text"],
                      "additionalProperties": false
                    }
                  }
                },
                "required": ["segments"],
                "additionalProperties": false
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "ApiKeyAuth": {
        "type": "http",
        "scheme": "bearer",
        "bearerFormat": "mza_<prefix>_<secret>",
        "description": "A clinic API key, made under Admin → Integrations. Scoped to named permissions; reaches only the clinic that issued it. Authorization: Bearer mza_<prefix>_<secret>."
      },
      "DeviceKeyBearer": {
        "type": "http",
        "scheme": "bearer",
        "bearerFormat": "mzv_<prefix>_<secret>",
        "description": "A device key, made under Voice Inbox → Integrations, for a recorder or notetaker. Authorization: Bearer mzv_<prefix>_<secret>."
      },
      "DeviceKeyHeader": {
        "type": "apiKey",
        "in": "header",
        "name": "X-MedAppz-Key",
        "description": "The same device key (mzv_…), sent as a header instead of a bearer token."
      }
    },
    "responses": {
      "Unauthenticated": {
        "description": "No valid key on the request.",
        "content": {
          "application/json": {
            "schema": { "$ref": "#/components/schemas/Error" },
            "example": {
              "error": {
                "code": "UNAUTHENTICATED",
                "message": "Authentication is required.",
                "requestId": "req_01J…"
              }
            }
          }
        }
      },
      "Forbidden": {
        "description": "The key is valid but lacks the scope this route needs.",
        "content": {
          "application/json": {
            "schema": { "$ref": "#/components/schemas/Error" },
            "example": {
              "error": {
                "code": "SCOPE_DENIED",
                "message": "This action is outside your assigned scope.",
                "requestId": "req_01J…"
              }
            }
          }
        }
      },
      "RateLimited": {
        "description": "Too many requests; back off and retry.",
        "content": {
          "application/json": {
            "schema": { "$ref": "#/components/schemas/Error" },
            "example": {
              "error": {
                "code": "RATE_LIMITED",
                "message": "Too many requests.",
                "requestId": "req_01J…"
              }
            }
          }
        },
        "headers": {
          "Retry-After": {
            "description": "Seconds to wait before the next attempt.",
            "schema": { "type": "integer" }
          }
        }
      },
      "ValidationFailed": {
        "description": "The request body failed schema validation.",
        "content": {
          "application/json": {
            "schema": { "$ref": "#/components/schemas/Error" },
            "example": {
              "error": {
                "code": "VALIDATION_FAILED",
                "message": "phone must be a valid mobile number.",
                "requestId": "req_01J…",
                "field": "phone"
              }
            }
          }
        }
      }
    },
    "schemas": {
      "Error": {
        "type": "object",
        "required": ["error"],
        "properties": {
          "error": {
            "type": "object",
            "required": ["code", "message", "requestId"],
            "properties": {
              "code": { "type": "string" },
              "message": { "type": "string" },
              "requestId": { "type": "string" },
              "field": { "type": "string" },
              "details": { "type": "object" }
            }
          }
        }
      },
      "WebhookEnvelope": {
        "type": "object",
        "required": [
          "id",
          "eventType",
          "eventVersion",
          "occurredAt",
          "tenantId",
          "aggregateType",
          "aggregateId",
          "payload"
        ],
        "properties": {
          "id": { "type": "string" },
          "eventType": {
            "type": "string",
            "enum": [
              "patient.patient.registered",
              "patient.patient.updated",
              "patient.patient.merged",
              "scheduling.booking.created",
              "scheduling.booking.cancelled",
              "scheduling.booking.rescheduled",
              "scheduling.booking.no_show",
              "clinical.encounter.finished",
              "billing.bill.finalised",
              "billing.payment.received",
              "billing.bill.voided",
              "billing.payment.refunded",
              "dispensedesk.dispense.completed",
              "wardline.admission.admitted",
              "wardline.admission.discharged",
              "leaddesk.lead.created",
              "admitline.case.staged"
            ]
          },
          "eventVersion": { "type": "integer" },
          "occurredAt": { "type": "string", "format": "date-time" },
          "tenantId": { "type": "string" },
          "facilityId": { "type": ["string", "null"] },
          "aggregateType": { "type": "string" },
          "aggregateId": { "type": "string" },
          "correlationId": { "type": ["string", "null"] },
          "payload": { "type": "object" }
        }
      }
    }
  },
  "security": [{ "ApiKeyAuth": [] }],
  "webhooks": {
    "patient.patient.registered": {
      "post": {
        "operationId": "webhookPatientPatientRegistered",
        "summary": "Delivered when patient.patient.registered occurs.",
        "description": "Sent by MedAppz to the URL you registered. Any 2xx response marks the delivery as received; anything else is retried with backoff (1 minute up to 8 hours, 6 attempts) before it is marked dead.",
        "parameters": [
          {
            "name": "x-medappz-signature",
            "in": "header",
            "required": true,
            "description": "t=<unix seconds>,v1=<hex HMAC-SHA256 of \"<t>.<raw body>\" with your webhook secret>. Reject a delivery whose timestamp is more than a few minutes old.",
            "schema": { "type": "string" }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": { "schema": { "$ref": "#/components/schemas/WebhookEnvelope" } }
          }
        },
        "responses": { "200": { "description": "Any 2xx marks the delivery as received." } }
      }
    },
    "patient.patient.updated": {
      "post": {
        "operationId": "webhookPatientPatientUpdated",
        "summary": "Delivered when patient.patient.updated occurs.",
        "description": "Sent by MedAppz to the URL you registered. Any 2xx response marks the delivery as received; anything else is retried with backoff (1 minute up to 8 hours, 6 attempts) before it is marked dead.",
        "parameters": [
          {
            "name": "x-medappz-signature",
            "in": "header",
            "required": true,
            "description": "t=<unix seconds>,v1=<hex HMAC-SHA256 of \"<t>.<raw body>\" with your webhook secret>. Reject a delivery whose timestamp is more than a few minutes old.",
            "schema": { "type": "string" }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": { "schema": { "$ref": "#/components/schemas/WebhookEnvelope" } }
          }
        },
        "responses": { "200": { "description": "Any 2xx marks the delivery as received." } }
      }
    },
    "patient.patient.merged": {
      "post": {
        "operationId": "webhookPatientPatientMerged",
        "summary": "Delivered when patient.patient.merged occurs.",
        "description": "Sent by MedAppz to the URL you registered. Any 2xx response marks the delivery as received; anything else is retried with backoff (1 minute up to 8 hours, 6 attempts) before it is marked dead.",
        "parameters": [
          {
            "name": "x-medappz-signature",
            "in": "header",
            "required": true,
            "description": "t=<unix seconds>,v1=<hex HMAC-SHA256 of \"<t>.<raw body>\" with your webhook secret>. Reject a delivery whose timestamp is more than a few minutes old.",
            "schema": { "type": "string" }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": { "schema": { "$ref": "#/components/schemas/WebhookEnvelope" } }
          }
        },
        "responses": { "200": { "description": "Any 2xx marks the delivery as received." } }
      }
    },
    "scheduling.booking.created": {
      "post": {
        "operationId": "webhookSchedulingBookingCreated",
        "summary": "Delivered when scheduling.booking.created occurs.",
        "description": "Sent by MedAppz to the URL you registered. Any 2xx response marks the delivery as received; anything else is retried with backoff (1 minute up to 8 hours, 6 attempts) before it is marked dead.",
        "parameters": [
          {
            "name": "x-medappz-signature",
            "in": "header",
            "required": true,
            "description": "t=<unix seconds>,v1=<hex HMAC-SHA256 of \"<t>.<raw body>\" with your webhook secret>. Reject a delivery whose timestamp is more than a few minutes old.",
            "schema": { "type": "string" }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": { "schema": { "$ref": "#/components/schemas/WebhookEnvelope" } }
          }
        },
        "responses": { "200": { "description": "Any 2xx marks the delivery as received." } }
      }
    },
    "scheduling.booking.cancelled": {
      "post": {
        "operationId": "webhookSchedulingBookingCancelled",
        "summary": "Delivered when scheduling.booking.cancelled occurs.",
        "description": "Sent by MedAppz to the URL you registered. Any 2xx response marks the delivery as received; anything else is retried with backoff (1 minute up to 8 hours, 6 attempts) before it is marked dead.",
        "parameters": [
          {
            "name": "x-medappz-signature",
            "in": "header",
            "required": true,
            "description": "t=<unix seconds>,v1=<hex HMAC-SHA256 of \"<t>.<raw body>\" with your webhook secret>. Reject a delivery whose timestamp is more than a few minutes old.",
            "schema": { "type": "string" }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": { "schema": { "$ref": "#/components/schemas/WebhookEnvelope" } }
          }
        },
        "responses": { "200": { "description": "Any 2xx marks the delivery as received." } }
      }
    },
    "scheduling.booking.rescheduled": {
      "post": {
        "operationId": "webhookSchedulingBookingRescheduled",
        "summary": "Delivered when scheduling.booking.rescheduled occurs.",
        "description": "Sent by MedAppz to the URL you registered. Any 2xx response marks the delivery as received; anything else is retried with backoff (1 minute up to 8 hours, 6 attempts) before it is marked dead.",
        "parameters": [
          {
            "name": "x-medappz-signature",
            "in": "header",
            "required": true,
            "description": "t=<unix seconds>,v1=<hex HMAC-SHA256 of \"<t>.<raw body>\" with your webhook secret>. Reject a delivery whose timestamp is more than a few minutes old.",
            "schema": { "type": "string" }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": { "schema": { "$ref": "#/components/schemas/WebhookEnvelope" } }
          }
        },
        "responses": { "200": { "description": "Any 2xx marks the delivery as received." } }
      }
    },
    "scheduling.booking.no_show": {
      "post": {
        "operationId": "webhookSchedulingBookingNoShow",
        "summary": "Delivered when scheduling.booking.no_show occurs.",
        "description": "Sent by MedAppz to the URL you registered. Any 2xx response marks the delivery as received; anything else is retried with backoff (1 minute up to 8 hours, 6 attempts) before it is marked dead.",
        "parameters": [
          {
            "name": "x-medappz-signature",
            "in": "header",
            "required": true,
            "description": "t=<unix seconds>,v1=<hex HMAC-SHA256 of \"<t>.<raw body>\" with your webhook secret>. Reject a delivery whose timestamp is more than a few minutes old.",
            "schema": { "type": "string" }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": { "schema": { "$ref": "#/components/schemas/WebhookEnvelope" } }
          }
        },
        "responses": { "200": { "description": "Any 2xx marks the delivery as received." } }
      }
    },
    "clinical.encounter.finished": {
      "post": {
        "operationId": "webhookClinicalEncounterFinished",
        "summary": "Delivered when clinical.encounter.finished occurs.",
        "description": "Sent by MedAppz to the URL you registered. Any 2xx response marks the delivery as received; anything else is retried with backoff (1 minute up to 8 hours, 6 attempts) before it is marked dead.",
        "parameters": [
          {
            "name": "x-medappz-signature",
            "in": "header",
            "required": true,
            "description": "t=<unix seconds>,v1=<hex HMAC-SHA256 of \"<t>.<raw body>\" with your webhook secret>. Reject a delivery whose timestamp is more than a few minutes old.",
            "schema": { "type": "string" }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": { "schema": { "$ref": "#/components/schemas/WebhookEnvelope" } }
          }
        },
        "responses": { "200": { "description": "Any 2xx marks the delivery as received." } }
      }
    },
    "billing.bill.finalised": {
      "post": {
        "operationId": "webhookBillingBillFinalised",
        "summary": "Delivered when billing.bill.finalised occurs.",
        "description": "Sent by MedAppz to the URL you registered. Any 2xx response marks the delivery as received; anything else is retried with backoff (1 minute up to 8 hours, 6 attempts) before it is marked dead.",
        "parameters": [
          {
            "name": "x-medappz-signature",
            "in": "header",
            "required": true,
            "description": "t=<unix seconds>,v1=<hex HMAC-SHA256 of \"<t>.<raw body>\" with your webhook secret>. Reject a delivery whose timestamp is more than a few minutes old.",
            "schema": { "type": "string" }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": { "schema": { "$ref": "#/components/schemas/WebhookEnvelope" } }
          }
        },
        "responses": { "200": { "description": "Any 2xx marks the delivery as received." } }
      }
    },
    "billing.payment.received": {
      "post": {
        "operationId": "webhookBillingPaymentReceived",
        "summary": "Delivered when billing.payment.received occurs.",
        "description": "Sent by MedAppz to the URL you registered. Any 2xx response marks the delivery as received; anything else is retried with backoff (1 minute up to 8 hours, 6 attempts) before it is marked dead.",
        "parameters": [
          {
            "name": "x-medappz-signature",
            "in": "header",
            "required": true,
            "description": "t=<unix seconds>,v1=<hex HMAC-SHA256 of \"<t>.<raw body>\" with your webhook secret>. Reject a delivery whose timestamp is more than a few minutes old.",
            "schema": { "type": "string" }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": { "schema": { "$ref": "#/components/schemas/WebhookEnvelope" } }
          }
        },
        "responses": { "200": { "description": "Any 2xx marks the delivery as received." } }
      }
    },
    "billing.bill.voided": {
      "post": {
        "operationId": "webhookBillingBillVoided",
        "summary": "Delivered when billing.bill.voided occurs.",
        "description": "Sent by MedAppz to the URL you registered. Any 2xx response marks the delivery as received; anything else is retried with backoff (1 minute up to 8 hours, 6 attempts) before it is marked dead.",
        "parameters": [
          {
            "name": "x-medappz-signature",
            "in": "header",
            "required": true,
            "description": "t=<unix seconds>,v1=<hex HMAC-SHA256 of \"<t>.<raw body>\" with your webhook secret>. Reject a delivery whose timestamp is more than a few minutes old.",
            "schema": { "type": "string" }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": { "schema": { "$ref": "#/components/schemas/WebhookEnvelope" } }
          }
        },
        "responses": { "200": { "description": "Any 2xx marks the delivery as received." } }
      }
    },
    "billing.payment.refunded": {
      "post": {
        "operationId": "webhookBillingPaymentRefunded",
        "summary": "Delivered when billing.payment.refunded occurs.",
        "description": "Sent by MedAppz to the URL you registered. Any 2xx response marks the delivery as received; anything else is retried with backoff (1 minute up to 8 hours, 6 attempts) before it is marked dead.",
        "parameters": [
          {
            "name": "x-medappz-signature",
            "in": "header",
            "required": true,
            "description": "t=<unix seconds>,v1=<hex HMAC-SHA256 of \"<t>.<raw body>\" with your webhook secret>. Reject a delivery whose timestamp is more than a few minutes old.",
            "schema": { "type": "string" }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": { "schema": { "$ref": "#/components/schemas/WebhookEnvelope" } }
          }
        },
        "responses": { "200": { "description": "Any 2xx marks the delivery as received." } }
      }
    },
    "dispensedesk.dispense.completed": {
      "post": {
        "operationId": "webhookDispensedeskDispenseCompleted",
        "summary": "Delivered when dispensedesk.dispense.completed occurs.",
        "description": "Sent by MedAppz to the URL you registered. Any 2xx response marks the delivery as received; anything else is retried with backoff (1 minute up to 8 hours, 6 attempts) before it is marked dead.",
        "parameters": [
          {
            "name": "x-medappz-signature",
            "in": "header",
            "required": true,
            "description": "t=<unix seconds>,v1=<hex HMAC-SHA256 of \"<t>.<raw body>\" with your webhook secret>. Reject a delivery whose timestamp is more than a few minutes old.",
            "schema": { "type": "string" }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": { "schema": { "$ref": "#/components/schemas/WebhookEnvelope" } }
          }
        },
        "responses": { "200": { "description": "Any 2xx marks the delivery as received." } }
      }
    },
    "wardline.admission.admitted": {
      "post": {
        "operationId": "webhookWardlineAdmissionAdmitted",
        "summary": "Delivered when wardline.admission.admitted occurs.",
        "description": "Sent by MedAppz to the URL you registered. Any 2xx response marks the delivery as received; anything else is retried with backoff (1 minute up to 8 hours, 6 attempts) before it is marked dead.",
        "parameters": [
          {
            "name": "x-medappz-signature",
            "in": "header",
            "required": true,
            "description": "t=<unix seconds>,v1=<hex HMAC-SHA256 of \"<t>.<raw body>\" with your webhook secret>. Reject a delivery whose timestamp is more than a few minutes old.",
            "schema": { "type": "string" }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": { "schema": { "$ref": "#/components/schemas/WebhookEnvelope" } }
          }
        },
        "responses": { "200": { "description": "Any 2xx marks the delivery as received." } }
      }
    },
    "wardline.admission.discharged": {
      "post": {
        "operationId": "webhookWardlineAdmissionDischarged",
        "summary": "Delivered when wardline.admission.discharged occurs.",
        "description": "Sent by MedAppz to the URL you registered. Any 2xx response marks the delivery as received; anything else is retried with backoff (1 minute up to 8 hours, 6 attempts) before it is marked dead.",
        "parameters": [
          {
            "name": "x-medappz-signature",
            "in": "header",
            "required": true,
            "description": "t=<unix seconds>,v1=<hex HMAC-SHA256 of \"<t>.<raw body>\" with your webhook secret>. Reject a delivery whose timestamp is more than a few minutes old.",
            "schema": { "type": "string" }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": { "schema": { "$ref": "#/components/schemas/WebhookEnvelope" } }
          }
        },
        "responses": { "200": { "description": "Any 2xx marks the delivery as received." } }
      }
    },
    "leaddesk.lead.created": {
      "post": {
        "operationId": "webhookLeaddeskLeadCreated",
        "summary": "Delivered when leaddesk.lead.created occurs.",
        "description": "Sent by MedAppz to the URL you registered. Any 2xx response marks the delivery as received; anything else is retried with backoff (1 minute up to 8 hours, 6 attempts) before it is marked dead.",
        "parameters": [
          {
            "name": "x-medappz-signature",
            "in": "header",
            "required": true,
            "description": "t=<unix seconds>,v1=<hex HMAC-SHA256 of \"<t>.<raw body>\" with your webhook secret>. Reject a delivery whose timestamp is more than a few minutes old.",
            "schema": { "type": "string" }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": { "schema": { "$ref": "#/components/schemas/WebhookEnvelope" } }
          }
        },
        "responses": { "200": { "description": "Any 2xx marks the delivery as received." } }
      }
    },
    "admitline.case.staged": {
      "post": {
        "operationId": "webhookAdmitlineCaseStaged",
        "summary": "Delivered when admitline.case.staged occurs.",
        "description": "Sent by MedAppz to the URL you registered. Any 2xx response marks the delivery as received; anything else is retried with backoff (1 minute up to 8 hours, 6 attempts) before it is marked dead.",
        "parameters": [
          {
            "name": "x-medappz-signature",
            "in": "header",
            "required": true,
            "description": "t=<unix seconds>,v1=<hex HMAC-SHA256 of \"<t>.<raw body>\" with your webhook secret>. Reject a delivery whose timestamp is more than a few minutes old.",
            "schema": { "type": "string" }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": { "schema": { "$ref": "#/components/schemas/WebhookEnvelope" } }
          }
        },
        "responses": { "200": { "description": "Any 2xx marks the delivery as received." } }
      }
    }
  }
}
