Пример #1
0
        ///<summary>Gets the data necessary to load FormProcEdit.</summary>
        public static LoadData GetLoadData(Procedure proc, Patient pat, Family fam)
        {
            if (RemotingClient.RemotingRole == RemotingRole.ClientWeb)
            {
                return(Meth.GetObject <LoadData>(MethodBase.GetCurrentMethod(), proc, pat, fam));
            }
            LoadData data = new LoadData();

            data.ListPatPlans = PatPlans.Refresh(pat.PatNum);
            if (!PatPlans.IsPatPlanListValid(data.ListPatPlans))             //PatPlans had invalid references and need to be refreshed.
            {
                data.ListPatPlans = PatPlans.Refresh(pat.PatNum);
            }
            data.ListInsSubs           = InsSubs.RefreshForFam(fam);
            data.ListInsPlans          = InsPlans.RefreshForSubList(data.ListInsSubs);
            data.ListClaims            = Claims.Refresh(pat.PatNum);
            data.ListClaimProcsForProc = ClaimProcs.RefreshForProc(proc.ProcNum);
            data.ListBenefits          = Benefits.Refresh(data.ListPatPlans, data.ListInsSubs);
            data.ListRefAttaches       = RefAttaches.RefreshFiltered(proc.PatNum, false, proc.ProcNum);
            data.ArrPaySplits          = PaySplits.Refresh(proc.PatNum);
            List <long> listPayNums = data.ArrPaySplits.Where(x => x.ProcNum == proc.ProcNum).Select(x => x.PayNum).ToList();

            data.ListPaymentsForProc = Payments.GetPayments(listPayNums);
            data.ArrAdjustments      = Adjustments.Refresh(proc.PatNum);
            data.OrthoProcedureLink  = OrthoProcLinks.GetByProcNum(proc.ProcNum);
            return(data);
        }
Пример #2
0
        ///<summary>Users using the OpenDentalService to create claim snapshots only get primary claim snap shots created.</summary>
        private static void CreateClaimSnapShotService()
        {
            //No need to check RemotingRole; no call to db.
            List <Procedure> listCompletedProcs = Procedures.GetCompletedByDateCompleteForDateRange(DateTime.Today, DateTime.Today);
            List <ClaimProc> listClaimProcs     = ClaimProcs.GetForProcsWithOrdinal(listCompletedProcs.Select(x => x.ProcNum).ToList(), 1).Where(x => !x.Status.In(ClaimProcStatus.Preauth, ClaimProcStatus.Adjustment)).ToList();
            List <PatPlan>   listPatPlans       = PatPlans.GetListByInsSubNums(listClaimProcs.Select(x => x.InsSubNum).ToList());

            listClaimProcs = listClaimProcs
                             .OrderByDescending(x => x.ClaimNum)    //order by claim num
                             .ThenByDescending(x => x.SecDateEntry) //then by creation date
                                                                    //group by procnum and ordinal
                             .GroupBy(x => new { ProcNum = x.ProcNum, Ordinal = PatPlans.GetOrdinal(x.InsSubNum, listPatPlans.Where(y => y.PatNum == x.PatNum).ToList()) })
                             .Select(x => x.First())                //get the first for each group
                             .ToList();
            //Loop through all the claimprocs and create a claimsnapshot entry for each.
            for (int i = 0; i < listClaimProcs.Count; i++)
            {
                ClaimProc cpCur = listClaimProcs[i];
                if (cpCur.Status == ClaimProcStatus.CapClaim ||
                    cpCur.Status == ClaimProcStatus.CapComplete ||
                    cpCur.Status == ClaimProcStatus.CapEstimate ||
                    cpCur.Status == ClaimProcStatus.Preauth ||
                    cpCur.Status == ClaimProcStatus.Supplemental ||
                    cpCur.Status == ClaimProcStatus.InsHist)
                {
                    continue;
                }
                //get the procfee
                double    procFee = 0;
                Procedure procCur = listCompletedProcs.Find(x => x.ProcNum == cpCur.ProcNum);
                if (procCur != null)
                {
                    procFee = procCur.ProcFee;
                }
                //get the writeoff
                double writeoffAmt = cpCur.WriteOff;
                //For the Service, only use the WriteOff amount on the claimproc if the claimproc is associated to a claim,
                //as this means that value has been set.
                if (cpCur.Status != ClaimProcStatus.NotReceived && cpCur.Status != ClaimProcStatus.Received)
                {
                    if (cpCur.WriteOffEstOverride != -1)
                    {
                        writeoffAmt = cpCur.WriteOffEstOverride;
                    }
                    else
                    {
                        writeoffAmt = cpCur.WriteOffEst;
                    }
                }
                //create the snapshot
                ClaimSnapshot snapshot = new ClaimSnapshot();
                snapshot.ProcNum         = cpCur.ProcNum;
                snapshot.Writeoff        = writeoffAmt;
                snapshot.InsPayEst       = cpCur.InsEstTotal;
                snapshot.Fee             = procFee;
                snapshot.ClaimProcNum    = cpCur.ClaimProcNum;
                snapshot.SnapshotTrigger = ClaimSnapshotTrigger.Service;
                ClaimSnapshots.Insert(snapshot);
            }
        }
Пример #3
0
 ///<summary>Returns the data needed for ProcFeeHelper. Does not get ListFees.</summary>
 public static ProcFeeHelper GetData(long patNum, ProcFeeHelper procFeeHelper)
 {
     if (RemotingClient.RemotingRole == RemotingRole.ClientWeb)
     {
         //Not passing procFeeHelper because the null lists will get turned into empty lists which messes things up.
         return(Meth.GetObject <ProcFeeHelper>(MethodBase.GetCurrentMethod(), patNum, null));
     }
     procFeeHelper              = procFeeHelper ?? new ProcFeeHelper(patNum);
     procFeeHelper.Pat          = procFeeHelper.Pat ?? Patients.GetPat(patNum);
     procFeeHelper.ListPatPlans = procFeeHelper.ListPatPlans ?? PatPlans.GetPatPlansForPat(patNum);
     procFeeHelper.ListInsSubs  = procFeeHelper.ListInsSubs ?? InsSubs.GetMany(procFeeHelper.ListPatPlans.Select(x => x.InsSubNum).ToList());
     procFeeHelper.ListInsPlans = procFeeHelper.ListInsPlans ?? InsPlans.GetPlans(procFeeHelper.ListInsSubs.Select(x => x.PlanNum).ToList());
     if (procFeeHelper.ListPatPlans.Count > 0)
     {
         PatPlan priPatPlan = procFeeHelper.ListPatPlans[0];
         InsSub  priInsSub  = InsSubs.GetSub(priPatPlan.InsSubNum, procFeeHelper.ListInsSubs);
         InsPlan priInsPlan = InsPlans.GetPlan(priInsSub.PlanNum, procFeeHelper.ListInsPlans);
         procFeeHelper.ListBenefitsPrimary = procFeeHelper.ListBenefitsPrimary ?? Benefits.RefreshForPlan(priInsPlan.PlanNum, priPatPlan.PatPlanNum);
     }
     else
     {
         procFeeHelper.ListBenefitsPrimary = new List <Benefit>();
     }
     return(procFeeHelper);
 }
Пример #4
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);
        }
Пример #5
0
        ///<summary>Throws exception if dependencies.  Doesn't delete anything else.</summary>
        public static void Delete(long insSubNum)
        {
            if (RemotingClient.RemotingRole == RemotingRole.ClientWeb)
            {
                Meth.GetVoid(MethodBase.GetCurrentMethod(), insSubNum);
                return;
            }
            try {
                ValidateNoKeys(insSubNum, true);
            }
            catch (ApplicationException ex) {
                throw new ApplicationException(Lans.g("FormInsPlan", "Not allowed to delete: ") + ex.Message);
            }
            string    command;
            DataTable table;

            //Remove from the patplan table just in case it is still there.
            command = "SELECT PatPlanNum FROM patplan WHERE InsSubNum = " + POut.Long(insSubNum);
            table   = Db.GetTable(command);
            for (int i = 0; i < table.Rows.Count; i++)
            {
                //benefits with this PatPlanNum are also deleted here
                PatPlans.Delete(PIn.Long(table.Rows[i]["PatPlanNum"].ToString()));
            }
            command = "DELETE FROM claimproc WHERE InsSubNum = " + POut.Long(insSubNum);
            Db.NonQ(command);
            Crud.InsSubCrud.Delete(insSubNum);
        }
Пример #6
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);
        }
Пример #7
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());
            if (!PrefC.GetBool(PrefName.EasyHideDentalSchools))
            {
                data.ListStudents = ReqStudents.GetForAppt(AptCur.AptNum);
            }
            return(data);
        }
Пример #8
0
        ///<summary>Gets the fee schedule from the primary MEDICAL insurance plan,
        ///the first insurance plan, the patient, or the provider in that order.</summary>
        public static long GetMedFeeSched(Patient pat, List <InsPlan> planList, List <PatPlan> patPlans, List <InsSub> subList, long procProvNum)
        {
            //No need to check RemotingRole; no call to db.
            long retVal = 0;

            if (PatPlans.GetInsSubNum(patPlans, 1) != 0)
            {
                //Pick the medinsplan with the ordinal closest to zero
                int    planOrdinal = 10;            //This is a hack, but I doubt anyone would have more than 10 plans
                bool   hasMedIns   = false;         //Keep track of whether we found a medical insurance plan, if not use dental insurance fee schedule.
                InsSub subCur;
                foreach (PatPlan patplan in patPlans)
                {
                    subCur = InsSubs.GetSub(patplan.InsSubNum, subList);
                    if (patplan.Ordinal < planOrdinal && InsPlans.GetPlan(subCur.PlanNum, planList).IsMedical)
                    {
                        planOrdinal = patplan.Ordinal;
                        hasMedIns   = true;
                    }
                }
                if (!hasMedIns)                                                         //If this patient doesn't have medical insurance (under ordinal 10)
                {
                    return(GetFeeSched(pat, planList, patPlans, subList, procProvNum)); //Use dental insurance fee schedule
                }
                subCur = InsSubs.GetSub(PatPlans.GetInsSubNum(patPlans, planOrdinal), subList);
                InsPlan PlanCur = InsPlans.GetPlan(subCur.PlanNum, planList);
                if (PlanCur == null)
                {
                    retVal = 0;
                }
                else
                {
                    retVal = PlanCur.FeeSched;
                }
            }
            if (retVal == 0)
            {
                if (pat.FeeSched != 0)
                {
                    retVal = pat.FeeSched;
                }
                else
                {
                    if (pat.PriProv == 0)
                    {
                        retVal = Providers.GetFirst(true).FeeSched;
                    }
                    else
                    {
                        Provider providerFirst = Providers.GetFirst();                      //Used in order to preserve old behavior...  If this fails, then old code would have failed.
                        Provider provider      = Providers.GetFirstOrDefault(x => x.ProvNum == pat.PriProv) ?? providerFirst;
                        retVal = provider.FeeSched;
                    }
                }
            }
            return(retVal);
        }
Пример #9
0
        ///<summary>Deletes the patplan with the specified patPlanNum.  Rearranges the other patplans for the patient to keep the ordinal sequence contiguous.  Then, recomputes all estimates for this patient because their coverage is now different.  Also sets patient.HasIns to the correct value.</summary>
        public static void Delete(long patPlanNum)
        {
            if (RemotingClient.RemotingRole == RemotingRole.ClientWeb)
            {
                Meth.GetVoid(MethodBase.GetCurrentMethod(), patPlanNum);
                return;
            }
            string    command = "SELECT PatNum FROM patplan WHERE PatPlanNum=" + POut.Long(patPlanNum);
            DataTable table   = Db.GetTable(command);

            if (table.Rows.Count == 0)
            {
                return;
            }
            long           patNum      = PIn.Long(table.Rows[0][0].ToString());
            List <PatPlan> patPlans    = PatPlans.Refresh(patNum);
            bool           doDecrement = false;

            for (int i = 0; i < patPlans.Count; i++)
            {
                if (doDecrement)                 //patPlan has already been deleted, so decrement the rest.
                {
                    command = "UPDATE patplan SET Ordinal=" + POut.Long(patPlans[i].Ordinal - 1)
                              + " WHERE PatPlanNum=" + POut.Long(patPlans[i].PatPlanNum);
                    Db.NonQ(command);
                    continue;
                }
                if (patPlans[i].PatPlanNum == patPlanNum)
                {
                    RemoveAssignedUser(patPlans[i]);
                    command = "DELETE FROM patplan WHERE PatPlanNum=" + POut.Long(patPlanNum);
                    Db.NonQ(command);
                    command = "DELETE FROM benefit WHERE PatPlanNum=" + POut.Long(patPlanNum);
                    Db.NonQ(command);
                    doDecrement = true;
                    InsVerifies.DeleteByFKey(patPlanNum, VerifyTypes.PatientEnrollment);
                }
            }
            Family           fam                = Patients.GetFamily(patNum);
            Patient          pat                = fam.GetPatient(patNum);
            List <ClaimProc> claimProcs         = ClaimProcs.Refresh(patNum);
            List <ClaimProc> listClaimProcsEsts = claimProcs.Where(x => x.Status.In(ClaimProcStatus.Estimate, ClaimProcStatus.CapEstimate)).ToList();
            List <Procedure> procs              = Procedures.Refresh(patNum);

            patPlans = PatPlans.Refresh(patNum);
            List <InsSub>  subList  = InsSubs.RefreshForFam(fam);
            List <InsPlan> planList = InsPlans.RefreshForSubList(subList);
            List <Benefit> benList  = Benefits.Refresh(patPlans, subList);

            Procedures.ComputeEstimatesForAll(patNum, listClaimProcsEsts, procs, planList, patPlans, benList, pat.Age, subList, claimProcs);
            Patients.SetHasIns(patNum);
//Cameron_ Possibly create outbound ADT message to update insurance info
        }
Пример #10
0
        ///<summary>Do not call this until after determining if the repeate charge might generate a claim.  This function checks current insurance and
        ///may not add claims if no insurance is found.</summary>
        private static List <Claim> AddClaimsHelper(RepeatCharge repeateCharge, Procedure proc)
        {
            //No remoting role check; no call to db
            List <PatPlan> patPlanList = PatPlans.Refresh(repeateCharge.PatNum);
            List <InsSub>  subList     = InsSubs.RefreshForFam(Patients.GetFamily(repeateCharge.PatNum));
            List <InsPlan> insPlanList = InsPlans.RefreshForSubList(subList);
            List <Benefit> benefitList = Benefits.Refresh(patPlanList, subList);
            List <Claim>   retVal      = new List <Claim>();
            Claim          claimCur;

            if (patPlanList.Count == 0)           //no current insurance, do not create a claim
            {
                return(retVal);
            }
            //create the claimprocs
            Procedures.ComputeEstimates(proc, proc.PatNum, new List <ClaimProc>(), true, insPlanList, patPlanList, benefitList,
                                        Patients.GetPat(proc.PatNum).Age, subList);
            //get claimprocs for this proc, may be more than one
            List <ClaimProc> claimProcList = ClaimProcs.GetForProc(ClaimProcs.Refresh(proc.PatNum), proc.ProcNum);
            string           claimType     = "P";

            if (patPlanList.Count == 1 && PatPlans.GetOrdinal(PriSecMed.Medical, patPlanList, insPlanList, subList) > 0)      //if there's exactly one medical plan
            {
                claimType = "Med";
            }
            claimCur      = Claims.CreateClaimForRepeatCharge(claimType, patPlanList, insPlanList, claimProcList, proc, subList);
            claimProcList = ClaimProcs.Refresh(proc.PatNum);
            if (claimCur.ClaimNum == 0)
            {
                return(retVal);
            }
            retVal.Add(claimCur);
            Claims.CalculateAndUpdate(new List <Procedure> {
                proc
            }, insPlanList, claimCur, patPlanList, benefitList, Patients.GetPat(proc.PatNum).Age, subList);
            if (PatPlans.GetOrdinal(PriSecMed.Secondary, patPlanList, insPlanList, subList) > 0 &&    //if there exists a secondary plan
                !CultureInfo.CurrentCulture.Name.EndsWith("CA"))                     //and not canada (don't create secondary claim for canada)
            {
                claimCur = Claims.CreateClaimForRepeatCharge("S", patPlanList, insPlanList, claimProcList, proc, subList);
                if (claimCur.ClaimNum == 0)
                {
                    return(retVal);
                }
                retVal.Add(claimCur);
                ClaimProcs.Refresh(proc.PatNum);
                claimCur.ClaimStatus = "H";
                Claims.CalculateAndUpdate(new List <Procedure> {
                    proc
                }, insPlanList, claimCur, patPlanList, benefitList, Patients.GetPat(proc.PatNum).Age, subList);
            }
            return(retVal);
        }
Пример #11
0
        ///<summary>Gets the fee schedule from the primary MEDICAL insurance plan, the patient, or the provider in that order.</summary>
        public static long GetMedFeeSched(Patient pat, List <InsPlan> planList, List <PatPlan> patPlans, List <InsSub> subList)
        {
            //No need to check RemotingRole; no call to db. ??
            long retVal = 0;

            if (PatPlans.GetInsSubNum(patPlans, 1) != 0)
            {
                //Pick the medinsplan with the ordinal closest to zero
                int    planOrdinal = 10;            //This is a hack, but I doubt anyone would have more than 10 plans
                InsSub subCur;
                foreach (PatPlan patplan in patPlans)
                {
                    subCur = InsSubs.GetSub(patplan.InsSubNum, subList);
                    if (patplan.Ordinal < planOrdinal && InsPlans.GetPlan(subCur.PlanNum, planList).IsMedical)
                    {
                        planOrdinal = patplan.Ordinal;
                    }
                }
                subCur = InsSubs.GetSub(PatPlans.GetInsSubNum(patPlans, planOrdinal), subList);
                InsPlan PlanCur = InsPlans.GetPlan(subCur.PlanNum, planList);
                if (PlanCur == null)
                {
                    retVal = 0;
                }
                else
                {
                    retVal = PlanCur.FeeSched;
                }
            }
            if (retVal == 0)
            {
                if (pat.FeeSched != 0)
                {
                    retVal = pat.FeeSched;
                }
                else
                {
                    if (pat.PriProv == 0)
                    {
                        retVal = ProviderC.ListShort[0].FeeSched;
                    }
                    else
                    {
                        //MessageBox.Show(Providers.GetIndex(Patients.Cur.PriProv).ToString());
                        retVal = ProviderC.ListLong[Providers.GetIndexLong(pat.PriProv)].FeeSched;
                    }
                }
            }
            return(retVal);
        }
Пример #12
0
        ///<summary>Deletes the patplan with the specified patPlanNum.  Rearranges the other patplans for the patient to keep the ordinal sequence contiguous.  Then, recomputes all estimates for this patient because their coverage is now different.  Also sets patient.HasIns to the correct value.</summary>
        public static void Delete(long patPlanNum)
        {
            if (RemotingClient.RemotingRole == RemotingRole.ClientWeb)
            {
                Meth.GetVoid(MethodBase.GetCurrentMethod(), patPlanNum);
                return;
            }
            string    command = "SELECT PatNum FROM patplan WHERE PatPlanNum=" + POut.Long(patPlanNum);
            DataTable table   = Db.GetTable(command);

            if (table.Rows.Count == 0)
            {
                return;
            }
            long           patNum      = PIn.Long(table.Rows[0][0].ToString());
            List <PatPlan> patPlans    = PatPlans.Refresh(patNum);
            bool           doDecrement = false;

            for (int i = 0; i < patPlans.Count; i++)
            {
                if (doDecrement)                 //patPlan has already been deleted, so decrement the rest.
                {
                    command = "UPDATE patplan SET Ordinal=" + POut.Long(patPlans[i].Ordinal - 1)
                              + " WHERE PatPlanNum=" + POut.Long(patPlans[i].PatPlanNum);
                    Db.NonQ(command);
                    continue;
                }
                if (patPlans[i].PatPlanNum == patPlanNum)
                {
                    command = "DELETE FROM patplan WHERE PatPlanNum=" + POut.Long(patPlanNum);
                    Db.NonQ(command);
                    command = "DELETE FROM benefit WHERE PatPlanNum=" + POut.Long(patPlanNum);
                    Db.NonQ(command);
                    doDecrement = true;
                }
            }
            Family           fam        = Patients.GetFamily(patNum);
            Patient          pat        = fam.GetPatient(patNum);
            List <ClaimProc> claimProcs = ClaimProcs.Refresh(patNum);
            List <Procedure> procs      = Procedures.Refresh(patNum);

            patPlans = PatPlans.Refresh(patNum);
            List <InsSub>  subList  = InsSubs.RefreshForFam(fam);
            List <InsPlan> planList = InsPlans.RefreshForSubList(subList);
            List <Benefit> benList  = Benefits.Refresh(patPlans, subList);

            Procedures.ComputeEstimatesForAll(patNum, claimProcs, procs, planList, patPlans, benList, pat.Age, subList);
            Patients.SetHasIns(patNum);
        }
Пример #13
0
        ///<summary>Deletes the patplan with the specified patPlanNum.  Rearranges the other patplans for the patient to keep the ordinal sequence contiguous.  Then, recomputes all estimates for this patient because their coverage is now different.  Also sets patient.HasIns to the correct value.</summary>
        public static void Delete(long patPlanNum)
        {
            if (RemotingClient.RemotingRole == RemotingRole.ClientWeb)
            {
                Meth.GetVoid(MethodBase.GetCurrentMethod(), patPlanNum);
                return;
            }
            string    command = "SELECT PatNum FROM patplan WHERE PatPlanNum=" + POut.Long(patPlanNum);
            DataTable table   = Db.GetTable(command);

            if (table.Rows.Count == 0)
            {
                return;
            }
            long           patNum      = PIn.Long(table.Rows[0][0].ToString());
            List <PatPlan> patPlans    = PatPlans.Refresh(patNum);
            bool           doDecrement = false;

            for (int i = 0; i < patPlans.Count; i++)
            {
                if (doDecrement)                 //patPlan has already been deleted, so decrement the rest.
                {
                    command = "UPDATE patplan SET Ordinal=" + POut.Long(patPlans[i].Ordinal - 1)
                              + " WHERE PatPlanNum=" + POut.Long(patPlans[i].PatPlanNum);
                    Db.NonQ(command);
                    continue;
                }
                if (patPlans[i].PatPlanNum == patPlanNum)
                {
                    RemoveAssignedUser(patPlans[i]);
                    command = "DELETE FROM patplan WHERE PatPlanNum=" + POut.Long(patPlanNum);
                    Db.NonQ(command);
                    command = "DELETE FROM benefit WHERE PatPlanNum=" + POut.Long(patPlanNum);
                    Db.NonQ(command);
                    doDecrement = true;
                    InsVerifies.DeleteByFKey(patPlanNum, VerifyTypes.PatientEnrollment);
                }
            }
            InsPlans.ComputeEstimatesForPatNums(new List <long> {
                patNum
            });
//Cameron_ Possibly create outbound ADT message to update insurance info
        }
Пример #14
0
        public static LoadData GetLoadData(Patient pat, Family fam, Claim claim)
        {
            if (RemotingClient.RemotingRole == RemotingRole.ClientWeb)
            {
                return(Meth.GetObject <LoadData>(MethodBase.GetCurrentMethod(), pat, fam, claim));
            }
            LoadData data = new LoadData();

            data.ListPatPlans            = PatPlans.Refresh(pat.PatNum);
            data.ListInsSubs             = InsSubs.RefreshForFam(fam);
            data.ListInsPlans            = InsPlans.RefreshForSubList(data.ListInsSubs);
            data.ListClaimProcs          = ClaimProcs.Refresh(pat.PatNum);
            data.ListProcs               = Procedures.Refresh(pat.PatNum);
            data.ListClaimValCodes       = ClaimValCodeLogs.GetForClaim(claim.ClaimNum);
            data.ClaimCondCodeLogCur     = ClaimCondCodeLogs.GetByClaimNum(claim.ClaimNum);
            data.TablePayments           = ClaimPayments.GetForClaim(claim.ClaimNum);
            data.TablePayments.TableName = "ClaimPayments";
            data.ListToothInitials       = ToothInitials.Refresh(pat.PatNum);
            data.ListCustomStatusEntries = ClaimTrackings.RefreshForClaim(ClaimTrackingType.StatusHistory, claim.ClaimNum);
            return(data);
        }
Пример #15
0
        ///<summary>Gets the fee schedule from the first insplan, the patient, or the provider in that order.  Either returns a fee schedule (fk to definition.DefNum) or 0.</summary>
        public static long GetFeeSched(Patient pat, List <InsPlan> planList, List <PatPlan> patPlans, List <InsSub> subList)
        {
            //No need to check RemotingRole; no call to db.
            //there's not really a good place to put this function, so it's here.
            long retVal = 0;

            if (PatPlans.GetInsSubNum(patPlans, 1) != 0)
            {
                InsSub  SubCur  = InsSubs.GetSub(PatPlans.GetInsSubNum(patPlans, 1), subList);
                InsPlan PlanCur = InsPlans.GetPlan(SubCur.PlanNum, planList);
                if (PlanCur == null)
                {
                    retVal = 0;
                }
                else
                {
                    retVal = PlanCur.FeeSched;
                }
            }
            if (retVal == 0)
            {
                if (pat.FeeSched != 0)
                {
                    retVal = pat.FeeSched;
                }
                else
                {
                    if (pat.PriProv == 0)
                    {
                        retVal = ProviderC.ListShort[0].FeeSched;
                    }
                    else
                    {
                        //MessageBox.Show(Providers.GetIndex(Patients.Cur.PriProv).ToString());
                        retVal = ProviderC.ListLong[Providers.GetIndexLong(pat.PriProv)].FeeSched;
                    }
                }
            }
            return(retVal);
        }
Пример #16
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);
            }
        }
Пример #17
0
        ///<summary>Gets the data necessary to load the Family Module.</summary>
        public static LoadData GetLoadData(long patNum, bool doCreateSecLog)
        {
            if (RemotingClient.RemotingRole == RemotingRole.ClientWeb)
            {
                return(Meth.GetObject <LoadData>(MethodBase.GetCurrentMethod(), patNum, doCreateSecLog));
            }
            LoadData data = new LoadData();

            data.Fam          = Patients.GetFamily(patNum);
            data.Pat          = data.Fam.GetPatient(patNum);
            data.ListPatPlans = PatPlans.Refresh(patNum);
            if (!PatPlans.IsPatPlanListValid(data.ListPatPlans))             //PatPlans had invalid references and need to be refreshed.
            {
                data.ListPatPlans = PatPlans.Refresh(patNum);
            }
            data.PatNote               = PatientNotes.Refresh(patNum, data.Pat.Guarantor);
            data.ListInsSubs           = InsSubs.RefreshForFam(data.Fam);
            data.ListInsPlans          = InsPlans.RefreshForSubList(data.ListInsSubs);
            data.ListBenefits          = Benefits.Refresh(data.ListPatPlans, data.ListInsSubs);
            data.ListRecalls           = Recalls.GetList(data.Fam.ListPats.Select(x => x.PatNum).ToList());
            data.ArrPatFields          = PatFields.Refresh(patNum);
            data.SuperFamilyMembers    = Patients.GetBySuperFamily(data.Pat.SuperFamily);
            data.SuperFamilyGuarantors = Patients.GetSuperFamilyGuarantors(data.Pat.SuperFamily);
            data.DictCloneSpecialities = Patients.GetClonesAndSpecialties(patNum);
            data.PatPict               = Documents.GetPatPictFromDb(patNum);
            data.HasPatPict            = (data.PatPict == null ? YN.No : YN.Yes);
            List <DisplayField> listDisplayFields = DisplayFields.GetForCategory(DisplayFieldCategory.PatientInformation);

            foreach (DisplayField field in listDisplayFields)
            {
                switch (field.InternalName)
                {
                case "Guardians":
                    data.ListGuardians = Guardians.Refresh(patNum);
                    break;

                case "Pat Restrictions":
                    data.ListPatRestricts = PatRestrictions.GetAllForPat(patNum);
                    break;

                case "Payor Types":
                    data.PayorTypeDesc = PayorTypes.GetCurrentDescription(patNum);
                    break;

                case "PatFields":
                    data.ListPatFieldDefLinks = FieldDefLinks.GetForLocation(FieldLocations.Family);
                    break;

                case "References":
                    data.ListCustRefEntries = CustRefEntries.GetEntryListForCustomer(patNum);
                    break;

                case "Referrals":
                    data.ListRefAttaches = RefAttaches.Refresh(patNum);
                    break;

                case "ResponsParty":
                    if (data.Pat.ResponsParty != 0)
                    {
                        data.ResponsibleParty = Patients.GetLim(data.Pat.ResponsParty);
                    }
                    break;
                }
            }
            if (data.Pat.DiscountPlanNum != 0)
            {
                data.DiscountPlan = DiscountPlans.GetPlan(data.Pat.DiscountPlanNum);
            }
            data.ListMergeLinks = PatientLinks.GetLinks(data.Fam.ListPats.Select(x => x.PatNum).ToList(), PatientLinkType.Merge);
            if (doCreateSecLog)
            {
                SecurityLogs.MakeLogEntry(Permissions.FamilyModule, patNum, "");
            }
            return(data);
        }
Пример #18
0
        ///<summary>Updates writeoff estimated for claimprocs for the passed in clinics. Called only in FormFeeSchedTools, located here to allow unit
        ///testing. Requires an ODProgressExtended to display UI updates.  If clinics are enabled and the user is not clinic restricted and chooses to run
        ///for all clinics, set doUpdatePrevClinicPref to true so that the ClinicNums will be stored in the preference table as they are finished to allow
        ///for pausing/resuming the process.</summary>
        public static long GlobalUpdateWriteoffs(List <long> listWriteoffClinicNums, ODProgressExtended progress, bool doUpdatePrevClinicPref = false)
        {
            //No need to check RemotingRole; no call to db.
            long       totalWriteoffsUpdated = 0;
            List <Fee> listFeesHQ            = Fees.GetByClinicNum(0);//All HQ fees
            Dictionary <long, List <Procedure> > dictPatProcs;
            List <FamProc> listFamProcs;
            Dictionary <long, List <ClaimProc> > dictClaimProcs;
            List <Fee>            listFeesHQandClinic;
            Lookup <FeeKey2, Fee> lookupFeesByCodeAndSched;
            List <InsSub>         listInsSubs;
            List <InsPlan>        listInsPlans;
            List <PatPlan>        listPatPlans;
            List <Benefit>        listBenefits;
            List <Action>         listActions;
            //Get all objects needed to check if procedures are linked to an orthocase here to avoid querying in loops.
            List <OrthoProcLink>             listOrthoProcLinksAll = new List <OrthoProcLink>();
            Dictionary <long, OrthoProcLink> dictOrthoProcLinksAll = new Dictionary <long, OrthoProcLink>();
            Dictionary <long, OrthoCase>     dictOrthoCases        = new Dictionary <long, OrthoCase>();
            Dictionary <long, OrthoSchedule> dictOrthoSchedules    = new Dictionary <long, OrthoSchedule>();

            OrthoCases.GetDataForAllProcLinks(ref listOrthoProcLinksAll, ref dictOrthoProcLinksAll, ref dictOrthoCases, ref dictOrthoSchedules);
            OrthoProcLink        orthoProcLink = null;
            OrthoCase            orthoCase     = null;
            OrthoSchedule        orthoSchedule = null;
            List <OrthoProcLink> listOrthoProcLinksForOrthoCase = null;

            foreach (long clinicNumCur in listWriteoffClinicNums)
            {
                progress.Fire(ODEventType.FeeSched, new ProgressBarHelper(Clinics.GetAbbr(clinicNumCur), "0%", 0, 100, ProgBarStyle.Blocks, "WriteoffProgress"));
                long   rowCurIndex = 0;               //reset for each clinic.
                object lockObj     = new object();    //used to lock rowCurIndex so the threads will correctly increment the count
                progress.Fire(ODEventType.FeeSched, new ProgressBarHelper(Lans.g("FeeSchedEvent", "Getting list to update writeoffs..."),
                                                                          progressBarEventType: ProgBarEventType.TextMsg));
                listFeesHQandClinic = Fees.GetByClinicNum(clinicNumCur);              //could be empty for some clinics that don't use overrides
                listFeesHQandClinic.AddRange(listFeesHQ);
                lookupFeesByCodeAndSched = (Lookup <FeeKey2, Fee>)listFeesHQandClinic.ToLookup(x => new FeeKey2(x.CodeNum, x.FeeSched));
                dictPatProcs             = Procedures.GetAllTp(clinicNumCur)
                                           .GroupBy(x => x.PatNum)
                                           .ToDictionary(x => x.Key, x => Procedures.SortListByTreatPlanPriority(x.ToList()).ToList());
                #region Has Paused or Cancelled
                while (progress.IsPaused)
                {
                    progress.AllowResume();
                    if (progress.IsCanceled)
                    {
                        break;
                    }
                }
                if (progress.IsCanceled)
                {
                    break;
                }
                #endregion Has Paused or Cancelled
                if (dictPatProcs.Count == 0)
                {
                    continue;
                }
                int procCount = dictPatProcs.Sum(x => x.Value.Count);
                listFamProcs = Patients.GetFamilies(dictPatProcs.Keys.ToList()).Where(x => x.Guarantor != null)
                               .Select(x => new FamProc {
                    GuarNum      = x.Guarantor.PatNum,
                    ListPatProcs = x.ListPats.Select(y => new PatProc {
                        PatNum    = y.PatNum,
                        Age       = y.Age,
                        ListProcs = dictPatProcs.TryGetValue(y.PatNum, out List <Procedure> listProcsCurr)?listProcsCurr:new List <Procedure>()
                    }).ToList()
                }).ToList();
                listPatPlans = PatPlans.GetPatPlansForPats(dictPatProcs.Keys.ToList());
                listInsSubs  = InsSubs.GetListInsSubs(dictPatProcs.Keys.ToList());
                List <long> listInsSubNums = listInsSubs.Select(x => x.InsSubNum).ToList();
                listInsSubs.AddRange(InsSubs.GetMany(listPatPlans.Select(x => x.InsSubNum).Distinct().Where(x => !listInsSubNums.Contains(x)).ToList()));
                listInsSubs  = listInsSubs.DistinctBy(x => x.InsSubNum).ToList();
                listInsPlans = InsPlans.RefreshForSubList(listInsSubs);
                listBenefits = Benefits.GetAllForPatPlans(listPatPlans, listInsSubs);
                #region Has Paused or Cancelled
                while (progress.IsPaused)
                {
                    progress.AllowResume();
                    if (progress.IsCanceled)
                    {
                        break;
                    }
                }
                if (progress.IsCanceled)
                {
                    break;
                }
                #endregion Has Paused or Cancelled
                //dictionary of key=PatNum, value=list of claimprocs, i.e. a dictionary linking each PatNum to a list of claimprocs for the given procs
                dictClaimProcs = ClaimProcs.GetForProcs(dictPatProcs.SelectMany(x => x.Value.Select(y => y.ProcNum)).ToList(), useDataReader: true)
                                 .GroupBy(x => x.PatNum)
                                 .ToDictionary(x => x.Key, x => x.ToList());
                #region Has Paused or Cancelled
                while (progress.IsPaused)
                {
                    progress.AllowResume();
                    if (progress.IsCanceled)
                    {
                        break;
                    }
                }
                if (progress.IsCanceled)
                {
                    break;
                }
                #endregion Has Paused or Cancelled
                progress.Fire(ODEventType.FeeSched, new ProgressBarHelper(Lans.g("FeeSchedEvent", "Updating writeoff estimates for patients..."),
                                                                          progressBarEventType: ProgBarEventType.TextMsg));
                listActions = listFamProcs.Select(x => new Action(() => {
                    #region Has Cancelled
                    if (progress.IsCanceled)
                    {
                        return;
                    }
                    #endregion Has Cancelled
                    List <long> listPatNums = x.ListPatProcs.Select(y => y.PatNum).ToList();
                    List <long> listInsSubNumsPatPlanCur          = listPatPlans.Where(y => y.PatNum.In(listPatNums)).Select(y => y.InsSubNum).ToList();
                    List <InsSub> listInsSubsCur                  = listInsSubs.FindAll(y => listPatNums.Contains(y.Subscriber) || y.InsSubNum.In(listInsSubNumsPatPlanCur));
                    List <long> listInsSubPlanNumsCur             = listInsSubsCur.Select(y => y.PlanNum).ToList();
                    List <InsPlan> listInsPlansCur                = listInsPlans.FindAll(y => listInsSubPlanNumsCur.Contains(y.PlanNum));
                    List <SubstitutionLink> listSubstitutionLinks = SubstitutionLinks.GetAllForPlans(listInsPlansCur);
                    List <PatPlan> listPatPlansCur;
                    List <Benefit> listBenefitsCur;
                    foreach (PatProc patProc in x.ListPatProcs)                     //foreach patient in the family
                    {
                        if (patProc.ListProcs.IsNullOrEmpty())
                        {
                            continue;
                        }
                        listPatPlansCur = listPatPlans.FindAll(y => y.PatNum == patProc.PatNum);
                        List <long> listInsPlanNumsCur = listInsPlansCur.Select(y => y.PlanNum).ToList();
                        List <long> listPatPlanNumsCur = listPatPlansCur.Select(y => y.PatPlanNum).ToList();
                        listBenefitsCur = listBenefits
                                          .FindAll(y => listInsPlanNumsCur.Contains(y.PlanNum) || listPatPlanNumsCur.Contains(y.PatPlanNum));
                        listBenefitsCur.Sort(Benefits.SortBenefits);
                        if (!dictClaimProcs.TryGetValue(patProc.PatNum, out List <ClaimProc> listClaimProcsCur))
                        {
                            listClaimProcsCur = new List <ClaimProc>();
                        }
                        foreach (Procedure procCur in patProc.ListProcs)                         //foreach proc for this patient
                        {
                            OrthoCases.FillOrthoCaseObjectsForProc(procCur.ProcNum, ref orthoProcLink, ref orthoCase, ref orthoSchedule
                                                                   , ref listOrthoProcLinksForOrthoCase, dictOrthoProcLinksAll, dictOrthoCases, dictOrthoSchedules, listOrthoProcLinksAll);
                            Procedures.ComputeEstimates(procCur, patProc.PatNum, ref listClaimProcsCur, false, listInsPlansCur, listPatPlansCur, listBenefitsCur,
                                                        null, null, true, patProc.Age, listInsSubsCur, listSubstLinks: listSubstitutionLinks, lookupFees: lookupFeesByCodeAndSched,
                                                        orthoProcLink: orthoProcLink, orthoCase: orthoCase, orthoSchedule: orthoSchedule, listOrthoProcLinksForOrthoCase: listOrthoProcLinksForOrthoCase);
                            double percentage = 0;
                            lock (lockObj) {
                                percentage = Math.Ceiling(((double)(++rowCurIndex) / procCount) * 100);
                            }
                            progress.Fire(ODEventType.FeeSched,
                                          new ProgressBarHelper(Clinics.GetAbbr(clinicNumCur), (int)percentage + "%", (int)percentage, 100, ProgBarStyle.Blocks, "WriteoffProgress"));
                        }
                    }
                })).ToList();
                ODThread.RunParallel(listActions, TimeSpan.FromHours(3),
                                     onException: new ODThread.ExceptionDelegate((ex) => {
                    //Notify the user what went wrong via the text box.
                    progress.Fire(ODEventType.FeeSched, new ProgressBarHelper("Error updating writeoffs: " + ex.Message,
                                                                              progressBarEventType: ProgBarEventType.TextMsg));
                })
                                     );
                if (listWriteoffClinicNums.Count > 1)               //only show if more than one clinic
                {
                    progress.Fire(ODEventType.FeeSched,
                                  new ProgressBarHelper(rowCurIndex + " " + Lans.g("FeeSchedTools", "procedures processed from") + " " + Clinics.GetAbbr(clinicNumCur),
                                                        progressBarEventType: ProgBarEventType.TextMsg));
                }
                totalWriteoffsUpdated += rowCurIndex;
                if (doUpdatePrevClinicPref && rowCurIndex == procCount)
                {
                    //if storing previously completed clinic and we actually completed this clinic's procs, update the pref
                    if (listWriteoffClinicNums.Last() == clinicNumCur)
                    {
                        //if this is the last clinic in the list, clear the last clinic pref so the next time it will run for all clinics
                        Prefs.UpdateString(PrefName.GlobalUpdateWriteOffLastClinicCompleted, "");
                    }
                    else
                    {
                        Prefs.UpdateString(PrefName.GlobalUpdateWriteOffLastClinicCompleted, POut.Long(clinicNumCur));
                    }
                    Signalods.SetInvalid(InvalidType.Prefs);
                }
                #region Has Cancelled
                if (progress.IsCanceled)
                {
                    break;
                }
                #endregion Has Cancelled
            }
            progress.OnProgressDone();
            progress.Fire(ODEventType.FeeSched, new ProgressBarHelper("Writeoffs updated. " + totalWriteoffsUpdated + " procedures processed.\r\nDone.",
                                                                      progressBarEventType: ProgBarEventType.TextMsg));
            return(totalWriteoffsUpdated);
        }
Пример #19
0
        ///<summary>Returns the number of subscribers moved.
        ///No need to pass in userNum, it's set before remoting role check and passed to the server if necessary.</summary>
        public static long MoveSubscribers(long insPlanNumFrom, long insPlanNumTo, 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)
            {
                return(Meth.GetLong(MethodBase.GetCurrentMethod(), insPlanNumFrom, insPlanNumTo, userNum));
            }
            List <InsSub> listInsSubsFrom    = GetListForPlanNum(insPlanNumFrom);
            List <long>   listBlockedPatNums = new List <long>();

            //Perform the same validation as when the user manually drops insplans from FormInsPlan using the Drop button.
            for (int i = 0; i < listInsSubsFrom.Count; i++)
            {
                InsSub         insSubFrom      = listInsSubsFrom[i];
                List <PatPlan> listPatPlanFrom = PatPlans.Refresh(insSubFrom.Subscriber);
                for (int j = 0; j < listPatPlanFrom.Count; j++)
                {
                    PatPlan patPlanFrom = listPatPlanFrom[j];
                    //The following comments and logic are copied from the FormInsPlan Drop button...
                    //If they have a claim for this ins with today's date, don't let them drop.
                    //We already have code in place to delete claimprocs when we drop ins, but the claimprocs attached to claims are protected.
                    //The claim clearly needs to be deleted if they are dropping.  We need the user to delete the claim before they drop the plan.
                    //We also have code in place to add new claimprocs when they add the correct insurance.
                    List <Claim> listClaims = Claims.Refresh(patPlanFrom.PatNum);                 //Get all claims for patient.
                    for (int k = 0; k < listClaims.Count; k++)
                    {
                        if (listClaims[k].PlanNum != insPlanNumFrom)                       //Make sure the claim is for the insurance plan we are about to change, not any other plans the patient might have.
                        {
                            continue;
                        }
                        if (listClaims[k].DateService != DateTime.Today)                       //not today
                        {
                            continue;
                        }
                        //Patient currently has a claim for the insplan they are trying to drop.
                        if (!listBlockedPatNums.Contains(patPlanFrom.PatNum))
                        {
                            listBlockedPatNums.Add(patPlanFrom.PatNum);
                        }
                    }
                }
            }
            if (listBlockedPatNums.Count > 0)
            {
                StringBuilder sb = new StringBuilder();
                for (int i = 0; i < listBlockedPatNums.Count; i++)
                {
                    sb.Append("\r\n");
                    Patient pat = Patients.GetPat(listBlockedPatNums[i]);
                    sb.Append("#" + listBlockedPatNums[i] + " " + pat.GetNameFLFormal());
                }
                throw new ApplicationException(Lans.g("InsSubs", "Before changing the subscribers on the insurance plan being moved from, please delete all of today's claims related to the insurance plan being moved from for the following patients") + ":" + sb.ToString());
            }
            //This loop mimics some of the logic in PatPlans.Delete().
            int insSubMovedCount = 0;

            for (int i = 0; i < listInsSubsFrom.Count; i++)
            {
                InsSub inssub       = listInsSubsFrom[i];
                long   oldInsSubNum = inssub.InsSubNum;
                inssub.InsSubNum       = 0;        //This will allow us to insert a new record.
                inssub.PlanNum         = insPlanNumTo;
                inssub.DateEffective   = DateTime.MinValue;
                inssub.BenefitNotes    = "";
                inssub.SubscNote       = "";
                inssub.SecUserNumEntry = userNum;
                long      insSubNumNew       = InsSubs.Insert(inssub);
                string    command            = "SELECT PatNum FROM patplan WHERE InsSubNum=" + POut.Long(oldInsSubNum);
                DataTable tablePatsForInsSub = Db.GetTable(command);
                if (tablePatsForInsSub.Rows.Count == 0)
                {
                    continue;
                }
                insSubMovedCount++;
                for (int j = 0; j < tablePatsForInsSub.Rows.Count; j++)
                {
                    long           patNum       = PIn.Long(tablePatsForInsSub.Rows[j]["PatNum"].ToString());
                    List <PatPlan> listPatPlans = PatPlans.Refresh(patNum);
                    for (int k = 0; k < listPatPlans.Count; k++)
                    {
                        PatPlan patPlan = listPatPlans[k];
                        if (patPlan.InsSubNum == oldInsSubNum)
                        {
                            command = "DELETE FROM benefit WHERE PatPlanNum=" + POut.Long(patPlan.PatPlanNum);                         //Delete patient specific benefits (rare).
                            Db.NonQ(command);
                            patPlan.InsSubNum = insSubNumNew;
                            PatPlans.Update(patPlan);
                        }
                    }
                    //Now that the plan has changed for the current subscriber, recalculate estimates.
                    bool prefChanged = false;
                    //Forcefully set pref false to prevent creating new estimates for all procs (including completed, sent procs)
                    if (Prefs.UpdateBool(PrefName.ClaimProcsAllowedToBackdate, false))
                    {
                        prefChanged = true;                      //We will turn the preference back on for the user after we finish our computations.
                    }
                    Family           fam            = Patients.GetFamily(patNum);
                    Patient          pat            = fam.GetPatient(patNum);
                    List <ClaimProc> listClaimProcs = ClaimProcs.Refresh(patNum);
                    List <Procedure> listProcs      = Procedures.Refresh(patNum);
                    listPatPlans = PatPlans.Refresh(patNum);
                    List <InsSub>  listInsSubs  = InsSubs.RefreshForFam(fam);
                    List <InsPlan> listInsPlans = InsPlans.RefreshForSubList(listInsSubs);
                    List <Benefit> listBenefits = Benefits.Refresh(listPatPlans, listInsSubs);
                    Procedures.ComputeEstimatesForAll(patNum, listClaimProcs, listProcs, listInsPlans, listPatPlans, listBenefits, pat.Age, listInsSubs);
                    if (prefChanged)
                    {
                        Prefs.UpdateBool(PrefName.ClaimProcsAllowedToBackdate, true);                       //set back to original value if changed.
                    }
                }
            }
            InsPlan insPlanFrom = InsPlans.RefreshOne(insPlanNumFrom);
            InsPlan planOld     = insPlanFrom.Copy();

            insPlanFrom.IsHidden = true;
            InsPlans.Update(insPlanFrom, planOld);
            return(insSubMovedCount);
        }