-- CreateTable
CREATE TABLE "patient_return_visits" (
    "id" UUID NOT NULL,
    "host_id" UUID NOT NULL,
    "tenant_id" TEXT NOT NULL,
    "patient_id" UUID NOT NULL,
    "external_id" TEXT NOT NULL,
    "clinic_id" TEXT,
    "task_date" DATE,
    "type" TEXT,
    "status" TEXT,
    "task_status" TEXT,
    "treatment_items" TEXT,
    "follow_content" TEXT,
    "result" TEXT,
    "created_at" TIMESTAMPTZ(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updated_at" TIMESTAMPTZ(3) NOT NULL,

    CONSTRAINT "patient_return_visits_pkey" PRIMARY KEY ("id")
);

-- CreateIndex
CREATE INDEX "patient_return_visits_patient_id_task_date_idx" ON "patient_return_visits"("patient_id", "task_date" DESC);

-- CreateIndex
CREATE UNIQUE INDEX "patient_return_visits_host_id_tenant_id_external_id_key" ON "patient_return_visits"("host_id", "tenant_id", "external_id");

-- AddForeignKey
ALTER TABLE "patient_return_visits" ADD CONSTRAINT "patient_return_visits_patient_id_fkey" FOREIGN KEY ("patient_id") REFERENCES "patients"("id") ON DELETE CASCADE ON UPDATE CASCADE;
