schema.prisma 3.7 KB

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