-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathschema.sql
More file actions
82 lines (72 loc) · 2.32 KB
/
Copy pathschema.sql
File metadata and controls
82 lines (72 loc) · 2.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
--Represents the patients registered at an insurance company--
CREATE TABLE "patients" (
"id" INTEGER,
"first_name" TEXT NOT NULL,
"last_name" TEXT NOT NULL,
"gender" TEXT NOT NULL CHECK ("gender" IN ('F', 'M')),
"age" INTEGER NOT NULL,
"country" TEXT NOT NULL,
PRIMARY KEY ("id")
);
--Represents the insurnace companies--
CREATE TABLE "insurers" (
"id" INTEGER,
"insurer_company" TEXT NOT NULL,
PRIMARY KEY ("id")
);
--Represents the hospitals visited by the patients--
CREATE TABLE "hospitals" (
"id" INTEGER,
"hospital_name" TEXT NOT NULL UNIQUE,
PRIMARY KEY ("id")
);
--Represents claims requested by the patients--
CREATE TABLE "claims"(
"id" INTEGER,
"patient_id" INTEGER,
"insurer_id" INTEGER,
"hospital_id" INTEGER,
"submitted" DATE NOT NULL,
"responded" DATE,
"overall_status" TEXT CHECK ("overall_status" IN ("partially approved", "rejected", "approved")),
"total" NUMERIC NOT NULL,
PRIMARY KEY ("id"),
FOREIGN KEY ("patient_id") REFERENCES "patients" ("id"),
FOREIGN KEY ("insurer_id") REFERENCES "insurers" ("id"),
FOREIGN KEY ("hospital_id") REFERENCES "hospitals" ("id")
);
--Represents the services a patient underwent under one claim--
CREATE TABLE "medicalServices" (
"id" INTEGER,
"claim_id" INTEGER,
"service_type" TEXT NOT NULL,
"price" NUMERIC NOT NULL,
PRIMARY KEY ("id"),
FOREIGN KEY ("claim_id") REFERENCES "claims"("id")
);
--Represents the services' status and reason--
CREATE TABLE "serviceStatus" (
"id" INTEGER,
"medicalService_id" INTEGER,
"status" TEXT NOT NULL CHECK ("status" IN ("pending", "progress", "rejected", "finished")),
"reason" TEXT,
PRIMARY KEY ("id"),
FOREIGN KEY ("medicalService_id") REFERENCES "medicalServices"("id")
);
--Represents total of money the insurance company covered--
CREATE TABLE "payments" (
"id" INTEGER,
"claim_id" INTEGER,
"covered_amount" NUMERIC NOT NULL,
PRIMARY KEY ("id"),
FOREIGN KEY ("claim_id") REFERENCES "claims"("id")
);
--Represents permiums paied by patients--
CREATE TABLE "permiums" (
"id" INTEGER,
"patient_id" INTEGER,
"amount" NUMERIC NULL,
"frequency" TEXT NOT NULL CHECK ("frequency" IN ("yearly", "monthly")),
PRIMARY KEY ("id"),
FOREIGN KEY ("patient_id") REFERENCES "patients"("id")
);