Ejemplo n.º 1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="fac_key">Facility Key</param>
        /// <param name="applyScheduleFilter">Boolean to filter the physician based on schedule</param>
        /// <param name="excludePartnerPhysicians">Boolean to  exclude partner physicians</param>
        /// <returns></returns>
        public IQueryable <AspNetUser> GetPhysiciansByFacility(Guid?fac_key, bool applyScheduleFilter, int?casType = 0)
        {
            var currentDate              = DateTime.Now.ToEST();
            var maxDate                  = DateTime.MaxValue;
            var defaultStatus            = _physicianStatusService.GetDefault();
            int nullPhysicianStatusOrder = defaultStatus != null ? defaultStatus.phs_assignment_priority.HasValue ? defaultStatus.phs_assignment_priority.Value : int.MaxValue : int.MaxValue;
            var facility                 = _facilityService.GetDetails(fac_key.Value);
            var licenseQuery             = (_unitOfWork.PhysicianLicenseRepository.Query()
                                            .Where(m => m.phl_is_active)
                                            .Where(m => DbFunctions.TruncateTime(currentDate) >= DbFunctions.TruncateTime(m.phl_issued_date))
                                            .Where(m => m.phl_license_state == null /*|| facility.fac_stt_key == null*/ || m.phl_license_state == facility.fac_stt_key)
                                            .Where(m => m.phl_expired_date == null || DbFunctions.TruncateTime(currentDate) <= DbFunctions.TruncateTime(m.phl_expired_date))
                                            ).Select(m => m.phl_user_key).Distinct();
            var physicianRole    = _adminService.GetRoleByName(UserRoles.Physician.ToDescription());
            var partnerPhysician = _adminService.GetRoleByName(UserRoles.PartnerPhysician.ToDescription());
            var schedule         = _schedulerService.GetSchedule(currentDate).Select(m => m.uss_user_id).ToList();
            var physiciansQuery  = from m in _unitOfWork.FacilityPhysicianRepository.Query()
                                   join n in licenseQuery on m.fap_user_key equals n
                                   join phy in GetPhysicians() on m.fap_user_key equals phy.Id
                                   where
                                   m.fap_fac_key == fac_key &&
                                   m.AspNetUser.IsActive &&
                                   m.AspNetUser.IsDeleted == false &&
                                   m.fap_is_active &&
                                   m.fap_is_on_boarded &&
                                   m.fap_hide == false &&
                                   (applyScheduleFilter == false || schedule.Contains(m.fap_user_key))
                                   select m;

            var busyPhysicianIds = getBusyPhysicians(fac_key.ToString(), currentDate);

            //var busyPhysicianIds = getBusyPhysicians(physiciansQuery.Select(m => m.AspNetUser.Id).ToList());

            var physicians = physiciansQuery.Select(m => new
            {
                m.AspNetUser,
                IsBusy    = busyPhysicianIds.Contains(m.AspNetUser.Id) ? 1 : 0,
                RoleOrder = (m.AspNetUser.AspNetUserRoles.FirstOrDefault() != null ? m.AspNetUser.AspNetUserRoles.FirstOrDefault().RoleId : "") == physicianRole.Id ? 1 : 2
            });

            physicians = physicians
                         .OrderBy(m => m.IsBusy)
                         .ThenBy(m => (m.AspNetUser.physician_status != null ? m.AspNetUser.physician_status.phs_assignment_priority : nullPhysicianStatusOrder))
                         .ThenBy(m => m.AspNetUser.CredentialIndex)
                         .ThenBy(m => m.RoleOrder)
                         .ThenBy(m => m.AspNetUser.status_change_date == null ? maxDate : m.AspNetUser.status_change_date);

            if (CaseType.StatEEG.ToInt() == casType || CaseType.RoutineEEG.ToInt() == casType || CaseType.LongTermEEG.ToInt() == casType)
            {
                return(physicians.Where(c => c.AspNetUser.IsEEG).Select(s => s.AspNetUser));
            }
            else
            {
                return(physicians.Select(m => m.AspNetUser));
            }
        }
Ejemplo n.º 2
0
        public List <Tuple <string, string, string, string, string, string> > GetScheduledPhysicians(bool isgetAllRequest, string userId, bool onlySchedulePhys = false, string phy_type = "Physician")
        {
            var random           = new Random();
            var physicianRole    = _adminService.GetRoleByName(UserRoles.Physician.ToDescription());
            var partnerPhysician = _adminService.GetRoleByName(UserRoles.PartnerPhysician.ToDescription());
            var PacPhysician     = _adminService.GetRoleByName(UserRoles.AOC.ToDescription());

            #region If  type is Physician
            if (phy_type == "Physician")
            {
                if (onlySchedulePhys)
                {
                    return((from s in this.GetFilteredSchedule(isgetAllRequest, userId)
                            join u in _unitOfWork.UserRepository.Query().Where(x => x.IsActive && x.IsDeleted == false) on s.uss_user_id equals u.Id
                            join r in _unitOfWork.UserRoleRepository.Query() on u.Id equals r.UserId
                            where r.RoleId == physicianRole.Id || r.RoleId == partnerPhysician.Id

                            select new { s.uss_user_id, u.UserInitial, u.FirstName, u.LastName, u.NPINumber, u.Gender }
                            )
                           .Distinct()
                           .OrderBy(x => x.FirstName).ThenBy(x => x.LastName)
                           .ToList()
                           .Select(x => new Tuple <string, string, string, string, string, string>(x.uss_user_id, string.Format("{0} {1} - {2}", x.FirstName, x.LastName, x.UserInitial), string.Format("#{0:X6}", random.Next(0x1000000)), string.Format("{0} {1} - {2}", x.FirstName, x.LastName, x.UserInitial), x.NPINumber ?? string.Empty, x.Gender))
                           .ToList());
                }
                else
                {
                    return((from u in _unitOfWork.UserRepository.Query().Where(x => x.IsActive && x.IsDeleted == false)
                            join r in _unitOfWork.UserRoleRepository.Query() on u.Id equals r.UserId
                            where r.RoleId == physicianRole.Id || r.RoleId == partnerPhysician.Id

                            select new { u.Id, u.UserInitial, u.FirstName, u.LastName, u.NPINumber, u.Gender }
                            )
                           .Distinct()
                           .OrderBy(x => x.FirstName).ThenBy(x => x.LastName)
                           .ToList()
                           .Select(x => new Tuple <string, string, string, string, string, string>(x.Id, string.Format("{0} {1} - {2}", x.FirstName, x.LastName, x.UserInitial), string.Format("#{0:X6}", random.Next(0x1000000)), string.Format("{0} {1} - {2}", x.FirstName, x.LastName, x.UserInitial), x.NPINumber ?? string.Empty, x.Gender))
                           .ToList());
                }
            }

            #endregion
            #region If  type is  Pac Physician
            else if (phy_type == "aoc")
            {
                if (onlySchedulePhys)
                {
                    return((from s in this.GetFilteredSchedule(isgetAllRequest, userId)
                            join u in _unitOfWork.UserRepository.Query().Where(x => x.IsActive && x.IsDeleted == false) on s.uss_user_id equals u.Id
                            join r in _unitOfWork.UserRoleRepository.Query() on u.Id equals r.UserId
                            where r.RoleId == PacPhysician.Id

                            select new { s.uss_user_id, u.UserInitial, u.FirstName, u.LastName, u.NPINumber, u.Gender }
                            )
                           .Distinct()
                           .OrderBy(x => x.FirstName).ThenBy(x => x.LastName)
                           .ToList()
                           .Select(x => new Tuple <string, string, string, string, string, string>(x.uss_user_id, string.Format("{0} {1} - {2}", x.FirstName, x.LastName, x.UserInitial), string.Format("#{0:X6}", random.Next(0x1000000)), string.Format("{0} {1} - {2}", x.FirstName, x.LastName, x.UserInitial), x.NPINumber ?? string.Empty, x.Gender))
                           .ToList());
                }
                else
                {
                    return((from u in _unitOfWork.UserRepository.Query().Where(x => x.IsActive && x.IsDeleted == false)
                            join r in _unitOfWork.UserRoleRepository.Query() on u.Id equals r.UserId
                            where r.RoleId == PacPhysician.Id

                            select new { u.Id, u.UserInitial, u.FirstName, u.LastName, u.NPINumber, u.Gender }
                            )
                           .Distinct()
                           .OrderBy(x => x.FirstName).ThenBy(x => x.LastName)
                           .ToList()
                           .Select(x => new Tuple <string, string, string, string, string, string>(x.Id, string.Format("{0} {1} - {2}", x.FirstName, x.LastName, x.UserInitial), string.Format("#{0:X6}", random.Next(0x1000000)), string.Format("{0} {1} - {2}", x.FirstName, x.LastName, x.UserInitial), x.NPINumber ?? string.Empty, x.Gender))
                           .ToList());
                }
            }
            #endregion
            #region If  type is Sleep
            else if (phy_type == "sleep")
            {
                if (onlySchedulePhys)
                {
                    return((from s in this.GetFilteredSchedule(isgetAllRequest, userId)
                            join u in _unitOfWork.UserRepository.Query().Where(x => x.IsActive && x.IsDeleted == false && x.IsSleep == true) on s.uss_user_id equals u.Id
                            join r in _unitOfWork.UserRoleRepository.Query() on u.Id equals r.UserId
                            where r.RoleId == physicianRole.Id || r.RoleId == partnerPhysician.Id

                            select new { s.uss_user_id, u.UserInitial, u.FirstName, u.LastName, u.NPINumber, u.Gender }
                            )
                           .Distinct()
                           .OrderBy(x => x.FirstName).ThenBy(x => x.LastName)
                           .ToList()
                           .Select(x => new Tuple <string, string, string, string, string, string>(x.uss_user_id, string.Format("{0} {1} - {2}", x.FirstName, x.LastName, x.UserInitial), string.Format("#{0:X6}", random.Next(0x1000000)), string.Format("{0} {1} - {2}", x.FirstName, x.LastName, x.UserInitial), x.NPINumber ?? string.Empty, x.Gender))
                           .ToList());
                }
                else
                {
                    return((from u in _unitOfWork.UserRepository.Query().Where(x => x.IsActive && x.IsDeleted == false && x.IsSleep == true)
                            join r in _unitOfWork.UserRoleRepository.Query() on u.Id equals r.UserId
                            where r.RoleId == physicianRole.Id || r.RoleId == partnerPhysician.Id

                            select new { u.Id, u.UserInitial, u.FirstName, u.LastName, u.NPINumber, u.Gender }
                            )
                           .Distinct()
                           .OrderBy(x => x.FirstName).ThenBy(x => x.LastName)
                           .ToList()
                           .Select(x => new Tuple <string, string, string, string, string, string>(x.Id, string.Format("{0} {1} - {2}", x.FirstName, x.LastName, x.UserInitial), string.Format("#{0:X6}", random.Next(0x1000000)), string.Format("{0} {1} - {2}", x.FirstName, x.LastName, x.UserInitial), x.NPINumber ?? string.Empty, x.Gender))
                           .ToList());
                }
            }

            #endregion


            return(null);
        }