Exemplo n.º 1
0
        ///<summary>Copies one fee schedule to one or more fee schedules.  fromClinicNum, fromProvNum, and toProvNum can be zero.  Set listClinicNumsTo to copy to multiple clinic overrides.  If this list is null or empty, clinicNum 0 will be used.</summary>
        public static void CopyFeeSchedule(FeeSched fromFeeSched, long fromClinicNum, long fromProvNum, FeeSched toFeeSched, List <long> listClinicNumsTo, long toProvNum)
        {
            if (RemotingClient.RemotingRole == RemotingRole.ClientWeb)
            {
                Meth.GetVoid(MethodBase.GetCurrentMethod(), fromFeeSched, fromClinicNum, fromProvNum, toFeeSched, listClinicNumsTo, toProvNum);
                return;
            }
            if (listClinicNumsTo == null)
            {
                listClinicNumsTo = new List <long>();
            }
            if (listClinicNumsTo.Count == 0)
            {
                listClinicNumsTo.Add(0);
            }
            //Store a local copy of the fees from the old FeeSched
            List <Fee> listFeeLocalCopy = Fees.GetListExact(toFeeSched.FeeSchedNum, listClinicNumsTo, toProvNum);

            //Delete all fees that exactly match setting in "To" combo selections.
            foreach (long clinicNum in listClinicNumsTo)
            {
                Fees.DeleteFees(toFeeSched.FeeSchedNum, clinicNum, toProvNum);
            }
            //Copy:
            List <Fee>    listNewFees = Fees.GetListExact(fromFeeSched.FeeSchedNum, fromClinicNum, fromProvNum);
            int           blockValue  = 0;
            int           blockMax    = (listNewFees.Count * listClinicNumsTo.Count);
            object        locker      = new object();
            List <Action> listActions = new List <Action>();

            foreach (long clinicNumTo in listClinicNumsTo)
            {
                listActions.Add(() => {
                    foreach (Fee fee in listNewFees)
                    {
                        bool isReplacementFee = false;
                        Fee newFee            = fee.Copy();
                        newFee.FeeNum         = 0;
                        newFee.ProvNum        = toProvNum;
                        newFee.ClinicNum      = clinicNumTo;
                        newFee.FeeSched       = toFeeSched.FeeSchedNum;
                        Fees.Insert(newFee);
                        //Check to see if this replaced an old fee with the same fee details
                        Fee oldFee = listFeeLocalCopy.Where(x => x.ProvNum == newFee.ProvNum)
                                     .Where(x => x.ClinicNum == newFee.ClinicNum)
                                     .Where(x => x.CodeNum == newFee.CodeNum)
                                     .Where(x => x.FeeSched == newFee.FeeSched)
                                     .FirstOrDefault();
                        if (oldFee != null)
                        {
                            isReplacementFee = true;
                        }
                        ProcedureCode procCode = ProcedureCodes.GetProcCode(fee.CodeNum);
                        string securityLogText = "Fee Schedule \"" + fromFeeSched.Description + "\" copied to Fee Schedule \"" + toFeeSched.Description + "\", ";
                        if (clinicNumTo != 0)
                        {
                            securityLogText += "To Clinic \"" + Clinics.GetDesc(clinicNumTo) + "\", ";
                        }
                        securityLogText += "Proc Code \"" + procCode.ProcCode + "\", Fee \"" + fee.Amount + "\", ";
                        if (isReplacementFee)
                        {
                            securityLogText += "Replacing Previous Fee \"" + oldFee.Amount + "\"";
                        }
                        SecurityLogs.MakeLogEntry(Permissions.FeeSchedEdit, 0, securityLogText);
                        FeeSchedEvent.Fire(ODEventType.FeeSched,
                                           new ProgressBarHelper(Lans.g("FormFeeSchedTools", "Copying fees, please wait") + "...", blockValue: blockValue, blockMax: blockMax,
                                                                 progressStyle: ProgBarStyle.Continuous));
                        lock (locker) {
                            blockValue++;
                        }
                    }
                });
            }
            //Research and testing will determine whether we can run this on multiple threads.
            ODThread.RunParallel(listActions, TimeSpan.FromMinutes(30), numThreads: 1);
        }