-- Modify "Consultation" table
ALTER TABLE "public"."Consultation" ALTER COLUMN "DstUnit_Code" TYPE character varying(20);
-- Modify "ControlLetter" table
ALTER TABLE "public"."ControlLetter" ALTER COLUMN "Unit_Code" TYPE character varying(20), ALTER COLUMN "Specialist_Code" TYPE character varying(20), ALTER COLUMN "Subspecialist_Code" TYPE character varying(20);
-- Modify "Encounter" table
ALTER TABLE "public"."Encounter" ALTER COLUMN "Specialist_Code" TYPE character varying(20), ALTER COLUMN "Subspecialist_Code" TYPE character varying(20), ALTER COLUMN "Unit_Code" TYPE character varying(20);
-- Modify "Chemo" table
ALTER TABLE "public"."Chemo" ALTER COLUMN "SrcUnit_Code" TYPE character varying(20);
-- Modify "Installation" table
ALTER TABLE "public"."Installation" ALTER COLUMN "Code" TYPE character varying(20);
-- Modify "InternalReference" table
ALTER TABLE "public"."InternalReference" ALTER COLUMN "Unit_Code" TYPE character varying(20);
-- Modify "PracticeSchedule" table
ALTER TABLE "public"."PracticeSchedule" ALTER COLUMN "Unit_Code" TYPE character varying(20);
-- Create "DevicePackage" table
CREATE TABLE "public"."DevicePackage" (
  "Id" serial NOT NULL,
  "CreatedAt" timestamptz NULL,
  "UpdatedAt" timestamptz NULL,
  "DeletedAt" timestamptz NULL,
  "Code" character varying(20) NOT NULL,
  "Name" character varying(50) NULL,
  PRIMARY KEY ("Id"),
  CONSTRAINT "uni_DevicePackage_Code" UNIQUE ("Code")
);
-- Create "DevicePackageItem" table
CREATE TABLE "public"."DevicePackageItem" (
  "Id" bigserial NOT NULL,
  "CreatedAt" timestamptz NULL,
  "UpdatedAt" timestamptz NULL,
  "DeletedAt" timestamptz NULL,
  "DevicePackage_Code" character varying(20) NOT NULL,
  "Device_Code" character varying(20) NOT NULL,
  PRIMARY KEY ("Id"),
  CONSTRAINT "fk_DevicePackageItem_Device" FOREIGN KEY ("Device_Code") REFERENCES "public"."Device" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION,
  CONSTRAINT "fk_DevicePackageItem_DevicePackage" FOREIGN KEY ("DevicePackage_Code") REFERENCES "public"."DevicePackage" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION
);
-- Create "MaterialPackage" table
CREATE TABLE "public"."MaterialPackage" (
  "Id" serial NOT NULL,
  "CreatedAt" timestamptz NULL,
  "UpdatedAt" timestamptz NULL,
  "DeletedAt" timestamptz NULL,
  "Code" character varying(20) NOT NULL,
  "Name" character varying(50) NULL,
  PRIMARY KEY ("Id"),
  CONSTRAINT "uni_MaterialPackage_Code" UNIQUE ("Code")
);
-- Create "MaterialPackageItem" table
CREATE TABLE "public"."MaterialPackageItem" (
  "Id" bigserial NOT NULL,
  "CreatedAt" timestamptz NULL,
  "UpdatedAt" timestamptz NULL,
  "DeletedAt" timestamptz NULL,
  "MaterialPackage_Code" character varying(20) NOT NULL,
  "Material_Code" character varying(20) NOT NULL,
  PRIMARY KEY ("Id"),
  CONSTRAINT "fk_MaterialPackageItem_Material" FOREIGN KEY ("Material_Code") REFERENCES "public"."Material" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION,
  CONSTRAINT "fk_MaterialPackageItem_MaterialPackage" FOREIGN KEY ("MaterialPackage_Code") REFERENCES "public"."MaterialPackage" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION
);
-- Modify "Infra" table
ALTER TABLE "public"."Infra" ALTER COLUMN "Code" TYPE character varying(20), ALTER COLUMN "InfraGroup_Code" TYPE character varying(20), ALTER COLUMN "Parent_Code" TYPE character varying(20);
-- Modify "Specialist" table
ALTER TABLE "public"."Specialist" ALTER COLUMN "Code" TYPE character varying(20), ALTER COLUMN "Unit_Code" TYPE character varying(20);
-- Modify "Subspecialist" table
ALTER TABLE "public"."Subspecialist" ALTER COLUMN "Code" TYPE character varying(20), ALTER COLUMN "Specialist_Code" TYPE character varying(20);
-- Modify "Unit" table
ALTER TABLE "public"."Unit" ALTER COLUMN "Code" TYPE character varying(20), ALTER COLUMN "Installation_Code" TYPE character varying(20);
-- Create "ProcedureRoom" table
CREATE TABLE "public"."ProcedureRoom" (
  "Id" serial NOT NULL,
  "CreatedAt" timestamptz NULL,
  "UpdatedAt" timestamptz NULL,
  "DeletedAt" timestamptz NULL,
  "Code" character varying(20) NULL,
  "Infra_Code" character varying(20) NULL,
  "Type_Code" character varying(10) NULL,
  "Unit_Code" character varying(20) NULL,
  "Specialist_Code" character varying(20) NULL,
  "Subspecialist_Code" character varying(20) NULL,
  PRIMARY KEY ("Id"),
  CONSTRAINT "uni_ProcedureRoom_Code" UNIQUE ("Code"),
  CONSTRAINT "uni_ProcedureRoom_Infra_Code" UNIQUE ("Infra_Code"),
  CONSTRAINT "fk_ProcedureRoom_Infra" FOREIGN KEY ("Infra_Code") REFERENCES "public"."Infra" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION,
  CONSTRAINT "fk_ProcedureRoom_Specialist" FOREIGN KEY ("Specialist_Code") REFERENCES "public"."Specialist" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION,
  CONSTRAINT "fk_ProcedureRoom_Subspecialist" FOREIGN KEY ("Subspecialist_Code") REFERENCES "public"."Subspecialist" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION,
  CONSTRAINT "fk_ProcedureRoom_Unit" FOREIGN KEY ("Unit_Code") REFERENCES "public"."Unit" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION
);
-- Create "ProcedureRoomOrder" table
CREATE TABLE "public"."ProcedureRoomOrder" (
  "Id" bigserial NOT NULL,
  "CreatedAt" timestamptz NULL,
  "UpdatedAt" timestamptz NULL,
  "DeletedAt" timestamptz NULL,
  "Encounter_Id" bigint NULL,
  "Infra_Code" character varying(20) NULL,
  PRIMARY KEY ("Id"),
  CONSTRAINT "fk_ProcedureRoomOrder_ProcedureRoom" FOREIGN KEY ("Infra_Code") REFERENCES "public"."ProcedureRoom" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION
);
-- Drop "Room" table
DROP TABLE "public"."Room";
