CREATE SEQUENCE IF NOT EXISTS public."EmergencyType_EmergencyTypeId_seq"
    INCREMENT 1
    START 1
    MINVALUE 1
    MAXVALUE 9223372036854775807
    CACHE 1;
----------------------------------------------------
CREATE TABLE IF NOT EXISTS public."EmergencyType"
(
    "EmergencyTypeId" integer NOT NULL DEFAULT nextval('"EmergencyType_EmergencyTypeId_seq"'::regclass),
    "EmergencyTypeName" text COLLATE pg_catalog."default",
    "Active" boolean DEFAULT true,
    CONSTRAINT "EmergencyType_pkey" PRIMARY KEY ("EmergencyTypeId")
)

TABLESPACE pg_default;

ALTER TABLE IF EXISTS public."EmergencyType"
    OWNER to postgres;
	--------------------------------------------------------
	INSERT INTO "EmergencyType" ("EmergencyTypeId", "EmergencyTypeName","Active")
VALUES (1,'Red',true),(2,'Yellow',true),(3,'Green',true);
-----------------------------------------------------------
CREATE SEQUENCE IF NOT EXISTS public."EmergencyDetail_EmergencyDetailId_seq"
    INCREMENT 1
    START 1
    MINVALUE 1
    MAXVALUE 9223372036854775807
    CACHE 1;
------------------------------------


CREATE TABLE IF NOT EXISTS public."EmergencyDetail"
(
    "EmergencyDetailId" integer NOT NULL DEFAULT nextval('"EmergencyDetail_EmergencyDetailId_seq"'::regclass),
    "DetailName" text COLLATE pg_catalog."default",
    "Active" boolean DEFAULT true,
	"EmergencyTypeId" integer not null,
    CONSTRAINT "EmergencyDetail_pkey" PRIMARY KEY ("EmergencyDetailId"),
	CONSTRAINT "FK_EmergencyDetail_EmergencyTypeId" FOREIGN KEY ("EmergencyTypeId")
        REFERENCES public."EmergencyType" ("EmergencyTypeId") MATCH SIMPLE
        ON UPDATE NO ACTION
        ON DELETE NO ACTION
);

-------------------------------------------------------------------

insert into "EmergencyDetail" ("EmergencyDetailId","DetailName","Active","EmergencyTypeId")
values(1,'CARDIAC ARREST',true,1),(2,'CARDIO RESPIRATORY DISTRESS',true,1),(3,'ECLAMPSIA OR IMMINENT SYMPTOMS',TRUE,1),(4,'SEVERE OR HEAVY BLEEDING',TRUE,1),
(5,'LIFE THREATENING CONDITION',TRUE,1),(6,'URGE TO PUSH',TRUE,1),(7,'OBJECTS PROTRUDING FROM VAGINA',TRUE,1),(8,'NO FETAL MOVEMENTS',TRUE,1),(9,'DIABETIC COMA',TRUE,1),
(10,'TRAUMA',TRUE,1);
insert into "EmergencyDetail" ("EmergencyDetailId","DetailName","Active","EmergencyTypeId")
values(11,'UTERINE CONTRACTIONS EVERY 2 MINS UNCOMFORTABLE',true,2),(12,'MULTIPARA IN ACTIVE LABOUR',true,2),(13,'ABDOMINAL PAIN',TRUE,2),(14,'PRETERM LABOUR/PPROM',TRUE,2),
(15,'PRE-ECLAMPSIA',TRUE,2),(16,'RUPTURE OF MEMBRANCES',TRUE,2),(17,'WOUND INFECTION',TRUE,2),(18,'BLEEDING P/V NOT HEAVY',TRUE,2),(19,'ELECTIVE LSCS ADMISSION',TRUE,2),
(20,'IOL ADMISSION',TRUE,2);
insert into "EmergencyDetail" ("EmergencyDetailId","DetailName","Active","EmergencyTypeId")
values(21,'NAUSEA VOMITNG',true,3),(22,'URINARY COMPLAINTS',true,2),(23,'STABLE GESTATIONAL HTN',TRUE,3),(24,'UPPER RESPIRATORY INFECTION',TRUE,3),
(25,'VAGINAL DISCHARGE',TRUE,3),(26,'WOUND CHECKS/SUTURE REMOVAL',TRUE,3),(27,'INJECTIONS AND LAB TESTS',TRUE,3),(28,'REPORTS/OUTSIDE REPORT OF CYST/TORSION/ECTOPIC/ PUL BUT ASYMPTOMATIC',TRUE,3),(29,'ANC BOOKING VISIT',TRUE,3),
(30,'SYMPTOMS OF FLU/COLD/UTI',TRUE,3),(31,'TRAVEL HISTORY',TRUE,3),(32,'CONTACT / EXPOSURE TO COV',TRUE,3);
----------------------------------------------------------------
CREATE SEQUENCE IF NOT EXISTS public."EmergencyEncounter_EmergencyEncounterId_seq"
    INCREMENT 1
    START 1
    MINVALUE 1
    MAXVALUE 9223372036854775807
    CACHE 1;
----------------------------------------------------
CREATE TABLE IF NOT EXISTS public."EmergencyEncounter"
(
    "EmergencyEncounterId" integer NOT NULL DEFAULT nextval('"EmergencyEncounter_EmergencyEncounterId_seq"') ,
    "AppointmentId" integer,
	"EmergencyTriage" text,
	"NursingERForm" text,
    "Active" boolean DEFAULT true,
	"PatientId" INTEGER,
	CONSTRAINT "EmergencyEncounter_PatientId_fkey" FOREIGN KEY ("PatientId")
        REFERENCES public."Patient" ("PatientId") MATCH SIMPLE
        ON UPDATE NO ACTION
        ON DELETE NO ACTION
);
alter table "EmergencyEncounter" add column "CreatedBy" integer;
alter table "EmergencyEncounter" add column "ModifiedBy" integer;
alter table "EmergencyEncounter" add column "CreatedDate" timestamp(6) without time zone;
alter table "EmergencyEncounter" add column "ModifiedDate" timestamp(6) without time zone;