-- Modify "Item" table
ALTER TABLE "public"."Item" ALTER COLUMN "Stock" TYPE bigint;
-- Create "Device" table
CREATE TABLE "public"."Device" (
  "Id" bigserial NOT NULL,
  "CreatedAt" timestamptz NULL,
  "UpdatedAt" timestamptz NULL,
  "DeletedAt" timestamptz NULL,
  "Code" character varying(10) NULL,
  "Name" character varying(50) NULL,
  "Uom_Code" character varying(10) NULL,
  "Item_Id" bigint NULL,
  PRIMARY KEY ("Id"),
  CONSTRAINT "uni_Device_Code" UNIQUE ("Code"),
  CONSTRAINT "fk_Device_Item" FOREIGN KEY ("Item_Id") REFERENCES "public"."Item" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION,
  CONSTRAINT "fk_Device_Uom" FOREIGN KEY ("Uom_Code") REFERENCES "public"."Uom" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION
);
-- Create "DoctorFee" table
CREATE TABLE "public"."DoctorFee" (
  "Id" bigserial NOT NULL,
  "CreatedAt" timestamptz NULL,
  "UpdatedAt" timestamptz NULL,
  "DeletedAt" timestamptz NULL,
  "Doctor_Id" bigint NULL,
  "FeeTypeCode" character varying(11) NULL,
  "Price" numeric NULL,
  "Item_Id" bigint NULL,
  PRIMARY KEY ("Id"),
  CONSTRAINT "fk_DoctorFee_Doctor" FOREIGN KEY ("Doctor_Id") REFERENCES "public"."Doctor" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION,
  CONSTRAINT "fk_DoctorFee_Item" FOREIGN KEY ("Item_Id") REFERENCES "public"."Item" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION
);
-- Modify "ItemPrice" table
ALTER TABLE "public"."ItemPrice" ADD COLUMN "InsuranceCompany_Code" character varying(20) NULL, ADD CONSTRAINT "fk_ItemPrice_InsuranceCompany" FOREIGN KEY ("InsuranceCompany_Code") REFERENCES "public"."InsuranceCompany" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION;
-- Create "Material" table
CREATE TABLE "public"."Material" (
  "Id" bigserial NOT NULL,
  "CreatedAt" timestamptz NULL,
  "UpdatedAt" timestamptz NULL,
  "DeletedAt" timestamptz NULL,
  "Code" character varying(10) NULL,
  "Name" character varying(50) NULL,
  "Uom_Code" character varying(10) NULL,
  "Stock" bigint NULL,
  "Item_Id" bigint NULL,
  PRIMARY KEY ("Id"),
  CONSTRAINT "uni_Material_Code" UNIQUE ("Code"),
  CONSTRAINT "fk_Material_Item" FOREIGN KEY ("Item_Id") REFERENCES "public"."Item" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION,
  CONSTRAINT "fk_Material_Uom" FOREIGN KEY ("Uom_Code") REFERENCES "public"."Uom" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION
);
-- Create "MedicalActionSrc" table
CREATE TABLE "public"."MedicalActionSrc" (
  "Id" bigserial NOT NULL,
  "CreatedAt" timestamptz NULL,
  "UpdatedAt" timestamptz NULL,
  "DeletedAt" timestamptz NULL,
  "Code" character varying(20) NULL,
  "Name" character varying(50) NULL,
  "Item_Id" bigint NULL,
  PRIMARY KEY ("Id"),
  CONSTRAINT "uni_MedicalActionSrc_Code" UNIQUE ("Code"),
  CONSTRAINT "fk_MedicalActionSrc_Item" FOREIGN KEY ("Item_Id") REFERENCES "public"."Item" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION
);
-- Create "MedicalActionSrcItem" table
CREATE TABLE "public"."MedicalActionSrcItem" (
  "Id" bigserial NOT NULL,
  "CreatedAt" timestamptz NULL,
  "UpdatedAt" timestamptz NULL,
  "DeletedAt" timestamptz NULL,
  "MedicalActionSrc_Id" bigint NULL,
  "ProcedureSrc_Id" bigint NULL,
  "Item_Id" bigint NULL,
  PRIMARY KEY ("Id"),
  CONSTRAINT "fk_MedicalActionSrcItem_Item" FOREIGN KEY ("Item_Id") REFERENCES "public"."Item" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION,
  CONSTRAINT "fk_MedicalActionSrcItem_MedicalActionSrc" FOREIGN KEY ("MedicalActionSrc_Id") REFERENCES "public"."MedicalActionSrc" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION,
  CONSTRAINT "fk_MedicalActionSrcItem_ProcedureSrc" FOREIGN KEY ("ProcedureSrc_Id") REFERENCES "public"."ProcedureSrc" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION
);
-- Create "Medicine" table
CREATE TABLE "public"."Medicine" (
  "Id" bigserial NOT NULL,
  "CreatedAt" timestamptz NULL,
  "UpdatedAt" timestamptz NULL,
  "DeletedAt" timestamptz NULL,
  "Code" character varying(10) NULL,
  "Name" character varying(50) NULL,
  "MedicineGroup_Code" character varying(10) NULL,
  "MedicineMethod_Code" character varying(10) NULL,
  "Uom_Code" character varying(10) NULL,
  "Dose" smallint NULL,
  "Infra_Id" integer NULL,
  "Stock" bigint NULL,
  "Item_Id" bigint NULL,
  PRIMARY KEY ("Id"),
  CONSTRAINT "uni_Medicine_Code" UNIQUE ("Code"),
  CONSTRAINT "fk_Medicine_Infra" FOREIGN KEY ("Infra_Id") REFERENCES "public"."Infra" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION,
  CONSTRAINT "fk_Medicine_Item" FOREIGN KEY ("Item_Id") REFERENCES "public"."Item" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION,
  CONSTRAINT "fk_Medicine_MedicineGroup" FOREIGN KEY ("MedicineGroup_Code") REFERENCES "public"."MedicineGroup" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION,
  CONSTRAINT "fk_Medicine_MedicineMethod" FOREIGN KEY ("MedicineMethod_Code") REFERENCES "public"."MedicineMethod" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION,
  CONSTRAINT "fk_Medicine_Uom" FOREIGN KEY ("Uom_Code") REFERENCES "public"."Uom" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION
);
-- Create "MedicineMix" table
CREATE TABLE "public"."MedicineMix" (
  "Id" bigserial NOT NULL,
  "CreatedAt" timestamptz NULL,
  "UpdatedAt" timestamptz NULL,
  "DeletedAt" timestamptz NULL,
  "Name" character varying(50) NULL,
  PRIMARY KEY ("Id")
);
-- Create "MedicineMixItem" table
CREATE TABLE "public"."MedicineMixItem" (
  "Id" bigserial NOT NULL,
  "CreatedAt" timestamptz NULL,
  "UpdatedAt" timestamptz NULL,
  "DeletedAt" timestamptz NULL,
  "MedicineMix_Id" bigint NULL,
  "Medicine_Id" bigint NULL,
  "Dose" smallint NULL,
  PRIMARY KEY ("Id"),
  CONSTRAINT "fk_MedicineMixItem_Medicine" FOREIGN KEY ("Medicine_Id") REFERENCES "public"."Medicine" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION,
  CONSTRAINT "fk_MedicineMixItem_MedicineMix" FOREIGN KEY ("MedicineMix_Id") REFERENCES "public"."MedicineMix" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION
);
