public override IEnumerable <BusinessObject> Save()
        {
            // save diag biopsy
            List <BusinessObject>             records          = new List <BusinessObject>();
            IEnumerable <ICaisisInputControl> stageGradeFields = CICHelper.GetCaisisInputControls(StageGradePanel);

            int?procedureId = null;

            if (!string.IsNullOrEmpty(ProcedureId.Value))
            {
                procedureId = int.Parse(ProcedureId.Value);
            }
            int?pathologyId = null;

            if (!string.IsNullOrEmpty(PathologyId.Value))
            {
                pathologyId = int.Parse(PathologyId.Value);
            }

            var inputs           = CICHelper.GetCaisisInputControls(this);
            var procFields       = CICHelper.GetInputControlsByTable <Procedure>(inputs);
            var pathFields       = CICHelper.GetInputControlsByTable <Pathology>(inputs);
            var biopsyPathFields = CICHelper.GetInputControlsByTable <BiopsyProstatePathology>(inputs);

            // validation
            if (CICHelper.InputControlsHaveValue(pathFields))
            {
                // step 1: create procedure
                Procedure procedure = new Procedure();
                if (procedureId.HasValue)
                {
                    procedure.Get(procedureId.Value);
                }
                else
                {
                    procedure[Procedure.PatientId] = base.patientId;
                }
                // copy field values
                procedure[Procedure.ProcName]     = PathSpecimenType.Value;
                procedure[Procedure.ProcDateText] = ProcDateText.Value;
                procedure[Procedure.ProcDate]     = ProcDate.Value;
                procedure[Procedure.ProcSite]     = PathSite.Value;
                // get special stamp
                procedure.AppendToUserName(GetEnteredBySuffix());
                procedure.Save();
                //base.SaveBizo(procedure);
                procedureId       = (int)procedure[Procedure.ProcedureId];
                ProcedureId.Value = procedureId + "";
                records.Add(procedure);

                // step 2: create path
                Pathology pathology = new Pathology();
                if (pathologyId.HasValue)
                {
                    pathology.Get(pathologyId.Value);
                }
                else
                {
                    pathology[Pathology.PatientId]    = base.patientId;
                    pathology[Pathology.ProcedureId]  = procedureId;
                    pathology[Pathology.PathDateText] = ProcDateText.Value;
                    pathology[Pathology.PathDate]     = ProcDate.Value;
                }
                pathology[Pathology.PathSpecimenType] = PathSpecimenType.Value;
                pathology[Pathology.PathSite]         = PathSite.Value;
                CICHelper.SetBOValues(this.Controls, pathology, base.patientId);
                base.SaveBizo(pathology);
                pathologyId       = (int)pathology[Pathology.PathologyId];
                PathologyId.Value = pathologyId + "";
                records.Add(pathology);

                // step 3: create biopsy path
                if (CICHelper.InputControlsHaveValue(biopsyPathFields))
                {
                    BiopsyProstatePathology biopsyPath = BusinessObject.GetByParent <BiopsyProstatePathology>(pathologyId.Value).FirstOrDefault();
                    // new
                    if (biopsyPath == null)
                    {
                        biopsyPath = new BiopsyProstatePathology();
                        biopsyPath[BiopsyProstatePathology.PathologyId] = pathologyId.Value;
                    }
                    CICHelper.SetBOValues(this.Controls, biopsyPath, pathologyId.Value);
                    base.SaveBizo(biopsyPath);
                }

                // step 4: save path stage grade
                if (CICHelper.InputControlsHaveValue(stageGradeFields) && !string.IsNullOrEmpty(PathStageT.Value))
                {
                    int?stageGradeId = null;
                    // load by pri key
                    if (!string.IsNullOrEmpty(PathologyStageGradeId.Value))
                    {
                        stageGradeId = int.Parse(PathologyStageGradeId.Value);
                    }
                    // get par key for save
                    else if (!string.IsNullOrEmpty(PathologyId.Value))
                    {
                        pathologyId = int.Parse(PathologyId.Value);
                    }
                    if (pathologyId.HasValue || stageGradeId.HasValue)
                    {
                        PathologyStageGrade stageGrade = base.SaveRecord <PathologyStageGrade>(StageGradePanel, pathologyId, stageGradeId);
                        PathologyStageGradeId.Value = stageGrade[PathologyStageGrade.PathologyStageGradeId] + "";
                        records.Add(stageGrade);
                    }
                }
            }

            //Populate();
            return(records);
        }
        private IEnumerable <BusinessObject> SaveProstatectomy()
        {
            // save prostatectomies
            List <BusinessObject> records       = new List <BusinessObject>();
            IEnumerable <Control> dirtyControls = base.GetDirtyInputControls(ProstatectomyDetailsFields);
            var  inputs  = CICHelper.GetCaisisInputControls(ProstatectomyDetailsFields);
            bool isDirty = dirtyControls.Contains(ProstatectomyDetailsFields);

            if (isDirty)
            {
                int?procedureId = null;
                if (!string.IsNullOrEmpty(ProcedureId.Value))
                {
                    procedureId = int.Parse(ProcedureId.Value);
                }
                int?pathologyId = null;
                if (!string.IsNullOrEmpty(PathologyId.Value))
                {
                    pathologyId = int.Parse(PathologyId.Value);
                }

                var procFields = CICHelper.GetInputControlsByTable <Procedure>(inputs);
                var pathFields = CICHelper.GetInputControlsByTable <Pathology>(inputs);
                var prostatectomyPathFields = CICHelper.GetInputControlsByTable <ProstatectomyPathology>(inputs);

                // create/update proc
                if (CICHelper.InputControlsHaveValue(procFields))
                {
                    // step 1: create procedure
                    Procedure procedure = new Procedure();
                    if (procedureId.HasValue)
                    {
                        procedure.Get(procedureId.Value);
                    }
                    else
                    {
                        procedure[Procedure.PatientId] = base.patientId;
                    }
                    CICHelper.SetBOValues(ProstatectomyDetailsFields.Controls, procedure, base.patientId);

                    // copy field values
                    procedure[Procedure.ProcName]     = ProcName.Value;
                    procedure[Procedure.ProcDateText] = ProcDateText.Value;
                    procedure[Procedure.ProcDate]     = ProcDate.Value;
                    // special case: special stamp to mark inital proc
                    //base.SaveBizo(procedure);
                    procedure.AppendToUserName(GetEnteredBySuffix());
                    procedure.Save();

                    procedureId       = (int)procedure[Procedure.ProcedureId];
                    ProcedureId.Value = procedureId + "";

                    // update biz list
                    records.Add(procedure);
                }
                // step 2: create/udpate path
                if (pathologyId.HasValue || (CICHelper.InputControlsHaveValue(pathFields) && procedureId.HasValue))
                {
                    Pathology pathology = new Pathology();
                    if (pathologyId.HasValue)
                    {
                        pathology.Get(pathologyId.Value);
                    }
                    else
                    {
                        pathology[Pathology.PatientId]        = base.patientId;
                        pathology[Pathology.ProcedureId]      = procedureId;
                        pathology[Pathology.PathSpecimenType] = ProcName.Value;
                        pathology[Pathology.PathDateText]     = ProcDateText.Value;
                        pathology[Pathology.PathDate]         = ProcDate.Value;
                        pathology[Pathology.PathDisease]      = "Prostate";
                    }
                    CICHelper.SetBOValues(ProstatectomyDetailsFields.Controls, pathology, base.patientId);
                    base.SaveBizo(pathology);
                    pathologyId       = (int)pathology[Pathology.PathologyId];
                    PathologyId.Value = pathologyId + "";
                    records.Add(pathology);
                }
                // step 3: create/udpate Prostatectomy Path
                if (CICHelper.InputControlsHaveValue(prostatectomyPathFields) && pathologyId.HasValue)
                {
                    ProstatectomyPathology prostatePath = new ProstatectomyPathology();
                    // load existing
                    prostatePath.Get(pathologyId.Value);
                    // else create
                    if (prostatePath.IsEmpty)
                    {
                        prostatePath[ProstatectomyPathology.PathologyId] = pathologyId;
                    }
                    CICHelper.SetBOValues(ProstatectomyDetailsFields.Controls, prostatePath, pathologyId.Value);
                    base.SaveBizo(prostatePath);
                    records.Add(prostatePath);
                }
            }
            // save grade details
            if (!string.IsNullOrEmpty(PathologyId.Value))
            {
                int pathologyId = int.Parse(PathologyId.Value);
                records.AddRange(SaveGradeDetails(pathologyId));
            }
            return(records);
        }