43 lines
1.0 KiB
PHP
43 lines
1.0 KiB
PHP
<?php
|
|
|
|
namespace App\Services\Cadastro\SujeitoAtencao;
|
|
|
|
use App\Exceptions\Cadastro\SujeitoAtencao\ObitoAlreadyRegisteredException;
|
|
use App\Models\Cadastro\SujeitoAtencao\Cidadao;
|
|
use App\Services\Integracao\IntegracaoCidadaoService;
|
|
|
|
class ObitoService
|
|
{
|
|
private Cidadao $cidadao;
|
|
|
|
public function __construct(Cidadao $cidadao)
|
|
{
|
|
$this->cidadao = $cidadao;
|
|
}
|
|
|
|
public function save(\DateTime $obitoEm, $declaracao, string $causa, int $cidId = null, $usuarioId = null)
|
|
{
|
|
if ($this->cidadao->obito) {
|
|
|
|
throw new ObitoAlreadyRegisteredException();
|
|
}
|
|
|
|
$obito = $this->cidadao->obito()->create([
|
|
'usuario_id' => $usuarioId ?? null,
|
|
'obito_em' => $obitoEm,
|
|
'declaracao' => $declaracao,
|
|
'causa' => $causa,
|
|
'cid_id' => $cidId,
|
|
]);
|
|
|
|
IntegracaoCidadaoService::integrar($this->cidadao->id);
|
|
|
|
return $obito;
|
|
}
|
|
|
|
public function get()
|
|
{
|
|
return $this->cidadao->obito;
|
|
}
|
|
}
|