This commit is contained in:
105
api/app/Http/Controllers/Cadastro/EspecialidadeController.php
Normal file
105
api/app/Http/Controllers/Cadastro/EspecialidadeController.php
Normal file
@@ -0,0 +1,105 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Cadastro;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Services\Cadastro\EspecialidadeService;
|
||||
use Illuminate\Http\Response;
|
||||
|
||||
class EspecialidadeController extends Controller
|
||||
{
|
||||
protected $modulo = 'cadastro';
|
||||
protected $funcionalidade = 'especialidade';
|
||||
|
||||
public function datatable()
|
||||
{
|
||||
return datatables()
|
||||
->of(EspecialidadeService::datatable())
|
||||
->filterColumn('ocupacao_descricao', function ($query, $keyword) {
|
||||
|
||||
$query->whereRaw("CONCAT(ocupacao.codigo, ' - ', ocupacao.nome) like ?", ["%{$keyword}%"]);
|
||||
})
|
||||
->filterColumn('permite_integracao_conectasus_cidadao', function ($query, $keyword) {
|
||||
|
||||
$value = mb_strtolower($keyword, 'UTF-8');
|
||||
if (str_contains($value, 'sim')) {
|
||||
$query->where('especialidade.permite_integracao_conectasus_cidadao', true);
|
||||
} elseif (str_contains($value, 'não') || str_contains($value, 'nao')) {
|
||||
$query->where('especialidade.permite_integracao_conectasus_cidadao', false);
|
||||
}
|
||||
})
|
||||
->toJson();
|
||||
}
|
||||
|
||||
public function autocomplete()
|
||||
{
|
||||
return datatables()
|
||||
->of(EspecialidadeService::autocomplete())
|
||||
->toJson();
|
||||
}
|
||||
|
||||
public function create()
|
||||
{
|
||||
$this->auth(__FUNCTION__);
|
||||
|
||||
return response()->json(EspecialidadeService::create(), Response::HTTP_OK);
|
||||
}
|
||||
|
||||
public function store()
|
||||
{
|
||||
$this->auth(__FUNCTION__);
|
||||
|
||||
return response()->json(EspecialidadeService::store(), Response::HTTP_CREATED);
|
||||
}
|
||||
|
||||
public function edit($id)
|
||||
{
|
||||
$this->auth(__FUNCTION__);
|
||||
|
||||
return response()->json(EspecialidadeService::edit($id), Response::HTTP_OK);
|
||||
}
|
||||
|
||||
public function update($id)
|
||||
{
|
||||
$this->auth(__FUNCTION__);
|
||||
|
||||
return response()->json(EspecialidadeService::update($id), Response::HTTP_OK);
|
||||
}
|
||||
|
||||
public function activate($id)
|
||||
{
|
||||
$this->auth(__FUNCTION__);
|
||||
|
||||
return response()->json(EspecialidadeService::activate($id), Response::HTTP_OK);
|
||||
}
|
||||
|
||||
public function deactivate($id)
|
||||
{
|
||||
$this->auth(__FUNCTION__);
|
||||
|
||||
return response()->json(EspecialidadeService::deactivate($id), Response::HTTP_OK);
|
||||
}
|
||||
|
||||
public function destroy($id)
|
||||
{
|
||||
$this->auth(__FUNCTION__);
|
||||
|
||||
EspecialidadeService::destroy($id);
|
||||
|
||||
return response()->noContent();
|
||||
}
|
||||
|
||||
public function getDadosParaAtribuicao()
|
||||
{
|
||||
return response()->json(EspecialidadeService::getDadosParaAtribuicao(), Response::HTTP_OK);
|
||||
}
|
||||
|
||||
public function saveAtribuicao()
|
||||
{
|
||||
$this->auth(__FUNCTION__);
|
||||
|
||||
EspecialidadeService::saveAtribuicao();
|
||||
|
||||
return response()->noContent();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,133 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Cadastro\Estabelecimento;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\Cadastro\Estabelecimento\SalaRequest;
|
||||
use App\Models\Cadastro\Estabelecimento\Sala;
|
||||
use Illuminate\Http\Response;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class SalaController extends Controller
|
||||
{
|
||||
protected $modulo = 'cadastro';
|
||||
protected $funcionalidade = 'sala';
|
||||
|
||||
public function datatable()
|
||||
{
|
||||
$salas = DB::table('cadastro_sala AS sala')
|
||||
->join('cadastro_centro_custo AS centro_custo', 'centro_custo.id', 'sala.centro_custo_id')
|
||||
->join('cadastro_setor AS setor', 'setor.id', 'centro_custo.setor_id')
|
||||
->select([
|
||||
'sala.id',
|
||||
'sala.nome',
|
||||
'setor.nome as setor_nome'
|
||||
])
|
||||
->whereNull('sala.deleted_at')
|
||||
->where('centro_custo.infraestrutura_id', $this->getCurrentLotacao()->infraestrutura_id)
|
||||
->orderBy('setor.nome')
|
||||
->orderBy('sala.nome')
|
||||
->get();
|
||||
|
||||
return response()->json($salas, Response::HTTP_OK);
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
$this->auth(__FUNCTION__);
|
||||
|
||||
$salas = $this->get(Sala::class)->orderBy('nome')->get();
|
||||
|
||||
return response()->json($salas, Response::HTTP_OK);
|
||||
}
|
||||
|
||||
public function create()
|
||||
{
|
||||
$this->auth(__FUNCTION__);
|
||||
|
||||
$sala = new Sala;
|
||||
$sala->fill(array_fill_keys($sala->getFillable(), null));
|
||||
|
||||
return response()->json(
|
||||
[
|
||||
'form' => $this->getFormData(),
|
||||
'model' => $sala->makeHidden('id')
|
||||
],
|
||||
Response::HTTP_OK
|
||||
);
|
||||
}
|
||||
|
||||
public function store(SalaRequest $request)
|
||||
{
|
||||
$this->auth(__FUNCTION__);
|
||||
|
||||
$sala = Sala::create($this->getParams($request))->fresh();
|
||||
|
||||
return response()->json($sala, Response::HTTP_CREATED);
|
||||
}
|
||||
|
||||
public function show($id)
|
||||
{
|
||||
$this->auth(__FUNCTION__);
|
||||
|
||||
return response()->json($this->get(Sala::class, $id), Response::HTTP_OK);
|
||||
}
|
||||
|
||||
public function edit($id)
|
||||
{
|
||||
$this->auth(__FUNCTION__);
|
||||
|
||||
$sala = Sala::findOrFail($id);
|
||||
|
||||
return response()->json(
|
||||
[
|
||||
'form' => $this->getFormData(),
|
||||
'model' => $sala->makeHidden('id'),
|
||||
],
|
||||
Response::HTTP_OK
|
||||
);
|
||||
}
|
||||
|
||||
private function getFormData()
|
||||
{
|
||||
$lotacao = $this->getCurrentLotacao();
|
||||
|
||||
return [
|
||||
'unidade' => $lotacao->infraestrutura->unidade->nome_fantasia,
|
||||
'infraestrutura' => $lotacao->infraestrutura->nome,
|
||||
'centros_custo' => $lotacao->infraestrutura->centrosCusto
|
||||
->map(fn ($centroCusto) => [
|
||||
'id' => $centroCusto->id,
|
||||
'setor' => $centroCusto->setor->nome
|
||||
])
|
||||
];
|
||||
}
|
||||
|
||||
public function update(SalaRequest $request, $id)
|
||||
{
|
||||
$this->auth(__FUNCTION__);
|
||||
|
||||
$sala = tap(Sala::findOrFail($id))->update($this->getParams($request));
|
||||
|
||||
return response()->json($sala->fresh(), Response::HTTP_OK);
|
||||
}
|
||||
|
||||
private function getParams($request)
|
||||
{
|
||||
$params = $request->all();
|
||||
|
||||
$params['nome'] = Str::upper($params['nome']);
|
||||
|
||||
return $params;
|
||||
}
|
||||
|
||||
public function destroy($id)
|
||||
{
|
||||
$this->auth(__FUNCTION__);
|
||||
|
||||
Sala::findOrFail($id)->delete();
|
||||
|
||||
return response()->json(null, Response::HTTP_NO_CONTENT);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,130 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Cadastro\Estabelecimento;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\Cadastro\Estabelecimento\SetorRequest;
|
||||
use App\Models\Cadastro\Estabelecimento\Servico;
|
||||
use App\Models\Cadastro\Estabelecimento\Setor;
|
||||
use App\Models\Cadastro\Estabelecimento\SetorTipo;
|
||||
use Illuminate\Http\Response;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class SetorController extends Controller
|
||||
{
|
||||
protected $modulo = 'cadastro';
|
||||
protected $funcionalidade = 'setor';
|
||||
|
||||
public function datatable()
|
||||
{
|
||||
$setores = DB::table('cadastro_setor')
|
||||
->join('cadastro_setor_tipo', 'cadastro_setor_tipo.id', 'cadastro_setor.tipo_id')
|
||||
->leftJoin('cadastro_servico', 'cadastro_servico.id', 'cadastro_setor.servico_id')
|
||||
->select(
|
||||
'cadastro_setor_tipo.nome AS tipo',
|
||||
'cadastro_servico.nome AS servico',
|
||||
'cadastro_setor.id',
|
||||
'cadastro_setor.nome',
|
||||
)
|
||||
->whereNull('cadastro_setor.deleted_at');
|
||||
|
||||
return datatables()->of($setores)->skipTotalRecords()->make(true);
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
$this->auth(__FUNCTION__);
|
||||
|
||||
$setores = $this->get(Setor::class)->orderBy('nome')->get();
|
||||
|
||||
return response()->json($setores, Response::HTTP_OK);
|
||||
}
|
||||
|
||||
public function create()
|
||||
{
|
||||
$this->auth(__FUNCTION__);
|
||||
|
||||
return response()->json(
|
||||
[
|
||||
'form' => $this->getFormData(),
|
||||
],
|
||||
Response::HTTP_OK
|
||||
);
|
||||
}
|
||||
|
||||
public function store(SetorRequest $request)
|
||||
{
|
||||
$this->auth(__FUNCTION__);
|
||||
|
||||
$setor = Setor::create($this->getParams($request))->fresh();
|
||||
|
||||
return response()->json($setor, Response::HTTP_CREATED);
|
||||
}
|
||||
|
||||
public function show(int $id)
|
||||
{
|
||||
$this->auth(__FUNCTION__);
|
||||
|
||||
return response()->json($this->get(Setor::class, $id), Response::HTTP_OK);
|
||||
}
|
||||
|
||||
public function edit($id)
|
||||
{
|
||||
$this->auth(__FUNCTION__);
|
||||
|
||||
$setor = Setor::findOrFail($id);
|
||||
|
||||
return response()->json(
|
||||
[
|
||||
'form' => $this->getFormData(),
|
||||
'model' => [
|
||||
'tipo_id' => $setor->tipo_id,
|
||||
'servico_id' => $setor->servico_id,
|
||||
'nome' => $setor->nome,
|
||||
],
|
||||
],
|
||||
Response::HTTP_OK
|
||||
);
|
||||
}
|
||||
|
||||
private function getFormData()
|
||||
{
|
||||
return [
|
||||
'tipos' => SetorTipo::orderBy('nome')->get()->map(fn ($tipo) => [
|
||||
'id' => $tipo->id,
|
||||
'nome' => $tipo->nome,
|
||||
]),
|
||||
'servicos' => Servico::orderBy('nome')->get()->map(fn ($servico) => [
|
||||
'id' => $servico->id,
|
||||
'nome' => $servico->nome,
|
||||
]),
|
||||
];
|
||||
}
|
||||
|
||||
public function update(SetorRequest $request, int $id)
|
||||
{
|
||||
$this->auth(__FUNCTION__);
|
||||
|
||||
$setor = tap(Setor::findOrFail($id))->update($this->getParams($request));
|
||||
|
||||
return response()->json($setor->fresh(), Response::HTTP_OK);
|
||||
}
|
||||
|
||||
private function getParams($request)
|
||||
{
|
||||
return [
|
||||
'tipo_id' => $request->tipo_id,
|
||||
'servico_id' => $request->servico_id,
|
||||
'nome' => mb_strtoupper($request->nome),
|
||||
];
|
||||
}
|
||||
|
||||
public function destroy($id)
|
||||
{
|
||||
$this->auth(__FUNCTION__);
|
||||
|
||||
Setor::findOrFail($id)->delete();
|
||||
|
||||
return response()->json(null, Response::HTTP_NO_CONTENT);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,376 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Cadastro\Estabelecimento;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\Cadastro\Estabelecimento\UnidadeRequest;
|
||||
use App\Models\Cadastro\Estabelecimento\EsferaAdministrativa;
|
||||
use App\Models\Cadastro\Estabelecimento\Infraestrutura;
|
||||
use App\Models\Cadastro\Estabelecimento\NaturezaJuridica;
|
||||
use App\Models\Cadastro\Estabelecimento\Sala;
|
||||
use App\Models\Cadastro\Estabelecimento\Unidade;
|
||||
use App\Models\Cadastro\Estabelecimento\UnidadeTipo;
|
||||
use App\Models\Cadastro\Localizacao\Zona;
|
||||
use App\Models\Cns\TermoInvalido;
|
||||
use App\Models\Intranet\Estado;
|
||||
use App\Services\Cadastro\Localizacao\EnderecoSaveService;
|
||||
use App\Utils\MaskUtil;
|
||||
use Illuminate\Http\Response;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class UnidadeController extends Controller
|
||||
{
|
||||
protected $modulo = 'cadastro';
|
||||
protected $funcionalidade = 'unidade';
|
||||
|
||||
public function datatable()
|
||||
{
|
||||
$unidades = Unidade::with(['gestor.cidadao']);
|
||||
|
||||
return datatables()
|
||||
->of($unidades)
|
||||
->filterColumn('cnpj', function ($query, $keyword) {
|
||||
|
||||
$query
|
||||
->whereRaw("cadastro_unidade.cnpj like ?", ["%{$keyword}%"])
|
||||
->orWhereRaw(
|
||||
"CONCAT(
|
||||
SUBSTR(cadastro_unidade.cnpj,1,2),
|
||||
'.',
|
||||
SUBSTR(cadastro_unidade.cnpj,3,3),
|
||||
'.',
|
||||
SUBSTR(cadastro_unidade.cnpj,6,3),
|
||||
'/',
|
||||
SUBSTR(cadastro_unidade.cnpj,9,4),
|
||||
'-',
|
||||
SUBSTR(cadastro_unidade.cnpj,13,2)
|
||||
) like ?",
|
||||
["%{$keyword}%"]
|
||||
);
|
||||
})
|
||||
->skipTotalRecords()
|
||||
->toJson();
|
||||
}
|
||||
|
||||
public function autocomplete()
|
||||
{
|
||||
$unidades = Unidade::with([]);
|
||||
|
||||
return datatables()->of($unidades)->toJson();
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
$this->auth(__FUNCTION__);
|
||||
|
||||
$where = $this->getWhereFromQueryString([
|
||||
'cnpj',
|
||||
'nome_fantasia',
|
||||
'cnes',
|
||||
'unidade_referencia',
|
||||
['not_id', '<>']
|
||||
]);
|
||||
|
||||
$unidades = $this->get(Unidade::class)->where($where)->orderBy('nome_fantasia')->get();
|
||||
|
||||
return response()->json($unidades, Response::HTTP_OK);
|
||||
}
|
||||
|
||||
public function create()
|
||||
{
|
||||
$this->auth(__FUNCTION__);
|
||||
|
||||
return response()->json(
|
||||
[
|
||||
'form' => $this->getFormData(),
|
||||
],
|
||||
Response::HTTP_OK
|
||||
);
|
||||
}
|
||||
|
||||
public function store(UnidadeRequest $request)
|
||||
{
|
||||
$this->auth(__FUNCTION__);
|
||||
|
||||
$unidade = $this->save($request->all());
|
||||
|
||||
return response()->json($unidade->fresh(), Response::HTTP_CREATED);
|
||||
}
|
||||
|
||||
public function show($id)
|
||||
{
|
||||
$this->auth(__FUNCTION__);
|
||||
|
||||
$unidade = $this->get(Unidade::class, $id);
|
||||
|
||||
return response()->json($unidade, Response::HTTP_OK);
|
||||
}
|
||||
|
||||
public function edit($id)
|
||||
{
|
||||
$this->auth(__FUNCTION__);
|
||||
|
||||
$unidade = Unidade::findOrFail($id);
|
||||
|
||||
$formData = $this->getFormData($id);
|
||||
|
||||
return response()->json(
|
||||
[
|
||||
'form' => $formData,
|
||||
'model' => [
|
||||
'cnpj' => $unidade->cnpj ? MaskUtil::getCnpjMasked($unidade->cnpj) : null,
|
||||
'nome_fantasia' => $unidade->nome_fantasia,
|
||||
'razao_social' => $unidade->razao_social,
|
||||
'site' => $unidade->site,
|
||||
'email' => $unidade->email,
|
||||
'tipo_id' => $unidade->tipo_id,
|
||||
'esfera_administrativa_id' => $unidade->esfera_administrativa_id,
|
||||
'gestor' => [
|
||||
'id' => $unidade->gestor ? $unidade->gestor->id : null,
|
||||
'cidadao_nome' => $unidade->gestor ? $unidade->gestor->cidadao->nome : null,
|
||||
],
|
||||
'natureza_juridica_id' => $unidade->natureza_juridica_id,
|
||||
'cnes' => $unidade->cnes,
|
||||
'pertence_sus' => $unidade->pertence_sus,
|
||||
'unidade_referencia' => $unidade->unidade_referencia,
|
||||
'unidade_prestadora' => $unidade->unidade_prestadora,
|
||||
'infraestruturas' => $unidade->infraestruturas->map(fn ($infraestrutura) => [
|
||||
'id' => $infraestrutura->id,
|
||||
'unidade_id' => $infraestrutura->infraestrutura->unidade_id ?? null,
|
||||
'infraestrutura_id' => $infraestrutura->infraestrutura_id,
|
||||
'principal' => $infraestrutura->principal,
|
||||
'nome' => $infraestrutura->nome ?? '',
|
||||
'telefone' => MaskUtil::getPhoneMasked($infraestrutura->telefone),
|
||||
'endereco' => [
|
||||
'estado_id' => $infraestrutura->endereco->logradouro->municipio->estado->id,
|
||||
'municipio' => $infraestrutura->endereco->logradouro->municipio,
|
||||
'logradouro' => $infraestrutura->endereco->logradouro,
|
||||
'numero' => $infraestrutura->endereco->numero,
|
||||
'sem_numero' => $infraestrutura->endereco->sem_numero,
|
||||
'complemento' => $infraestrutura->endereco->complemento ?? '',
|
||||
'zona_id' => $infraestrutura->endereco->zona_id,
|
||||
],
|
||||
'centrosCusto' => $infraestrutura->centrosCusto->map(fn ($centroCusto) => [
|
||||
'id' => $centroCusto->id,
|
||||
'setor_id' => $centroCusto->setor_id,
|
||||
'setor_nome' => $centroCusto->setor->nome,
|
||||
'salas' => $centroCusto->salas->map(fn ($sala) => [
|
||||
'id' => $sala->id,
|
||||
'nome' => $sala->nome,
|
||||
]),
|
||||
]),
|
||||
]),
|
||||
'local' => null
|
||||
],
|
||||
],
|
||||
Response::HTTP_OK
|
||||
);
|
||||
}
|
||||
|
||||
private function getFormData($id = null)
|
||||
{
|
||||
return [
|
||||
'termos_invalidos' => TermoInvalido::all()->map(fn ($termo) => $termo->descricao),
|
||||
'dados_administrativos' => [
|
||||
'tipos' => UnidadeTipo::orderBy('descricao')->get()->map(fn ($tipo) => [
|
||||
'id' => $tipo->id,
|
||||
'descricao' => $tipo->descricao,
|
||||
]),
|
||||
'esferas_administrativas' => EsferaAdministrativa::orderBy('descricao')->get()->map(fn ($esfera) => [
|
||||
'id' => $esfera->id,
|
||||
'descricao' => $esfera->descricao,
|
||||
]),
|
||||
'naturezas_juridicas' => NaturezaJuridica::orderBy('descricao')->get()->map(fn ($natureza) => [
|
||||
'id' => $natureza->id,
|
||||
'descricao' => $natureza->descricao,
|
||||
]),
|
||||
],
|
||||
'infraestruturas' => [
|
||||
'unidades' => Unidade::setEagerLoads([])
|
||||
->when($id, fn ($q) => $q->where('id', '<>', $id))
|
||||
->whereHas('infraestruturas')
|
||||
->orderBy('nome_fantasia')
|
||||
->get(['id', 'nome_fantasia'])
|
||||
->map(fn ($unidade) => [
|
||||
'id' => $unidade->id,
|
||||
'nome_fantasia' => $unidade->nome_fantasia,
|
||||
'infraestruturas' => $unidade->infraestruturas()->setEagerLoads([])->with('endereco')
|
||||
->get()
|
||||
->sortBy('nome')
|
||||
->values(),
|
||||
]),
|
||||
'estados' => Estado::where('pais_id', 1)->orderBy('nome')->get()->map(fn ($estado) => [
|
||||
'id' => $estado->id,
|
||||
'uf' => $estado->uf,
|
||||
]),
|
||||
'zonas' => Zona::orderBy('descricao')->get()->map(fn ($zona) => [
|
||||
'id' => $zona->id,
|
||||
'descricao' => $zona->descricao
|
||||
]),
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
public function update(UnidadeRequest $request, $id)
|
||||
{
|
||||
$this->auth(__FUNCTION__);
|
||||
|
||||
$unidade = $this->save($request->all(), (Unidade::findOrFail($id))->id);
|
||||
|
||||
return response()->json($unidade->fresh(), Response::HTTP_OK);
|
||||
}
|
||||
|
||||
private function save($params, $id = null)
|
||||
{
|
||||
$unidade = null;
|
||||
|
||||
DB::transaction(function () use (&$unidade, $params, $id) {
|
||||
|
||||
$this->prepareUnidadeData($params);
|
||||
|
||||
$unidade = Unidade::updateOrCreate(
|
||||
['id' => $id],
|
||||
$params
|
||||
);
|
||||
|
||||
$infraestruturas = $params['infraestruturas'] ?? [];
|
||||
|
||||
$this->deleteInfraestruturasNotPresent($unidade, $infraestruturas);
|
||||
$this->saveInfraestruturas($unidade, $infraestruturas);
|
||||
});
|
||||
|
||||
return $unidade;
|
||||
}
|
||||
|
||||
private function prepareUnidadeData(&$params)
|
||||
{
|
||||
$params['nome_fantasia'] = mb_strtoupper($params['nome_fantasia']);
|
||||
$params['razao_social'] = mb_strtoupper($params['razao_social']);
|
||||
}
|
||||
|
||||
private function deleteInfraestruturasNotPresent($unidade, $infraestruturas)
|
||||
{
|
||||
$ids = collect($infraestruturas)->pluck('id')->filter(fn ($id) => !is_null($id))->toArray();
|
||||
|
||||
$unidade->infraestruturas()->whereNotIn('id', $ids)->each(function ($infraestrutura) {
|
||||
|
||||
$infraestrutura->centrosCusto()->each(function ($centroCusto) {
|
||||
|
||||
Sala::destroy($centroCusto->salas()->pluck('id'));
|
||||
|
||||
$centroCusto->delete();
|
||||
});
|
||||
|
||||
$infraestrutura->delete();
|
||||
});
|
||||
}
|
||||
|
||||
private function saveInfraestruturas($unidade, $infraestruturas)
|
||||
{
|
||||
foreach ($infraestruturas as $infraestrutura) {
|
||||
|
||||
$this->prepareInfraestruturaData($infraestrutura);
|
||||
|
||||
$enderecoSaveService = new EnderecoSaveService($infraestrutura['endereco']);
|
||||
$infraestrutura['endereco_id'] = ($enderecoSaveService->save())->id;
|
||||
|
||||
$infraestruturaSaved = $unidade->infraestruturas()->updateOrCreate(
|
||||
['id' => $infraestrutura['id'] ?? null],
|
||||
$infraestrutura
|
||||
);
|
||||
|
||||
$centrosCusto = $infraestrutura['centros_custo'] ?? [];
|
||||
|
||||
$this->deleteCentrosCustoNotPresent($infraestruturaSaved, $centrosCusto);
|
||||
$this->saveCentrosCusto($infraestruturaSaved, $centrosCusto);
|
||||
}
|
||||
}
|
||||
|
||||
private function prepareInfraestruturaData(&$params)
|
||||
{
|
||||
if (array_key_exists('nome', $params) && is_string($params['nome'])) {
|
||||
|
||||
$params['nome'] = mb_strtoupper($params['nome']);
|
||||
}
|
||||
|
||||
if (array_key_exists('principal', $params)
|
||||
&& (int) $params['principal'] === 1
|
||||
&& array_key_exists('nome', $params)
|
||||
) {
|
||||
|
||||
$params['nome'] = null;
|
||||
}
|
||||
}
|
||||
|
||||
private function deleteCentrosCustoNotPresent($infraestrutura, $centrosCusto)
|
||||
{
|
||||
$ids = collect($centrosCusto)->pluck('id')->filter(fn ($id) => !is_null($id))->toArray();
|
||||
|
||||
$infraestrutura->centrosCusto()->whereNotIn('id', $ids)->each(function ($centroCusto) {
|
||||
|
||||
Sala::destroy($centroCusto->salas()->pluck('id'));
|
||||
|
||||
$centroCusto->delete();
|
||||
});
|
||||
}
|
||||
|
||||
private function saveCentrosCusto($infraestrutura, $centrosCusto)
|
||||
{
|
||||
foreach ($centrosCusto as $centroCusto) {
|
||||
|
||||
$centroCustoSaved = $infraestrutura->centrosCusto()->updateOrCreate(
|
||||
['id' => $centroCusto['id'] ?? null],
|
||||
$centroCusto
|
||||
);
|
||||
|
||||
$salas = $centroCusto['salas'] ?? [];
|
||||
|
||||
$this->deleteSalasNotPresent($centroCustoSaved, $salas);
|
||||
$this->saveSalas($centroCustoSaved, $salas);
|
||||
}
|
||||
}
|
||||
|
||||
private function deleteSalasNotPresent($centroCusto, $salas)
|
||||
{
|
||||
$ids = collect($salas)->pluck('id')->filter(fn ($id) => !is_null($id))->toArray();
|
||||
|
||||
Sala::destroy($centroCusto->salas()->whereNotIn('id', $ids)->pluck('id'));
|
||||
}
|
||||
|
||||
private function saveSalas($centroCusto, $salas)
|
||||
{
|
||||
foreach ($salas as $sala) {
|
||||
|
||||
$this->prepareSalaData($sala);
|
||||
|
||||
$centroCusto->salas()->updateOrCreate(
|
||||
['id' => $sala['id'] ?? null],
|
||||
$sala
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
private function prepareSalaData(&$params)
|
||||
{
|
||||
if (array_key_exists('nome', $params) && is_string($params['nome'])) {
|
||||
|
||||
$params['nome'] = mb_strtoupper($params['nome']);
|
||||
}
|
||||
}
|
||||
|
||||
public function destroy($id)
|
||||
{
|
||||
$this->auth(__FUNCTION__);
|
||||
|
||||
$unidade = Unidade::findOrFail($id);
|
||||
|
||||
DB::transaction(function () use ($unidade) {
|
||||
|
||||
Infraestrutura::destroy($unidade->infraestruturas()->pluck('id'));
|
||||
|
||||
$unidade->delete();
|
||||
});
|
||||
|
||||
return response()->json(null, Response::HTTP_NO_CONTENT);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Cadastro\Fabricante;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Cadastro\Fabricante;
|
||||
use App\Services\Cadastro\Fabricante\FabricanteService;
|
||||
use Illuminate\Http\Response;
|
||||
|
||||
class FabricanteController extends Controller
|
||||
{
|
||||
protected $modulo = 'cadastro';
|
||||
protected $funcionalidade = 'fabricante';
|
||||
|
||||
public function autocomplete()
|
||||
{
|
||||
return FabricanteService::autocomplete();
|
||||
}
|
||||
|
||||
public function datatable()
|
||||
{
|
||||
return FabricanteService::datatable();
|
||||
}
|
||||
|
||||
public function create()
|
||||
{
|
||||
$this->auth(__FUNCTION__);
|
||||
|
||||
return response()->json(FabricanteService::create(), Response::HTTP_OK);
|
||||
}
|
||||
|
||||
public function store()
|
||||
{
|
||||
$this->auth(__FUNCTION__);
|
||||
|
||||
return response()->json(FabricanteService::store(), Response::HTTP_CREATED);
|
||||
}
|
||||
|
||||
public function edit($id)
|
||||
{
|
||||
$this->auth(__FUNCTION__);
|
||||
|
||||
return response()->json(FabricanteService::edit($id), Response::HTTP_OK);
|
||||
}
|
||||
|
||||
public function update($id)
|
||||
{
|
||||
$this->auth(__FUNCTION__);
|
||||
|
||||
return response()->json(FabricanteService::update($id), Response::HTTP_OK);
|
||||
}
|
||||
|
||||
public function destroy($id)
|
||||
{
|
||||
$this->auth(__FUNCTION__);
|
||||
|
||||
return response()->json(FabricanteService::destroy($id), Response::HTTP_NO_CONTENT);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Cadastro\Feriado;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Services\Cadastro\Feriado\FeriadoService;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Response;
|
||||
class FeriadoController extends Controller
|
||||
{
|
||||
protected $modulo = 'cadastro';
|
||||
protected $funcionalidade = 'feriado';
|
||||
|
||||
public function datatable()
|
||||
{
|
||||
return datatables()->of(FeriadoService::datatable())
|
||||
->filterColumn('cadastro_feriado.mes', function($query, $keyword) {
|
||||
$query->whereRaw("cadastro_feriado.mes = ? OR CASE
|
||||
WHEN cadastro_feriado.mes = 1 THEN 'JANEIRO'
|
||||
WHEN cadastro_feriado.mes = 2 THEN 'FEVEREIRO'
|
||||
WHEN cadastro_feriado.mes = 3 THEN 'MARÇO'
|
||||
WHEN cadastro_feriado.mes = 4 THEN 'ABRIL'
|
||||
WHEN cadastro_feriado.mes = 5 THEN 'MAIO'
|
||||
WHEN cadastro_feriado.mes = 6 THEN 'JUNHO'
|
||||
WHEN cadastro_feriado.mes = 7 THEN 'JULHO'
|
||||
WHEN cadastro_feriado.mes = 8 THEN 'AGOSTO'
|
||||
WHEN cadastro_feriado.mes = 9 THEN 'SETEMBRO'
|
||||
WHEN cadastro_feriado.mes = 10 THEN 'OUTUBRO'
|
||||
WHEN cadastro_feriado.mes = 11 THEN 'NOVEMBRO'
|
||||
WHEN cadastro_feriado.mes = 12 THEN 'DEZEMBRO'
|
||||
END LIKE ?", [$keyword, "%{$keyword}%"]);
|
||||
})
|
||||
->filterColumn('cadastro_feriado.dia', function ($query, $keyword) {
|
||||
$query->whereRaw("cadastro_feriado.dia like ?", ["%{$keyword}%"]);
|
||||
})
|
||||
->filterColumn('cadastro_feriado.ano', function ($query, $keyword) {
|
||||
$query->whereRaw("cadastro_feriado.ano like ?", ["%{$keyword}%"]);
|
||||
})
|
||||
->skipTotalRecords()
|
||||
->toJson();
|
||||
}
|
||||
|
||||
public function create()
|
||||
{
|
||||
$this->auth(__FUNCTION__);
|
||||
|
||||
return response()->json(FeriadoService::create(), Response::HTTP_CREATED);
|
||||
}
|
||||
|
||||
public function store(Request $request)
|
||||
{
|
||||
$this->auth(__FUNCTION__);
|
||||
|
||||
return response()->json(FeriadoService::store($request), Response::HTTP_CREATED);
|
||||
}
|
||||
|
||||
public function edit($id)
|
||||
{
|
||||
$this->auth(__FUNCTION__);
|
||||
|
||||
return response()->json(FeriadoService::edit($id), Response::HTTP_OK);
|
||||
}
|
||||
|
||||
public function update(Request $request, $id)
|
||||
{
|
||||
$this->auth(__FUNCTION__);
|
||||
|
||||
return response()->json(FeriadoService::update($request, $id), Response::HTTP_NO_CONTENT);
|
||||
}
|
||||
|
||||
public function destroy($id)
|
||||
{
|
||||
$this->auth(__FUNCTION__);
|
||||
|
||||
return response()->json(FeriadoService::destroy($id), Response::HTTP_NO_CONTENT);
|
||||
}
|
||||
|
||||
}
|
||||
71
api/app/Http/Controllers/Cadastro/FeridaController.php
Normal file
71
api/app/Http/Controllers/Cadastro/FeridaController.php
Normal file
@@ -0,0 +1,71 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Cadastro;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Services\Cadastro\FeridaService;
|
||||
use Illuminate\Http\Response;
|
||||
|
||||
class FeridaController extends Controller
|
||||
{
|
||||
protected $modulo = 'cadastro';
|
||||
protected $funcionalidade = 'ferida';
|
||||
|
||||
public function datatable()
|
||||
{
|
||||
return datatables()
|
||||
->of(FeridaService::datatable())
|
||||
->toJson();
|
||||
}
|
||||
|
||||
public function create()
|
||||
{
|
||||
$this->auth(__FUNCTION__);
|
||||
|
||||
return response()->json(FeridaService::create(), Response::HTTP_OK);
|
||||
}
|
||||
|
||||
public function store()
|
||||
{
|
||||
$this->auth(__FUNCTION__);
|
||||
|
||||
return response()->json(FeridaService::store(), Response::HTTP_CREATED);
|
||||
}
|
||||
|
||||
public function edit($id)
|
||||
{
|
||||
$this->auth(__FUNCTION__);
|
||||
|
||||
return response()->json(FeridaService::edit($id), Response::HTTP_OK);
|
||||
}
|
||||
|
||||
public function update($id)
|
||||
{
|
||||
$this->auth(__FUNCTION__);
|
||||
|
||||
return response()->json(FeridaService::update($id), Response::HTTP_OK);
|
||||
}
|
||||
|
||||
public function activate($id)
|
||||
{
|
||||
$this->auth(__FUNCTION__);
|
||||
|
||||
return response()->json(FeridaService::activate($id), Response::HTTP_OK);
|
||||
}
|
||||
|
||||
public function deactivate($id)
|
||||
{
|
||||
$this->auth(__FUNCTION__);
|
||||
|
||||
return response()->json(FeridaService::deactivate($id), Response::HTTP_OK);
|
||||
}
|
||||
|
||||
public function destroy($id)
|
||||
{
|
||||
$this->auth(__FUNCTION__);
|
||||
|
||||
FeridaService::destroy($id);
|
||||
|
||||
return response()->noContent();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Cadastro\Fornecedor;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Services\Cadastro\Fornecedor\FornecedorService;
|
||||
use Illuminate\Http\Response;
|
||||
|
||||
class FornecedorController extends Controller
|
||||
{
|
||||
protected $modulo = 'cadastro';
|
||||
protected $funcionalidade = 'fornecedor';
|
||||
|
||||
public function autocomplete()
|
||||
{
|
||||
return FornecedorService::autocomplete();
|
||||
}
|
||||
|
||||
public function datatable()
|
||||
{
|
||||
return FornecedorService::datatable();
|
||||
}
|
||||
|
||||
public function create()
|
||||
{
|
||||
$this->auth(__FUNCTION__);
|
||||
|
||||
return response()->json(FornecedorService::create(), Response::HTTP_OK);
|
||||
}
|
||||
|
||||
public function store()
|
||||
{
|
||||
$this->auth(__FUNCTION__);
|
||||
|
||||
return response()->json(FornecedorService::store(), Response::HTTP_CREATED);
|
||||
}
|
||||
|
||||
public function edit($id)
|
||||
{
|
||||
$this->auth(__FUNCTION__);
|
||||
|
||||
return response()->json(FornecedorService::edit($id), Response::HTTP_OK);
|
||||
}
|
||||
|
||||
public function update($id)
|
||||
{
|
||||
$this->auth(__FUNCTION__);
|
||||
|
||||
return response()->json(FornecedorService::update($id), Response::HTTP_OK);
|
||||
}
|
||||
|
||||
public function destroy($id)
|
||||
{
|
||||
$this->auth(__FUNCTION__);
|
||||
|
||||
return response()->json(FornecedorService::destroy($id), Response::HTTP_NO_CONTENT);
|
||||
}
|
||||
}
|
||||
54
api/app/Http/Controllers/Cadastro/Grupo/GrupoController.php
Normal file
54
api/app/Http/Controllers/Cadastro/Grupo/GrupoController.php
Normal file
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Cadastro\Grupo;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Services\Cadastro\Grupo\GrupoService;
|
||||
use DB;
|
||||
use Illuminate\Http\Response;
|
||||
|
||||
class GrupoController extends Controller
|
||||
{
|
||||
protected $modulo = 'cadastro';
|
||||
protected $funcionalidade = 'grupo';
|
||||
|
||||
public function datatable()
|
||||
{
|
||||
return datatables()->of(GrupoService::datatable())->skipTotalRecords()->toJson();
|
||||
}
|
||||
|
||||
public function create()
|
||||
{
|
||||
$this->auth(__FUNCTION__);
|
||||
|
||||
return response()->json(GrupoService::create(), Response::HTTP_CREATED);
|
||||
}
|
||||
|
||||
public function store()
|
||||
{
|
||||
$this->auth(__FUNCTION__);
|
||||
|
||||
return response()->json(GrupoService::store(), Response::HTTP_CREATED);
|
||||
}
|
||||
|
||||
public function edit($id)
|
||||
{
|
||||
$this->auth(__FUNCTION__);
|
||||
|
||||
return response()->json(GrupoService::edit($id), Response::HTTP_OK);
|
||||
}
|
||||
|
||||
public function update($id)
|
||||
{
|
||||
$this->auth(__FUNCTION__);
|
||||
|
||||
return response()->json(GrupoService::update($id), Response::HTTP_OK);
|
||||
}
|
||||
|
||||
public function destroy($id)
|
||||
{
|
||||
$this->auth(__FUNCTION__);
|
||||
|
||||
return response()->json(GrupoService::destroy($id), Response::HTTP_NO_CONTENT);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Cadastro\Localizacao;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\Cadastro\Localizacao\BairroRequest;
|
||||
use App\Models\Cadastro\Localizacao\Bairro;
|
||||
use Illuminate\Http\Response;
|
||||
|
||||
class BairroController extends Controller
|
||||
{
|
||||
protected $modulo = 'cadastro';
|
||||
protected $funcionalidade = 'bairro';
|
||||
|
||||
public function datatable()
|
||||
{
|
||||
$bairros = Bairro::with([]);
|
||||
|
||||
return datatables()->of($bairros)->skipTotalRecords()->toJson();
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
$this->auth(__FUNCTION__);
|
||||
|
||||
$bairros = $this->get(Bairro::class)->orderBy('nome')->get();
|
||||
|
||||
return response()->json($bairros, Response::HTTP_OK);
|
||||
}
|
||||
|
||||
public function store(BairroRequest $request)
|
||||
{
|
||||
$this->auth(__FUNCTION__);
|
||||
|
||||
$bairro = Bairro::create($this->getParams($request));
|
||||
|
||||
return response()->json($bairro, Response::HTTP_CREATED);
|
||||
}
|
||||
|
||||
public function show($id)
|
||||
{
|
||||
$this->auth(__FUNCTION__);
|
||||
|
||||
return response()->json($this->get(Bairro::class, $id), Response::HTTP_OK);
|
||||
}
|
||||
|
||||
public function edit($id)
|
||||
{
|
||||
$this->auth(__FUNCTION__);
|
||||
|
||||
$bairro = Bairro::findOrFail($id);
|
||||
|
||||
return response()->json(
|
||||
[
|
||||
'model' => [
|
||||
'nome' => $bairro->nome,
|
||||
],
|
||||
],
|
||||
Response::HTTP_OK
|
||||
);
|
||||
}
|
||||
|
||||
public function update(BairroRequest $request, $id)
|
||||
{
|
||||
$this->auth(__FUNCTION__);
|
||||
|
||||
$bairro = tap(Bairro::findOrFail($id))->update($this->getParams($request));
|
||||
|
||||
return response()->json($bairro->fresh(), Response::HTTP_OK);
|
||||
}
|
||||
|
||||
private function getParams($request)
|
||||
{
|
||||
return [
|
||||
'nome' => mb_strtoupper($request->nome)
|
||||
];
|
||||
}
|
||||
|
||||
public function destroy($id)
|
||||
{
|
||||
$this->auth(__FUNCTION__);
|
||||
|
||||
Bairro::findOrFail($id)->delete();
|
||||
|
||||
return response()->json(null, Response::HTTP_NO_CONTENT);
|
||||
}
|
||||
|
||||
public function autocomplete()
|
||||
{
|
||||
$bairros = Bairro::with([]);
|
||||
return datatables()->of($bairros)->toJson();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,275 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Cadastro\Localizacao;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\Cadastro\Localizacao\LogradouroRequest;
|
||||
use App\Models\Cadastro\Localizacao\Bairro;
|
||||
use App\Models\Cadastro\Localizacao\Logradouro;
|
||||
use App\Models\Cadastro\Localizacao\LogradouroTipo;
|
||||
use App\Models\Cns\TermoInvalido;
|
||||
use App\Models\Intranet\Estado;
|
||||
use App\Utils\DataUtil;
|
||||
use App\Utils\MaskUtil;
|
||||
use Illuminate\Http\Response;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class LogradouroController extends Controller
|
||||
{
|
||||
protected $modulo = 'cadastro';
|
||||
protected $funcionalidade = 'logradouro';
|
||||
|
||||
public function datatable()
|
||||
{
|
||||
$logradouros = DB::table('cadastro_logradouro')
|
||||
->whereNull('cadastro_logradouro.deleted_at')
|
||||
->select([
|
||||
'cadastro_logradouro.id',
|
||||
'cadastro_estado.uf AS estado_uf',
|
||||
'cadastro_municipio.nome AS municipio_nome',
|
||||
'cadastro_bairro.nome AS bairro_nome',
|
||||
'cadastro_logradouro_tipo.descricao as logradouro_tipo_descricao',
|
||||
'cadastro_logradouro.nome',
|
||||
'cadastro_logradouro.cep',
|
||||
'cadastro_logradouro.tipo_id',
|
||||
])
|
||||
->join('intranet.cadastro_municipio', 'cadastro_municipio.id', 'cadastro_logradouro.municipio_id')
|
||||
->join('intranet.cadastro_estado', 'cadastro_estado.id', 'cadastro_municipio.estado_id')
|
||||
->join('cadastro_bairro', 'cadastro_bairro.id', 'cadastro_logradouro.bairro_id')
|
||||
->join('cadastro_logradouro_tipo', 'cadastro_logradouro_tipo.id', 'cadastro_logradouro.tipo_id');
|
||||
|
||||
return datatables()
|
||||
->of($logradouros)
|
||||
->filterColumn('cep', function ($query, $keyword) {
|
||||
|
||||
$query
|
||||
->whereRaw("cadastro_logradouro.cep like ?", ["%{$keyword}%"])
|
||||
->orWhereRaw(
|
||||
"CONCAT(
|
||||
SUBSTR(cadastro_logradouro.cep,1,2),
|
||||
'.',
|
||||
SUBSTR(cadastro_logradouro.cep,3,3),
|
||||
'-',
|
||||
SUBSTR(cadastro_logradouro.cep,6,3)
|
||||
) like ?",
|
||||
["%{$keyword}%"]
|
||||
);
|
||||
})
|
||||
->skipTotalRecords()
|
||||
->toJson();
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
$this->auth(__FUNCTION__);
|
||||
|
||||
$logradouros = $this->get(Logradouro::class)
|
||||
->where($this->getWhereFromQueryString(['cep', 'municipio_id']))
|
||||
->orderBy('nome')
|
||||
->get();
|
||||
|
||||
return response()->json($logradouros, Response::HTTP_OK);
|
||||
}
|
||||
|
||||
public function hasCep($cep)
|
||||
{
|
||||
return response()->json(Logradouro::where('cep', $cep)->exists(), Response::HTTP_OK);
|
||||
}
|
||||
|
||||
public function create()
|
||||
{
|
||||
$this->auth(__FUNCTION__);
|
||||
|
||||
return response()->json(
|
||||
[
|
||||
'form' => $this->getFormData()
|
||||
],
|
||||
Response::HTTP_OK
|
||||
);
|
||||
}
|
||||
|
||||
public function store(LogradouroRequest $request)
|
||||
{
|
||||
$this->auth(__FUNCTION__);
|
||||
|
||||
$logradouro = null;
|
||||
|
||||
if (DataUtil::getBooleanValueFromStringBoolean($request->search_by_base_endereco_nacional) === true) {
|
||||
$tipo = LogradouroTipo::where('descricao', $request->logradouro_tipo_nome)->first();
|
||||
$bairro = Bairro::where('nome', $request->bairro_nome)->first();
|
||||
|
||||
if (is_null($tipo)) {
|
||||
$tipo = LogradouroTipo::create(['descricao' => $request->logradouro_tipo_nome])->fresh();
|
||||
}
|
||||
|
||||
if (is_null($bairro)) {
|
||||
$bairro = Bairro::create(['nome' => $request->bairro_nome])->fresh();
|
||||
}
|
||||
|
||||
$logradouro = Logradouro::where('municipio_id', $request->municipio_id)
|
||||
->where('bairro_id', $bairro->id)
|
||||
->where('tipo_id', $tipo->id)
|
||||
->where('nome', $request->logradouro_nome)
|
||||
->where('cep', $request->logradouro_cep)
|
||||
->first();
|
||||
|
||||
if (is_null($logradouro)) {
|
||||
$logradouro = Logradouro::create([
|
||||
'municipio_id' => $request->municipio_id,
|
||||
'tipo_id' => $tipo->id,
|
||||
'bairro_id' => $bairro->id,
|
||||
'nome' => $request->logradouro_nome,
|
||||
'cep' => $request->logradouro_cep,
|
||||
])->fresh();
|
||||
}
|
||||
} else {
|
||||
$logradouro = Logradouro::create($this->getParams($request))->fresh();
|
||||
}
|
||||
|
||||
return response()->json($logradouro, Response::HTTP_CREATED);
|
||||
}
|
||||
|
||||
public function show($id)
|
||||
{
|
||||
$this->auth(__FUNCTION__);
|
||||
|
||||
return response()->json($this->get(Logradouro::class, $id), Response::HTTP_OK);
|
||||
}
|
||||
|
||||
public function edit($id)
|
||||
{
|
||||
$this->auth(__FUNCTION__);
|
||||
|
||||
$logradouro = Logradouro::findOrFail($id);
|
||||
|
||||
return response()->json(
|
||||
[
|
||||
'form' => $this->getFormData(),
|
||||
'model' => [
|
||||
'tipo_id' => $logradouro->tipo_id,
|
||||
'bairro' => $logradouro->bairro,
|
||||
'estado_id' => $logradouro->municipio->estado_id,
|
||||
'municipio' => $logradouro->municipio,
|
||||
'cep' => MaskUtil::getCepMasked($logradouro->cep),
|
||||
'nome' => $logradouro->nome,
|
||||
],
|
||||
],
|
||||
Response::HTTP_OK
|
||||
);
|
||||
}
|
||||
|
||||
private function getFormData()
|
||||
{
|
||||
return [
|
||||
'termos_invalidos' => TermoInvalido::all()->map(fn ($termo) => $termo->descricao),
|
||||
'tipos' => LogradouroTipo::orderBy('descricao')->get()->map(fn ($tipo) => [
|
||||
'id' => $tipo->id,
|
||||
'descricao' => $tipo->descricao,
|
||||
]),
|
||||
'estados' => Estado::where('pais_id', 1)->orderBy('nome')->get()->map(fn ($estado) => [
|
||||
'id' => $estado->id,
|
||||
'uf' => $estado->uf,
|
||||
]),
|
||||
];
|
||||
}
|
||||
|
||||
public function update(LogradouroRequest $request, $id)
|
||||
{
|
||||
$this->auth(__FUNCTION__);
|
||||
|
||||
$logradouro = tap(Logradouro::findOrFail($id))->update($this->getParams($request));
|
||||
|
||||
return response()->json($logradouro->fresh(), Response::HTTP_OK);
|
||||
}
|
||||
|
||||
private function getParams($request)
|
||||
{
|
||||
return [
|
||||
'tipo_id' => $request->tipo_id,
|
||||
'bairro_id' => $request->bairro_id,
|
||||
'estado_id' => $request->estado_id,
|
||||
'municipio_id' => $request->municipio_id,
|
||||
'cep' => $request->cep,
|
||||
'nome' => mb_strtoupper($request->nome)
|
||||
];
|
||||
}
|
||||
|
||||
public function destroy($id)
|
||||
{
|
||||
$this->auth(__FUNCTION__);
|
||||
|
||||
Logradouro::findOrFail($id)->delete();
|
||||
|
||||
return response()->json(null, Response::HTTP_NO_CONTENT);
|
||||
}
|
||||
|
||||
public function autocomplete()
|
||||
{
|
||||
if (isset(request()->search_by_base_endereco_nacional) && DataUtil::getBooleanValueFromStringBoolean(request()->search_by_base_endereco_nacional) === true) {
|
||||
$logradouros = DB::table('intranet.cadastro_logradouro')
|
||||
->select([
|
||||
'cadastro_estado.uf AS estado_uf',
|
||||
'cadastro_municipio.nome AS municipio_nome',
|
||||
'cadastro_bairro.nome AS bairro_nome',
|
||||
'cadastro_logradouro_tipo.id AS logradouro_tipo_id',
|
||||
'cadastro_logradouro_tipo.nome AS logradouro_tipo_nome',
|
||||
'cadastro_logradouro.nome AS logradouro_nome',
|
||||
DB::raw('COALESCE(cadastro_logradouro.cep, cadastro_municipio.cep) AS logradouro_cep'),
|
||||
])
|
||||
->join('intranet.cadastro_logradouro_tipo', 'cadastro_logradouro_tipo.id', 'cadastro_logradouro.tipo_id')
|
||||
->join('intranet.cadastro_bairro', 'cadastro_bairro.id', 'cadastro_logradouro.bairro_id')
|
||||
->join('intranet.cadastro_municipio', 'cadastro_municipio.id', 'cadastro_bairro.municipio_id')
|
||||
->join('intranet.cadastro_estado', 'cadastro_estado.id', 'cadastro_municipio.estado_id')
|
||||
->when(request()->municipio_id, fn ($q) => $q->where('cadastro_municipio.id', request()->municipio_id));
|
||||
} else {
|
||||
$logradouros = Logradouro::with([]);
|
||||
|
||||
if (is_numeric(request()->municipio_id)) {
|
||||
|
||||
$logradouros->where('municipio_id', request()->municipio_id);
|
||||
}
|
||||
|
||||
if (is_numeric(request()->cep)) {
|
||||
|
||||
$logradouros->where('cep', request()->cep);
|
||||
}
|
||||
|
||||
if (is_numeric(request()->tipo_id)) {
|
||||
|
||||
$logradouros->where('tipo_id', request()->tipo_id);
|
||||
}
|
||||
|
||||
if (is_numeric(request()->bairro_id)) {
|
||||
|
||||
$logradouros->where('bairro_id', request()->bairro_id);
|
||||
}
|
||||
|
||||
if (request()->with_domicilio) {
|
||||
|
||||
$logradouros->whereHas('enderecos', function ($query) {
|
||||
$query->whereHas('domicilios', function ($query) {
|
||||
$query->whereHas('cadastroDomiciliar');
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return datatables()
|
||||
->of($logradouros)
|
||||
->filterColumn('cadastro_logradouro.cep', function ($query, $keyword) {
|
||||
$query
|
||||
->whereRaw("COALESCE(cadastro_logradouro.cep, cadastro_municipio.cep) like ?", ["%{$keyword}%"])
|
||||
->orWhereRaw(
|
||||
"CONCAT(
|
||||
SUBSTR(COALESCE(cadastro_logradouro.cep, cadastro_municipio.cep),1,2),
|
||||
'.',
|
||||
SUBSTR(COALESCE(cadastro_logradouro.cep, cadastro_municipio.cep),3,3),
|
||||
'-',
|
||||
SUBSTR(COALESCE(cadastro_logradouro.cep, cadastro_municipio.cep),6,3)
|
||||
) like ?",
|
||||
["%{$keyword}%"]
|
||||
);
|
||||
})
|
||||
->toJson();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,94 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Cadastro\Localizacao;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\Cadastro\Localizacao\LoteamentoRequest;
|
||||
use App\Models\Cadastro\Localizacao\Loteamento;
|
||||
use Illuminate\Http\Response;
|
||||
|
||||
class LoteamentoController extends Controller
|
||||
{
|
||||
protected $modulo = 'cadastro';
|
||||
protected $funcionalidade = 'loteamento';
|
||||
|
||||
public function datatable()
|
||||
{
|
||||
$loteamentos = Loteamento::with([]);
|
||||
|
||||
return datatables()->of($loteamentos)->skipTotalRecords()->toJson();
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
$this->auth(__FUNCTION__);
|
||||
|
||||
$loteamentos = $this->get(Loteamento::class)->orderBy('nome')->get();
|
||||
|
||||
return response()->json($loteamentos, Response::HTTP_OK);
|
||||
}
|
||||
|
||||
public function store(LoteamentoRequest $request)
|
||||
{
|
||||
$this->auth(__FUNCTION__);
|
||||
|
||||
$loteamento = Loteamento::create($this->getParams($request));
|
||||
|
||||
return response()->json($loteamento, Response::HTTP_CREATED);
|
||||
}
|
||||
|
||||
public function show($id)
|
||||
{
|
||||
$this->auth(__FUNCTION__);
|
||||
|
||||
return response()->json($this->get(Loteamento::class, $id), Response::HTTP_OK);
|
||||
}
|
||||
|
||||
public function edit($id)
|
||||
{
|
||||
$this->auth(__FUNCTION__);
|
||||
|
||||
$loteamento = Loteamento::findOrFail($id);
|
||||
|
||||
return response()->json(
|
||||
[
|
||||
'model' => [
|
||||
'nome' => $loteamento->nome,
|
||||
],
|
||||
],
|
||||
Response::HTTP_OK
|
||||
);
|
||||
}
|
||||
|
||||
public function update(LoteamentoRequest $request, $id)
|
||||
{
|
||||
$this->auth(__FUNCTION__);
|
||||
|
||||
$loteamento = tap(Loteamento::findOrFail($id))->update($this->getParams($request));
|
||||
|
||||
return response()->json($loteamento->fresh(), Response::HTTP_OK);
|
||||
}
|
||||
|
||||
private function getParams($request)
|
||||
{
|
||||
return [
|
||||
'nome' => mb_strtoupper($request->nome)
|
||||
];
|
||||
}
|
||||
|
||||
public function destroy($id)
|
||||
{
|
||||
$this->auth(__FUNCTION__);
|
||||
|
||||
Loteamento::findOrFail($id)->delete();
|
||||
|
||||
return response()->json(null, Response::HTTP_NO_CONTENT);
|
||||
}
|
||||
|
||||
public function autocomplete()
|
||||
{
|
||||
$loteamentos = Loteamento::with([]);
|
||||
|
||||
return datatables()->of($loteamentos)->toJson();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Cadastro\Material;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Services\Cadastro\Material\MaterialService;
|
||||
use Illuminate\Http\Response;
|
||||
|
||||
class MaterialController extends Controller
|
||||
{
|
||||
protected $modulo = 'cadastro';
|
||||
protected $funcionalidade = 'material';
|
||||
|
||||
public function autocomplete()
|
||||
{
|
||||
return datatables()->of(MaterialService::autocomplete())->make(true);
|
||||
}
|
||||
|
||||
public function datatable()
|
||||
{
|
||||
return datatables()
|
||||
->of(MaterialService::datatable())
|
||||
->filterColumn('apresentacao', function ($query, $keyword) {
|
||||
|
||||
$query->whereRaw("CONCAT(
|
||||
UPPER(cadastro_apresentacao.nome),
|
||||
' ',
|
||||
CAST(cadastro_material.quantidade AS INTEGER),
|
||||
' ',
|
||||
UPPER(COALESCE(apresentacao_unidade_medida.nome, ''))
|
||||
) like ?", ["%{$keyword}%"]);
|
||||
})
|
||||
->make(true);
|
||||
}
|
||||
|
||||
public function getEstoque($materialId, $centroCustoId = null)
|
||||
{
|
||||
return response()->json(
|
||||
MaterialService::getEstoque($materialId, $centroCustoId),
|
||||
Response::HTTP_OK
|
||||
);
|
||||
}
|
||||
|
||||
public function create()
|
||||
{
|
||||
$this->auth(__FUNCTION__);
|
||||
|
||||
return response()->json(MaterialService::create(), Response::HTTP_CREATED);
|
||||
}
|
||||
|
||||
public function store()
|
||||
{
|
||||
$this->auth(__FUNCTION__);
|
||||
|
||||
return response()->json(MaterialService::store(), Response::HTTP_CREATED);
|
||||
}
|
||||
|
||||
public function edit($id)
|
||||
{
|
||||
$this->auth(__FUNCTION__);
|
||||
|
||||
return response()->json(MaterialService::edit($id), Response::HTTP_OK);
|
||||
}
|
||||
|
||||
public function update($id)
|
||||
{
|
||||
$this->auth(__FUNCTION__);
|
||||
|
||||
return response()->json(MaterialService::update($id), Response::HTTP_OK);
|
||||
}
|
||||
|
||||
public function destroy($id)
|
||||
{
|
||||
$this->auth(__FUNCTION__);
|
||||
|
||||
return response()->json(MaterialService::destroy($id), Response::HTTP_NO_CONTENT);
|
||||
}
|
||||
|
||||
public function editMaterialBnafar($materialId)
|
||||
{
|
||||
return response()->json(MaterialService::editMaterialBnafar($materialId), Response::HTTP_OK);
|
||||
}
|
||||
|
||||
public function updateMaterialBnafar($materialId)
|
||||
{
|
||||
return response()->json(MaterialService::updateMaterialBnafar($materialId), Response::HTTP_OK);
|
||||
}
|
||||
|
||||
public function storeIntegracaoBnafarMedicamentos($materialId)
|
||||
{
|
||||
return response()->json(MaterialService::storeIntegracaoBnafarMedicamentos($materialId), Response::HTTP_CREATED);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Cadastro;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Services\Cadastro\MaterialBnafarService;
|
||||
|
||||
class MaterialBnafarController extends Controller
|
||||
{
|
||||
public function autocomplete()
|
||||
{
|
||||
$query = MaterialBnafarService::autocomplete();
|
||||
|
||||
return datatables()
|
||||
->of($query)
|
||||
->filterColumn('descricao', function($query, $keyword) {
|
||||
$query->whereRaw(
|
||||
"descricao COLLATE utf8mb4_general_ci LIKE ?",
|
||||
["%{$keyword}%"]
|
||||
);
|
||||
})
|
||||
->make(true);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,275 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Cadastro\Medicamento;
|
||||
|
||||
use App\Enums\Cadastro\Medicamento\FormaFarmaceutica as MedicamentoFormaFarmaceutica;
|
||||
use App\Enums\Cadastro\Medicamento\ViaAdministracao as MedicamentoViaAdministracao;
|
||||
use App\Enums\Cadastro\UnidadeMedida as CadastroUnidadeMedida;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\Cadastro\Medicamento\MedicamentoRequest;
|
||||
use App\Models\Cadastro\Medicamento\FormaFarmaceutica;
|
||||
use App\Models\Cadastro\Medicamento\Medicamento;
|
||||
use App\Models\Cadastro\Medicamento\ReceitaTipo;
|
||||
use App\Models\Cadastro\Medicamento\ViaAdministracao;
|
||||
use App\Models\Cadastro\UnidadeMedida;
|
||||
use App\Utils\DataUtil;
|
||||
use DB;
|
||||
use Illuminate\Http\Response;
|
||||
|
||||
class MedicamentoController extends Controller
|
||||
{
|
||||
protected $modulo = 'cadastro';
|
||||
protected $funcionalidade = 'medicamento';
|
||||
|
||||
public function autocomplete()
|
||||
{
|
||||
$medicamentos = DB::table('cadastro_medicamento')
|
||||
->select(
|
||||
'cadastro_medicamento.id',
|
||||
'cadastro_medicamento.nome',
|
||||
'cadastro_via_administracao.nome AS via_administracao',
|
||||
'via_administracao_id',
|
||||
'cadastro_forma_farmaceutica.nome AS forma_farmaceutica',
|
||||
'forma_farmaceutica_id',
|
||||
'cadastro_unidade_medida.sigla AS unidade_medida',
|
||||
'unidade_medida_id',
|
||||
'receita_tipo_id',
|
||||
'exibir_receita',
|
||||
'exibir_prescricao_interna',
|
||||
)
|
||||
->leftJoin(
|
||||
'cadastro_forma_farmaceutica',
|
||||
'cadastro_forma_farmaceutica.id',
|
||||
'cadastro_medicamento.forma_farmaceutica_id'
|
||||
)
|
||||
->leftJoin(
|
||||
'cadastro_via_administracao',
|
||||
'cadastro_via_administracao.id',
|
||||
'cadastro_medicamento.via_administracao_id'
|
||||
)
|
||||
->leftJoin(
|
||||
'cadastro_unidade_medida',
|
||||
'cadastro_unidade_medida.id',
|
||||
'cadastro_medicamento.unidade_medida_id'
|
||||
)
|
||||
->whereNull('cadastro_medicamento.deleted_at');
|
||||
|
||||
if (DataUtil::isStringTrue(request()->exibir_prescricao_interna)) {
|
||||
|
||||
$medicamentos->where('cadastro_medicamento.exibir_prescricao_interna', '=', 1);
|
||||
}
|
||||
|
||||
if (DataUtil::isStringTrue(request()->exibir_receita)) {
|
||||
|
||||
$medicamentos->where('cadastro_medicamento.exibir_receita', '=', 1);
|
||||
}
|
||||
|
||||
if (is_numeric(request()->query('via_administracao_id'))) {
|
||||
|
||||
$medicamentos->where('via_administracao_id', request()->query('via_administracao_id'));
|
||||
}
|
||||
|
||||
if (is_numeric(request()->query('receita_tipo_id'))) {
|
||||
|
||||
$medicamentos->where('receita_tipo_id', request()->query('receita_tipo_id'));
|
||||
}
|
||||
|
||||
return datatables()->of($medicamentos)->toJson();
|
||||
}
|
||||
|
||||
public function datatable()
|
||||
{
|
||||
$medicamentos = DB::table('cadastro_medicamento')
|
||||
->select(
|
||||
'id',
|
||||
'nome',
|
||||
)
|
||||
->whereNull('cadastro_medicamento.deleted_at');
|
||||
|
||||
return datatables()->of($medicamentos)->skipTotalRecords()->toJson();
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
$this->auth(__FUNCTION__);
|
||||
|
||||
$medicamentos = $this->get(Medicamento::class)->orderBy('nome')->get();
|
||||
|
||||
return response()->json($medicamentos, Response::HTTP_OK);
|
||||
}
|
||||
|
||||
public function create()
|
||||
{
|
||||
$this->auth(__FUNCTION__);
|
||||
|
||||
$medicamento = new Medicamento;
|
||||
$medicamento->fill(array_fill_keys($medicamento->getFillable(), null));
|
||||
|
||||
return response()->json(
|
||||
[
|
||||
'form' => $this->getFormData(),
|
||||
'model' => $medicamento->makeHidden(['id'])
|
||||
],
|
||||
Response::HTTP_OK
|
||||
);
|
||||
}
|
||||
|
||||
public function store(MedicamentoRequest $request)
|
||||
{
|
||||
$this->auth(__FUNCTION__);
|
||||
|
||||
$medicamento = Medicamento::create($this->getParams($request))->fresh();
|
||||
|
||||
return response()->json($medicamento, Response::HTTP_CREATED);
|
||||
}
|
||||
|
||||
public function show($id)
|
||||
{
|
||||
$this->auth(__FUNCTION__);
|
||||
|
||||
return response()->json($this->get(Medicamento::class, $id), Response::HTTP_OK);
|
||||
}
|
||||
|
||||
public function edit($id)
|
||||
{
|
||||
$this->auth(__FUNCTION__);
|
||||
|
||||
$medicamento = Medicamento::findOrFail($id);
|
||||
|
||||
return response()->json(
|
||||
[
|
||||
'form' => $this->getFormData(),
|
||||
'model' => $medicamento->makeHidden(['id'])
|
||||
],
|
||||
Response::HTTP_OK
|
||||
);
|
||||
}
|
||||
|
||||
private function getFormData()
|
||||
{
|
||||
return [
|
||||
'unidades_medida' => $this->getUnidadesMedida(),
|
||||
'vias_administracao' => $this->getViasAdministracao(),
|
||||
'formas_farmaceutica' => $this->getFormasFarmaceuticas(),
|
||||
'tipos_receita' => ReceitaTipo::orderBy('nome')->get(),
|
||||
];
|
||||
}
|
||||
|
||||
private function getUnidadesMedida()
|
||||
{
|
||||
$unidades = [
|
||||
CadastroUnidadeMedida::GOTAS,
|
||||
CadastroUnidadeMedida::GRAMAS,
|
||||
CadastroUnidadeMedida::MILIGRAMAS,
|
||||
CadastroUnidadeMedida::MILILITROS,
|
||||
CadastroUnidadeMedida::UNIDADES,
|
||||
CadastroUnidadeMedida::UNIDADES_INTERNACIONAIS,
|
||||
CadastroUnidadeMedida::DOSE,
|
||||
];
|
||||
|
||||
return UnidadeMedida::whereIn('id', $unidades)->orderBy('nome')->get(['id', 'nome']);
|
||||
}
|
||||
|
||||
private function getViasAdministracao()
|
||||
{
|
||||
$vias = [
|
||||
MedicamentoViaAdministracao::BUCAL,
|
||||
MedicamentoViaAdministracao::CAPILAR,
|
||||
MedicamentoViaAdministracao::DERMATOLOGICA,
|
||||
MedicamentoViaAdministracao::ENDOVENOSA,
|
||||
MedicamentoViaAdministracao::EPIDURAL,
|
||||
MedicamentoViaAdministracao::EXTERNO,
|
||||
MedicamentoViaAdministracao::INALATORIA,
|
||||
MedicamentoViaAdministracao::INALATORIA_POR_VIA_NASAL,
|
||||
MedicamentoViaAdministracao::INALATORIA_POR_VIA_ORAL,
|
||||
MedicamentoViaAdministracao::INTRA_ARTERIAL,
|
||||
MedicamentoViaAdministracao::INTRA_ARTICULAR,
|
||||
MedicamentoViaAdministracao::INTRADERMICA,
|
||||
MedicamentoViaAdministracao::INTRAMUSCULAR,
|
||||
MedicamentoViaAdministracao::INTRATECAL,
|
||||
MedicamentoViaAdministracao::INTRAUTERINA,
|
||||
MedicamentoViaAdministracao::INTRAVENOSA,
|
||||
MedicamentoViaAdministracao::IRRIGACAO,
|
||||
MedicamentoViaAdministracao::LOCAL,
|
||||
MedicamentoViaAdministracao::NASAL,
|
||||
MedicamentoViaAdministracao::OFTALMICA,
|
||||
MedicamentoViaAdministracao::ORAL,
|
||||
MedicamentoViaAdministracao::OTOLOGICA,
|
||||
MedicamentoViaAdministracao::OUTRAS,
|
||||
MedicamentoViaAdministracao::PARENTERAL,
|
||||
MedicamentoViaAdministracao::RETAL,
|
||||
MedicamentoViaAdministracao::SUBCUTANEA,
|
||||
MedicamentoViaAdministracao::SUBLINGUAL,
|
||||
MedicamentoViaAdministracao::TOPICA,
|
||||
MedicamentoViaAdministracao::TRANSDERMICA,
|
||||
MedicamentoViaAdministracao::URETRAL,
|
||||
MedicamentoViaAdministracao::VAGINAL,
|
||||
MedicamentoViaAdministracao::IMPLANTE_SUBDERMICO,
|
||||
];
|
||||
|
||||
return ViaAdministracao::whereIn('id', $vias)->orderBy('nome')->get();
|
||||
}
|
||||
|
||||
private function getFormasFarmaceuticas()
|
||||
{
|
||||
$formas = [
|
||||
MedicamentoFormaFarmaceutica::ADESIVO,
|
||||
MedicamentoFormaFarmaceutica::AEROSSOL,
|
||||
MedicamentoFormaFarmaceutica::CAPSULA,
|
||||
MedicamentoFormaFarmaceutica::CARPULE,
|
||||
MedicamentoFormaFarmaceutica::COLIRIO,
|
||||
MedicamentoFormaFarmaceutica::COMPRIMIDO,
|
||||
MedicamentoFormaFarmaceutica::CREME,
|
||||
MedicamentoFormaFarmaceutica::DRAGEA,
|
||||
MedicamentoFormaFarmaceutica::ELIXIR,
|
||||
MedicamentoFormaFarmaceutica::EMULSAO,
|
||||
MedicamentoFormaFarmaceutica::ENEMA,
|
||||
MedicamentoFormaFarmaceutica::ESMALTE,
|
||||
MedicamentoFormaFarmaceutica::GEL,
|
||||
MedicamentoFormaFarmaceutica::GELEIA,
|
||||
MedicamentoFormaFarmaceutica::GRANULADO,
|
||||
MedicamentoFormaFarmaceutica::LIQUIDO,
|
||||
MedicamentoFormaFarmaceutica::LOCAO,
|
||||
MedicamentoFormaFarmaceutica::OVULO,
|
||||
MedicamentoFormaFarmaceutica::PASTA,
|
||||
MedicamentoFormaFarmaceutica::PASTILHA,
|
||||
MedicamentoFormaFarmaceutica::PO,
|
||||
MedicamentoFormaFarmaceutica::POMADA,
|
||||
MedicamentoFormaFarmaceutica::SABONETE,
|
||||
MedicamentoFormaFarmaceutica::SOLUCAO,
|
||||
MedicamentoFormaFarmaceutica::SPRAY,
|
||||
MedicamentoFormaFarmaceutica::SUPOSITORIO,
|
||||
MedicamentoFormaFarmaceutica::SUSPENSAO,
|
||||
MedicamentoFormaFarmaceutica::UNIDADE,
|
||||
MedicamentoFormaFarmaceutica::TABLETE,
|
||||
MedicamentoFormaFarmaceutica::XAROPE,
|
||||
];
|
||||
|
||||
return FormaFarmaceutica::whereIn('id', $formas)->orderBy('nome')->get();
|
||||
}
|
||||
|
||||
public function update(MedicamentoRequest $request, $id)
|
||||
{
|
||||
$this->auth(__FUNCTION__);
|
||||
|
||||
$medicamento = tap(Medicamento::findOrFail($id))->update($this->getParams($request));
|
||||
|
||||
return response()->json($medicamento->fresh(), Response::HTTP_OK);
|
||||
}
|
||||
|
||||
private function getParams($request)
|
||||
{
|
||||
return $request->all();
|
||||
}
|
||||
|
||||
public function destroy($id)
|
||||
{
|
||||
$this->auth(__FUNCTION__);
|
||||
|
||||
Medicamento::findOrFail($id)->delete();
|
||||
|
||||
return response()->json(null, Response::HTTP_NO_CONTENT);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Cadastro;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Services\Cadastro\MedicamentoNaoPadronizadoService;
|
||||
use Illuminate\Http\Response;
|
||||
|
||||
class MedicamentoNaoPadronizadoController extends Controller
|
||||
{
|
||||
public function autocomplete()
|
||||
{
|
||||
return datatables()->of(MedicamentoNaoPadronizadoService::autocomplete())->make(true);
|
||||
}
|
||||
|
||||
public function store()
|
||||
{
|
||||
return response()->json(MedicamentoNaoPadronizadoService::store(), Response::HTTP_CREATED);
|
||||
}
|
||||
|
||||
public function destroy($id)
|
||||
{
|
||||
return response()->json(MedicamentoNaoPadronizadoService::destroy($id), Response::HTTP_NO_CONTENT);
|
||||
}
|
||||
}
|
||||
76
api/app/Http/Controllers/Cadastro/ObitoController.php
Normal file
76
api/app/Http/Controllers/Cadastro/ObitoController.php
Normal file
@@ -0,0 +1,76 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Cadastro;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Services\Cadastro\ObitoService;
|
||||
use Illuminate\Http\Response;
|
||||
|
||||
class ObitoController extends Controller
|
||||
{
|
||||
protected $modulo = 'cadastro';
|
||||
protected $funcionalidade = 'obito';
|
||||
|
||||
public function create()
|
||||
{
|
||||
$this->auth(__FUNCTION__);
|
||||
|
||||
return response()->json(ObitoService::create(), Response::HTTP_CREATED);
|
||||
}
|
||||
|
||||
public function store()
|
||||
{
|
||||
$this->auth(__FUNCTION__);
|
||||
|
||||
return response()->json(ObitoService::store(), Response::HTTP_CREATED);
|
||||
}
|
||||
|
||||
public function edit($id)
|
||||
{
|
||||
$this->auth(__FUNCTION__);
|
||||
|
||||
return response()->json(ObitoService::edit($id), Response::HTTP_OK);
|
||||
}
|
||||
|
||||
public function update($id)
|
||||
{
|
||||
$this->auth(__FUNCTION__);
|
||||
|
||||
return response()->json(ObitoService::update($id), Response::HTTP_OK);
|
||||
}
|
||||
|
||||
public function destroy($id)
|
||||
{
|
||||
$this->auth(__FUNCTION__);
|
||||
|
||||
ObitoService::destroy($id);
|
||||
|
||||
return response()->noContent();
|
||||
}
|
||||
|
||||
public function datatable()
|
||||
{
|
||||
return datatables()
|
||||
->of(ObitoService::datatable())
|
||||
->filterColumn('cadastro_obito.obito_em', function ($query, $keyword) {
|
||||
$query->whereRaw("DATE_FORMAT(cadastro_obito.obito_em, '%d/%m/%Y') like ?", ["%{$keyword}%"]);
|
||||
})
|
||||
->skipTotalRecords()
|
||||
->toJson();
|
||||
}
|
||||
|
||||
public function autocompleteCidadao()
|
||||
{
|
||||
return datatables()->of(ObitoService::autocompleteCidadao())->toJson();
|
||||
}
|
||||
|
||||
public function autocompleteCid()
|
||||
{
|
||||
return datatables()->of(ObitoService::autocompleteCid())->toJson();
|
||||
}
|
||||
|
||||
public function autocompleteUsuario()
|
||||
{
|
||||
return datatables()->of(ObitoService::autocompleteUsuario())->toJson();
|
||||
}
|
||||
}
|
||||
88
api/app/Http/Controllers/Cadastro/OciController.php
Normal file
88
api/app/Http/Controllers/Cadastro/OciController.php
Normal file
@@ -0,0 +1,88 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Cadastro;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Services\Cadastro\OciService;
|
||||
use App\Utils\MaskUtil;
|
||||
use Illuminate\Http\Response;
|
||||
|
||||
class OciController extends Controller
|
||||
{
|
||||
protected $modulo = 'cadastro';
|
||||
protected $funcionalidade = 'oci';
|
||||
|
||||
public function datatable()
|
||||
{
|
||||
return datatables()
|
||||
->of(OciService::datatable())
|
||||
->filterColumn('procedimento_descricao', function ($query, $keyword) {
|
||||
|
||||
$query
|
||||
->whereRaw("CONCAT(procedimento.codigo, ' - ', procedimento.nome) like ?", ["%{$keyword}%"])
|
||||
->orWhereRaw(
|
||||
"CONCAT(
|
||||
CONCAT(
|
||||
SUBSTR(procedimento_codigo,1,2),
|
||||
'.',
|
||||
SUBSTR(procedimento_codigo,3,2),
|
||||
'.',
|
||||
SUBSTR(procedimento_codigo,5,2),
|
||||
'.',
|
||||
SUBSTR(procedimento_codigo,7,3),
|
||||
'-',
|
||||
SUBSTR(procedimento_codigo,10,1)
|
||||
),
|
||||
' - ',
|
||||
procedimento.nome
|
||||
) like ?",
|
||||
["%{$keyword}%"]
|
||||
);
|
||||
})
|
||||
->addColumn('procedimento_descricao', fn ($oci) =>
|
||||
MaskUtil::getProcedimentoMasked($oci->procedimento_codigo) . " - {$oci->procedimento_nome}")
|
||||
->toJson();
|
||||
}
|
||||
|
||||
public function list()
|
||||
{
|
||||
return response()->json(OciService::list(), Response::HTTP_OK);
|
||||
}
|
||||
|
||||
public function create()
|
||||
{
|
||||
$this->auth(__FUNCTION__);
|
||||
|
||||
return response()->json(OciService::create(), Response::HTTP_OK);
|
||||
}
|
||||
|
||||
public function store()
|
||||
{
|
||||
$this->auth(__FUNCTION__);
|
||||
|
||||
return response()->json(OciService::store(), Response::HTTP_CREATED);
|
||||
}
|
||||
|
||||
public function edit($id)
|
||||
{
|
||||
$this->auth(__FUNCTION__);
|
||||
|
||||
return response()->json(OciService::edit($id), Response::HTTP_OK);
|
||||
}
|
||||
|
||||
public function update($id)
|
||||
{
|
||||
$this->auth(__FUNCTION__);
|
||||
|
||||
return response()->json(OciService::update($id), Response::HTTP_OK);
|
||||
}
|
||||
|
||||
public function destroy($id)
|
||||
{
|
||||
$this->auth(__FUNCTION__);
|
||||
|
||||
OciService::destroy($id);
|
||||
|
||||
return response()->noContent();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Cadastro;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Services\Cadastro\OrigemProgramaticaService;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Response;
|
||||
|
||||
class OrigemProgramaticaController extends Controller
|
||||
{
|
||||
protected $modulo = 'cadastro';
|
||||
protected $funcionalidade = 'origem-programatica';
|
||||
|
||||
public function create()
|
||||
{
|
||||
$this->auth(__FUNCTION__);
|
||||
|
||||
return response()->json(OrigemProgramaticaService::create(), Response::HTTP_OK);
|
||||
}
|
||||
|
||||
public function store(Request $request)
|
||||
{
|
||||
$this->auth(__FUNCTION__);
|
||||
|
||||
return response()->json(OrigemProgramaticaService::store($request), Response::HTTP_CREATED);
|
||||
}
|
||||
|
||||
public function edit($id)
|
||||
{
|
||||
$this->auth(__FUNCTION__);
|
||||
|
||||
return response()->json(OrigemProgramaticaService::edit($id), Response::HTTP_OK);
|
||||
}
|
||||
|
||||
public function update(Request $request, $id)
|
||||
{
|
||||
$this->auth(__FUNCTION__);
|
||||
|
||||
return response()->json(OrigemProgramaticaService::update($request, $id), Response::HTTP_OK);
|
||||
}
|
||||
|
||||
public function destroy($id)
|
||||
{
|
||||
$this->auth(__FUNCTION__);
|
||||
|
||||
return response()->json(OrigemProgramaticaService::destroy($id), Response::HTTP_NO_CONTENT);
|
||||
}
|
||||
|
||||
public function datatable()
|
||||
{
|
||||
return datatables()
|
||||
->of(OrigemProgramaticaService::datatable())
|
||||
->filterColumn('cadastro_origem_programatica.ativo', function ($query, $keyword) {
|
||||
$query->whereRaw("CASE WHEN cadastro_origem_programatica.ativo THEN 'Sim' ELSE 'Não' END LIKE ?", ["%{$keyword}%"]);
|
||||
})
|
||||
->make(true);
|
||||
}
|
||||
|
||||
public function autocomplete()
|
||||
{
|
||||
return datatables()
|
||||
->of(OrigemProgramaticaService::autocomplete())
|
||||
->make(true);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Cadastro\Parametrizacao;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Services\Cadastro\Parametrizacao\ParametrizacaoService;
|
||||
use DB;
|
||||
use Illuminate\Http\Response;
|
||||
|
||||
class ParametrizacaoController extends Controller
|
||||
{
|
||||
protected $modulo = 'cadastro';
|
||||
protected $funcionalidade = 'parametrizacao';
|
||||
|
||||
public function create()
|
||||
{
|
||||
$this->auth(__FUNCTION__);
|
||||
|
||||
return response()->json(ParametrizacaoService::create(), Response::HTTP_CREATED);
|
||||
}
|
||||
|
||||
public function store()
|
||||
{
|
||||
$this->auth(__FUNCTION__);
|
||||
|
||||
return response()->json(ParametrizacaoService::store(), Response::HTTP_CREATED);
|
||||
}
|
||||
|
||||
public function edit($id)
|
||||
{
|
||||
$this->auth(__FUNCTION__);
|
||||
|
||||
return response()->json(ParametrizacaoService::edit($id), Response::HTTP_OK);
|
||||
}
|
||||
|
||||
public function update($id)
|
||||
{
|
||||
$this->auth(__FUNCTION__);
|
||||
|
||||
return response()->json(ParametrizacaoService::update($id), Response::HTTP_OK);
|
||||
}
|
||||
|
||||
public function destroy($id)
|
||||
{
|
||||
$this->auth(__FUNCTION__);
|
||||
|
||||
return response()->json(ParametrizacaoService::destroy($id), Response::HTTP_NO_CONTENT);
|
||||
}
|
||||
|
||||
public function getInfraestruturas()
|
||||
{
|
||||
return response()->json(ParametrizacaoService::getInfraestruturas(), Response::HTTP_OK);
|
||||
}
|
||||
|
||||
public function getUsuarios()
|
||||
{
|
||||
return response()->json(ParametrizacaoService::getUsuarios(), Response::HTTP_OK);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Cadastro;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Services\Cadastro\RelatorioMaterialService;
|
||||
use Illuminate\Http\Response;
|
||||
|
||||
class RelatorioMaterialController extends Controller
|
||||
{
|
||||
protected $modulo = 'cadastro';
|
||||
protected $funcionalidade = 'relatorio-material';
|
||||
|
||||
public function index()
|
||||
{
|
||||
$this->auth(__FUNCTION__);
|
||||
|
||||
return response()->json(RelatorioMaterialService::index(), Response::HTTP_OK);
|
||||
}
|
||||
|
||||
public function create()
|
||||
{
|
||||
return response()->json(RelatorioMaterialService::create(), Response::HTTP_OK);
|
||||
}
|
||||
|
||||
public function list()
|
||||
{
|
||||
return response()->json(RelatorioMaterialService::list(), Response::HTTP_OK);
|
||||
}
|
||||
|
||||
public function autocomplete()
|
||||
{
|
||||
return datatables()->of(RelatorioMaterialService::autocomplete())->make(true);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Cadastro;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Services\Cadastro\RelatorioPacienteBairroService;
|
||||
use Illuminate\Http\Response;
|
||||
|
||||
class RelatorioPacienteBairroController extends Controller
|
||||
{
|
||||
protected $modulo = 'cadastro';
|
||||
protected $funcionalidade = 'relatorio-paciente-bairro';
|
||||
|
||||
public function index()
|
||||
{
|
||||
$this->auth(__FUNCTION__);
|
||||
|
||||
return response()->json(RelatorioPacienteBairroService::index(), Response::HTTP_OK);
|
||||
}
|
||||
|
||||
public function list()
|
||||
{
|
||||
return response()->json(RelatorioPacienteBairroService::list(), Response::HTTP_OK);
|
||||
}
|
||||
|
||||
public function autocompletePaciente()
|
||||
{
|
||||
return datatables()
|
||||
->of(RelatorioPacienteBairroService::autocompletePaciente())
|
||||
->filterColumn('paciente.prontuario', function ($query, $keyword) {
|
||||
|
||||
$query->whereRaw("LPAD(paciente.prontuario, 7, 0) like ?", ["%{$keyword}%"]);
|
||||
})
|
||||
->toJson();
|
||||
}
|
||||
|
||||
public function autocompleteLogradouro()
|
||||
{
|
||||
return datatables()
|
||||
->of(RelatorioPacienteBairroService::autocompleteLogradouro())
|
||||
->toJson();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Cadastro;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Services\Cadastro\RelatorioUsuarioService;
|
||||
use Illuminate\Http\Response;
|
||||
|
||||
class RelatorioUsuarioController extends Controller
|
||||
{
|
||||
protected $modulo = 'cadastro';
|
||||
protected $funcionalidade = 'relatorio-usuario';
|
||||
|
||||
public function index()
|
||||
{
|
||||
$this->auth(__FUNCTION__);
|
||||
|
||||
return response()->json(RelatorioUsuarioService::index(), Response::HTTP_OK);
|
||||
}
|
||||
|
||||
public function list()
|
||||
{
|
||||
return response()->json(RelatorioUsuarioService::list(), Response::HTTP_OK);
|
||||
}
|
||||
|
||||
public function autocompleteUsuario()
|
||||
{
|
||||
return datatables()
|
||||
->of(RelatorioUsuarioService::autocompleteUsuario())
|
||||
->filterColumn('cidadao.data_nascimento', function ($query, $keyword) {
|
||||
|
||||
$query->whereRaw("DATE_FORMAT(cidadao.data_nascimento, '%d/%m/%Y') like ?", ["%{$keyword}%"]);
|
||||
})
|
||||
->filterColumn('cidadao.cpf', function ($query, $keyword) {
|
||||
|
||||
$query
|
||||
->whereRaw("cidadao.cpf like ?", ["%{$keyword}%"])
|
||||
->orWhereRaw(
|
||||
"CONCAT(
|
||||
SUBSTR(cidadao.cpf, 1, 3),
|
||||
'.',
|
||||
SUBSTR(cidadao.cpf, 4, 3),
|
||||
'.',
|
||||
SUBSTR(cidadao.cpf, 7, 3),
|
||||
'-',
|
||||
SUBSTR(cidadao.cpf, 10, 2)
|
||||
) like ?",
|
||||
["%{$keyword}%"]
|
||||
);
|
||||
})
|
||||
->toJson();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Cadastro;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Services\Cadastro\ServicoManutencaoService;
|
||||
use Illuminate\Http\Response;
|
||||
|
||||
class ServicoManutencaoController extends Controller
|
||||
{
|
||||
protected $modulo = 'cadastro';
|
||||
protected $funcionalidade = 'servico-manutencao';
|
||||
|
||||
public function datatable()
|
||||
{
|
||||
return datatables()
|
||||
->of(ServicoManutencaoService::datatable())
|
||||
->toJson();
|
||||
}
|
||||
|
||||
public function create()
|
||||
{
|
||||
$this->auth(__FUNCTION__);
|
||||
|
||||
return response()->json(ServicoManutencaoService::create(), Response::HTTP_CREATED);
|
||||
}
|
||||
|
||||
public function list()
|
||||
{
|
||||
$this->auth(__FUNCTION__);
|
||||
|
||||
return response()->json(ServicoManutencaoService::list(), Response::HTTP_OK);
|
||||
}
|
||||
|
||||
public function store()
|
||||
{
|
||||
$this->auth(__FUNCTION__);
|
||||
|
||||
return response()->json(ServicoManutencaoService::store(), Response::HTTP_CREATED);
|
||||
}
|
||||
|
||||
public function edit($id)
|
||||
{
|
||||
$this->auth(__FUNCTION__);
|
||||
|
||||
return response()->json(ServicoManutencaoService::edit($id), Response::HTTP_OK);
|
||||
}
|
||||
|
||||
public function update($id)
|
||||
{
|
||||
$this->auth(__FUNCTION__);
|
||||
|
||||
return response()->json(ServicoManutencaoService::update($id), Response::HTTP_OK);
|
||||
}
|
||||
|
||||
public function destroy($id)
|
||||
{
|
||||
$this->auth(__FUNCTION__);
|
||||
|
||||
return response()->json(ServicoManutencaoService::destroy($id), Response::HTTP_NO_CONTENT);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Cadastro\Subgrupo;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Services\Cadastro\Subgrupo\SubgrupoService;
|
||||
use DB;
|
||||
use Illuminate\Http\Response;
|
||||
|
||||
class SubgrupoController extends Controller
|
||||
{
|
||||
protected $modulo = 'cadastro';
|
||||
protected $funcionalidade = 'subgrupo';
|
||||
|
||||
public function datatable()
|
||||
{
|
||||
return datatables()->of(SubgrupoService::datatable())->skipTotalRecords()->toJson();
|
||||
}
|
||||
|
||||
public function create()
|
||||
{
|
||||
$this->auth(__FUNCTION__);
|
||||
|
||||
return response()->json(SubgrupoService::create(), Response::HTTP_CREATED);
|
||||
}
|
||||
|
||||
public function store()
|
||||
{
|
||||
$this->auth(__FUNCTION__);
|
||||
|
||||
return response()->json(SubgrupoService::store(), Response::HTTP_CREATED);
|
||||
}
|
||||
|
||||
public function edit($id)
|
||||
{
|
||||
$this->auth(__FUNCTION__);
|
||||
|
||||
return response()->json(SubgrupoService::edit($id), Response::HTTP_OK);
|
||||
}
|
||||
|
||||
public function update($id)
|
||||
{
|
||||
$this->auth(__FUNCTION__);
|
||||
|
||||
return response()->json(SubgrupoService::update($id), Response::HTTP_OK);
|
||||
}
|
||||
|
||||
public function destroy($id)
|
||||
{
|
||||
$this->auth(__FUNCTION__);
|
||||
|
||||
return response()->json(SubgrupoService::destroy($id), Response::HTTP_NO_CONTENT);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,131 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Cadastro\SujeitoAtencao;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\Cadastro\SujeitoAtencao\AlergiaRequest;
|
||||
use App\Models\Cadastro\SujeitoAtencao\Alergia;
|
||||
use App\Models\Cadastro\SujeitoAtencao\AlergiaTipo;
|
||||
use Illuminate\Http\Response;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class AlergiaController extends Controller
|
||||
{
|
||||
protected $modulo = 'cadastro';
|
||||
protected $funcionalidade = 'alergia';
|
||||
|
||||
public function index()
|
||||
{
|
||||
$this->auth(__FUNCTION__);
|
||||
|
||||
$alergias = $this->get(Alergia::class)->orderBy('agente_substancia_especifica')->get();
|
||||
|
||||
return response()->json($alergias, Response::HTTP_OK);
|
||||
}
|
||||
|
||||
public function create()
|
||||
{
|
||||
$this->auth(__FUNCTION__);
|
||||
|
||||
return response()->json(
|
||||
[
|
||||
'form' => $this->getFormData(),
|
||||
],
|
||||
Response::HTTP_OK
|
||||
);
|
||||
}
|
||||
|
||||
public function store(AlergiaRequest $request)
|
||||
{
|
||||
$this->auth(__FUNCTION__);
|
||||
|
||||
$alergia = Alergia::create($this->prepareData($request->all()));
|
||||
|
||||
return response()->json($alergia->fresh(), Response::HTTP_CREATED);
|
||||
}
|
||||
|
||||
public function show($id)
|
||||
{
|
||||
$this->auth(__FUNCTION__);
|
||||
|
||||
return response()->json($this->get(Alergia::class, $id), Response::HTTP_OK);
|
||||
}
|
||||
|
||||
public function edit($id)
|
||||
{
|
||||
$this->auth(__FUNCTION__);
|
||||
|
||||
$alergia = Alergia::findOrFail($id);
|
||||
|
||||
return response()->json(
|
||||
[
|
||||
'form' => $this->getFormData(),
|
||||
'model' => [
|
||||
'tipo_id' => $alergia->tipo_id,
|
||||
'agente_substancia_especifica' => $alergia->agente_substancia_especifica,
|
||||
],
|
||||
],
|
||||
Response::HTTP_OK
|
||||
);
|
||||
}
|
||||
|
||||
private function getFormData()
|
||||
{
|
||||
return [
|
||||
'tipos' => AlergiaTipo::orderBy('descricao')->get(),
|
||||
];
|
||||
}
|
||||
|
||||
public function update(AlergiaRequest $request, $id)
|
||||
{
|
||||
$this->auth(__FUNCTION__);
|
||||
|
||||
$alergia = tap(Alergia::findOrFail($id))->update($this->prepareData($request->all()));
|
||||
|
||||
return response()->json($alergia->fresh(), Response::HTTP_OK);
|
||||
}
|
||||
|
||||
public function prepareData($params)
|
||||
{
|
||||
return [
|
||||
'tipo_id' => $params['tipo_id'],
|
||||
'agente_substancia_especifica' => mb_strtoupper($params['agente_substancia_especifica']),
|
||||
];
|
||||
}
|
||||
|
||||
public function destroy($id)
|
||||
{
|
||||
$this->auth(__FUNCTION__);
|
||||
|
||||
Alergia::findOrFail($id)->delete();
|
||||
|
||||
return response()->json(null, Response::HTTP_NO_CONTENT);
|
||||
}
|
||||
|
||||
public function datatable()
|
||||
{
|
||||
$status = DB::table('cadastro_alergia')
|
||||
->join('cadastro_alergia_tipo', 'cadastro_alergia_tipo.id', 'cadastro_alergia.tipo_id')
|
||||
->select(
|
||||
'cadastro_alergia.id',
|
||||
'cadastro_alergia.agente_substancia_especifica',
|
||||
'cadastro_alergia.tipo_id',
|
||||
'cadastro_alergia_tipo.descricao AS tipo_descricao',
|
||||
)
|
||||
->whereNull('cadastro_alergia.deleted_at');
|
||||
|
||||
return datatables()->of($status)->skipTotalRecords()->make(true);
|
||||
}
|
||||
|
||||
public function autocomplete()
|
||||
{
|
||||
$alergias = Alergia::with('tipo');
|
||||
|
||||
if (is_numeric(request()->tipo_id)) {
|
||||
|
||||
$alergias->where('tipo_id', request()->tipo_id);
|
||||
}
|
||||
|
||||
return datatables()->of($alergias)->make(true);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
<?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);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,94 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Cadastro\SujeitoAtencao;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\Cadastro\SujeitoAtencao\ConvenioMedicoRequest;
|
||||
use App\Models\Cadastro\SujeitoAtencao\ConvenioMedico;
|
||||
use Illuminate\Http\Response;
|
||||
|
||||
class ConvenioMedicoController extends Controller
|
||||
{
|
||||
protected $modulo = 'cadastro';
|
||||
protected $funcionalidade = 'convenio-medico';
|
||||
|
||||
public function datatable()
|
||||
{
|
||||
$conveniosMedico = ConvenioMedico::with([]);
|
||||
|
||||
return datatables()->of($conveniosMedico)->skipTotalRecords()->toJson();
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
$this->auth(__FUNCTION__);
|
||||
|
||||
$conveniosMedico = $this->get(ConvenioMedico::class)->orderBy('nome')->get();
|
||||
|
||||
return response()->json($conveniosMedico, Response::HTTP_OK);
|
||||
}
|
||||
|
||||
public function store(ConvenioMedicoRequest $request)
|
||||
{
|
||||
$this->auth(__FUNCTION__);
|
||||
|
||||
$convenioMedico = ConvenioMedico::create($this->getParams($request));
|
||||
|
||||
return response()->json($convenioMedico, Response::HTTP_CREATED);
|
||||
}
|
||||
|
||||
public function show($id)
|
||||
{
|
||||
$this->auth(__FUNCTION__);
|
||||
|
||||
return response()->json($this->get(ConvenioMedico::class, $id), Response::HTTP_OK);
|
||||
}
|
||||
|
||||
public function edit($id)
|
||||
{
|
||||
$this->auth(__FUNCTION__);
|
||||
|
||||
$convenioMedico = ConvenioMedico::findOrFail($id);
|
||||
|
||||
return response()->json(
|
||||
[
|
||||
'model' => [
|
||||
'nome' => $convenioMedico->nome,
|
||||
],
|
||||
],
|
||||
Response::HTTP_OK
|
||||
);
|
||||
}
|
||||
|
||||
public function update(ConvenioMedicoRequest $request, $id)
|
||||
{
|
||||
$this->auth(__FUNCTION__);
|
||||
|
||||
$convenioMedico = tap(ConvenioMedico::findOrFail($id))->update($this->getParams($request));
|
||||
|
||||
return response()->json($convenioMedico->fresh(), Response::HTTP_OK);
|
||||
}
|
||||
|
||||
private function getParams($request)
|
||||
{
|
||||
return [
|
||||
'nome' => mb_strtoupper($request->nome)
|
||||
];
|
||||
}
|
||||
|
||||
public function destroy($id)
|
||||
{
|
||||
$this->auth(__FUNCTION__);
|
||||
|
||||
ConvenioMedico::findOrFail($id)->delete();
|
||||
|
||||
return response()->json(null, Response::HTTP_NO_CONTENT);
|
||||
}
|
||||
|
||||
public function autocomplete()
|
||||
{
|
||||
$conveniosMedico = ConvenioMedico::with([]);
|
||||
|
||||
return datatables()->of($conveniosMedico)->toJson();
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,568 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Cadastro\SujeitoAtencao;
|
||||
|
||||
use App\Enums\Cadastro\SujeitoAtencao\TipoRegistroUsuario;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\Cadastro\SujeitoAtencao\UsuarioRequest;
|
||||
use App\Mail\UsuarioLogin;
|
||||
use App\Models\Cadastro\Estabelecimento\Unidade;
|
||||
use App\Models\Cadastro\Parametrizacao\ParametrizacaoPermissaoOcupacao;
|
||||
use App\Models\Cadastro\SujeitoAtencao\Lotacao;
|
||||
use App\Models\Cadastro\SujeitoAtencao\Sexo;
|
||||
use App\Models\Cadastro\SujeitoAtencao\Usuario;
|
||||
use App\Models\Cadastro\SujeitoAtencao\UsuarioAssinatura;
|
||||
use App\Models\Cadastro\SujeitoAtencao\UsuarioHistoricoAcesso;
|
||||
use App\Models\Cadastro\SujeitoAtencao\UsuarioRegistroTipo;
|
||||
use App\Models\Cns\TermoInvalido;
|
||||
use App\Models\Intranet\Estado;
|
||||
use App\Services\Cadastro\SujeitoAtencao\CidadaoService;
|
||||
use App\Services\Cadastro\SujeitoAtencao\UsuarioService;
|
||||
use App\Services\Integracao\IntegracaoCidadaoService;
|
||||
use App\Utils\DataUtil;
|
||||
use App\Utils\Email;
|
||||
use App\Utils\Senha;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Response;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class UsuarioController extends Controller
|
||||
{
|
||||
protected $modulo = 'cadastro';
|
||||
protected $funcionalidade = 'usuario';
|
||||
|
||||
public static function datatable()
|
||||
{
|
||||
$showNaoRegularizados = DataUtil::isStringBoolean(request()->get('showNaoRegularizados'))
|
||||
&& DataUtil::getBooleanValueFromStringBoolean(request()->get('showNaoRegularizados'));
|
||||
|
||||
$usuarios = DB::table('cadastro_usuario')
|
||||
->select(
|
||||
'cadastro_usuario.id',
|
||||
'cadastro_cidadao.nome',
|
||||
'cadastro_cidadao.cpf',
|
||||
'cadastro_cidadao.cns',
|
||||
'cadastro_usuario.bloqueado',
|
||||
DB::raw('
|
||||
DATE_FORMAT(cadastro_cidadao.data_nascimento, "%d/%m/%Y") as data_nascimento
|
||||
'),
|
||||
'cadastro_usuario.email',
|
||||
DB::raw("
|
||||
(
|
||||
SELECT TRUE
|
||||
FROM cadastro_obito
|
||||
WHERE cadastro_obito.cidadao_id = cadastro_cidadao.id
|
||||
AND cadastro_obito.deleted_at IS NULL
|
||||
LIMIT 1
|
||||
) AS obito
|
||||
")
|
||||
)
|
||||
->join('cadastro_cidadao', 'cadastro_cidadao.id', 'cadastro_usuario.cidadao_id')
|
||||
->whereNull('cadastro_usuario.deleted_at')
|
||||
->when($showNaoRegularizados, function ($query) {
|
||||
|
||||
$query->whereNull('cadastro_cidadao.cns');
|
||||
})
|
||||
->when(!$showNaoRegularizados, function ($query) {
|
||||
|
||||
$query->whereNotNull('cadastro_cidadao.cns');
|
||||
});
|
||||
|
||||
return datatables()
|
||||
->of($usuarios)
|
||||
->filterColumn('cadastro_cidadao.cpf', function ($query, $keyword) {
|
||||
|
||||
$query
|
||||
->whereRaw("cadastro_cidadao.cpf like ?", ["%{$keyword}%"])
|
||||
->orWhereRaw(
|
||||
"CONCAT(
|
||||
SUBSTR(cadastro_cidadao.cpf,1,3),
|
||||
'.',
|
||||
SUBSTR(cadastro_cidadao.cpf,4,3),
|
||||
'.',
|
||||
SUBSTR(cadastro_cidadao.cpf,7,3),
|
||||
'-',
|
||||
SUBSTR(cadastro_cidadao.cpf,10,2)
|
||||
) like ?",
|
||||
["%{$keyword}%"]
|
||||
);
|
||||
})
|
||||
->skipTotalRecords()
|
||||
->toJson();
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
$this->auth(__FUNCTION__);
|
||||
|
||||
$usuarios = $this->get(Usuario::class)->get();
|
||||
|
||||
return response()->json($usuarios, Response::HTTP_OK);
|
||||
}
|
||||
|
||||
public function create()
|
||||
{
|
||||
$this->auth(__FUNCTION__);
|
||||
|
||||
return response()->json(
|
||||
[
|
||||
'form' => $this->getFormData(),
|
||||
],
|
||||
Response::HTTP_OK
|
||||
);
|
||||
}
|
||||
|
||||
public function store(UsuarioRequest $request)
|
||||
{
|
||||
$this->auth(__FUNCTION__);
|
||||
|
||||
$usuario = $this->save($request->all());
|
||||
|
||||
return response()->json($usuario->fresh(), Response::HTTP_CREATED);
|
||||
}
|
||||
|
||||
public function assinatura(Request $request)
|
||||
{
|
||||
return response()->json(UsuarioService::assinatura($request), Response::HTTP_CREATED);
|
||||
}
|
||||
|
||||
public function destroyAssinatura($id)
|
||||
{
|
||||
return response()->json(UsuarioService::destroyAssinatura($id), Response::HTTP_NO_CONTENT);
|
||||
}
|
||||
|
||||
public function loadAssinatura($id)
|
||||
{
|
||||
|
||||
return response()->json(
|
||||
[
|
||||
'form' => [],
|
||||
'model' => [
|
||||
'assinatura' => UsuarioAssinatura::where('usuario_id', $id)
|
||||
->get()
|
||||
->map(fn ($unidade) => [
|
||||
'id' => $unidade->id ?? null,
|
||||
'arquivo' => $unidade->arquivo ?? null,
|
||||
])
|
||||
->values(),
|
||||
],
|
||||
],
|
||||
Response::HTTP_OK
|
||||
);
|
||||
}
|
||||
|
||||
public function downloadAssinatura($id)
|
||||
{
|
||||
|
||||
$response = UsuarioService::downloadAssinatura($id);
|
||||
|
||||
$headers = [
|
||||
'Content-Type' => 'application/png',
|
||||
];
|
||||
|
||||
return response()->download($response['arquivo'], $response['nome'], $headers);
|
||||
}
|
||||
|
||||
public function show($id)
|
||||
{
|
||||
$this->auth(__FUNCTION__);
|
||||
|
||||
$usuario = $this->get(Usuario::class, $id);
|
||||
|
||||
if (request()->query('with') && $this->hasRelationOnWith('lotacoes.infraestrutura.unidade')) {
|
||||
|
||||
$usuario->lotacoes->each(fn ($l) => $l->infraestrutura->makeVisible('unidade'));
|
||||
}
|
||||
|
||||
return response()->json($usuario, Response::HTTP_OK);
|
||||
}
|
||||
|
||||
private function hasRelationOnWith($relation)
|
||||
{
|
||||
$with = request()->query('with');
|
||||
|
||||
return (is_array($with) && in_array($relation, $with))
|
||||
|| (is_string($with) && $with === $relation);
|
||||
}
|
||||
|
||||
public function edit($id)
|
||||
{
|
||||
$this->auth(__FUNCTION__);
|
||||
|
||||
$usuario = Usuario::findOrFail($id);
|
||||
|
||||
return response()->json(
|
||||
[
|
||||
'form' => array_merge(
|
||||
['cidadao' => CidadaoService::edit($usuario->cidadao_id)['form']],
|
||||
$this->getFormData()
|
||||
),
|
||||
'model' => [
|
||||
'documentos' => [
|
||||
'conselho_profissional' => [
|
||||
'registro_tipo_id' => $usuario->registro_tipo_id,
|
||||
'registro_tipo_outro' => $usuario->registro_tipo_outro,
|
||||
'registro_numero' => $usuario->registro_numero,
|
||||
'registro_estado_id' => $usuario->registro_estado_id,
|
||||
],
|
||||
],
|
||||
'lotacoes' => $usuario->lotacoes->map(fn ($lotacao) => [
|
||||
'id' => $lotacao->id,
|
||||
'unidade_id' => $lotacao->infraestrutura->unidade_id,
|
||||
'unidade_nome' => $lotacao->infraestrutura->unidade->nome_fantasia,
|
||||
'infraestrutura_id' => $lotacao->infraestrutura_id,
|
||||
'infraestrutura_nome' => $lotacao->infraestrutura->nome,
|
||||
'ocupacao' => $lotacao->ocupacao,
|
||||
'realiza_atendimento' => $lotacao->realiza_atendimento,
|
||||
'disabled' => !$lotacao->is_allowed_to_delete,
|
||||
'principal' => $lotacao->principal,
|
||||
'ativo' => $lotacao->ativo,
|
||||
'centros_custo' => $lotacao->centrosCusto->map(fn ($centroCusto) => [
|
||||
'id' => $centroCusto->id,
|
||||
'nome' => $centroCusto->setor->nome,
|
||||
]),
|
||||
]),
|
||||
'email' => $usuario->email,
|
||||
'usuario' => $usuario->usuario,
|
||||
'cidadao' => array_merge([
|
||||
'id' => $usuario->cidadao_id,
|
||||
], CidadaoService::edit($usuario->cidadao_id)['model']),
|
||||
],
|
||||
],
|
||||
Response::HTTP_OK
|
||||
);
|
||||
}
|
||||
|
||||
private function getFormData()
|
||||
{
|
||||
|
||||
return [
|
||||
'termos_invalidos' => TermoInvalido::all()->map(fn ($termo) => $termo->descricao),
|
||||
'data_atual' => Carbon::now()->format('d/m/Y'),
|
||||
'is_permissao_endereco' => true,
|
||||
'documentos' => [
|
||||
'conselho_profissional' => [
|
||||
'tipos_registro' => UsuarioRegistroTipo::orderBy('descricao')->get()->map(fn ($tipo) => [
|
||||
'id' => $tipo->id,
|
||||
'descricao' => $tipo->sigla ? "{$tipo->sigla} - {$tipo->descricao}" : $tipo->descricao
|
||||
]),
|
||||
'estados' => Estado::orderBy('nome')->get()->map(fn ($estado) => [
|
||||
'id' => $estado->id,
|
||||
'uf' => $estado->uf
|
||||
]),
|
||||
],
|
||||
],
|
||||
'lotacao' => [
|
||||
'unidades' => Unidade::orderBy('nome_fantasia')->get()->map(fn ($unidade) => [
|
||||
'id' => $unidade->id,
|
||||
'nome_fantasia' => $unidade->nome_fantasia,
|
||||
'infraestruturas' => $unidade->infraestruturas->sortBy('nome')->map(fn ($infraestrutura) => [
|
||||
'id' => $infraestrutura->id,
|
||||
'nome' => $infraestrutura->nome,
|
||||
])->values()
|
||||
]),
|
||||
],
|
||||
'sexos' => Sexo::orderBy('descricao')->get()->map(fn ($sexo) => [
|
||||
'id' => $sexo->id,
|
||||
'descricao' => $sexo->descricao
|
||||
]),
|
||||
];
|
||||
}
|
||||
|
||||
public function update(UsuarioRequest $request, $id)
|
||||
{
|
||||
$this->auth(__FUNCTION__);
|
||||
|
||||
$usuario = $this->save($request->all(), (Usuario::findOrFail($id))->id);
|
||||
|
||||
return response()->json($usuario->fresh(), Response::HTTP_OK);
|
||||
}
|
||||
|
||||
private function save($params, $id = null)
|
||||
{
|
||||
$usuario = null;
|
||||
|
||||
DB::transaction(function () use (&$usuario, $params, $id) {
|
||||
|
||||
$cidadao = CidadaoService::save($params['cidadao']);
|
||||
|
||||
$data = $this->getPreparedData($params, $id);
|
||||
$data['cidadao_id'] = $cidadao->id;
|
||||
|
||||
$usuario = Usuario::updateOrCreate(
|
||||
['id' => $id],
|
||||
$data
|
||||
);
|
||||
|
||||
$this->deleteLotacoesNotPresent($usuario, $data['lotacoes']);
|
||||
$this->saveLotacoes($usuario, $data['lotacoes']);
|
||||
|
||||
if ($usuario !== null && $id === null && !empty($data['email'])) {
|
||||
|
||||
$object = new \stdClass();
|
||||
$object->user = $usuario->usuario;
|
||||
$object->password = $data['senha'];
|
||||
$object->cliente = request()->header('customer');
|
||||
|
||||
Email::enviar($data['email'], new UsuarioLogin($object));
|
||||
}
|
||||
|
||||
if (!$params['cidadao']['cadastro_simplificado']) {
|
||||
|
||||
IntegracaoCidadaoService::integrar($cidadao->id, 'usuario');
|
||||
IntegracaoCidadaoService::integrar($cidadao->id, 'paciente');
|
||||
}
|
||||
});
|
||||
|
||||
return $usuario;
|
||||
}
|
||||
|
||||
private function getPreparedData($params, $id = null)
|
||||
{
|
||||
$partName = Str::substr(preg_replace('/\s+/', '', $params['cidadao']['nome']), -3);
|
||||
$partTimestamp = Str::substr(Carbon::now()->timestamp, -6);
|
||||
|
||||
$usuario = $params['cidadao']['cadastro_simplificado']
|
||||
? "{$partName}{$partTimestamp}"
|
||||
: $params['usuario'];
|
||||
|
||||
$data = [
|
||||
'registro_tipo_id' => $params['documentos']['conselho_profissional']['registro_tipo_id'] ?? null,
|
||||
'registro_tipo_outro' => $params['documentos']['conselho_profissional']['registro_tipo_outro'] ?? null,
|
||||
'registro_numero' => $params['documentos']['conselho_profissional']['registro_numero'] ?? null,
|
||||
'registro_estado_id' => $params['documentos']['conselho_profissional']['registro_estado_id'] ?? null,
|
||||
'email' => $params['email'] ?? null,
|
||||
'usuario' => $usuario,
|
||||
'lotacoes' => $params['lotacoes'] ?? [],
|
||||
];
|
||||
|
||||
if ($id === null) {
|
||||
|
||||
$data['senha'] = Senha::gerar();
|
||||
$data['troca_senha'] = true;
|
||||
}
|
||||
|
||||
if ($data['registro_tipo_id'] !== TipoRegistroUsuario::OUTRO) {
|
||||
|
||||
$data['registro_tipo_outro'] = null;
|
||||
}
|
||||
|
||||
if (is_string($data['registro_tipo_outro'])) {
|
||||
|
||||
$data['registro_tipo_outro'] = mb_strtoupper($data['registro_tipo_outro']);
|
||||
}
|
||||
|
||||
if (is_string($data['registro_numero'])) {
|
||||
|
||||
$data['registro_numero'] = mb_strtoupper($data['registro_numero']);
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
private function deleteLotacoesNotPresent($usuario, $lotacoes)
|
||||
{
|
||||
$ids = collect($lotacoes)->pluck('id')->filter(fn ($id) => !is_null($id))->toArray();
|
||||
|
||||
Lotacao::destroy($usuario->lotacoes()->whereNotIn('id', $ids)->pluck('id'));
|
||||
}
|
||||
|
||||
private function saveLotacoes($usuario, $lotacoes)
|
||||
{
|
||||
foreach ($lotacoes as $lotacaoData) {
|
||||
$lotacao = $usuario->lotacoes()->updateOrCreate(
|
||||
['id' => $lotacaoData['id'] ?? null],
|
||||
$lotacaoData
|
||||
);
|
||||
|
||||
$lotacao->centrosCusto()->sync($lotacaoData['centros_custo'] ?? []);
|
||||
}
|
||||
}
|
||||
|
||||
public function destroy($id)
|
||||
{
|
||||
$this->auth(__FUNCTION__);
|
||||
|
||||
Usuario::findOrFail($id)->delete();
|
||||
|
||||
return response()->json(null, Response::HTTP_NO_CONTENT);
|
||||
}
|
||||
|
||||
public function gerarSenha($id)
|
||||
{
|
||||
$this->auth(__FUNCTION__);
|
||||
|
||||
$usuario = Usuario::findOrFail($id);
|
||||
|
||||
if ($usuario) {
|
||||
$senha = Senha::gerar();
|
||||
|
||||
$params = [
|
||||
'senha' => $senha,
|
||||
'troca_senha' => true,
|
||||
];
|
||||
|
||||
$usuario->update($params);
|
||||
|
||||
$object = new \stdClass();
|
||||
$object->user = $usuario->usuario;
|
||||
$object->password = $senha;
|
||||
$object->cliente = request()->header('customer');
|
||||
|
||||
Email::enviar($usuario->email, new UsuarioLogin($object));
|
||||
}
|
||||
|
||||
return response()->json($usuario->fresh(), Response::HTTP_OK);
|
||||
}
|
||||
|
||||
public function bloquear($id)
|
||||
{
|
||||
$this->auth(__FUNCTION__);
|
||||
|
||||
$usuario = Usuario::findOrFail($id);
|
||||
|
||||
$usuario->update(['bloqueado' => true]);
|
||||
|
||||
return response()->json($usuario->fresh(), Response::HTTP_OK);
|
||||
}
|
||||
|
||||
public function desbloquear($id)
|
||||
{
|
||||
$this->auth(__FUNCTION__);
|
||||
|
||||
$usuario = Usuario::findOrFail($id);
|
||||
|
||||
$usuario->update(['bloqueado' => false]);
|
||||
|
||||
UsuarioHistoricoAcesso::where('usuario_id', $usuario->id)->update(['ativo' => false]);
|
||||
|
||||
return response()->json($usuario->fresh(), Response::HTTP_OK);
|
||||
}
|
||||
|
||||
public function autocomplete()
|
||||
{
|
||||
return datatables()->of(UsuarioService::autocomplete())->toJson();
|
||||
}
|
||||
|
||||
public function lotacoes($id, Request $request)
|
||||
{
|
||||
if(!$id) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$data = Lotacao::where('usuario_id', $id)
|
||||
->get()
|
||||
->map(fn ($lotacao) => [
|
||||
'id' => $lotacao->id,
|
||||
'unidade' => $lotacao->infraestrutura->nome,
|
||||
'codigo' => $lotacao->ocupacao->codigo,
|
||||
'ocupacao' => $lotacao->ocupacao->nome,
|
||||
]);
|
||||
|
||||
return response()->json($data, Response::HTTP_OK);
|
||||
}
|
||||
|
||||
public static function getEquipes(){
|
||||
|
||||
return DB::table('atencao_basica_parametrizacao_equipe_usuario')
|
||||
->select([
|
||||
'atencao_basica_parametrizacao_equipe.id AS id',
|
||||
DB::raw("
|
||||
CONCAT(
|
||||
CASE
|
||||
WHEN atencao_basica_parametrizacao_area.numero_ine IS NOT NULL THEN CONCAT('INE: ', atencao_basica_parametrizacao_area.numero_ine)
|
||||
ELSE ''
|
||||
END,
|
||||
CASE
|
||||
WHEN atencao_basica_parametrizacao_area.descricao IS NOT NULL AND atencao_basica_parametrizacao_area.numero_ine IS NOT NULL THEN ' - Área: '
|
||||
WHEN atencao_basica_parametrizacao_area.descricao IS NOT NULL THEN 'Área: '
|
||||
ELSE ''
|
||||
END,
|
||||
COALESCE(atencao_basica_parametrizacao_area.descricao, ''),
|
||||
CASE
|
||||
WHEN atencao_basica_parametrizacao_microarea.descricao IS NOT NULL AND (atencao_basica_parametrizacao_area.numero_ine IS NOT NULL OR atencao_basica_parametrizacao_area.descricao IS NOT NULL) THEN ' - Microárea: '
|
||||
WHEN atencao_basica_parametrizacao_microarea.descricao IS NOT NULL THEN 'Microárea: '
|
||||
ELSE ''
|
||||
END,
|
||||
COALESCE(atencao_basica_parametrizacao_microarea.descricao, '')
|
||||
) AS descricao
|
||||
"),
|
||||
'atencao_basica_parametrizacao_microarea.id as microarea_id'
|
||||
])
|
||||
->join('atencao_basica_parametrizacao_equipe', 'atencao_basica_parametrizacao_equipe.id', 'atencao_basica_parametrizacao_equipe_usuario.equipe_id')
|
||||
->join('cadastro_unidade', 'cadastro_unidade.id', 'atencao_basica_parametrizacao_equipe.unidade_id')
|
||||
->leftJoin('atencao_basica_parametrizacao_area', 'atencao_basica_parametrizacao_area.id', 'atencao_basica_parametrizacao_equipe.area_id')
|
||||
->leftJoin('atencao_basica_parametrizacao_microarea', 'atencao_basica_parametrizacao_microarea.id', 'atencao_basica_parametrizacao_equipe.microarea_id')
|
||||
->where('atencao_basica_parametrizacao_equipe_usuario.ativo', true)
|
||||
->when(request()->usuario_id, fn ($q, $id) => $q->where('atencao_basica_parametrizacao_equipe_usuario.usuario_id', $id))
|
||||
->when(request()->infraestrutura_id, fn ($q, $id) => $q->where('atencao_basica_parametrizacao_equipe.infraestrutura_id', $id))
|
||||
->get();
|
||||
}
|
||||
|
||||
public static function getUnidades(){
|
||||
|
||||
return DB::table('atencao_basica_parametrizacao_equipe_usuario')
|
||||
->select([
|
||||
'cadastro_unidade.id AS id',
|
||||
DB::raw("CONCAT(TRIM(cadastro_unidade.cnes), ' - ', cadastro_unidade.nome_fantasia ) AS nome_fantasia"),
|
||||
])
|
||||
->join('atencao_basica_parametrizacao_equipe', 'atencao_basica_parametrizacao_equipe.id', 'atencao_basica_parametrizacao_equipe_usuario.equipe_id')
|
||||
->join('cadastro_unidade', 'cadastro_unidade.id', 'atencao_basica_parametrizacao_equipe.unidade_id')
|
||||
->where('atencao_basica_parametrizacao_equipe_usuario.ativo', true)
|
||||
->when(request()->usuario_id, fn ($q, $id) => $q->where('atencao_basica_parametrizacao_equipe_usuario.usuario_id', $id))
|
||||
->distinct()
|
||||
->orderBy('cadastro_unidade.cnes')
|
||||
->get();
|
||||
}
|
||||
|
||||
public static function getInfraestruturas(){
|
||||
|
||||
return DB::table('atencao_basica_parametrizacao_equipe_usuario')
|
||||
->select([
|
||||
'cadastro_infraestrutura.id AS id',
|
||||
DB::raw('COALESCE(cadastro_infraestrutura.nome, cadastro_unidade.nome_fantasia) AS nome'),
|
||||
])
|
||||
->join('atencao_basica_parametrizacao_equipe', 'atencao_basica_parametrizacao_equipe.id', 'atencao_basica_parametrizacao_equipe_usuario.equipe_id')
|
||||
->join('cadastro_infraestrutura', 'cadastro_infraestrutura.id', 'atencao_basica_parametrizacao_equipe.infraestrutura_id')
|
||||
->join('cadastro_unidade', 'cadastro_unidade.id', 'atencao_basica_parametrizacao_equipe.unidade_id')
|
||||
->where('atencao_basica_parametrizacao_equipe_usuario.ativo', true)
|
||||
->when(request()->usuario_id, fn ($q, $id) => $q->where('atencao_basica_parametrizacao_equipe_usuario.usuario_id', $id))
|
||||
->when(request()->unidade_id, fn ($q, $id) => $q->where('atencao_basica_parametrizacao_equipe.unidade_id', $id))
|
||||
->distinct()
|
||||
->orderBy('nome')
|
||||
->get();
|
||||
}
|
||||
|
||||
public static function getOcupacoes()
|
||||
{
|
||||
$usuario = Usuario::findOrFail(request()->usuario_id);
|
||||
|
||||
$ocupacaoSelecionada = request()->ocupacao_id;
|
||||
|
||||
return $usuario->lotacoes
|
||||
->filter(function ($lotacao) use ($ocupacaoSelecionada) {
|
||||
return $lotacao->infraestrutura->id == request()->infraestrutura_id
|
||||
&& (
|
||||
$lotacao->ativo
|
||||
|| $lotacao->ocupacao_id == $ocupacaoSelecionada
|
||||
);
|
||||
})
|
||||
->pluck('ocupacao');
|
||||
}
|
||||
|
||||
public function getCentrosCusto()
|
||||
{
|
||||
return DB::table('cadastro_centro_custo')
|
||||
->select([
|
||||
'cadastro_centro_custo.id',
|
||||
'cadastro_setor.nome',
|
||||
])
|
||||
->join('cadastro_setor', 'cadastro_setor.id', '=', 'cadastro_centro_custo.setor_id')
|
||||
->where('infraestrutura_id', request()->infraestrutura_id)
|
||||
->whereNull('cadastro_centro_custo.deleted_at')
|
||||
->orderBy('cadastro_setor.nome')
|
||||
->get();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Cadastro\SujeitoAtencao;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\Cadastro\SujeitoAtencao\UsuarioPerfilRequest;
|
||||
use App\Models\Cadastro\SujeitoAtencao\Usuario;
|
||||
use Hash;
|
||||
use Illuminate\Http\Response;
|
||||
|
||||
class UsuarioPerfilController extends Controller
|
||||
{
|
||||
public function show($id)
|
||||
{
|
||||
return response()->json($this->get(Usuario::class, $id), Response::HTTP_OK);
|
||||
}
|
||||
|
||||
public function edit($id)
|
||||
{
|
||||
return response()->json(['model' => Usuario::findOrFail($id)], Response::HTTP_OK);
|
||||
}
|
||||
|
||||
public function update(UsuarioPerfilRequest $request, $id)
|
||||
{
|
||||
$usuario = Usuario::findOrFail($id);
|
||||
|
||||
if ($request->senha && Hash::check($request->senha, $usuario->senha) === false) {
|
||||
return response()->json(['error' => 'A senha digita esta incorreta.'], Response::HTTP_UNAUTHORIZED);
|
||||
}
|
||||
|
||||
unset($request['senha']);
|
||||
|
||||
if($request->nova_senha) {
|
||||
$request['senha'] = $request->nova_senha;
|
||||
}
|
||||
|
||||
$usuario->update($request->all());
|
||||
|
||||
return response()->json($usuario->fresh(), Response::HTTP_OK);
|
||||
}
|
||||
}
|
||||
65
api/app/Http/Controllers/Cadastro/SupervisorController.php
Normal file
65
api/app/Http/Controllers/Cadastro/SupervisorController.php
Normal file
@@ -0,0 +1,65 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Cadastro;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Services\Cadastro\SupervisorService;
|
||||
use Illuminate\Http\Response;
|
||||
|
||||
class SupervisorController extends Controller
|
||||
{
|
||||
protected $modulo = 'cadastro';
|
||||
protected $funcionalidade = 'supervisor';
|
||||
|
||||
public function datatable()
|
||||
{
|
||||
return datatables()->of(SupervisorService::datatable())->toJson();
|
||||
}
|
||||
|
||||
public function list()
|
||||
{
|
||||
return response()->json(SupervisorService::list(), Response::HTTP_OK);
|
||||
}
|
||||
|
||||
public function isSupervisor($usuarioId)
|
||||
{
|
||||
return response()->json(SupervisorService::isSupervisor($usuarioId), Response::HTTP_OK);
|
||||
}
|
||||
|
||||
public function create()
|
||||
{
|
||||
$this->auth(__FUNCTION__);
|
||||
|
||||
return response()->json(SupervisorService::create(), Response::HTTP_CREATED);
|
||||
}
|
||||
|
||||
public function store()
|
||||
{
|
||||
$this->auth(__FUNCTION__);
|
||||
|
||||
return response()->json(SupervisorService::store(), Response::HTTP_CREATED);
|
||||
}
|
||||
|
||||
public function edit($id)
|
||||
{
|
||||
$this->auth(__FUNCTION__);
|
||||
|
||||
return response()->json(SupervisorService::edit($id), Response::HTTP_OK);
|
||||
}
|
||||
|
||||
public function update($id)
|
||||
{
|
||||
$this->auth(__FUNCTION__);
|
||||
|
||||
return response()->json(SupervisorService::update($id), Response::HTTP_OK);
|
||||
}
|
||||
|
||||
public function destroy($id)
|
||||
{
|
||||
$this->auth(__FUNCTION__);
|
||||
|
||||
SupervisorService::destroy($id);
|
||||
|
||||
return response()->noContent();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Cadastro;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Services\Cadastro\UnidadeExecutanteManutencaoService;
|
||||
use Illuminate\Http\Response;
|
||||
|
||||
class UnidadeExecutanteManutencaoController extends Controller
|
||||
{
|
||||
protected $modulo = 'cadastro';
|
||||
protected $funcionalidade = 'unidade-executante-manutencao';
|
||||
|
||||
public function datatable()
|
||||
{
|
||||
return datatables()
|
||||
->of(UnidadeExecutanteManutencaoService::datatable())
|
||||
->toJson();
|
||||
}
|
||||
|
||||
public function create()
|
||||
{
|
||||
$this->auth(__FUNCTION__);
|
||||
|
||||
return response()->json(UnidadeExecutanteManutencaoService::create(), Response::HTTP_CREATED);
|
||||
}
|
||||
|
||||
public function store()
|
||||
{
|
||||
$this->auth(__FUNCTION__);
|
||||
|
||||
return response()->json(UnidadeExecutanteManutencaoService::store(), Response::HTTP_CREATED);
|
||||
}
|
||||
|
||||
public function edit($id)
|
||||
{
|
||||
$this->auth(__FUNCTION__);
|
||||
|
||||
return response()->json(UnidadeExecutanteManutencaoService::edit($id), Response::HTTP_OK);
|
||||
}
|
||||
|
||||
public function update($id)
|
||||
{
|
||||
$this->auth(__FUNCTION__);
|
||||
|
||||
return response()->json(UnidadeExecutanteManutencaoService::update($id), Response::HTTP_OK);
|
||||
}
|
||||
|
||||
public function destroy($id)
|
||||
{
|
||||
$this->auth(__FUNCTION__);
|
||||
|
||||
return response()->json(UnidadeExecutanteManutencaoService::destroy($id), Response::HTTP_NO_CONTENT);
|
||||
}
|
||||
|
||||
public function autocompleteUnidade()
|
||||
{
|
||||
return datatables()
|
||||
->of(UnidadeExecutanteManutencaoService::autocompleteUnidade())
|
||||
->toJson();
|
||||
}
|
||||
|
||||
public function autocompleteFornecedor()
|
||||
{
|
||||
return datatables()
|
||||
->of(UnidadeExecutanteManutencaoService::autocompleteFornecedor())
|
||||
->toJson();
|
||||
}
|
||||
}
|
||||
112
api/app/Http/Controllers/Cadastro/UnidadeExternaController.php
Normal file
112
api/app/Http/Controllers/Cadastro/UnidadeExternaController.php
Normal file
@@ -0,0 +1,112 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Cadastro;
|
||||
|
||||
use App\Exceptions\Cadastro\UnidadeExterna\DuplicatedNomeFantasiaException;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\Cadastro\Estabelecimento\UnidadeExternaRequest;
|
||||
use App\Models\Cadastro\UnidadeExterna;
|
||||
use Illuminate\Http\Response;
|
||||
|
||||
class UnidadeExternaController extends Controller
|
||||
{
|
||||
protected $modulo = 'cadastro';
|
||||
protected $funcionalidade = 'unidade-externa';
|
||||
|
||||
public function autocomplete()
|
||||
{
|
||||
$unidadesExterna = UnidadeExterna::with([]);
|
||||
|
||||
return datatables()->of($unidadesExterna)->toJson();
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
$this->auth(__FUNCTION__);
|
||||
|
||||
$unidades = $this->get(UnidadeExterna::class)->orderBy('nome_fantasia')->get();
|
||||
|
||||
return response()->json($unidades, Response::HTTP_OK);
|
||||
}
|
||||
|
||||
public function store(UnidadeExternaRequest $request)
|
||||
{
|
||||
$this->auth(__FUNCTION__);
|
||||
|
||||
$params = $this->getParams($request);
|
||||
$unidadeExterna = UnidadeExterna::where('nome_fantasia', $params['nome_fantasia'])->first();
|
||||
|
||||
if (!is_null($unidadeExterna)) {
|
||||
|
||||
throw new DuplicatedNomeFantasiaException;
|
||||
}
|
||||
|
||||
return response()->json(UnidadeExterna::create($params)->fresh(), Response::HTTP_CREATED);
|
||||
}
|
||||
|
||||
public function show($id)
|
||||
{
|
||||
$this->auth(__FUNCTION__);
|
||||
|
||||
return response()->json($this->get(UnidadeExterna::class, $id), Response::HTTP_OK);
|
||||
}
|
||||
|
||||
public function edit($id)
|
||||
{
|
||||
$this->auth(__FUNCTION__);
|
||||
|
||||
$unidadeExterna = UnidadeExterna::findOrFail($id);
|
||||
|
||||
return response()->json(
|
||||
[
|
||||
'form' => [],
|
||||
'model' => $unidadeExterna
|
||||
],
|
||||
Response::HTTP_OK
|
||||
);
|
||||
}
|
||||
|
||||
public function update(UnidadeExternaRequest $request, $id)
|
||||
{
|
||||
$this->auth(__FUNCTION__);
|
||||
|
||||
$params = $this->getParams($request);
|
||||
|
||||
$unidadeExterna = UnidadeExterna::where('nome_fantasia', $params['nome_fantasia'])
|
||||
->where('id', '<>', $id)
|
||||
->first();
|
||||
|
||||
if (!is_null($unidadeExterna)) {
|
||||
|
||||
throw new DuplicatedNomeFantasiaException;
|
||||
}
|
||||
|
||||
$unidade = tap(UnidadeExterna::findOrFail($id))->update($params);
|
||||
|
||||
return response()->json($unidade, Response::HTTP_OK);
|
||||
}
|
||||
|
||||
private function getParams($request)
|
||||
{
|
||||
return [
|
||||
'nome_fantasia' => mb_strtoupper($request->nome_fantasia),
|
||||
'municipio_id' => $request->municipio_id,
|
||||
];
|
||||
}
|
||||
|
||||
public function destroy($id)
|
||||
{
|
||||
$this->auth(__FUNCTION__);
|
||||
|
||||
UnidadeExterna::findOrFail($id)->delete();
|
||||
|
||||
return response()->json(null, Response::HTTP_NO_CONTENT);
|
||||
}
|
||||
|
||||
public function datatable()
|
||||
{
|
||||
$unidadesExterna = UnidadeExterna::with([]);
|
||||
|
||||
return datatables()->of($unidadesExterna)->toJson();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Cadastro;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Services\Cadastro\UnificacaoUsuarioPacienteService;
|
||||
use App\Utils\MaskUtil;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Response;
|
||||
use Carbon\Carbon;
|
||||
|
||||
class UnificacaoUsuarioPacienteController extends Controller
|
||||
{
|
||||
protected $modulo = 'cadastro';
|
||||
protected $funcionalidade = 'unificacao-usuario-paciente';
|
||||
|
||||
public function autocomplete()
|
||||
{
|
||||
return datatables()
|
||||
->of(UnificacaoUsuarioPacienteService::autocomplete())
|
||||
->filterColumn('cadastro_paciente.prontuario', function ($query, $keyword) {
|
||||
$query->whereRaw('LPAD(cadastro_paciente.prontuario,7,0) like ?', ["%{$keyword}%"]);
|
||||
})
|
||||
->filterColumn('cadastro_cidadao.data_nascimento', function($query, $keyword){
|
||||
$keyword = preg_replace('/[^0-9]/', '', $keyword);
|
||||
if(strlen($keyword) == 8){
|
||||
$data = Carbon::createFromFormat('dmY', $keyword)->format('Y-m-d');
|
||||
$query->whereDate('cadastro_cidadao.data_nascimento', $data);
|
||||
}
|
||||
})
|
||||
->editColumn('cpf', fn ($query) => MaskUtil::getCpfMasked($query->cpf))
|
||||
->editColumn('cns', fn ($query) => MaskUtil::getCnsMasked($query->cns))
|
||||
->toJson();
|
||||
}
|
||||
|
||||
public function store(Request $request)
|
||||
{
|
||||
$this->auth(__FUNCTION__);
|
||||
|
||||
return response()->json(UnificacaoUsuarioPacienteService::store($request), Response::HTTP_OK);
|
||||
}
|
||||
}
|
||||
66
api/app/Http/Controllers/Cadastro/VacinaController.php
Normal file
66
api/app/Http/Controllers/Cadastro/VacinaController.php
Normal file
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Cadastro;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Services\Cadastro\VacinaService;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Response;
|
||||
|
||||
class VacinaController extends Controller
|
||||
{
|
||||
protected $modulo = 'cadastro';
|
||||
protected $funcionalidade = 'vacina';
|
||||
|
||||
public function create()
|
||||
{
|
||||
$this->auth(__FUNCTION__);
|
||||
|
||||
return response()->json(VacinaService::create(), Response::HTTP_OK);
|
||||
}
|
||||
|
||||
public function store(Request $request)
|
||||
{
|
||||
$this->auth(__FUNCTION__);
|
||||
|
||||
return response()->json(VacinaService::store($request), Response::HTTP_CREATED);
|
||||
}
|
||||
|
||||
public function edit($id)
|
||||
{
|
||||
$this->auth(__FUNCTION__);
|
||||
|
||||
return response()->json(VacinaService::edit($id), Response::HTTP_OK);
|
||||
}
|
||||
|
||||
public function update(Request $request, $id)
|
||||
{
|
||||
$this->auth(__FUNCTION__);
|
||||
|
||||
return response()->json(VacinaService::update($request, $id), Response::HTTP_OK);
|
||||
}
|
||||
|
||||
public function destroy($id)
|
||||
{
|
||||
$this->auth(__FUNCTION__);
|
||||
|
||||
return response()->json(VacinaService::destroy($id), Response::HTTP_NO_CONTENT);
|
||||
}
|
||||
|
||||
public function datatable()
|
||||
{
|
||||
return datatables()
|
||||
->of(VacinaService::datatable())
|
||||
->filterColumn('cadastro_vacina.calendario', function ($query, $keyword) {
|
||||
$query->whereRaw("CASE WHEN cadastro_vacina.calendario THEN 'Sim' ELSE 'Não' END LIKE ?", ["%{$keyword}%"]);
|
||||
})
|
||||
->make(true);
|
||||
}
|
||||
|
||||
public function autocomplete()
|
||||
{
|
||||
return datatables()
|
||||
->of(VacinaService::autocomplete())
|
||||
->make(true);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user