{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://developers.youareaccountable.com/schemas/notes.updated.json",
  "title": "NotesUpdated",
  "description": "A note is edited. Sends the full note.",
  "type": "object",
  "required": [
    "event_type",
    "data"
  ],
  "properties": {
    "event_type": {
      "const": "notes.updated"
    },
    "data": {
      "type": "object",
      "required": [
        "note_id",
        "medical_record_number",
        "note_content",
        "created_at",
        "created_by",
        "session_details",
        "coaching_session",
        "flags",
        "tox_id",
        "file"
      ],
      "properties": {
        "note_id": {
          "type": "string",
          "description": "The note's ID."
        },
        "medical_record_number": {
          "type": "string",
          "format": "uuid",
          "description": "The member's medical record number. Always a UUID. Use it to match the event to your own record."
        },
        "plan_name": {
          "type": [
            "string",
            "null"
          ],
          "description": "The member's Accountable plan. Can be null or left out."
        },
        "note_content": {
          "type": "string",
          "description": "The text of the note."
        },
        "created_at": {
          "type": "string",
          "format": "date-time",
          "description": "The date on the note."
        },
        "updated_at": {
          "type": "string",
          "format": "date-time",
          "description": "When the note was last changed."
        },
        "created_by": {
          "type": [
            "string",
            "null"
          ],
          "description": "First and last name of the person who wrote the note."
        },
        "session_details": {
          "type": [
            "object",
            "null"
          ],
          "description": "The actual times the coach logged. null when the note has none.",
          "properties": {
            "start_time": {
              "type": [
                "string",
                "null"
              ],
              "format": "date-time",
              "description": "When the session started. null on a no-show note."
            },
            "stop_time": {
              "type": [
                "string",
                "null"
              ],
              "format": "date-time",
              "description": "When the session ended. Ignore it when start_time is null."
            },
            "duration_minutes": {
              "type": [
                "number",
                "null"
              ],
              "description": "How long the session ran."
            }
          }
        },
        "coaching_session": {
          "type": [
            "object",
            "null"
          ],
          "description": "The scheduled session this note was matched to. Set only on check-in and no-show notes that match a scheduled session.",
          "required": [
            "session_id",
            "scheduled_date",
            "status",
            "recurrence_group_id"
          ],
          "properties": {
            "session_id": {
              "type": "string",
              "description": "The scheduled session's ID."
            },
            "scheduled_date": {
              "type": "string",
              "format": "date-time",
              "description": "The scheduled start time."
            },
            "end_time": {
              "type": [
                "string",
                "null"
              ],
              "format": "date-time",
              "description": "The scheduled end time."
            },
            "duration_minutes": {
              "type": [
                "number",
                "null"
              ],
              "description": "The scheduled length."
            },
            "status": {
              "enum": [
                "scheduled",
                "completed",
                "canceled",
                "no-show"
              ]
            },
            "recurrence_group_id": {
              "type": [
                "string",
                "null"
              ],
              "description": "Set when the session belongs to a recurring series."
            }
          }
        },
        "flags": {
          "type": "object",
          "description": "What kind of note this is.",
          "properties": {
            "essential_info": {
              "type": "boolean",
              "description": "The note holds important information about the member."
            },
            "recovery_capital_summary": {
              "type": "boolean",
              "description": "The note came from a recovery capital assessment."
            },
            "compliance": {
              "type": "boolean",
              "description": "The note is a compliance note."
            },
            "tox_review": {
              "type": "boolean",
              "description": "The note came from a review of a recorded test."
            },
            "onboarding_complete": {
              "type": "boolean",
              "description": "The note marks the end of onboarding."
            },
            "notify_care_team": {
              "type": "boolean",
              "description": "The care team was notified about the note."
            },
            "call": {
              "type": "boolean",
              "description": "A call was made."
            },
            "email": {
              "type": "boolean",
              "description": "An email was sent."
            },
            "checkin": {
              "type": "boolean",
              "description": "The note documents a session with the member."
            },
            "family_contact": {
              "type": "boolean",
              "description": "The note documents contact with family."
            },
            "clinical_contact": {
              "type": "boolean",
              "description": "The note documents contact with a clinician."
            },
            "justice_contact": {
              "type": "boolean",
              "description": "The note documents contact with probation, court or other justice staff."
            },
            "no_show": {
              "type": "boolean",
              "description": "The member missed a scheduled session."
            }
          }
        },
        "tox_id": {
          "type": [
            "string",
            "null"
          ],
          "description": "The related test result, if there is one. Matches test_id on toxicology and breathalyzer events."
        },
        "file": {
          "type": "null",
          "description": "Reserved. Always null."
        }
      }
    }
  }
}
