Spaces:
Running
Running
File size: 2,866 Bytes
c2858c1 | 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 | import type { PrismaClient } from "@prisma/client";
import { seedPatients } from "./seed-data";
export async function resetDatabase(prisma: PrismaClient) {
await prisma.order.deleteMany();
await prisma.clinicalNote.deleteMany();
await prisma.labResult.deleteMany();
await prisma.scenario.deleteMany();
await prisma.encounter.deleteMany();
await prisma.patient.deleteMany();
for (const patient of seedPatients) {
await prisma.patient.create({
data: {
id: patient.id,
mrn: patient.mrn,
fullName: patient.fullName,
age: patient.age,
sex: patient.sex,
allergiesJson: JSON.stringify(patient.allergies),
bannerFlagsJson: JSON.stringify(patient.bannerFlags),
summary: patient.summary,
encounters: {
create: patient.encounters.map((encounter) => ({
id: encounter.id,
type: encounter.type,
reasonForVisit: encounter.reasonForVisit,
provider: encounter.provider,
startedAt: new Date(encounter.startedAt),
status: encounter.status,
labs: {
create: encounter.labs.map((lab) => ({
id: lab.id,
name: lab.name,
loinc: lab.loinc,
value: lab.value,
unit: lab.unit,
referenceRange: lab.referenceRange,
abnormal: lab.abnormal,
collectedAt: new Date(lab.collectedAt)
}))
},
notes: {
create: encounter.notes.map((note) => ({
id: note.id,
type: note.type,
title: note.title,
author: note.author,
content: note.content,
signed: note.signed,
createdAt: new Date(note.createdAt)
}))
},
orders: {
create: encounter.orders.map((order) => ({
id: order.id,
name: order.name,
category: order.category,
parametersJson: JSON.stringify(order.parameters),
status: order.status,
rationale: order.rationale,
createdAt: new Date(order.createdAt)
}))
}
}))
},
scenarios: {
create: patient.scenarios.map((scenario, index) => ({
id: scenario.id,
title: scenario.title,
objective: scenario.objective,
rubricJson: JSON.stringify(scenario.rubric),
requiredOrdersJson: JSON.stringify(scenario.requiredOrders),
requiredNoteElementsJson: JSON.stringify(scenario.requiredNoteElements),
encounterId: patient.encounters[index]?.id ?? patient.encounters[0]?.id
}))
}
}
});
}
}
|