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); }
// define mapping of tables that have OPTIONAL KEYS: // - Procedures to Pathology // - Procedures to OperatingRoomDetails // - Pathology to OperatingRoomDetails private void SetLinksBasedOnTableRelationship(string currentTableName, string tableName, int currentTablePrimaryKeyValue) { bool isChildForm = false; // none of the forms in this mapping are children of the current table if (currentTablePrimaryKeyValue == 0) // key value not defined on new forms- just display an active link to relevant forms { AppendLinkToRelevantForm(tableName, 0, 0, 0, isChildForm); return; } Procedure procedure = new Procedure(); Pathology pathology = new Pathology(); OperatingRoomDetail orDetail = new OperatingRoomDetail(); string procedureTableName = procedure.TableName; string pathologyTableName = pathology.TableName; string orDetailsTableName = orDetail.TableName; switch (currentTableName) { case "Procedures": // see if this procedure record has an ORDetailId if (tableName.Equals(orDetailsTableName)) { // procedure.Find(Procedure.ProcedureId, currentTablePrimaryKeyValue); // ? procedure.Get(currentTablePrimaryKeyValue); int orDetailId = 0; if (procedure[Procedure.OperatingRoomDetailId] != System.DBNull.Value) { orDetailId = (int)procedure[Procedure.OperatingRoomDetailId]; } int recordCount = 0; if (orDetailId > 0) { recordCount = 1; // a procedure can be associated with at most one OperatingRoomDetail record } AppendLinkToRelevantForm(orDetailsTableName, orDetailId, 0, recordCount, isChildForm); } // see if the pathology table has any record with this procedureId else if (tableName.Equals(pathologyTableName)) { //pathology.Find(Pathology.ProcedureId, currentTablePrimaryKeyValue); //int recordCount = pathology.RecordCount; var conditions = new Dictionary <string, object>() { { Pathology.ProcedureId, currentTablePrimaryKeyValue } }; IEnumerable <Pathology> paths = BusinessObject.GetByFields <Pathology>(conditions); int recordCount = paths.Count(); int recordIndex = 0; if (recordCount > 0) // could be multiple path records all with the same procedure id { for (int i = 0; i < recordCount; i++) { if (recordCount > 1) { recordIndex = i + 1; } //DataRow dr = pathology.DataSourceView.Table.Rows[i]; //AppendLinkToRelevantForm(pathologyTableName, (int)dr[Pathology.PathologyId], recordIndex, recordCount, isChildForm); Pathology p = paths.ElementAt(i); AppendLinkToRelevantForm(pathologyTableName, (int)p[Pathology.PathologyId], recordIndex, recordCount, isChildForm); } } else { AppendLinkToRelevantForm(pathology.TableName, recordIndex, recordCount, isChildForm); } } break; case "Pathology": // see if this Pathogy Record has an ORDetailID OR a Procedure Id if (tableName.Equals(orDetailsTableName)) { pathology.Get(currentTablePrimaryKeyValue); int orDetailId = 0; if (pathology[Pathology.OperatingRoomDetailId] != System.DBNull.Value) { orDetailId = (int)pathology[Pathology.OperatingRoomDetailId]; } int recordCount = 0; if (orDetailId > 0) { recordCount = 1; // a pathology can be associated with at most one OperatingRoomDetail record } AppendLinkToRelevantForm(orDetailsTableName, orDetailId, 0, recordCount, isChildForm); } else if (tableName.Equals(procedureTableName)) { pathology.Get(currentTablePrimaryKeyValue); int procedureId = 0; if (pathology[Pathology.ProcedureId] != System.DBNull.Value) { procedureId = (int)pathology[Pathology.ProcedureId]; } int recordCount = 0; if (procedureId > 0) { recordCount = 1; // a pathology can be associated with at most one pathology record } AppendLinkToRelevantForm(procedureTableName, procedureId, 0, recordCount, isChildForm); } break; case "OperatingRoomDetails": // see if the Procedures table and the Pathology table have records with this ORDetailId if (tableName.Equals(pathologyTableName)) { //pathology.Find(Pathology.OperatingRoomDetailId, currentTablePrimaryKeyValue); //int recordCount = pathology.RecordCount; var conditions = new Dictionary <string, object>() { { Pathology.OperatingRoomDetailId, currentTablePrimaryKeyValue } }; IEnumerable <Pathology> paths = BusinessObject.GetByFields <Pathology>(conditions); int recordCount = paths.Count(); int recordIndex = 0; if (recordCount > 0) // could be multiple path records all with the same procedure id { for (int i = 0; i < recordCount; i++) { if (recordCount > 1) { recordIndex = i + 1; } //DataRow dr = pathology.DataSourceView.Table.Rows[i]; //AppendLinkToRelevantForm(pathologyTableName, (int)dr[Pathology.PathologyId], recordIndex, recordCount, isChildForm); Pathology p = paths.ElementAt(i); AppendLinkToRelevantForm(pathologyTableName, (int)p[Pathology.PathologyId], recordIndex, recordCount, isChildForm); } } else { AppendLinkToRelevantForm(pathologyTableName, recordIndex, recordCount, isChildForm); } } else if (tableName.Equals(procedureTableName)) { //procedure.Find(Procedure.OperatingRoomDetailId, currentTablePrimaryKeyValue); //int recordCount = procedure.RecordCount; var conditions = new Dictionary <string, object>() { { Procedure.OperatingRoomDetailId, currentTablePrimaryKeyValue } }; IEnumerable <Procedure> procs = BusinessObject.GetByFields <Procedure>(conditions); int recordCount = procs.Count(); int recordIndex = 0; if (recordCount > 0) // could be multiple path records all with the same procedure id { for (int i = 0; i < recordCount; i++) { if (recordCount > 1) { recordIndex = i + 1; } //DataRow dr = procedure.DataSourceView.Table.Rows[i]; //AppendLinkToRelevantForm(procedureTableName, (int)dr[Procedure.ProcedureId], recordIndex, recordCount, isChildForm); Procedure p = procs.ElementAt(i); AppendLinkToRelevantForm(procedureTableName, (int)p[Procedure.ProcedureId], recordIndex, recordCount, isChildForm); } } else { AppendLinkToRelevantForm(procedureTableName, recordIndex, recordCount, isChildForm); } } break; default: break; } // use switch }
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()); }