forked from RiseUP/riseup_squad_03
fix(principal): integra auth, agenda e laudos com a api
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import { useMemo, useState } from 'react'
|
||||
import { useEffect, useMemo, useState } from 'react'
|
||||
|
||||
import { reportRepository } from '../repositories/reportRepository.js'
|
||||
import { patientRepository } from '../repositories/patientRepository.js'
|
||||
|
||||
|
||||
const statusConfig = {
|
||||
@@ -43,7 +44,14 @@ const labelClass = 'mb-1.5 block text-xs font-medium text-[#e5e5e5]'
|
||||
const cardClass = 'rounded-2xl border border-[#404040] bg-[#262626] shadow-sm'
|
||||
|
||||
export function ReportsPage() {
|
||||
const [reports, setReports] = useState(() => reportRepository.getInitialReports())
|
||||
const [reports, setReports] = useState([])
|
||||
const [patients, setPatients] = useState([])
|
||||
|
||||
useEffect(() => {
|
||||
reportRepository.getInitialReports().then(setReports).catch(console.error)
|
||||
patientRepository.getAll().then(setPatients).catch(console.error)
|
||||
}, [])
|
||||
|
||||
const [search, setSearch] = useState('')
|
||||
const [filterStatus, setFilterStatus] = useState('')
|
||||
const [openMenuId, setOpenMenuId] = useState(null)
|
||||
@@ -104,64 +112,34 @@ export function ReportsPage() {
|
||||
setEditorOpen(true)
|
||||
}
|
||||
|
||||
function saveReport(status) {
|
||||
if (!editor.patient.trim() || !editor.content.trim()) {
|
||||
return
|
||||
}
|
||||
async function saveReport(status) {
|
||||
if (!editor.patient.trim() || !editor.content.trim()) return
|
||||
|
||||
try {
|
||||
const selectedPatient = patients.find(p => p.name === editor.patient || p.full_name === editor.patient)
|
||||
const patientId = selectedPatient?.id || null
|
||||
|
||||
const date = new Date().toLocaleDateString('pt-BR')
|
||||
setReports((currentReports) => {
|
||||
if (editor.id) {
|
||||
return currentReports.map((report) =>
|
||||
report.id === editor.id
|
||||
? {
|
||||
...report,
|
||||
type: editor.type,
|
||||
patient: editor.patient,
|
||||
doctor: editor.doctor,
|
||||
content: editor.content,
|
||||
showDate: editor.showDate,
|
||||
signDigital: editor.signDigital,
|
||||
status,
|
||||
versions: [
|
||||
...report.versions,
|
||||
{
|
||||
version: report.versions.length + 1,
|
||||
action: status === 'finalizado' ? 'Liberado' : 'Rascunho',
|
||||
user: currentUser,
|
||||
summary: status === 'finalizado' ? 'Laudo liberado' : 'Rascunho salvo',
|
||||
},
|
||||
],
|
||||
}
|
||||
: report,
|
||||
)
|
||||
}
|
||||
|
||||
return [
|
||||
{
|
||||
id: `report-${Date.now()}`,
|
||||
const updated = await reportRepository.update(editor.id, {
|
||||
type: editor.type,
|
||||
patient: editor.patient,
|
||||
doctor: editor.doctor,
|
||||
date,
|
||||
status,
|
||||
content: editor.content,
|
||||
showDate: editor.showDate,
|
||||
signDigital: editor.signDigital,
|
||||
versions: [
|
||||
{ version: 1, action: 'Criado', user: currentUser, summary: 'Laudo criado localmente' },
|
||||
{
|
||||
version: 2,
|
||||
action: status === 'finalizado' ? 'Liberado' : 'Rascunho',
|
||||
user: currentUser,
|
||||
summary: status === 'finalizado' ? 'Laudo liberado' : 'Rascunho salvo',
|
||||
},
|
||||
],
|
||||
},
|
||||
...currentReports,
|
||||
]
|
||||
})
|
||||
setEditorOpen(false)
|
||||
patientId: patientId,
|
||||
status,
|
||||
})
|
||||
setReports(curr => curr.map(r => r.id == updated.id ? { ...updated, status } : r))
|
||||
} else {
|
||||
const created = await reportRepository.create({
|
||||
type: editor.type,
|
||||
content: editor.content,
|
||||
patientId: patientId,
|
||||
status,
|
||||
})
|
||||
setReports(curr => [{ ...created, status }, ...curr])
|
||||
}
|
||||
setEditorOpen(false)
|
||||
} catch(e) {
|
||||
alert(e.message || 'Erro ao persistir na Base de Dados')
|
||||
}
|
||||
}
|
||||
|
||||
function releaseReport(reportId) {
|
||||
@@ -391,7 +369,7 @@ function ReportRow({
|
||||
type="button"
|
||||
>
|
||||
<ReportIcon className="size-3.5" name="history" />
|
||||
v{report.versions.length}
|
||||
v{report.versions ? report.versions.length : 1}
|
||||
</button>
|
||||
</td>
|
||||
<td className="relative px-4 py-3 text-right">
|
||||
|
||||
Reference in New Issue
Block a user