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,
"aCL IgG" FLOAT,
"aCL IgM" FLOAT,
"ANA" INT,
"aCL IgA" INT,
FOREIGN KEY ("ID") REFERENCES "Patient"("ID")
);

CREATE TABLE "Laboratory" (
"ID" INT,
"Date" DATE,
"UA" FLOAT,
"CRP" TEXT,
PRIMARY KEY ("ID", "Date"),
FOREIGN KEY ("ID") REFERENCES "Patient"("ID")
);

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



INSERT INTO "Patient" VALUES ("1", "F", "1980-05-12");
INSERT INTO "Patient" VALUES ("2", "M", "1975-11-23");
INSERT INTO "Patient" VALUES ("3", "F", "1990-07-30");
INSERT INTO "Patient" VALUES ("4", "F", "1985-02-14");
INSERT INTO "Patient" VALUES ("5", "M", "1968-09-05");
INSERT INTO "Laboratory" VALUES ("1", "2023-01-10", "6.49", "Normal");
INSERT INTO "Laboratory" VALUES ("1", "2023-06-15", "6.50", "Normal");
INSERT INTO "Laboratory" VALUES ("2", "2023-03-20", "7.00", "Elevated");
INSERT INTO "Laboratory" VALUES ("3", "2023-04-25", "6.50", "Normal");
INSERT INTO "Laboratory" VALUES ("4", "2023-05-05", "6.48", "Normal");
INSERT INTO "Laboratory" VALUES ("4", "2023-07-10", "6.50", "Normal");
INSERT INTO "Laboratory" VALUES ("5", "2023-02-28", "5.00", "Normal");
INSERT INTO "Examination" VALUES ("1", "12.5", "8.3", "0", "4");
INSERT INTO "Examination" VALUES ("2", "15.0", "7.0", "1", "5");
INSERT INTO "Examination" VALUES ("3", "20.0", "10.0", "0", "6");
INSERT INTO "Examination" VALUES ("4", "18.0", "9.5", "0", "7");
INSERT INTO "Examination" VALUES ("5", "11.0", "6.0", "1", "3");