-- Create "Appointment" table CREATE TABLE "public"."Appointment" ( "Id" bigserial NOT NULL, "CreatedAt" timestamptz NULL, "UpdatedAt" timestamptz NULL, "DeletedAt" timestamptz NULL, "PracticeSchedule_Id" bigint NULL, "Patient_Id" bigint NULL, "Person_ResidentIdentityNumber" character varying(16) NULL, "Person_Name" character varying(100) NULL, "Person_PhoneNumber" character varying(30) NULL, "PaymentMethod_Code" character varying(10) NULL, "RefNumber" character varying(20) NULL, PRIMARY KEY ("Id"), CONSTRAINT "fk_Appointment_Patient" FOREIGN KEY ("Patient_Id") REFERENCES "public"."Patient" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION, CONSTRAINT "fk_Appointment_PracticeSchedule" FOREIGN KEY ("PracticeSchedule_Id") REFERENCES "public"."PracticeSchedule" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION ); -- Modify "Encounter" table ALTER TABLE "public"."Encounter" ADD COLUMN "Appointment_Doctor_Id" bigint NULL, ADD COLUMN "Appointment_Id" bigint NULL, ADD COLUMN "EarlyEducation" text NULL, ADD COLUMN "MedicalDischargeEducation" text NULL, ADD COLUMN "AdmDischargeEducation" text NULL, ADD COLUMN "DischargeReason" text NULL, ADD CONSTRAINT "fk_Encounter_Appointment" FOREIGN KEY ("Appointment_Id") REFERENCES "public"."Appointment" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION, ADD CONSTRAINT "fk_Encounter_Appointment_Doctor" FOREIGN KEY ("Appointment_Doctor_Id") REFERENCES "public"."Doctor" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION; -- Create "Adime" table CREATE TABLE "public"."Adime" ( "Id" bigserial NOT NULL, "CreatedAt" timestamptz NULL, "UpdatedAt" timestamptz NULL, "DeletedAt" timestamptz NULL, "Encounter_Id" bigint NULL, "Employee_Id" bigint NULL, "Time" timestamptz NULL, "Value" text NULL, PRIMARY KEY ("Id"), CONSTRAINT "fk_Adime_Employee" FOREIGN KEY ("Employee_Id") REFERENCES "public"."Employee" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION, CONSTRAINT "fk_Adime_Encounter" FOREIGN KEY ("Encounter_Id") REFERENCES "public"."Encounter" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION ); -- Create "Ambulatory" table CREATE TABLE "public"."Ambulatory" ( "Id" bigserial NOT NULL, "CreatedAt" timestamptz NULL, "UpdatedAt" timestamptz NULL, "DeletedAt" timestamptz NULL, "Encounter_Id" bigint NULL, "Class_Code" character varying(10) NULL, PRIMARY KEY ("Id"), CONSTRAINT "fk_Ambulatory_Encounter" FOREIGN KEY ("Encounter_Id") REFERENCES "public"."Encounter" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION ); -- Create "Emergency" table CREATE TABLE "public"."Emergency" ( "Id" bigserial NOT NULL, "CreatedAt" timestamptz NULL, "UpdatedAt" timestamptz NULL, "DeletedAt" timestamptz NULL, "Encounter_Id" bigint NULL, "Class_Code" character varying(10) NULL, PRIMARY KEY ("Id"), CONSTRAINT "fk_Emergency_Encounter" FOREIGN KEY ("Encounter_Id") REFERENCES "public"."Encounter" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION ); -- Create "Inpatient" table CREATE TABLE "public"."Inpatient" ( "Id" bigserial NOT NULL, "CreatedAt" timestamptz NULL, "UpdatedAt" timestamptz NULL, "DeletedAt" timestamptz NULL, "Encounter_Id" bigint NULL, "Class_Code" character varying(10) NULL, "Infra_Id" integer NULL, PRIMARY KEY ("Id"), CONSTRAINT "fk_Inpatient_Encounter" FOREIGN KEY ("Encounter_Id") REFERENCES "public"."Encounter" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION, CONSTRAINT "fk_Inpatient_Infra" FOREIGN KEY ("Infra_Id") REFERENCES "public"."Infra" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION ); -- Create "Sbar" table CREATE TABLE "public"."Sbar" ( "Id" bigserial NOT NULL, "CreatedAt" timestamptz NULL, "UpdatedAt" timestamptz NULL, "DeletedAt" timestamptz NULL, "Encounter_Id" bigint NULL, "Employee_Id" bigint NULL, "Time" timestamptz NULL, "Value" text NULL, PRIMARY KEY ("Id"), CONSTRAINT "fk_Sbar_Employee" FOREIGN KEY ("Employee_Id") REFERENCES "public"."Employee" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION, CONSTRAINT "fk_Sbar_Encounter" FOREIGN KEY ("Encounter_Id") REFERENCES "public"."Encounter" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION ); -- Create "Soapi" table CREATE TABLE "public"."Soapi" ( "Id" bigserial NOT NULL, "CreatedAt" timestamptz NULL, "UpdatedAt" timestamptz NULL, "DeletedAt" timestamptz NULL, "Encounter_Id" bigint NULL, "Employee_Id" bigint NULL, "Time" timestamptz NULL, "Value" text NULL, PRIMARY KEY ("Id"), CONSTRAINT "fk_Soapi_Employee" FOREIGN KEY ("Employee_Id") REFERENCES "public"."Employee" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION, CONSTRAINT "fk_Soapi_Encounter" FOREIGN KEY ("Encounter_Id") REFERENCES "public"."Encounter" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION );