This commit is contained in:
@@ -0,0 +1,607 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services\AtencaoBasica\Exportacao;
|
||||
|
||||
use App\Enums\AtencaoBasica\Exportacao\Sexo as ExportacaoSexo;
|
||||
use App\Enums\AtencaoBasica\Procedimento\TipoDadoSerializado;
|
||||
use App\Enums\Cadastro\SujeitoAtencao\Sexo;
|
||||
use App\Models\AtencaoBasica\Exportacao\Exportacao;
|
||||
use App\Models\AtencaoBasica\Procedimento\Procedimento;
|
||||
use App\Models\AtencaoBasica\Procedimento\ProcedimentoAtendimento;
|
||||
use App\Models\AtencaoBasica\Procedimento\ProcedimentoAtendimentoIvcf;
|
||||
use App\Rules\Cns;
|
||||
|
||||
use App\Services\Service;
|
||||
use Carbon\Carbon;
|
||||
use DOMDocument;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use ZipArchive;
|
||||
|
||||
class FichaProcedimentoService extends Service
|
||||
{
|
||||
|
||||
public static function create($arquivo_caminho, $arquivo_nome, $exportacaoArquivoId, $usuarioId = null)
|
||||
{
|
||||
$mes_ano = request()->mes_ano;
|
||||
|
||||
foreach (self::getFichasProcedimento($mes_ano) as $fichaProcedimento) {
|
||||
|
||||
$dadosExportacao = self::getDadosExportacao($fichaProcedimento, $exportacaoArquivoId, $usuarioId);
|
||||
|
||||
$xmlPath = Storage::path($arquivo_caminho . 'xml_temp.xml');
|
||||
|
||||
$dadosExportacao['dom']->save($xmlPath);
|
||||
$zip = new ZipArchive;
|
||||
$zip->open(Storage::path($arquivo_caminho . $arquivo_nome), ZipArchive::CREATE);
|
||||
$zip->addFile($xmlPath, 'PR_' . $dadosExportacao['exportacao']->uuid . '.esus.xml');
|
||||
$zip->close();
|
||||
|
||||
unlink($xmlPath);
|
||||
}
|
||||
}
|
||||
|
||||
public static function gerarExportacoes($mesAnoInicial)
|
||||
{
|
||||
$exportacoes = collect();
|
||||
|
||||
foreach (self::getFichasProcedimento($mesAnoInicial, false) as $fichaProcedimento) {
|
||||
|
||||
$dadosExportacao = self::getDadosExportacao($fichaProcedimento);
|
||||
|
||||
$exportacoes->push([
|
||||
'exportacao_id' => $dadosExportacao['exportacao']->id,
|
||||
'data_atendimento' => $fichaProcedimento->data_usuario_responsavel,
|
||||
'usuario_id' => $fichaProcedimento->usuario->id,
|
||||
'ocupacao_id' => $fichaProcedimento->ocupacao->id,
|
||||
'equipe_id' => $fichaProcedimento->equipe->id,
|
||||
'procedimento_id' => $fichaProcedimento->id,
|
||||
'procedimento_atendimentos' => $dadosExportacao['procedimento_atendimentos'],
|
||||
'xml' => [
|
||||
'nome_arquivo' => 'PR_' . $dadosExportacao['exportacao']->uuid . '.esus.xml',
|
||||
'conteudo' => $dadosExportacao['dom']->saveXml(),
|
||||
]
|
||||
]);
|
||||
}
|
||||
|
||||
return $exportacoes;
|
||||
}
|
||||
|
||||
private static function getFichasProcedimento($mes_ano, $somenteMesAno = true)
|
||||
{
|
||||
return Procedimento::whereNull('exportacao_id')
|
||||
->when($somenteMesAno,
|
||||
fn ($q) => $q->whereYear('data_usuario_responsavel', substr($mes_ano, 2))
|
||||
->whereMonth('data_usuario_responsavel', substr($mes_ano, 0, 2)),
|
||||
fn ($q) => $q->where(function ($q) use ($mes_ano) {
|
||||
$q->whereYear('data_usuario_responsavel', '>', substr($mes_ano, 2))
|
||||
->orWhere(function ($q) use ($mes_ano) {
|
||||
$q->whereYear('data_usuario_responsavel', substr($mes_ano, 2))
|
||||
->whereMonth('data_usuario_responsavel', '>=', substr($mes_ano, 0, 2));
|
||||
});
|
||||
})
|
||||
)
|
||||
->get();
|
||||
}
|
||||
|
||||
private static function getDadosExportacao($fichaProcedimento, $exportacaoArquivoId = null, $usuarioId = null)
|
||||
{
|
||||
$uuid = ExportacaoService::getUuid($fichaProcedimento->equipe->unidade->cnes);
|
||||
|
||||
$dom = new DOMDocument('1.0', 'UTF-8');
|
||||
$dadoTransporteTransportXml = $dom->createElementNS('http://esus.ufsc.br/dadotransporte', 'ns3:dadoTransporteTransportXml');
|
||||
$dadoTransporteTransportXml->setAttributeNS('http://www.w3.org/2000/xmlns/', 'xmlns:ns2', 'http://esus.ufsc.br/dadoinstalacao');
|
||||
$dadoTransporteTransportXml->setAttributeNS('http://www.w3.org/2000/xmlns/', 'xmlns:ns3', 'http://esus.ufsc.br/dadotransporte');
|
||||
$dadoTransporteTransportXml->setAttributeNS('http://www.w3.org/2000/xmlns/', 'xmlns:ns4', 'http://esus.ufsc.br/fichaprocedimentomaster');
|
||||
|
||||
$dadoTransporteTransportXml->appendChild($dom->createElement('uuidDadoSerializado', $uuid));
|
||||
$dadoTransporteTransportXml->appendChild($dom->createElement('tipoDadoSerializado', TipoDadoSerializado::PROCEDIMENTOS));
|
||||
$dadoTransporteTransportXml->appendChild($dom->createElement('codIbge', $fichaProcedimento->equipe->infraestrutura->endereco->logradouro->municipio->ibge));
|
||||
$dadoTransporteTransportXml->appendChild($dom->createElement('cnesDadoSerializado', $fichaProcedimento->equipe->unidade->cnes));
|
||||
|
||||
if($fichaProcedimento->equipe->area->numero_ine){
|
||||
|
||||
$dadoTransporteTransportXml->appendChild($dom->createElement('ineDadoSerializado', $fichaProcedimento->equipe->area->numero_ine));
|
||||
}
|
||||
|
||||
$fichaProcedimentoMasterTransport = $dom->createElement('ns4:fichaProcedimentoMasterTransport');
|
||||
$dadoTransporteTransportXml->appendChild($fichaProcedimentoMasterTransport);
|
||||
|
||||
$headerTransport = $dom->createElement('headerTransport');
|
||||
$fichaProcedimentoMasterTransport->appendChild($headerTransport);
|
||||
|
||||
$headerTransport->appendChild($dom->createElement('profissionalCNS', $fichaProcedimento->usuario->cidadao->cns ?? ''));
|
||||
$headerTransport->appendChild($dom->createElement('cboCodigo_2002', $fichaProcedimento->ocupacao->codigo ));
|
||||
$headerTransport->appendChild($dom->createElement('cnes', $fichaProcedimento->equipe->unidade->cnes));
|
||||
|
||||
if($fichaProcedimento->equipe->area->numero_ine){
|
||||
|
||||
$headerTransport->appendChild($dom->createElement('ine', $fichaProcedimento->equipe->area->numero_ine));
|
||||
}
|
||||
|
||||
$headerTransport->appendChild($dom->createElement('dataAtendimento', strtotime($fichaProcedimento->data_usuario_responsavel) * 1000));
|
||||
$headerTransport->appendChild($dom->createElement('codigoIbgeMunicipio', $fichaProcedimento->equipe->infraestrutura->endereco->logradouro->municipio->ibge));
|
||||
|
||||
$dom->appendChild($dadoTransporteTransportXml);
|
||||
|
||||
$retorno = self::getPacientes($dom, $fichaProcedimento, $fichaProcedimentoMasterTransport);
|
||||
$procedimentoAtendimentos = $retorno['procedimento_atendimentos'];
|
||||
|
||||
$fichaProcedimentoMasterTransport->appendChild($dom->createElement('uuidFicha', $uuid));
|
||||
$fichaProcedimentoMasterTransport->appendChild($dom->createElement('tpCdsOrigem', '3'));
|
||||
|
||||
if($fichaProcedimento->afericao_pa){
|
||||
|
||||
$fichaProcedimentoMasterTransport->appendChild($dom->createElement('numTotalAfericaoPa', $fichaProcedimento->afericao_pa ?? ''));
|
||||
}
|
||||
|
||||
if($fichaProcedimento->afericao_temperatura){
|
||||
|
||||
$fichaProcedimentoMasterTransport->appendChild($dom->createElement('numTotalAfericaoTemperatura', $fichaProcedimento->afericao_temperatura ?? ''));
|
||||
}
|
||||
|
||||
if($fichaProcedimento->curativo_simples){
|
||||
|
||||
$fichaProcedimentoMasterTransport->appendChild($dom->createElement('numTotalCurativoSimples', $fichaProcedimento->curativo_simples ?? ''));
|
||||
}
|
||||
|
||||
if($fichaProcedimento->coleta_material_exame_laboratorial){
|
||||
|
||||
$fichaProcedimentoMasterTransport->appendChild($dom->createElement('numTotalColetaMaterialParaExameLaboratorial', $fichaProcedimento->coleta_material_exame_laboratorial ?? ''));
|
||||
}
|
||||
|
||||
if($fichaProcedimento->glicemia_capilar){
|
||||
|
||||
$fichaProcedimentoMasterTransport->appendChild($dom->createElement('numTotalGlicemiaCapilar', $fichaProcedimento->glicemia_capilar ?? ''));
|
||||
}
|
||||
|
||||
if($fichaProcedimento->medicao_altura){
|
||||
|
||||
$fichaProcedimentoMasterTransport->appendChild($dom->createElement('numTotalMedicaoAltura', $fichaProcedimento->medicao_altura ?? ''));
|
||||
}
|
||||
|
||||
if($fichaProcedimento->medicao_peso){
|
||||
|
||||
$fichaProcedimentoMasterTransport->appendChild($dom->createElement('numTotalMedicaoPeso', $fichaProcedimento->medicao_peso ?? ''));
|
||||
}
|
||||
|
||||
ExportacaoService::elementRemetente($dom, $dadoTransporteTransportXml);
|
||||
ExportacaoService::elementOriginadora($dom, $dadoTransporteTransportXml);
|
||||
ExportacaoService::elementVersao($dom, $dadoTransporteTransportXml);
|
||||
|
||||
$exportacao = new Exportacao();
|
||||
$exportacao->uuid = $uuid;
|
||||
$exportacao->exportacao_arquivo_id = $exportacaoArquivoId;
|
||||
$exportacao->save();
|
||||
|
||||
$fichaProcedimento->uuid_ficha = $uuid;
|
||||
$fichaProcedimento->exportacao_id = $exportacao->id;
|
||||
$fichaProcedimento->data_hora_exportacao = Carbon::now()->format('Y-m-d H:i:s');
|
||||
$fichaProcedimento->usuario_exportacao_id = $usuarioId ?? self::getCurrentLotacao()->usuario_id ?? null;
|
||||
$fichaProcedimento->save();
|
||||
|
||||
return [
|
||||
'exportacao' => $exportacao,
|
||||
'dom' => $dom,
|
||||
'procedimento_atendimentos' => $procedimentoAtendimentos,
|
||||
];
|
||||
}
|
||||
|
||||
private static function getPacientes(&$dom, $fichaProcedimento, &$fichaProcedimentoMasterTransport){
|
||||
|
||||
$procedimentoAtendimentosPosicoes = collect();
|
||||
|
||||
$procedimentoPaciente = ProcedimentoAtendimento::where('procedimento_id', $fichaProcedimento->id)
|
||||
->get();
|
||||
|
||||
foreach ($procedimentoPaciente as $i => $procedimento) {
|
||||
|
||||
$procedimentoAtendimentosPosicoes->push([
|
||||
'posicao' => $i + 1,
|
||||
'id' => $procedimento->id,
|
||||
]);
|
||||
|
||||
$atendProcedimentos = $dom->createElement('atendProcedimentos');
|
||||
$fichaProcedimentoMasterTransport->appendChild($atendProcedimentos);
|
||||
|
||||
if($procedimento->paciente) {
|
||||
if($procedimento->paciente->prontuario){
|
||||
|
||||
$atendProcedimentos->appendChild($dom->createElement('numProntuario', $procedimento->paciente->prontuario));
|
||||
}
|
||||
|
||||
if (Cns::isValid($procedimento->paciente->cidadao->cns)) {
|
||||
|
||||
$atendProcedimentos->appendChild($dom->createElement('cnsCidadao', $procedimento->paciente->cidadao->cns ?? ''));
|
||||
}
|
||||
|
||||
if (!Cns::isValid($procedimento->paciente->cidadao->cns)) {
|
||||
|
||||
$atendProcedimentos->appendChild($dom->createElement('cpfCidadao', $procedimento->paciente->cidadao->cpf ?? ''));
|
||||
}
|
||||
|
||||
$atendProcedimentos->appendChild($dom->createElement('dtNascimento', strtotime($procedimento->paciente->cidadao->data_nascimento->format('Y-m-d')) * 1000));
|
||||
$atendProcedimentos->appendChild($dom->createElement('sexo', self::sexo($procedimento->paciente->cidadao->sexo->id)));
|
||||
}
|
||||
|
||||
$atendProcedimentos->appendChild($dom->createElement('localAtendimento', $procedimento->local_atendimento_id));
|
||||
$atendProcedimentos->appendChild($dom->createElement('turno', $procedimento->turno_id));
|
||||
$atendProcedimentos->appendChild($dom->createElement('statusEscutaInicialOrientacao', $procedimento->escuta_inicial ? 'true' : 'false'));
|
||||
|
||||
self::getProcedimentos($dom, $procedimento, $atendProcedimentos);
|
||||
|
||||
$dataHoraInicialAtendimento = strtotime($fichaProcedimento->data_usuario_responsavel . ' ' . Carbon::parse($procedimento->created_at)->format('H:i:s'));
|
||||
$atendProcedimentos->appendChild($dom->createElement('dataHoraInicialAtendimento', $dataHoraInicialAtendimento * 1000));
|
||||
|
||||
$dataHoraFinalAtendimento = $dataHoraInicialAtendimento;
|
||||
$dataHoraFinalAtendimento += 5 * 60;
|
||||
$atendProcedimentos->appendChild($dom->createElement('dataHoraFinalAtendimento', $dataHoraFinalAtendimento * 1000));
|
||||
|
||||
self::getMedicoes($dom, $procedimento, $atendProcedimentos);
|
||||
self::getIvcf($dom, $procedimento, $atendProcedimentos);
|
||||
}
|
||||
|
||||
return [
|
||||
'procedimento_atendimentos' => $procedimentoAtendimentosPosicoes,
|
||||
];
|
||||
}
|
||||
|
||||
private static function getMedicoes(&$dom, $procedimento, &$atendProcedimento){
|
||||
|
||||
$medicoesNecessarias = [
|
||||
'circunferencia_abdominal',
|
||||
'perimetro_panturrilha',
|
||||
'afericao_pa',
|
||||
'frequencia_respiratoria',
|
||||
'frequencia_cardiaca',
|
||||
'temperatura',
|
||||
'saturacao_o2',
|
||||
'glicemia_capilar',
|
||||
'momento_coleta_id',
|
||||
'peso',
|
||||
'altura',
|
||||
'perimetro_cefalico'
|
||||
];
|
||||
|
||||
$existeMedicao = false;
|
||||
foreach ($medicoesNecessarias as $campo) {
|
||||
if (!empty($procedimento->$campo)) {
|
||||
$existeMedicao = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ($existeMedicao) {
|
||||
$medicoes = $dom->createElement('medicoes');
|
||||
$atendProcedimento->appendChild($medicoes);
|
||||
|
||||
if (!empty($fichaAtendimentoIndividual->circunferencia_abdominal)) {
|
||||
$medicoes->appendChild($dom->createElement('circunferenciaAbdominal', $procedimento->circunferencia_abdominal));
|
||||
}
|
||||
|
||||
if (!empty($procedimento->perimetro_panturrilha)) {
|
||||
$medicoes->appendChild($dom->createElement('perimetroPanturrilha', $procedimento->perimetro_panturrilha));
|
||||
}
|
||||
|
||||
if (!empty($procedimento->afericao_pa)) {
|
||||
$pressao = explode('/', $procedimento->afericao_pa);
|
||||
|
||||
if (count($pressao) === 2) {
|
||||
$medicoes->appendChild($dom->createElement('pressaoArterialSistolica', $pressao[0]));
|
||||
$medicoes->appendChild($dom->createElement('pressaoArterialDiastolica', $pressao[1]));
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($procedimento->frequencia_respiratoria)) {
|
||||
$medicoes->appendChild($dom->createElement('frequenciaRespiratoria', $procedimento->frequencia_respiratoria));
|
||||
}
|
||||
|
||||
if (!empty($procedimento->frequencia_cardiaca)) {
|
||||
$medicoes->appendChild($dom->createElement('frequenciaCardiaca', $procedimento->frequencia_cardiaca));
|
||||
}
|
||||
|
||||
if (!empty($procedimento->temperatura)) {
|
||||
$medicoes->appendChild($dom->createElement('temperatura', $procedimento->temperatura));
|
||||
}
|
||||
|
||||
if (!empty($procedimento->saturacao_o2)) {
|
||||
$medicoes->appendChild($dom->createElement('saturacaoO2', $procedimento->saturacao_o2));
|
||||
}
|
||||
|
||||
if (!empty($procedimento->glicemia_capilar)) {
|
||||
$medicoes->appendChild($dom->createElement('glicemiaCapilar', $procedimento->glicemia_capilar));
|
||||
}
|
||||
|
||||
if (!empty($procedimento->momento_coleta_id)) {
|
||||
$medicoes->appendChild($dom->createElement('tipoGlicemiaCapilar', $procedimento->momentoColeta->codigo_esus));
|
||||
}
|
||||
|
||||
if (!empty($procedimento->peso)) {
|
||||
$medicoes->appendChild($dom->createElement('peso', $procedimento->peso));
|
||||
}
|
||||
|
||||
if (!empty($procedimento->altura)) {
|
||||
$medicoes->appendChild($dom->createElement('altura', $procedimento->altura));
|
||||
}
|
||||
|
||||
if (!empty($procedimento->perimetro_cefalico)) {
|
||||
$medicoes->appendChild($dom->createElement('perimetroCefalico', $procedimento->perimetro_cefalico));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static function getIvcf(&$dom, $procedimento, &$atendProcedimentos)
|
||||
{
|
||||
$procedimentoAtendimentoIvcf = ProcedimentoAtendimentoIvcf::where('procedimento_atendimento_id', $procedimento->id)->first();
|
||||
|
||||
if ($procedimentoAtendimentoIvcf) {
|
||||
$pacienteIdade = $procedimentoAtendimentoIvcf->procedimentoAtendimento->paciente->cidadao->idade['anos'] ?? null;
|
||||
|
||||
$resultado = null;
|
||||
$hasSgIdade = true;
|
||||
$hasSgPercepcaoSaude = false;
|
||||
$hasSgAvdInstrumental = false;
|
||||
$hasSgAvdBasica = false;
|
||||
$hasSgCognicao = false;
|
||||
$hasSgHumor = false;
|
||||
$hasSgAlcancePreensaoPinca = false;
|
||||
$hasSgCapAerobicaMuscular = false;
|
||||
$hasSgMarcha = false;
|
||||
$hasSgContinencia = false;
|
||||
$hasSgVisao = false;
|
||||
$hasSgAudicao = false;
|
||||
$hasSgComorbidade = false;
|
||||
$dataResultado = strtotime($procedimentoAtendimentoIvcf->updated_at) * 1000;
|
||||
|
||||
if ($pacienteIdade >= 75 && $pacienteIdade <= 84) {
|
||||
$resultado += 1;
|
||||
}
|
||||
else if ($pacienteIdade >= 85) {
|
||||
$resultado += 3;
|
||||
}
|
||||
|
||||
if ($procedimentoAtendimentoIvcf->estado_saude_geral === 'regular_ou_ruim') {
|
||||
$resultado += 1;
|
||||
$hasSgPercepcaoSaude = true;
|
||||
}
|
||||
|
||||
if ($procedimentoAtendimentoIvcf->limitacao_compras || $procedimentoAtendimentoIvcf->limitacao_gestao_financeira || $procedimentoAtendimentoIvcf->limitacao_tarefas_domesticas) {
|
||||
$resultado += 4;
|
||||
$hasSgAvdInstrumental = true;
|
||||
}
|
||||
|
||||
if ($procedimentoAtendimentoIvcf->banho_independencia) {
|
||||
$resultado += 6;
|
||||
$hasSgAvdBasica = true;
|
||||
}
|
||||
|
||||
if ($procedimentoAtendimentoIvcf->relato_esquecimento_por_terceiros) {
|
||||
$resultado += 1;
|
||||
$hasSgCognicao = true;
|
||||
}
|
||||
|
||||
if ($procedimentoAtendimentoIvcf->esquecimento_piorando) {
|
||||
$resultado += 1;
|
||||
$hasSgCognicao = true;
|
||||
}
|
||||
|
||||
if ($procedimentoAtendimentoIvcf->esquecimento_impacta_atividades) {
|
||||
$resultado += 2;
|
||||
$hasSgCognicao = true;
|
||||
}
|
||||
|
||||
if ($procedimentoAtendimentoIvcf->humor_tristeza_desanimo) {
|
||||
$resultado += 2;
|
||||
$hasSgHumor = true;
|
||||
}
|
||||
|
||||
if ($procedimentoAtendimentoIvcf->perda_interesse_atividades) {
|
||||
$resultado += 2;
|
||||
$hasSgHumor = true;
|
||||
}
|
||||
|
||||
if ($procedimentoAtendimentoIvcf->limitacao_elevar_bracos) {
|
||||
$resultado += 1;
|
||||
$hasSgAlcancePreensaoPinca = true;
|
||||
}
|
||||
|
||||
if ($procedimentoAtendimentoIvcf->limitacao_motricidade_fina) {
|
||||
$resultado += 1;
|
||||
$hasSgAlcancePreensaoPinca = true;
|
||||
}
|
||||
|
||||
if ($procedimentoAtendimentoIvcf->perda_peso_nao_intencional || $procedimentoAtendimentoIvcf->imc_abaixo_22 || $procedimentoAtendimentoIvcf->panturrilha_abaixo_31 || $procedimentoAtendimentoIvcf->marcha_lenta_4m_maior_5s) {
|
||||
$resultado += 2;
|
||||
$hasSgCapAerobicaMuscular = true;
|
||||
}
|
||||
|
||||
if ($procedimentoAtendimentoIvcf->dificuldade_caminhar_impacto_atividades) {
|
||||
$resultado += 2;
|
||||
$hasSgMarcha = true;
|
||||
}
|
||||
|
||||
if ($procedimentoAtendimentoIvcf->quedas_recorrentes) {
|
||||
$resultado += 2;
|
||||
$hasSgMarcha = true;
|
||||
}
|
||||
|
||||
if ($procedimentoAtendimentoIvcf->incontinencia) {
|
||||
$resultado += 2;
|
||||
$hasSgContinencia = true;
|
||||
}
|
||||
|
||||
if ($procedimentoAtendimentoIvcf->problema_visao_impacto_atividades) {
|
||||
$resultado += 2;
|
||||
$hasSgVisao = true;
|
||||
}
|
||||
|
||||
if ($procedimentoAtendimentoIvcf->problema_audicao_impacto_atividades) {
|
||||
$resultado += 2;
|
||||
$hasSgAudicao = true;
|
||||
}
|
||||
|
||||
if ($procedimentoAtendimentoIvcf->doencas_cronicas_multiplas || $procedimentoAtendimentoIvcf->polifarmacia_5_ou_mais_medicamentos || $procedimentoAtendimentoIvcf->internacao_ultimos_6_meses) {
|
||||
$resultado += 4;
|
||||
$hasSgComorbidade = true;
|
||||
}
|
||||
|
||||
$ivcf = $dom->createElement('ivcf');
|
||||
$atendProcedimentos->appendChild($ivcf);
|
||||
|
||||
$ivcf->appendChild($dom->createElement('resultado', $resultado));
|
||||
$ivcf->appendChild($dom->createElement('hasSgIdade', $hasSgIdade ? 'true' : 'false'));
|
||||
$ivcf->appendChild($dom->createElement('hasSgPercepcaoSaude', $hasSgPercepcaoSaude ? 'true' : 'false'));
|
||||
$ivcf->appendChild($dom->createElement('hasSgAvdInstrumental', $hasSgAvdInstrumental ? 'true' : 'false'));
|
||||
$ivcf->appendChild($dom->createElement('hasSgAvdBasica', $hasSgAvdBasica ? 'true' : 'false'));
|
||||
$ivcf->appendChild($dom->createElement('hasSgCognicao', $hasSgCognicao ? 'true' : 'false'));
|
||||
$ivcf->appendChild($dom->createElement('hasSgHumor', $hasSgHumor ? 'true' : 'false'));
|
||||
$ivcf->appendChild($dom->createElement('hasSgAlcancePreensaoPinca', $hasSgAlcancePreensaoPinca ? 'true' : 'false'));
|
||||
$ivcf->appendChild($dom->createElement('hasSgCapAerobicaMuscular', $hasSgCapAerobicaMuscular ? 'true' : 'false'));
|
||||
$ivcf->appendChild($dom->createElement('hasSgMarcha', $hasSgMarcha ? 'true' : 'false'));
|
||||
$ivcf->appendChild($dom->createElement('hasSgContinencia', $hasSgContinencia ? 'true' : 'false'));
|
||||
$ivcf->appendChild($dom->createElement('hasSgVisao', $hasSgVisao ? 'true' : 'false'));
|
||||
$ivcf->appendChild($dom->createElement('hasSgAudicao', $hasSgAudicao ? 'true' : 'false'));
|
||||
$ivcf->appendChild($dom->createElement('hasSgComorbidade', $hasSgComorbidade ? 'true' : 'false'));
|
||||
$ivcf->appendChild($dom->createElement('dataResultado', $dataResultado));
|
||||
}
|
||||
}
|
||||
|
||||
private static function getProcedimentos(&$dom, $procedimento, &$atendProcedimento){
|
||||
|
||||
$atendimentoProcedimentosPequenaCirurgia = DB::table('atencao_basica_procedimento_atendimento_pequena_cirurgia')
|
||||
->select([
|
||||
'atencao_basica_cadastro_procedimento_pequena_cirurgia.codigo_esus',
|
||||
'atencao_basica_cadastro_procedimento_pequena_cirurgia.codigo_procedimento',
|
||||
])
|
||||
->join(
|
||||
'atencao_basica_cadastro_procedimento_pequena_cirurgia',
|
||||
'atencao_basica_cadastro_procedimento_pequena_cirurgia.id',
|
||||
'atencao_basica_procedimento_atendimento_pequena_cirurgia.pequena_cirurgia_id'
|
||||
)
|
||||
->where('atencao_basica_procedimento_atendimento_pequena_cirurgia.procedimento_atendimento_id', $procedimento->id)
|
||||
->get();
|
||||
|
||||
foreach ($atendimentoProcedimentosPequenaCirurgia as $procedimentosPequenaCirurgia) {
|
||||
|
||||
if (isset($procedimentosPequenaCirurgia->codigo_procedimento)
|
||||
&& !empty(trim($procedimentosPequenaCirurgia->codigo_procedimento))
|
||||
) {
|
||||
$codigoPequenaCirurgia = $procedimentosPequenaCirurgia->codigo_procedimento;
|
||||
}
|
||||
else {
|
||||
$codigoPequenaCirurgia = $procedimentosPequenaCirurgia->codigo_esus;
|
||||
}
|
||||
|
||||
$atendProcedimento->appendChild($dom->createElement('procedimentos', $codigoPequenaCirurgia ));
|
||||
}
|
||||
|
||||
$atendimentoProcedimentosTesteRapido = DB::table('atencao_basica_procedimento_atendimento_teste_rapido')
|
||||
->select([
|
||||
'atencao_basica_cadastro_teste_rapido.codigo_esus',
|
||||
'atencao_basica_cadastro_teste_rapido.codigo_procedimento',
|
||||
])
|
||||
->join(
|
||||
'atencao_basica_cadastro_teste_rapido',
|
||||
'atencao_basica_cadastro_teste_rapido.id',
|
||||
'atencao_basica_procedimento_atendimento_teste_rapido.teste_rapido_id'
|
||||
)
|
||||
->where('atencao_basica_procedimento_atendimento_teste_rapido.procedimento_atendimento_id', $procedimento->id)
|
||||
->get();
|
||||
|
||||
foreach ($atendimentoProcedimentosTesteRapido as $procedimentosTesteRapido) {
|
||||
|
||||
if (isset($procedimentosTesteRapido->codigo_procedimento)
|
||||
&& !empty(trim($procedimentosTesteRapido->codigo_procedimento))
|
||||
) {
|
||||
$codigoTesteRapido = $procedimentosTesteRapido->codigo_procedimento;
|
||||
}
|
||||
else {
|
||||
$codigoTesteRapido = $procedimentosTesteRapido->codigo_esus;
|
||||
}
|
||||
|
||||
$atendProcedimento->appendChild($dom->createElement('procedimentos', $codigoTesteRapido));
|
||||
}
|
||||
|
||||
$atendimentoProcedimentosViaAdministracao = DB::table('atencao_basica_procedimento_via_administracao')
|
||||
->select([
|
||||
'atencao_basica_cadastro_via_administracao.codigo_esus',
|
||||
'atencao_basica_cadastro_via_administracao.codigo_procedimento',
|
||||
])
|
||||
->join(
|
||||
'atencao_basica_cadastro_via_administracao',
|
||||
'atencao_basica_cadastro_via_administracao.id',
|
||||
'atencao_basica_procedimento_via_administracao.via_administracao_id'
|
||||
)
|
||||
->where('atencao_basica_procedimento_via_administracao.procedimento_atendimento_id', $procedimento->id)
|
||||
->get();
|
||||
|
||||
foreach ($atendimentoProcedimentosViaAdministracao as $procedimentosViaAdministracao) {
|
||||
|
||||
if (isset($procedimentosViaAdministracao->codigo_procedimento)
|
||||
&& !empty(trim($procedimentosViaAdministracao->codigo_procedimento))
|
||||
) {
|
||||
$codigoViaAdministracao = $procedimentosViaAdministracao->codigo_procedimento;
|
||||
}
|
||||
else {
|
||||
$codigoViaAdministracao = $procedimentosViaAdministracao->codigo_esus;
|
||||
}
|
||||
|
||||
$atendProcedimento->appendChild($dom->createElement('procedimentos', $codigoViaAdministracao));
|
||||
}
|
||||
|
||||
$codigoProcedimentoPequenaCirurgia = $atendimentoProcedimentosPequenaCirurgia->pluck('codigo_procedimento')->toArray();
|
||||
$codigoProcedimentoTesteRapido = $atendimentoProcedimentosTesteRapido->pluck('codigo_procedimento')->toArray();
|
||||
$codigoProcedimentoViaAdministracao = $atendimentoProcedimentosViaAdministracao->pluck('codigo_procedimento')->toArray();
|
||||
|
||||
$atendimentoProcedimentos = DB::table('atencao_basica_procedimento_atendimento_procedimento')
|
||||
->select([
|
||||
'procedimento.codigo',
|
||||
])
|
||||
->join(
|
||||
'sigtap.procedimento as procedimento',
|
||||
'procedimento.id',
|
||||
'atencao_basica_procedimento_atendimento_procedimento.procedimento_id'
|
||||
)
|
||||
->join(
|
||||
'atencao_basica_procedimento_atendimento',
|
||||
'atencao_basica_procedimento_atendimento.id',
|
||||
'atencao_basica_procedimento_atendimento_procedimento.procedimento_atendimento_id'
|
||||
)
|
||||
->where('atencao_basica_procedimento_atendimento_procedimento.procedimento_atendimento_id', $procedimento->id)
|
||||
->whereNotIn('procedimento.codigo', $codigoProcedimentoPequenaCirurgia)
|
||||
->whereNotIn('procedimento.codigo', $codigoProcedimentoTesteRapido)
|
||||
->whereNotIn('procedimento.codigo', $codigoProcedimentoViaAdministracao)
|
||||
->where(function ($query) {
|
||||
$query->whereNull('atencao_basica_procedimento_atendimento.atendimento_individual_id')
|
||||
->orWhere(function($query) {
|
||||
$query->whereNotNull('atencao_basica_procedimento_atendimento.atendimento_individual_id')
|
||||
->where('procedimento.codigo', 'NOT LIKE', '09%');
|
||||
});
|
||||
})
|
||||
->get();
|
||||
|
||||
foreach ($atendimentoProcedimentos as $procedimento) {
|
||||
|
||||
$atendProcedimento->appendChild($dom->createElement('procedimentos', $procedimento->codigo));
|
||||
}
|
||||
}
|
||||
|
||||
private static function sexo($sexo_id) {
|
||||
$sexo = null;
|
||||
|
||||
if ($sexo_id === Sexo::MASCULINO) {
|
||||
$sexo = ExportacaoSexo::MASCULINO;
|
||||
}
|
||||
else if ($sexo_id === Sexo::FEMININO) {
|
||||
$sexo = ExportacaoSexo::FEMININO;
|
||||
}
|
||||
else if ($sexo_id === Sexo::INDETERMINADO) {
|
||||
$sexo = ExportacaoSexo::INDETERMINADO;
|
||||
}
|
||||
else {
|
||||
$sexo = ExportacaoSexo::IGNORADO;
|
||||
}
|
||||
|
||||
return $sexo;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user