///<summary>Replaces ImportCanadaFeeSchedule. Imports a canadian fee schedule. Called only in FormFeeSchedTools, located here to allow unit testing. ///Fires FeeSchedEvents for a progress bar.</summary> public static List <Fee> ImportCanadaFeeSchedule2(FeeSched feeSched, string feeData, long clinicNum, long provNum, out int numImported, out int numSkipped) { //No need to check RemotingRole; no call to db. string[] feeLines = feeData.Split('\n'); numImported = 0; numSkipped = 0; List <Fee> listFees = Fees.GetListExact(feeSched.FeeSchedNum, clinicNum, provNum); List <Fee> listFeesImported = new List <Fee>(listFees); for (int i = 0; i < feeLines.Length; i++) { string[] fields = feeLines[i].Split('\t'); if (fields.Length > 1) // && fields[1]!=""){//we no longer skip blank fees { string procCode = fields[0]; if (ProcedureCodes.IsValidCode(procCode)) { long codeNum = ProcedureCodes.GetCodeNum(procCode); Fee fee = Fees.GetFee(codeNum, feeSched.FeeSchedNum, clinicNum, provNum, listFees); //gets best match if (fields[1] == "") //an empty entry will delete an existing fee, but not insert a blank override { if (fee == null) //nothing to do { } else { //doesn't matter if the existing fee is an override or not. Fees.Delete(fee); listFeesImported.Remove(fee); } } else //value found in text file { if (fee == null) //no current fee { fee = new Fee(); fee.Amount = PIn.Double(fields[1], doUseEnUSFormat: true); //The fees are always in the format "1.00" so we need to parse accordingly. fee.FeeSched = feeSched.FeeSchedNum; fee.CodeNum = codeNum; fee.ClinicNum = clinicNum; fee.ProvNum = provNum; Fees.Insert(fee); listFeesImported.Add(fee); } else { fee.Amount = PIn.Double(fields[1], doUseEnUSFormat: true); Fees.Update(fee); } } numImported++; } else { numSkipped++; } FeeSchedEvent.Fire(ODEventType.FeeSched, new ProgressBarHelper(Lans.g("FeeScheds", "Processing fees, please wait") + "...", "", (numImported + numSkipped), feeLines.Length, ProgBarStyle.Continuous)); } } return(listFeesImported); }
///<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); }