Beispiel #1
0
        private void butOK_Click(object sender, EventArgs e)
        {
            if (!EntriesAreValid())
            {
                return;
            }
            //This list should only contain a single patNum, but just in case.
            List <long> listDistinctPatNums = ProcList.Select(x => x.PatNum).Distinct().ToList();
            DateTime    procDate            = DateTime.MinValue;

            if (textDate.Text != "" && ProcList.Any(x => x.ProcDate != PIn.Date(textDate.Text)))
            {
                procDate = PIn.Date(textDate.Text);
            }
            #region Update ProcList and DB to reflect selections
            List <ClaimProc> listClaimProcsAll = ClaimProcs.RefreshForProcs(ProcList.Select(x => x.ProcNum).ToList());
            //Get data for any OrthoCases that may be linked to procs in ProcList
            List <OrthoProcLink>             listOrthoProcLinksAllForPat   = new List <OrthoProcLink>();
            Dictionary <long, OrthoProcLink> dictOrthoProcLinksForProcList = new Dictionary <long, OrthoProcLink>();
            Dictionary <long, OrthoCase>     dictOrthoCases     = new Dictionary <long, OrthoCase>();
            Dictionary <long, OrthoSchedule> dictOrthoSchedules = new Dictionary <long, OrthoSchedule>();
            OrthoCases.GetDataForListProcs(ref listOrthoProcLinksAllForPat, ref dictOrthoProcLinksForProcList, ref dictOrthoCases, ref dictOrthoSchedules, ProcList);
            OrthoCase            orthoCase     = null;
            OrthoSchedule        orthoSchedule = null;
            List <OrthoProcLink> listOrthoProcLinksForOrthoCase = null;
            foreach (Procedure proc in ProcList)
            {
                bool             hasChanged            = false;
                bool             hasDateChanged        = false;
                List <ClaimProc> listClaimProcsForProc = ClaimProcs.GetForProc(listClaimProcsAll, proc.ProcNum);
                Procedure        procOld = _procOldList.Find(x => x.ProcNum == proc.ProcNum); //this shouldn't fail, it needs to be in this list.
                if (procDate != DateTime.MinValue && proc.ProcDate != procDate)               //Using value entered in the textbox.
                {
                    proc.ProcDate = procDate;
                    //ClaimProc.ProcDate will be "synched" in Procedures.ComputeEstimates(), but only if not attached to a claim.  Mimics FormprocEdit.
                    hasDateChanged = true;
                    hasChanged     = true;
                }
                if (comboProv.GetSelected <Provider>() != null && comboProv.GetSelected <Provider>().ProvNum != proc.ProvNum)           //Using selection
                {
                    proc.ProvNum = comboProv.GetSelected <Provider>().ProvNum;
                    //Mimics FormProcEdit, uses different criteria than Procedures.ComputeEstimates().
                    ClaimProcs.TrySetProvFromProc(proc, listClaimProcsForProc);
                    hasChanged = true;
                }
                if (comboClinic.GetSelected <Clinic>() != null && comboClinic.GetSelected <Clinic>().ClinicNum != proc.ClinicNum)           //Using selection
                {
                    proc.ClinicNum = comboClinic.GetSelected <Clinic>().ClinicNum;
                    listClaimProcsForProc.ForEach(x => x.ClinicNum = proc.ClinicNum);
                    hasChanged = true;
                }
                if (hasChanged)
                {
                    Procedures.Update(proc, procOld);
                    if (hasDateChanged)
                    {
                        List <ClaimProc> listNewClaimProcs;
                        dictOrthoProcLinksForProcList.TryGetValue(proc.ProcNum, out OrthoProcLink orthoProcLink);
                        //If proc is linked to an OrthoCase, update dates for OrthoCase.
                        if (orthoProcLink != null)
                        {
                            OrthoCases.UpdateDatesByLinkedProc(orthoProcLink, proc);
                        }
                        OrthoCases.FillOrthoCaseObjectsForProc(proc.ProcNum, ref orthoProcLink, ref orthoCase, ref orthoSchedule, ref listOrthoProcLinksForOrthoCase,
                                                               dictOrthoProcLinksForProcList, dictOrthoCases, dictOrthoSchedules, listOrthoProcLinksAllForPat);
                        RecomputeEstimates(proc, listClaimProcsForProc, out listNewClaimProcs, orthoProcLink, orthoCase, orthoSchedule, listOrthoProcLinksForOrthoCase);
                        ClaimProcs.InsertMany(listNewClaimProcs);                        //Only insert claimProcs that were newly added.
                    }
                }
            }
            ClaimProcs.UpdateMany(listClaimProcsAll);            //Does not contain new claimProcs.
            foreach (long patNum in listDistinctPatNums)         //Should be a single patient.
            {
                Recalls.Synch(patNum);
            }
            #endregion
            #region Security Log Entries
            string logTextProcComplete = "";       //To make security log for procs that were C (specific permission)
            string logTextProcExisting = "";       //To make a security log for procs that were EO,EC (specific permission)
            string logTextProcOther    = "";       //All other procedures (general permission)
            foreach (long patNum in listDistinctPatNums)
            {
                foreach (Procedure proc in ProcList)                 //necessary because of different original values
                {
                    Procedure procOld = _procOldList.FirstOrDefault(x => x.ProcNum == proc.ProcNum);
                    if (procOld == null)
                    {
                        continue;
                    }
                    //If proc has not been changed then a blank string will be returned.
                    //Only changed procs will be reflected in security log entries.
                    switch (procOld.ProcStatus)
                    {
                    case ProcStat.C:
                        logTextProcComplete += ConstructSecurityLogForProcType(proc, procOld);
                        break;

                    case ProcStat.EO:
                    case ProcStat.EC:
                        logTextProcExisting += ConstructSecurityLogForProcType(proc, procOld);
                        break;

                    default:
                        logTextProcOther += ConstructSecurityLogForProcType(proc, procOld);
                        break;
                    }
                }
                if (logTextProcComplete != "")
                {
                    SecurityLogs.MakeLogEntry(Permissions.ProcComplEdit, patNum, logTextProcComplete);
                }
                if (logTextProcExisting != "")
                {
                    SecurityLogs.MakeLogEntry(Permissions.ProcExistingEdit, patNum, logTextProcExisting);
                }
                if (logTextProcOther != "")
                {
                    SecurityLogs.MakeLogEntry(Permissions.ProcEdit, patNum, logTextProcOther);
                }
            }
            #endregion
            DialogResult = DialogResult.OK;
        }