/// <summary> /// Gets the Diagnostic related to the Specimen Accession /// </summary> /// <param name="specimenAccessionId"></param> /// <param name="diagnosticId"></param> /// <returns></returns> private RelatedRecord GetDiagnosticRelatedRecord(int specimenAccessionId, int diagnosticId) { IEnumerable <RelatedRecord> diagnosticRelatedRecords = GetDiagnosticRelatedRecords(specimenAccessionId); RelatedRecord relatedRecord = diagnosticRelatedRecords.FirstOrDefault(r => r[RelatedRecord.DestPrimaryKey].ToString() == diagnosticId.ToString()); return(relatedRecord); }
/// <summary> /// Creates a related record with the specified source system, in which Caisis is the destination table and checks for existing records before inserting (if true). /// </summary> /// <param name="srcSystem"></param> /// <param name="srcTable"></param> /// <param name="srcPrimaryKey"></param> /// <param name="destTable"></param> /// <param name="destPriKey"></param> /// <param name="relationStrength"></param> /// <param name="checkExisiting"></param> /// <returns></returns> public static RelatedRecord CreateRelatedRecord(string srcSystem, string srcTable, int srcPrimaryKey, string destTable, int destPriKey, int?relationStrength, bool checkExisiting) { // validate exisiting record if needed, and return if found if (checkExisiting && HasRelatedRecords(srcSystem, srcTable, srcPrimaryKey, destTable, destPriKey)) { return(GetRelatedRecords(srcSystem, srcTable, srcPrimaryKey, destTable, destPriKey).First()); } // otherwise, insert and return else { RelatedRecord relatedRecord = new RelatedRecord(); relatedRecord[RelatedRecord.SrcTableName] = srcTable; relatedRecord[RelatedRecord.SrcPrimaryKey] = srcPrimaryKey; relatedRecord[RelatedRecord.DestTableName] = destTable; relatedRecord[RelatedRecord.DestPrimaryKey] = destPriKey; relatedRecord[RelatedRecord.SrcSystem] = srcSystem; if (relationStrength.HasValue) { relatedRecord[RelatedRecord.RelationStrength] = relationStrength.Value; } relatedRecord.Save(); return(relatedRecord); } }
/// <summary> /// Builds the data entry interface based on table /// </summary> protected void BuildUnplannedEvent() { // Build UI: build column layout based on default metadata var inputs = CICHelper.GetCaisisInputControlsByTableName(QueryTableName, null); int colCount = new Caisis.Controller.PatientDataEntryController(null).GetNumDisplayColumns(QueryTableName); DataEntryLayout.BuildLayout(inputs, colCount, new string[] { }); // Populate: populate exising record if (!string.IsNullOrEmpty(PriKeyField.Value)) { int priKey = int.Parse(PriKeyField.Value); // load record and populate form var biz = BusinessObjectFactory.BuildBusinessObject(QueryTableName); biz.Get(priKey); // populate section with biz base.PopulateForm(DataEntryLayout, biz); // set related record if exists if (!string.IsNullOrEmpty(PatientItemId.Value)) { int patientItemId = int.Parse(base.DecrypyValue(PatientItemId.Value)); RelatedRecord relatedRecord = Caisis.Controller.RelatedRecordController.GetRelatedRecords("ProtocolMgr_PatientItems", patientItemId, QueryTableName, priKey).FirstOrDefault(); if (relatedRecord != null) { RelatedRecordId.Value = relatedRecord[RelatedRecord.RelatedRecordId].ToString(); } } } }
/// <summary> /// Saves the Diganostic + Imaging details, and adds related record /// </summary> /// <param name="specimenAccession"></param> private void SaveDiagnostic(SpecimenAccession specimenAccession) { int patientId = (int)specimenAccession[SpecimenAccession.PatientId]; int specimenAccessionId = (int)specimenAccession[SpecimenAccession.SpecimenAccessionId]; // save Diagnostics int?diagnosticId = null; if (!string.IsNullOrEmpty(DiagnosticIdField.Value)) { diagnosticId = int.Parse(DiagnosticIdField.Value); } Diagnostic diagnostic = new Diagnostic(); // load diagnostic if (diagnosticId.HasValue) { diagnostic.Get(diagnosticId.Value); } // set required fields else { diagnostic[Diagnostic.PatientId] = patientId; diagnostic[Diagnostic.DxDate] = specimenAccession[SpecimenAccession.CollectDate]; diagnostic[Diagnostic.DxDateText] = specimenAccession[SpecimenAccession.CollectDateText]; diagnostic[Diagnostic.DxTarget] = "Prostate"; } // update type??? diagnostic[Diagnostic.DxType] = AccessionProcName.Text; // set bizo value CICHelper.SetBOValues(Tissue_DiagnosticFields.Controls, diagnostic, patientId); // save diagnostic diagnostic.Save(); // on update, link to SA if (diagnostic.PrimaryKeyHasValue) { diagnosticId = (int)diagnostic[Diagnostic.DiagnosticId]; DiagnosticIdField.Value = diagnosticId.Value.ToString(); // create related Diagnostic RelatedRecord relatedDiagnostic = CreateRelatedDiagnostic(specimenAccessionId, diagnosticId.Value); // get ImageFindingProstate ImageFindingProstate finding = BusinessObject.GetByParent <ImageFindingProstate>(diagnosticId.Value).FirstOrDefault(); // else, create if (finding == null) { finding = new ImageFindingProstate(); finding[ImageFindingProstate.DiagnosticId] = diagnosticId.Value; } // set fields CICHelper.SetBOValues(Tissue_DiagnosticFields.Controls, finding, diagnosticId.Value); // update finding.Save(); } }
/// <summary> /// Creates a related record for the Diagnostic (if one doesn't exist) to the current Specimen Accession /// </summary> /// <param name="specimenAccessionId"></param> /// <param name="diagnosticId"></param> /// <returns></returns> private RelatedRecord CreateRelatedDiagnostic(int specimenAccessionId, int diagnosticId) { // get existing realted record RelatedRecord relatedRecord = GetDiagnosticRelatedRecord(specimenAccessionId, diagnosticId); // else, create if (relatedRecord == null) { relatedRecord = RelatedRecordController.CreateRelatedRecord("SpecimenAccessions", specimenAccessionId, "Diagnostics", diagnosticId); } return(relatedRecord); }
/// <summary> /// /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void DeleteClick(object sender, EventArgs e) { if (!string.IsNullOrEmpty(ToxicityIdField.Value)) { // delete main tox record Toxicity biz = new Toxicity(); biz.Delete(int.Parse(ToxicityIdField.Value)); RegisterUpdateScript(true); // delete associated record RelatedRecord relatedRecord = new RelatedRecord(); relatedRecord.Delete(int.Parse(RelatedRecordId.Value)); } }
/// <summary> /// Delete the link between the Diagnostic and Spcimen Accession /// </summary> /// <param name="specimenAccessionId"></param> /// <param name="diagnosticId"></param> private void DeleteRelatedDiagnostic(int specimenAccessionId, int diagnosticId) { // delete related record RelatedRecord relatedRecord = GetDiagnosticRelatedRecord(specimenAccessionId, diagnosticId); if (relatedRecord != null) { new RelatedRecord().Delete((int)relatedRecord[RelatedRecord.RelatedRecordId]); } // delete diagnostic ??? Diagnostic diagnostic = new Diagnostic(); diagnostic.Delete(diagnosticId); DiagnosticIdField.Value = ""; }
/// <summary> /// /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void DeleteClick(object sender, EventArgs e) { if (!string.IsNullOrEmpty(SurveyIdField.Value)) { Survey biz = new Survey(); biz.Delete(int.Parse(SurveyIdField.Value)); SurveyIdField.Value = string.Empty; SurveyPluginControl.SetSurveyIdField(SurveyIdField.Value); // delete associated record RelatedRecord relatedRecord = new RelatedRecord(); relatedRecord.Delete(int.Parse(RelatedRecordId.Value)); // register update script RegisterUpdateScript(true); } }
/// <summary> /// Delete the data entry form and close /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void DeleteClick(object sender, EventArgs e) { var biz = BusinessObjectFactory.BuildBusinessObject(QueryTableName); if (!string.IsNullOrEmpty(PriKeyField.Value)) { biz.Delete(int.Parse(PriKeyField.Value)); // update hidden field PriKeyField.Value = string.Empty; // delete associated record if (!string.IsNullOrEmpty(RelatedRecordId.Value)) { RelatedRecord relatedRecord = new RelatedRecord(); relatedRecord.Delete(int.Parse(RelatedRecordId.Value)); RelatedRecordId.Value = string.Empty; // register update script RegisterUpdateScript(true); } } BuildUnplannedEvent(); }
/// <summary> /// /// </summary> /// <param name="fieldsAndValues"></param> /// <returns></returns> private static bool HasRelatedRecords(Dictionary <string, object> fieldsAndValues) { return(RelatedRecord.Exists <RelatedRecord>(fieldsAndValues)); }
/// <summary> /// /// </summary> /// <param name="fieldsAndValues"></param> /// <returns></returns> private static IEnumerable <RelatedRecord> GetRelatedRecords(Dictionary <string, object> fieldsAndValues) { return(RelatedRecord.GetByFields <RelatedRecord>(fieldsAndValues)); }
/// <summary> /// /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void SaveClick(object sender, EventArgs e) { // Save Diagnostic Record Diagnostic biz = new Diagnostic(); RelatedRecord relatedDiagnostic = new RelatedRecord(); // load existing record if (!IsNew) { biz.Get(DiagnosticId); // load exisiting related diagnostic (if any) var relatedDiagnostics = Caisis.Controller.RelatedRecordController.GetRelatedRecords(biz.TableName, DiagnosticId, biz.TableName); if (relatedDiagnostics.Count() > 0) { // load related diagnostic relatedDiagnostic = relatedDiagnostics.First(); } } // set biz fields from control fields CICHelper.SetBOValues(this.Controls, biz, (int.Parse(BaseDecryptedPatientId))); // special cases, manual setting of biz fields // handle baseline logic if (ImgBaseline.Checked) { // use total num from baseline panel biz[Diagnostic.ImgBaseline] = ImgBaseline.Value; // !!! baseline total number will be stored in new tumors biz[Diagnostic.DxNumNewTumors] = DxTotalNumTumorsBaseline.Value; //biz[Diagnostic.DxTotalNumTumors] = string.Empty; } else { // use total num from non baseline panel biz[Diagnostic.ImgBaseline] = ImgBaseline.Value; biz[Diagnostic.DxTotalNumTumors] = DxTotalNumTumorsFollowUp.Value; } // set tracer field biz[Diagnostic.DxTracer] = TracerUptake.Value; // finally save diagnostic and child findings biz.Save(); int diagnosticId = (int)biz[Diagnostic.DiagnosticId]; // Save DxImageFindings this.SaveDxImaging(diagnosticId); // important, related record must be created after update // SPECIAL CASE: for current diagnostic create related record for capturing compared to scan for follow up if (PrevScans.SelectedIndex > -1 && !string.IsNullOrEmpty(PrevScans.SelectedValue)) { int relatedDiagnosticId = int.Parse(PrevScans.SelectedValue); // if no realted record created, insert if (relatedDiagnostic.IsEmpty) { relatedDiagnostic = Caisis.Controller.RelatedRecordController.CreateRelatedRecord(biz.TableName, diagnosticId, biz.TableName, relatedDiagnosticId); } // otherwise update diagnostic id in exising record else { // if current related diag id != current diag id, update table if (relatedDiagnostic[RelatedRecord.DestPrimaryKey].ToString() != relatedDiagnosticId.ToString()) { relatedDiagnostic[RelatedRecord.DestPrimaryKey] = relatedDiagnosticId; relatedDiagnostic.Save(); } } } // if no value selected, delete existing RELATED record (if any) else if (!relatedDiagnostic.IsEmpty) { int relatedRecordId = (int)relatedDiagnostic[relatedDiagnostic.PrimaryKeyName]; relatedDiagnostic.Delete(relatedRecordId); } // Re-populate form with new request ReloadPage(diagnosticId.ToString()); }
public static InvalidRelationshipTypeException SetMessageItems(RelatedRecord relatedRecord) { string messageTemplate = "The following association type is not valid for the '{0}' worksheet: '{1}'"; throw new InvalidRelationshipTypeException(String.Format(messageTemplate, relatedRecord.SrcWorksheetName, relatedRecord.Relationship.Type)); }
private void Save() { // required string sourceTable = SourceTables.SelectedValue; string destTable = DestTableName; int? destPriKey = null; Dictionary <string, Dictionary <int, string> > tablesRecordsAndKeys = new Dictionary <string, Dictionary <int, string> >(); tablesRecordsAndKeys.Add(sourceTable, new Dictionary <int, string>()); var recordsAndKeys = tablesRecordsAndKeys[sourceTable]; // determine if using actual records or eform if (IsActualRecord) { destPriKey = int.Parse(DestTablePrimaryKey); } foreach (RepeaterItem item in TableRecordsRptr.Items) { // get related record if (if it exists) HiddenField srcTableKeyField = item.FindControl("SrcTablePriKey") as HiddenField; HiddenField relatedRecordIdField = item.FindControl("RelatedRecordId") as HiddenField; // get dest key (should always exist) int srcPriKey = int.Parse(srcTableKeyField.Value); // get existing related record (if exists) int?relatedRecordId = null; if (!string.IsNullOrEmpty(relatedRecordIdField.Value)) { relatedRecordId = int.Parse(relatedRecordIdField.Value); } // iterate relation strengths and insert/update/delete relation (if applicable) bool doDelete = true; // mark inital strength for update/insert/delete, empty recordsAndKeys[srcPriKey] = string.Empty; foreach (int relationStrength in RelationStrengths) { RadioButton relationRadio = item.FindControl("Relation_Radio_" + relationStrength) as RadioButton; if (relationRadio.Checked) { // once an item is checked, no need to delete doDelete = false; // mark updated relation recordsAndKeys[srcPriKey] = relationStrength.ToString(); // if record exists (updated strength) if (relatedRecordId.HasValue) { RelatedRecord biz = new RelatedRecord(); biz.Get(relatedRecordId.Value); biz[RelatedRecord.RelationStrength] = relationStrength; biz.Save(); } // if there is a destination, update else if (destPriKey.HasValue) { RelatedRecord biz = RelatedRecordController.CreateRelatedRecord(RelatedRecordController.SOURCE_SYSTEM, sourceTable, srcPriKey, destTable, destPriKey.Value, relationStrength, true); } else if (IsEform) { // handled by update map } // only 1 checked radio per row break; } } // if no items have been checked, remove related record if (doDelete) { // delete real relation if (relatedRecordId.HasValue) { RelatedRecord biz = new RelatedRecord(); biz.Delete(relatedRecordId.Value); // update keys relatedRecordId = null; relatedRecordIdField.Value = string.Empty; } // delete eform reation else if (IsEform) { // handled by update map } } } // for eforms, insert/update/delete relationships if (IsEform) { // udpate xml XmlDocument eformXML = GetEformXml(); rc.UpdateEformRelatedRecords(eformXML, DestTableName, EformRecordId, tablesRecordsAndKeys); // update record EForm biz = new EForm(); biz.Get(int.Parse(EformId)); biz[EForm.EFormXML] = eformXML.OuterXml; biz.Save(); } // Register update script if (!string.IsNullOrEmpty(RelatedClientId))// && sourceTable == SrcTableName) { var relationStrengths = tablesRecordsAndKeys.SelectMany(a => a.Value.Select(b => b.Value)).Where(a => !string.IsNullOrEmpty(a)); string clientRelationArray = "[" + string.Join(",", relationStrengths.ToArray()) + "]"; Page.ClientScript.RegisterStartupScript(this.GetType(), "refreshAndCloseRelatedRecords", "refreshAndCloseRelatedRecords('" + RelatedClientId + "', " + clientRelationArray + ");", true); } else { Page.ClientScript.RegisterStartupScript(this.GetType(), "refreshAndCloseRelatedRecords", "refreshAndCloseRelatedRecords();", true); } }