예제 #1
0
        public static bool Sync(List <UserClinic> listNew, long userNum)
        {
            if (RemotingClient.RemotingRole == RemotingRole.ClientWeb)
            {
                return(Meth.GetBool(MethodBase.GetCurrentMethod(), listNew, userNum));
            }
            List <UserClinic> listOld = UserClinics.GetForUser(userNum);

            return(Crud.UserClinicCrud.Sync(listNew, listOld));
        }
예제 #2
0
        ///<summary>Gets all the employees for a specific clinicNum, according to their associated user.  Pass in a clinicNum of 0 to get the list of unassigned or "all" employees (depending on isAll flag).  In addition to setting clinicNum to 0, set isAll true to get a list of all employees or false to get a list of employees that are not associated to any clinics.  Always gets the list of employees from the cache which is sorted by FName, LastName.</summary>
        public static List <Employee> GetEmpsForClinic(long clinicNum, bool isAll, bool getUnassigned = false)
        {
            //No need to check RemotingRole; no call to db.
            List <Employee> listEmpsShort = Employees.GetDeepCopy(true);

            if (!PrefC.HasClinicsEnabled || (clinicNum == 0 && isAll))           //Simply return all employees.
            {
                return(listEmpsShort);
            }
            List <Employee> listEmpsWithClinic = new List <Employee>();
            List <Employee> listEmpsUnassigned = new List <Employee>();
            Dictionary <long, List <UserClinic> > dictUserClinics = new Dictionary <long, List <UserClinic> >();

            foreach (Employee empCur in listEmpsShort)
            {
                List <Userod> listUsers = Userods.GetUsersByEmployeeNum(empCur.EmployeeNum);
                if (listUsers.Count == 0)
                {
                    listEmpsUnassigned.Add(empCur);
                    continue;
                }
                foreach (Userod userCur in listUsers)             //At this point we know there is at least one Userod associated to this employee.
                {
                    if (userCur.ClinicNum == 0)                   //User's default clinic is HQ
                    {
                        listEmpsUnassigned.Add(empCur);
                        continue;
                    }
                    if (!dictUserClinics.ContainsKey(userCur.UserNum))                              //User is restricted to a clinic(s).  Compare to clinicNum
                    {
                        dictUserClinics[userCur.UserNum] = UserClinics.GetForUser(userCur.UserNum); //run only once per user
                    }
                    if (dictUserClinics[userCur.UserNum].Count == 0)                                //unrestricted user, employee should show in all lists
                    {
                        listEmpsUnassigned.Add(empCur);
                        listEmpsWithClinic.Add(empCur);
                    }
                    else if (dictUserClinics[userCur.UserNum].Any(x => x.ClinicNum == clinicNum))                   //user restricted to this clinic
                    {
                        listEmpsWithClinic.Add(empCur);
                    }
                }
            }
            if (getUnassigned)
            {
                return(listEmpsUnassigned.Union(listEmpsWithClinic).OrderBy(x => Employees.GetNameFL(x)).ToList());
            }
            //Returning the isAll employee list was handled above (all non-hidden emps, ListShort).
            if (clinicNum == 0)                                                                         //Return list of unassigned employees.  This is used for the 'Headquarters' clinic filter.
            {
                return(listEmpsUnassigned.GroupBy(x => x.EmployeeNum).Select(x => x.First()).ToList()); //select distinct emps
            }
            //Return list of employees restricted to the specified clinic.
            return(listEmpsWithClinic.GroupBy(x => x.EmployeeNum).Select(x => x.First()).ToList());           //select distinct emps
        }
예제 #3
0
        public static List <Clinic> GetAllForUserod(Userod curUser)
        {
            List <Clinic> listClinics = GetDeepCopy();

            if (!PrefC.HasClinicsEnabled)
            {
                return(listClinics);
            }
            if (curUser.ClinicIsRestricted && curUser.ClinicNum != 0)
            {
                List <UserClinic> listUserClinics = UserClinics.GetForUser(curUser.UserNum);
                return(listClinics.FindAll(x => listUserClinics.Exists(y => y.ClinicNum == x.ClinicNum)).ToList());
            }
            return(listClinics);
        }
예제 #4
0
        ///<summary>Returns a list of clinics the curUser has permission to access.
        ///If the user is not restricted, the list will contain all of the clinics. Does NOT include hidden clinics (and never should anyway).</summary>
        ///<param name="doIncludeHQ">If true and the user is not restricted, includes HQ as a clinic with a ClinicNum of 0, even if clinics are disabled.</param>
        public static List <Clinic> GetForUserod(Userod curUser, bool doIncludeHQ = false, string hqClinicName = null)
        {
            List <Clinic> listClinics = new List <Clinic>();

            //Add HQ clinic if requested, even if clinics are disabled.  Counter-intuitive, but required for offices that had clinics enabled and then
            //turned them off.  If clinics are enabled and the user is restricted this will be filtered out below.
            if (doIncludeHQ)
            {
                listClinics.Add(GetPracticeAsClinicZero(hqClinicName));
            }
            listClinics.AddRange(GetDeepCopy(true));            //don't include hidden clinics
            if (PrefC.HasClinicsEnabled && curUser.ClinicIsRestricted && curUser.ClinicNum != 0)
            {
                //Clinics are enabled and user is restricted, return clinics the person has permission for.
                List <long> listUserClinicNums = UserClinics.GetForUser(curUser.UserNum).Select(x => x.ClinicNum).ToList();
                listClinics.RemoveAll(x => !listUserClinicNums.Contains(x.ClinicNum));                //Remove all clinics that are not in the list of UserClinics.
            }
            return(listClinics);
        }
예제 #5
0
        ///<summary>Returns a list of clinics the curUser has permission to access.
        ///If the user is not restricted, the list will contain all of the clinics. Does NOT include hidden clinics (and never should anyway).</summary>
        ///<param name="doIncludeHQ">If true and the user is not restricted, includes HQ as a clinic with a ClinicNum of 0.</param>
        public static List <Clinic> GetForUserod(Userod curUser, bool doIncludeHQ = false, string hqClinicName = null)
        {
            if (!PrefC.HasClinicsEnabled)             //clinics not enabled, return all clinics. Counter-intuitive, but required for offices that had clinics enabled and then turned them off.
            {
                return(GetDeepCopy());
            }
            List <Clinic> listClinics = GetDeepCopy(true);

            if (curUser.ClinicIsRestricted && curUser.ClinicNum != 0)           //User is restricted, return clinics the person has permission for.
            {
                List <UserClinic> listUserClinics = UserClinics.GetForUser(curUser.UserNum);
                //Find all clinics that there is a UserClinic entry for.
                return(listClinics.FindAll(x => listUserClinics.Exists(y => y.ClinicNum == x.ClinicNum)).ToList());
            }
            //User is not restricted, return all clinics.
            if (doIncludeHQ)
            {
                listClinics.Insert(0, GetPracticeAsClinicZero(hqClinicName));
            }
            return(listClinics);
        }