public override IEnumerable <BusinessObject> Save() { // validation var inputs = CICHelper.GetCaisisInputControls(this); bool valid = CICHelper.InputControlsHaveValue(inputs); if (!valid) { return(new BusinessObject[0]); } LabTest lab = new LabTest(); // update if (!string.IsNullOrEmpty(LabTestIdField.Value)) { lab.Get(int.Parse(LabTestIdField.Value)); } // insert else { lab[BOL.LabTest.LabTest_Field] = "PSA"; lab[BOL.LabTest.LabUnits] = "ng/ml"; } CICHelper.SetBOValues(this.Controls, lab, base.patientId); // get special stamp lab.AppendToUserName(GetEnteredBySuffix()); lab.Save(); // update key LabTestIdField.Value = lab[BOL.LabTest.LabTestId] + ""; if (lab.PrimaryKeyHasValue) { return new BusinessObject[] { lab } } ; else { return(new BusinessObject[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(); }