139 lines
3.4 KiB
Plaintext
139 lines
3.4 KiB
Plaintext
generator client {
|
|
provider = "prisma-client"
|
|
output = "../src/generated/prisma"
|
|
}
|
|
|
|
datasource db {
|
|
provider = "postgresql"
|
|
}
|
|
|
|
enum Role {
|
|
SYSTEM_ADMIN
|
|
HOSPITAL_ADMIN
|
|
DIRECTOR
|
|
LEADER
|
|
DOCTOR
|
|
ENGINEER
|
|
}
|
|
|
|
enum DeviceStatus {
|
|
ACTIVE
|
|
INACTIVE
|
|
}
|
|
|
|
enum TaskStatus {
|
|
PENDING
|
|
ACCEPTED
|
|
COMPLETED
|
|
CANCELLED
|
|
}
|
|
|
|
model Hospital {
|
|
id Int @id @default(autoincrement())
|
|
name String
|
|
departments Department[]
|
|
users User[]
|
|
patients Patient[]
|
|
tasks Task[]
|
|
}
|
|
|
|
model Department {
|
|
id Int @id @default(autoincrement())
|
|
name String
|
|
hospitalId Int
|
|
hospital Hospital @relation(fields: [hospitalId], references: [id])
|
|
groups Group[]
|
|
users User[]
|
|
|
|
@@index([hospitalId])
|
|
}
|
|
|
|
model Group {
|
|
id Int @id @default(autoincrement())
|
|
name String
|
|
departmentId Int
|
|
department Department @relation(fields: [departmentId], references: [id])
|
|
users User[]
|
|
|
|
@@index([departmentId])
|
|
}
|
|
|
|
model User {
|
|
id Int @id @default(autoincrement())
|
|
name String
|
|
phone String
|
|
// Backend login password hash (bcrypt).
|
|
passwordHash String?
|
|
openId String? @unique
|
|
role Role
|
|
hospitalId Int?
|
|
departmentId Int?
|
|
groupId Int?
|
|
hospital Hospital? @relation(fields: [hospitalId], references: [id])
|
|
department Department? @relation(fields: [departmentId], references: [id])
|
|
group Group? @relation(fields: [groupId], references: [id])
|
|
doctorPatients Patient[] @relation("DoctorPatients")
|
|
createdTasks Task[] @relation("TaskCreator")
|
|
acceptedTasks Task[] @relation("TaskEngineer")
|
|
|
|
@@index([phone])
|
|
@@index([hospitalId, role])
|
|
@@index([departmentId, role])
|
|
@@index([groupId, role])
|
|
}
|
|
|
|
model Patient {
|
|
id Int @id @default(autoincrement())
|
|
name String
|
|
phone String
|
|
idCardHash String
|
|
hospitalId Int
|
|
doctorId Int
|
|
hospital Hospital @relation(fields: [hospitalId], references: [id])
|
|
doctor User @relation("DoctorPatients", fields: [doctorId], references: [id])
|
|
devices Device[]
|
|
|
|
@@index([phone, idCardHash])
|
|
@@index([hospitalId, doctorId])
|
|
}
|
|
|
|
model Device {
|
|
id Int @id @default(autoincrement())
|
|
snCode String @unique
|
|
currentPressure Int
|
|
status DeviceStatus @default(ACTIVE)
|
|
patientId Int
|
|
patient Patient @relation(fields: [patientId], references: [id])
|
|
taskItems TaskItem[]
|
|
|
|
@@index([patientId, status])
|
|
}
|
|
|
|
model Task {
|
|
id Int @id @default(autoincrement())
|
|
status TaskStatus @default(PENDING)
|
|
creatorId Int
|
|
engineerId Int?
|
|
hospitalId Int
|
|
createdAt DateTime @default(now())
|
|
creator User @relation("TaskCreator", fields: [creatorId], references: [id])
|
|
engineer User? @relation("TaskEngineer", fields: [engineerId], references: [id])
|
|
hospital Hospital @relation(fields: [hospitalId], references: [id])
|
|
items TaskItem[]
|
|
|
|
@@index([hospitalId, status, createdAt])
|
|
}
|
|
|
|
model TaskItem {
|
|
id Int @id @default(autoincrement())
|
|
taskId Int
|
|
deviceId Int
|
|
oldPressure Int
|
|
targetPressure Int
|
|
task Task @relation(fields: [taskId], references: [id], onDelete: Cascade)
|
|
device Device @relation(fields: [deviceId], references: [id])
|
|
|
|
@@index([taskId])
|
|
@@index([deviceId])
|
|
}
|