schema.prisma 4.2 KB

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