Пример #1
0
        public static List <PayPlanProductionEntry> GetProductionForLinks(List <PayPlanLink> listCredits)
        {
            //No remoting role check; no call to db
            List <long> listProcNums          = listCredits.FindAll(x => x.LinkType == PayPlanLinkType.Procedure).Select(x => x.FKey).ToList();
            List <long> listAdjNumsForCredits = listCredits.FindAll(x => x.LinkType == PayPlanLinkType.Adjustment).Select(x => x.FKey).ToList();
            List <PayPlanProductionEntry> listPayPlanProductionEntries = new List <PayPlanProductionEntry>();
            //ortho cases to be implemented later.
            List <Procedure>  listProcedures        = Procedures.GetManyProc(listProcNums, false);
            List <Adjustment> listCreditAdjustments = Adjustments.GetMany(listAdjNumsForCredits);
            List <Adjustment> listProcAdjustments   = Adjustments.GetForProcs(listProcNums);
            List <ClaimProc>  listClaimProcs        = ClaimProcs.GetForProcs(listProcNums); //used for calculating patient porition

            foreach (PayPlanLink credit in listCredits)
            {
                if (credit.LinkType == PayPlanLinkType.Procedure)
                {
                    Procedure proc = listProcedures.FirstOrDefault(x => x.ProcNum == credit.FKey);
                    if (proc != null)
                    {
                        listPayPlanProductionEntries.Add(new PayPlanProductionEntry(proc, credit, listClaimProcs, listProcAdjustments));
                    }
                }
                else if (credit.LinkType == PayPlanLinkType.Adjustment)
                {
                    Adjustment adj = listCreditAdjustments.FirstOrDefault(x => x.AdjNum == credit.FKey);
                    if (adj != null)
                    {
                        listPayPlanProductionEntries.Add(new PayPlanProductionEntry(adj, credit));
                    }
                }
            }
            return(listPayPlanProductionEntries);
        }
Пример #2
0
        ///<summary>Gets the data necesary to load FormApptEdit.</summary>
        public static LoadData GetLoadData(Appointment AptCur, bool IsNew)
        {
            if (RemotingClient.RemotingRole == RemotingRole.ClientWeb)
            {
                return(Meth.GetObject <LoadData>(MethodBase.GetCurrentMethod(), AptCur, IsNew));
            }
            LoadData data = new LoadData();

            data.ListProcsForAppt = Procedures.GetProcsForApptEdit(AptCur);
            data.ListAppointments = Appointments.GetAppointmentsForProcs(data.ListProcsForAppt);
            data.Family           = Patients.GetFamily(AptCur.PatNum);
            data.ListPatPlans     = PatPlans.Refresh(AptCur.PatNum);
            data.ListInsSubs      = InsSubs.RefreshForFam(data.Family);
            data.ListBenefits     = Benefits.Refresh(data.ListPatPlans, data.ListInsSubs);
            data.ListInsPlans     = InsPlans.RefreshForSubList(data.ListInsSubs);
            data.TableApptFields  = Appointments.GetApptFields(AptCur.AptNum);
            data.TableComms       = Appointments.GetCommTable(AptCur.PatNum.ToString(), AptCur.AptNum);
            data.Lab             = (IsNew ? null : LabCases.GetForApt(AptCur));
            data.PatientTable    = Appointments.GetPatTable(AptCur.PatNum.ToString(), AptCur);
            data.ListClaimProcs  = ClaimProcs.RefreshForProcs(data.ListProcsForAppt.Select(x => x.ProcNum).ToList());
            data.ListAdjustments = Adjustments.GetForProcs(data.ListProcsForAppt.Select(x => x.ProcNum).ToList());
            if (!PrefC.GetBool(PrefName.EasyHideDentalSchools))
            {
                data.ListStudents = ReqStudents.GetForAppt(AptCur.AptNum);
            }
            return(data);
        }
Пример #3
0
        ///<summary>Returns a list of overcharged payplans from the listPayPlanNums. Only necessary for Dynamic Payment Plans.
        ///Returns an empty list if none are overcharged.</summary>
        public static List <PayPlan> GetOverchargedPayPlans(List <long> listPayPlanNums)
        {
            if (RemotingClient.RemotingRole == RemotingRole.ClientWeb)
            {
                return(Meth.GetObject <List <PayPlan> >(MethodBase.GetCurrentMethod(), listPayPlanNums));
            }
            List <PayPlan> listDynamicPayPlansForPatient = new List <PayPlan>();

            foreach (long payPlanNum in listPayPlanNums)
            {
                if (payPlanNum == 0)
                {
                    continue;                    //do not include installment plans
                }
                PayPlan payPlanCur = PayPlans.GetOne(payPlanNum);
                if (payPlanCur.IsDynamic)                 //Only add Dynamic PayPlans to the list since they are all we care about
                {
                    listDynamicPayPlansForPatient.Add(payPlanCur);
                }
            }
            #region Get Data
            List <PayPlanLink>   listPayPlanLinksAll        = PayPlanLinks.GetForPayPlans(listPayPlanNums);
            List <long>          listProcedureLinkFKeys     = listPayPlanLinksAll.Where(x => x.LinkType == PayPlanLinkType.Procedure).Select(x => x.FKey).ToList();
            List <long>          listAdjustmentLinkFKeys    = listPayPlanLinksAll.Where(x => x.LinkType == PayPlanLinkType.Adjustment).Select(x => x.FKey).ToList();
            List <PayPlanCharge> listPayPlanCharges         = PayPlanCharges.GetForPayPlans(listPayPlanNums);
            List <Procedure>     listProcsAttachedToPayPlan = Procedures.GetManyProc(listProcedureLinkFKeys, false);
            List <Adjustment>    listAdjsAttachedToPayPlan  = Adjustments.GetMany(listAdjustmentLinkFKeys);
            List <ClaimProc>     listClaimProcsForProcs     = ClaimProcs.GetForProcs(listProcedureLinkFKeys);
            List <Adjustment>    listAdjForProcs            = Adjustments.GetForProcs(listProcedureLinkFKeys);
            #endregion Get Data
            List <PayPlan> listPayPlansOvercharged = new List <PayPlan>();
            foreach (PayPlan payPlanCur in listDynamicPayPlansForPatient)
            {
                List <PayPlanLink> listLinksForPayPlan = listPayPlanLinksAll.FindAll(x => x.PayPlanNum == payPlanCur.PayPlanNum);
                //Get total amount that has been debited for the current pay plan thus far.
                decimal amtDebitedTotal = listPayPlanCharges.FindAll(x => x.PayPlanNum == payPlanCur.PayPlanNum && x.ChargeType == PayPlanChargeType.Debit)
                                          .Sum(x => (decimal)x.Principal);
                #region Sum Linked Production
                decimal totalPrincipalForPayPlan = 0;
                foreach (PayPlanLink payPlanLink in listLinksForPayPlan)
                {
                    PayPlanProductionEntry productionEntry = null;
                    if (payPlanLink.LinkType == PayPlanLinkType.Procedure)
                    {
                        Procedure proc = listProcsAttachedToPayPlan.FirstOrDefault(x => x.ProcNum == payPlanLink.FKey);
                        if (proc != null)
                        {
                            productionEntry = new PayPlanProductionEntry(proc, payPlanLink, listClaimProcsForProcs, listAdjForProcs);
                        }
                    }
                    else if (payPlanLink.LinkType == PayPlanLinkType.Adjustment)
                    {
                        Adjustment adj = listAdjsAttachedToPayPlan.FirstOrDefault(x => x.AdjNum == payPlanLink.FKey);
                        if (adj != null)
                        {
                            productionEntry = new PayPlanProductionEntry(adj, payPlanLink);
                        }
                    }
                    if (productionEntry != null)
                    {
                        if (productionEntry.AmountOverride == 0)
                        {
                            totalPrincipalForPayPlan += productionEntry.AmountOriginal;
                        }
                        else
                        {
                            totalPrincipalForPayPlan += productionEntry.AmountOverride;
                        }
                    }
                }
                #endregion Sum Linked Production
                //If the total that has been debited thus far exceeds the total principal for the pay plan, it is overcharged.
                if (amtDebitedTotal.IsGreaterThan(totalPrincipalForPayPlan))
                {
                    listPayPlansOvercharged.Add(payPlanCur);
                }
            }
            return(listPayPlansOvercharged);
        }
Пример #4
0
        private static List <TreatPlanPresenterEntry> GetListTreatPlanPresenterEntries(List <long> listClinicNums, bool isFirstPresenter, bool isPresenter
                                                                                       , DateTime dateStart, DateTime dateEnd)
        {
            //No need to check RemotingRole; private method.
            List <Procedure> listProcsComplete   = ReportsComplex.RunFuncOnReportServer(() => Procedures.GetCompletedForDateRangeLimited(dateStart, dateEnd, listClinicNums));
            List <ProcTP>    listProcTPs         = ReportsComplex.RunFuncOnReportServer(() => ProcTPs.GetForProcs(listProcsComplete.Select(x => x.ProcNum).ToList()));
            List <Procedure> listTreatPlanProcs  = listProcsComplete.Where(x => listProcTPs.Select(y => y.ProcNumOrig).Contains(x.ProcNum)).ToList();
            List <TreatPlan> listSavedTreatPlans = ReportsComplex.RunFuncOnReportServer(() => TreatPlans.GetFromProcTPs(listProcTPs));          // attached proctps to treatment plans.
            List <ClaimProc> listClaimProcs      = ReportsComplex.RunFuncOnReportServer(() => ClaimProcs.GetForProcsLimited(listTreatPlanProcs.Select(x => x.ProcNum).ToList(),
                                                                                                                            ClaimProcStatus.Received, ClaimProcStatus.Supplemental, ClaimProcStatus.CapComplete, ClaimProcStatus.NotReceived));
            List <Adjustment> listAdjustments = ReportsComplex.RunFuncOnReportServer(() => Adjustments.GetForProcs(listTreatPlanProcs.Select(x => x.ProcNum).ToList()));
            List <Userod>     listUserods     = ReportsComplex.RunFuncOnReportServer(() => Userods.GetAll());
            List <TreatPlanPresenterEntry> listTreatPlanPresenterEntries = new List <TreatPlanPresenterEntry>();
            List <ProcedureCode>           listProcCodes = ProcedureCodes.GetCodesForCodeNums(listTreatPlanProcs.Select(x => x.CodeNum).ToList());

            foreach (Procedure procCur in listTreatPlanProcs)
            {
                double grossProd = procCur.ProcFeeTotal;
                double writeOffs = listClaimProcs.Where(x => x.ProcNum == procCur.ProcNum)
                                   .Where(x => x.Status == ClaimProcStatus.CapComplete)
                                   .Sum(x => x.WriteOff);
                grossProd -= writeOffs;
                writeOffs  = listClaimProcs.Where(x => x.ProcNum == procCur.ProcNum)
                             .Where(x => x.Status == ClaimProcStatus.NotReceived ||
                                    x.Status == ClaimProcStatus.Received ||
                                    x.Status == ClaimProcStatus.Supplemental)
                             .Sum(x => x.WriteOff);
                double    adjustments = listAdjustments.Where(x => x.ProcNum == procCur.ProcNum).Sum(x => x.AdjAmt);
                double    netProd     = grossProd - writeOffs + adjustments;
                TreatPlan treatPlanCur;
                if (isFirstPresenter)
                {
                    treatPlanCur = listSavedTreatPlans.Where(x => x.ListProcTPs.Any(y => y.ProcNumOrig == procCur.ProcNum)).OrderBy(x => x.DateTP).First();
                }
                else                   //radioLastPresented
                {
                    treatPlanCur = listSavedTreatPlans.Where(x => x.ListProcTPs.Any(y => y.ProcNumOrig == procCur.ProcNum)).OrderByDescending(x => x.DateTP).First();
                }
                Userod userPresenter;
                if (isPresenter)
                {
                    userPresenter = listUserods.FirstOrDefault(x => x.UserNum == treatPlanCur.UserNumPresenter);
                }
                else                   //radioEntryUser
                {
                    userPresenter = listUserods.FirstOrDefault(x => x.UserNum == treatPlanCur.SecUserNumEntry);
                }
                ProcedureCode procCode = listProcCodes.First(x => x.CodeNum == procCur.CodeNum);
                listTreatPlanPresenterEntries.Add(new TreatPlanPresenterEntry()
                {
                    Presenter        = userPresenter == null?"":userPresenter.UserName,
                    DatePresented    = treatPlanCur.DateTP,
                    DateCompleted    = procCur.ProcDate,
                    ProcDescript     = procCode.Descript,
                    GrossProd        = grossProd,
                    Adjustments      = adjustments,
                    WriteOffs        = writeOffs,
                    NetProd          = netProd,
                    UserNumPresenter = userPresenter == null?0:userPresenter.UserNum,
                    PresentedClinic  = procCur.ClinicNum
                });
            }
            return(listTreatPlanPresenterEntries);
        }
        ///<summary>If not using clinics then supply an empty list of clinicNums.</summary>
        public static DataTable GetTreatPlanPresentationStatistics(DateTime dateStart, DateTime dateEnd, bool isFirstPresented, bool hasAllClinics
                                                                   , bool hasClinicsEnabled, bool isPresenter, bool isGross, bool hasAllUsers, List <long> listUserNums, List <long> listClinicNums)
        {
            if (RemotingClient.RemotingRole == RemotingRole.ClientWeb)
            {
                return(Meth.GetTable(MethodBase.GetCurrentMethod(), dateStart, dateEnd, isFirstPresented, hasAllClinics, hasClinicsEnabled, isPresenter, isGross
                                     , hasAllUsers, listUserNums, listClinicNums));
            }
            List <ProcTP>          listProcTPsAll       = ReportsComplex.RunFuncOnReportServer(() => ProcTPs.GetAllLim());
            List <TreatPlan>       listSavedTreatPlans  = ReportsComplex.RunFuncOnReportServer(() => TreatPlans.GetAllSavedLim());
            List <ProcTpTreatPlan> listProcTPTreatPlans = new List <ProcTpTreatPlan>();

            listProcTPsAll.ForEach(x =>
            {
                listProcTPTreatPlans.Add(new ProcTpTreatPlan()
                {
                    TreatPlanCur = listSavedTreatPlans.First(y => y.TreatPlanNum == x.TreatPlanNum),
                    ProcTPCur    = x
                });
            });
            //get one entry per procedure with their first/last date of presentation based on radio buttons.
            if (isFirstPresented)
            {
                listProcTPTreatPlans = listProcTPTreatPlans
                                       .OrderBy(x => x.ProcTPCur.ProcNumOrig)
                                       .ThenBy(x => x.TreatPlanCur.DateTP)
                                       .ThenBy(x => x.TreatPlanCur.TreatPlanNum)
                                       .GroupBy(x => x.ProcTPCur.ProcNumOrig)
                                       .Select(x => x.First())
                                       .ToList();
            }
            else
            {
                listProcTPTreatPlans = listProcTPTreatPlans
                                       .OrderBy(x => x.ProcTPCur.ProcNumOrig)
                                       .ThenByDescending(x => x.TreatPlanCur.DateTP)
                                       .ThenBy(x => x.TreatPlanCur.TreatPlanNum)
                                       .GroupBy(x => x.ProcTPCur.ProcNumOrig)
                                       .Select(x => x.First())
                                       .ToList();
            }
            //get rid of any entries that are outside the range selected.
            listProcTPTreatPlans = listProcTPTreatPlans.Where(x => x.TreatPlanCur.DateTP.Date >= dateStart &&
                                                              x.TreatPlanCur.DateTP.Date <= dateEnd).ToList();
            //Get the associated procedures, claimprocs, adjustments, users, appointments.
            List <Procedure> listProcsForTreatPlans = ReportsComplex.RunFuncOnReportServer(() =>
                                                                                           Procedures.GetForProcTPs(listProcTPTreatPlans.Select(x => x.ProcTPCur).ToList(), ProcStat.C, ProcStat.TP));

            if (hasClinicsEnabled && !hasAllClinics)
            {
                listProcsForTreatPlans =
                    listProcsForTreatPlans.FindAll(x => listClinicNums.Contains(x.ClinicNum));
            }
            List <ClaimProc> listClaimProcs = ReportsComplex.RunFuncOnReportServer(() => ClaimProcs.GetForProcsLimited(listProcsForTreatPlans.Select(x => x.ProcNum).ToList(),
                                                                                                                       ClaimProcStatus.CapComplete, ClaimProcStatus.NotReceived, ClaimProcStatus.Received, ClaimProcStatus.Supplemental, ClaimProcStatus.Estimate));
            List <Adjustment> listAdjustments = ReportsComplex.RunFuncOnReportServer(() => Adjustments.GetForProcs(listProcsForTreatPlans.Select(x => x.ProcNum).ToList()));
            List <Userod>     listUserods     = ReportsComplex.RunFuncOnReportServer(() => Userods.GetAll());
            List <TreatPlanPresenterEntry> listTreatPlanPresenterEntries = new List <TreatPlanPresenterEntry>();
            List <ProcedureCode>           listProcCodes = ReportsComplex.RunFuncOnReportServer(() => ProcedureCodes.GetCodesForCodeNums(listProcsForTreatPlans.Select(x => x.CodeNum).ToList()));
            List <Appointment>             listApts      = ReportsComplex.RunFuncOnReportServer(() => Appointments.GetMultApts(listProcsForTreatPlans.Select(x => x.AptNum).ToList()));
            double amt = listProcsForTreatPlans.Sum(x => x.ProcFee);

            foreach (Procedure procCur in listProcsForTreatPlans)
            {
                double grossProd = procCur.ProcFeeTotal;
                double writeOffs = listClaimProcs.Where(x => x.ProcNum == procCur.ProcNum)
                                   .Where(x => x.Status == ClaimProcStatus.CapComplete)
                                   .Sum(x => x.WriteOff);
                grossProd -= writeOffs;
                if (procCur.ProcStatus == ProcStat.C)
                {
                    writeOffs += listClaimProcs.Where(x => x.ProcNum == procCur.ProcNum)
                                 .Where(x => x.Status.In(ClaimProcStatus.NotReceived, ClaimProcStatus.Received, ClaimProcStatus.Supplemental))
                                 .Sum(x => x.WriteOff);
                }
                else
                {
                    foreach (ClaimProc claimProcCur in listClaimProcs.Where(x => x.ProcNum == procCur.ProcNum).Where(x => x.Status == ClaimProcStatus.Estimate))
                    {
                        if (claimProcCur.WriteOffEstOverride == -1)
                        {
                            if (claimProcCur.WriteOffEst != -1)
                            {
                                writeOffs += claimProcCur.WriteOffEst;
                            }
                        }
                        else
                        {
                            writeOffs += claimProcCur.WriteOffEstOverride;
                        }
                    }
                    //writeOffs += listClaimProcs.Where(x => x.ProcNum == procCur.ProcNum)
                    //	.Where(x => x.Status == ClaimProcStatus.Estimate)
                    //	.Sum(x => x.WriteOffEstOverride == -1 ? (x.WriteOffEst == -1 ? 0 : x.WriteOffEst) : x.WriteOffEstOverride); //Allen won't let me commit this nested ternary :(
                }
                double    adjustments  = listAdjustments.Where(x => x.ProcNum == procCur.ProcNum).Sum(x => x.AdjAmt);
                double    netProd      = grossProd - writeOffs + adjustments;
                TreatPlan treatPlanCur = listProcTPTreatPlans.Where(x => x.ProcTPCur.ProcNumOrig == procCur.ProcNum).First().TreatPlanCur;
                Userod    userPresenter;
                if (isPresenter)
                {
                    userPresenter = listUserods.FirstOrDefault(x => x.UserNum == treatPlanCur.UserNumPresenter);
                }
                else                   //radioEntryUser
                {
                    userPresenter = listUserods.FirstOrDefault(x => x.UserNum == treatPlanCur.SecUserNumEntry);
                }
                ProcedureCode procCode = listProcCodes.First(x => x.CodeNum == procCur.CodeNum);
                Appointment   aptCur   = listApts.FirstOrDefault(x => x.AptNum == procCur.AptNum);
                listTreatPlanPresenterEntries.Add(new TreatPlanPresenterEntry()
                {
                    Presenter        = userPresenter == null ? "" : userPresenter.UserName,
                    DatePresented    = treatPlanCur.DateTP,
                    DateCompleted    = procCur.ProcDate,
                    ProcDescript     = procCode.Descript,
                    GrossProd        = grossProd,
                    Adjustments      = adjustments,
                    WriteOffs        = writeOffs,
                    NetProd          = netProd,
                    UserNumPresenter = userPresenter == null?0:userPresenter.UserNum,
                    PresentedClinic  = procCur.ClinicNum,
                    ProcStatus       = procCur.ProcStatus,
                    TreatPlanNum     = treatPlanCur.TreatPlanNum,
                    AptNum           = procCur.AptNum,
                    AptStatus        = aptCur == null?ApptStatus.None:aptCur.AptStatus
                });
            }
            DataTable table = new DataTable();

            table.Columns.Add("Presenter");
            table.Columns.Add("# of Plans");
            table.Columns.Add("# of Procs");
            table.Columns.Add("# of ProcsSched");
            table.Columns.Add("# of ProcsComp");
            if (isGross)
            {
                table.Columns.Add("GrossTPAmt");
                table.Columns.Add("GrossSchedAmt");
                table.Columns.Add("GrossCompAmt");
            }
            else
            {
                table.Columns.Add("NetTpAmt");
                table.Columns.Add("NetSchedAmt");
                table.Columns.Add("NetCompAmt");
            }
            if (!hasAllUsers)
            {
                listTreatPlanPresenterEntries = listTreatPlanPresenterEntries.Where(x => listUserNums.Contains(x.UserNumPresenter)).ToList();
            }
            listTreatPlanPresenterEntries = listTreatPlanPresenterEntries.OrderBy(x => x.Presenter).ToList();
            listTreatPlanPresenterEntries
            .GroupBy(x => x.Presenter).ToList().ForEach(x =>
            {
                DataRow row            = table.NewRow();
                row["Presenter"]       = x.First().Presenter == "" ? "None" : x.First().Presenter;
                row["# of Plans"]      = x.GroupBy(y => y.TreatPlanNum).Count();
                row["# of Procs"]      = x.Count();
                row["# of ProcsSched"] = x.Count(y => y.ProcStatus == ProcStat.TP && y.AptNum != 0 && y.AptStatus == ApptStatus.Scheduled);
                row["# of ProcsComp"]  = x.Count(y => y.ProcStatus == ProcStat.C);
                if (isGross)
                {
                    row["GrossTpAmt"]    = x.Sum(y => y.GrossProd);
                    row["GrossSchedAmt"] = x.Where(y => y.ProcStatus == ProcStat.TP && y.AptNum != 0 && y.AptStatus == ApptStatus.Scheduled).Sum(y => y.GrossProd);
                    row["GrossCompAmt"]  = x.Where(y => y.ProcStatus == ProcStat.C).Sum(y => y.GrossProd);
                }
                else
                {
                    row["NetTpAmt"]    = x.Sum(y => y.NetProd);
                    row["NetSchedAmt"] = x.Where(y => y.ProcStatus == ProcStat.TP && y.AptNum != 0 && y.AptStatus == ApptStatus.Scheduled).Sum(y => y.NetProd);
                    row["NetCompAmt"]  = x.Where(y => y.ProcStatus == ProcStat.C).Sum(y => y.NetProd);
                }
                table.Rows.Add(row);
            });

            //DataTable table=ReportsComplex.RunFuncOnReportServer(() => ReportsComplex.GetTable(query));
            return(table);
        }