context: using CodeBase;
  using System;
  using System.Collections;
  using System.Collections.Generic;
  using System.Data;
  using System.Diagnostics;
  using System.Reflection;
  
  namespace OpenDentBusiness {
  	///<summary></summary>
  	public class InsPlans {
  		///<summary>Also fills PlanNum from db.</summary>
  		public static long Insert(InsPlan plan) {
  			return Insert(plan,false);
  		}
  		
  		///<summary>Also fills PlanNum from db.</summary>
  		public static long Insert(InsPlan plan,bool useExistingPK) {
  			if(RemotingClient.RemotingRole!=RemotingRole.ServerWeb) {
  				plan.SecUserNumEntry=Security.CurUser.UserNum;//must be before normal remoting role check to get user at workstation
  			}
  			if(RemotingClient.RemotingRole==RemotingRole.ClientWeb) {
  				plan.PlanNum=Meth.GetLong(MethodBase.GetCurrentMethod(),plan,useExistingPK);
  				return plan.PlanNum;
  			}
  			long planNum=0;
  			if(DataConnection.DBtype==DatabaseType.Oracle) {
  				planNum=Crud.InsPlanCrud.Insert(plan);//Oracle ALWAYS uses existing PKs because they do not support auto-incrementing.
  			}
  			else {
  				planNum=Crud.InsPlanCrud.Insert(plan,useExistingPK);
  			}
  			InsVerifies.InsertForPlanNum(planNum);
  			return planNum;
  		}
  
  		///<summary></summary>
  		public static void Update(InsPlan plan) {
  			if(RemotingClient.RemotingRole==RemotingRole.ClientWeb) {
  				Meth.GetVoid(MethodBase.GetCurrentMethod(),plan);
  				return;
  			}
  			Crud.InsPlanCrud.Update(plan);
  		}
  
  		///<summary>It's fastest if you supply a plan list that contains the plan, but it also works just fine if it can't initally locate the plan in the list.  You can supply an list of length 0 or null.  If still not found, returns null.</summary>
  		public static InsPlan GetPlan(long planNum,List<InsPlan> planList) {
  			//No need to check RemotingRole; no call to db.
  			InsPlan retPlan=new InsPlan();
  			if(planNum==0) {
  				return null;
  			}
  			if(planList==null) {
  				planList=new List<InsPlan>();
  			}
  			bool found=false;
  			for(int i=0;i<planList.Count;i++) {
  				if(planList[i].PlanNum==planNum) {
  					found=true;
  					retPlan=planList[i];
  				}
  			}
  			if(!found) {
  				retPlan=RefreshOne(planNum);//retPlan will now be null if not found
  			}
  			if(retPlan==null) {
  				//MessageBox.Show(Lans.g("InsPlans","Database is inconsistent.  Please run the database maintenance tool."));
  				return new InsPlan();
  			}
  			if(retPlan==null) {
  				return null;
  			}
  			return retPlan;
  		}
  
  		/*
  		///<summary>Will return null if no active plan for that ordinal.  Ordinal means primary, secondary, etc.</summary>
  		public static InsPlan GetPlanByOrdinal(int patNum,int ordinal) {
  			string command="SELECT * FROM insplan WHERE EXISTS "
  				+"(SELECT * FROM patplan WHERE insplan.PlanNum=patplan.PlanNum "
  				+"AND patplan.PatNum="+POut.PInt(patNum)
  				+" AND patplan.Ordinal="+POut.PInt(ordinal);
  			//num = '"+planNum+"'";
  		}*/
  
  		public static InsPlan[] GetByTrojanID(string trojanID) {
  			if(RemotingClient.RemotingRole==RemotingRole.ClientWeb) {
  				return Meth.GetObject<InsPlan[]>(MethodBase.GetCurrentMethod(),trojanID);
  			} 
  			string command="SELECT * FROM insplan WHERE TrojanID = '"+POut.String(trojanID)+"'";
  			return Crud.InsPlanCrud.SelectMany(command).ToArray();
  		}
  
  		///<summary>Only loads one plan from db. Can return null.</summary>
  		public static InsPlan RefreshOne(long planNum) {
  			if(RemotingClient.RemotingRole==RemotingRole.ClientWeb) {
  				return Meth.GetObject<InsPlan>(MethodBase.GetCurrentMethod(),planNum);
  			} 
  			if(planNum==0){
  				return null;
  			}
  			string command="SELECT * FROM insplan WHERE plannum = '"+planNum+"'";
  			return Crud.InsPlanCrud.SelectOne(command);
  		}
  
  		//<summary>Deprecated.  Instead, use RefreshForSubList.</summary>
  		//public static List<InsPlan> RefreshForFam(){//Family Fam) {
  		//	return null;
  		//}
  
  		///<summary>Gets List of plans based on the subList.  The list won't be in the same order.</summary>
  		public static List<InsPlan> RefreshForSubList(List<InsSub> subList) {
  			if(RemotingClient.RemotingRole==RemotingRole.ClientWeb) {
  				return Meth.GetObject<List<InsPlan>>(MethodBase.GetCurrentMethod(),subList);
  			}
  			if(subList.Count==0) {
  				return new List<InsPlan>();
  			}
  			string command="SELECT * FROM insplan WHERE";
  			for(int i=0;i<subList.Count;i++) {
  				if(i>0) {
  					command+=" OR";
  				}
  				command+=" PlanNum="+POut.Long(subList[i].PlanNum);
  			}
  			return Crud.InsPlanCrud.SelectMany(command);
  		}
  
  		///<summary>Tests all fields for equality.</summary>
  		public static bool AreEqualValue(InsPlan plan1,InsPlan plan2) {
  			if(plan1.PlanNum==plan2.PlanNum
  				&& plan1.GroupName==plan2.GroupName
  				&& plan1.GroupNum==plan2.GroupNum
  				&& plan1.PlanNote==plan2.PlanNote
  				&& plan1.FeeSched==plan2.FeeSched
  				&& plan1.PlanType==plan2.PlanType
  				&& plan1.ClaimFormNum==plan2.ClaimFormNum
  				&& plan1.UseAltCode==plan2.UseAltCode
  				&& plan1.ClaimsUseUCR==plan2.ClaimsUseUCR
  				&& plan1.CopayFeeSched==plan2.CopayFeeSched
  				&& plan1.EmployerNum==plan2.EmployerNum
  				&& plan1.CarrierNum==plan2.CarrierNum
  				&& plan1.AllowedFeeSched==plan2.AllowedFeeSched
  				&& plan1.TrojanID==plan2.TrojanID
  				&& plan1.DivisionNo==plan2.DivisionNo
  				&& plan1.IsMedical==plan2.IsMedical
  				&& plan1.FilingCode==plan2.FilingCode
  				&& plan1.DentaideCardSequence==plan2.DentaideCardSequence
  				&& plan1.ShowBaseUnits==plan2.ShowBaseUnits
  				&& plan1.CodeSubstNone==plan2.CodeSubstNone
  				&& plan1.IsHidden==plan2.IsHidden
  				&& plan1.MonthRenew==plan2.MonthRenew
  				&& plan1.FilingCodeSubtype==plan2.FilingCodeSubtype
  				&& plan1.CanadianPlanFlag==plan2.CanadianPlanFlag
  				&& plan1.CobRule==plan2.CobRule
  				&& plan1.HideFromVerifyList==plan2.HideFromVerifyList) 
  			{
  				return true;
  			}
  			return false;
  		}
  
  		/*
  		///<summary>Called from FormInsPlan when applying changes to all identical insurance plans. This updates the synchronized fields for all plans like the specified insPlan.  Current InsPlan must be set to the new values that we want.  BenefitNotes and SubscNote are specific to subscriber and are not changed.  PlanNotes are handled separately in a different function after this one is complete.</summary>
  		public static void UpdateForLike(InsPlan like, InsPlan plan) {
  			if(RemotingClient.RemotingRole==RemotingRole.ClientWeb) {
  				Meth.GetVoid(MethodBase.GetCurrentMethod(),like,plan);
  				return;
  			}
  			string command= "UPDATE insplan SET "
  				+"EmployerNum = '"     +POut.Long   (plan.EmployerNum)+"'"
  				+",GroupName = '"      +POut.String(plan.GroupName)+"'"
  				+",GroupNum = '"       +POut.String(plan.GroupNum)+"'"
  				+",DivisionNo = '"     +POut.String(plan.DivisionNo)+"'"
  				+",CarrierNum = '"     +POut.Long   (plan.CarrierNum)+"'"
  				+",PlanType = '"       +POut.String(plan.PlanType)+"'"
  				+",UseAltCode = '"     +POut.Bool  (plan.UseAltCode)+"'"
  				+",IsMedical = '"      +POut.Bool  (plan.IsMedical)+"'"
  				+",ClaimsUseUCR = '"   +POut.Bool  (plan.ClaimsUseUCR)+"'"
  				+",FeeSched = '"       +POut.Long   (plan.FeeSched)+"'"
  				+",CopayFeeSched = '"  +POut.Long   (plan.CopayFeeSched)+"'"
  				+",ClaimFormNum = '"   +POut.Long   (plan.ClaimFormNum)+"'"
  				+",AllowedFeeSched= '" +POut.Long   (plan.AllowedFeeSched)+"'"
  				+",TrojanID = '"       +POut.String(plan.TrojanID)+"'"
  				+",FilingCode = '"     +POut.Long   (plan.FilingCode)+"'"
  				+",FilingCodeSubtype = '"+POut.Long(plan.FilingCodeSubtype)+"'"
  				+",ShowBaseUnits = '"  +POut.Bool  (plan.ShowBaseUnits)+"'"
  				//+",DedBeforePerc = '"  +POut.PBool  (plan.DedBeforePerc)+"'"
  				+",CodeSubstNone='"    +POut.Bool  (plan.CodeSubstNone)+"'"
  				+",IsHidden='"         +POut.Bool  (plan.IsHidden)+"'"
  				+",MonthRenew='"       +POut.Int   (plan.MonthRenew)+"'"
  				//It is most likely that MonthRenew would be the same for everyone on the same plan.  If we get complaints, we might have to add an option.
  				+" WHERE "
  				+"EmployerNum = '"        +POut.Long   (like.EmployerNum)+"' "
  				+"AND GroupName = '"      +POut.String(like.GroupName)+"' "
  				+"AND GroupNum = '"       +POut.String(like.GroupNum)+"' "
  				+"AND DivisionNo = '"     +POut.String(like.DivisionNo)+"'"
  				+"AND CarrierNum = '"     +POut.Long   (like.CarrierNum)+"' "
  				+"AND IsMedical = '"      +POut.Bool  (like.IsMedical)+"'";
  			Db.NonQ(command);
  		}*/
  
  		///<summary>Gets a description of the specified plan, including carrier name and subscriber. It's fastest if you supply a plan list that contains the plan, but it also works just fine if it can't initally locate the plan in the list.  You can supply an array of length 0 for both family and planlist.</summary>
  		public static string GetDescript(long planNum,Family family,List<InsPlan> planList,long insSubNum,List<InsSub> subList) {
  			//No need to check RemotingRole; no call to db.
  			if(planNum==0) {
  				return "";
  			}
  			InsPlan plan=GetPlan(planNum,planList);
  			if(plan==null || plan.PlanNum==0) {
  				return "";
  			}
  			InsSub sub=InsSubs.GetSub(insSubNum,subList);
  			if(sub==null || sub.InsSubNum==0) {
  				return "";
  			}
  			string subscriber=family.GetNameInFamFL(sub.Subscriber);
  			if(subscriber=="") {//subscriber from another family
  				subscriber=Patients.GetLim(sub.Subscriber).GetNameLF();
  			}
  			string retStr="";
  			//loop just to get the index of the plan in the family list
  			bool otherFam=true;
  			for(int i=0;i<planList.Count;i++) {
  				if(planList[i].PlanNum==planNum) {
  					otherFam=false;
  					//retStr += (i+1).ToString()+": ";
  				}
  			}
  			if(otherFam) {//retStr=="")
  				retStr="(other fam):";
  			}
  			Carrier carrier=Carriers.GetCarrier(plan.CarrierNum);
  			string carrierName=carrier.CarrierName;
  			if(carrierName.Length>20) {
  				carrierName=carrierName.Substring(0,20)+"...";
  			}
  			retStr+=carrierName;
  			retStr+=" ("+subscriber+")";
  			return retStr;
  		}
  
  		///<summary>Used in Ins lines in Account module and in Family module.</summary>
  		public static string GetCarrierName(long planNum,List<InsPlan> planList) {
  			//No need to check RemotingRole; no call to db.
  			InsPlan plan=GetPlan(planNum,planList);
  			if(plan==null) {
  				return "";
  			}
  			Carrier carrier=Carriers.GetCarrier(plan.CarrierNum);
  			if(carrier.CarrierNum==0) {//if corrupted
  				return "";
  			}
  			return carrier.CarrierName;
  		}
  
  		/// <summary>Returns a DataTable containing the PlanNum, CarrierNum, and CarrierName for a list of PlanNums.</summary>
  		public static DataTable GetCarrierNames(List<long> listPlanNums) {
  			if(RemotingClient.RemotingRole==RemotingRole.ClientWeb) {
  				return Meth.GetTable(MethodBase.GetCurrentMethod(),listPlanNums);
  			}
  			if(listPlanNums.Count==0) {
  				return new DataTable();
  			}
  			string command="SELECT PlanNum,CarrierNum,'' AS CarrierName FROM insplan WHERE PlanNum IN ("+string.Join(",",listPlanNums)+")";
  			DataTable table=Db.GetTable(command);
  			foreach(DataRow row in table.Rows) {
  				row["CarrierName"]=Carriers.GetName(PIn.Long(row["CarrierNum"].ToString()));
  			}
  			return table;
  		}
  
  		/// <summary>Only used once in Claims.cs.  Gets insurance benefits remaining for one benefit year.  Returns actual remaining insurance based on ClaimProc data, taking into account inspaid and ins pending. Must supply all claimprocs for the patient.  Date used to determine which benefit year to calc.  Usually today's date.  The insplan.PlanNum is the plan to get value for.  ExcludeClaim is the ClaimNum to exclude, or enter -1 to include all.  This does not yet handle calculations where ortho max is different from regular max.  Just takes the most general annual max, and subtracts all benefits used from all categories.</summary>
  		public static double GetInsRem(List<ClaimProcHist> histList,DateTime asofDate,long planNum,long patPlanNum,long excludeClaim,List<InsPlan> planList,List<Benefit> benList,long patNum,long insSubNum) {
  			//No need to check RemotingRole; no call to db.
  			double insUsed=GetInsUsedDisplay(histList,asofDate,planNum,patPlanNum,excludeClaim,planList,benList,patNum,insSubNum);
  			InsPlan plan=InsPlans.GetPlan(planNum,planList);
  			double insPending=GetPendingDisplay(histList,asofDate,plan,patPlanNum,excludeClaim,patNum,insSubNum,benList);
  			double annualMaxFam=Benefits.GetAnnualMaxDisplay(benList,planNum,patPlanNum,true);
  			double annualMaxInd=Benefits.GetAnnualMaxDisplay(benList,planNum,patPlanNum,false);
  			double annualMax=annualMaxInd;
  			if(annualMaxFam>annualMaxInd){
  				annualMax=annualMaxFam;
  			}
  			if(annualMax<0) {
  				return 999999;
  			}
  			if(annualMax-insUsed-insPending<0) {
  				return 0;
  			}
  			return annualMax-insUsed-insPending;
  		}
  
  		///<summary>Only for display purposes rather than for calculations.  Get pending insurance for a given plan for one benefit year. Include a history list for the patient/family.  asofDate used to determine which benefit year to calc.  Usually the date of service for a claim.  The planNum is the plan to get value for.</summary>
  		public static double GetPendingDisplay(List<ClaimProcHist> histList,DateTime asofDate,InsPlan curPlan,long patPlanNum,long excludeClaim,long patNum,long insSubNum,List<Benefit> benefitList) {
  			//No need to check RemotingRole; no call to db.
  			//InsPlan curPlan=GetPlan(planNum,PlanList);
  			if(curPlan==null) {
  				return 0;
  			}
  			//get the most recent renew date, possibly including today:
  			DateTime renewDate=BenefitLogic.ComputeRenewDate(asofDate,curPlan.MonthRenew);
  			DateTime stopDate=renewDate.AddYears(1);
  			double retVal=0;
  			//CovCat generalCat=CovCats.GetForEbenCat(EbenefitCategory.General);
  			//CovSpan[] covSpanArray=null;
  			//if(generalCat!=null) {
  			//  covSpanArray=CovSpans.GetForCat(generalCat.CovCatNum);
  			//}
  			for(int i=0;i<histList.Count;i++) {
  				//if(generalCat!=null) {//If there is a general category, then we only consider codes within it.  This is how we exclude ortho.
  				//  if(!CovSpans.IsCodeInSpans(histList[i].StrProcCode,covSpanArray)) {//for example, ortho
  				//    continue;
  				//  }
  				//}
  				if(Benefits.LimitationExistsNotGeneral(benefitList,curPlan.PlanNum,patPlanNum,histList[i].StrProcCode)) {
  					continue;
  				}
  				if(histList[i].PlanNum==curPlan.PlanNum
  					&& histList[i].InsSubNum==insSubNum
  					&& histList[i].ClaimNum != excludeClaim
  					&& histList[i].ProcDate < stopDate
  					&& histList[i].ProcDate >= renewDate
  					//enum ClaimProcStatus{NotReceived,Received,Preauth,Adjustment,Supplemental}
  					&& histList[i].Status==ClaimProcStatus.NotReceived
  					&& histList[i].PatNum==patNum)
  				//Status Adjustment has no insPayEst, so can ignore it here.
  				{
  					retVal+=histList[i].Amount;
  				}
  			}
  			return retVal;
  		}
  
  		/// <summary>Only for display purposes rather than for calculations.  Get insurance benefits used for one benefit year.  Must supply all relevant hist for the patient.  asofDate is used to determine which benefit year to calc.  Usually date of service for a claim.  The insplan.PlanNum is the plan to get value for.  ExcludeClaim is the ClaimNum to exclude, or enter -1 to include all.  The behavior of this changed in 7.1.  It now only includes values that apply towards annual max.  So if there is a limitation override for a category like ortho or preventive, then completed procedures in those categories will be excluded.  The benefitList passed in might very well have benefits from other insurance plans included.</summary>
  		public static double GetInsUsedDisplay(List<ClaimProcHist> histList,DateTime asofDate,long planNum,long patPlanNum,long excludeClaim,List<InsPlan> planList,List<Benefit> benefitList,long patNum,long insSubNum) {
  			//No need to check RemotingRole; no call to db.
  			InsPlan curPlan=GetPlan(planNum,planList);
  			if(curPlan==null) {
  				return 0;
  			}
  			//get the most recent renew date, possibly including today:
  			DateTime renewDate=BenefitLogic.ComputeRenewDate(asofDate,curPlan.MonthRenew);
  			DateTime stopDate=renewDate.AddYears(1);
  			double retVal=0;
  			//CovCat generalCat=CovCats.GetForEbenCat(EbenefitCategory.General);
  			//CovSpan[] covSpanArray=null;
  			//if(generalCat!=null) {
  			//  covSpanArray=CovSpans.GetForCat(generalCat.CovCatNum);
  			//}
  			for(int i=0;i<histList.Count;i++) {
  				if(histList[i].PlanNum!=planNum
  					|| histList[i].InsSubNum != insSubNum
  					|| histList[i].ClaimNum == excludeClaim
  					|| histList[i].ProcDate.Date >= stopDate
  					|| histList[i].ProcDate.Date < renewDate
  					|| histList[i].PatNum != patNum)
  				{
  					continue;
  				}
  				if(Benefits.LimitationExistsNotGeneral(benefitList,planNum,patPlanNum,histList[i].StrProcCode)) {
  					continue;
  				}
  				//if(generalCat!=null){//If there is a general category, then we only consider codes within it.  This is how we exclude ortho.
  				//	if(histList[i].StrProcCode!="" && !CovSpans.IsCodeInSpans(histList[i].StrProcCode,covSpanArray)){//for example, ortho
  				//		continue;
  				//	}
  				//}
  				//enum ClaimProcStatus{NotReceived,Received,Preauth,Adjustment,Supplemental}
  				if(histList[i].Status==ClaimProcStatus.Received 
  					|| histList[i].Status==ClaimProcStatus.Adjustment
  					|| histList[i].Status==ClaimProcStatus.Supplemental) 
  				{
  					retVal+=histList[i].Amount;
  				}
  			}
  			return retVal;
  		}
  
  		///<summary>Only for display purposes rather than for calculations.  Get insurance deductible used for one benefit year.  Must supply a history list for the patient/family.  asofDate is used to determine which benefit year to calc.  Usually date of service for a claim.  The planNum is the plan to get value for.  ExcludeClaim is the ClaimNum to exclude, or enter -1 to include all.  It includes pending deductibles in the result.</summary>
  		public static double GetDedUsedDisplay(List<ClaimProcHist> histList,DateTime asofDate,long planNum,long patPlanNum,long excludeClaim,List<InsPlan> planList,BenefitCoverageLevel coverageLevel,long patNum) {
  			//No need to check RemotingRole; no call to db.
  			InsPlan curPlan=GetPlan(planNum,planList);
  			if(curPlan==null) {
  				return 0;
  			}
  			//get the most recent renew date, possibly including today. Date based on annual max.
  			DateTime renewDate=BenefitLogic.ComputeRenewDate(asofDate,curPlan.MonthRenew);
  			DateTime stopDate=renewDate.AddYears(1);
  			double retVal=0;
  			for(int i=0;i<histList.Count;i++) {
  				if(histList[i].PlanNum!=planNum
  					|| histList[i].ClaimNum == excludeClaim
  					|| histList[i].ProcDate >= stopDate
  					|| histList[i].ProcDate < renewDate
  					//no need to check status, because only the following statuses will be part of histlist:
  					//Adjustment,NotReceived,Received,Supplemental
  					)
  				{
  					continue;
  				}
  				if(coverageLevel!=BenefitCoverageLevel.Family && histList[i].PatNum != patNum) {
  					continue;//to exclude histList items from other family members
  				}
  				retVal+=histList[i].Deduct;
  			}
  			return retVal;
  		}
  
  		///<summary>Only for display purposes rather than for calculations.  Get insurance deductible used for one benefit year.  Must supply a history list for the patient/family.  asofDate is used to determine which benefit year to calc.  Usually date of service for a claim.  The planNum is the plan to get value for.  ExcludeClaim is the ClaimNum to exclude, or enter -1 to include all.  It includes pending deductibles in the result. The ded and dedFam variables are the individual and family deductibles respectively. This function assumes that the individual deductible 'ded' is always available, but that the family deductible 'dedFam' is optional (set to -1 if not available).</summary>
  		public static double GetDedRemainDisplay(List<ClaimProcHist> histList,DateTime asofDate,long planNum,long patPlanNum,long excludeClaim,List<InsPlan> planList,long patNum,double ded,double dedFam) {
  			//No need to check RemotingRole; no call to db.
  			InsPlan curPlan=GetPlan(planNum,planList);
  			if(curPlan==null) {
  				return 0;
  			}
  			//get the most recent renew date, possibly including today. Date based on annual max.
  			DateTime renewDate=BenefitLogic.ComputeRenewDate(asofDate,curPlan.MonthRenew);
  			DateTime stopDate=renewDate.AddYears(1);
  			double dedRemInd=ded;
  			double dedRemFam=dedFam;
  			for(int i=0;i<histList.Count;i++) {
  				if(histList[i].PlanNum!=planNum
  					|| histList[i].ClaimNum == excludeClaim
  					|| histList[i].ProcDate >= stopDate
  					|| histList[i].ProcDate < renewDate
  					//no need to check status, because only the following statuses will be part of histlist:
  					//Adjustment,NotReceived,Received,Supplemental
  					) {
  					continue;
  				}
  				dedRemFam-=histList[i].Deduct;
  				if(histList[i].PatNum==patNum) {
  					dedRemInd-=histList[i].Deduct;
  				}
  			}
  			if(dedFam>=0) {
  				return Math.Max(0,Math.Min(dedRemInd,dedRemFam));//never negative
  			}
  			return Math.Max(0,dedRemInd);//never negative
  		}
  
  		/*
  		///<summary>Used once from Claims and also in ContrTreat.  Gets insurance deductible remaining for one benefit year which includes the given date.  Must supply all claimprocs for the patient.  Must supply all benefits for patient so that we know if it's a service year or a calendar year.  Date used to determine which benefit year to calc.  Usually today's date.  The insplan.PlanNum is the plan to get value for.  ExcludeClaim is the ClaimNum to exclude, or enter -1 to include all.  The supplied procCode is needed because some deductibles, for instance, do not apply to preventive.</summary>
  		public static double GetDedRem(List<ClaimProc> claimProcList,DateTime date,int planNum,int patPlanNum,int excludeClaim,List<InsPlan> PlanList,List<Benefit> benList,string procCode) {
  			//No need to check RemotingRole; no call to db.
  			double dedTot=Benefits.GetDeductibleByCode(benList,planNum,patPlanNum,procCode);
  			double dedUsed=GetDedUsed(claimProcList,date,planNum,patPlanNum,excludeClaim,PlanList,benList);
  			if(dedTot-dedUsed<0){
  				return 0;
  			}
  			return dedTot-dedUsed;
  		}*/
  
  		/*
  		///<Summary>Only used in TP to calculate discount for PPO procedure.  Will return -1 if no fee found.</Summary>
  		public static double GetPPOAllowed(int codeNum,InsPlan plan){
  			//plan has already been tested to not be null and to be a PPO plan.
  			double fee=Fees.GetAmount(codeNum,plan.FeeSched);//could be -1
  		}*/
  
  		///<summary>This is used in FormQuery.SubmitQuery to allow display of carrier names.</summary>
  		public static Hashtable GetHListAll(){
  			//No need to check RemotingRole; no call to db.
  			DataTable table=GetCarrierTable();
  			Hashtable HListAll=new Hashtable(table.Rows.Count);
  			long plannum;
  			string carrierName;
  			for(int i=0;i<table.Rows.Count;i++){
  				plannum=PIn.Long(table.Rows[i][0].ToString());
  				carrierName=PIn.String(table.Rows[i][1].ToString());
  				HListAll.Add(plannum,carrierName);
  			}
  			return HListAll;
  		}
  
  		public static DataTable GetCarrierTable() {
  			if(RemotingClient.RemotingRole==RemotingRole.ClientWeb) {
  				return Meth.GetTable(MethodBase.GetCurrentMethod());
  			}
  			string command="SELECT insplan.PlanNum,carrier.CarrierName "
  				+"FROM insplan,carrier "
  				+"WHERE insplan.CarrierNum=carrier.CarrierNum";
  			return Db.GetTable(command);
  		}
  		/*
  		///<summary>Used by Trojan.  Gets all distinct notes for the planNums supplied.  Includes blank notes.</summary>
  		public static string[] GetNotesForPlans(List<long> planNums) {
  			if(RemotingClient.RemotingRole==RemotingRole.ClientWeb) {
  				return Meth.GetObject<string[]>(MethodBase.GetCurrentMethod(),planNums,excludePlanNum);
  			}
  			if(planNums.Count==0) {//this should never happen, but just in case...
  				return new string[0];
  			}
  
gt: 			if(planNums.Count==1 && planNums[0]==excludePlanNum){