///<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); } }
///<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); }