-- SEQUENCE: public.AccountCredential_AccountCredentialId_seq

-- DROP SEQUENCE IF EXISTS public."AccountCredential_AccountCredentialId_seq";

CREATE SEQUENCE IF NOT EXISTS public."OTRegister_OTRegisterId_seq"
    INCREMENT 1
    START 1
    MINVALUE 1
    MAXVALUE 9223372036854775807
    CACHE 1;

DROP TABLE IF EXISTS public."OTRegister";

CREATE TABLE IF NOT EXISTS public."OTRegister"
(
    "OTRegisterId" integer NOT NULL DEFAULT nextval('"OTRegister_OTRegisterId_seq"'::regclass),
    "PatientId" integer NOT NULL,
    "SurgeryId" integer NOT NULL,
    "ProviderId" integer NOT NULL,
    "AssitantId" integer NOT NULL,
    "AnaesthetistId" integer NOT NULL,
    "AnaesthesiaTypeId" integer NOT NULL,
    "NurseId" integer NOT NULL,
    "SurgeryTypeId" integer NOT NULL,
    "CaseType" character varying(10) COLLATE pg_catalog."default",
    "Diagnosis" character varying(20) COLLATE pg_catalog."default",
    "Remarks" character varying(30) COLLATE pg_catalog."default",
    "Active" boolean NOT NULL DEFAULT true,
    "OREntryDate" timestamp(6) without time zone NOT NULL,
    "SignInDate" timestamp(6) without time zone NOT NULL,
    "SignOutDate" timestamp(6) without time zone NOT NULL,
    "ShiftWardToDate" timestamp(6) without time zone NOT NULL,
    "Address" character varying(80) COLLATE pg_catalog."default",
    "CreatedBy" integer,
    "CreatedDate" timestamp(6) without time zone NOT NULL,
    "ModifiedBy" integer,
    "ModifiedDate" timestamp(6) without time zone,
    "OTRoomId" integer,
    CONSTRAINT "OTRegister_pkey" PRIMARY KEY ("OTRegisterId"),
    CONSTRAINT "FK_IdProof_CreatedBy" FOREIGN KEY ("CreatedBy")
        REFERENCES public."Account" ("AccountId") MATCH SIMPLE
        ON UPDATE NO ACTION
        ON DELETE NO ACTION,
    CONSTRAINT "FK_IdProof_ModifiedBy" FOREIGN KEY ("ModifiedBy")
        REFERENCES public."Account" ("AccountId") MATCH SIMPLE
        ON UPDATE NO ACTION
        ON DELETE NO ACTION,
    CONSTRAINT "FK_OTRegister_PatientId" FOREIGN KEY ("PatientId")
        REFERENCES public."Patient" ("PatientId") MATCH SIMPLE
        ON UPDATE NO ACTION
        ON DELETE NO ACTION,
    CONSTRAINT "FK_OTRoom_Surgery_fkey" FOREIGN KEY ("OTRoomId")
        REFERENCES public."OTRoom" ("OTRoomId") MATCH SIMPLE
        ON UPDATE NO ACTION
        ON DELETE NO ACTION,
    CONSTRAINT "OTRegister_AnaesthesiaTypeId_fkey" FOREIGN KEY ("AnaesthesiaTypeId")
        REFERENCES public."AnaesthesiaType" ("AnaesthesiaTypeId") MATCH SIMPLE
        ON UPDATE NO ACTION
        ON DELETE NO ACTION,
    CONSTRAINT "OTRegister_AnaesthetistId_fkey" FOREIGN KEY ("AnaesthetistId")
        REFERENCES public."Account" ("AccountId") MATCH SIMPLE
        ON UPDATE NO ACTION
        ON DELETE NO ACTION,
    CONSTRAINT "OTRegister_AssitantId_fkey" FOREIGN KEY ("AssitantId")
        REFERENCES public."Account" ("AccountId") MATCH SIMPLE
        ON UPDATE NO ACTION
        ON DELETE NO ACTION,
    CONSTRAINT "OTRegister_NurseId_fkey" FOREIGN KEY ("NurseId")
        REFERENCES public."Account" ("AccountId") MATCH SIMPLE
        ON UPDATE NO ACTION
        ON DELETE NO ACTION,
    CONSTRAINT "OTRegister_ProviderId_fkey" FOREIGN KEY ("ProviderId")
        REFERENCES public."Provider" ("ProviderId") MATCH SIMPLE
        ON UPDATE NO ACTION
        ON DELETE NO ACTION,
    CONSTRAINT "OTRegister_SurgeryId_fkey" FOREIGN KEY ("SurgeryId")
        REFERENCES public."Surgery" ("SurgeryId") MATCH SIMPLE
        ON UPDATE NO ACTION
        ON DELETE NO ACTION
)

TABLESPACE pg_default;

ALTER TABLE IF EXISTS public."OTRegister"
    OWNER to postgres;
---------------------------------------------------------
CREATE SEQUENCE IF NOT EXISTS public."AnaesthesiaType_AnaesthesiaType_seq"
    INCREMENT 1
    START 1
    MINVALUE 1
    MAXVALUE 9223372036854775807
    CACHE 1;

CREATE TABLE IF NOT EXISTS public."AnaesthesiaType"
(
    "AnaesthesiaTypeId" bigint NOT NULL DEFAULT nextval('"AnaesthesiaType_AnaesthesiaType_seq"'::regclass),
    "Name" character varying(255) COLLATE pg_catalog."default",
    "Active" boolean DEFAULT true,
    "CreatedBy" bigint NOT NULL,
    "CreatedDate" timestamp without time zone NOT NULL,
    "ModifiedBy" bigint,
    "ModifiedDate" timestamp without time zone,
    CONSTRAINT "AnaesthesiaType_pkey" PRIMARY KEY ("AnaesthesiaTypeId"),
    CONSTRAINT "FK_AnaesthesiaType_CreatedBy" FOREIGN KEY ("CreatedBy")
        REFERENCES public."Account" ("AccountId") MATCH SIMPLE
        ON UPDATE NO ACTION
        ON DELETE NO ACTION,
    CONSTRAINT "FK_AnaesthesiaType_ModifiedBy" FOREIGN KEY ("ModifiedBy")
        REFERENCES public."Account" ("AccountId") MATCH SIMPLE
        ON UPDATE NO ACTION
        ON DELETE NO ACTION
)
---------------------------------------------------------------------------------------
CREATE SEQUENCE IF NOT EXISTS public."CaseType_CaseypeId_seq"
    INCREMENT 1
    START 1
    MINVALUE 1
    MAXVALUE 2147483647
    CACHE 1
   


	CREATE TABLE IF NOT EXISTS public."CaseType"
(
    "CaseTypeId" integer NOT NULL DEFAULT nextval('"CaseType_CaseypeId_seq"'::regclass),
    "CaseName" character varying(100) COLLATE pg_catalog."default" NOT NULL,
    CONSTRAINT "CaseType_pkey" PRIMARY KEY ("CaseTypeId")
)
-----------------------------------------------------
INSERT INTO public."LogType"(
	"LogTypeId", "LogTypeName", "Active")
	VALUES (71,'OTRegister', true);