generator client { provider = "prisma-client-js" } datasource db { provider = "postgresql" url = env("DATABASE_URL") } model User { id String @id @default(cuid()) name String lastname String username String @unique email String? @unique password String? identificacion String? @unique isExternalAuth Boolean @default(false) role Role @default(PATIENT) profileImage String? phone String? dateOfBirth DateTime? gender Gender? address String? emergencyContact String? medicalHistory String? allergies String? currentMedications String? isActive Boolean @default(true) createdAt DateTime @default(now()) updatedAt DateTime @updatedAt deletedAt DateTime? // Relaciones records Record[] assignedPatients PatientAssignment[] @relation("DoctorPatients") assignedDoctor PatientAssignment[] @relation("PatientDoctor") patientAppointments Appointment[] @relation("PatientAppointments") doctorAppointments Appointment[] @relation("DoctorAppointments") dailyLogs DailyLog[] } model PatientAssignment { id String @id @default(cuid()) doctorId String patientId String assignedAt DateTime @default(now()) notes String? isActive Boolean @default(true) doctor User @relation("DoctorPatients", fields: [doctorId], references: [id], onDelete: Cascade) patient User @relation("PatientDoctor", fields: [patientId], references: [id], onDelete: Cascade) @@unique([doctorId, patientId]) } model Record { id String @id @default(cuid()) userId String content String messages Json? chatType ChatType @default(MEDICAL) createdAt DateTime @default(now()) user User @relation(fields: [userId], references: [id], onDelete: Cascade) appointment Appointment? } model Appointment { id String @id @default(cuid()) createdAt DateTime @default(now()) updatedAt DateTime @updatedAt // Relaciones pacienteId String paciente User @relation("PatientAppointments", fields: [pacienteId], references: [id], onDelete: Cascade) medicoId String? medico User? @relation("DoctorAppointments", fields: [medicoId], references: [id], onDelete: SetNull) recordId String? @unique record Record? @relation(fields: [recordId], references: [id], onDelete: SetNull) // Info de la cita fechaSolicitada DateTime? estado AppointmentStatus @default(PENDIENTE) motivoConsulta String motivoRechazo String? notas String? // Notas de consulta (durante videollamada) notasConsulta String? notasGuardadas Boolean @default(false) notasGuardadasAt DateTime? // Jitsi roomName String? @unique @@index([pacienteId]) @@index([medicoId]) @@index([estado]) @@index([fechaSolicitada]) } model DailyLog { id String @id @default(cuid()) userId String user User @relation(fields: [userId], references: [id], onDelete: Cascade) date DateTime @db.Date // Métricas (1-5) mood Int? energy Int? sleepHours Float? sleepQuality Int? // Notas personales notes String? @db.Text // Metadata createdAt DateTime @default(now()) updatedAt DateTime @updatedAt @@unique([userId, date]) @@index([userId]) @@index([date]) } enum Role { ADMIN DOCTOR PATIENT } enum AppointmentStatus { PENDIENTE APROBADA RECHAZADA COMPLETADA CANCELADA } enum Gender { MALE FEMALE OTHER PREFER_NOT_TO_SAY } enum ChatType { MEDICAL PSYCHOLOGICAL }