schema.prisma 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. generator client {
  2. provider = "prisma-client-js"
  3. }
  4. datasource db {
  5. provider = "postgresql"
  6. url = env("DATABASE_URL")
  7. }
  8. model User {
  9. id String @id @default(cuid())
  10. name String
  11. lastname String
  12. username String @unique
  13. email String? @unique
  14. password String?
  15. identificacion String? @unique
  16. isExternalAuth Boolean @default(false)
  17. role Role @default(PATIENT)
  18. profileImage String?
  19. phone String?
  20. dateOfBirth DateTime?
  21. gender Gender?
  22. address String?
  23. emergencyContact String?
  24. medicalHistory String?
  25. allergies String?
  26. currentMedications String?
  27. createdAt DateTime @default(now())
  28. updatedAt DateTime @updatedAt
  29. // Relaciones
  30. records Record[]
  31. assignedPatients PatientAssignment[] @relation("DoctorPatients")
  32. assignedDoctor PatientAssignment[] @relation("PatientDoctor")
  33. patientAppointments Appointment[] @relation("PatientAppointments")
  34. doctorAppointments Appointment[] @relation("DoctorAppointments")
  35. }
  36. model PatientAssignment {
  37. id String @id @default(cuid())
  38. doctorId String
  39. patientId String
  40. assignedAt DateTime @default(now())
  41. notes String?
  42. isActive Boolean @default(true)
  43. doctor User @relation("DoctorPatients", fields: [doctorId], references: [id], onDelete: Cascade)
  44. patient User @relation("PatientDoctor", fields: [patientId], references: [id], onDelete: Cascade)
  45. @@unique([doctorId, patientId])
  46. }
  47. model Record {
  48. id String @id @default(cuid())
  49. userId String
  50. content String
  51. messages Json?
  52. createdAt DateTime @default(now())
  53. user User @relation(fields: [userId], references: [id], onDelete: Cascade)
  54. appointment Appointment?
  55. }
  56. model Appointment {
  57. id String @id @default(cuid())
  58. createdAt DateTime @default(now())
  59. updatedAt DateTime @updatedAt
  60. // Relaciones
  61. pacienteId String
  62. paciente User @relation("PatientAppointments", fields: [pacienteId], references: [id], onDelete: Cascade)
  63. medicoId String?
  64. medico User? @relation("DoctorAppointments", fields: [medicoId], references: [id], onDelete: SetNull)
  65. recordId String? @unique
  66. record Record? @relation(fields: [recordId], references: [id], onDelete: SetNull)
  67. reportId String?
  68. // Info de la cita
  69. fechaSolicitada DateTime?
  70. estado AppointmentStatus @default(PENDIENTE)
  71. motivoConsulta String
  72. motivoRechazo String?
  73. notas String?
  74. // Notas de consulta (durante videollamada)
  75. notasConsulta String?
  76. notasGuardadas Boolean @default(false)
  77. notasGuardadasAt DateTime?
  78. // Jitsi
  79. roomName String? @unique
  80. @@index([pacienteId])
  81. @@index([medicoId])
  82. @@index([estado])
  83. @@index([fechaSolicitada])
  84. }
  85. enum Role {
  86. ADMIN
  87. DOCTOR
  88. PATIENT
  89. }
  90. enum AppointmentStatus {
  91. PENDIENTE
  92. APROBADA
  93. RECHAZADA
  94. COMPLETADA
  95. CANCELADA
  96. }
  97. enum Gender {
  98. MALE
  99. FEMALE
  100. OTHER
  101. PREFER_NOT_TO_SAY
  102. }