Files
riseup_squad_03/src/repositories/professionalRepository.js
letvb20-dot efb942d5aa modified: index.html
modified:   src/App.jsx
modified:   src/components/AppShell.jsx
modified:   src/components/featureStateStyles.js
modified:   src/config/permissions.js
modified:   src/hooks/useAgenda.js
modified:   src/mappers/reportMapper.js
modified:   src/pages/AgendaPage.jsx
modified:   src/pages/AnalyticsPage.jsx
modified:   src/pages/AuthPages.jsx
modified:   src/pages/HomePage.jsx
modified:   src/pages/MedicalRecordsPage.jsx
modified:   src/pages/MessagesPage.jsx
modified:   src/pages/PatientsPage.jsx
modified:   src/pages/ReportsPage.jsx
modified:   src/pages/SettingsPage.jsx
deleted:    src/pages/TeamPage.jsx
modified:   src/pages/UsersPage.jsx
modified:   src/repositories/availabilityRepository.js
modified:   src/repositories/patientRepository.js
modified:   src/repositories/professionalRepository.js
modified:   src/repositories/reportRepository.js
modified:   src/repositories/settingsRepository.js
2026-05-07 01:11:10 -03:00

55 lines
2.2 KiB
JavaScript

import { apiConfig, getAuthenticatedHeaders } from '../config/api.js'
export const professionalRepository = {
async getAll() {
const response = await fetch(`${apiConfig.restUrl}/doctors`, {
headers: getAuthenticatedHeaders()
})
if (!response.ok) throw new Error('Erro ao buscar médicos.')
const data = await response.json()
return (Array.isArray(data) ? data : []).map(mapProfessional)
},
getCoverageMap() {
return {
slots: ['08-12', '09-13', '10-15', '13-18', '08-14'],
weekdays: ['Seg', 'Ter', 'Qua', 'Qui', 'Sex'],
}
},
resolveCurrentProfessional(profile, professionals = []) {
const doctorId = normalizeValue(profile?.doctorId)
const userId = normalizeValue(profile?.id)
const email = normalizeValue(profile?.email)
return (
professionals.find((professional) => normalizeValue(professional.id) === doctorId) ||
professionals.find((professional) => normalizeValue(professional.userId) === userId) ||
professionals.find((professional) => normalizeValue(professional.id) === userId) ||
professionals.find((professional) => normalizeValue(professional.email) === email) ||
null
)
},
}
function mapProfessional(doctor) {
return {
id: String(doctor.id || doctor.medico_id || doctor.user_id || doctor.name || doctor.nome),
userId: doctor.user_id || doctor.userId || doctor.usuario_id || doctor.auth_user_id || null,
name: doctor.name || doctor.nome || doctor.full_name || 'Médico(a)',
email: doctor.email || doctor.user_email || doctor.usuario_email || '',
unit: doctor.unit || doctor.unidade || doctor.clinic_unit || doctor.clinica || doctor.location || '',
role: doctor.specialty || doctor.speciality || doctor.especialidade || doctor.role || 'Médico(a)',
schedule: doctor.schedule || doctor.agenda || doctor.disponibilidade || 'Seg a Sex, 08h as 18h',
nextSlot: doctor.nextSlot || doctor.proximo_horario || doctor.next_slot || 'Consulta pendente',
patients: doctor.patients || doctor.pacientes_ativos || doctor.active_patients || 0,
status: doctor.status || doctor.situacao || 'Disponivel',
}
}
function normalizeValue(value) {
return String(value || '').trim().toLowerCase()
}