-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathseed.js
More file actions
336 lines (304 loc) · 8.26 KB
/
Copy pathseed.js
File metadata and controls
336 lines (304 loc) · 8.26 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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
// seed.js
import { PrismaClient } from '@prisma/client';
const prisma = new PrismaClient();
import bcrypt from 'bcrypt';
async function main() {
// Clear existing data (be careful with this in production!)
await prisma.prescriptionItem.deleteMany();
await prisma.prescription.deleteMany();
await prisma.appointment.deleteMany();
await prisma.availabilitySlot.deleteMany();
await prisma.doctorClinic.deleteMany();
await prisma.contact.deleteMany();
await prisma.notification.deleteMany();
await prisma.patient.deleteMany();
await prisma.doctor.deleteMany();
await prisma.clinic.deleteMany();
await prisma.user.deleteMany();
// Hash passwords
const saltRounds = 10;
const hashedPassword = await bcrypt.hash('password123', saltRounds);
// Create users
const adminUser = await prisma.user.create({
data: {
email: 'admin@example.com',
password: hashedPassword,
firstName: 'Admin',
lastName: 'User',
role: 'DOCTOR',
},
});
const doctorUser1 = await prisma.user.create({
data: {
email: 'doctor1@example.com',
password: hashedPassword,
firstName: 'John',
lastName: 'Smith',
phoneNumber: '+1234567890',
address: '123 Medical St, Cityville',
role: 'DOCTOR',
},
});
const doctorUser2 = await prisma.user.create({
data: {
email: 'doctor2@example.com',
password: hashedPassword,
firstName: 'Sarah',
lastName: 'Johnson',
phoneNumber: '+1987654321',
address: '456 Health Ave, Townsville',
role: 'DOCTOR',
},
});
const patientUser1 = await prisma.user.create({
data: {
email: 'patient1@example.com',
password: hashedPassword,
firstName: 'Michael',
lastName: 'Brown',
phoneNumber: '+1122334455',
address: '789 Wellness Blvd, Villagetown',
role: 'PATIENT',
},
});
const patientUser2 = await prisma.user.create({
data: {
email: 'patient2@example.com',
password: hashedPassword,
firstName: 'Emily',
lastName: 'Davis',
phoneNumber: '+1555666777',
address: '321 Care Lane, Hamlet City',
role: 'PATIENT',
},
});
// Create doctors
const doctor1 = await prisma.doctor.create({
data: {
userId: doctorUser1.id,
licenseNumber: 'MD123456',
specialty: 'Cardiology',
yearsOfExperience: 10,
bio: 'Board certified cardiologist with extensive experience in heart health.',
},
});
const doctor2 = await prisma.doctor.create({
data: {
userId: doctorUser2.id,
licenseNumber: 'MD654321',
specialty: 'Pediatrics',
yearsOfExperience: 8,
bio: 'Pediatric specialist focused on children\'s health and development.',
},
});
// Create patients
const patient1 = await prisma.patient.create({
data: {
userId: patientUser1.id,
dateOfBirth: new Date('1985-05-15'),
bloodType: 'A+',
allergies: 'Penicillin, Peanuts',
medicalHistory: 'History of high blood pressure',
},
});
const patient2 = await prisma.patient.create({
data: {
userId: patientUser2.id,
dateOfBirth: new Date('1990-11-22'),
bloodType: 'O-',
allergies: 'None',
medicalHistory: 'No significant medical history',
},
});
// Create clinics
const clinic1 = await prisma.clinic.create({
data: {
name: 'City Medical Center',
address: '123 Main Street, Cityville',
phoneNumber: '+18005551234',
email: 'info@citymedical.com',
latitude: 34.052235,
longitude: -118.243683,
},
});
const clinic2 = await prisma.clinic.create({
data: {
name: 'Town Health Clinic',
address: '456 Oak Avenue, Townsville',
phoneNumber: '+18005555678',
email: 'contact@townhealth.org',
latitude: 34.063235,
longitude: -118.253683,
},
});
// Associate doctors with clinics
await prisma.doctorClinic.create({
data: {
doctorId: doctor1.id,
clinicId: clinic1.id,
},
});
await prisma.doctorClinic.create({
data: {
doctorId: doctor1.id,
clinicId: clinic2.id,
},
});
await prisma.doctorClinic.create({
data: {
doctorId: doctor2.id,
clinicId: clinic2.id,
},
});
// Add doctor contacts
await prisma.contact.create({
data: {
type: 'EMAIL',
content: 'personal@doctor1.com',
doctor_id: doctor1.id,
},
});
await prisma.contact.create({
data: {
type: 'PHONE',
content: '+1234567890',
doctor_id: doctor1.id,
},
});
await prisma.contact.create({
data: {
type: 'EMAIL',
content: 'personal@doctor2.com',
doctor_id: doctor2.id,
},
});
// Create availability slots
const nextWeek = new Date();
nextWeek.setDate(nextWeek.getDate() + 7);
const slot1 = await prisma.availabilitySlot.create({
data: {
doctorId: doctor1.id,
clinicId: clinic1.id,
dayOfWeek: 'MONDAY',
startTime: new Date('1970-01-01T09:00:00Z'),
endTime: new Date('1970-01-01T17:00:00Z'),
isRecurring: true,
},
});
const slot2 = await prisma.availabilitySlot.create({
data: {
doctorId: doctor1.id,
clinicId: clinic2.id,
dayOfWeek: 'WEDNESDAY',
startTime: new Date('1970-01-01T10:00:00Z'),
endTime: new Date('1970-01-01T16:00:00Z'),
isRecurring: true,
},
});
const slot3 = await prisma.availabilitySlot.create({
data: {
doctorId: doctor2.id,
clinicId: clinic2.id,
dayOfWeek: 'TUESDAY',
startTime: new Date('1970-01-01T08:00:00Z'),
endTime: new Date('1970-01-01T15:00:00Z'),
isRecurring: true,
},
});
// Create appointments
const appointment1 = await prisma.appointment.create({
data: {
patientId: patient1.id,
doctorId: doctor1.id,
clinicId: clinic1.id,
slotId: slot1.id,
appointmentDate: nextWeek,
startTime: new Date('1970-01-01T10:00:00Z'),
endTime: new Date('1970-01-01T10:30:00Z'),
status: 'SCHEDULED',
qrCode: 'QRCODE123',
complaint: 'Chest pain and discomfort',
},
});
const appointment2 = await prisma.appointment.create({
data: {
patientId: patient2.id,
doctorId: doctor2.id,
clinicId: clinic2.id,
slotId: slot3.id,
appointmentDate: nextWeek,
startTime: new Date('1970-01-01T11:00:00Z'),
endTime: new Date('1970-01-01T11:30:00Z'),
status: 'CONFIRMED',
qrCode: 'QRCODE456',
complaint: 'Annual checkup',
},
});
// Create prescriptions
const prescription1 = await prisma.prescription.create({
data: {
appointmentId: appointment1.id,
doctorId: doctor1.id,
patientId: patient1.id,
diagnosis: 'Hypertension',
notes: 'Monitor blood pressure regularly',
},
});
await prisma.prescriptionItem.create({
data: {
prescriptionId: prescription1.id,
medicationName: 'Lisinopril',
dosage: '10mg',
frequency: 'Once daily',
duration: '30 days',
instructions: 'Take in the morning with food',
},
});
const prescription2 = await prisma.prescription.create({
data: {
appointmentId: appointment2.id,
doctorId: doctor2.id,
patientId: patient2.id,
diagnosis: 'Vitamin D deficiency',
notes: 'Get sunlight exposure and take supplements',
},
});
await prisma.prescriptionItem.create({
data: {
prescriptionId: prescription2.id,
medicationName: 'Vitamin D3',
dosage: '2000 IU',
frequency: 'Once daily',
duration: '90 days',
instructions: 'Take with largest meal of the day',
},
});
// Create notifications
await prisma.notification.create({
data: {
userId: patientUser1.id,
title: 'Appointment Reminder',
message: 'Your appointment with Dr. Smith is tomorrow at 10:00 AM',
type: 'APPOINTMENT',
relatedId: appointment1.id,
},
});
await prisma.notification.create({
data: {
userId: patientUser2.id,
title: 'Prescription Ready',
message: 'Your prescription for Vitamin D3 is ready for pickup',
type: 'PRESCRIPTION',
relatedId: prescription2.id,
},
});
console.log('Database seeded successfully!');
}
main()
.catch((e) => {
console.error(e);
process.exit(1);
})
.finally(async () => {
await prisma.$disconnect();
});