schema.prisma 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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. dailyLogs DailyLog[]
  36. }
  37. model PatientAssignment {
  38. id String @id @default(cuid())
  39. doctorId String
  40. patientId String
  41. assignedAt DateTime @default(now())
  42. notes String?
  43. isActive Boolean @default(true)
  44. doctor User @relation("DoctorPatients", fields: [doctorId], references: [id], onDelete: Cascade)
  45. patient User @relation("PatientDoctor", fields: [patientId], references: [id], onDelete: Cascade)
  46. @@unique([doctorId, patientId])
  47. }
  48. model Record {
  49. id String @id @default(cuid())
  50. userId String
  51. content String
  52. messages Json?
  53. chatType ChatType @default(MEDICAL)
  54. createdAt DateTime @default(now())
  55. user User @relation(fields: [userId], references: [id], onDelete: Cascade)
  56. appointment Appointment?
  57. }
  58. model Appointment {
  59. id String @id @default(cuid())
  60. createdAt DateTime @default(now())
  61. updatedAt DateTime @updatedAt
  62. // Relaciones
  63. pacienteId String
  64. paciente User @relation("PatientAppointments", fields: [pacienteId], references: [id], onDelete: Cascade)
  65. medicoId String?
  66. medico User? @relation("DoctorAppointments", fields: [medicoId], references: [id], onDelete: SetNull)
  67. recordId String? @unique
  68. record Record? @relation(fields: [recordId], references: [id], onDelete: SetNull)
  69. // Info de la cita
  70. fechaSolicitada DateTime?
  71. estado AppointmentStatus @default(PENDIENTE)
  72. motivoConsulta String
  73. motivoRechazo String?
  74. notas String?
  75. // Notas de consulta (durante videollamada)
  76. notasConsulta String?
  77. notasGuardadas Boolean @default(false)
  78. notasGuardadasAt DateTime?
  79. // Jitsi
  80. roomName String? @unique
  81. @@index([pacienteId])
  82. @@index([medicoId])
  83. @@index([estado])
  84. @@index([fechaSolicitada])
  85. }
  86. model DailyLog {
  87. id String @id @default(cuid())
  88. userId String
  89. user User @relation(fields: [userId], references: [id], onDelete: Cascade)
  90. date DateTime @db.Date
  91. // Métricas (1-5)
  92. mood Int?
  93. energy Int?
  94. sleepHours Float?
  95. sleepQuality Int?
  96. // Notas personales
  97. notes String? @db.Text
  98. // Metadata
  99. createdAt DateTime @default(now())
  100. updatedAt DateTime @updatedAt
  101. @@unique([userId, date])
  102. @@index([userId])
  103. @@index([date])
  104. }
  105. enum Role {
  106. ADMIN
  107. DOCTOR
  108. PATIENT
  109. }
  110. enum AppointmentStatus {
  111. PENDIENTE
  112. APROBADA
  113. RECHAZADA
  114. COMPLETADA
  115. CANCELADA
  116. }
  117. enum Gender {
  118. MALE
  119. FEMALE
  120. OTHER
  121. PREFER_NOT_TO_SAY
  122. }
  123. enum ChatType {
  124. MEDICAL
  125. PSYCHOLOGICAL
  126. }