Exemplo n.º 1
0
        public User CreateUser(string firstName, string lastName, string email, string password, bool isAdmin = false)
        {
            using (var db = new loisEntities1())
            {
                try
                {
                    var salt  = GenerateSalt();
                    var pHash = HashPassword(password, salt);

                    var user = new User()
                    {
                        firstname    = firstName,
                        lastname     = lastName,
                        email        = email,
                        passwordhash = pHash,
                        salt         = salt,
                        admin        = isAdmin,
                        enabled      = true
                    };

                    var mapping = mapper.Map <Authentication>(user);

                    if (db.Authentications.Any(x => x.Email == user.email))
                    {
                        return(user);
                    }

                    db.Authentications.Add(mapping);

                    if (isAdmin)
                    {
                        var adminGroup = db.AuthenticationGroups.FirstOrDefault(x => x.GroupName == "Admin");

                        db.AuthGroupUsers.Add(new AuthGroupUser()
                        {
                            Authentication      = mapping,
                            AuthenticationGroup = adminGroup
                        });
                    }
                    else
                    {
                        var userGroup = db.AuthenticationGroups.FirstOrDefault(x => x.GroupName == "User");
                        db.AuthGroupUsers.Add(new AuthGroupUser()
                        {
                            Authentication      = mapping,
                            AuthenticationGroup = userGroup
                        });
                    }

                    db.SaveChanges();

                    return(user);
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                    throw;
                }
            }
        }
Exemplo n.º 2
0
        public Requisition GetRequisitionById(int id, bool loadDocs = true)
        {
            using (var db = new loisEntities1())
            {
                var req = db.Requisitions.FirstOrDefault(x => x.RequisitionNo == id);

                if (req == null)
                {
                    return(null);
                }

                var model   = mapper.Map <Requisition>(req);
                var patient = db.Patients.FirstOrDefault(x => x.PatientId == model.PatientId);
                if (patient != null)
                {
                    model.Patient = mapper.Map <Patient>(patient);
                }

                if (loadDocs)
                {
                    var docs = new DocumentService(db).GetDocumentsByReqId(id);
                    model.Documents = docs.ToList();
                }

                return(model);
            }
        }
Exemplo n.º 3
0
        public bool SaveRequisition(Requisition requisition)
        {
            using (var db = new loisEntities1())
            {
                var mapping = mapper.Map <DAL.Lois.Requisition>(requisition);

                db.Requisitions.AddOrUpdate(mapping);
                db.SaveChanges();

                return(true);
            }
        }
Exemplo n.º 4
0
        public bool SavePatient(Patient pat)
        {
            using (var db = new loisEntities1())
            {
                var p = mapper.Map <DAL.Lois.Patient>(pat);

                db.Patients.AddOrUpdate(p);
                db.SaveChanges();

                return(true);
            }
        }
Exemplo n.º 5
0
        public bool DeleteByUserId(int userId)
        {
            using (var db = new loisEntities1())
            {
                var tokens = db.Tokens.Where(x => x.UserId == userId);

                db.Tokens.RemoveRange(tokens);
                db.SaveChanges();
            }

            return(true);
        }
Exemplo n.º 6
0
        public void InsertRequistion()
        {
            var req  = LOIS.BLL.Factories.RequisitionFactory.CreateRequisition(1, new FakeProlisService());
            var repo = new RequisitionService();

            repo.SaveRequisition(req);
            using (var b = new loisEntities1())
            {
                var r = b.Requisitions.First(x => x.RequisitionNo == 1);

                b.Requisitions.Remove(r);
                b.SaveChanges();
            }
        }
Exemplo n.º 7
0
        public bool ValidateToken(string authToken)
        {
            using (var db = new loisEntities1())
            {
                var token = db.Tokens.FirstOrDefault(x => x.AuthToken == authToken && x.ExpiresOn > DateTime.Now);

                if (token != null)
                {
                    return(true);
                }

                return(false);
            }
        }
Exemplo n.º 8
0
        public bool Kill(string tokenId)
        {
            using (var db = new loisEntities1())
            {
                var token = db.Tokens.FirstOrDefault(x => x.AuthToken == tokenId);

                if (token != null)
                {
                    db.Tokens.Remove(token);
                    db.SaveChanges();
                }
            }

            return(true);
        }
Exemplo n.º 9
0
        public IEnumerable <Requisition> GetRequisitions()
        {
            using (var db = new loisEntities1())
            {
                var output = new List <Requisition>();
                var reqs   = db.Requisitions.ToList();

                foreach (var req in reqs)
                {
                    var mapped = mapper.Map <Requisition>(req);
                    output.Add(mapped);
                }

                return(output);
            }
        }
Exemplo n.º 10
0
        public IEnumerable <User> GetUsers()
        {
            var output = new List <User>();

            using (var db = new loisEntities1())
            {
                var users = db.Authentications.ToList();

                foreach (var user in users)
                {
                    var mapping = mapper.Map <User>(user);
                    mapping.Groups = user.AuthGroupUsers.Select(x => x.AuthenticationGroup.GroupName).ToList();
                    output.Add(mapping);
                }
            }

            return(output);
        }
Exemplo n.º 11
0
        /// <summary>
        /// Used to get search results to and from the RequisitionSearchService
        /// </summary>
        /// <param name="search"></param>
        /// <returns></returns>
        public IEnumerable <Requisition> GetRequisitions(RequisitionSearch search)
        {
            using (var db = new loisEntities1())
            {
                var output = new List <Core.Models.Requisition>();
                var reqs   = RequisitionSearchService.Search(search, db).ToList();

                foreach (var req in reqs)
                {
                    var patient = db.Patients.FirstOrDefault(x => x.PatientId == req.PatientId);
                    var patMap  = mapper.Map <Patient>(patient);
                    var mapping = mapper.Map <Requisition>(req);
                    mapping.Patient = patMap;
                    output.Add(mapping);
                }

                return(output);
            }
        }
Exemplo n.º 12
0
        public bool ChangePassword(string email, string newPassword, string oldPassword)
        {
            var user = Authenticate(email, oldPassword);

            if (user == null)
            {
                return(false);
            }

            var newHash = HashPassword(newPassword, user.salt);

            using (var db = new loisEntities1())
            {
                var dbUser = db.Authentications.First(x => x.Email == user.email);
                dbUser.PasswordHash = newHash;
                db.SaveChanges();
            }

            return(true);
        }
Exemplo n.º 13
0
        public static IQueryable <DAL.Lois.Requisition> Search(RequisitionSearch searchModel, loisEntities1 context)
        {
            var reqs = context.Requisitions.AsQueryable();

            if (searchModel.RequisitionId.HasValue)
            {
                reqs = reqs.Where(x => x.RequisitionNo == searchModel.RequisitionId);
            }

            if (!string.IsNullOrEmpty(searchModel.EMRNo))
            {
                reqs = reqs.Where(x => x.EmrNo.ToLower().Contains(searchModel.EMRNo));
            }

            if (searchModel.AccessionDateStart.HasValue)
            {
                reqs = reqs.Where(x => x.AccessionDate >= searchModel.AccessionDateStart);
            }

            if (searchModel.AccessionDateEnd.HasValue)
            {
                reqs = reqs.Where(x => x.AccessionDate <= searchModel.AccessionDateEnd);
            }

            if (searchModel.CollectedDateStart.HasValue)
            {
                reqs = reqs.Where(x => x.CollectedDate >= searchModel.CollectedDateStart);
            }

            if (searchModel.CollectedDateEnd.HasValue)
            {
                reqs = reqs.Where(x => x.CollectedDate <= searchModel.CollectedDateEnd);
            }

            if (searchModel.ScannedDateStart.HasValue)
            {
                reqs = reqs.Where(x => x.ScannedDate >= searchModel.ScannedDateStart);
            }

            if (searchModel.ScannedDateEnd.HasValue)
            {
                reqs = reqs.Where(x => x.ScannedDate <= searchModel.ScannedDateEnd);
            }

            //Patient stuff
            if (searchModel.PatientId.HasValue)
            {
                reqs = reqs.Where(x => x.PatientId == searchModel.PatientId);
            }

            if (!string.IsNullOrEmpty(searchModel.PatientFirstName) || !string.IsNullOrEmpty(searchModel.PatientLastName) || searchModel.PatientSSN.HasValue)
            {
                //Get patient
                var patients = context.Patients.AsQueryable();

                if (!string.IsNullOrEmpty(searchModel.PatientFirstName))
                {
                    patients = context.Patients.Where(p => p.FirstName.ToLower().Contains(searchModel.PatientFirstName));
                }

                if (!string.IsNullOrEmpty(searchModel.PatientLastName))
                {
                    patients = context.Patients.Where(p => p.LastName.ToLower().Contains(searchModel.PatientLastName));
                }

                if (searchModel.PatientSSN.HasValue)
                {
                    patients = context.Patients.Where(p => p.SSN == searchModel.PatientSSN);
                }

                var patIds = patients.Select(x => x.PatientId).ToList();

                reqs = reqs.Where(r => r.PatientId != null && patIds.Any(p => p == r.PatientId.Value));
            }

            //Insurance
            //todo add insurance search

            return(reqs);
        }
Exemplo n.º 14
0
 public DocumentService(loisEntities1 database = null)
 {
     mapper = mapperConfig.CreateConfig().CreateMapper();
     db     = database ?? new DAL.Lois.loisEntities1();
     db.Configuration.LazyLoadingEnabled = false;
 }
Exemplo n.º 15
0
        public Token GenerateToken(int userId)
        {
            string   token    = Guid.NewGuid().ToString();
            DateTime issuedOn = DateTime.Now;
            double   expireTime;

            try
            {
                expireTime =
                    Convert.ToDouble(ConfigurationManager.AppSettings["AuthTokenExpiry"]);
            }
            catch (Exception)
            {
                //8 hrs
                expireTime = 1000 * 60 * 60 * 8;
            }

            if (expireTime == 0)
            {
                expireTime = 1000 * 60 * 60 * 8;
            }
            DateTime expiredOn = DateTime.Now.AddMilliseconds(expireTime);

            var t = new Token()
            {
                userid    = userId,
                authtoken = token,
                issuedon  = issuedOn,
                expireson = expiredOn
            };

            //Insert to db
            using (var db = new loisEntities1())
            {
                var t1 = db.Tokens.FirstOrDefault(x => x.UserId == userId);

                if (t1 != null)
                {
                    t1.ExpiresOn = t.expireson;
                    db.SaveChanges();

                    t.authtoken = t1.AuthToken;
                    t.issuedon  = t1.IssuedOn;
                    t.tokenid   = t1.TokenId;
                }
                else
                {
                    var dbToken = new DAL.Lois.Token()
                    {
                        UserId    = t.userid,
                        ExpiresOn = t.expireson,
                        IssuedOn  = t.issuedon,
                        AuthToken = t.authtoken
                    };
                    db.Tokens.Add(dbToken);
                    db.SaveChanges();
                }
            }

            return(t);
        }