Ejemplo n.º 1
0
        public void DeveCadastrarUmPaciente()
        {
            // var servicePaciente = new PacienteService(new PacienteRepository(new UnitOfWork<ClinicasContext>(new ClinicasContext())));
            using (var db = new ClinicasContext())
            {
                try
                {
                    var pessoa   = new Pessoa("Renato", "", "M", "PF", null, "", "", "", "", "", "", "", "", "", "", "", "", db.Estados.First(), db.Cidades.First(), "", "", "", "", "", db.Usuarios.First(), "", db.Clinica.First());
                    var paciente = new Paciente(pessoa, "", "Ativo");

                    db.Paciente.Add(paciente);
                    db.SaveChanges();
                }
                catch (DbEntityValidationException ex)
                {
                    // Retrieve the error messages as a list of strings.
                    var errorMessages = ex.EntityValidationErrors
                                        .SelectMany(x => x.ValidationErrors)
                                        .Select(x => x.ErrorMessage);

                    // Join the list to a single string.
                    var fullErrorMessage = string.Join("; ", errorMessages);

                    // Combine the original exception message with the new one.
                    var exceptionMessage = string.Concat(ex.Message, " The validation errors are: ", fullErrorMessage);

                    // Throw a new DbEntityValidationException with the improved exception message.
                    throw new DbEntityValidationException(exceptionMessage, ex.EntityValidationErrors);
                }
            }
        }
Ejemplo n.º 2
0
        public void Login()
        {
            var _service = new UsuarioService(new UsuarioRepository(new UnitOfWork <ClinicasContext>(new ClinicasContext())));

            using (var db = new ClinicasContext())
            {
                try
                {
                    var usuario = _service.ObterUsuario("*****@*****.**", "150709");
                    Assert.IsNull(usuario);
                }
                catch (DbEntityValidationException ex)
                {
                    // Retrieve the error messages as a list of strings.
                    var errorMessages = ex.EntityValidationErrors
                                        .SelectMany(x => x.ValidationErrors)
                                        .Select(x => x.ErrorMessage);

                    // Join the list to a single string.
                    var fullErrorMessage = string.Join("; ", errorMessages);

                    // Combine the original exception message with the new one.
                    var exceptionMessage = string.Concat(ex.Message, " The validation errors are: ", fullErrorMessage);

                    // Throw a new DbEntityValidationException with the improved exception message.
                    throw new DbEntityValidationException(exceptionMessage, ex.EntityValidationErrors);
                }
            }
        }
Ejemplo n.º 3
0
        public void QtdePacientesCadastrados()
        {
            var _serviceDashboard = new DashboardService(new DashboardRepository(new UnitOfWork <ClinicasContext>(new ClinicasContext())));

            using (var db = new ClinicasContext())
            {
                try
                {
                    int qtd = _serviceDashboard.QtdePacientes(1, 1);

                    Assert.IsNotNull(qtd);
                }
                catch (DbEntityValidationException ex)
                {
                    // Retrieve the error messages as a list of strings.
                    var errorMessages = ex.EntityValidationErrors
                                        .SelectMany(x => x.ValidationErrors)
                                        .Select(x => x.ErrorMessage);

                    // Join the list to a single string.
                    var fullErrorMessage = string.Join("; ", errorMessages);

                    // Combine the original exception message with the new one.
                    var exceptionMessage = string.Concat(ex.Message, " The validation errors are: ", fullErrorMessage);

                    // Throw a new DbEntityValidationException with the improved exception message.
                    throw new DbEntityValidationException(exceptionMessage, ex.EntityValidationErrors);
                }
            }
        }
Ejemplo n.º 4
0
        public void SalvarMarcado()
        {
            try
            {
                var db     = new ClinicasContext();
                var agenda = db.Agenda.ToList();
                foreach (var item in agenda)
                {
                    item.Marcado(db.Usuarios.First(), db.Paciente.First(), db.Funcionario.First(), db.Especialidade.First(), db.Procedimento.First(), db.Convenio.First(), "C", "observação", "blá blá ", 0, 0, db.TipoAtendimento.First());
                }
                db.SaveChanges();
            }
            catch (DbEntityValidationException ex)
            {
                // Retrieve the error messages as a list of strings.
                var errorMessages = ex.EntityValidationErrors
                                    .SelectMany(x => x.ValidationErrors)
                                    .Select(x => x.ErrorMessage);

                // Join the list to a single string.
                var fullErrorMessage = string.Join("; ", errorMessages);

                // Combine the original exception message with the new one.
                var exceptionMessage = string.Concat(ex.Message, " The validation errors are: ", fullErrorMessage);

                // Throw a new DbEntityValidationException with the improved exception message.
                throw new DbEntityValidationException(exceptionMessage, ex.EntityValidationErrors);
            }
        }
Ejemplo n.º 5
0
        public void SalvarRealizado()
        {
            try
            {
                var db     = new ClinicasContext();
                var agenda = db.Agenda.Include("Itens").First(x => x.IdAgenda == 4);
                agenda.ConfirmarAtendimento(db.Usuarios.Find(1));
                db.SaveChanges();
            }
            catch (DbEntityValidationException ex)
            {
                // Retrieve the error messages as a list of strings.
                var errorMessages = ex.EntityValidationErrors
                                    .SelectMany(x => x.ValidationErrors)
                                    .Select(x => x.ErrorMessage);

                // Join the list to a single string.
                var fullErrorMessage = string.Join("; ", errorMessages);

                // Combine the original exception message with the new one.
                var exceptionMessage = string.Concat(ex.Message, " The validation errors are: ", fullErrorMessage);

                // Throw a new DbEntityValidationException with the improved exception message.
                throw new DbEntityValidationException(exceptionMessage, ex.EntityValidationErrors);
            }
        }
Ejemplo n.º 6
0
        public override async Task GrantResourceOwnerCredentials(OAuthGrantResourceOwnerCredentialsContext context)
        {
            context.OwinContext.Response.Headers.Add("Access-Control-Allow-Origin", new[] { "*" });

            try
            {
                var user     = context.UserName;
                var password = context.Password;

                var db      = new ClinicasContext();
                var usuario = db.Usuarios.Include(m => m.Clinica).FirstOrDefault(x => x.Login == user && x.Senha == password);

                if (usuario == null)
                {
                    context.SetError("invalid_grant", "Usuário ou senha inválidos");
                    return;
                }

                var identity = new ClaimsIdentity(context.Options.AuthenticationType);

                var roles = new List <string>();
                roles.Add("User");


                identity.AddClaim(new Claim("IdClinica", usuario.IdClinica.ToString()));
                identity.AddClaim(new Claim("IdGrupoUsuario", usuario.IdGrupoUsuario.ToString()));
                identity.AddClaim(new Claim(ClaimTypes.Name, usuario.Login));

                foreach (var role in roles)
                {
                    identity.AddClaim(new Claim(ClaimTypes.Role, role));
                }

                GenericPrincipal principal = new GenericPrincipal(identity, roles.ToArray());
                Thread.CurrentPrincipal = principal;

                /* var props = new AuthenticationProperties(new Dictionary<string, string>()
                 *     {
                 *         { "Login", usuario.Login },
                 *         { "IdClinica", usuario.IdClinica.ToString() },
                 *         { "IdGrupoUsuario", usuario.IdGrupoUsuario.ToString() }
                 *
                 * });  */

                ///  var ticket = new AuthenticationTicket(identity, props);
                ///    /* context.Validated(identity); */
                ///
                context.Validated(identity);
            }
            catch (Exception ex)
            {
                context.SetError("invalid_grant", "Falha ao autenticar " + ex.Message);
            }
        }
Ejemplo n.º 7
0
        public void EstoqueSaida()
        {
            using (var db = new ClinicasContext())
            {
                var material = db.Material.Find(5);
                material.GerarMovimentoEstoque(10, "Saida", db.Unidades.Find(5));

                db.Entry(material).State = EntityState.Modified;
                db.SaveChanges();
            }
        }
Ejemplo n.º 8
0
        public void RetornaFuncionalidadesUsuario()
        {
            //  var _service = new UsuarioService(new UsuarioRepository(new UnitOfWork<ClinicasContext>(new ClinicasContext())));
            using (var db = new ClinicasContext())
            {
                try
                {
                    var modulos = db.Database.SqlQuery <ModulosModel>(" select * from vw_menu_grupousuario where IdGrupoUsuario = '1' ").ToList();

                    var lista = new List <ModulosModel>();

                    foreach (var item in modulos)
                    {
                        var func = db.Database.SqlQuery <FuncionalidadeModel>(" select * from vw_menu_grupousuario where IdModulo = '" + item.IdModulo + "'   ").ToList();

                        lista.Add(new ModulosModel()
                        {
                            IdModulo        = item.IdModulo,
                            NmModulo        = item.NmModulo,
                            Icon            = item.Icon,
                            Funcionalidades = func
                        });
                    }


                    Assert.IsNotNull(lista);
                }
                catch (DbEntityValidationException ex)
                {
                    // Retrieve the error messages as a list of strings.
                    var errorMessages = ex.EntityValidationErrors
                                        .SelectMany(x => x.ValidationErrors)
                                        .Select(x => x.ErrorMessage);

                    // Join the list to a single string.
                    var fullErrorMessage = string.Join("; ", errorMessages);

                    // Combine the original exception message with the new one.
                    var exceptionMessage = string.Concat(ex.Message, " The validation errors are: ", fullErrorMessage);

                    // Throw a new DbEntityValidationException with the improved exception message.
                    throw new DbEntityValidationException(exceptionMessage, ex.EntityValidationErrors);
                }
            }
        }
Ejemplo n.º 9
0
        public void DeveGerarumaGuiaConsulta()
        {
            var db = new ClinicasContext();

            var guia = new Guia();

            var dadosBeneficiario = new DadosBeneficiario("123456", "Plano B", DateTime.Now.AddMonths(12), "Renato Ayres de Oliveira", "123456");

            var cabecalhoGuia       = new CabecalhoGuia("1234567", "0000001", DateTime.Now);
            var dadosContratado     = new DadosContratado("PF", "12345656", "CID", "1234567", "RUA", "CAMPINAS 453", "123456", "", "BELO HORIZONTE", "MG", "66666", "30520540", "", "CRM", "123456777", "SP", "66666");
            var hipoteseDiagnostica = new HipoteseDiagnostica("A", "15 01 35", "", "", "", "", "");
            var dadosAtendimento    = new DadosAtendimento(DateTime.Now, "123456", "101012", "1", "1", "Teste Observação", null, null);

            guia.GerarGuiaConsulta(cabecalhoGuia, dadosBeneficiario, dadosContratado, hipoteseDiagnostica, dadosAtendimento, db.Clinica.First());

            db.Guia.Add(guia);
            db.SaveChanges();
        }
Ejemplo n.º 10
0
        public void LiberarAgenda()
        {
            var db = new ClinicasContext();

            var agenda = new Agenda();

            agenda.Aguardando(DateTime.Now, new TimeSpan(08, 00, 00), db.Usuarios.Find(1), db.Funcionario.First(x => x.Tipo == "Profissional de Saúde"), db.Clinica.First(), "teste");

            db.Agenda.Add(agenda);
            db.SaveChanges();

            /* var guia = new AgendaDTO();
             *
             * var especialidade = "";
             * var profissional = "";
             *
             * DateTime data = DateTime.Now;
             * DateTime TempoInicio = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 08, 00, 00);
             * DateTime TempoTermino = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 18, 00, 00);
             *
             * DateTime IntervaloInicio = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 12, 00, 00);
             * DateTime IntervaloTermino = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 14, 00, 00);
             *
             * double intervaloMinutos = 30;
             *
             * List<DateTime> arrHorario = new List<DateTime>();
             * while (TempoInicio <= TempoTermino)
             * {
             *  arrHorario.Add(TempoInicio);
             *  TempoInicio = TempoInicio.AddHours(0).AddMinutes(intervaloMinutos).AddSeconds(0);
             * }
             *
             * List<DateTime> arrIntervalo = new List<DateTime>();
             * while (IntervaloInicio < IntervaloTermino)
             * {
             *  arrIntervalo.Add(IntervaloInicio);
             *  IntervaloInicio = IntervaloInicio.AddHours(0).AddMinutes(intervaloMinutos).AddSeconds(0);
             * }
             * var list3 = arrHorario.Where(x => !arrIntervalo.Contains(x)).ToList();
             *
             * db.SaveChanges(); */
        }