PRAGMA foreign_keys = ON;

PRAGMA writable_schema = 1;
DELETE FROM sqlite_master WHERE type IN ("table", "index", "trigger");
PRAGMA writable_schema = 0;
VACUUM;

CREATE TABLE "Examination" (
"ID" INT,
"Examination Date" DATE,
"ANA" INT,
FOREIGN KEY ("ID") REFERENCES "Patient"("ID")
);

CREATE TABLE "Laboratory" (
"ID" INT,
"Date" DATE,
"TP" FLOAT,
"ALB" FLOAT,
PRIMARY KEY ("ID", "Date"),
FOREIGN KEY ("ID") REFERENCES "Patient"("ID")
);

CREATE TABLE "Patient" (
"ID" INT UNIQUE,
"SEX" TEXT,
PRIMARY KEY ("ID")
);



INSERT INTO "Patient" VALUES ("1", "M");
INSERT INTO "Patient" VALUES ("2", "F");
INSERT INTO "Patient" VALUES ("3", "M");
INSERT INTO "Patient" VALUES ("4", "F");
INSERT INTO "Patient" VALUES ("5", "M");
INSERT INTO "Laboratory" VALUES ("1", "2024-01-10", "7.2", "4.8");
INSERT INTO "Laboratory" VALUES ("1", "2024-02-15", "6.8", "3.4");
INSERT INTO "Laboratory" VALUES ("2", "2024-01-12", "7.0", "5.4");
INSERT INTO "Laboratory" VALUES ("2", "2024-03-20", "6.5", "5.5");
INSERT INTO "Laboratory" VALUES ("3", "2024-01-15", "7.5", "3.6");
INSERT INTO "Laboratory" VALUES ("3", "2024-02-18", "7.1", "4.9");
INSERT INTO "Laboratory" VALUES ("4", "2024-01-20", "6.9", "3.5");
INSERT INTO "Laboratory" VALUES ("4", "2024-02-22", "7.3", "4.7");
INSERT INTO "Laboratory" VALUES ("5", "2024-01-25", "7.4", "5.3");
INSERT INTO "Laboratory" VALUES ("5", "2024-03-01", "7.0", "3.3");
INSERT INTO "Examination" VALUES ("1", "2024-01-11", "20");
INSERT INTO "Examination" VALUES ("1", "2024-02-16", "18");
INSERT INTO "Examination" VALUES ("2", "2024-01-13", "22");
INSERT INTO "Examination" VALUES ("2", "2024-03-21", "19");
INSERT INTO "Examination" VALUES ("3", "2024-01-16", "25");
INSERT INTO "Examination" VALUES ("3", "2024-02-19", "21");
INSERT INTO "Examination" VALUES ("4", "2024-01-21", "23");
INSERT INTO "Examination" VALUES ("4", "2024-02-23", "20");
INSERT INTO "Examination" VALUES ("5", "2024-01-26", "24");
INSERT INTO "Examination" VALUES ("5", "2024-03-02", "17");