This commit is contained in:
110
api/app/Services/ExameImagem/RelatorioLancamentoService.php
Normal file
110
api/app/Services/ExameImagem/RelatorioLancamentoService.php
Normal file
@@ -0,0 +1,110 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services\ExameImagem;
|
||||
|
||||
use App\Services\Service;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class RelatorioLancamentoService extends Service
|
||||
{
|
||||
public static function getLancamento($idPaciente)
|
||||
{
|
||||
$lancamento = DB::table('exame_imagem_agendamento_exame')
|
||||
->select(
|
||||
'exame_imagem_agendamento_exame.id AS id_paciente',
|
||||
'exame_imagem_agendamento_exame.resultado AS resultado',
|
||||
'exame_imagem_agendamento_exame.agendamento_id AS agendamento_id',
|
||||
'cadastro_paciente.id AS paciente_id',
|
||||
'cidadao.nome AS paciente_nome',
|
||||
'cidadao.nome_social AS paciente_nome_social',
|
||||
'cidadao.preferencia_nome_id AS paciente_preferencia_nome_id',
|
||||
'exame_imagem_agendamento.nome_responsavel AS nome_responsavel',
|
||||
'exame_imagem_agendamento.urgente AS urgente',
|
||||
'cadastro_unidade_solicitante.nome_fantasia AS unidade_solicitante_nome',
|
||||
'cadastro_unidade.nome_fantasia',
|
||||
'medico_cidadao.nome AS medico_solicitante',
|
||||
'profissional.nome AS profissional_nome',
|
||||
'parametrizacao_exame.id AS exame_id',
|
||||
'parametrizacao_exame.nome AS exame_nome',
|
||||
'cadastro_usuario_registro_tipo.descricao AS registro_nome',
|
||||
'cadastro_usuario_registro_tipo.id AS registro_id',
|
||||
'cadastro_usuario_registro_tipo.sigla AS registro_sigla',
|
||||
'profissional_cidadao.registro_numero AS registro_numero',
|
||||
DB::raw('LPAD(cadastro_paciente.prontuario,7,0) AS prontuario'),
|
||||
DB::raw("DATE_FORMAT(cidadao.data_nascimento, '%d/%m/%Y') data_nascimento"),
|
||||
DB::raw('CONCAT(TIMESTAMPDIFF(YEAR, cidadao.data_nascimento, exame_imagem_agendamento.data), " anos") AS paciente_idade'),
|
||||
DB::raw("DATE_FORMAT(exame_imagem_agendamento.data, '%d/%m/%Y') AS data"),
|
||||
DB::raw("DATE_FORMAT(exame_imagem_agendamento.created_at, '%d/%m/%Y') AS data_pedido"),
|
||||
)
|
||||
->join(
|
||||
'exame_imagem_agendamento',
|
||||
'exame_imagem_agendamento.id',
|
||||
'exame_imagem_agendamento_exame.agendamento_id'
|
||||
)
|
||||
->join(
|
||||
'cadastro_paciente',
|
||||
'cadastro_paciente.id',
|
||||
'exame_imagem_agendamento_exame.paciente_id'
|
||||
)
|
||||
->join(
|
||||
'cadastro_cidadao AS cidadao',
|
||||
'cidadao.id',
|
||||
'cadastro_paciente.cidadao_id'
|
||||
)
|
||||
->join(
|
||||
'cadastro_infraestrutura',
|
||||
'cadastro_infraestrutura.id',
|
||||
'exame_imagem_agendamento.infraestrutura_id'
|
||||
)
|
||||
->join(
|
||||
'cadastro_unidade',
|
||||
'cadastro_unidade.id',
|
||||
'cadastro_infraestrutura.unidade_id'
|
||||
)
|
||||
->join(
|
||||
'cadastro_infraestrutura AS cadastro_infraestrutura_solicitante',
|
||||
'cadastro_infraestrutura_solicitante.id',
|
||||
'exame_imagem_agendamento.infraestrutura_solicitante_id'
|
||||
)
|
||||
->join(
|
||||
'cadastro_unidade AS cadastro_unidade_solicitante',
|
||||
'cadastro_unidade_solicitante.id',
|
||||
'cadastro_infraestrutura_solicitante.unidade_id'
|
||||
)
|
||||
->join(
|
||||
'cadastro_usuario',
|
||||
'cadastro_usuario.id',
|
||||
'exame_imagem_agendamento.medico_id'
|
||||
)
|
||||
->join(
|
||||
'cadastro_cidadao AS medico_cidadao',
|
||||
'medico_cidadao.id',
|
||||
'cadastro_usuario.cidadao_id'
|
||||
)
|
||||
->join(
|
||||
'cadastro_usuario AS profissional_cidadao',
|
||||
'profissional_cidadao.id',
|
||||
'exame_imagem_agendamento.profissional_id'
|
||||
)
|
||||
->join(
|
||||
'cadastro_cidadao AS profissional',
|
||||
'profissional.id',
|
||||
'profissional_cidadao.cidadao_id'
|
||||
)
|
||||
->join(
|
||||
'parametrizacao_exame',
|
||||
'parametrizacao_exame.id',
|
||||
'exame_imagem_agendamento_exame.exame_id'
|
||||
)
|
||||
->leftjoin(
|
||||
'cadastro_usuario_registro_tipo',
|
||||
'cadastro_usuario_registro_tipo.id',
|
||||
'profissional_cidadao.registro_tipo_id'
|
||||
)
|
||||
->where('exame_imagem_agendamento_exame.id', $idPaciente)
|
||||
->first();
|
||||
|
||||
return $lancamento;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user