{
  "openapi": "3.0.3",
  "info": {
    "title": "Webhook API",
    "description": "Webhook API reference.",
    "version": ""
  },
  "paths": {
    "/webhook": {
      "post": {
        "summary": "Receive webhook events",
        "description": "This is the endpoint you need to implement on your server to receive events. This page references the format of all the possible events.",
        "tags": [
          "Webhook"
        ],
        "operationId": "assistant-receive-webhook",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/webhook_event"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Respond with 200 to acknowledge the handling of this webhook event, otherwise we will retry the call later."
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "encounter.note.generated": {
        "$ref": "#/components/schemas/encounter_note_generated"
      },
      "encounter.feedback.submitted": {
        "$ref": "#/components/schemas/encounter_feedback_submitted"
      },
      "user.created": {
        "$ref": "#/components/schemas/user_created"
      },
      "encounter.note.copied": {
        "$ref": "#/components/schemas/encounter_note_copied"
      },
      "uuid": {
        "type": "string",
        "format": "uuid",
        "description": "A unique identifier.",
        "example": "98FCE1EF-DBCA-41EF-8BC7-4D1621AC07C6"
      },
      "created_at": {
        "type": "string",
        "format": "date-time",
        "description": "The creation date of this object, in ISO 8601 format.",
        "example": "2022-03-10T19:16:23.456Z"
      },
      "base_webhook_event": {
        "type": "object",
        "properties": {
          "id": {
            "$ref": "#/components/schemas/uuid",
            "description": "The unique identifier of this webhook event."
          },
          "created_at": {
            "$ref": "#/components/schemas/created_at",
            "description": "Creation date of this webhook event."
          },
          "type": {
            "type": "string",
            "description": "Type of this event, serves as a discriminator between the different possible webhook types."
          }
        },
        "required": [
          "id",
          "created_at",
          "type"
        ]
      },
      "user": {
        "type": "object",
        "properties": {
          "id": {
            "$ref": "#/components/schemas/uuid"
          },
          "email": {
            "type": "string",
            "format": "email",
            "example": "doctor@nabla.com"
          }
        },
        "required": [
          "id",
          "email"
        ]
      },
      "encounter": {
        "type": "object",
        "properties": {
          "id": {
            "$ref": "#/components/schemas/uuid"
          },
          "external_id": {
            "type": "string",
            "description": "A client-defined identifier used to associate the encounter with an external system (e.g., EHR).\nThis value is set when creating an encounter via Nabla's web application through this URL and query parameter: https://app.nabla.com/create-encounter-from-external-id?external_id=[EXTERNAL_ID]. It enables downstream systems to retrieve, track, or link back to the original resource that triggered the encounter creation."
          },
          "created_at": {
            "type": "string",
            "format": "date-time",
            "description": "The date and time at which this encounter was created."
          },
          "user": {
            "$ref": "#/components/schemas/user"
          },
          "fhir_patient_id": {
            "type": "string",
            "description": "The FHIR patient ID of the encounter (only in case of EHR integrated encounter)",
            "example": "a-1959508.E-12345"
          },
          "fhir_encounter_id": {
            "type": "string",
            "description": "The FHIR encounter ID (only in case of EHR integrated encounter)",
            "example": "a-1959508.encounter-12345"
          }
        },
        "required": [
          "id",
          "created_at",
          "user"
        ]
      },
      "note_section_key": {
        "type": "string",
        "enum": [
          "ALLERGIES",
          "APPOINTMENTS",
          "ASSESSMENT",
          "ASSESSMENT_AND_PLAN",
          "CARDIOVASCULAR_RISKS",
          "CHIEF_COMPLAINT",
          "CURRENT_MEDICATIONS",
          "DIET_APPOINTMENTS",
          "DIET_CHIEF_COMPLAINT",
          "DIET_HABITS",
          "DIET_LIFESTYLE",
          "DIET_MEDICAL_HISTORY",
          "DIET_OBJECTIVES",
          "DIET_VITALS",
          "FAMILY_HISTORY",
          "HISTORY_OF_PRESENT_ILLNESS",
          "IMAGING_RESULTS",
          "IMMUNIZATIONS",
          "LAB_RESULTS",
          "MENTAL_HEALTH_EXAM",
          "MENTAL_HEALTH_HISTORY",
          "PAST_MEDICAL_HISTORY",
          "PAST_OBSTETRIC_HISTORY",
          "PAST_SURGICAL_HISTORY",
          "PHYSICAL_EXAM",
          "PLAN",
          "PRESCRIPTION",
          "PSYCHOLOGY_HISTORY_OF_COMPLAINT",
          "SOAP_ASSESSMENT",
          "SOAP_ASSESSMENT_AND_PLAN",
          "SOAP_DIAGNOSTIC_TESTS_ORDERED",
          "SOAP_OBJECTIVE",
          "SOAP_PHYSICAL_EXAM",
          "SOAP_PLAN",
          "SOAP_SUBJECTIVE",
          "SOCIAL_HISTORY",
          "SYMPTOMS",
          "VITALS",
          "WELL_CHILD_CARE",
          "CLINICAL_HISTORY",
          "PAST_MEDICATIONS",
          "GAPS_IN_CARE",
          "MEMBER_FOCUSED_CARE_PLAN",
          "REFERRALS",
          "RESULTS",
          "CALL_SUMMARY",
          "PATIENT_GOALS",
          "GOALS",
          "MEDICAL_PROCEDURES_PERFORMED",
          "PATIENT_ADMINISTRATIVE_INFORMATION",
          "ACTIVITIES_OF_DAILY_LIVING",
          "INSTRUMENTAL_ACTIVITIES_OF_DAILY_LIVING",
          "COGNITIVE_FUNCTIONING",
          "CULTURAL_NEEDS",
          "VISUAL_HEARING_NEEDS",
          "PHYSICAL_ENVIRONMENT_RISKS",
          "RESOURCES",
          "HEALTH_INSURANCE_INFORMATION",
          "LIFE_PLANNING",
          "SOCIAL_DETERMINANTS_OF_HEALTH",
          "CARE_PLAN_AND_SERVICES",
          "FOLLOW_UP_AND_REVIEW",
          "CUSTOM_SECTION_1",
          "CUSTOM_SECTION_2",
          "CUSTOM_SECTION_3",
          "CUSTOM_SECTION_4",
          "CUSTOM_SECTION_5",
          "CUSTOM_SECTION_6",
          "CUSTOM_SECTION_7",
          "CUSTOM_SECTION_8",
          "CUSTOM_SECTION_9",
          "CUSTOM_SECTION_10",
          "CUSTOM_SECTION_11",
          "CUSTOM_SECTION_12",
          "CUSTOM_SECTION_13",
          "CUSTOM_SECTION_14",
          "CUSTOM_SECTION_15",
          "CUSTOM_SECTION_16",
          "CUSTOM_SECTION_17",
          "CUSTOM_SECTION_18",
          "CUSTOM_SECTION_19",
          "CUSTOM_SECTION_20"
        ]
      },
      "note_section": {
        "type": "object",
        "description": "A note section.",
        "properties": {
          "key": {
            "$ref": "#/components/schemas/note_section_key"
          },
          "title": {
            "type": "string",
            "description": "The section title.",
            "example": "Chief complaint"
          },
          "text": {
            "type": "string",
            "description": "Content of the note section.",
            "example": "- Persistent fatigue\n- Mild headaches on the right side"
          }
        },
        "required": [
          "key",
          "title",
          "text"
        ]
      },
      "note": {
        "type": "object",
        "description": "The note, including any edit the user made after its generation.",
        "properties": {
          "sections": {
            "type": "array",
            "description": "Content of the note structured in multiple sections.",
            "items": {
              "$ref": "#/components/schemas/note_section"
            }
          },
          "title": {
            "type": "string",
            "description": "Suggested title for the note."
          },
          "free_text": {
            "type": "string",
            "description": "Content of the note's free text field, as inputted by the user, if any. This field is edited separately from the note sections, and is appended to the note when it is copied or exported.",
            "example": "Patient to call back after the lab results are in."
          }
        },
        "required": [
          "sections",
          "title"
        ]
      },
      "transcript_item": {
        "type": "object",
        "description": "A portion of the transcribed encounter.",
        "properties": {
          "text": {
            "type": "string",
            "description": "The transcribed text.",
            "example": "Also, I’m allergic to peanuts."
          },
          "speaker": {
            "type": "string",
            "enum": [
              "DOCTOR",
              "PATIENT",
              "UNSPECIFIED",
              "DOCTOR_2",
              "DOCTOR_3",
              "PATIENT_2",
              "ACCOMPANYING_PERSON",
              "ACCOMPANYING_PERSON_2"
            ]
          },
          "start_offset_ms": {
            "type": "integer",
            "description": "Start time of this transcription item as the offset, in milliseconds, from the start of the encounter.",
            "example": 65100
          },
          "end_offset_ms": {
            "type": "integer",
            "description": "End time of this transcription item as the offset, in milliseconds, from the start of the encounter. Equals the `start_time_ms` plus the duration of the related transcribed audio portion.",
            "example": 69300
          }
        },
        "required": [
          "text",
          "speaker",
          "start_offset_ms",
          "end_offset_ms"
        ]
      },
      "transcript": {
        "type": "object",
        "description": "Transcription of the encounter, used to generate the note.",
        "properties": {
          "transcript_items": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/transcript_item"
            }
          }
        },
        "required": [
          "transcript_items"
        ]
      },
      "encounter_with_note_and_transcript": {
        "type": "object",
        "description": "The generated note, the transcript used for the generation and the relevant encounter.",
        "properties": {
          "encounter": {
            "$ref": "#/components/schemas/encounter"
          },
          "note": {
            "$ref": "#/components/schemas/note"
          },
          "transcript": {
            "$ref": "#/components/schemas/transcript"
          },
          "patient_context": {
            "type": "string",
            "description": "The free-text patient context as inputted by the user, if any.",
            "example": "28yo woman with diabetes"
          },
          "fhir_patient_id": {
            "type": "string",
            "deprecated": true,
            "description": "Deprecated: use `encounter.fhir_patient_id` instead, which carries the same value and is present on every webhook event embedding an encounter.",
            "example": "a-1959508.E-12345"
          },
          "fhir_encounter_id": {
            "type": "string",
            "deprecated": true,
            "description": "Deprecated: use `encounter.fhir_encounter_id` instead, which carries the same value and is present on every webhook event embedding an encounter.",
            "example": "a-1959508.encounter-12345"
          }
        },
        "required": [
          "encounter",
          "note",
          "transcript"
        ]
      },
      "encounter_note_generated": {
        "x-sensitive-medical-data": true,
        "x-webhook-type": "ASSISTANT_ENCOUNTER_NOTE_GENERATED",
        "allOf": [
          {
            "$ref": "#/components/schemas/base_webhook_event"
          },
          {
            "type": "object",
            "description": "Event sent when a user generates a note by ending an encounter.",
            "properties": {
              "data": {
                "$ref": "#/components/schemas/encounter_with_note_and_transcript"
              }
            },
            "required": [
              "data"
            ]
          }
        ]
      },
      "encounter_with_rating": {
        "type": "object",
        "description": "User's feedback along with the relevant encounter.",
        "properties": {
          "encounter": {
            "$ref": "#/components/schemas/encounter"
          },
          "rating": {
            "type": "integer",
            "minimum": 1,
            "maximum": 5,
            "description": "User's rating for the generated note: from _Complete rewrite needed_ (1) to _Almost no edits needed_ (5)."
          },
          "feedback": {
            "type": "string",
            "description": "Free-text feedback on the generated note. Typically, this explains the given rating by suggesting specific improvements and/or highlighting the good points."
          }
        },
        "required": [
          "encounter"
        ]
      },
      "encounter_feedback_submitted": {
        "x-sensitive-medical-data": true,
        "x-webhook-type": "ASSISTANT_ENCOUNTER_FEEDBACK_SUBMITTED",
        "allOf": [
          {
            "$ref": "#/components/schemas/base_webhook_event"
          },
          {
            "type": "object",
            "description": "Event sent when a user submits a feedback and/or star rating for a generated note in an encounter.",
            "properties": {
              "data": {
                "$ref": "#/components/schemas/encounter_with_rating"
              }
            },
            "required": [
              "data"
            ]
          }
        ]
      },
      "user_created": {
        "x-sensitive-medical-data": false,
        "x-webhook-type": "ASSISTANT_USER_CREATED",
        "allOf": [
          {
            "$ref": "#/components/schemas/base_webhook_event"
          },
          {
            "type": "object",
            "description": "Event sent when a user is created, either manually or on their first sign-in when SSO auto-provisioning is enabled.",
            "properties": {
              "data": {
                "$ref": "#/components/schemas/user"
              }
            },
            "required": [
              "data"
            ]
          }
        ]
      },
      "encounter_with_note": {
        "type": "object",
        "description": "The copied note along with the relevant encounter.",
        "properties": {
          "encounter": {
            "$ref": "#/components/schemas/encounter"
          },
          "note": {
            "$ref": "#/components/schemas/note"
          }
        },
        "required": [
          "encounter",
          "note"
        ]
      },
      "encounter_note_copied": {
        "x-sensitive-medical-data": true,
        "x-webhook-type": "ASSISTANT_ENCOUNTER_NOTE_COPIED",
        "allOf": [
          {
            "$ref": "#/components/schemas/base_webhook_event"
          },
          {
            "type": "object",
            "description": "Event sent when a user presses the \"Copy note\" button in an encounter. The note is sent as copied, including the user's edits and inserted Dot Phrases.",
            "properties": {
              "data": {
                "$ref": "#/components/schemas/encounter_with_note"
              }
            },
            "required": [
              "data"
            ]
          }
        ]
      },
      "webhook_event": {
        "oneOf": [
          {
            "$ref": "#/components/schemas/encounter_note_generated",
            "title": "encounter.note.generated"
          },
          {
            "$ref": "#/components/schemas/encounter_feedback_submitted",
            "title": "encounter.feedback.submitted"
          },
          {
            "$ref": "#/components/schemas/user_created",
            "title": "user.created"
          },
          {
            "$ref": "#/components/schemas/encounter_note_copied",
            "title": "encounter.note.copied"
          }
        ],
        "discriminator": {
          "propertyName": "type",
          "mapping": {
            "encounter.note.generated": "#/components/schemas/encounter_note_generated",
            "encounter.feedback.submitted": "#/components/schemas/encounter_feedback_submitted",
            "user.created": "#/components/schemas/user_created",
            "encounter.note.copied": "#/components/schemas/encounter_note_copied"
          }
        },
        "example": {
          "id": "0cf0b04d-5bbe-47a9-9601-3dd037644f65",
          "created_at": "2024-07-15T12:47:34.380Z",
          "type": "encounter.note.generated",
          "data": {
            "encounter": {
              "id": "131b105c-e70d-4442-a49f-46243942e288",
              "created_at": "2024-07-15T12:15:18.450Z",
              "user": {
                "id": "b1a23529-abfe-49d9-91a0-24a8de364e0f",
                "email": "doctor@nabla.com"
              }
            },
            "note": {
              "title": "Fatigue and headache",
              "sections": [
                {
                  "key": "CHIEF_COMPLAINT",
                  "title": "Chief complaint",
                  "text": "- Persistent fatigue\n- Mild headaches on the right side"
                },
                {
                  "key": "PAST_MEDICAL_HISTORY",
                  "title": "Past medical history",
                  "text": "- Hypertension\n- Elevated blood sugar levels"
                },
                {
                  "key": "LAB_RESULTS",
                  "title": "Lab results",
                  "text": "- Blood sugar level: 1.4 g/L\n- LDL cholesterol: 2 g/L"
                }
              ]
            },
            "transcript": {
              "transcript_items": [
                {
                  "speaker": "PATIENT",
                  "start_offset_ms": 3400,
                  "end_offset_ms": 27200,
                  "text": "I've been feeling exhausted for the past few months, and I've been getting headaches on the right side of my head, especially at the end of the day. I also have high blood pressure and my blood sugar levels have been elevated."
                },
                {
                  "speaker": "DOCTOR",
                  "start_offset_ms": 29650,
                  "end_offset_ms": 86100,
                  "text": "I see, based on your lab results, your blood sugar level is 1.4 g/L, and your LDL cholesterol is 2 g/L, both of which are elevated. Your fatigue and headaches might be linked to your sleep patterns, especially since you snore. I'll order a home sleep test to check for sleep apnea. We'll discuss the results in a follow-up."
                }
              ]
            }
          }
        }
      }
    }
  }
}