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" (
"Examination Date" DATE,
"Diagnosis" TEXT
);

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

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



INSERT INTO "Examination" VALUES ("2023-01-10", "Hypertension");
INSERT INTO "Examination" VALUES ("2023-02-15", "Diabetes");
INSERT INTO "Examination" VALUES ("2023-03-20", "Anemia");
INSERT INTO "Examination" VALUES ("2023-04-05", "Asthma");
INSERT INTO "Examination" VALUES ("2023-05-12", "Chronic Kidney Disease");
INSERT INTO "Patient" VALUES ("1", "M", "1980-05-20", "-", "Hypertension");
INSERT INTO "Patient" VALUES ("2", "F", "1975-11-30", "Emergency", "Diabetes");
INSERT INTO "Patient" VALUES ("3", "F", "1990-07-15", "-", "Asthma");
INSERT INTO "Patient" VALUES ("4", "M", "1965-03-10", "-", "Chronic Kidney Disease");
INSERT INTO "Patient" VALUES ("5", "F", "2000-12-01", "Inpatient", "Anemia");
INSERT INTO "Patient" VALUES ("6", "M", "1988-09-25", "-", "Hypertension");
INSERT INTO "Patient" VALUES ("7", "F", "1995-06-05", "-", "Diabetes");
INSERT INTO "Patient" VALUES ("8", "M", "1970-01-17", "Emergency", "Asthma");
INSERT INTO "Patient" VALUES ("9", "F", "1983-08-22", "-", "Anemia");
INSERT INTO "Patient" VALUES ("10", "M", "1992-04-30", "-", "Hypertension");
INSERT INTO "Laboratory" VALUES ("1", "2023-01-15", "250");
INSERT INTO "Laboratory" VALUES ("1", "2023-02-15", "310");
INSERT INTO "Laboratory" VALUES ("1", "2023-03-15", "299");
INSERT INTO "Laboratory" VALUES ("2", "2023-01-20", "400");
INSERT INTO "Laboratory" VALUES ("3", "2023-02-25", "300");
INSERT INTO "Laboratory" VALUES ("3", "2023-03-25", "280");
INSERT INTO "Laboratory" VALUES ("4", "2023-01-30", "150");
INSERT INTO "Laboratory" VALUES ("4", "2023-02-28", "320");
INSERT INTO "Laboratory" VALUES ("4", "2023-03-30", "290");
INSERT INTO "Laboratory" VALUES ("5", "2023-01-10", "270");
INSERT INTO "Laboratory" VALUES ("6", "2023-02-05", "NULL");
INSERT INTO "Laboratory" VALUES ("6", "2023-03-05", "295");
INSERT INTO "Laboratory" VALUES ("7", "2023-01-12", "280");
INSERT INTO "Laboratory" VALUES ("7", "2023-02-12", "310");
INSERT INTO "Laboratory" VALUES ("8", "2023-01-18", "305");
INSERT INTO "Laboratory" VALUES ("9", "2023-02-22", "299");
INSERT INTO "Laboratory" VALUES ("9", "2023-03-22", "301");
INSERT INTO "Laboratory" VALUES ("10", "2023-01-25", "300");
INSERT INTO "Laboratory" VALUES ("10", "2023-02-25", "290");