This commit is contained in:
32
api/app/Rules/Sigtap/SexoIsValidForProcedimento.php
Normal file
32
api/app/Rules/Sigtap/SexoIsValidForProcedimento.php
Normal file
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace App\Rules\Sigtap;
|
||||
|
||||
use App\Models\Cadastro\SujeitoAtencao\Paciente;
|
||||
use App\Models\Sigtap\Procedimento;
|
||||
use App\Services\Sigtap\ProcedimentoValidationService;
|
||||
use Illuminate\Contracts\Validation\Rule;
|
||||
|
||||
class SexoIsValidForProcedimento implements Rule
|
||||
{
|
||||
private $pacienteId;
|
||||
|
||||
public function __construct($pacienteId)
|
||||
{
|
||||
$this->pacienteId = $pacienteId;
|
||||
}
|
||||
|
||||
public function passes($attribute, $value)
|
||||
{
|
||||
$procedimento = Procedimento::findOrFail($value);
|
||||
$paciente = Paciente::findOrFail($this->pacienteId);
|
||||
$validation = new ProcedimentoValidationService($procedimento);
|
||||
|
||||
return $validation->isSexoValid($paciente->cidadao->sexo);
|
||||
}
|
||||
|
||||
public function message()
|
||||
{
|
||||
return 'Sexo não permitido para o procedimento selecionado.';
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user