{
  "$schema": "mantara.schema.v1",
  "system_name": "Healthcare Management System",
  "schema_name": "ai_sch_20260514_063824",
  "description": "A comprehensive system for managing healthcare operations, including patient records, appointments, billing, and reports.",
  "menus": [
    {
      "menu_id": 1,
      "menu_name": "User Management",
      "sequence_number": 1,
      "description": "Manage user accounts, roles, and departments.",
      "submenus": [
        {
          "submenu_id": 101,
          "submenu_name": "User Accounts",
          "sequence_number": 1,
          "description": "Manage user profiles and authentication.",
          "tables": [
            {
              "table_name": "users",
              "comment": "Stores user accounts and authentication details.",
              "columns": [
                {
                  "name": "id",
                  "type": "UUID",
                  "constraints": "PRIMARY KEY DEFAULT gen_random_uuid()"
                },
                {
                  "name": "submenu_id",
                  "type": "INT",
                  "constraints": "DEFAULT 101 NOT NULL REFERENCES hms.submenu(submenu_id)"
                },
                {
                  "name": "email",
                  "type": "VARCHAR(255)",
                  "constraints": "NOT NULL UNIQUE"
                },
                {
                  "name": "password_hash",
                  "type": "VARCHAR(255)",
                  "constraints": "NOT NULL",
                  "comment": "Stores bcrypt hash, never plain text"
                },
                {
                  "name": "first_name",
                  "type": "VARCHAR(100)",
                  "constraints": "NOT NULL"
                },
                {
                  "name": "last_name",
                  "type": "VARCHAR(100)",
                  "constraints": "NOT NULL"
                },
                {
                  "name": "role",
                  "type": "VARCHAR(50)",
                  "constraints": "NOT NULL CHECK (role IN ('administrator', 'doctor', 'nurse', 'receptionist', 'billing_officer'))"
                },
                {
                  "name": "phone",
                  "type": "VARCHAR(20)"
                },
                {
                  "name": "department_id",
                  "type": "UUID",
                  "constraints": "REFERENCES hms.departments(id) ON DELETE SET NULL"
                },
                {
                  "name": "is_active",
                  "type": "BOOLEAN",
                  "constraints": "NOT NULL DEFAULT true"
                },
                {
                  "name": "created_at",
                  "type": "TIMESTAMP",
                  "constraints": "NOT NULL DEFAULT CURRENT_TIMESTAMP"
                },
                {
                  "name": "updated_at",
                  "type": "TIMESTAMP",
                  "constraints": "NOT NULL DEFAULT CURRENT_TIMESTAMP"
                }
              ],
              "foreign_keys": [
                {
                  "column": "department_id",
                  "references": "hms.departments(id)",
                  "on_delete": "SET NULL"
                }
              ]
            }
          ]
        },
        {
          "submenu_id": 102,
          "submenu_name": "Departments",
          "sequence_number": 2,
          "description": "Manage organizational units within the healthcare facility.",
          "tables": [
            {
              "table_name": "departments",
              "comment": "Stores department details within the healthcare facility.",
              "columns": [
                {
                  "name": "id",
                  "type": "UUID",
                  "constraints": "PRIMARY KEY DEFAULT gen_random_uuid()"
                },
                {
                  "name": "submenu_id",
                  "type": "INT",
                  "constraints": "DEFAULT 102 NOT NULL REFERENCES hms.submenu(submenu_id)"
                },
                {
                  "name": "name",
                  "type": "VARCHAR(100)",
                  "constraints": "NOT NULL UNIQUE"
                },
                {
                  "name": "description",
                  "type": "TEXT"
                },
                {
                  "name": "created_at",
                  "type": "TIMESTAMP",
                  "constraints": "NOT NULL DEFAULT CURRENT_TIMESTAMP"
                },
                {
                  "name": "updated_at",
                  "type": "TIMESTAMP",
                  "constraints": "NOT NULL DEFAULT CURRENT_TIMESTAMP"
                }
              ]
            }
          ]
        }
      ]
    },
    {
      "menu_id": 2,
      "menu_name": "Patient Management",
      "sequence_number": 2,
      "description": "Manage patient records, demographics, and medical history.",
      "submenus": [
        {
          "submenu_id": 201,
          "submenu_name": "Patient Records",
          "sequence_number": 1,
          "description": "Manage patient demographic and contact information.",
          "tables": [
            {
              "table_name": "patients",
              "comment": "Stores patient demographic and contact information.",
              "columns": [
                {
                  "name": "id",
                  "type": "UUID",
                  "constraints": "PRIMARY KEY DEFAULT gen_random_uuid()"
                },
                {
                  "name": "submenu_id",
                  "type": "INT",
                  "constraints": "DEFAULT 201 NOT NULL REFERENCES hms.submenu(submenu_id)"
                },
                {
                  "name": "patient_number",
                  "type": "VARCHAR(50)",
                  "constraints": "NOT NULL UNIQUE"
                },
                {
                  "name": "first_name",
                  "type": "VARCHAR(100)",
                  "constraints": "NOT NULL"
                },
                {
                  "name": "last_name",
                  "type": "VARCHAR(100)",
                  "constraints": "NOT NULL"
                },
                {
                  "name": "date_of_birth",
                  "type": "DATE",
                  "constraints": "NOT NULL"
                },
                {
                  "name": "gender",
                  "type": "VARCHAR(20)",
                  "constraints": "NOT NULL CHECK (gender IN ('male', 'female', 'other'))"
                },
                {
                  "name": "phone",
                  "type": "VARCHAR(20)"
                },
                {
                  "name": "email",
                  "type": "VARCHAR(100)"
                },
                {
                  "name": "address",
                  "type": "TEXT"
                },
                {
                  "name": "city",
                  "type": "VARCHAR(100)"
                },
                {
                  "name": "state",
                  "type": "VARCHAR(100)"
                },
                {
                  "name": "postal_code",
                  "type": "VARCHAR(20)"
                },
                {
                  "name": "country",
                  "type": "VARCHAR(100)"
                },
                {
                  "name": "emergency_contact_name",
                  "type": "VARCHAR(200)"
                },
                {
                  "name": "emergency_contact_phone",
                  "type": "VARCHAR(20)"
                },
                {
                  "name": "emergency_contact_relationship",
                  "type": "VARCHAR(100)"
                },
                {
                  "name": "insurance_provider_id",
                  "type": "UUID",
                  "constraints": "REFERENCES hms.insurance_providers(id) ON DELETE SET NULL"
                },
                {
                  "name": "insurance_policy_number",
                  "type": "VARCHAR(100)"
                },
                {
                  "name": "created_at",
                  "type": "TIMESTAMP",
                  "constraints": "NOT NULL DEFAULT CURRENT_TIMESTAMP"
                },
                {
                  "name": "updated_at",
                  "type": "TIMESTAMP",
                  "constraints": "NOT NULL DEFAULT CURRENT_TIMESTAMP"
                }
              ],
              "foreign_keys": [
                {
                  "column": "insurance_provider_id",
                  "references": "hms.insurance_providers(id)",
                  "on_delete": "SET NULL"
                }
              ]
            }
          ]
        },
        {
          "submenu_id": 202,
          "submenu_name": "Medical Records",
          "sequence_number": 2,
          "description": "Manage comprehensive medical history for each patient.",
          "tables": [
            {
              "table_name": "medical_records",
              "comment": "Stores comprehensive medical history for each patient.",
              "columns": [
                {
                  "name": "id",
                  "type": "UUID",
                  "constraints": "PRIMARY KEY DEFAULT gen_random_uuid()"
                },
                {
                  "name": "submenu_id",
                  "type": "INT",
                  "constraints": "DEFAULT 202 NOT NULL REFERENCES hms.submenu(submenu_id)"
                },
                {
                  "name": "patient_id",
                  "type": "UUID",
                  "constraints": "NOT NULL UNIQUE REFERENCES hms.patients(id) ON DELETE CASCADE"
                },
                {
                  "name": "blood_type",
                  "type": "VARCHAR(10)"
                },
                {
                  "name": "allergies",
                  "type": "TEXT"
                },
                {
                  "name": "chronic_conditions",
                  "type": "TEXT"
                },
                {
                  "name": "family_medical_history",
                  "type": "TEXT"
                },
                {
                  "name": "surgical_history",
                  "type": "TEXT"
                },
                {
                  "name": "immunization_history",
                  "type": "TEXT"
                },
                {
                  "name": "notes",
                  "type": "TEXT"
                },
                {
                  "name": "created_at",
                  "type": "TIMESTAMP",
                  "constraints": "NOT NULL DEFAULT CURRENT_TIMESTAMP"
                },
                {
                  "name": "updated_at",
                  "type": "TIMESTAMP",
                  "constraints": "NOT NULL DEFAULT CURRENT_TIMESTAMP"
                }
              ],
              "foreign_keys": [
                {
                  "column": "patient_id",
                  "references": "hms.patients(id)",
                  "on_delete": "CASCADE"
                }
              ]
            }
          ]
        }
      ]
    },
    {
      "menu_id": 3,
      "menu_name": "Appointment Management",
      "sequence_number": 3,
      "description": "Schedule and manage patient appointments.",
      "submenus": [
        {
          "submenu_id": 301,
          "submenu_name": "Appointments",
          "sequence_number": 1,
          "description": "Manage scheduling and details of patient appointments.",
          "tables": [
            {
              "table_name": "appointments",
              "comment": "Stores details of patient appointments.",
              "columns": [
                {
                  "name": "id",
                  "type": "UUID",
                  "constraints": "PRIMARY KEY DEFAULT gen_random_uuid()"
                },
                {
                  "name": "submenu_id",
                  "type": "INT",
                  "constraints": "DEFAULT 301 NOT NULL REFERENCES hms.submenu(submenu_id)"
                },
                {
                  "name": "patient_id",
                  "type": "UUID",
                  "constraints": "NOT NULL REFERENCES hms.patients(id) ON DELETE CASCADE"
                },
                {
                  "name": "doctor_id",
                  "type": "UUID",
                  "constraints": "NOT NULL REFERENCES hms.users(id) ON DELETE RESTRICT"
                },
                {
                  "name": "department_id",
                  "type": "UUID",
                  "constraints": "REFERENCES hms.departments(id) ON DELETE SET NULL"
                },
                {
                  "name": "appointment_date",
                  "type": "DATE",
                  "constraints": "NOT NULL"
                },
                {
                  "name": "appointment_time",
                  "type": "TIME",
                  "constraints": "NOT NULL"
                },
                {
                  "name": "duration_minutes",
                  "type": "INTEGER",
                  "constraints": "NOT NULL DEFAULT 30"
                },
                {
                  "name": "appointment_type",
                  "type": "VARCHAR(50)",
                  "constraints": "NOT NULL CHECK (appointment_type IN ('consultation', 'follow_up', 'emergency', 'routine_checkup', 'procedure'))"
                },
                {
                  "name": "status",
                  "type": "VARCHAR(50)",
                  "constraints": "NOT NULL CHECK (status IN ('scheduled', 'confirmed', 'checked_in', 'in_progress', 'completed', 'cancelled', 'no_show'))"
                },
                {
                  "name": "reason",
                  "type": "TEXT"
                },
                {
                  "name": "notes",
                  "type": "TEXT"
                },
                {
                  "name": "created_at",
                  "type": "TIMESTAMP",
                  "constraints": "NOT NULL DEFAULT CURRENT_TIMESTAMP"
                },
                {
                  "name": "updated_at",
                  "type": "TIMESTAMP",
                  "constraints": "NOT NULL DEFAULT CURRENT_TIMESTAMP"
                }
              ],
              "foreign_keys": [
                {
                  "column": "patient_id",
                  "references": "hms.patients(id)",
                  "on_delete": "CASCADE"
                },
                {
                  "column": "doctor_id",
                  "references": "hms.users(id)",
                  "on_delete": "RESTRICT"
                },
                {
                  "column": "department_id",
                  "references": "hms.departments(id)",
                  "on_delete": "SET NULL"
                }
              ]
            }
          ]
        }
      ]
    },
    {
      "menu_id": 4,
      "menu_name": "Clinical Management",
      "sequence_number": 4,
      "description": "Manage consultations, prescriptions, and lab tests.",
      "submenus": [
        {
          "submenu_id": 401,
          "submenu_name": "Consultations",
          "sequence_number": 1,
          "description": "Document and manage patient consultations.",
          "tables": [
            {
              "table_name": "consultations",
              "comment": "Stores details of patient consultations.",
              "columns": [
                {
                  "name": "id",
                  "type": "UUID",
                  "constraints": "PRIMARY KEY DEFAULT gen_random_uuid()"
                },
                {
                  "name": "submenu_id",
                  "type": "INT",
                  "constraints": "DEFAULT 401 NOT NULL REFERENCES hms.submenu(submenu_id)"
                },
                {
                  "name": "appointment_id",
                  "type": "UUID",
                  "constraints": "UNIQUE REFERENCES hms.appointments(id) ON DELETE SET NULL"
                },
                {
                  "name": "patient_id",
                  "type": "UUID",
                  "constraints": "NOT NULL REFERENCES hms.patients(id) ON DELETE CASCADE"
                },
                {
                  "name": "doctor_id",
                  "type": "UUID",
                  "constraints": "NOT NULL REFERENCES hms.users(id) ON DELETE RESTRICT"
                },
                {
                  "name": "consultation_date",
                  "type": "TIMESTAMP",
                  "constraints": "NOT NULL"
                },
                {
                  "name": "chief_complaint",
                  "type": "TEXT"
                },
                {
                  "name": "present_illness",
                  "type": "TEXT"
                },
                {
                  "name": "examination_findings",
                  "type": "TEXT"
                },
                {
                  "name": "diagnosis",
                  "type": "TEXT"
                },
                {
                  "name": "treatment_plan",
                  "type": "TEXT"
                },
                {
                  "name": "notes",
                  "type": "TEXT"
                },
                {
                  "name": "follow_up_required",
                  "type": "BOOLEAN",
                  "constraints": "NOT NULL DEFAULT false"
                },
                {
                  "name": "follow_up_date",
                  "type": "DATE"
                },
                {
                  "name": "created_at",
                  "type": "TIMESTAMP",
                  "constraints": "NOT NULL DEFAULT CURRENT_TIMESTAMP"
                },
                {
                  "name": "updated_at",
                  "type": "TIMESTAMP",
                  "constraints": "NOT NULL DEFAULT CURRENT_TIMESTAMP"
                }
              ],
              "foreign_keys": [
                {
                  "column": "appointment_id",
                  "references": "hms.appointments(id)",
                  "on_delete": "SET NULL"
                },
                {
                  "column": "patient_id",
                  "references": "hms.patients(id)",
                  "on_delete": "CASCADE"
                },
                {
                  "column": "doctor_id",
                  "references": "hms.users(id)",
                  "on_delete": "RESTRICT"
                }
              ]
            }
          ]
        },
        {
          "submenu_id": 402,
          "submenu_name": "Prescriptions",
          "sequence_number": 2,
          "description": "Manage medication prescriptions issued during consultations.",
          "tables": [
            {
              "table_name": "prescriptions",
              "comment": "Stores medication prescriptions issued during consultations.",
              "columns": [
                {
                  "name": "id",
                  "type": "UUID",
                  "constraints": "PRIMARY KEY DEFAULT gen_random_uuid()"
                },
                {
                  "name": "submenu_id",
                  "type": "INT",
                  "constraints": "DEFAULT 402 NOT NULL REFERENCES hms.submenu(submenu_id)"
                },
                {
                  "name": "consultation_id",
                  "type": "UUID",
                  "constraints": "NOT NULL REFERENCES hms.consultations(id) ON DELETE CASCADE"
                },
                {
                  "name": "patient_id",
                  "type": "UUID",
                  "constraints": "NOT NULL REFERENCES hms.patients(id) ON DELETE CASCADE"
                },
                {
                  "name": "doctor_id",
                  "type": "UUID",
                  "constraints": "NOT NULL REFERENCES hms.users(id) ON DELETE RESTRICT"
                },
                {
                  "name": "medication_name",
                  "type": "VARCHAR(200)",
                  "constraints": "NOT NULL"
                },
                {
                  "name": "dosage",
                  "type": "VARCHAR(100)",
                  "constraints": "NOT NULL"
                },
                {
                  "name": "frequency",
                  "type": "VARCHAR(100)",
                  "constraints": "NOT NULL"
                },
                {
                  "name": "duration",
                  "type": "VARCHAR(100)",
                  "constraints": "NOT NULL"
                },
                {
                  "name": "quantity",
                  "type": "INTEGER"
                },
                {
                  "name": "route",
                  "type": "VARCHAR(50)"
                },
                {
                  "name": "special_instructions",
                  "type": "TEXT"
                },
                {
                  "name": "is_active",
                  "type": "BOOLEAN",
                  "constraints": "NOT NULL DEFAULT true"
                },
                {
                  "name": "prescribed_date",
                  "type": "DATE",
                  "constraints": "NOT NULL"
                },
                {
                  "name": "created_at",
                  "type": "TIMESTAMP",
                  "constraints": "NOT NULL DEFAULT CURRENT_TIMESTAMP"
                },
                {
                  "name": "updated_at",
                  "type": "TIMESTAMP",
                  "constraints": "NOT NULL DEFAULT CURRENT_TIMESTAMP"
                }
              ],
              "foreign_keys": [
                {
                  "column": "consultation_id",
                  "references": "hms.consultations(id)",
                  "on_delete": "CASCADE"
                },
                {
                  "column": "patient_id",
                  "references": "hms.patients(id)",
                  "on_delete": "CASCADE"
                },
                {
                  "column": "doctor_id",
                  "references": "hms.users(id)",
                  "on_delete": "RESTRICT"
                }
              ]
            }
          ]
        },
        {
          "submenu_id": 403,
          "submenu_name": "Lab Tests",
          "sequence_number": 3,
          "description": "Manage lab test orders and results.",
          "tables": [
            {
              "table_name": "lab_tests",
              "comment": "Stores lab test orders and results for patients.",
              "columns": [
                {
                  "name": "id",
                  "type": "UUID",
                  "constraints": "PRIMARY KEY DEFAULT gen_random_uuid()"
                },
                {
                  "name": "submenu_id",
                  "type": "INT",
                  "constraints": "DEFAULT 403 NOT NULL REFERENCES hms.submenu(submenu_id)"
                },
                {
                  "name": "patient_id",
                  "type": "UUID",
                  "constraints": "NOT NULL REFERENCES hms.patients(id) ON DELETE CASCADE"
                },
                {
                  "name": "consultation_id",
                  "type": "UUID",
                  "constraints": "REFERENCES hms.consultations(id) ON DELETE SET NULL"
                },
                {
                  "name": "ordered_by_doctor_id",
                  "type": "UUID",
                  "constraints": "NOT NULL REFERENCES hms.users(id) ON DELETE RESTRICT"
                },
                {
                  "name": "test_name",
                  "type": "VARCHAR(200)",
                  "constraints": "NOT NULL"
                },
                {
                  "name": "test_type",
                  "type": "VARCHAR(100)"
                },
                {
                  "name": "ordered_date",
                  "type": "TIMESTAMP",
                  "constraints": "NOT NULL"
                },
                {
                  "name": "sample_collected_date",
                  "type": "TIMESTAMP"
                },
                {
                  "name": "result_date",
                  "type": "TIMESTAMP"
                },
                {
                  "name": "result_value",
                  "type": "TEXT"
                },
                {
                  "name": "result_unit",
                  "type": "VARCHAR(50)"
                },
                {
                  "name": "reference_range",
                  "type": "VARCHAR(100)"
                },
                {
                  "name": "status",
                  "type": "VARCHAR(50)",
                  "constraints": "NOT NULL CHECK (status IN ('ordered', 'sample_collected', 'in_progress', 'completed', 'cancelled'))"
                },
                {
                  "name": "notes",
                  "type": "TEXT"
                },
                {
                  "name": "created_at",
                  "type": "TIMESTAMP",
                  "constraints": "NOT NULL DEFAULT CURRENT_TIMESTAMP"
                },
                {
                  "name": "updated_at",
                  "type": "TIMESTAMP",
                  "constraints": "NOT NULL DEFAULT CURRENT_TIMESTAMP"
                }
              ],
              "foreign_keys": [
                {
                  "column": "patient_id",
                  "references": "hms.patients(id)",
                  "on_delete": "CASCADE"
                },
                {
                  "column": "consultation_id",
                  "references": "hms.consultations(id)",
                  "on_delete": "SET NULL"
                },
                {
                  "column": "ordered_by_doctor_id",
                  "references": "hms.users(id)",
                  "on_delete": "RESTRICT"
                }
              ]
            }
          ]
        }
      ]
    },
    {
      "menu_id": 5,
      "menu_name": "Billing & Finance",
      "sequence_number": 5,
      "description": "Manage billing, payments, and financial reports.",
      "submenus": [
        {
          "submenu_id": 501,
          "submenu_name": "Invoices",
          "sequence_number": 1,
          "description": "Generate and manage patient invoices.",
          "tables": [
            {
              "table_name": "invoices",
              "comment": "Stores billing information for patient services.",
              "columns": [
                {
                  "name": "id",
                  "type": "UUID",
                  "constraints": "PRIMARY KEY DEFAULT gen_random_uuid()"
                },
                {
                  "name": "submenu_id",
                  "type": "INT",
                  "constraints": "DEFAULT 501 NOT NULL REFERENCES hms.submenu(submenu_id)"
                },
                {
                  "name": "invoice_number",
                  "type": "VARCHAR(50)",
                  "constraints": "NOT NULL UNIQUE"
                },
                {
                  "name": "patient_id",
                  "type": "UUID",
                  "constraints": "NOT NULL REFERENCES hms.patients(id) ON DELETE RESTRICT"
                },
                {
                  "name": "appointment_id",
                  "type": "UUID",
                  "constraints": "REFERENCES hms.appointments(id) ON DELETE SET NULL"
                },
                {
                  "name": "invoice_date",
                  "type": "DATE",
                  "constraints": "NOT NULL"
                },
                {
                  "name": "due_date",
                  "type": "DATE"
                },
                {
                  "name": "subtotal",
                  "type": "DECIMAL(10,2)",
                  "constraints": "NOT NULL"
                },
                {
                  "name": "tax_amount",
                  "type": "DECIMAL(10,2)",
                  "constraints": "NOT NULL DEFAULT 0"
                },
                {
                  "name": "discount_amount",
                  "type": "DECIMAL(10,2)",
                  "constraints": "NOT NULL DEFAULT 0"
                },
                {
                  "name": "total_amount",
                  "type": "DECIMAL(10,2)",
                  "constraints": "NOT NULL"
                },
                {
                  "name": "amount_paid",
                  "type": "DECIMAL(10,2)",
                  "constraints": "NOT NULL DEFAULT 0"
                },
                {
                  "name": "balance_due",
                  "type": "DECIMAL(10,2)",
                  "constraints": "NOT NULL"
                },
                {
                  "name": "status",
                  "type": "VARCHAR(50)",
                  "constraints": "NOT NULL CHECK (status IN ('draft', 'issued', 'partially_paid', 'paid', 'overdue', 'cancelled'))"
                },
                {
                  "name": "notes",
                  "type": "TEXT"
                },
                {
                  "name": "created_by_user_id",
                  "type": "UUID",
                  "constraints": "REFERENCES hms.users(id) ON DELETE SET NULL"
                },
                {
                  "name": "created_at",
                  "type": "TIMESTAMP",
                  "constraints": "NOT NULL DEFAULT CURRENT_TIMESTAMP"
                },
                {
                  "name": "updated_at",
                  "type": "TIMESTAMP",
                  "constraints": "NOT NULL DEFAULT CURRENT_TIMESTAMP"
                }
              ],
              "foreign_keys": [
                {
                  "column": "patient_id",
                  "references": "hms.patients(id)",
                  "on_delete": "RESTRICT"
                },
                {
                  "column": "appointment_id",
                  "references": "hms.appointments(id)",
                  "on_delete": "SET NULL"
                },
                {
                  "column": "created_by_user_id",
                  "references": "hms.users(id)",
                  "on_delete": "SET NULL"
                }
              ]
            }
          ]
        },
        {
          "submenu_id": 502,
          "submenu_name": "Payments",
          "sequence_number": 2,
          "description": "Record and manage payments for invoices.",
          "tables": [
            {
              "table_name": "payments",
              "comment": "Records payments made against invoices.",
              "columns": [
                {
                  "name": "id",
                  "type": "UUID",
                  "constraints": "PRIMARY KEY DEFAULT gen_random_uuid()"
                },
                {
                  "name": "submenu_id",
                  "type": "INT",
                  "constraints": "DEFAULT 502 NOT NULL REFERENCES hms.submenu(submenu_id)"
                },
                {
                  "name": "invoice_id",
                  "type": "UUID",
                  "constraints": "NOT NULL REFERENCES hms.invoices(id) ON DELETE RESTRICT"
                },
                {
                  "name": "patient_id",
                  "type": "UUID",
                  "constraints": "NOT NULL REFERENCES hms.patients(id) ON DELETE RESTRICT"
                },
                {
                  "name": "payment_date",
                  "type": "TIMESTAMP",
                  "constraints": "NOT NULL"
                },
                {
                  "name": "amount",
                  "type": "DECIMAL(10,2)",
                  "constraints": "NOT NULL"
                },
                {
                  "name": "payment_method",
                  "type": "VARCHAR(50)",
                  "constraints": "NOT NULL CHECK (payment_method IN ('cash', 'credit_card', 'debit_card', 'insurance', 'bank_transfer', 'cheque', 'other'))"
                },
                {
                  "name": "transaction_reference",
                  "type": "VARCHAR(100)"
                },
                {
                  "name": "notes",
                  "type": "TEXT"
                },
                {
                  "name": "processed_by_user_id",
                  "type": "UUID",
                  "constraints": "REFERENCES hms.users(id) ON DELETE SET NULL"
                },
                {
                  "name": "created_at",
                  "type": "TIMESTAMP",
                  "constraints": "NOT NULL DEFAULT CURRENT_TIMESTAMP"
                },
                {
                  "name": "updated_at",
                  "type": "TIMESTAMP",
                  "constraints": "NOT NULL DEFAULT CURRENT_TIMESTAMP"
                }
              ],
              "foreign_keys": [
                {
                  "column": "invoice_id",
                  "references": "hms.invoices(id)",
                  "on_delete": "RESTRICT"
                },
                {
                  "column": "patient_id",
                  "references": "hms.patients(id)",
                  "on_delete": "RESTRICT"
                },
                {
                  "column": "processed_by_user_id",
                  "references": "hms.users(id)",
                  "on_delete": "SET NULL"
                }
              ]
            }
          ]
        }
      ]
    },
    {
      "menu_id": 6,
      "menu_name": "Configuration",
      "sequence_number": 6,
      "description": "Manage system configurations and settings.",
      "submenus": [
        {
          "submenu_id": 601,
          "submenu_name": "Insurance Providers",
          "sequence_number": 1,
          "description": "Manage insurance providers accepted by the facility.",
          "tables": [
            {
              "table_name": "insurance_providers",
              "comment": "Stores details of insurance providers accepted by the facility.",
              "columns": [
                {
                  "name": "id",
                  "type": "UUID",
                  "constraints": "PRIMARY KEY DEFAULT gen_random_uuid()"
                },
                {
                  "name": "submenu_id",
                  "type": "INT",
                  "constraints": "DEFAULT 601 NOT NULL REFERENCES hms.submenu(submenu_id)"
                },
                {
                  "name": "name",
                  "type": "VARCHAR(200)",
                  "constraints": "NOT NULL"
                },
                {
                  "name": "contact_person",
                  "type": "VARCHAR(100)"
                },
                {
                  "name": "phone",
                  "type": "VARCHAR(20)"
                },
                {
                  "name": "email",
                  "type": "VARCHAR(100)"
                },
                {
                  "name": "address",
                  "type": "TEXT"
                },
                {
                  "name": "coverage_policy",
                  "type": "TEXT"
                },
                {
                  "name": "created_at",
                  "type": "TIMESTAMP",
                  "constraints": "NOT NULL DEFAULT CURRENT_TIMESTAMP"
                },
                {
                  "name": "updated_at",
                  "type": "TIMESTAMP",
                  "constraints": "NOT NULL DEFAULT CURRENT_TIMESTAMP"
                }
              ]
            }
          ]
        }
      ]
    }
  ],
  "assumptions": [
    "Each patient has one primary insurance provider.",
    "Appointments are linked to a specific department and doctor.",
    "Consultations are created from checked-in appointments."
  ],
  "open_questions": [
    "Should the system support multi-currency billing?",
    "Is there a need for role-based access beyond admin/user?"
  ]
}
