new file: src/App.css new file: src/App.jsx new file: src/assets/figma/login-clinic.png new file: src/assets/hero.png new file: src/assets/react.svg new file: src/assets/vite.svg new file: src/components/AppShell.jsx new file: src/components/Brand.jsx new file: src/components/ui.jsx new file: src/data/mockData.js new file: src/index.css new file: src/main.jsx new file: src/pages/AgendaPage.jsx new file: src/pages/AnalyticsPage.jsx new file: src/pages/AuthPages.jsx new file: src/pages/HomePage.jsx new file: src/pages/MedicalRecordsPage.jsx new file: src/pages/MessagesPage.jsx new file: src/pages/NotFoundPage.jsx new file: src/pages/PatientsPage.jsx new file: src/pages/ProfilePage.jsx new file: src/pages/ReportsPage.jsx new file: src/pages/SettingsPage.jsx new file: src/pages/TeamPage.jsx new file: src/pages/VisitsPage.jsx new file: src/repositories/analyticsRepository.js new file: src/repositories/appointmentRepository.js new file: src/repositories/communicationRepository.js new file: src/repositories/homeRepository.js new file: src/repositories/medicalRecordRepository.js new file: src/repositories/patientRepository.js new file: src/repositories/professionalRepository.js new file: src/repositories/profileRepository.js new file: src/repositories/reportRepository.js new file: src/repositories/settingsRepository.js new file: src/repositories/visitRepository.js new file: src/services/analyticsService.js new file: src/services/appointmentService.js new file: src/services/communicationService.js new file: src/services/homeService.js new file: src/services/medicalRecordService.js new file: src/services/patientService.js new file: src/services/professionalService.js new file: src/services/profileService.js new file: src/services/reportService.js new file: src/services/settingsService.js
122 lines
3.5 KiB
JavaScript
122 lines
3.5 KiB
JavaScript
const BASE_URL = 'https://yuanqfswhberkoevtmfr.supabase.co/rest/v1'
|
|
const FUNCTIONS_URL = 'https://yuanqfswhberkoevtmfr.supabase.co/functions/v1'
|
|
const API_KEY = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6Inl1YW5xZnN3aGJlcmtvZXZ0bWZyIiwicm9sZSI6ImFub24iLCJpYXQiOjE3NTQ5NTQzNjksImV4cCI6MjA3MDUzMDM2OX0.g8Fm4XAvtX46zifBZnYVH4tVuQkqUH6Ia9CXQj4DztQ'
|
|
|
|
const headers = {
|
|
'apikey': API_KEY,
|
|
'Authorization': `Bearer ${API_KEY}`,
|
|
'Content-Type': 'application/json',
|
|
}
|
|
|
|
export const patientRepository = {
|
|
// 1. Listar pacientes
|
|
async getAll() {
|
|
const response = await fetch(`${BASE_URL}/patients?select=*`, { headers })
|
|
if (!response.ok) throw new Error('Erro ao buscar pacientes')
|
|
return response.json()
|
|
},
|
|
|
|
async getById(patientId) {
|
|
const patients = await this.getAll()
|
|
return patients.find((p) => String(p.id) === String(patientId)) || null
|
|
},
|
|
|
|
async getDirectoryRows() {
|
|
const patients = await this.getAll()
|
|
return patients.map((patient) => ({
|
|
...patient,
|
|
name: patient.full_name,
|
|
phone: patient.phone_mobile,
|
|
detailId: patient.id,
|
|
insurance: 'Particular',
|
|
city: 'Recife',
|
|
state: 'PE',
|
|
vip: false,
|
|
lastVisitIso: null,
|
|
lastVisit: 'Ainda nao houve atendimento',
|
|
nextVisit: 'Nenhum atendimento agendado',
|
|
}))
|
|
},
|
|
|
|
// 2. Criar paciente (direto)
|
|
async create(data) {
|
|
const body = {
|
|
full_name: data.name,
|
|
cpf: data.cpf,
|
|
email: data.email,
|
|
phone_mobile: data.phone,
|
|
birth_date: data.birthDate || null,
|
|
created_by: data.createdBy || '00000000-0000-0000-0000-000000000000',
|
|
}
|
|
|
|
const response = await fetch(`${BASE_URL}/patients`, {
|
|
method: 'POST',
|
|
headers: { ...headers, 'Prefer': 'return=representation' },
|
|
body: JSON.stringify(body),
|
|
})
|
|
|
|
if (!response.ok) {
|
|
const error = await response.json().catch(() => ({}))
|
|
console.error('Erro da API ao criar paciente:', error)
|
|
throw new Error(error.message || error.hint || JSON.stringify(error))
|
|
}
|
|
|
|
return response.json()
|
|
},
|
|
|
|
// 3. Criar paciente com validação de CPF (Edge Function)
|
|
async createWithValidation(data) {
|
|
const body = {
|
|
full_name: data.name,
|
|
cpf: data.cpf,
|
|
email: data.email,
|
|
phone_mobile: data.phone,
|
|
birth_date: data.birthDate || null,
|
|
created_by: data.createdBy || '00000000-0000-0000-0000-000000000000',
|
|
}
|
|
|
|
const response = await fetch(`${FUNCTIONS_URL}/create-patient`, {
|
|
method: 'POST',
|
|
headers,
|
|
body: JSON.stringify(body),
|
|
})
|
|
|
|
if (!response.ok) {
|
|
const error = await response.json().catch(() => ({}))
|
|
throw new Error(error.message || 'Erro ao criar paciente com validacao')
|
|
}
|
|
|
|
return response.json()
|
|
},
|
|
|
|
// 4. Atualizar paciente
|
|
async update(patientId, data) {
|
|
const body = {
|
|
full_name: data.name,
|
|
cpf: data.cpf,
|
|
email: data.email,
|
|
phone_mobile: data.phone,
|
|
birth_date: data.birthDate || null,
|
|
}
|
|
|
|
const response = await fetch(`${BASE_URL}/patients?id=eq.${patientId}`, {
|
|
method: 'PATCH',
|
|
headers: { ...headers, 'Prefer': 'return=representation' },
|
|
body: JSON.stringify(body),
|
|
})
|
|
|
|
if (!response.ok) throw new Error('Erro ao atualizar paciente')
|
|
return response.json()
|
|
},
|
|
|
|
// 5. Deletar paciente
|
|
async remove(patientId) {
|
|
const response = await fetch(`${BASE_URL}/patients?id=eq.${patientId}`, {
|
|
method: 'DELETE',
|
|
headers,
|
|
})
|
|
|
|
if (!response.ok) throw new Error('Erro ao deletar paciente')
|
|
return true
|
|
},
|
|
} |