85 lines
2.6 KiB
PHP
85 lines
2.6 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Cadastro\SujeitoAtencao;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use App\Models\Cadastro\SujeitoAtencao\Cidadao;
|
|
use App\Models\Cadastro\SujeitoAtencao\Paciente;
|
|
use App\Models\Cadastro\SujeitoAtencao\Usuario;
|
|
use App\Services\Cadastro\SujeitoAtencao\CidadaoService;
|
|
use App\Utils\DataUtil;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Http\Response;
|
|
|
|
class CidadaoController extends Controller
|
|
{
|
|
protected $modulo = 'cadastro';
|
|
protected $funcionalidade = 'cidadao';
|
|
|
|
public function index()
|
|
{
|
|
$cidadaos = collect();
|
|
$pacientes = collect();
|
|
$usuarios = collect();
|
|
|
|
if (DataUtil::isStringTrue(request()->query('with_cidadaos'))) {
|
|
|
|
$cidadaos = Cidadao::where($this->getWhereFromQueryString(['cpf', 'dnv', 'nome', 'data_nascimento', 'nome_mae']))
|
|
->when(DataUtil::isStringTrue(request()->query('with_pacientes')), fn ($q) => $q->whereDoesntHave('paciente'))
|
|
->when(DataUtil::isStringTrue(request()->query('with_usuarios')), fn ($q) => $q->whereDoesntHave('usuario'))
|
|
->get();
|
|
}
|
|
|
|
if (DataUtil::isStringTrue(request()->query('with_pacientes'))) {
|
|
|
|
$pacientes = Paciente::whereHas('cidadao', function ($query) {
|
|
|
|
$query->where($this->getWhereFromQueryString(['cpf', 'dnv', 'nome', 'data_nascimento', 'nome_mae']));
|
|
})->get();
|
|
}
|
|
|
|
if (DataUtil::isStringTrue(request()->query('with_usuarios'))) {
|
|
|
|
$usuarios = Usuario::whereHas('cidadao', function ($query) {
|
|
|
|
$query->where($this->getWhereFromQueryString(['cpf', 'dnv', 'nome', 'data_nascimento', 'nome_mae']));
|
|
})->get();
|
|
}
|
|
|
|
$found = $cidadaos->isNotEmpty() || $pacientes->isNotEmpty() || $usuarios->isNotEmpty();
|
|
|
|
return response()->json(compact('found', 'cidadaos', 'pacientes', 'usuarios'), Response::HTTP_OK);
|
|
}
|
|
|
|
public function create()
|
|
{
|
|
return response()->json(
|
|
[
|
|
'form' => CidadaoService::create()['form'],
|
|
],
|
|
Response::HTTP_OK
|
|
);
|
|
}
|
|
|
|
public function show(int $id)
|
|
{
|
|
return response()->json($this->get(Cidadao::class, $id), Response::HTTP_OK);
|
|
}
|
|
|
|
public function edit($id)
|
|
{
|
|
return response()->json(
|
|
[
|
|
'form' => CidadaoService::edit($id)['form'],
|
|
'model' => CidadaoService::edit($id)['model'],
|
|
],
|
|
Response::HTTP_OK
|
|
);
|
|
}
|
|
|
|
public function update(Request $request)
|
|
{
|
|
return response()->json(CidadaoService::update($request), Response::HTTP_OK);
|
|
}
|
|
}
|