-- Modify "Chemo" table
ALTER TABLE "public"."Chemo" ADD COLUMN "Doctor_Code" character varying(20) NULL, ADD COLUMN "NextChemoDate" timestamptz NULL, ADD CONSTRAINT "fk_Chemo_Doctor" FOREIGN KEY ("Doctor_Code") REFERENCES "public"."Doctor" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION;
-- Rename a column from "Encounter_Id" to "Chemo_Id"
ALTER TABLE "public"."ChemoProtocol" RENAME COLUMN "Encounter_Id" TO "Chemo_Id";
-- Modify "ChemoProtocol" table
ALTER TABLE "public"."ChemoProtocol" DROP CONSTRAINT "fk_ChemoProtocol_Encounter", ALTER COLUMN "DurationUnit_Code" TYPE text, ADD COLUMN "Interval" bigint NULL, ADD COLUMN "Cycle" bigint NULL, ADD COLUMN "Series" integer NULL, ADD COLUMN "Status_Code" text NULL, ADD CONSTRAINT "fk_ChemoProtocol_Chemo" FOREIGN KEY ("Chemo_Id") REFERENCES "public"."Chemo" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION;
-- Create "ChemoPlan" table
CREATE TABLE "public"."ChemoPlan" (
  "Id" bigserial NOT NULL,
  "CreatedAt" timestamptz NULL,
  "UpdatedAt" timestamptz NULL,
  "DeletedAt" timestamptz NULL,
  "Parent_Id" bigint NULL,
  "Protocol_Id" bigint NULL,
  "SeriesNumber" integer NULL,
  "CycleNumber" bigint NULL,
  "PlanDate" timestamptz NULL,
  "RealizationDate" timestamptz NULL,
  "Notes" text NULL,
  "Status" text NULL,
  PRIMARY KEY ("Id"),
  CONSTRAINT "fk_ChemoPlan_Protocol" FOREIGN KEY ("Protocol_Id") REFERENCES "public"."ChemoProtocol" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION
);
