Ejemplo n.º 1
0
        ///<summary>Gets a good chunk of the data used in the TP Module.</summary>
        public static TPModuleData GetModuleData(long patNum, bool doMakeSecLog)
        {
            if (RemotingClient.RemotingRole == RemotingRole.ClientWeb)           //Remoting role check here to reduce round-trips to the server.
            {
                return(Meth.GetObject <TPModuleData>(MethodBase.GetCurrentMethod(), patNum, doMakeSecLog));
            }
            TPModuleData tpData = new TPModuleData();

            tpData.Fam         = Patients.GetFamily(patNum);
            tpData.Pat         = tpData.Fam.GetPatient(patNum);
            tpData.PatPlanList = PatPlans.Refresh(patNum);
            if (!PatPlans.IsPatPlanListValid(tpData.PatPlanList))
            {
                //PatPlans had invalid references and need to be refreshed.
                tpData.PatPlanList = PatPlans.Refresh(patNum);
            }
            tpData.SubList     = InsSubs.RefreshForFam(tpData.Fam);
            tpData.InsPlanList = InsPlans.RefreshForSubList(tpData.SubList);
            tpData.BenefitList = Benefits.Refresh(tpData.PatPlanList, tpData.SubList);
            tpData.ClaimList   = Claims.Refresh(tpData.Pat.PatNum);
            tpData.HistList    = ClaimProcs.GetHistList(tpData.Pat.PatNum, tpData.BenefitList, tpData.PatPlanList, tpData.InsPlanList, DateTime.Today,
                                                        tpData.SubList);
            tpData.ListSubstLinks = SubstitutionLinks.GetAllForPlans(tpData.InsPlanList);
            TreatPlanType tpTypeCur = (tpData.Pat.DiscountPlanNum == 0?TreatPlanType.Insurance:TreatPlanType.Discount);

            TreatPlans.AuditPlans(patNum, tpTypeCur);
            tpData.ListProcedures = Procedures.Refresh(patNum);
            tpData.ListTreatPlans = TreatPlans.GetAllForPat(patNum);
            tpData.ArrProcTPs     = ProcTPs.Refresh(patNum);
            if (doMakeSecLog)
            {
                SecurityLogs.MakeLogEntry(Permissions.TPModule, patNum, "");
            }
            return(tpData);
        }
Ejemplo n.º 2
0
        ///<summary>Called after setting the status to treatPlanCur to Active.
        ///Updates the status of any other plan with Active status to Inactive.
        ///If the original heading of the other plan is "Active Treatment Plan" it will be updated to "Inactive Treatment Plan".</summary>
        public static void SetOtherActiveTPsToInactive(TreatPlan treatPlanCur)
        {
            if (RemotingClient.RemotingRole == RemotingRole.ClientWeb)
            {
                Meth.GetVoid(MethodBase.GetCurrentMethod(), treatPlanCur);
                return;
            }
            string command = "SELECT * FROM treatplan "
                             + "WHERE PatNum=" + POut.Long(treatPlanCur.PatNum) + " "
                             + "AND TPStatus=" + POut.Int((int)TreatPlanStatus.Active) + " "
                             + "AND TreatPlanNum!=" + POut.Long(treatPlanCur.TreatPlanNum);
            //Make Active TP's inactive. Rename if TP's still have default name.
            List <TreatPlan> listActivePlans = Crud.TreatPlanCrud.SelectMany(command);

            foreach (TreatPlan tp in listActivePlans)             //should only ever be one, but just in case there are multiple this will rectify the problem.
            {
                if (tp.Heading == Lans.g("TreatPlans", "Active Treatment Plan"))
                {
                    tp.Heading = Lans.g("TreatPlans", "Inactive Treatment Plan");
                }
                tp.TPStatus = TreatPlanStatus.Inactive;
                TreatPlans.Update(tp);
            }
            //Heading is changed from within the form, if they have changed it back to Inactive Treatment Plan it was deliberate.
            //if(treatPlanCur.Heading==Lans.g("TreatPlans","Inactive Treatment Plan")) {
            //	treatPlanCur.Heading=Lans.g("TreatPlans","Active Treatment Plan");
            //}
            //Not necessary, treatPlanCur should be set to Active prior to calling this function.
            //treatPlanCur.TPStatus=TreatPlanStatus.Active;
            //TreatPlans.Update(treatPlanCur);
        }
Ejemplo n.º 3
0
        ///<summary>Gets most of the data necessary to fill the static text fields.</summary>
        public static StaticTextData GetStaticTextData(Patient pat, Family fam, List <long> listProcCodeNums)
        {
            if (RemotingClient.RemotingRole == RemotingRole.ClientWeb)
            {
                return(Meth.GetObject <StaticTextData>(MethodBase.GetCurrentMethod(), pat, fam, listProcCodeNums));
            }
            StaticTextData data = new StaticTextData();

            data.PatNote               = PatientNotes.Refresh(pat.PatNum, pat.Guarantor);
            data.ListRefAttaches       = RefAttaches.Refresh(pat.PatNum);
            data.ListSubs              = InsSubs.RefreshForFam(fam);
            data.ListPlans             = InsPlans.RefreshForSubList(data.ListSubs);
            data.ListPatPlans          = PatPlans.Refresh(pat.PatNum);
            data.ListBenefits          = Benefits.Refresh(data.ListPatPlans, data.ListSubs);
            data.HistList              = ClaimProcs.GetHistList(pat.PatNum, data.ListBenefits, data.ListPatPlans, data.ListPlans, DateTime.Today, data.ListSubs);
            data.ListTreatPlans        = TreatPlans.Refresh(pat.PatNum);
            data.ListRecallsForFam     = Recalls.GetList(fam.ListPats.Select(x => x.PatNum).ToList());
            data.ListAppts             = Appointments.GetListForPat(pat.PatNum);
            data.ListFutureApptsForFam = Appointments.GetFutureSchedApts(fam.ListPats.Select(x => x.PatNum).ToList());
            data.ListDiseases          = Diseases.Refresh(pat.PatNum, true);
            data.ListAllergies         = Allergies.GetAll(pat.PatNum, false);
            data.ListMedicationPats    = MedicationPats.Refresh(pat.PatNum, false);
            data.ListFamPopups         = Popups.GetForFamily(pat);
            data.ListProceduresSome    = Procedures.RefreshForProcCodeNums(pat.PatNum, listProcCodeNums);
            return(data);
        }
Ejemplo n.º 4
0
        ///<summary></summary>
        public static List <TreatPlanAttach> GetAllForPatNum(long patNum)
        {
            if (RemotingClient.RemotingRole == RemotingRole.ClientWeb)
            {
                return(Meth.GetObject <List <TreatPlanAttach> >(MethodBase.GetCurrentMethod(), patNum));
            }
            List <TreatPlan> listTreatPlans = TreatPlans.GetAllForPat(patNum);

            if (listTreatPlans.Count == 0)
            {
                return(new List <TreatPlanAttach>());
            }
            return(GetAllForTPs(listTreatPlans.Select(x => x.TreatPlanNum).Distinct().ToList()));
        }
Ejemplo n.º 5
0
        ///<summmary>Updates all active and inactive TP's to match the patients current treatment plan type.</summmary>
        public static void UpdateTreatmentPlanType(Patient pat)
        {
            //No need to check RemotingRole; no call to db.
            List <TreatPlan> listTps = TreatPlans.GetAllForPat(pat.PatNum);

            listTps.RemoveAll(x => x.TPStatus == TreatPlanStatus.Saved);                //keep active and inactive tp's, not saved ones.
            TreatPlanType newType = pat.DiscountPlanNum == 0 ? TreatPlanType.Insurance : TreatPlanType.Discount;

            foreach (TreatPlan tp in listTps)
            {
                if (tp.TPType != newType)
                {
                    tp.TPType = newType;
                    TreatPlans.Update(tp);
                }
            }
        }
Ejemplo n.º 6
0
 ///<summary>No need to pass in userNum, it's set before remoting role check and passed to the server if necessary.
 ///<para>This is the automation behind keeping treatplans correct.  Many calls to DB, consider optimizing or calling sparingly.</para>
 ///<para>Ensures patients only have one active treatplan, marks extras inactive and creates an active if necessary.</para>
 ///<para>Attaches procedures to the active plan if the proc status is TP or status is TPi and the procs is attached to a sched/planned appt.</para>
 ///<para>Creates an unassigned treatplan if necessary and attaches any unassigned procedures to it.</para>
 ///<para>Also maintains priorities of treatplanattaches and procedures and updates the procstatus of TP and TPi procs if necessary.</para></summary>
 public static void AuditPlans(long patNum, TreatPlanType tpType, long userNum = 0)
 {
     if (RemotingClient.RemotingRole != RemotingRole.ServerWeb)
     {
         userNum = Security.CurUser.UserNum;              //must be before normal remoting role check to get user at workstation
     }
     if (RemotingClient.RemotingRole == RemotingRole.ClientWeb)
     {
         Meth.GetVoid(MethodBase.GetCurrentMethod(), patNum, tpType, userNum);
         return;
     }
     #region Pseudo Code
     //Get all treatplans for the patient
     //Find active TP if it already exists
     //If more than one active TP, update all but the first to Inactive
     //Find unassigned TP if it already exists
     //Get all treatplanattaches for the treatplans
     //Get all TP and TPi procs for the patient
     //Get list of procs for the active plan, i.e. TPA exists linking to active plan or ProcStatus is TP or attached to sched/planned appt
     //Get list of inactive procs, i.e. ProcStatus is TPi and AptNum is 0 and PlannedAptNum is 0 and no TPA exists linking it to the active plan
     //Create an active plan if one doesn't exist and there are procs that need to be attached to it
     //Create an unassigned plan if one doesn't exist and there are unassigned TPi procs
     //For each proc that should be attached to the active plan
     //  update status from TPi to TP
     //  if TPA exists linking to active plan, update priority to TPA priority
     //  delete any TPA that links the proc to the unassigned plan
     //  if TPA linking the proc to the active plan does not exist, insert one with TPA priority set to the proc priority
     //For each proc that is not attached to the active plan (ProcStatus is TPi)
     //  set proc priority to 0
     //  if TPA does not exist, insert one linking the proc to the unassigned plan with TPA priority 0
     //  if multiple TPAs exist with one linking the proc to the unassigned plan, delete the TPA linking to the unassigned plan
     //Foreach TPA
     //  if TPA links proc to the unassigned plan and TPA exists linking the proc to any other plan, delete the link to the unassigned plan
     //If an unassigned plan exists and there are no TPAs pointing to it, delete the unassigned plan
     #endregion Pseudo Code
     #region Variables
     List <TreatPlan>       listTreatPlans       = TreatPlans.GetAllForPat(patNum);                                                                                               //All treatplans for the pat. [([Includes Saved Plans]}};
     TreatPlan              activePlan           = listTreatPlans.FirstOrDefault(x => x.TPStatus == TreatPlanStatus.Active);                                                      //can be null
     TreatPlan              unassignedPlan       = listTreatPlans.FirstOrDefault(x => x.TPStatus == TreatPlanStatus.Inactive && x.Heading == Lans.g("TreatPlans", "Unassigned")); //can be null
     List <TreatPlanAttach> listTPAs             = TreatPlanAttaches.GetAllForTPs(listTreatPlans.Select(x => x.TreatPlanNum).ToList());
     List <Procedure>       listProcsTpTpi       = Procedures.GetProcsByStatusForPat(patNum, new[] { ProcStat.TP, ProcStat.TPi });                                                //All TP and TPi procs for the pat.
     List <Procedure>       listProcsForActive   = new List <Procedure>();                                                                                                        //All procs that should be linked to the active plan (can be linked to inactive plans as well)
     List <Procedure>       listProcsForInactive = new List <Procedure>();                                                                                                        //All procs that should not be linked to the active plan (linked to inactive or unnasigned)
     long[] arrayTpaProcNums = listTPAs.Select(x => x.ProcNum).ToArray();                                                                                                         //All procnums from listTPAs, makes it easier to see if a TPA exists for a proc
     #endregion Variables
     #region Fill Proc Lists and Create Active and Unassigned Plans
     foreach (Procedure procCur in listProcsTpTpi)             //puts each procedure in listProcsForActive or listProcsForInactive
     {
         if (procCur.ProcStatus == ProcStat.TP ||              //all TP procs should be linked to active plan
             procCur.AptNum > 0 ||                             //all procs attached to an appt should be linked to active plan
             procCur.PlannedAptNum > 0 ||                      //all procs attached to a planned appt should be linked to active plan
             (activePlan != null &&                            //if active plan exists and proc is linked to it, add to list
              listTPAs.Any(x => x.ProcNum == procCur.ProcNum && x.TreatPlanNum == activePlan.TreatPlanNum)))
         {
             listProcsForActive.Add(procCur);
         }
         else                  //TPi status, AptNum=0, PlannedAptNum=0, and not attached to active plan
         {
             listProcsForInactive.Add(procCur);
         }
     }
     //Create active plan if needed
     if (activePlan == null && listProcsForActive.Count > 0)
     {
         activePlan = new TreatPlan()
         {
             Heading  = Lans.g("TreatPlans", "Active Treatment Plan"),
             Note     = PrefC.GetString(PrefName.TreatmentPlanNote),
             TPStatus = TreatPlanStatus.Active,
             PatNum   = patNum,
             //UserNumPresenter=userNum,
             SecUserNumEntry = userNum,
             TPType          = tpType
         };
         TreatPlans.Insert(activePlan);
         listTreatPlans.Add(activePlan);
     }
     //Update extra active plans to Inactive status, should only ever be one Active status plan
     //All TP procs are linked to the active plan, so proc statuses won't have to change to TPi for procs attached to an "extra" active plan
     foreach (TreatPlan tp in listTreatPlans.FindAll(x => x.TPStatus == TreatPlanStatus.Active && activePlan != null && x.TreatPlanNum != activePlan.TreatPlanNum))
     {
         tp.TPStatus = TreatPlanStatus.Inactive;
         TreatPlans.Update(tp);
     }
     //Create unassigned plan if needed
     if (unassignedPlan == null && listProcsForInactive.Any(x => !arrayTpaProcNums.Contains(x.ProcNum)))
     {
         unassignedPlan = new TreatPlan()
         {
             Heading  = Lans.g("TreatPlans", "Unassigned"),
             Note     = PrefC.GetString(PrefName.TreatmentPlanNote),
             TPStatus = TreatPlanStatus.Inactive,
             PatNum   = patNum,
             //UserNumPresenter=userNum,
             SecUserNumEntry = userNum,
             TPType          = tpType
         };
         TreatPlans.Insert(unassignedPlan);
         listTreatPlans.Add(unassignedPlan);
     }
     #endregion Fill Proc Lists and Create Active and Unassigned Plans
     #region Procs for Active Plan
     //Update proc status to TP for all procs that should be linked to the active plan.
     //For procs with an existing TPA linking it to the active plan, update proc priority to the TPA priority.
     //Remove any TPAs linking the proc to the unassigned plan.
     //Create TPAs linking the proc to the active plan if needed with TPA priority set to the proc priority.
     foreach (Procedure procActive in listProcsForActive)
     {
         Procedure procOld = procActive.Copy();
         procActive.ProcStatus = ProcStat.TP;
         //checking the array of ProcNums for an existing TPA is fast, so check the list first
         if (arrayTpaProcNums.Contains(procActive.ProcNum))
         {
             if (unassignedPlan != null)                   //remove any TPAs linking the proc to the unassigned plan
             {
                 listTPAs.RemoveAll(x => x.ProcNum == procActive.ProcNum && x.TreatPlanNum == unassignedPlan.TreatPlanNum);
             }
             TreatPlanAttach tpaActivePlan = listTPAs.FirstOrDefault(x => x.ProcNum == procActive.ProcNum && x.TreatPlanNum == activePlan.TreatPlanNum);
             if (tpaActivePlan == null)                   //no TPA linking the proc to the active plan, create one with priority equal to the proc priority
             {
                 listTPAs.Add(new TreatPlanAttach()
                 {
                     ProcNum = procActive.ProcNum, TreatPlanNum = activePlan.TreatPlanNum, Priority = procActive.Priority
                 });
             }
             else                      //TPA linking this proc to the active plan exists, update proc priority to equal TPA priority
             {
                 procActive.Priority = tpaActivePlan.Priority;
             }
         }
         else                  //no TPAs exist for this proc, add one linking the proc to the active plan and set the TPA priority equal to the proc priority
         {
             listTPAs.Add(new TreatPlanAttach()
             {
                 ProcNum = procActive.ProcNum, TreatPlanNum = activePlan.TreatPlanNum, Priority = procActive.Priority
             });
         }
         Procedures.Update(procActive, procOld);
     }
     #endregion Procs for Active Plan
     #region Procs for Inactive and Unassigned Plans
     //Update proc priority to 0 for all inactive procs.
     //If no TPA exists for the proc, create a TPA with priority 0 linking the proc to the unassigned plan.
     foreach (Procedure procInactive in listProcsForInactive)
     {
         Procedure procOld = procInactive.Copy();
         procInactive.Priority = 0;
         Procedures.Update(procInactive, procOld);
         if (unassignedPlan != null && !arrayTpaProcNums.Contains(procInactive.ProcNum))
         {
             //no TPAs for this proc, add a new one to the list linking proc to the unassigned plan
             listTPAs.Add(new TreatPlanAttach {
                 TreatPlanNum = unassignedPlan.TreatPlanNum, ProcNum = procInactive.ProcNum, Priority = 0
             });
         }
     }
     #endregion Procs for Inactive and Unassigned Plans
     #region Sync and Clean-Up TreatPlanAttach List
     //Remove any TPAs if the proc isn't in listProcsTpTpi, status could've changed or possibly proc is for a different pat.
     listTPAs.RemoveAll(x => !listProcsTpTpi.Select(y => y.ProcNum).Contains(x.ProcNum));
     if (unassignedPlan != null)           //if an unassigned plan exists
     //Remove any TPAs from the list that link a proc to the unassigned plan if there is a TPA that links the proc to any other plan
     {
         listTPAs.RemoveAll(x => x.TreatPlanNum == unassignedPlan.TreatPlanNum &&
                            listTPAs.Any(y => y.ProcNum == x.ProcNum && y.TreatPlanNum != unassignedPlan.TreatPlanNum));
     }
     listTreatPlans.ForEach(x => TreatPlanAttaches.Sync(listTPAs.FindAll(y => y.TreatPlanNum == x.TreatPlanNum), x.TreatPlanNum));
     if (unassignedPlan != null)                                                       //Must happen after Sync. Delete the unassigned plan if it exists and there are no TPAs pointing to it.
     {
         listTPAs = TreatPlanAttaches.GetAllForTreatPlan(unassignedPlan.TreatPlanNum); //from DB.
         if (listTPAs.Count == 0)                                                      //nothing attached to unassigned anymore
         {
             Crud.TreatPlanCrud.Delete(unassignedPlan.TreatPlanNum);
         }
     }
     #endregion Sync and Clean-Up TreatPlanAttach List
 }
Ejemplo n.º 7
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);
        }
Ejemplo n.º 9
0
        ///<summary>Runs the required queries to populate the necessary StaticTextData fields corresponding to staticTextDependencies.</summary>
        private void LoadData(StaticTextFieldDependency staticTextDependencies, Patient pat, Family fam, List <long> listProcCodeNums)
        {
            bool isMiddleTier = (RemotingClient.RemotingRole == RemotingRole.ServerWeb);

            System.Diagnostics.Stopwatch timer = null;
            if (ODBuild.IsDebug())
            {
                timer = new System.Diagnostics.Stopwatch();
                timer.Start();
            }
            if (staticTextDependencies.HasFlag(StaticTextFieldDependency.Pat))
            {
                //patient should already be loaded.
            }
            if (fam == null && staticTextDependencies.HasFlag(StaticTextFieldDependency.Fam))
            {
                fam = Patients.GetFamily(pat.PatNum);
            }
            if (PatNote == null)
            {
                if (staticTextDependencies.HasFlag(StaticTextFieldDependency.PatNote))
                {
                    PatNote = PatientNotes.Refresh(pat.PatNum, pat.Guarantor);
                }
                else
                {
                    PatNote = new PatientNote();
                }
            }
            bool IsQueryNeeded <T>(ref List <T> list, StaticTextFieldDependency dependency)
            {
                if (list == null || (isMiddleTier && list.Count == 0))             //Middle Tier deserializes null lists to empty lists.
                {
                    if (staticTextDependencies.HasFlag(dependency))
                    {
                        return(true);
                    }
                    else
                    {
                        list = new List <T>();
                    }
                }
                return(false);
            }

            if (IsQueryNeeded(ref ListRefAttaches, StaticTextFieldDependency.ListRefAttaches))
            {
                ListRefAttaches = RefAttaches.Refresh(pat.PatNum);
            }
            if (IsQueryNeeded(ref ListInsSubs, StaticTextFieldDependency.ListInsSubs))
            {
                ListInsSubs = InsSubs.RefreshForFam(fam);
            }
            if (IsQueryNeeded(ref ListInsPlans, StaticTextFieldDependency.ListInsPlans))
            {
                ListInsPlans = InsPlans.RefreshForSubList(ListInsSubs);
            }
            if (IsQueryNeeded(ref ListPatPlans, StaticTextFieldDependency.ListPatPlans))
            {
                ListPatPlans = PatPlans.Refresh(pat.PatNum);
            }
            if (IsQueryNeeded(ref ListBenefits, StaticTextFieldDependency.ListBenefits))
            {
                ListBenefits = Benefits.Refresh(ListPatPlans, ListInsSubs);
            }
            if (IsQueryNeeded(ref HistList, StaticTextFieldDependency.HistList))
            {
                HistList = ClaimProcs.GetHistList(pat.PatNum, ListBenefits, ListPatPlans, ListInsPlans, DateTime.Today, ListInsSubs);
            }
            if (IsQueryNeeded(ref ListTreatPlans, StaticTextFieldDependency.ListTreatPlans))
            {
                ListTreatPlans = TreatPlans.Refresh(pat.PatNum);
            }
            if (IsQueryNeeded(ref ListRecallsForFam, StaticTextFieldDependency.ListRecallsForFam))
            {
                ListRecallsForFam = Recalls.GetList(fam.ListPats.Select(x => x.PatNum).ToList());
            }
            if (IsQueryNeeded(ref ListAppts, StaticTextFieldDependency.ListAppts))
            {
                ListAppts = Appointments.GetListForPat(pat.PatNum);
            }
            if (IsQueryNeeded(ref ListFutureApptsForFam, StaticTextFieldDependency.ListFutureApptsForFam))
            {
                ListFutureApptsForFam = Appointments.GetFutureSchedApts(fam.ListPats.Select(x => x.PatNum).ToList());
            }
            if (IsQueryNeeded(ref ListDiseases, StaticTextFieldDependency.ListDiseases))
            {
                ListDiseases = Diseases.Refresh(pat.PatNum, true);
            }
            if (IsQueryNeeded(ref ListAllergies, StaticTextFieldDependency.ListAllergies))
            {
                ListAllergies = Allergies.GetAll(pat.PatNum, false);
            }
            if (IsQueryNeeded(ref ListMedicationPats, StaticTextFieldDependency.ListMedicationPats))
            {
                ListMedicationPats = MedicationPats.Refresh(pat.PatNum, false);
            }
            if (IsQueryNeeded(ref ListFamPopups, StaticTextFieldDependency.ListFamPopups))
            {
                ListFamPopups = Popups.GetForFamily(pat);
            }
            if (IsQueryNeeded(ref ListProceduresSome, StaticTextFieldDependency.ListProceduresSome))
            {
                ListProceduresSome = Procedures.RefreshForProcCodeNums(pat.PatNum, listProcCodeNums);
            }
            if (IsQueryNeeded(ref ListProceduresPat, StaticTextFieldDependency.ListProceduresPat))
            {
                ListProceduresPat = Procedures.Refresh(pat.PatNum);
            }
            if (IsQueryNeeded(ref ListPlannedAppts, StaticTextFieldDependency.ListPlannedAppts))
            {
                ListPlannedAppts = new List <PlannedAppt>();
                PlannedAppt plannedAppt = PlannedAppts.GetOneOrderedByItemOrder(pat.PatNum);
                if (plannedAppt != null)
                {
                    ListPlannedAppts.Add(plannedAppt);
                }
            }
            if (ODBuild.IsDebug())
            {
                timer.Stop();
                Console.WriteLine("Static text field query time (ms): " + timer.ElapsedMilliseconds);
            }
        }