Ejemplo n.º 1
0
        ///<summary>Creates a new discount adjustment for the given procedure using the discount plan fee.</summary>
        public static void CreateAdjustmentForDiscountPlan(Procedure procedure)
        {
            //No need to check RemotingRole; no call to db.
            DiscountPlan discountPlan = DiscountPlans.GetPlan(Patients.GetPat(procedure.PatNum).DiscountPlanNum);

            if (discountPlan == null)
            {
                return;                //No discount plan.
            }
            //Figure out how much the patient saved and make an adjustment for the difference so that the office find how much money they wrote off.
            double discountAmt = Fees.GetAmount(procedure.CodeNum, discountPlan.FeeSchedNum, procedure.ClinicNum, procedure.ProvNum);

            if (discountAmt == -1)
            {
                return;                //No fee entered, don't make adjustment.
            }
            double adjAmt = procedure.ProcFee - discountAmt;

            if (adjAmt <= 0)
            {
                return;                //We do not need to create adjustments for 0 dollars.
            }
            Adjustment adjustmentCur = new Adjustment();

            adjustmentCur.DateEntry = DateTime.Today;
            adjustmentCur.AdjDate   = DateTime.Today;
            adjustmentCur.ProcDate  = procedure.ProcDate;
            adjustmentCur.ProvNum   = procedure.ProvNum;
            adjustmentCur.PatNum    = procedure.PatNum;
            adjustmentCur.AdjType   = discountPlan.DefNum;
            adjustmentCur.ClinicNum = procedure.ClinicNum;
            adjustmentCur.AdjAmt    = (-adjAmt);
            adjustmentCur.ProcNum   = procedure.ProcNum;
            Insert(adjustmentCur);
            TsiTransLogs.CheckAndInsertLogsIfAdjTypeExcluded(adjustmentCur);
            SecurityLogs.MakeLogEntry(Permissions.AdjustmentCreate, procedure.PatNum, "Adjustment made for discount plan: " + adjustmentCur.AdjAmt.ToString("f"));
        }
Ejemplo n.º 2
0
        ///<summary>Gets all possible fees associated with the various objects passed in.  Gets fees from db based on code and fee schedule combos.  Includes all provider overrides.  Includes default/no clinic as well as any specified clinic overrides. Although the list always includes extra fees from scheds that we don't need, it's still a very small list.  That list is then used repeatedly by other code in loops to find the actual individual fee amounts.</summary>
        public static List <Fee> GetListFromObjects(List <ProcedureCode> listProcedureCodes, List <string> listMedicalCodes, List <long> listProvNumsTreat, long patPriProv,
                                                    long patSecProv, long patFeeSched, List <InsPlan> listInsPlans, List <long> listClinicNums, List <Appointment> listAppts,
                                                    List <SubstitutionLink> listSubstLinks, long discountPlan
                                                    //listCodeNums,listProvNumsTreat,listProcCodesProvNumDefault,patPriProv,patSecProv,patFeeSched,listInsPlans,listClinicNums
                                                    //List<long> listProcCodesProvNumDefault
                                                    )
        {
            //listMedicalCodes: it already automatically gets the medical codes from procCodes.  This is just for procs. If no procs yet, it will be null.
            //listMedicalCodes can be done by: listProcedures.Select(x=>x.MedicalCode).ToList();  //this is just the strings
            //One way to get listProvNumsTreat is listProcedures.Select(x=>x.ProvNum).ToList()
            //One way to specify a single provNum in listProvNumsTreat is new List<long>(){provNum}
            //One way to get clinicNums is listProcedures.Select(x=>x.ClinicNum).ToList()
            //Another way to get clinicNums is new List<long>(){clinicNum}.
            //These objects will be cleaned up, so they can have duplicates, zeros, invalid keys, nulls, etc
            //In some cases, we need to pass in a list of appointments to make sure we've included all possible providers, both ProvNum and ProvHyg
            //In that case, it's common to leave listProvNumsTreat null because we clearly do not have any of those providers set yet.
            if (RemotingClient.RemotingRole == RemotingRole.ClientWeb)
            {
                return(Meth.GetObject <List <Fee> >(MethodBase.GetCurrentMethod(), listProcedureCodes, listMedicalCodes, listProvNumsTreat, patPriProv,
                                                    patSecProv, patFeeSched, listInsPlans, listClinicNums, listAppts, listSubstLinks, discountPlan));
            }
            if (listProcedureCodes == null)
            {
                return(new List <Fee>());
            }
            List <long> listCodeNumsOut = new List <long>();

            foreach (ProcedureCode procedureCode in listProcedureCodes)
            {
                if (procedureCode == null)
                {
                    continue;
                }
                if (!listCodeNumsOut.Contains(procedureCode.CodeNum))
                {
                    listCodeNumsOut.Add(procedureCode.CodeNum);
                }
                if (ProcedureCodes.IsValidCode(procedureCode.MedicalCode))
                {
                    long codeNumMed = ProcedureCodes.GetCodeNum(procedureCode.MedicalCode);
                    if (!listCodeNumsOut.Contains(codeNumMed))
                    {
                        listCodeNumsOut.Add(codeNumMed);
                    }
                }
                if (ProcedureCodes.IsValidCode(procedureCode.SubstitutionCode))
                {
                    long codeNumSub = ProcedureCodes.GetCodeNum(procedureCode.SubstitutionCode);
                    if (!listCodeNumsOut.Contains(codeNumSub))
                    {
                        listCodeNumsOut.Add(codeNumSub);
                    }
                }
            }
            if (listMedicalCodes != null)
            {
                foreach (string strMedCode in listMedicalCodes)
                {
                    if (ProcedureCodes.IsValidCode(strMedCode))
                    {
                        long codeNumMed = ProcedureCodes.GetCodeNum(strMedCode);
                        if (!listCodeNumsOut.Contains(codeNumMed))
                        {
                            listCodeNumsOut.Add(codeNumMed);
                        }
                    }
                }
            }
            if (listSubstLinks != null)
            {
                foreach (SubstitutionLink substitutionLink in listSubstLinks)                //Grab all subst codes, since we don't know which ones we will need.
                {
                    if (ProcedureCodes.IsValidCode(substitutionLink.SubstitutionCode))
                    {
                        long codeNum = ProcedureCodes.GetCodeNum(substitutionLink.SubstitutionCode);
                        if (!listCodeNumsOut.Contains(codeNum))
                        {
                            listCodeNumsOut.Add(codeNum);
                        }
                    }
                }
            }
            //Fee schedules. Will potentially include many.=======================================================================================
            List <long> listFeeScheds = new List <long>();
            //Add feesched for first provider (See Claims.CalculateAndUpdate)---------------------------------------------------------------------
            Provider provFirst = Providers.GetFirst();

            if (provFirst != null && provFirst.FeeSched != 0 && !listFeeScheds.Contains(provFirst.FeeSched))
            {
                listFeeScheds.Add(provFirst.FeeSched);
            }
            //Add feesched for PracticeDefaultProv------------------------------------------------------------------------------------------------
            Provider provPracticeDefault = Providers.GetProv(PrefC.GetLong(PrefName.PracticeDefaultProv));

            if (provPracticeDefault != null && provPracticeDefault.FeeSched != 0 && !listFeeScheds.Contains(provPracticeDefault.FeeSched))
            {
                listFeeScheds.Add(provPracticeDefault.FeeSched);
            }
            //Add feescheds for all treating providers---------------------------------------------------------------------------------------------
            if (listProvNumsTreat != null)
            {
                foreach (long provNumTreat in listProvNumsTreat)
                {
                    Provider provTreat = Providers.GetProv(provNumTreat);
                    if (provTreat != null && provTreat.FeeSched != 0 && !listFeeScheds.Contains(provTreat.FeeSched))
                    {
                        listFeeScheds.Add(provTreat.FeeSched);                        //treating provs fee scheds
                    }
                }
            }
            //Add feescheds for the patient's primary and secondary providers----------------------------------------------------------------------
            Provider providerPatPri = Providers.GetProv(patPriProv);

            if (providerPatPri != null && providerPatPri.FeeSched != 0 && !listFeeScheds.Contains(providerPatPri.FeeSched))
            {
                listFeeScheds.Add(providerPatPri.FeeSched);
            }
            Provider providerPatSec = Providers.GetProv(patSecProv);

            if (providerPatSec != null && providerPatSec.FeeSched != 0 && !listFeeScheds.Contains(providerPatSec.FeeSched))
            {
                listFeeScheds.Add(providerPatSec.FeeSched);
            }
            //Add feescheds for all procedurecode.ProvNumDefaults---------------------------------------------------------------------------------
            foreach (ProcedureCode procedureCode in listProcedureCodes)
            {
                if (procedureCode == null)
                {
                    continue;
                }
                long provNumDefault = procedureCode.ProvNumDefault;
                if (provNumDefault == 0)
                {
                    continue;
                }
                Provider provDefault = Providers.GetProv(provNumDefault);
                if (provDefault != null && provDefault.FeeSched != 0 && !listFeeScheds.Contains(provDefault.FeeSched))
                {
                    listFeeScheds.Add(provDefault.FeeSched);
                }
            }
            //Add feescheds for appointment providers---------------------------------------------------------------------------------------------
            if (listAppts != null)
            {
                foreach (Appointment appointment in listAppts)
                {
                    Provider provAppt = Providers.GetProv(appointment.ProvNum);
                    if (provAppt != null && provAppt.FeeSched != 0 && !listFeeScheds.Contains(provAppt.FeeSched))
                    {
                        listFeeScheds.Add(provAppt.FeeSched);
                    }
                    Provider provApptHyg = Providers.GetProv(appointment.ProvHyg);
                    if (provApptHyg != null && provApptHyg.FeeSched != 0 && !listFeeScheds.Contains(provApptHyg.FeeSched))
                    {
                        listFeeScheds.Add(provApptHyg.FeeSched);
                    }
                }
            }
            //Add feesched for patient.  Rare. --------------------------------------------------------------------------------------------------
            if (patFeeSched != 0)
            {
                if (!listFeeScheds.Contains(patFeeSched))
                {
                    listFeeScheds.Add(patFeeSched);
                }
            }
            //Add feesched for each insplan, both reg and allowed--------------------------------------------------------------------------------
            if (listInsPlans != null)
            {
                foreach (InsPlan insPlan in listInsPlans)
                {
                    if (insPlan.FeeSched != 0 && !listFeeScheds.Contains(insPlan.FeeSched))
                    {
                        listFeeScheds.Add(insPlan.FeeSched);                        //insplan feeSched
                    }
                    if (insPlan.AllowedFeeSched != 0 && !listFeeScheds.Contains(insPlan.AllowedFeeSched))
                    {
                        listFeeScheds.Add(insPlan.AllowedFeeSched);                        //allowed feeSched
                    }
                    if (insPlan.CopayFeeSched != 0 && !listFeeScheds.Contains(insPlan.CopayFeeSched))
                    {
                        listFeeScheds.Add(insPlan.CopayFeeSched);                        //copay feeSched
                    }
                }
            }
            if (discountPlan != 0)
            {
                long discountPlanFeeSched = DiscountPlans.GetPlan(discountPlan).FeeSchedNum;
                if (!listFeeScheds.Contains(discountPlanFeeSched))
                {
                    listFeeScheds.Add(discountPlanFeeSched);
                }
            }
            //ClinicNums========================================================================================================================
            List <long> listClinicNumsOut = new List <long>();        //usually empty or one entry

            if (listClinicNums != null)
            {
                foreach (long clinicNum in listClinicNums)
                {
                    if (clinicNum != 0 && !listClinicNumsOut.Contains(clinicNum))
                    {
                        listClinicNumsOut.Add(clinicNum);                        //proc ClinicNums
                    }
                }
            }
            if (listFeeScheds.Count == 0 || listProcedureCodes.Count == 0)
            {
                return(new List <Fee>());
            }
            string command = "SELECT * FROM fee WHERE (";

            for (int i = 0; i < listFeeScheds.Count; i++)
            {
                if (i > 0)
                {
                    command += " OR ";
                }
                command += "FeeSched=" + POut.Long(listFeeScheds[i]);
            }
            command += ") AND (";
            for (int i = 0; i < listCodeNumsOut.Count; i++)
            {
                if (i > 0)
                {
                    command += " OR ";
                }
                command += "CodeNum=" + POut.Long(listCodeNumsOut[i]);
            }
            command += ") AND (ClinicNum=0";
            for (int i = 0; i < listClinicNumsOut.Count; i++)
            {
                command += " OR ClinicNum=" + POut.Long(listClinicNumsOut[i]);
            }
            command += ")";
            return(Crud.FeeCrud.SelectMany(command));
        }
Ejemplo n.º 3
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);
        }