Example #1
0
        public JsonResult CarregaMunicipios(int id)
        {
            SelectList municipios = new SelectList(MunicipioModel.ObterMunicipio(id), "mun_id_municipio", "mun_ds_municipio");

            ViewBag.Municipio = municipios;
            return(Json(municipios));
        }
Example #2
0
        private void PegaR1070(R1070Model r1070)
        {
            r1070.tpAmb   = tpAmb_comboBox.Text;
            r1070.procEmi = procEmi_comboBox.Text;
            r1070.verProc = verProc_textBox.Text;
            r1070.tpInsc  = tpInsc_comboBox.Text;

            r1070.nrInsc     = maskedRaw(nrInsc_textBox);
            r1070.tpProc     = tpProc_comboBox.Text;
            r1070.nrProc     = nrProc_textBox.Text;
            r1070.iniValid   = iniValidProc_dtp.Value.Date;
            r1070.fimValid   = fimValidProc_dtp.Value.Date;
            r1070.indAutoria = indAutoria_comboBox.Text;
            //r1070.codSusp = codSusp_textBox.Text;
            //r1070.indSusp = indSusp_comboBox.Text;
            //r1070.dtDecisao = dtDecisao_dtp.Value.Date;
            //r1070.indDeposito = indDeposito_checkbox.Text;
            r1070.ufVara = ufVara_comboBox.Text;

            MunicipioModel mu = (MunicipioModel)codMunic_comboBox.SelectedItem;

            if (mu != null)
            {
                r1070.codMunic = mu.codigo;
            }

            r1070.idVara       = idVara_textBox.Text;
            r1070.TipoOperacao = tipOper_comboBox.Text;

            r1070.DataHoraGeracaoEvento = DateTime.Now;
            r1070.IdentificacaoUnica    = "0";
        }
        public JsonResult LocalizarMunicipio(String municipio)
        {
            MunicipioModel   municipioModel = new MunicipioModel();
            List <Municipio> result         = municipioModel.listarMunicipios(municipio);

            return(Json(result, JsonRequestBehavior.AllowGet));
        }
Example #4
0
        // GET: IdentificacaoCrianca
        public ActionResult Index()
        {
            //carregar o objeto com base no id do usuário logado (pode estar na sessão, classe autenticação)
            // direcionar para a view passando o objeto carregado (objeto IdentificacaoCriancaModel)

            //ViewBag.UF = new SelectList(new Dictionary<int, string>() { { 1, "BA" }, { 2, "SP" } }, "key", "value");
            //ViewBag.Municipio = new SelectList(new Dictionary<int, string>() { { 1, "Salvador" }, { 2, "Feira de Santana" } }, "key", "value");

            ViewBag.Etnia = new SelectList(new Dictionary <string, string>()
            {
                { "1", "Branca" }, { "2", "Amarela" }, { "3", "Parda" }, { "4", "Negra" }, { "5", "Indigena" }
            }, "key", "value");
            ViewBag.UF = new SelectList(UFModel.ObterUF(), "uff_id_uf", "uff_ds_uf");



            int idUsuarioLogado = UsuarioModel.ObterUsuarioSessao().idUsuario;
            IdentificacaoCriancaModel identificacaoCrianca = IdentificacaoCriancaModel.ObterRegistro(idUsuarioLogado);

            identificacaoCrianca.dataNascimento = String.IsNullOrEmpty(identificacaoCrianca.dataNascimento)  ? "" : identificacaoCrianca.dataNascimento.ToString();
            ViewBag.Municipio = new SelectList(MunicipioModel.ObterMunicipio(identificacaoCrianca.idUf), "mun_id_municipio", "mun_ds_municipio");

            ViewBag.Mensagem = TempData["mensagem"] == null ? "" : TempData["mensagem"].ToString();
            return(View(identificacaoCrianca));
        }
        public void Teste_Mapper()
        {
            var model = new MunicipioModel
            {
                Id       = Guid.NewGuid(),
                Nome     = Faker.Address.City(),
                CodIBGE  = Faker.RandomNumber.Next(0000000, 9999999),
                UfId     = new Guid("e7e416de-477c-4fa3-a541-b5af5f35ccf6"),
                CreateAt = DateTime.Now,
                UpdateAt = DateTime.Now
            };

            var listaEntity = new List <MunicipioEntity>();

            for (int i = 0; i < 5; i++)
            {
                var item = new MunicipioEntity
                {
                    Id       = Guid.NewGuid(),
                    Nome     = Faker.Address.City(),
                    CodIBGE  = Faker.RandomNumber.Next(0000000, 9999999),
                    UfId     = new Guid("e7e416de-477c-4fa3-a541-b5af5f35ccf6"),
                    CreateAt = DateTime.Now,
                    UpdateAt = DateTime.Now
                };

                listaEntity.Add(item);
            }

            //Model to Entity
            var dtoToEntity = Mapper.Map <MunicipioEntity>(model);

            Assert.Equal(dtoToEntity.Id, model.Id);
            Assert.Equal(dtoToEntity.Nome, model.Nome);
            Assert.Equal(dtoToEntity.UfId, model.UfId);
            Assert.Equal(dtoToEntity.CreateAt, model.CreateAt);
            Assert.Equal(dtoToEntity.UpdateAt, model.UpdateAt);


            //Entity to DTO
            var UfDto = Mapper.Map <MunicipioDto>(dtoToEntity);

            Assert.Equal(UfDto.Id, dtoToEntity.Id);
            Assert.Equal(UfDto.Nome, dtoToEntity.Nome);
            Assert.Equal(UfDto.UfId, dtoToEntity.UfId);

            var listDto = Mapper.Map <List <MunicipioDto> >(listaEntity);

            Assert.True(listaEntity.Count == listDto.Count());
            for (int i = 0; i < listDto.Count(); i++)
            {
                Assert.Equal(listDto[i].Id, listaEntity[i].Id);
                Assert.Equal(listDto[i].Nome, listaEntity[i].Nome);
                Assert.Equal(listDto[i].UfId, listaEntity[i].UfId);
            }

            var ufModel = Mapper.Map <MunicipioDto>(dtoToEntity);
        }
        // GET: MudancaEndereco
        public ActionResult Index()
        {
            ViewBag.UF        = new SelectList(UFModel.ObterUF(), "uff_id_uf", "uff_ds_uf");
            ViewBag.Municipio = new SelectList(MunicipioModel.ObterMunicipio(0), "mun_id_municipio", "mun_ds_municipio");
            int idUsuarioLogado = UsuarioModel.ObterUsuarioSessao().idUsuario;

            ViewBag.Mensagem = TempData["mensagem"] == null ? "" : TempData["mensagem"].ToString();
            return(View(MudancaEnderecoModel.ObterRegistro(idUsuarioLogado)));
        }
Example #7
0
        // POST: api/Municipio
        public IHttpActionResult Post(MunicipioModel municipio)
        {
            Municipio municipioDomain;

            municipioDomain = Mapper.Map <MunicipioModel, Municipio>(municipio);
            municipioService.CreateMunicipio(municipioDomain);
            municipioService.Save();
            return(Created(string.Format("/api/municipio/{0}", municipio.Id), municipio));
        }
Example #8
0
        public MunicipioModel RetornaDadosMunicipioFacede(string codigo)
        {
            MunicipioModel model = new MunicipioModel();

            model.codigo = codigo;

            model = _business.GetOneMunicipio(model);

            return(model);
        }
Example #9
0
        public void Insert(MunicipioModel entidade)
        {
            var sql = $"INSERT INTO MUNICIPIO (MUNCODI,MUNNOME,ESTCODI) VALUES"
                      + $"('{entidade.MUNCODI}',"
                      + $"'{entidade.MUNNOME}',"
                      + $"'{entidade.ESTCODI}')";

            ExecuteNonResult(sql);
            MessageBox.Show("Registro inserido com sucesso !!!");
        }
Example #10
0
 public Municipio ModelToEntity(MunicipioModel municipio)
 {
     return(new Municipio
     {
         Id = municipio.Id,
         Nome = municipio.Nome,
         Uf = municipio.Uf,
         Codigo = municipio.Codigo,
     });
 }
Example #11
0
        public void Update(MunicipioModel entidade)
        {
            var sql = $"UPDATE MUNICIPIO SET "
                      + $"MUNCODI = '{entidade.MUNCODI}',"
                      + $"MUNNOME = '{entidade.MUNNOME}',"
                      + $"ESTCODI = '{entidade.ESTCODI}' "
                      + $"WHERE MUNCODI = { entidade.MUNCODI}";

            ExecuteNonResult(sql);
            MessageBox.Show("Registro gravado com sucesso !!!");
        }
Example #12
0
        public async Task <IHttpActionResult> Remove([FromBody] MunicipioModel model)
        {
            object result = await repository.Remove(rhNetContext, model);

            if (result.GetType() == typeof(MunicipioModel))
            {
                return(Ok(result));
            }
            else
            {
                return(BadRequest(result.ToString()));
            }
        }
        public MunicipioModel GetByCity(string name)
        {
            MunicipioModel obj = null;

            try
            {
                obj = DbSet.FirstOrDefault(x => x.MunNome == name);
            }
            catch (Exception ex)
            {
                _log.LogError(ex.Message, ex);
            }

            return(obj);
        }
Example #14
0
        public ActionResult Index()
        {
            ViewBag.UF        = new SelectList(UFModel.ObterUF(), "uff_id_uf", "uff_ds_uf");
            ViewBag.Municipio = new SelectList(MunicipioModel.ObterMunicipio(0), "mun_id_municipio", "mun_ds_municipio");
            int idUsuarioLogado        = UsuarioModel.ObterUsuarioSessao().idUsuario;
            DadosRecemNascidoModel obj = DadosRecemNascidoModel.ObterRegistro(idUsuarioLogado);

            if (obj.idUf > 0)
            {
                CarregaMunicipios(obj.idUf);
            }

            ViewBag.Mensagem = TempData["mensagem"] == null ? "" : TempData["mensagem"].ToString();
            return(View(obj));
        }
Example #15
0
        // PUT: api/Municipio/5
        public IHttpActionResult Put(int id, MunicipioModel municipio)
        {
            Municipio municipioDomain;

            municipioDomain = Mapper.Map <MunicipioModel, Municipio>(municipio);


            if (municipioService.GetMunicipio(id) == null)
            {
                return(NotFound());
            }
            municipioService.UpdateMunicipio(municipioDomain);
            municipioService.Save();
            return(Ok());
        }
        public MunicipioModel GetById(int id)
        {
            MunicipioModel obj = null;

            try
            {
                obj = DbSet.FirstOrDefault(x => x.id == id);
            }
            catch (Exception ex)
            {
                _log.LogError(ex.Message, ex);
            }

            return(obj);
        }
Example #17
0
        private string codMunic(string ufVaraX, string value)
        {
            if (ufVara(ufVaraX) == null)
            {
                string msg = "Município";

                List <string> ufSigla = new List <string>
                {
                    "AC", "AL", "AP", "AM", "BA", "CE", "DF", "ES", "GO", "MA", "MT", "MS", "MG", "PA",
                    "PB", "PR", "PE", "PI", "RJ", "RN", "RS", "RO", "RR", "SC", "SP", "SE", "TO", "EX",
                };

                List <int> ufCod = new List <int>
                {
                    12, 27, 16, 13, 29, 23, 53, 32, 52, 21, 51, 50, 31, 15,
                    25, 41, 26, 22, 33, 24, 43, 11, 14, 42, 35, 28, 17, 99
                };

                int cod = 0;

                for (int i = 0; i < ufSigla.Count; i++)
                {
                    if (ufSigla[i].Equals(ufVaraX))
                    {
                        cod = ufCod[i];
                        break;
                    }
                }

                MunicipioFacede facede = new MunicipioFacede();

                MunicipioModel model = facede.RetornaDadosMunicipioFacede(value);

                if (model == null)
                {
                    return(msg);
                }

                if (model.uf != cod)
                {
                    return(msg);
                }
            }

            return(null);
        }
Example #18
0
        public async Task <IHttpActionResult> Update([FromBody] MunicipioModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            object result = await repository.Update(rhNetContext, model);

            if (result.GetType() == typeof(MunicipioModel))
            {
                return(Ok(result));
            }
            else
            {
                return(BadRequest(result.ToString()));
            }
        }
Example #19
0
 public MunicipioModel Recuperar_Muni(long IdMunicipio)
 {
     try
     {
         string    Query           = String.Format("Select IdMunicipio,NombreMuni from Municipio where IdMunicipio='{0}'", IdMunicipio);
         var       Resultado       = _oConexionDAL.TablaConnsulta(Query);
         DataTable Datos           = Resultado;
         DataRow   Row             = Datos.Rows[0];
         var       oMunicipioModel = new MunicipioModel()
         {
             IdMunicipio = Convert.ToInt32(Row["IdMunicipio"]),
             NombreMuni  = Row["NombreMuni"].ToString()
         };
         return(oMunicipioModel);
     }
     catch (Exception)
     {
         return(null);
     }
 }
        public async Task <object> Remove(RhNetContext rhNetContext, MunicipioModel municipioModel)
        {
            Municipio municipio = await rhNetContext.Municipios.FindAsync(municipioModel.Id);

            if (municipio == null)
            {
                return("Município não encontrado.");
            }

            try
            {
                rhNetContext.Entry(municipio).State = EntityState.Deleted;
                await rhNetContext.SaveChangesAsync();

                return(municipioModel);
            }
            catch (DbUpdateException ex)
            {
                return(ex.InnerException.ToString());
            }
        }
Example #21
0
 public List <MunicipioModel> TablaMunicipios()
 {
     try
     {
         string Query     = ("Select IdMunicipio,NombreMuni from Municipio where StatusMuni=1");
         var    Resultado = _oConexionDAL.TablaConnsulta(Query);
         List <MunicipioModel> Municipios = new List <MunicipioModel>();
         foreach (DataRow Municipio in Resultado.Rows)
         {
             var _oMunicipioModel = new MunicipioModel()
             {
                 IdMunicipio = int.Parse(Municipio[0].ToString()),
                 NombreMuni  = Municipio[1].ToString()
             };
             Municipios.Add(_oMunicipioModel);
         }
         return(Municipios);
     }
     catch (Exception)
     {
         return(null);
     }
 }
        public async Task <object> Update(RhNetContext rhNetContext, MunicipioModel municipioModel)
        {
            Municipio municipio = await rhNetContext.Municipios.FindAsync(municipioModel.Id);

            if (municipio == null)
            {
                return("Município não encontrado.");
            }
            municipio.Descricao     = municipioModel.Descricao;
            municipio.Codigo_Audesp = municipioModel.Codigo_Audesp;

            try
            {
                rhNetContext.Entry(municipio).State = EntityState.Modified;
                await rhNetContext.SaveChangesAsync();

                return(municipioModel);
            }
            catch (DbUpdateException ex)
            {
                return(ex.InnerException.ToString());
            }
        }
        public async Task <object> Add(RhNetContext rhNetContext, MunicipioModel municipioModel)
        {
            Municipio municipio = new Municipio()
            {
                Codigo_Audesp = municipioModel.Codigo_Audesp,
                Descricao     = municipioModel.Descricao
            };

            try
            {
                rhNetContext.Entry(municipio).State = EntityState.Added;
                await rhNetContext.SaveChangesAsync();

                await rhNetContext.Entry(municipio).ReloadAsync();

                municipioModel.Id = municipio.Id;

                return(municipioModel);
            }
            catch (DbUpdateException ex)
            {
                return(ex.InnerException.ToString());
            }
        }
Example #24
0
 public MunicipioController()
 {
     oMunicipio = new MunicipioModel();
 }
        public void E_Possivel_Mapear_os_Modelos_Municipio()
        {
            var model = new MunicipioModel
            {
                Id       = Guid.NewGuid(),
                Nome     = Faker.Address.City(),
                CodIBGE  = Faker.RandomNumber.Next(1, 10000),
                UfId     = Guid.NewGuid(),
                CreateAt = DateTime.UtcNow,
                UpdateAt = DateTime.UtcNow
            };

            var listaEntity = new List <MunicipioEntity>();

            for (int i = 0; i < 5; i++)
            {
                var item = new MunicipioEntity
                {
                    Id       = Guid.NewGuid(),
                    Nome     = Faker.Address.City(),
                    CodIBGE  = Faker.RandomNumber.Next(1, 10000),
                    UfId     = Guid.NewGuid(),
                    CreateAt = DateTime.UtcNow,
                    UpdateAt = DateTime.UtcNow,
                    Uf       = new UfEntity
                    {
                        Id    = Guid.NewGuid(),
                        Nome  = Faker.Address.UsState(),
                        Sigla = Faker.Address.UsState().Substring(1, 3)
                    }
                };
                listaEntity.Add(item);
            }

            //Model => Entity
            var entity = Mapper.Map <MunicipioEntity>(model);

            Assert.Equal(entity.Id, model.Id);
            Assert.Equal(entity.Nome, model.Nome);
            Assert.Equal(entity.CodIBGE, model.CodIBGE);
            Assert.Equal(entity.UfId, model.UfId);
            Assert.Equal(entity.CreateAt, model.CreateAt);
            Assert.Equal(entity.UpdateAt, model.UpdateAt);

            //Entity para Dto
            var userDto = Mapper.Map <MunicipioDto>(entity);

            Assert.Equal(userDto.Id, entity.Id);
            Assert.Equal(userDto.Nome, entity.Nome);
            Assert.Equal(userDto.CodIBGE, entity.CodIBGE);
            Assert.Equal(userDto.UfId, entity.UfId);

            var userDtoCompleto = Mapper.Map <MunicipioDtoCompleto>(listaEntity.FirstOrDefault());

            Assert.Equal(userDtoCompleto.Id, listaEntity.FirstOrDefault().Id);
            Assert.Equal(userDtoCompleto.Nome, listaEntity.FirstOrDefault().Nome);
            Assert.Equal(userDtoCompleto.CodIBGE, listaEntity.FirstOrDefault().CodIBGE);
            Assert.Equal(userDtoCompleto.UfId, listaEntity.FirstOrDefault().UfId);
            Assert.NotNull(userDtoCompleto.Uf);

            var listaDto = Mapper.Map <List <MunicipioDto> >(listaEntity);

            Assert.True(listaDto.Count() == listaEntity.Count());
            for (int i = 0; i < listaDto.Count(); i++)
            {
                Assert.Equal(listaDto[i].Id, listaEntity[i].Id);
                Assert.Equal(listaDto[i].Nome, listaEntity[i].Nome);
                Assert.Equal(listaDto[i].CodIBGE, listaEntity[i].CodIBGE);
                Assert.Equal(listaDto[i].UfId, listaEntity[i].UfId);
            }

            var userDtoCreateResult = Mapper.Map <MunicipioDtoCreateResult>(entity);

            Assert.Equal(userDtoCreateResult.Id, entity.Id);
            Assert.Equal(userDtoCreateResult.Nome, entity.Nome);
            Assert.Equal(userDtoCreateResult.CodIBGE, entity.CodIBGE);
            Assert.Equal(userDtoCreateResult.UfId, entity.UfId);
            Assert.Equal(userDtoCreateResult.CreateAt, entity.CreateAt);

            var userDtoUpdateResult = Mapper.Map <MunicipioDtoUpdateResult>(entity);

            Assert.Equal(userDtoUpdateResult.Id, entity.Id);
            Assert.Equal(userDtoUpdateResult.Nome, entity.Nome);
            Assert.Equal(userDtoUpdateResult.CodIBGE, entity.CodIBGE);
            Assert.Equal(userDtoCreateResult.UfId, entity.UfId);
            Assert.Equal(userDtoUpdateResult.UpdateAt, entity.UpdateAt);

            //Dto para Model
            var userModel = Mapper.Map <MunicipioModel>(userDto);

            Assert.Equal(userModel.Id, userDto.Id);
            Assert.Equal(userModel.Nome, userDto.Nome);
            Assert.Equal(userModel.CodIBGE, userDto.CodIBGE);
            Assert.Equal(userModel.UfId, userDto.UfId);

            var userDtoCreate = Mapper.Map <MunicipioDtoCreate>(userModel);

            Assert.Equal(userDtoCreate.Nome, userModel.Nome);
            Assert.Equal(userDtoCreate.CodIBGE, userModel.CodIBGE);
            Assert.Equal(userDtoCreate.UfId, userModel.UfId);

            var userDtoUpdate = Mapper.Map <MunicipioDtoUpdate>(userModel);

            Assert.Equal(userDtoUpdate.Id, userModel.Id);
            Assert.Equal(userDtoUpdate.Nome, userModel.Nome);
            Assert.Equal(userDtoUpdate.CodIBGE, userModel.CodIBGE);
            Assert.Equal(userDtoUpdate.UfId, userModel.UfId);
        }
Example #26
0
 public bool Insert(MunicipioModel municipioModel)
 {
     _context.Add(ModelToEntity(municipioModel));
     return(_context.SaveChanges() == 1 ? true : false);
 }
Example #27
0
 public bool Update(MunicipioModel municipioModel)
 {
     _context.Update(ModelToEntity(municipioModel));
     return(_context.SaveChanges() == 1 ? true : false);
 }
Example #28
0
        public MunicipioModel GetOneMunicipio(MunicipioModel model)
        {
            var obj = _municipiosRepository.Municipios.GetOneByCodigo(model);

            return(obj);
        }
Example #29
0
        public async Task <ActionResult> Remove([FromServices] RhNetContext rhNetContext, [FromBody] MunicipioModel municipioModel)
        {
            MunicipioRepository repository = new MunicipioRepository();
            object result = await repository.Remove(rhNetContext, municipioModel);

            if (result.GetType() == typeof(MunicipioModel))
            {
                return(Ok(result));
            }
            else
            {
                return(BadRequest(result.ToString()));
            }
        }
Example #30
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);
                }
            }
        }