-- Modify "Ambulatory" table
ALTER TABLE "public"."Ambulatory" DROP CONSTRAINT "fk_Ambulatory_Encounter", ADD COLUMN "VisitMode_Code" text NULL, ADD CONSTRAINT "fk_Encounter_Ambulatory" FOREIGN KEY ("Encounter_Id") REFERENCES "public"."Encounter" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION;
-- Modify "Emergency" table
ALTER TABLE "public"."Emergency" DROP CONSTRAINT "fk_Emergency_Encounter", ADD CONSTRAINT "fk_Encounter_Emergency" FOREIGN KEY ("Encounter_Id") REFERENCES "public"."Encounter" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION;
-- Modify "Inpatient" table
ALTER TABLE "public"."Inpatient" DROP CONSTRAINT "fk_Inpatient_Encounter", ADD CONSTRAINT "fk_Encounter_Inpatient" FOREIGN KEY ("Encounter_Id") REFERENCES "public"."Encounter" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION;
-- Create "Rehab" table
CREATE TABLE "public"."Rehab" (
  "Id" bigserial NOT NULL,
  "CreatedAt" timestamptz NULL,
  "UpdatedAt" timestamptz NULL,
  "DeletedAt" timestamptz NULL,
  "Encounter_Id" bigint NULL,
  "Doctor_Id" bigint NULL,
  "AllocatedVisitCount" bigint NULL,
  PRIMARY KEY ("Id"),
  CONSTRAINT "fk_Rehab_Doctor" FOREIGN KEY ("Doctor_Id") REFERENCES "public"."Doctor" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION,
  CONSTRAINT "fk_Rehab_Encounter" FOREIGN KEY ("Encounter_Id") REFERENCES "public"."Encounter" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION
);
