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