public bool CheckIfUserNameExists(string userName)
 {
     using (var dataContext = new HealthReunionEntities())
     {
         return dataContext.Users.Where(u => u.UserName.Trim() == userName && u.PatientId == null).FirstOrDefault() != null ;
     }
 }
    public void AddProviderWithDefaultUser(Provider provider, User user)
    {
        using (TransactionScope scope = new TransactionScope())
        {
            using (var dataContext = new HealthReunionEntities())
            {

                if (CheckIfUserNameExists(user.UserName))
                    throw new Exception("User name already exist");

                if(CheckIfProviderNameExists(provider.ProviderName))
                    throw new Exception("Provider name already exist");

                // Add provider enity
                dataContext.Providers.Add(provider);

                // Save changes so that it will insert records into database.
                dataContext.SaveChanges();

                user.ProviderId = provider.ProviderId;

                user.Password = EncryptDecrypt.EncryptData(user.Password, EncryptDecrypt.ReadCert());

                // Add user entity
                dataContext.Users.Add(user);

                dataContext.SaveChanges();

                // Complete the transaction if everything goes well.
                scope.Complete();
            }
        }
    }
 public string GetProviderEmailById(int id)
 {
     using (var dataContext = new HealthReunionEntities())
     {
         return dataContext.Providers.Find(id).Email;
     }
 }
 public Document GetDocumentById(int documentId, string documentType)
 {
     using (var dataContext = new HealthReunionEntities())
     {
         return dataContext.Documents.Where(d => d.DocumentId == documentId && d.DocumentType.Equals(documentType)).First();
     }
 }
    public void AddPatient(Patient patient, string userName, string defaultPassword)
    {
        using (TransactionScope scope = new TransactionScope())
        {
            using (var dataContext = new HealthReunionEntities())
            {
                if (CheckIfUserNameExists(userName))
                    throw new Exception("User name already exist");

                // Add provider enity
                dataContext.Patients.Add(patient);

                // Save changes so that it will insert records into database.
                dataContext.SaveChanges();

                var user = new User();
                user.UserName = userName;
                user.Password = defaultPassword;

                user.PatientId = patient.PatientId;
                user.IsDefaultPassword = true;

                // Add user entity
                dataContext.Users.Add(user);

                dataContext.SaveChanges();

                // Complete the transaction if everything goes well.
                scope.Complete();
            }
        }
    }
    public void AddPatient(Patient patient, string userName)
    {
        using (TransactionScope scope = new TransactionScope())
        {
            using (var dataContext = new HealthReunionEntities())
            {
                // Add provider enity
                dataContext.Patients.Add(patient);

                // Save changes so that it will insert records into database.
                dataContext.SaveChanges();

                var user = new User();
                user.UserName = userName;
                user.Password = "******";

                user.PatientId = patient.PatientId;

                // Add user entity
                dataContext.Users.Add(user);

                dataContext.SaveChanges();

                // Complete the transaction if everything goes well.
                scope.Complete();
            }
        }
    }
    public List<PatientDocumentsModel> GetDocuments(int patientId, int providerId)
    {
        var patientDocumentsList = new List<PatientDocumentsModel>();
        using (var dataContext = new HealthReunionEntities())
        {
            var patientDocuments = (from doc in dataContext.Documents
                                    join patient in dataContext.Patients
                                    on doc.PatientId equals patient.PatientId
                                    where doc.PatientId == patientId && doc.ProviderId == providerId
                                    select new { Patients = patient , Documents = doc}).ToList();

            foreach (var item in patientDocuments)
            {
                patientDocumentsList.Add(new PatientDocumentsModel
                {
                    FirstName = item.Patients.FirstName,
                    LastName = item.Patients.LastName,
                    MiddleName = item.Patients.MiddleName,
                    DocumentId = item.Documents.DocumentId,
                    DocumentType = item.Documents.DocumentType,
                    PatientId = item.Documents.PatientId,
                    ProviderId = item.Documents.ProviderId,
                    CreationTime = item.Documents.CreationTime,
                    DocumentText = System.Text.Encoding.UTF8.GetString(item.Documents.Document1)
                });
            }

            return patientDocumentsList;
        }
    }
 public List<Patient> GetAllPatients(int providerId)
 {
     using (var dataContext = new HealthReunionEntities())
     {
         return dataContext.Patients.Where(p => p.ProviderId == providerId).ToList();
     }
 }
 public Patient GetPatientById(int patientID)
 {
     using (var dataContext = new HealthReunionEntities())
     {
         return dataContext.Patients.Where(p => p.PatientId == patientID).FirstOrDefault();
     }
 }
 public bool CheckIfProviderNameExists(string providerName)
 {
     using (var dataContext = new HealthReunionEntities())
     {
         return dataContext.Providers.Where(p => p.ProviderName.Trim() == providerName).FirstOrDefault() != null;
     }
 }
 public List<Provider> GetAllProviders()
 {
     using (var dataContext = new HealthReunionEntities())
     {
         return dataContext.Providers.ToList();
     }
 }
 public bool ValidateUser(string userName, string passWord, int providerID)
 {
     using (var dataContext = new HealthReunionEntities())
     {
         passWord = EncryptDecrypt.EncryptData(passWord, EncryptDecrypt.ReadCert());
         return dataContext.Users.Where(u => u.UserName.Trim() == userName && u.Password.Trim() == passWord && u.ProviderId == providerID).FirstOrDefault() != null;
     }
 }
 public List<User> GetUsersByProviderId(int providerId)
 {
     using (var dataContext = new HealthReunionEntities())
     {
         return (from u in dataContext.Users
                     where u.ProviderId == providerId
                     select u).ToList();
     }
 }
 public User GetUserById(int patientId)
 {
     using (var dataContext = new HealthReunionEntities())
     {
         var user = (from u in dataContext.Users
                     where u.PatientId == patientId
                     select u).FirstOrDefault();
         return user;
     }
 }
 public void AddDocuments(Document document)
 {
     using (var dataContext = new HealthReunionEntities())
     {
         // Add document entity
         dataContext.Documents.Add(document);
         // Save changes so that it will insert records into database.
         dataContext.SaveChanges();
     }
 }
 public void AddUser(User user)
 {
     using (var dataContext = new HealthReunionEntities())
     {
         user.Password = EncryptDecrypt.EncryptData(user.Password, EncryptDecrypt.ReadCert());
         // Add user entity
         dataContext.Users.Add(user);
         // Save changes so that it will insert records into database.
         dataContext.SaveChanges();
     }
 }
    public string GetEmailAddress(int patientID)
    {
        using (var dataContext = new HealthReunionEntities())
        {
            var patient = dataContext.Patients.Where(p => p.PatientId == patientID).FirstOrDefault();
            if (patient != null)
                return patient.Email;

            return string.Empty;
        }
    }
 public void RemoveUser(int userId)
 {
     using (var dataContext = new HealthReunionEntities())
     {
         var user = dataContext.Users.Find(userId);
         if (user != null)
         {
             dataContext.Users.Remove(user);
             dataContext.SaveChanges();
         }
     }
 }
        /// <summary>
        /// Get all appointments for by Provider Id and Date
        /// </summary>
        /// <param name="patientId"></param>
        /// <param name="appointmentDate"></param>
        /// <returns></returns>
        public List<Appointment> GetAllAppointments(int providerId, string date)
        {
            using (var dataContext = new HealthReunionEntities())
            {
                var parsedDate = DateTime.Parse(date);

                return (from appointment in dataContext.Appointments
                        where appointment.AppointmentDate == parsedDate
                                   && appointment.ProviderId == providerId
                        select appointment).ToList();
            }
        }
Example #20
0
        /// <summary>
        /// Get all appointments for by Provider Id and Date
        /// </summary>
        /// <param name="patientId"></param>
        /// <param name="appointmentDate"></param>
        /// <returns></returns>
        public List <Appointment> GetAllAppointments(int providerId, string date)
        {
            using (var dataContext = new HealthReunionEntities())
            {
                var parsedDate = DateTime.Parse(date);

                return((from appointment in dataContext.Appointments
                        where appointment.AppointmentDate == parsedDate &&
                        appointment.ProviderId == providerId
                        select appointment).ToList());
            }
        }
 public void UpdatePassword(User user)
 {
     using (var dataContext = new HealthReunionEntities())
     {
         var original = dataContext.Users.Find(user.UserId);
         if (original != null)
         {
             original.Password = EncryptDecrypt.EncryptData(user.Password, EncryptDecrypt.ReadCert());
         }
         dataContext.SaveChanges();
     }
 }
 /// <summary>
 /// Add Appointments
 /// </summary>
 /// <param name="appointment"></param>
 public void AddAppointments(List<Appointment> appointments)
 {
     using (var tran = new TransactionScope())
     {
         foreach (var appointment in appointments)
         {
             using (var dataContext = new HealthReunionEntities())
             {
                 var dbAppointment = (from app in dataContext.Appointments
                                    where app.AppointmentDate == appointment.AppointmentDate && app.PatientId == appointment.PatientId
                                    && app.ProviderId == appointment.ProviderId && app.Time == appointment.Time
                                    select app).FirstOrDefault();
                 if (dbAppointment == null)
                 {
                     dataContext.Appointments.Add(appointment);
                     dataContext.SaveChanges();
                 }
             }
         }
         tran.Complete();
     }
 }
Example #23
0
 /// <summary>
 /// Add Appointments
 /// </summary>
 /// <param name="appointment"></param>
 public void AddAppointments(List <Appointment> appointments)
 {
     using (var tran = new TransactionScope())
     {
         foreach (var appointment in appointments)
         {
             using (var dataContext = new HealthReunionEntities())
             {
                 var dbAppointment = (from app in dataContext.Appointments
                                      where app.AppointmentDate == appointment.AppointmentDate && app.PatientId == appointment.PatientId &&
                                      app.ProviderId == appointment.ProviderId && app.Time == appointment.Time
                                      select app).FirstOrDefault();
                 if (dbAppointment == null)
                 {
                     dataContext.Appointments.Add(appointment);
                     dataContext.SaveChanges();
                 }
             }
         }
         tran.Complete();
     }
 }
        public ActionResult ProviderRegistration(ProviderViewModel providerViewModel)
        {
            if (!ModelState.IsValid)
            {
                return View(providerViewModel);
            }
            try
            {
                HealthReunionDataAccess.HealthReunionEntities dataContext = new HealthReunionDataAccess.HealthReunionEntities();
                ProviderRepository providerRepository = new ProviderRepository();

                var provider = new Provider
                {
                    ProviderName = providerViewModel.ProviderName,
                    TermsOfUse = providerViewModel.TermsOfUse.Trim(),
                    ProviderDescription = providerViewModel.ProviderDescription.Trim(),
                    PrivacyStatement = providerViewModel.PrivacyStatement.Trim(),
                    AuthorizationReason = providerViewModel.AuthorizationReason.Trim(),
                    Email = providerViewModel.Email.Trim()
                };

                var user = new User
                {
                    UserName = providerViewModel.UserName.Trim(),
                    Password = providerViewModel.Password.Trim(),
                    ProviderId = provider.ProviderId
                };

                providerRepository.AddProviderWithDefaultUser(provider, user);
            }
            catch (Exception ex)
            {
                ModelState.AddModelError("", ex.Message);
                return View(providerViewModel);
            }
            ViewBag.Message = string.Format("Provider '{0}' Created Sucessfully!", providerViewModel.ProviderName);
            return View(new ProviderViewModel());
        }
Example #25
0
        /// <summary>
        /// Fetch all available appointment booking for a Provider based on the given date.
        /// </summary>
        /// <param name="providerId"></param>
        /// <param name="date"></param>
        /// <returns></returns>
        public List <String> GetAvailableAppointmentBookings(int providerId, string date)
        {
            using (var dataContext = new HealthReunionEntities())
            {
                var           parsedDate       = DateTime.Parse(date);
                List <String> availableSlots   = new List <String>();
                var           appointmentEnums = StringValueAttribute.GetStringValues(typeof(AppointmentTimeEnum));
                var           matchedAppointmentBookingTime = (from appointment in dataContext.Appointments
                                                               where appointment.AppointmentDate == parsedDate &&
                                                               appointment.ProviderId == providerId
                                                               select appointment.Time).ToList();

                foreach (var time in appointmentEnums)
                {
                    if (!matchedAppointmentBookingTime.Contains(time))
                    {
                        availableSlots.Add(time);
                    }
                }

                return(availableSlots);
            }
        }
        /// <summary>
        /// Fetch all available appointment booking for a Provider based on the given date.
        /// </summary>
        /// <param name="providerId"></param>
        /// <param name="date"></param>
        /// <returns></returns>
        public List<String> GetAvailableAppointmentBookings(int providerId, string date)
        {
            using (var dataContext = new HealthReunionEntities())
            {
                var parsedDate = DateTime.Parse(date);
                List<String> availableSlots = new List<String>();
                var appointmentEnums = StringValueAttribute.GetStringValues(typeof(AppointmentTimeEnum));
                var matchedAppointmentBookingTime = (from appointment in dataContext.Appointments
                                                     where appointment.AppointmentDate == parsedDate
                                                     && appointment.ProviderId == providerId
                                                     select appointment.Time).ToList();

                foreach (var time in appointmentEnums)
                {
                    if (!matchedAppointmentBookingTime.Contains(time))
                        availableSlots.Add(time);
                }

                return availableSlots;
            }
        }
 public string GetUserNameByPatientId(int patientID)
 {
     using (var dataContext = new HealthReunionEntities())
     {
         return dataContext.Users.Where(p => p.PatientId == patientID).First().UserName;
     }
 }
 public void UpdatePatient(Patient patient, string userName)
 {
     using (var dataContext = new HealthReunionEntities())
     {
         var patientToUpdate = dataContext.Patients.Where(p => p.PatientId == patient.PatientId && p.ProviderId == patient.ProviderId).First();
         patientToUpdate.ProviderId = patient.PatientId;
         patientToUpdate.MedicalRecordNumber = Guid.NewGuid();
         patientToUpdate.LastName = patient.LastName.Trim();
         patientToUpdate.FirstName = patient.FirstName.Trim();
         patientToUpdate.MiddleName = patient.MiddleName.Trim();
         patientToUpdate.DOB = patient.DOB;
         patientToUpdate.Address = patient.Address.Trim();
         patientToUpdate.Phone = patient.Phone.Trim();
         patientToUpdate.Email = patient.Email.Trim();
         patientToUpdate.City = patient.City.Trim();
         patientToUpdate.State = patient.State.Trim();
         patientToUpdate.Country = patient.Country;
         patientToUpdate.IsActive = true;
         dataContext.SaveChanges();
     }
 }
 public int GetProviderIdForPatient(int patientID)
 {
     using (var dataContext = new HealthReunionEntities())
     {
         return dataContext.Patients.Where(p => p.PatientId == patientID).First().ProviderId;
     }
 }
        public ActionResult PatientRegistration(PatientViewModel patientViewModel)
        {
            if (!LogOnHelper.CheckLogOn()) return RedirectToAction("Login", "Account");

            if (!ModelState.IsValid)
            {
                return View(patientViewModel);
            }
            try
            {
                HealthReunionDataAccess.HealthReunionEntities dataContext = new HealthReunionDataAccess.HealthReunionEntities();
                PatientRepository patientRepository = new PatientRepository();

                Patient patient = new Patient();
                patient.PatientId = patientViewModel.PatientViewEntity.PatientId;
                patient.ProviderId = int.Parse(Session["ProviderId"].ToString());
                patient.MedicalRecordNumber = Guid.NewGuid();
                patient.LastName = patientViewModel.PatientViewEntity.LastName.Trim();
                patient.FirstName = patientViewModel.PatientViewEntity.FirstName.Trim();
                patient.MiddleName = patientViewModel.PatientViewEntity.MiddleName.Trim();
                patient.DOB = DateTime.Parse(patientViewModel.PatientViewEntity.DOB).Date;
                patient.Address = patientViewModel.PatientViewEntity.Address.Trim();
                patient.Phone = patientViewModel.PatientViewEntity.Phone.Trim();
                patient.Email = patientViewModel.PatientViewEntity.Email.Trim();
                patient.City = patientViewModel.PatientViewEntity.City.Trim();
                patient.State = patientViewModel.PatientViewEntity.State.Trim();
                patient.Country = patientViewModel.PatientViewEntity.Country;
                patient.IsActive = true;

                if (patientViewModel.PatientViewEntity.Gender.Equals("Male"))
                    patient.Sex = true;
                else
                    patient.Sex = false;

                if (patientViewModel.PatientViewEntity.PatientId == 0)
                {
                    string defaultPassword = RandomPasswordGenerator.Generate(8);
                    defaultPassword = EncryptDecrypt.EncryptData(defaultPassword, EncryptDecrypt.ReadCert());
                    patientRepository.AddPatient(patient, patientViewModel.PatientViewEntity.UserName.Trim(), defaultPassword);
                    var sendMail = new SMTPApi(ConfigurationManager.AppSettings["SmtpFromEmailAddress"].ToString(), new List<String> { patient.Email });
                    var stringBuilder = new StringBuilder();
                    stringBuilder.AppendLine("<b>HealthReunion Patient Portal Log On Information. Below are the credentials</b><hr/>");
                    stringBuilder.AppendFormat("<br/>User Name: {0}", patientViewModel.PatientViewEntity.UserName.Trim());
                    stringBuilder.AppendFormat("<br/>Password: {0}", defaultPassword);
                    stringBuilder.AppendLine("<br/><hr/>Please log on to HealthReunion Patient Portal - http://healthreunionpatients.azurewebsites.net/ to access your clinical information.");
                    sendMail.SimpleHtmlEmail(stringBuilder.ToString());
                }
                else
                {
                    patientRepository.UpdatePatient(patient, patientViewModel.PatientViewEntity.UserName.Trim());
                }
            }
            catch (Exception ex)
            {
                ModelState.AddModelError("", ex.Message);
                return View(patientViewModel);
            }
            ViewBag.Message = string.Format("Patient '{0} {1} {2}' Created Sucessfully!. An Email is trigged to {3} with credentials to Log in to HealthReunion Patient Portal.",
                patientViewModel.PatientViewEntity.FirstName, patientViewModel.PatientViewEntity.MiddleName, patientViewModel.PatientViewEntity.LastName, patientViewModel.PatientViewEntity.Email);

            patientViewModel.PatientViewEntity = new PatientViewEntity();
            patientViewModel.PatientViewModelGrid = GetPatientsForLoggedInProvider();
            return View(patientViewModel);
        }