schema.prisma 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  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. reportId String?
  70. // Info de la cita
  71. fechaSolicitada DateTime?
  72. estado AppointmentStatus @default(PENDIENTE)
  73. motivoConsulta String
  74. motivoRechazo String?
  75. notas String?
  76. // Notas de consulta (durante videollamada)
  77. notasConsulta String?
  78. notasGuardadas Boolean @default(false)
  79. notasGuardadasAt DateTime?
  80. // Jitsi
  81. roomName String? @unique
  82. @@index([pacienteId])
  83. @@index([medicoId])
  84. @@index([estado])
  85. @@index([fechaSolicitada])
  86. }
  87. model DailyLog {
  88. id String @id @default(cuid())
  89. userId String
  90. user User @relation(fields: [userId], references: [id], onDelete: Cascade)
  91. date DateTime @db.Date
  92. // Métricas (1-5)
  93. mood Int?
  94. energy Int?
  95. sleepHours Float?
  96. sleepQuality Int?
  97. // Notas personales
  98. notes String? @db.Text
  99. // Metadata
  100. createdAt DateTime @default(now())
  101. updatedAt DateTime @updatedAt
  102. @@unique([userId, date])
  103. @@index([userId])
  104. @@index([date])
  105. }
  106. enum Role {
  107. ADMIN
  108. DOCTOR
  109. PATIENT
  110. }
  111. enum AppointmentStatus {
  112. PENDIENTE
  113. APROBADA
  114. RECHAZADA
  115. COMPLETADA
  116. CANCELADA
  117. }
  118. enum Gender {
  119. MALE
  120. FEMALE
  121. OTHER
  122. PREFER_NOT_TO_SAY
  123. }
  124. enum ChatType {
  125. MEDICAL
  126. PSYCHOLOGICAL
  127. }