schema.prisma 4.1 KB

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