refactor(principal): remove legenda global do AppShell
This commit is contained in:
@@ -1,142 +1,64 @@
|
||||
import { apiConfig, apiEndpoint, getAuthenticatedHeaders } from '../config/api.js'
|
||||
import { apiConfig, getAuthenticatedHeaders } from '../config/api.js'
|
||||
import { reportMapper } from '../mappers/reportMapper.js'
|
||||
import { fetchJsonWithFallback, normalizeCollection, normalizeItem } from './repositoryUtils.js'
|
||||
import { getResponseError, normalizeItem } from './repositoryUtils.js'
|
||||
|
||||
export const reportRepository = {
|
||||
async getInitialReports() {
|
||||
const data = await fetchJsonWithFallback(
|
||||
[
|
||||
{
|
||||
url: apiEndpoint('/reports'),
|
||||
options: { headers: getAuthenticatedHeaders() },
|
||||
},
|
||||
{
|
||||
url: `${apiConfig.restUrl}/reports?select=*,patients(full_name),doctors(name)`,
|
||||
options: { headers: getAuthenticatedHeaders() },
|
||||
},
|
||||
],
|
||||
'Falha ao buscar laudos da API.',
|
||||
)
|
||||
async getInitialReports(filters = {}) {
|
||||
const query = new URLSearchParams()
|
||||
query.set('select', '*')
|
||||
query.set('order', filters.order || 'created_at.desc')
|
||||
|
||||
return normalizeCollection(data, ['reports', 'relatorios', 'laudos', 'data']).map(reportMapper.toUi)
|
||||
if (filters.patientId) {
|
||||
query.set('patient_id', `eq.${filters.patientId}`)
|
||||
}
|
||||
|
||||
if (filters.status) {
|
||||
query.set('status', `eq.${filters.status}`)
|
||||
}
|
||||
|
||||
if (filters.createdBy) {
|
||||
query.set('created_by', `eq.${filters.createdBy}`)
|
||||
}
|
||||
|
||||
const response = await fetch(`${apiConfig.restUrl}/reports?${query.toString()}`, {
|
||||
headers: getAuthenticatedHeaders(),
|
||||
})
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(await getResponseError(response, 'Falha ao buscar relatorios medicos.'))
|
||||
}
|
||||
|
||||
const data = await response.json()
|
||||
return (Array.isArray(data) ? data : []).map(reportMapper.toUi)
|
||||
},
|
||||
|
||||
async create(uiData) {
|
||||
const data = await fetchJsonWithFallback(
|
||||
[
|
||||
{
|
||||
url: apiEndpoint('/reports'),
|
||||
options: {
|
||||
method: 'POST',
|
||||
headers: getAuthenticatedHeaders(),
|
||||
body: JSON.stringify(reportMapper.toApi(uiData)),
|
||||
},
|
||||
},
|
||||
{
|
||||
url: `${apiConfig.restUrl}/reports`,
|
||||
options: {
|
||||
method: 'POST',
|
||||
headers: getAuthenticatedHeaders({ Prefer: 'return=representation' }),
|
||||
body: JSON.stringify(reportMapper.toApi(uiData, 'supabase')),
|
||||
},
|
||||
},
|
||||
],
|
||||
'Falha ao salvar laudo.',
|
||||
)
|
||||
const response = await fetch(`${apiConfig.restUrl}/reports`, {
|
||||
method: 'POST',
|
||||
headers: getAuthenticatedHeaders({ Prefer: 'return=representation' }),
|
||||
body: JSON.stringify(reportMapper.toApi(uiData)),
|
||||
})
|
||||
|
||||
return reportMapper.toUi(normalizeItem(data, ['report', 'relatorio', 'laudo', 'data']))
|
||||
if (!response.ok) {
|
||||
throw new Error(await getResponseError(response, 'Falha ao criar relatorio medico.'))
|
||||
}
|
||||
|
||||
const data = await response.json()
|
||||
return reportMapper.toUi(normalizeItem(data))
|
||||
},
|
||||
|
||||
async update(id, uiData) {
|
||||
const data = await fetchJsonWithFallback(
|
||||
[
|
||||
{
|
||||
url: apiEndpoint(`/reports/${id}`),
|
||||
options: {
|
||||
method: 'PATCH',
|
||||
headers: getAuthenticatedHeaders(),
|
||||
body: JSON.stringify(reportMapper.toApi({ ...uiData, id })),
|
||||
},
|
||||
},
|
||||
{
|
||||
url: apiEndpoint('/reports'),
|
||||
options: {
|
||||
method: 'PATCH',
|
||||
headers: getAuthenticatedHeaders(),
|
||||
body: JSON.stringify({ id, ...reportMapper.toApi(uiData) }),
|
||||
},
|
||||
},
|
||||
{
|
||||
url: `${apiConfig.restUrl}/reports?id=eq.${id}`,
|
||||
options: {
|
||||
method: 'PATCH',
|
||||
headers: getAuthenticatedHeaders({ Prefer: 'return=representation' }),
|
||||
body: JSON.stringify(reportMapper.toApi(uiData, 'supabase')),
|
||||
},
|
||||
},
|
||||
],
|
||||
'Falha ao atualizar o laudo.',
|
||||
)
|
||||
const response = await fetch(`${apiConfig.restUrl}/reports?id=eq.${id}`, {
|
||||
method: 'PATCH',
|
||||
headers: getAuthenticatedHeaders({ Prefer: 'return=representation' }),
|
||||
body: JSON.stringify(reportMapper.toApi(uiData)),
|
||||
})
|
||||
|
||||
return reportMapper.toUi(normalizeItem(data, ['report', 'relatorio', 'laudo', 'data']))
|
||||
},
|
||||
if (!response.ok) {
|
||||
throw new Error(await getResponseError(response, 'Falha ao atualizar relatorio medico.'))
|
||||
}
|
||||
|
||||
getTemplates() {
|
||||
return [
|
||||
{
|
||||
id: 't1',
|
||||
name: 'Atestado Medico Padrao',
|
||||
type: 'Atestado Medico',
|
||||
description: 'Atestado simples para repouso, consulta e CID.',
|
||||
content:
|
||||
'Atesto para os devidos fins que o(a) paciente [NOME DO PACIENTE] esteve em consulta medica nesta data, necessitando de [DIAS] dias de repouso por motivo de saude (CID: [CODIGO]).',
|
||||
},
|
||||
{
|
||||
id: 't2',
|
||||
name: 'Encaminhamento Especializado',
|
||||
type: 'Encaminhamento',
|
||||
description: 'Encaminhamento para avaliacao de especialidade.',
|
||||
content:
|
||||
'Encaminho o(a) paciente [NOME DO PACIENTE] para avaliacao da especialidade de [ESPECIALIDADE] devido ao quadro clinico de [SINTOMAS/DIAGNOSTICO PREVIO].\n\nConduta mantida ate o momento: [MEDICACOES]',
|
||||
},
|
||||
{
|
||||
id: 't3',
|
||||
name: 'Laudo de Evolucao Diaria',
|
||||
type: 'Evolucao Clinica',
|
||||
description: 'Modelo para evolucao clinica diaria.',
|
||||
content:
|
||||
'Paciente evolui [BEM/MAL], [COM/SEM] queixas no momento.\nSinais vitais: PA [VALOR], FC [VALOR] bpm, SatO2 [VALOR]%.\nExame fisico: [DESCRICAO].\nConduta: [MANTER/ALTERAR TRATAMENTO OPCOES].',
|
||||
},
|
||||
{
|
||||
id: 't4',
|
||||
name: 'Receituario de Uso Continuo',
|
||||
type: 'Receituario Fixado',
|
||||
description: 'Lista de medicamentos de uso continuo.',
|
||||
content:
|
||||
'Uso continuo:\n1. [MEDICAMENTO] - [DOSE] - Tomar [POSOLOGIA]\n2. [MEDICAMENTO] - [DOSE] - Tomar [POSOLOGIA]',
|
||||
},
|
||||
]
|
||||
},
|
||||
|
||||
getAdminUsers() {
|
||||
return ['Dr. Henrique Cardoso', 'Dra. Marina Lopes', 'Dra. Ana Silva']
|
||||
},
|
||||
|
||||
getCurrentUser() {
|
||||
return 'Dr. Henrique Cardoso'
|
||||
},
|
||||
|
||||
getDoctors() {
|
||||
return ['Dr. Henrique Cardoso', 'Dra. Marina Lopes', 'Dra. Ana Silva', 'Dr. Roberto Santos']
|
||||
},
|
||||
|
||||
getReportTypes() {
|
||||
return [
|
||||
'Atestado Medico',
|
||||
'Encaminhamento',
|
||||
'Evolucao Clinica',
|
||||
'Receituario Fixado',
|
||||
'Laudo de Procedimento',
|
||||
]
|
||||
const data = await response.json()
|
||||
return reportMapper.toUi(normalizeItem(data))
|
||||
},
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user