public IEnumerable <BusinessObject> SaveGradeDetails(int pathologyId)
        {
            List <BusinessObject> records = new List <BusinessObject>();
            bool formIsDirty = dirtyControls.Contains(GradeDetailsPanel);

            if (formIsDirty)
            {
                var  inputs             = CICHelper.GetCaisisInputControls(GradeDetailsPanel);
                var  stageGradeFields   = CICHelper.GetInputControlsByTable <PathologyStageGrade>(inputs);
                bool stageGradeHasValue = CICHelper.InputControlsHaveValue(stageGradeFields);
                if (stageGradeHasValue)
                {
                    int?pathStageGradeId = null;
                    if (!string.IsNullOrEmpty(PathologyStageGradeId.Value))
                    {
                        pathStageGradeId = int.Parse(PathologyStageGradeId.Value);
                    }
                    PathologyStageGrade pathStageGrade = new PathologyStageGrade();
                    // udpate
                    if (pathStageGradeId.HasValue)
                    {
                        pathStageGrade.Get(pathStageGradeId.Value);
                    }
                    // insert
                    else
                    {
                        pathStageGrade[PathologyStageGrade.PathologyId] = pathologyId;
                    }
                    CICHelper.SetBOValues(GradeDetailsPanel.Controls, pathStageGrade, pathologyId);
                    base.SaveBizo(pathStageGrade);
                    if (pathStageGrade.PrimaryKeyHasValue)
                    {
                        pathStageGradeId            = (int)pathStageGrade[PathologyStageGrade.PathologyStageGradeId];
                        PathologyStageGradeId.Value = pathStageGradeId + "";
                        records.Add(pathStageGrade);
                    }
                }
            }
            return(records.ToArray());
        }
        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);
        }
        public override IEnumerable <BusinessObject> Save()
        {
            List <BusinessObject> records       = new List <BusinessObject>();
            IEnumerable <Control> dirtyControls = base.GetDirtyInputControls(BiopsiesRptr);

            foreach (RepeaterItem dirtyRow in dirtyControls)
            {
                // key controls
                HiddenField procIdField = dirtyRow.FindControl("ProcedureId") as HiddenField;
                HiddenField pathIdField = dirtyRow.FindControl("PathologyId") as HiddenField;
                int?        procedureId = null;
                if (!string.IsNullOrEmpty(procIdField.Value))
                {
                    procedureId = int.Parse(procIdField.Value);
                }
                int?pathologyId = null;
                if (!string.IsNullOrEmpty(pathIdField.Value))
                {
                    pathologyId = int.Parse(pathIdField.Value);
                }

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

                // special fields
                ICaisisInputControl pathType     = dirtyRow.FindControl("PathSpecimenType") as ICaisisInputControl;
                ICaisisInputControl procDateText = dirtyRow.FindControl("ProcDateText") as ICaisisInputControl;
                ICaisisInputControl procDate     = dirtyRow.FindControl("ProcDate") as ICaisisInputControl;
                ICaisisInputControl pathSite     = dirtyRow.FindControl("PathSite") as ICaisisInputControl;

                // 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]     = pathType.Value;
                    procedure[Procedure.ProcSite]     = pathSite.Value;
                    procedure[Procedure.ProcDateText] = procDateText.Value;
                    procedure[Procedure.ProcDate]     = procDate.Value;

                    base.SaveBizo(procedure);
                    procedureId       = (int)procedure[Procedure.ProcedureId];
                    procIdField.Value = procedureId + "";
                    // 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] = pathType.Value;
                    pathology[Pathology.PathSite]         = pathSite.Value;
                    CICHelper.SetBOValues(dirtyRow.Controls, pathology, base.patientId);
                    base.SaveBizo(pathology);
                    pathologyId       = (int)pathology[Pathology.PathologyId];
                    pathIdField.Value = pathologyId + "";

                    // update biz list
                    records.Add(procedure);
                    records.Add(pathology);
                }
                // step 3: create biopsy path
                if (CICHelper.InputControlsHaveValue(biopsyPathFields) && pathologyId.HasValue)
                {
                    BiopsyProstatePathology biopsyPath = new BiopsyProstatePathology();
                    // load existing
                    biopsyPath.Get(pathologyId.Value);
                    // else create
                    if (biopsyPath.IsEmpty)
                    {
                        biopsyPath[BiopsyProstatePathology.PathologyId] = pathologyId;
                    }
                    CICHelper.SetBOValues(dirtyRow.Controls, biopsyPath, pathologyId.Value);
                    base.SaveBizo(biopsyPath);
                    records.Add(biopsyPath);
                }
            }
            //Populate();
            return(records.ToArray());
        }