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

ALTER SEQUENCE public."HealthCard_HealthCardId_seq"
    OWNER TO postgres;


---------------------------------------------------------------------------------------------------------------------
-- Table: public.HealthCard

-- DROP TABLE IF EXISTS public."HealthCard";

CREATE TABLE IF NOT EXISTS public."HealthCard"
(
    "HealthCardId" integer NOT NULL DEFAULT nextval('"HealthCard_HealthCardId_seq"'::regclass),
    "HealthCardName" character varying(50) COLLATE pg_catalog."default" NOT NULL,
    "Amount" bigint NOT NULL,
    "AllowMembers" integer,
    "ValidityType" character varying COLLATE pg_catalog."default",
    "Duration" integer,
    "Active" boolean NOT NULL DEFAULT true,
    "CreatedBy" integer NOT NULL,
    "CreatedDate" timestamp(6) without time zone NOT NULL,
    "ModifiedBy" integer,
    "ModifiedDate" timestamp(6) without time zone,
    CONSTRAINT "HealthCard_pkey" PRIMARY KEY ("HealthCardId"),
    CONSTRAINT "UQ_HealthCard_HealthCardName" UNIQUE ("HealthCardName"),
    CONSTRAINT "FK_HealthCard_CreatedBy" FOREIGN KEY ("CreatedBy")
        REFERENCES public."Account" ("AccountId") MATCH SIMPLE
        ON UPDATE NO ACTION
        ON DELETE CASCADE,
    CONSTRAINT "FK_HealthCard_ModifiedBy" FOREIGN KEY ("ModifiedBy")
        REFERENCES public."Account" ("AccountId") MATCH SIMPLE
        ON UPDATE NO ACTION
        ON DELETE CASCADE
)

TABLESPACE pg_default;

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

ALTER SEQUENCE public."HealthCardMember_HealthCardMemberId_seq"
    OWNER TO postgres;

----------------------------------------------------------------------------------------------------
-- SEQUENCE: public.IssueHealthCard_IssueHealthCardId_seq

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

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

ALTER SEQUENCE public."IssueHealthCard_IssueHealthCardId_seq"
    OWNER TO postgres;

------------------------------------------------------------------------------------------	
-- Table: public.HealthCardMember

-- DROP TABLE IF EXISTS public."HealthCardMember";

CREATE TABLE IF NOT EXISTS public."HealthCardMember"
(
    "HealthCardMemberId" integer NOT NULL DEFAULT nextval('"HealthCardMember_HealthCardMemberId_seq"'::regclass),
    "IssueHealthCardId" integer,
    "DependentPatientId" integer,
    CONSTRAINT "HealthCardMember_pkey" PRIMARY KEY ("HealthCardMemberId"),
    CONSTRAINT "HealthCardMember_DependentPatientId_fkey" FOREIGN KEY ("DependentPatientId")
        REFERENCES public."Patient" ("PatientId") MATCH SIMPLE
        ON UPDATE NO ACTION
        ON DELETE NO ACTION,
    CONSTRAINT "HealthCardMember_IssueHealthCardId_fkey" FOREIGN KEY ("IssueHealthCardId")
        REFERENCES public."IssueHealthCard" ("IssueHealthCardId") MATCH SIMPLE
        ON UPDATE NO ACTION
        ON DELETE NO ACTION
)

TABLESPACE pg_default;

ALTER TABLE IF EXISTS public."HealthCardMember"
    OWNER to postgres;
	
------------------------------------------------------------------------------------------------------------
-- Table: public.IssueHealthCard

-- DROP TABLE IF EXISTS public."IssueHealthCard";

CREATE TABLE IF NOT EXISTS public."IssueHealthCard"
(
    "IssueHealthCardId" integer NOT NULL DEFAULT nextval('"IssueHealthCard_IssueHealthCardId_seq"'::regclass),
    "HealthCardId" integer NOT NULL,
    "CardNumber" text COLLATE pg_catalog."default",
    "PatientId" integer,
    "CreatedBy" integer,
    "CreatedDate" timestamp without time zone,
    "ModifiedBy" integer,
    "ModifiedDate" timestamp without time zone,
    "IssuedDate" date NOT NULL,
    "Active" boolean DEFAULT true,
    "PayTypeId" integer,
    "PaymentNumber" character varying(50) COLLATE pg_catalog."default",
    "NetAmount" numeric(8,2),
    "ValidTill" date,
    CONSTRAINT "IssueHealthCard_pkey" PRIMARY KEY ("IssueHealthCardId"),
    CONSTRAINT "IssueHealthCard_CreatedBy_fkey" FOREIGN KEY ("CreatedBy")
        REFERENCES public."Account" ("AccountId") MATCH SIMPLE
        ON UPDATE NO ACTION
        ON DELETE NO ACTION,
    CONSTRAINT "IssueHealthCard_HealthCardId_fkey" FOREIGN KEY ("HealthCardId")
        REFERENCES public."HealthCard" ("HealthCardId") MATCH SIMPLE
        ON UPDATE NO ACTION
        ON DELETE NO ACTION,
    CONSTRAINT "IssueHealthCard_ModifiedBy_fkey" FOREIGN KEY ("ModifiedBy")
        REFERENCES public."Account" ("AccountId") MATCH SIMPLE
        ON UPDATE NO ACTION
        ON DELETE NO ACTION,
    CONSTRAINT "IssueHealthCard_PatientId_fkey" FOREIGN KEY ("PatientId")
        REFERENCES public."Patient" ("PatientId") MATCH SIMPLE
        ON UPDATE NO ACTION
        ON DELETE NO ACTION,
    CONSTRAINT "IssueHealthCard_PayTypeId_fkey" FOREIGN KEY ("PayTypeId")
        REFERENCES public."PayType" ("PayTypeId") MATCH SIMPLE
        ON UPDATE NO ACTION
        ON DELETE NO ACTION
)

TABLESPACE pg_default;

ALTER TABLE IF EXISTS public."IssueHealthCard"
    OWNER to postgres;

-------------------------------------------------------
INSERT INTO "LogType" ("LogTypeId","LogTypeName","Active")
VALUES (79,'HealthCard',TRUE);	