-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdbscript4.sql
More file actions
193 lines (177 loc) · 6.69 KB
/
dbscript4.sql
File metadata and controls
193 lines (177 loc) · 6.69 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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
-- Insert user information
INSERT INTO usertable (username, user_type)
VALUES ('Shashwat Singh', 1);
INSERT INTO userinfo (user_id, fullname, user_height, user_weight, race, date_of_birth, ethnicity, sex, gender)
SELECT user_id, 'Shashwat Singh', 175, 75, 'Asian', '1990-05-15', 'Indian', 'Male', 'Male'
FROM usertable
WHERE username = 'Shashwat Singh';
-- Insert medical records
INSERT INTO notes (user_id, note, note_date, history_user_id)
SELECT user_id, 'Routine checkup, everything seems normal', DATE '2023-01-05', 1
FROM usertable
WHERE username = 'Shashwat Singh'
UNION ALL
SELECT user_id, 'Follow up on previous diagnosis', DATE '2023-03-10', 2
FROM usertable
WHERE username = 'Shashwat Singh'
UNION ALL
SELECT user_id, 'Prescription refill', DATE '2023-07-20', 3
FROM usertable
WHERE username = 'Shashwat Singh'
UNION ALL
SELECT user_id, 'Complains of stomach ache', DATE '2023-09-15', 4
FROM usertable
WHERE username = 'Shashwat Singh'
UNION ALL
SELECT user_id, 'Emergency visit due to accident', DATE '2023-11-25', 5
FROM usertable
WHERE username = 'Shashwat Singh';
INSERT INTO medicine (user_id, med_name, med_dosage, med_frequency, med_date, history_user_id)
SELECT user_id, 'Paracetamol', '500mg', 'As needed', DATE '2023-01-05', 1
FROM usertable
WHERE username = 'Shashwat Singh'
UNION ALL
SELECT user_id, 'Lisinopril', '10mg', 'Once daily', DATE '2023-03-10', 2
FROM usertable
WHERE username = 'Shashwat Singh'
UNION ALL
SELECT user_id, 'Metformin', '1000mg', 'Twice daily', DATE '2023-07-20', 3
FROM usertable
WHERE username = 'Shashwat Singh'
UNION ALL
SELECT user_id, 'Omeprazole', '20mg', 'Once daily', DATE '2023-09-15', 4
FROM usertable
WHERE username = 'Shashwat Singh'
UNION ALL
SELECT user_id, 'Ibuprofen', '400mg', 'As needed', DATE '2023-11-25', 5
FROM usertable
WHERE username = 'Shashwat Singh';
INSERT INTO vitals (user_id, vital_name, vital_value, vital_date, history_user_id)
SELECT user_id, 'Blood Pressure', '120/80 mmHg', DATE '2023-01-05', 1
FROM usertable
WHERE username = 'Shashwat Singh'
UNION ALL
SELECT user_id, 'Heart Rate', '75 bpm', DATE '2023-03-10', 2
FROM usertable
WHERE username = 'Shashwat Singh'
UNION ALL
SELECT user_id, 'Blood Sugar', '110 mg/dL', DATE '2023-07-20', 3
FROM usertable
WHERE username = 'Shashwat Singh'
UNION ALL
SELECT user_id, 'Temperature', '98.6°F', DATE '2023-09-15', 4
FROM usertable
WHERE username = 'Shashwat Singh'
UNION ALL
SELECT user_id, 'Respiratory Rate', '16 breaths/min', DATE '2023-11-25', 5
FROM usertable
WHERE username = 'Shashwat Singh';
INSERT INTO vaccine (user_id, vac_name, vac_date, history_user_id)
SELECT user_id, 'Flu Vaccine', DATE '2022-10-01', 1
FROM usertable
WHERE username = 'Shashwat Singh'
UNION ALL
SELECT user_id, 'COVID-19 Vaccine', DATE '2023-05-15', 2
FROM usertable
WHERE username = 'Shashwat Singh'
UNION ALL
SELECT user_id, 'Tetanus Vaccine', DATE '2020-08-20', 3
FROM usertable
WHERE username = 'Shashwat Singh'
UNION ALL
SELECT user_id, 'Hepatitis B Vaccine', DATE '2018-12-05', 4
FROM usertable
WHERE username = 'Shashwat Singh'
UNION ALL
SELECT user_id, 'MMR Vaccine', DATE '2015-06-10', 5
FROM usertable
WHERE username = 'Shashwat Singh';
INSERT INTO lab_result (user_id, lab_result, lab_date, history_user_id)
SELECT user_id, 'CBC - Within normal ranges', DATE '2023-01-05', 1
FROM usertable
WHERE username = 'Shashwat Singh'
UNION ALL
SELECT user_id, 'Cholesterol - Slightly elevated', DATE '2023-03-10', 2
FROM usertable
WHERE username = 'Shashwat Singh'
UNION ALL
SELECT user_id, 'HbA1c - Within target range', DATE '2023-07-20', 3
FROM usertable
WHERE username = 'Shashwat Singh'
UNION ALL
SELECT user_id, 'Liver Function - Normal', DATE '2023-09-15', 4
FROM usertable
WHERE username = 'Shashwat Singh'
UNION ALL
SELECT user_id, 'Urine Analysis - No abnormalities detected', DATE '2023-11-25', 5
FROM usertable
WHERE username = 'Shashwat Singh';
INSERT INTO surgeries (user_id, surgery, surgery_date, history_user_id)
SELECT user_id, 'Appendectomy', DATE '2010-08-15', 1
FROM usertable
WHERE username = 'Shashwat Singh'
UNION ALL
SELECT user_id, 'Knee Replacement', DATE '2015-03-20', 2
FROM usertable
WHERE username = 'Shashwat Singh'
UNION ALL
SELECT user_id, 'Gallbladder Removal', DATE '2018-10-10', 3
FROM usertable
WHERE username = 'Shashwat Singh'
UNION ALL
SELECT user_id, 'Hernia Repair', DATE '2019-05-05', 4
FROM usertable
WHERE username = 'Shashwat Singh'
UNION ALL
SELECT user_id, 'Tonsillectomy', DATE '2005-07-01', 5
FROM usertable
WHERE username = 'Shashwat Singh';
INSERT INTO emergencies (user_id, emergency_name, emergency_date, history_user_id)
SELECT user_id, 'Car Accident', DATE '2023-11-25', 5
FROM usertable
WHERE username = 'Shashwat Singh';
-- Insert symptoms with proper diag_id linkage
INSERT INTO diagnosis (user_id, diagnosis, diag_date, history_user_id)
SELECT user_id, 'Hypertension', DATE '2023-03-10', 2
FROM usertable
WHERE username = 'Shashwat Singh'
RETURNING user_id, diag_id;
INSERT INTO symptoms (user_id, diag_id, symptom, symptom_date, history_user_id)
SELECT user_id, diag_id, 'Headaches', DATE '2023-02-01', 2
FROM diagnosis
WHERE user_id = (SELECT user_id FROM usertable WHERE username = 'Shashwat Singh')
UNION ALL
SELECT user_id, diag_id, 'Dizziness', DATE '2023-02-01', 2
FROM diagnosis
WHERE user_id = (SELECT user_id FROM usertable WHERE username = 'Shashwat Singh');
INSERT INTO diagnosis (user_id, diagnosis, diag_date, history_user_id)
SELECT user_id, 'Type 2 Diabetes', DATE '2023-07-20', 3
FROM usertable
WHERE username = 'Shashwat Singh'
RETURNING user_id, diag_id;
INSERT INTO symptoms (user_id, diag_id, symptom, symptom_date, history_user_id)
SELECT user_id, diag_id, 'Frequent urination', DATE '2023-07-01', 3
FROM diagnosis
WHERE user_id = (SELECT user_id FROM usertable WHERE username = 'Shashwat Singh')
UNION ALL
SELECT user_id, diag_id, 'Fatigue', DATE '2023-07-01', 3
FROM diagnosis
WHERE user_id = (SELECT user_id FROM usertable WHERE username = 'Shashwat Singh');
INSERT INTO diagnosis (user_id, diagnosis, diag_date, history_user_id)
SELECT user_id, 'GERD', DATE '2023-09-15', 4
FROM usertable
WHERE username = 'Shashwat Singh'
RETURNING user_id, diag_id;
INSERT INTO symptoms (user_id, diag_id, symptom, symptom_date, history_user_id)
SELECT user_id, diag_id, 'Abdominal pain', DATE '2023-09-15', 4
FROM diagnosis
WHERE user_id = (SELECT user_id FROM usertable WHERE username = 'Shashwat Singh');
INSERT INTO diagnosis (user_id, diagnosis, diag_date, history_user_id)
SELECT user_id, 'Fractured Rib', DATE '2023-11-25', 5
FROM usertable
WHERE username = 'Shashwat Singh'
RETURNING user_id, diag_id;
INSERT INTO symptoms (user_id, diag_id, symptom, symptom_date, history_user_id)
SELECT user_id, diag_id, 'Chest pain', DATE '2023-11-25', 5
FROM diagnosis
WHERE user_id = (SELECT user_id FROM usertable WHERE username = 'Shashwat Singh');