Пример #1
0
        public IActionResult Create()
        {
            var model = new ExameViewModel();

            model.GroupsList = _groupsService.GetAllGroups();
            return(View(model));
        }
Пример #2
0
        public async Task <IActionResult> Edit(Guid id, ExameViewModel exameViewModel)
        {
            if (id != exameViewModel.Id)
            {
                return(NotFound());
            }

            if (!ModelState.IsValid)
            {
                return(View(exameViewModel));
            }

            exameViewModel.Nome = exameViewModel.Nome.Trim().ToUpper();

            var jaCadastrado = await _exameRepository.JaCadastradoMesmoNome(exameViewModel.Nome);

            if (jaCadastrado)
            {
                ModelState.AddModelError(string.Empty, "Esse tipo de exame já foi cadastrado!");
                return(View(exameViewModel));
            }

            var exame = _mapper.Map <Exame>(exameViewModel);
            await _exameRepository.Atualizar(exame);

            return(RedirectToAction("Index"));
        }
Пример #3
0
        public PaginaDeResultado <ExameViewModel> GetAllExame(int PaginaNumero, int PaginaTamanho)
        {
            var model = new ExameViewModel();

            try
            {
                int ExcludeRecords = (PaginaTamanho * PaginaNumero) - PaginaNumero;
                List <ExameViewModel> detalheList = new List <ExameViewModel>();
                var modelList = _unitOfWork.GenericRepository <Exame>().GetAll()
                                .Skip(ExcludeRecords).Take(PaginaTamanho).ToList();
                var contaTotal = _unitOfWork.GenericRepository <Exame>().GetAll().ToList();

                detalheList = ExameListInfo(modelList);
                if (detalheList != null)
                {
                    model.ExameList  = detalheList;
                    model.ContaTotal = contaTotal.Count();
                }
            }
            catch (Exception ex)
            {
                _ILogger.LogError(ex.Message);
            }
            var resultado = new PaginaDeResultado <ExameViewModel>
            {
                Data          = model.ExameList,
                TotalItems    = model.ContaTotal,
                PaginaNumero  = PaginaNumero,
                PaginaTamanho = PaginaTamanho,
            };

            return(resultado);
        }
Пример #4
0
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            Exame exame = db.Exames.Find(id);

            if (exame == null)
            {
                return(HttpNotFound());
            }

            ExameViewModel tipoExameViewModel = new ExameViewModel();
            var            tipoExames         = db.TiposExames.ToList();

            foreach (var item in tipoExames)
            {
                tipoExameViewModel.ListarTiposExamesViewModel.Add(new SelectListItem()
                {
                    Text  = Convert.ToString(item.TipoExameID) + " - " + item.NomeTipoExame,
                    Value = Convert.ToString(item.TipoExameID),
                });
            }

            tipoExameViewModel.ExameID         = exame.ExameID;
            tipoExameViewModel.TipoExameID     = exame.TipoExameID;
            tipoExameViewModel.NomeExame       = exame.NomeExame;
            tipoExameViewModel.ObservacaoExame = exame.ObservacaoExame;

            return(View(tipoExameViewModel));
        }
Пример #5
0
 public IActionResult Edit(ExameViewModel exameViewModel)
 {
     ViewBag.VirusBacteria = new SelectList(_virusBacteriaContext.GetAll(), "IdVirusBacteria", "Nome");
     ViewBag.AreaAtuacao   = new SelectList(_areaAtuacaoContext.GetAll(), "IdAreaAtuacao", "Descricao");
     ViewBag.googleKey     = _configuration["GOOGLE_KEY"];
     if (!ModelState.IsValid)
     {
         return(View(exameViewModel));
     }
     try
     {
         exameViewModel.Usuario = _usuarioContext.RetornLoggedUser((ClaimsIdentity)User.Identity).UsuarioModel;
         if (_exameContext.Update(exameViewModel))
         {
             TempData["mensagemSucesso"] = "Edição realizada com SUCESSO!";
         }
         else
         {
             TempData["mensagemErro"] = "Notificação DUPLICADA! Já existe um exame registrado desse paciente para esse Vírus/Bactéria na " +
                                        "data informada e método aplicado. Por favor, verifique se os dados da notificação estão corretos.";
         }
     }
     catch (ServiceException se)
     {
         TempData["mensagemErro"] = se.Message;
     }
     return(View(new ExameViewModel()));
 }
Пример #6
0
        public async Task <IActionResult> Create(ExameViewModel exameViewModel)
        {
            if (ModelState.IsValid)
            {
                await _exameService.AddExameAsync(exameViewModel);

                return(RedirectToAction(nameof(Index)));
            }
            return(View(exameViewModel));
        }
Пример #7
0
        public IActionResult Edit(ExameViewModel viewModel)
        {
            if (ModelState.IsValid)
            {
                return(SetViewModelByActionName(nameof(Edit), viewModel));
            }

            SetSelectList();
            return(View(viewModel));
        }
Пример #8
0
        public IActionResult Create(ExameViewModel exameViewModel)
        {
            ViewBag.googleKey      = _configuration["GOOGLE_KEY"];
            ViewBag.VirusBacteria  = new SelectList(_virusBacteriaContext.GetAll(), "IdVirusBacteria", "Nome");
            ViewBag.AreaAtuacao    = new SelectList(_areaAtuacaoContext.GetAll(), "IdAreaAtuacao", "Descricao");
            exameViewModel.Usuario = _usuarioContext.RetornLoggedUser((ClaimsIdentity)User.Identity).UsuarioModel;

            try
            {
                if (exameViewModel.PesquisarCpf == 1)
                {
                    var cpf    = Methods.RemoveSpecialsCaracts(exameViewModel.Paciente.Cpf);                  // cpf sem caracteres especiais
                    var pessoa = _pessoaContext.GetByCpf(cpf);
                    if (pessoa != null)
                    {
                        exameViewModel.Paciente = pessoa;
                        ModelState.Clear();
                        return(View(exameViewModel));
                    }
                    else
                    {
                        var exameVazio = new ExameViewModel();
                        exameVazio.Paciente.Cpf = exameViewModel.Paciente.Cpf;
                        ModelState.Clear();
                        return(View(exameVazio));
                    }
                }
                else
                {
                    if (ModelState.IsValid)
                    {
                        //_exameContext.CorrigeLocalizacao(exameViewModel.Paciente, _configuration["GOOGLE_KEY"]);

                        if (_exameContext.Insert(exameViewModel))
                        {
                            TempData["mensagemSucesso"] = "Notificação realizada com SUCESSO!";
                        }
                        else
                        {
                            TempData["mensagemErro"] = "Notificação DUPLICADA! Já existe um exame registrado desse paciente para esse Vírus/Bactéria na " +
                                                       "data informada e método aplicado. Por favor, verifique se os dados da notificação estão corretos.";
                        }
                    }
                    else
                    {
                        return(View(exameViewModel));
                    }
                }
            } catch (ServiceException se)
            {
                TempData["mensagemErro"] = se.Message;
            }

            return(RedirectToAction(nameof(Create)));
        }
Пример #9
0
        public async Task <ActionResult <ExameViewModel> > GetById(Guid id)
        {
            var exame = await _exameRepository.GetByIdAsync(id);

            var result = new ExameViewModel
            {
                Id        = exame.Id,
                Descricao = exame.Descricao,
                Preco     = exame.Preco
            };

            return(Ok(result));
        }
Пример #10
0
        public async Task <IActionResult> EnviarSMS(int id, PesquisaExameViewModel pesquisaExame, IFormCollection collection)
        {
            ExameViewModel exameView         = _exameContext.GetById(id);
            var            usuario           = _usuarioContext.RetornLoggedUser((ClaimsIdentity)User.Identity);
            var            trabalhaMunicipio = _pessoaTrabalhaMunicipioContext.GetByIdPessoa(usuario.UsuarioModel.IdPessoa);
            var            trabalhaEstado    = _pessoaTrabalhaEstadoContext.GetByIdPessoa(usuario.UsuarioModel.IdPessoa);

            try
            {
                string     statusAnteriorSMS = exameView.Exame.StatusNotificacao;
                ExameModel exame             = exameView.Exame;
                if (new Util.TelefoneCelularAttribute().IsValid(exameView.Paciente.FoneCelular))
                {
                    if (exame.StatusNotificacao.Equals(ExameModel.NOTIFICADO_ENVIADO))
                    {
                        exame = await _smsService.ConsultarSMSExameAsync(trabalhaEstado, trabalhaMunicipio, exame);
                    }
                    else if (exame.StatusNotificacao.Equals(ExameModel.NOTIFICADO_NAO) || exame.StatusNotificacao.Equals(ExameModel.NOTIFICADO_PROBLEMAS))
                    {
                        exame = await _smsService.EnviarSMSResultadoExameAsync(trabalhaEstado, trabalhaMunicipio, exame, exameView.Paciente);
                    }
                }
                if (statusAnteriorSMS.Equals(ExameModel.NOTIFICADO_ENVIADO) && exame.StatusNotificacao.Equals(ExameModel.NOTIFICADO_SIM))
                {
                    TempData["mensagemSucesso"] = "SMS foi entregue com SUCESSO!";
                }
                else if (statusAnteriorSMS.Equals(ExameModel.NOTIFICADO_NAO) && exame.StatusNotificacao.Equals(ExameModel.NOTIFICADO_ENVIADO))
                {
                    TempData["mensagemSucesso"] = "SMS enviado com SUCESSO!";
                }
                else if (statusAnteriorSMS.Equals(ExameModel.NOTIFICADO_NAO) && exame.StatusNotificacao.Equals(ExameModel.NOTIFICADO_NAO))
                {
                    TempData["mensagemErro"] = "Ocorreram problemas no envio do SMS. Favor conferir telefone e repetir operação em alguns minutos.";
                }
                else if (statusAnteriorSMS.Equals(ExameModel.NOTIFICADO_ENVIADO) && exame.StatusNotificacao.Equals(ExameModel.NOTIFICADO_ENVIADO))
                {
                    TempData["mensagemErro"] = "Ainda aguardando resposta da operadora. Favor repetir a consulta em alguns minutos.";
                }
                else if (statusAnteriorSMS.Equals(ExameModel.NOTIFICADO_ENVIADO) && exame.StatusNotificacao.Equals(ExameModel.NOTIFICADO_PROBLEMAS))
                {
                    TempData["mensagemErro"] = "Operadora não conseguiu entregar o SMS. Favor conferir telefone e repetir envio em alguns minutos.";
                }
            } catch (ServiceException se)
            {
                TempData["mensagemErro"] = se.Message;
            }

            return(RedirectToAction("Notificate", "Exame", pesquisaExame));
        }
Пример #11
0
 public ActionResult Edit(ExameViewModel exameViewModel)
 {
     if (ModelState.IsValid)
     {
         if (!_exameAppService.Atualizar(exameViewModel))
         {
             TempData["Mensagem"] = "Atenção, há um Exame com os mesmos dados já cadastrada')</SCRIPT>";
         }
         else
         {
             return(RedirectToAction("Index"));
         }
     }
     return(View(exameViewModel));
 }
Пример #12
0
        public async Task <ExameViewModel> AddExameAsync(ExameViewModel exameVM)
        {
            try
            {
                Exame objExame = exameVM.ConvertExameViewModel(exameVM);
                await _unitOfWork.GenericRepository <Exame>().AddAsync(objExame);

                _unitOfWork.Save();
            }
            catch (Exception ex)
            {
                return(null);
            }
            return(exameVM);
        }
Пример #13
0
        public bool Atualizar(ExameViewModel exameViewModel)
        {
            var exame = Mapper.Map <ExameViewModel, Exame>(exameViewModel);

            var examespRenovar = _exameService.Find(e => (e.FuncionarioId == exame.FuncionarioId) && (e.TipoExameId == exame.TipoExameId) && (e.Renovado == false) && (e.Delete == false) && (e.ExameId != exame.ExameId)).FirstOrDefault();

            BeginTransaction();
            if (examespRenovar != null)
            {
                examespRenovar.Renovado = true;
                _exameService.Atualizar(examespRenovar);
            }
            _exameService.Atualizar(exame);
            Commit();
            return(true);
        }
Пример #14
0
        public async Task <IActionResult> ConsultarSMSEnviados(List <ExameViewModel> exames, PesquisaExameViewModel pesquisaExame)
        {
            var usuario           = _usuarioContext.RetornLoggedUser((ClaimsIdentity)User.Identity);
            var trabalhaMunicipio = _pessoaTrabalhaMunicipioContext.GetByIdPessoa(usuario.UsuarioModel.IdPessoa);
            var trabalhaEstado    = _pessoaTrabalhaEstadoContext.GetByIdPessoa(usuario.UsuarioModel.IdPessoa);

            try
            {
                int entregasSucesso    = 0;
                int entregasFalhas     = 0;
                int entregasAguardando = 0;
                foreach (ExameViewModel exame in exames)
                {
                    ExameViewModel exameView = _exameContext.GetById(exame.Exame.IdExame);
                    if (new Util.TelefoneCelularAttribute().IsValid(exameView.Paciente.FoneCelular))
                    {
                        if (exameView.Exame.StatusNotificacao.Equals(ExameModel.NOTIFICADO_ENVIADO))
                        {
                            var exameNotificado = await _smsService.ConsultarSMSExameAsync(trabalhaEstado, trabalhaMunicipio, exameView.Exame);

                            if (exameNotificado.StatusNotificacao.Equals(ExameModel.NOTIFICADO_SIM))
                            {
                                entregasSucesso++;
                            }
                            else if (exameNotificado.StatusNotificacao.Equals(ExameModel.NOTIFICADO_PROBLEMAS))
                            {
                                entregasFalhas++;
                            }
                            else
                            {
                                entregasAguardando++;
                            }
                        }
                    }
                }
                string mensagem = "";
                mensagem += (entregasSucesso > 0) ? "Foram entregues " + entregasSucesso + " SMS com SUCESSO. " : "";
                mensagem += (entregasFalhas > 0) ? "Ocorreram problemas no envio de " + entregasFalhas + " SMS. " : "";
                mensagem += (entregasAguardando > 0) ? "Aguardando resposta da operadora de " + entregasAguardando + " SMS." : "";

                TempData["mensagemSucesso"] = "Consultas aos SMS enviadas com sucesso! " + mensagem;
            } catch (ServiceException se)
            {
                TempData["mensagemErro"] = se.Message;
            }
            return(RedirectToAction("Notificate", "Exame", pesquisaExame));
        }
Пример #15
0
 public IActionResult Put([FromBody] ExameViewModel viewModel)
 {
     try
     {
         _exameService.Update(viewModel.ToEntity());
         return(Ok());
     }
     catch (AppException ex)
     {
         return(SendFeedback(ex.Message));
     }
     catch (System.Exception ex)
     {
         _logger.LogError(ex.Message, ex, ex.InnerException);
         return(SendFeedback(_unavailable));
     }
 }
Пример #16
0
 public ActionResult Create(ExameViewModel exameViewModel)
 {
     if (ModelState.IsValid)
     {
         if (!_exameAppService.Adicionar(exameViewModel))
         {
             TempData["Mensagem"] = "Atenção, há um Exame com os mesmos dados";
         }
         else
         {
             return(RedirectToAction("Index"));
         }
     }
     ViewBag.FuncionarioId = new SelectList(_funcionarioAppService.ObterTodos(), "FuncionarioId", "Nome", exameViewModel.FuncionarioId);
     ViewBag.TipoExameId   = new SelectList(_tipoExameAppService.ObterTodos(), "TipoExameId", "Nome", exameViewModel.TipoExameId);
     return(View(exameViewModel));
 }
Пример #17
0
        public ActionResult Create()
        {
            ExameViewModel tipoExameViewModel = new ExameViewModel();
            var            tipoExames         = db.TiposExames.ToList();

            foreach (var item in tipoExames)
            {
                tipoExameViewModel.ListarTiposExamesViewModel.Add(new SelectListItem()
                {
                    Text     = Convert.ToString(item.TipoExameID) + " - " + item.NomeTipoExame,
                    Value    = Convert.ToString(item.TipoExameID),
                    Selected = true
                });
            }

            return(View(tipoExameViewModel));
        }
Пример #18
0
        public IActionResult Create(ExameViewModel exameViewModel)
        {
            ViewBag.googleKey      = _configuration["GOOGLE_KEY"];
            ViewBag.VirusBacteria  = new SelectList(_virusBacteriaContext.GetAll(), "IdVirusBacteria", "Nome");
            ViewBag.AreaAtuacao    = new SelectList(_areaAtuacaoContext.GetAll(), "IdAreaAtuacao", "Descricao");
            exameViewModel.Usuario = _usuarioContext.RetornLoggedUser((ClaimsIdentity)User.Identity).UsuarioModel;

            try
            {
                if (exameViewModel.PesquisarCpf == 1)
                {
                    var cpf    = Methods.RemoveSpecialsCaracts(exameViewModel.Paciente.Cpf);                  // cpf sem caracteres especiais
                    var pessoa = _pessoaContext.GetByCpf(cpf);
                    if (pessoa != null)
                    {
                        exameViewModel.Paciente = pessoa;
                        ModelState.Clear();
                        return(View(exameViewModel));
                    }
                    else
                    {
                        var exameVazio = new ExameViewModel();
                        exameVazio.Paciente.Cpf = exameViewModel.Paciente.Cpf;
                        return(View(exameVazio));
                    }
                }
                else
                {
                    if (ModelState.IsValid)
                    {
                        _exameContext.Insert(exameViewModel);
                        TempData["mensagemSucesso"] = "Notificação realizada com SUCESSO!";
                    }
                    else
                    {
                        return(View(exameViewModel));
                    }
                }
            } catch (ServiceException se)
            {
                TempData["mensagemErro"] = se.Message;
            }

            return(RedirectToAction(nameof(Create)));
        }
Пример #19
0
        private IActionResult SetViewModelByActionName(string actionName, ExameViewModel viewModel)
        {
            HttpResponseMessage response = null;
            string messageFeedback       = "";

            try
            {
                switch (actionName)
                {
                case nameof(Delete):
                    response        = _client.DeleteAsync($"exame/{viewModel.ExameId}").Result;
                    messageFeedback = $"Exame {viewModel.Nome?.ToUpper()} deletado com sucesso.";
                    break;

                case nameof(Create):
                    var contentCreate = new StringContent(JsonConvert.SerializeObject(viewModel), Encoding.UTF8, "application/json");
                    response        = _client.PostAsync("exame", contentCreate).Result;
                    messageFeedback = $"Exame { viewModel.Nome?.ToUpper()} criado com sucesso.";
                    break;

                case nameof(Edit):
                    var contentEdit = new StringContent(JsonConvert.SerializeObject(viewModel), Encoding.UTF8, "application/json");
                    response        = _client.PutAsync($"exame/{viewModel.ExameId}", contentEdit).Result;
                    messageFeedback = $"Exame {viewModel.Nome?.ToUpper()} editado com sucesso.";
                    break;
                }

                if (response.IsSuccessStatusCode)
                {
                    SendFeedback(false, messageFeedback);
                    return(RedirectToAction(nameof(Index)));
                }
                else
                {
                    return(SendFeedback(response));
                }
            }
            catch (System.Exception ex)
            {
                _logger.LogError(ex.Message, ex, ex.InnerException);
                return(SendFeedback(response));
            }
        }
Пример #20
0
 public IActionResult Edit(ExameViewModel exameViewModel)
 {
     ViewBag.VirusBacteria = new SelectList(_virusBacteriaContext.GetAll(), "IdVirusBacteria", "Nome");
     ViewBag.AreaAtuacao   = new SelectList(_areaAtuacaoContext.GetAll(), "IdAreaAtuacao", "Descricao");
     ViewBag.googleKey     = _configuration["GOOGLE_KEY"];
     if (!ModelState.IsValid)
     {
         return(View(exameViewModel));
     }
     try
     {
         exameViewModel.Usuario = _usuarioContext.RetornLoggedUser((ClaimsIdentity)User.Identity).UsuarioModel;
         _exameContext.Update(exameViewModel);
     }
     catch (ServiceException se)
     {
         TempData["mensagemErro"] = se.Message;
     }
     TempData["mensagemSucesso"] = "Edição realizada com SUCESSO!";
     return(View(new ExameViewModel()));
 }
Пример #21
0
 private Exame ModelToEntityImportacao(ExameViewModel item, ExameModel exame)
 {
     return(new Exame
     {
         IdExame = exame != null ? exame.IdExame : 0,
         IdPaciente = item.Paciente.Idpessoa,
         IdVirusBacteria = item.Exame.IdVirusBacteria,
         IdAgenteSaude = item.Exame.IdAgenteSaude,
         DataExame = item.Exame.DataExame,
         DataInicioSintomas = item.Exame.DataInicioSintomas,
         DataNotificacao = DateTime.Now,
         IgG = item.Exame.IgG,
         IgM = item.Exame.IgM,
         Pcr = item.Exame.Pcr,
         IgMigG = item.Exame.IgGIgM,
         IdMunicipio = item.Exame.IdMunicipio,
         IdEstado = item.Exame.IdEstado,
         IdEmpresaSaude = item.Exame.IdEmpresaSaude,
         IdAreaAtuacao = item.Exame.IdAreaAtuacao,
         CodigoColeta = item.Exame.CodigoColeta,
         PerdaOlfatoPaladar = Convert.ToByte(item.Exame.PerdaOlfatoPaladar),
         Febre = Convert.ToByte(item.Exame.Febre),
         Tosse = Convert.ToByte(item.Exame.Tosse),
         Coriza = Convert.ToByte(item.Exame.Coriza),
         DificuldadeRespiratoria = Convert.ToByte(item.Exame.DificuldadeRespiratoria),
         DorGarganta = Convert.ToByte(item.Exame.DorGarganta),
         Diarreia = Convert.ToByte(item.Exame.Diarreia),
         DorOuvido = Convert.ToByte(item.Exame.DorOuvido),
         Nausea = Convert.ToByte(item.Exame.Nausea),
         DorAbdominal = Convert.ToByte(item.Exame.DorAbdominal),
         IdNotificacao = "",
         OutroSintomas = "",
         MetodoExame = item.Exame.MetodoExame,
         StatusNotificacao = exame != null ? exame.StatusNotificacao : "N"
     });
 }
Пример #22
0
        public static Exame ToEntity(this ExameViewModel viewModel)
        {
            IMapper mapper = ExameToExameViewModelConfig().CreateMapper();

            return(mapper.Map <Exame>(viewModel));
        }
Пример #23
0
        public void Import(IFormFile file, UsuarioViewModel agente)
        {
            var _pessoaTrabalhaMunicipioService = new PessoaTrabalhaMunicipioService(_context);
            var _pessoaTrabalhaEstadoContext    = new PessoaTrabalhaEstadoService(_context);
            var _municipioGeoService            = new MunicipioGeoService(_context);
            var _virusBacteriaService           = new VirusBacteriaService(_context);
            var _pessoaService         = new PessoaService(_context);
            var _empresaExameService   = new EmpresaExameService(_context);
            var _situacaoPessoaService = new SituacaoVirusBacteriaService(_context);
            var _municipioService      = new MunicipioService(_context);
            var _estadoService         = new EstadoService(_context);
            var _exameService          = new ExameService(_context);
            var secretarioMunicipio    = _pessoaTrabalhaMunicipioService.GetByIdPessoa(agente.UsuarioModel.IdPessoa);
            var secretarioEstado       = _pessoaTrabalhaEstadoContext.GetByIdPessoa(agente.UsuarioModel.IdPessoa);
            var examesPlanilha         = new List <ExameViewModel>();
            var indices           = new IndiceItemArquivoImportacao();
            var listVirusBacteria = _virusBacteriaService.GetAll();

            string[] line = { };
            Dictionary <string, MunicipioGeoModel> mapCidade      = new Dictionary <string, MunicipioGeoModel>();
            Dictionary <string, EstadoModel>       mapEstado      = new Dictionary <string, EstadoModel>();
            Dictionary <string, EstadoModel>       mapSiglaEstado = new Dictionary <string, EstadoModel>();
            MunicipioModel municipioSecretario = null;

            if (secretarioMunicipio != null)
            {
                municipioSecretario = _municipioService.GetById(secretarioMunicipio.IdMunicipio);
            }

            using (var reader = new StreamReader(file.OpenReadStream(), Encoding.UTF7))
            {
                var cabecalho = reader.ReadLine();
                indices = IndexaColunasArquivoGal(cabecalho) ?? IndexaColunasArquivoUFS(cabecalho);

                if (indices == null)
                {
                    throw new ServiceException("Essa planilha não possui as informações necessárias para fazer a importação, " +
                                               "por favor verifique a planilha e tente novamente.");
                }

                if (indices.EhPlanilhaGal)
                {
                    line = reader.ReadLine().Split(';');
                    while (reader.Peek() >= 0 && String.Concat(line).Length > 0)
                    {
                        EstadoModel estadoPaciente = null;
                        if (line[indices.IndiceEstadoPaciente].Length > 2)
                        {
                            if (mapEstado.GetValueOrDefault(line[indices.IndiceEstadoPaciente]) == null)
                            {
                                mapEstado.Add(line[indices.IndiceEstadoPaciente], _estadoService.GetByName(line[indices.IndiceEstadoPaciente]));
                            }
                            estadoPaciente = mapEstado.GetValueOrDefault(line[indices.IndiceEstadoPaciente]);
                        }
                        else if (line[indices.IndiceEstadoPaciente].Length == 2)
                        {
                            if (mapSiglaEstado.GetValueOrDefault(line[indices.IndiceEstadoPaciente]) == null)
                            {
                                mapSiglaEstado.Add(line[indices.IndiceEstadoPaciente], _estadoService.GetByUf(line[indices.IndiceEstadoPaciente]));
                            }
                            estadoPaciente = mapSiglaEstado.GetValueOrDefault(line[indices.IndiceEstadoPaciente]);
                        }
                        if (mapCidade.GetValueOrDefault(line[indices.IndiceCidadePaciente]) == null)
                        {
                            mapCidade.Add(line[indices.IndiceCidadePaciente], _municipioGeoService.GetByName(line[indices.IndiceCidadePaciente], estadoPaciente.CodigoUf));
                        }
                        MunicipioGeoModel cidadePaciente = mapCidade.GetValueOrDefault(line[indices.IndiceCidadePaciente]);
                        if (mapCidade.GetValueOrDefault(line[indices.IndiceCidadeEmpresa]) == null)
                        {
                            mapCidade.Add(line[indices.IndiceCidadeEmpresa], _municipioGeoService.GetByName(line[indices.IndiceCidadeEmpresa], estadoPaciente.CodigoUf));
                        }
                        MunicipioGeoModel cidadeEmpresa = mapCidade.GetValueOrDefault(line[indices.IndiceCidadeEmpresa]);

                        var exame = new ExameViewModel
                        {
                            Paciente = new PessoaModel
                            {
                                Nome                                    = line[indices.IndiceNomePaciente],
                                Cidade                                  = line[indices.IndiceCidadePaciente],
                                Cep                                     = line[indices.IndiceCepPaciente].Length > 0 ? Methods.RemoveSpecialsCaracts(line[indices.IndiceCepPaciente]) : "00000000",
                                Bairro                                  = line[indices.IndiceBairroPaciente].Length > 0 && line[indices.IndiceBairroPaciente].Length < 60 ? line[indices.IndiceBairroPaciente] : "NAO INFORMADO",
                                Estado                                  = line[indices.IndiceEstadoPaciente].Length > 2 ? mapEstado.GetValueOrDefault(line[indices.IndiceEstadoPaciente]).Uf : line[indices.IndiceEstadoPaciente].ToUpper(),
                                FoneCelular                             = line[indices.IndiceFoneCelularPaciente],
                                DataNascimento                          = !line[indices.IndiceDataNascimentoPaciente].Equals("") ? Convert.ToDateTime(line[indices.IndiceDataNascimentoPaciente]) : DateTime.MinValue,
                                Longitude                               = cidadePaciente != null?cidadePaciente.Longitude.ToString() : "0",
                                                               Latitude = cidadePaciente != null?cidadePaciente.Latitude.ToString() : "0",
                                                                              IdAreaAtuacao      = 0,
                                                                              OutrasComorbidades = "",
                                                                              OutrosSintomas     = "",
                                                                              Cpf = line[indices.IndiceTipoDocumento1Paciente].Equals("CPF") && Methods.ValidarCpf(line[indices.IndiceDocumento1Paciente]) ?
                                                                                    Methods.RemoveSpecialsCaracts(line[indices.IndiceDocumento1Paciente]) : line[indices.IndiceTipoDocumento2Paciente].Equals("CPF") && Methods.ValidarCpf(line[indices.IndiceDocumento2Paciente]) ?
                                                                                    Methods.RemoveSpecialsCaracts(line[indices.IndiceDocumento2Paciente]) : "",
                                                                              Sexo   = line[indices.IndiceSexoPaciente].Equals("FEMININO") ? "F" : "M",
                                                                              Rua    = line[indices.IndiceRuaPaciente].Length > 0 && line[indices.IndiceRuaPaciente].Length < 60 ? line[indices.IndiceRuaPaciente].Split('-')[0] : "NÃO INFORMADO",
                                                                              Numero = line[indices.IndiceRuaPaciente].Length > 0 && line[indices.IndiceRuaPaciente].Split('-').Length >= 2 ?
                                                                                       (Methods.SoContemNumeros(line[indices.IndiceRuaPaciente].Split('-')[1].Trim()) ? line[indices.IndiceRuaPaciente].Split('-')[1].Trim() : "") : "",
                                                                              Complemento = line[indices.IndiceRuaPaciente].Length > 0 && line[indices.IndiceRuaPaciente].Split('-').Length == 3 ?
                                                                                            (line[indices.IndiceRuaPaciente].Split('-')[2].Trim().Length < 100 ? line[indices.IndiceRuaPaciente].Split('-')[2].Trim() : "") : "",
                                                                              Cns       = line[indices.IndiceCnsPaciente],
                                                                              Profissao = "NÃO INFORMADA",
                            },

                            Exame = new ExameModel
                            {
                                IdAgenteSaude = agente.UsuarioModel.IdPessoa,
                                DataExame     = Convert.ToDateTime(line[indices.IndiceDataExame]),
                                IdEstado      = secretarioMunicipio != null?Convert.ToInt32(municipioSecretario.Uf) : secretarioEstado.IdEstado,
                                                    IdAreaAtuacao      = 0,
                                                    CodigoColeta       = line[indices.IndiceCodigoColeta],
                                                    MetodoExame        = "F",
                                                    IdVirusBacteria    = GetIdVirusBacteriaItemImportacao(line[indices.IndiceTipoExame], listVirusBacteria),
                                                    DataInicioSintomas = line[indices.IndiceDataInicioSintomas].Equals("") ? Convert.ToDateTime(line[indices.IndiceDataExame]) : Convert.ToDateTime(line[indices.IndiceDataInicioSintomas]),
                                                    IgG    = line[indices.IndiceMetodoExame].ToUpper().Contains(IndiceItemArquivoImportacao.METODO_IGG) && !line[indices.IndiceMetodoExame].ToUpper().Contains(IndiceItemArquivoImportacao.METODO_IGM) ? GetMetodoExameImportacao(line[indices.IndiceMetodoExame], IndiceItemArquivoImportacao.METODO_IGG, line[indices.IndiceResultadoExame].Length > 0 ? line[indices.IndiceResultadoExame] : line[indices.IndiceObservacaoExame]) : "N",
                                                    IgM    = line[indices.IndiceMetodoExame].ToUpper().Contains(IndiceItemArquivoImportacao.METODO_IGM) && !line[indices.IndiceMetodoExame].ToUpper().Contains(IndiceItemArquivoImportacao.METODO_IGG) ? GetMetodoExameImportacao(line[indices.IndiceMetodoExame], IndiceItemArquivoImportacao.METODO_IGM, line[indices.IndiceResultadoExame].Length > 0 ? line[indices.IndiceResultadoExame] : line[indices.IndiceObservacaoExame]) : "N",
                                                    Pcr    = line[indices.IndiceMetodoExame].ToUpper().Contains(IndiceItemArquivoImportacao.METODO_PCR) ? GetMetodoExameImportacao(line[indices.IndiceMetodoExame], IndiceItemArquivoImportacao.METODO_PCR, line[indices.IndiceResultadoExame].Length > 0 ? line[indices.IndiceResultadoExame] : line[indices.IndiceObservacaoExame]) : "N",
                                                    IgGIgM = line[indices.IndiceMetodoExame].ToUpper().Contains(IndiceItemArquivoImportacao.METODO_IGG) && line[indices.IndiceMetodoExame].ToUpper().Contains(IndiceItemArquivoImportacao.METODO_IGM) ? GetMetodoExameImportacao(line[indices.IndiceMetodoExame], IndiceItemArquivoImportacao.METODO_IGG_IGM, line[indices.IndiceResultadoExame].Length > 0 ? line[indices.IndiceResultadoExame] : line[indices.IndiceObservacaoExame]) : "N",
                            },

                            EmpresaExame = new EmpresaExameModel
                            {
                                Cnpj     = "NÃO INFORMADO",
                                Nome     = line[indices.IndiceNomeEmpresa],
                                Cnes     = line[indices.IndiceCnesEmpresa],
                                Cidade   = line[indices.IndiceCidadeEmpresa],
                                Latitude = cidadeEmpresa != null?cidadeEmpresa.Latitude.ToString() : "0",
                                               Longitude = cidadeEmpresa != null?cidadeEmpresa.Longitude.ToString() : "0",
                                                               Estado      = line[indices.IndiceEstadoEmpresa],
                                                               Rua         = "NÃO INFORMADO",
                                                               Bairro      = "NÃO INFORMADO",
                                                               Cep         = "00000000",
                                                               FoneCelular = "00000000000",
                            },
                        };

                        if (secretarioMunicipio != null)
                        {
                            exame.Exame.IdMunicipio = secretarioMunicipio.IdMunicipio;
                        }
                        else
                        {
                            exame.Exame.IdMunicipio = null;
                        }

                        examesPlanilha.Add(exame);

                        line = reader.ReadLine().Split(';');
                    }
                }
                else
                {
                    line = reader.ReadLine().Split(';');
                    //MunicipioGeoModel cidadePaciente;
                    while (reader.Peek() >= 0 && String.Concat(line).Length > 0)
                    {
                        EstadoModel estadoPaciente = null;
                        if (line[indices.IndiceEstadoPaciente].Length > 2)
                        {
                            if (mapEstado.GetValueOrDefault(line[indices.IndiceEstadoPaciente]) == null)
                            {
                                mapEstado.Add(line[indices.IndiceEstadoPaciente], _estadoService.GetByName(line[indices.IndiceEstadoPaciente]));
                            }
                            estadoPaciente = mapEstado.GetValueOrDefault(line[indices.IndiceEstadoPaciente]);
                        }
                        else if (line[indices.IndiceEstadoPaciente].Length == 2)
                        {
                            if (mapSiglaEstado.GetValueOrDefault(line[indices.IndiceEstadoPaciente]) == null)
                            {
                                mapSiglaEstado.Add(line[indices.IndiceEstadoPaciente], _estadoService.GetByUf(line[indices.IndiceEstadoPaciente]));
                            }
                            estadoPaciente = mapSiglaEstado.GetValueOrDefault(line[indices.IndiceEstadoPaciente]);
                        }
                        if (mapCidade.GetValueOrDefault(line[indices.IndiceCidadePaciente]) == null)
                        {
                            mapCidade.Add(line[indices.IndiceCidadePaciente], _municipioGeoService.GetByName(line[indices.IndiceCidadePaciente], estadoPaciente.CodigoUf));
                        }
                        MunicipioGeoModel cidadePaciente = mapCidade.GetValueOrDefault(line[indices.IndiceCidadePaciente]);
                        if (mapCidade.GetValueOrDefault(line[indices.IndiceCidadeEmpresa]) == null)
                        {
                            mapCidade.Add(line[indices.IndiceCidadeEmpresa], _municipioGeoService.GetByName(line[indices.IndiceCidadeEmpresa], estadoPaciente.CodigoUf));
                        }
                        MunicipioGeoModel cidadeEmpresa = mapCidade.GetValueOrDefault(line[indices.IndiceCidadeEmpresa]);
                        var exame = new ExameViewModel
                        {
                            Paciente = new PessoaModel
                            {
                                Nome                                    = line[indices.IndiceNomePaciente],
                                Cidade                                  = line[indices.IndiceCidadePaciente],
                                Cep                                     = line[indices.IndiceCepPaciente].Length > 0 ? Methods.RemoveSpecialsCaracts(line[indices.IndiceCepPaciente]) : "00000000",
                                Bairro                                  = line[indices.IndiceBairroPaciente].Length > 0 && line[indices.IndiceBairroPaciente].Length < 60 ? line[indices.IndiceBairroPaciente] : "NAO INFORMADO",
                                Estado                                  = line[indices.IndiceEstadoPaciente].Length > 2 ? estadoPaciente.Uf : line[indices.IndiceEstadoPaciente].ToUpper(),
                                FoneCelular                             = line[indices.IndiceFoneCelularPaciente],
                                DataNascimento                          = !line[indices.IndiceDataNascimentoPaciente].Equals("") ? Convert.ToDateTime(line[indices.IndiceDataNascimentoPaciente]) : DateTime.MinValue,
                                Longitude                               = cidadePaciente != null?cidadePaciente.Longitude.ToString() : "0",
                                                               Latitude = cidadePaciente != null?cidadePaciente.Latitude.ToString() : "0",
                                                                              IdAreaAtuacao      = 0,
                                                                              OutrasComorbidades = "",
                                                                              OutrosSintomas     = "",
                                                                              Sexo               = "M",
                                                                              Rua                = line[indices.IndiceRuaPaciente].Length > 0 && line[indices.IndiceRuaPaciente].Length < 60 ? line[indices.IndiceRuaPaciente] : "NÃO INFORMADO",
                                                                              Numero             = line[indices.IndicenNumeroResidenciaPaciente].Length > 0 ? line[indices.IndicenNumeroResidenciaPaciente] : "",
                                                                              Complemento        = line[indices.IndiceComplementoPaciente].Length > 0 ? line[indices.IndiceComplementoPaciente] : "",
                                                                              Cpf                = line[indices.IndiceCpfPaciente].Length > 0 && Methods.ValidarCpf(line[indices.IndiceCpfPaciente]) ? line[indices.IndiceCpfPaciente] : "",
                                                                              Profissao          = line[indices.IndiceProfissaoPaciente],
                                                                              Hipertenso         = VerificaSintomaOuDoencaImportacao(line, indices.IndicesDoencaPacienteUfs, IndiceItemArquivoImportacao.DOENCA_HIPERTENSAO),
                                                                              Diabetes           = VerificaSintomaOuDoencaImportacao(line, indices.IndicesDoencaPacienteUfs, IndiceItemArquivoImportacao.DOENCA_DIABETES),
                                                                              Obeso              = VerificaSintomaOuDoencaImportacao(line, indices.IndicesDoencaPacienteUfs, IndiceItemArquivoImportacao.DOENCA_OBESIDADE),
                                                                              Cardiopatia        = VerificaSintomaOuDoencaImportacao(line, indices.IndicesDoencaPacienteUfs, IndiceItemArquivoImportacao.DOENCA_CARDIOPATIA),
                                                                              Imunodeprimido     = VerificaSintomaOuDoencaImportacao(line, indices.IndicesDoencaPacienteUfs, IndiceItemArquivoImportacao.DEONCA_IMUNODEPRIMIDO),
                                                                              Cancer             = VerificaSintomaOuDoencaImportacao(line, indices.IndicesDoencaPacienteUfs, IndiceItemArquivoImportacao.DEONCA_CANCER),
                                                                              DoencaRespiratoria = VerificaSintomaOuDoencaImportacao(line, indices.IndicesDoencaPacienteUfs, IndiceItemArquivoImportacao.DOENCA_RESPIRATORIA),
                                                                              DoencaRenal        = VerificaSintomaOuDoencaImportacao(line, indices.IndicesDoencaPacienteUfs, IndiceItemArquivoImportacao.DOENCA_RENAL),
                                                                              Epilepsia          = VerificaSintomaOuDoencaImportacao(line, indices.IndicesDoencaPacienteUfs, IndiceItemArquivoImportacao.DEONCA_EPILESIA),
                            },

                            Exame = new ExameModel
                            {
                                IdAgenteSaude = agente.UsuarioModel.IdPessoa,
                                DataExame     = Convert.ToDateTime(line[indices.IndiceDataExame]),
                                IdEstado      = secretarioMunicipio != null?Convert.ToInt32(municipioSecretario.Uf) : secretarioEstado.IdEstado,
                                                    IdAreaAtuacao      = 0,
                                                    CodigoColeta       = line[indices.IndiceCodigoColeta],
                                                    MetodoExame        = "F",
                                                    PerdaOlfatoPaladar = VerificaSintomaOuDoencaImportacao(line, indices.IndicesSintomasPacienteUfs, IndiceItemArquivoImportacao.SINTOMA_PERDA_OLFATO),
                                                    Febre  = VerificaSintomaOuDoencaImportacao(line, indices.IndicesSintomasPacienteUfs, IndiceItemArquivoImportacao.SINTOMA_FEBRE),
                                                    Tosse  = VerificaSintomaOuDoencaImportacao(line, indices.IndicesSintomasPacienteUfs, IndiceItemArquivoImportacao.SINTOMA_TOSSE),
                                                    Coriza = VerificaSintomaOuDoencaImportacao(line, indices.IndicesSintomasPacienteUfs, IndiceItemArquivoImportacao.SINTOMA_CORIZA),
                                                    DificuldadeRespiratoria = VerificaSintomaOuDoencaImportacao(line, indices.IndicesSintomasPacienteUfs, IndiceItemArquivoImportacao.SINTOMA_DIFICULDADE_RESPIRATORIA),
                                                    DorGarganta             = VerificaSintomaOuDoencaImportacao(line, indices.IndicesSintomasPacienteUfs, IndiceItemArquivoImportacao.SINTOMA_DOR_DE_GARGANTA),
                                                    Diarreia           = VerificaSintomaOuDoencaImportacao(line, indices.IndicesSintomasPacienteUfs, IndiceItemArquivoImportacao.SINTOMA_DIARREIA),
                                                    DorOuvido          = VerificaSintomaOuDoencaImportacao(line, indices.IndicesSintomasPacienteUfs, IndiceItemArquivoImportacao.SINTOMA_DOR_DE_OUVIDO),
                                                    Nausea             = VerificaSintomaOuDoencaImportacao(line, indices.IndicesSintomasPacienteUfs, IndiceItemArquivoImportacao.SINTOMA_NAUSEAS),
                                                    DorAbdominal       = VerificaSintomaOuDoencaImportacao(line, indices.IndicesSintomasPacienteUfs, IndiceItemArquivoImportacao.SINTOMA_DORES_E_DESCONFORTO),
                                                    IdVirusBacteria    = GetIdVirusBacteriaItemImportacao("COVID-19", listVirusBacteria),
                                                    DataInicioSintomas = Convert.ToDateTime(line[indices.IndiceDataExame]),
                                                    IgG            = "N",
                                                    IgM            = line[indices.IndiceRealizouTeste].ToUpper().Contains("POSITIVO") ? "S" : "N",
                                                    Pcr            = "N",
                                                    IgGIgM         = "N",
                                                    IdEmpresaSaude = EmpresaExameModel.EMPRESA_ESTADO_MUNICIPIO,
                            },
                        };

                        if (secretarioMunicipio != null)
                        {
                            exame.Exame.IdMunicipio = secretarioMunicipio.IdMunicipio;
                        }
                        else
                        {
                            exame.Exame.IdMunicipio = null;
                        }

                        examesPlanilha.Add(exame);

                        line = reader.ReadLine().Split(';');
                    }
                }
            }

            foreach (var exameView in examesPlanilha)
            {
                var exameGravado = _context.Exame
                                   .Where(e => e.CodigoColeta.Equals(exameView.Exame.CodigoColeta))
                                   .Select(ex => new
                {
                    IdExame   = ex.IdExame,
                    IdPessoa  = ex.IdPaciente,
                    IdEmpresa = ex.IdEmpresaSaude
                }).FirstOrDefault();
                if (exameGravado == null || (exameGravado != null && exameGravado.IdEmpresa < 1))
                {
                    var empresa = _empresaExameService.GetByCNES(exameView.EmpresaExame.Cnes);
                    if (empresa == null)
                    {
                        empresa = _empresaExameService.Insert(exameView.EmpresaExame);
                    }
                    exameView.Exame.IdEmpresaSaude = empresa.Id;
                }

                if (exameGravado == null)
                {
                    _exameService.Insert(exameView);
                }
                else
                {
                    _exameService.Update(exameView);
                }
            }
        }
Пример #24
0
 public IActionResult Delete(ExameViewModel viewModel)
 {
     return(SetViewModelByActionName(nameof(Delete), viewModel));
 }