private Claim CreateClaim(string claimType, List <PatPlan> patPlanList, List <InsPlan> planList, List <ClaimProc> claimProcList, Procedure proc, List <InsSub> subList)
        {
            long           claimFormNum = 0;
            InsPlan        planCur      = new InsPlan();
            InsSub         subCur       = new InsSub();
            Relat          relatOther   = Relat.Self;
            long           clinicNum    = proc.ClinicNum;
            PlaceOfService placeService = proc.PlaceService;

            switch (claimType)
            {
            case "P":
                subCur  = InsSubs.GetSub(PatPlans.GetInsSubNum(patPlanList, PatPlans.GetOrdinal(PriSecMed.Primary, patPlanList, planList, subList)), subList);
                planCur = InsPlans.GetPlan(subCur.PlanNum, planList);
                break;

            case "S":
                subCur  = InsSubs.GetSub(PatPlans.GetInsSubNum(patPlanList, PatPlans.GetOrdinal(PriSecMed.Secondary, patPlanList, planList, subList)), subList);
                planCur = InsPlans.GetPlan(subCur.PlanNum, planList);
                break;

            case "Med":
                //It's already been verified that a med plan exists
                subCur  = InsSubs.GetSub(PatPlans.GetInsSubNum(patPlanList, PatPlans.GetOrdinal(PriSecMed.Medical, patPlanList, planList, subList)), subList);
                planCur = InsPlans.GetPlan(subCur.PlanNum, planList);
                break;
            }
            ClaimProc claimProcCur = Procedures.GetClaimProcEstimate(proc.ProcNum, claimProcList, planCur, subCur.InsSubNum);

            if (claimProcCur == null)
            {
                claimProcCur = new ClaimProc();
                ClaimProcs.CreateEst(claimProcCur, proc, planCur, subCur);
            }
            Claim claimCur = new Claim();

            claimCur.PatNum       = proc.PatNum;
            claimCur.DateService  = proc.ProcDate;
            claimCur.ClinicNum    = proc.ClinicNum;
            claimCur.PlaceService = proc.PlaceService;
            claimCur.ClaimStatus  = "W";
            claimCur.DateSent     = DateTimeOD.Today;
            claimCur.PlanNum      = planCur.PlanNum;
            claimCur.InsSubNum    = subCur.InsSubNum;
            InsSub sub;

            switch (claimType)
            {
            case "P":
                claimCur.PatRelat   = PatPlans.GetRelat(patPlanList, PatPlans.GetOrdinal(PriSecMed.Primary, patPlanList, planList, subList));
                claimCur.ClaimType  = "P";
                claimCur.InsSubNum2 = PatPlans.GetInsSubNum(patPlanList, PatPlans.GetOrdinal(PriSecMed.Secondary, patPlanList, planList, subList));
                sub = InsSubs.GetSub(claimCur.InsSubNum2, subList);
                if (sub.PlanNum > 0 && InsPlans.RefreshOne(sub.PlanNum).IsMedical)
                {
                    claimCur.PlanNum2  = 0;                         //no sec ins
                    claimCur.PatRelat2 = Relat.Self;
                }
                else
                {
                    claimCur.PlanNum2  = sub.PlanNum;                         //might be 0 if no sec ins
                    claimCur.PatRelat2 = PatPlans.GetRelat(patPlanList, PatPlans.GetOrdinal(PriSecMed.Secondary, patPlanList, planList, subList));
                }
                break;

            case "S":
                claimCur.PatRelat   = PatPlans.GetRelat(patPlanList, PatPlans.GetOrdinal(PriSecMed.Secondary, patPlanList, planList, subList));
                claimCur.ClaimType  = "S";
                claimCur.InsSubNum2 = PatPlans.GetInsSubNum(patPlanList, PatPlans.GetOrdinal(PriSecMed.Primary, patPlanList, planList, subList));
                sub = InsSubs.GetSub(claimCur.InsSubNum2, subList);
                claimCur.PlanNum2  = sub.PlanNum;
                claimCur.PatRelat2 = PatPlans.GetRelat(patPlanList, PatPlans.GetOrdinal(PriSecMed.Primary, patPlanList, planList, subList));
                break;

            case "Med":
                claimCur.PatRelat  = PatPlans.GetFromList(patPlanList, subCur.InsSubNum).Relationship;
                claimCur.ClaimType = "Other";
                if (PrefC.GetBool(PrefName.ClaimMedTypeIsInstWhenInsPlanIsMedical))
                {
                    claimCur.MedType = EnumClaimMedType.Institutional;
                }
                else
                {
                    claimCur.MedType = EnumClaimMedType.Medical;
                }
                break;

            case "Other":
                claimCur.PatRelat  = relatOther;
                claimCur.ClaimType = "Other";
                //plannum2 is not automatically filled in.
                claimCur.ClaimForm = claimFormNum;
                if (planCur.IsMedical)
                {
                    if (PrefC.GetBool(PrefName.ClaimMedTypeIsInstWhenInsPlanIsMedical))
                    {
                        claimCur.MedType = EnumClaimMedType.Institutional;
                    }
                    else
                    {
                        claimCur.MedType = EnumClaimMedType.Medical;
                    }
                }
                break;
            }
            if (planCur.PlanType == "c")          //if capitation
            {
                claimCur.ClaimType = "Cap";
            }
            claimCur.ProvTreat = proc.ProvNum;
            if (Providers.GetIsSec(proc.ProvNum))
            {
                claimCur.ProvTreat = Patients.GetPat(proc.PatNum).PriProv;
                //OK if zero, because auto select first in list when open claim
            }
            claimCur.IsProsthesis  = "N";
            claimCur.ProvBill      = Providers.GetBillingProvNum(claimCur.ProvTreat, claimCur.ClinicNum);    //OK if zero, because it will get fixed in claim
            claimCur.EmployRelated = YN.No;
            claimCur.ClaimForm     = planCur.ClaimFormNum;
            Claims.Insert(claimCur);
            //attach procedure
            claimProcCur.ClaimNum = claimCur.ClaimNum;
            if (planCur.PlanType == "c")           //if capitation
            {
                claimProcCur.Status = ClaimProcStatus.CapClaim;
            }
            else
            {
                claimProcCur.Status = ClaimProcStatus.NotReceived;
            }
            if (planCur.UseAltCode && (ProcedureCodes.GetProcCode(proc.CodeNum).AlternateCode1 != ""))
            {
                claimProcCur.CodeSent = ProcedureCodes.GetProcCode(proc.CodeNum).AlternateCode1;
            }
            else if (planCur.IsMedical && proc.MedicalCode != "")
            {
                claimProcCur.CodeSent = proc.MedicalCode;
            }
            else
            {
                claimProcCur.CodeSent = ProcedureCodes.GetProcCode(proc.CodeNum).ProcCode;
                if (claimProcCur.CodeSent.Length > 5 && claimProcCur.CodeSent.Substring(0, 1) == "D")
                {
                    claimProcCur.CodeSent = claimProcCur.CodeSent.Substring(0, 5);
                }
                if (CultureInfo.CurrentCulture.Name.EndsWith("CA"))         //Canadian. en-CA or fr-CA
                {
                    if (claimProcCur.CodeSent.Length > 5)                   //In Canadian e-claims, codes can contain letters or numbers and cannot be longer than 5 characters.
                    {
                        claimProcCur.CodeSent = claimProcCur.CodeSent.Substring(0, 5);
                    }
                }
            }
            claimProcCur.LineNumber = (byte)1;
            ClaimProcs.Update(claimProcCur);
            return(claimCur);
        }