示例#1
0
        /// <summary>
        /// Returns the Pathology(key) AND (ProstatectomyPathology OR BiopsyProstatePathology)(value) used for calulating gleason score.
        /// </summary>
        /// <param name="patientProtocolId"></param>
        /// <returns></returns>
        public static KeyValuePair <Pathology, BusinessObject>?GetGleasonPathologyRecord(int patientProtocolId)
        {
            Pathology path = PatientProtocolController.GetPatientRelatedRecords <Pathology>(patientProtocolId).FirstOrDefault();

            if (path != null && !path.IsEmpty)
            {
                int    pathologyId = (int)path[Pathology.PathologyId];
                string pathType    = path[Pathology.PathSpecimenType].ToString();
                // manuall set child records
                if (pathType.Equals("Prostatectomy"))
                {
                    var prostatectomy = BusinessObject.GetByParent <ProstatectomyPathology>(pathologyId).FirstOrDefault();
                    if (prostatectomy != null)
                    {
                        return(new KeyValuePair <Pathology, BusinessObject>(path, prostatectomy));
                    }
                }
                else if (pathType == "Biopsy")
                {
                    var biopsy = BusinessObject.GetByParent <BiopsyProstatePathology>(pathologyId).FirstOrDefault();
                    if (biopsy != null)
                    {
                        return(new KeyValuePair <Pathology, BusinessObject>(path, biopsy));
                    }
                }
            }
            return(null);
        }
示例#2
0
        public static float?GetPatientPSADoublingTime(int patientProtocolId)
        {
            float parseResult = 0;
            var   labs        = PatientProtocolController.GetPatientRelatedRecords <LabTest>(patientProtocolId);
            var   psaByDate   = from lab in labs
                                where lab[LabTest.LabTest_Field].ToString() == "PSA"
                                where !lab.IsNull(LabTest.LabDate) && !lab.IsNull(LabTest.LabResult)
                                let labResult = lab[LabTest.LabResult].ToString()
                                                let labDate = (DateTime)lab[LabTest.LabDate]
                                                              where float.TryParse(labResult, out parseResult)
                                                              select new KeyValuePair <float, DateTime>(parseResult, labDate);

            return(GetPSADoublingTime(psaByDate));
        }
        private void BuildLabTestsInterface()
        {
            int patientProtocolId = int.Parse(PatientProtocolId);
            var labs       = PatientProtocolController.GetPatientRelatedRecords <LabTest>(patientProtocolId);
            var sortedLabs = from lab in labs
                             where lab[LabTest.LabTest_Field].ToString() == "PSA"
                             orderby(lab.IsNull(LabTest.LabTestId) ? int.MaxValue : (int)lab[LabTest.LabTestId]) ascending
                             orderby(lab.IsNull(LabTest.LabDate)?DateTime.MaxValue : (DateTime)lab[LabTest.LabDate]) ascending
                             select lab;

            var labsView = sortedLabs.AsDataView <LabTest>();

            LabTestsGrid.BlankRows        = 15;
            LabTestsGrid.VisibleBlankRows = labsView.Count > 2 ? 2 : 4;
            LabTestsGrid.DataSource       = labsView;
            LabTestsGrid.DataBind();

            // run inital calculation
            CalculatePSADoublingTime();
        }
        /// <summary>
        /// Return a list of LabTest Ids related to the current PatientProtocol
        /// </summary>
        /// <param name="patientProtocolId"></param>
        /// <returns></returns>
        private IEnumerable <int> GetRelatedLabTestIds(int patientProtocolId)
        {
            var relatedLabs = PatientProtocolController.GetPatientRelatedRecords(patientProtocolId, "LabTests");

            return(relatedLabs.Select(b => int.Parse(b[RelatedRecord.SrcPrimaryKey].ToString())));
        }
        /// <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();
        }