Example #1
0
    /// <summary>
    /// Controls display of menu containing links to child forms. Menu links driven by PatientDataEntryConfig.xml file.
    /// </summary>
    /// <param name="formNode">XmlNode containing meta data on current form</param>
    /// <param name="primaryKeyValue">Integer with current record id if it exists</param>
    public void Show(string tableName, int primaryKeyValue, int parentKeyValue, bool isParentRecordLocked)//, List<String> tableNames)
    {
        //_currentNode = menuNode;
        _currentTableName     = GetActiveTableName(tableName);
        _primaryKeyValue      = primaryKeyValue;
        _parentKeyValue       = parentKeyValue;
        _isParentRecordLocked = isParentRecordLocked;

        // the sequence in which these methods fire is important!
        GetRelevantTableNames();
        GetOtherTableNames();
//        SetOtherLinks();
        SetRelevantLinks();


        if (subFormNavigation.Text != "" || relevantFormNavigation.Text != "")
        {
            this.Visible = true;

            //if (_childRecordsExist)
            //{   // show populated icon
            //    SubDataIcon.Src = "../../Images/icon_hasDetails.gif";
            //}
        }

        // show related records
        RelatedRecordController rc = new RelatedRecordController();
        var relatableTables        = rc.GetRelatedRecordUtilityTables();

        if (relatableTables.Contains(tableName) && _primaryKeyValue > 0)
        {
            this.Visible = true;
            ShowRelatedRecords(tableName, primaryKeyValue, parentKeyValue, isParentRecordLocked);
        }
    }
Example #2
0
        /// <summary>
        /// Adds a related column
        /// </summary>
        /// <param name="dataSource"></param>
        /// <param name="tableName"></param>
        /// <param name="toxicityId"></param>
        /// <returns></returns>
        private DataView GetRelatedRecords(DataTable dataSource, string tableName, int?toxicityId)
        {
            // get required fields
            string priKeyName = BOL.BusinessObject.GetPrimaryKeyName(tableName);

            // add related record column
            if (!dataSource.Columns.Contains("RelatedRecordId"))
            {
                dataSource.Columns.Add(new DataColumn("RelatedRecordId", typeof(int), null));
            }
            if (toxicityId.HasValue)
            {
                var relatedTableRecords = RelatedRecordController.GetRelatedRecordsByDest(tableName, "Toxicities", toxicityId.Value);
                // find related records by row
                var foundRelatedRecords = from row in dataSource.AsEnumerable()
                                          let rowPriKey = row[priKeyName].ToString()
                                                          let relatedRecord = relatedTableRecords.FirstOrDefault(r => r[RelatedRecord.SrcPrimaryKey].ToString() == rowPriKey)
                                                                              where relatedRecord != null
                                                                              select new
                {
                    Row             = row,
                    RelatedRecordId = (int)relatedRecord["RelatedRecordId"]
                };
                foreach (var record in foundRelatedRecords)
                {
                    DataRow row = record.Row;
                    row["RelatedRecordId"] = record.RelatedRecordId;
                }
            }
            return(dataSource.DefaultView);
        }
Example #3
0
        /// <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);
        }
        protected void RebindOnDelete(object sender, GridViewDeletedEventArgs e)
        {
            // cleanup related record
            int patientProtocolId = int.Parse(PatientProtocolId);

            string labTestId = e.Keys[LabTest.LabTestId].ToString();

            if (!string.IsNullOrEmpty(labTestId))
            {
                RelatedRecordController.DeleteRelatedRecord(new LabTest().TableName, int.Parse(labTestId), new PatientProtocol().TableLabel, patientProtocolId);
            }
            // rebuild interface
            BuildLabTestsInterface();
        }
Example #5
0
        /// <summary>
        /// Get the related Diagnostic record
        /// </summary>
        /// <param name="specimenAccessionId"></param>
        /// <returns></returns>
        private Diagnostic GetRealtedDiagnostic(int specimenAccessionId)
        {
            // TODO: what if accession is realted to multiple diagnostics ???
            IEnumerable <RelatedRecord> diagnosticRelatedRecords = GetDiagnosticRelatedRecords(specimenAccessionId);
            IEnumerable <Diagnostic>    relatedDiagnostics       = RelatedRecordController.GetRelatedBizObjects <Diagnostic>(diagnosticRelatedRecords, RelatedRecord.DestTableName, RelatedRecord.DestPrimaryKey);
            Diagnostic diagnostic = relatedDiagnostics.FirstOrDefault();

            // validation: patient
            if (diagnostic != null && !diagnostic.IsEmpty)
            {
                int patientId = int.Parse(BaseDecryptedPatientId);
                if ((int)diagnostic[Diagnostic.PatientId] == patientId)
                {
                    return(diagnostic);
                }
            }
            return(null);
        }
Example #6
0
    /// <summary>
    /// For the given table, show a list of related records as well as available tables to relate
    /// </summary>
    /// <param name="tableName"></param>
    /// <param name="primaryKeyValue"></param>
    /// <param name="parentKeyValue"></param>
    /// <param name="isParentRecordLocked"></param>
    protected void ShowRelatedRecords(string tableName, int primaryKeyValue, int parentKeyValue, bool isParentRecordLocked)
    {
        if (primaryKeyValue > 0)
        {
            // set url
            RelatedRecordsFrame.Attributes["src"] = "RelatedRecords.aspx?destTableName=" + tableName + "&destTablePrimaryKey=" + primaryKeyValue;
            // build existing related records
            DataView relatedRecords = RelatedRecordController.GetRelatedRecords(tableName, primaryKeyValue).AsDataView <RelatedRecord>();

            RelatedRecordsRptr.DataSource = relatedRecords;
            RelatedRecordsRptr.DataBind();

            // show related records container
            RelatedRecordsContainer.Visible = true;
            RelatedRecordsPopup.Visible     = true;
        }
        else
        {
            RelatedRecordsContainer.Visible = false;
            RelatedRecordsPopup.Visible     = false;
        }
    }
        /// <summary>
        /// Inserts/Updates the relevent labs and gleason calculations
        /// </summary>
        private void SaveDetails()
        {
            // validation
            int             patientId         = int.Parse(BaseDecryptedPatientId);
            int             patientProtocolId = int.Parse(PatientProtocolId);
            PatientProtocol patientProtocol   = new PatientProtocol();

            patientProtocol.Get(patientProtocolId);

            var relatedLabTestIds = GetRelatedLabTestIds(patientProtocolId);

            // LABS (PSA)
            List <KeyValuePair <float, DateTime> > labResults = new List <KeyValuePair <float, DateTime> >();

            foreach (GridViewRow row in LabTestsGrid.Rows)
            {
                LabTest lab = new LabTest();
                // load???
                string currentRowId = LabTestsGrid.DataKeys[row.RowIndex][LabTest.LabTestId].ToString();
                if (!string.IsNullOrEmpty(currentRowId))
                {
                    lab.Get(int.Parse(currentRowId));
                }
                CICHelper.SetBOValues(row.Controls, lab, patientId);
                if (!lab.IsEmpty)
                {
                    lab[LabTest.LabTest_Field] = "PSA";
                    lab.Save();
                    int labTestId = (int)lab[LabTest.LabTestId];

                    string labTest        = lab[LabTest.LabTest_Field].ToString();
                    string labResult      = lab[LabTest.LabResult].ToString();
                    float  labResultValue = 0;
                    if (labTest.Equals("PSA") && float.TryParse(labResult, out labResultValue) && !lab.IsNull(LabTest.LabDate))
                    {
                        DateTime labDate = (DateTime)lab[LabTest.LabDate];
                        labResults.Add(new KeyValuePair <float, DateTime>(labResultValue, labDate));
                    }

                    // RELATED RECORD
                    if (!relatedLabTestIds.Contains(labTestId))
                    {
                        BOL.RelatedRecord relatedRecord = RelatedRecordController.CreateRelatedRecord(lab, patientProtocol);
                    }
                }
            }

            // calculate doubling time
            float?dbl = ProtocolMgmtUtil.GetPatientPSADoublingTime(patientProtocolId);

            if (dbl.HasValue)
            {
                PSADoublingTime.Text = dbl + " Months";
            }
            else
            {
                PSADoublingTime.Text = "N/A";
            }

            // GLEASON SCORE
            Pathology pathology = PatientProtocolController.GetPatientRelatedRecords <Pathology>(patientProtocolId).FirstOrDefault();

            // create new patholgy if needed
            if (!string.IsNullOrEmpty(PathSpecimenType.Value))
            {
                bool   isNewPathology = pathology == null;
                string pathType       = PathSpecimenType.Value;
                if (isNewPathology)
                {
                    pathology = new Pathology();
                    pathology[Pathology.PatientId] = patientId;
                }
                pathology[Pathology.PathSpecimenType] = pathType;
                pathology[Pathology.PathDateText]     = PathDateText.Value;
                pathology[Pathology.PathDate]         = PathDate.Value;
                pathology.Save();
                if (!pathology.IsEmpty)
                {
                    int pathologyId = (int)pathology[Pathology.PathologyId];
                    // create child record
                    if (pathType.Equals("Prostatectomy"))
                    {
                        var prostatectomy = BusinessObject.GetByParent <ProstatectomyPathology>(pathologyId).FirstOrDefault();
                        if (prostatectomy == null)
                        {
                            prostatectomy = new ProstatectomyPathology();
                            prostatectomy[ProstatectomyPathology.PathologyId] = pathologyId;
                        }
                        prostatectomy[ProstatectomyPathology.PathGG1] = GleasonField1.Text;
                        prostatectomy[ProstatectomyPathology.PathGG2] = GleasonField2.Text;
                        prostatectomy[ProstatectomyPathology.PathGGS] = GleasonFieldSum.Text;
                        prostatectomy.Save();
                    }
                    else if (pathType == "Biopsy")
                    {
                        var biopsy = BusinessObject.GetByParent <BiopsyProstatePathology>(pathologyId).FirstOrDefault();
                        if (biopsy == null)
                        {
                            biopsy = new BiopsyProstatePathology();
                            biopsy[BiopsyProstatePathology.PathologyId] = pathologyId;
                        }
                        biopsy[BiopsyProstatePathology.PathGG1] = GleasonField1.Text;
                        biopsy[BiopsyProstatePathology.PathGG2] = GleasonField2.Text;
                        biopsy[BiopsyProstatePathology.PathGGS] = GleasonFieldSum.Text;
                        biopsy.Save();
                    }
                    // create related record if needed
                    if (isNewPathology)
                    {
                        BOL.RelatedRecord relatedPathology = RelatedRecordController.CreateRelatedRecord(pathology, patientProtocol);
                    }
                }
            }

            // rebuild UI
            BuildInterfaces();
        }
Example #8
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);
            }
        }
Example #9
0
        /// <summary>
        /// Gets a list of Diagnostic related records
        /// </summary>
        /// <param name="specimenAccessionId"></param>
        /// <returns></returns>
        private IEnumerable <RelatedRecord> GetDiagnosticRelatedRecords(int specimenAccessionId)
        {
            IEnumerable <RelatedRecord> diagnosticRelatedRecords = RelatedRecordController.GetRelatedRecords("SpecimenAccessions", specimenAccessionId, "Diagnostics");

            return(diagnosticRelatedRecords);
        }