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