This commit is contained in:
@@ -0,0 +1,72 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Impressao\Ambulatorio;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Ambulatorio\Atendimento;
|
||||
use App\Models\Ambulatorio\PuericulturaQuestionarioMChatR;
|
||||
use App\Utils\Exports\Pdf1;
|
||||
|
||||
class LaudoMChatRController extends Controller
|
||||
{
|
||||
private const TITLE = 'LAUDO M-CHAT-R';
|
||||
private const TEMPLATE = 'ambulatorio.laudo-m-chat-r';
|
||||
|
||||
public function __invoke($atendimentoId, $soapId = null)
|
||||
{
|
||||
$laudos = collect();
|
||||
|
||||
$atendimento = Atendimento::findOrFail($atendimentoId);
|
||||
|
||||
$atendimento->soaps()
|
||||
->where('is_rascunho', false)
|
||||
->when($soapId, fn ($q) => $q->where('id', $soapId))
|
||||
->whereHas('puericulturaQuestionarioMChatR')->get()->each(function ($soap) use (&$laudos) {
|
||||
$paciente = $soap->atendimento->paciente;
|
||||
|
||||
$questionario = PuericulturaQuestionarioMChatR::orderBy('id')->get()->map(function ($query) use ($soap) {
|
||||
$resposta = $soap->puericulturaQuestionarioMChatR()
|
||||
->where('questionario_m_chat_r_id', $query->id)
|
||||
->first();
|
||||
|
||||
return [
|
||||
'id' => $query->id,
|
||||
'descricao' => $query->descricao,
|
||||
'valor_resposta_sim' => $query->valor_resposta_sim,
|
||||
'valor_resposta_nao' => $query->valor_resposta_nao,
|
||||
'pergunta' => $query->descricao,
|
||||
'resposta' => $resposta->resposta,
|
||||
];
|
||||
});
|
||||
|
||||
$score = $questionario->reduce(function ($total, $query) {
|
||||
$valor = $query['resposta']
|
||||
? $query['valor_resposta_sim']
|
||||
: $query['valor_resposta_nao'];
|
||||
|
||||
return $total + $valor;
|
||||
}, 0);
|
||||
|
||||
$classificacao = null;
|
||||
|
||||
if ($score <= 2) {
|
||||
$classificacao = 'Baixo risco';
|
||||
} elseif ($score >= 3 && $score <= 7) {
|
||||
$classificacao = 'Risco moderado';
|
||||
} elseif ($score >= 8) {
|
||||
$classificacao = 'Alto risco';
|
||||
}
|
||||
|
||||
$laudos->push([
|
||||
'data_hora_atendimento' => $soap->created_at->format('d/m/Y \à\s H:i'),
|
||||
'paciente_nome' => $paciente->cidadao->nome,
|
||||
'paciente_idade' => $paciente->cidadao->idadeFormatada,
|
||||
'questionario' => $questionario,
|
||||
'score' => $score,
|
||||
'classificacao' => $classificacao,
|
||||
]);
|
||||
});
|
||||
|
||||
return Pdf1::generate(self::TITLE, self::TEMPLATE, compact('laudos'));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user