Esempio n. 1
0
        /// <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);
            }
        }
Esempio n. 2
0
        /// <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());
        }
Esempio n. 3
0
        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);
            }
        }