/// <summary> /// Update Patient's Study Id and/or warn if already exits. /// </summary> /// <param name="e"></param> protected void UpdateStudyId(CaisisAjaxEventArgs e) { string newStudyId = e.ClientParam; if (PatientPage != null && !string.IsNullOrEmpty(newStudyId) && !string.IsNullOrEmpty(PatientPage.PatientProtocolId)) { // ok to update when study id doesn't exits if (!ProtocolMgmtDa.StudyIdExists(newStudyId, int.Parse(PatientPage.BaseProtocolId))) { int ptProtocolId = int.Parse(PatientPage.PatientProtocolId); PatientProtocol biz = new PatientProtocol(); biz.Get(ptProtocolId); biz[PatientProtocol.PtProtocolStudyId] = newStudyId; biz.Save(); // CREATE STUDY ID IDENTIFIER PatientProtocolController.CreateStudyIdIdentifier(biz); // echo back value to client e.ReturnValue = newStudyId; } // otherwise exists, and warn else { // echo back to client study id exits e.ReturnValue = "The StudyId entered already exits in the system."; } } else { // echo to client there were issues e.ReturnValue = "Please Enter a valid StudyId."; } }
private void DeletePatientProtocol(int patientProtocolId, IEnumerable <int> patientSchemaIds) { PatientProtocol patientProtocol = new PatientProtocol(); foreach (int patientSchemaId in patientSchemaIds) { DeletePatientSchema(patientSchemaId); } patientProtocol.Delete(patientProtocolId); }
protected void UpdateBtn_Click(object sender, EventArgs e) { foreach (int rowIndex in BulkPatientEdit.DirtyRows) { GridViewRow row = BulkPatientEdit.Rows[rowIndex]; var values = CICHelper.GetCaisisInputControlDictionary(row).ToDictionary(a => a.Key, a => a.Value.Value); string patientIdValue = BulkPatientEdit.DataKeys[rowIndex][Patient.PatientId] + ""; int? patientId = null; // update new Patient Patient patient = UpdateRecord <Patient>(patientIdValue, new Dictionary <string, object> { { Patient.PtRace, values[Patient.PtRace] } }); if (patient.PrimaryKeyHasValue) { patientId = (int)patient[Patient.PatientId]; } if (patientId.HasValue) { // update Registration ID identifier string identifierId = BulkPatientEdit.DataKeys[rowIndex][Identifier.IdentifierId] + ""; string registrationID = values[Identifier.Identifier_Field]; if (!string.IsNullOrEmpty(registrationID)) { Identifier localIdentifier = UpdateRecord <Identifier>(identifierId, new Dictionary <string, object> { { Identifier.PatientId, patientId }, { Identifier.IdType, "Registration ID" }, { Identifier.Identifier_Field, registrationID }, }); } // update PatientProtocol string ptProtocolId = BulkPatientEdit.DataKeys[rowIndex][PatientProtocol.PatientProtocolId] + ""; PatientProtocol ptProtocol = UpdateRecord <PatientProtocol>(ptProtocolId, new Dictionary <string, object> { { PatientProtocol.PatientId, patientId }, { PatientProtocol.ProtocolId, protocolId } }); string statusId = BulkPatientEdit.DataKeys[rowIndex][PatientProtocolStatus.PatientProtocolStatusId] + ""; // update Registration Status if (ptProtocol.PrimaryKeyHasValue) { PatientProtocolStatus status = UpdateRecord <PatientProtocolStatus>(statusId, new Dictionary <string, object> { { PatientProtocolStatus.PatientProtocolId, (int)ptProtocol[PatientProtocol.PatientProtocolId] }, { PatientProtocolStatus.PtProtocolStatus, "Registered" }, { PatientProtocolStatus.PtProtocolStatusDate, values[PatientProtocolStatus.PtProtocolStatusDate] }, { PatientProtocolStatus.PtProtocolStatusDateText, values[PatientProtocolStatus.PtProtocolStatusDateText] } }); } } } // rebuild BuildBulkEdit(); // refresh main list Page.ClientScript.RegisterStartupScript(this.GetType(), "reloadParentPage", "if(parent.reloadListAndCalendar) { parent.reloadListAndCalendar(); }", true); }
protected void BuildPatientVisits(object sender, EventArgs e) { if (PatientList.SelectedItem != null && !string.IsNullOrEmpty(PatientList.SelectedItem.Value)) { string dataset = CacheManager.GetDatasetSQL(Session[SessionKey.DatasetId]); int protocolId = int.Parse(BaseProtocolId); int ptProtocolId = int.Parse(PatientList.SelectedValue); PatientProtocol ptProtocol = new PatientProtocol(); ptProtocol.Get(ptProtocolId); int patientId = (int)ptProtocol[PatientProtocol.PatientId]; BuildPatientSchedule(patientId); } }
/// <summary> /// Initalizes public properties used for getting Patient specific ids /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void InitalizeParams(object sender, EventArgs e) { // Patient Protocol and StudyId string queryPatientProtocolId = GetURLValue(QUERY_PATIENT_PROTOCOL_ID_KEY); if (!string.IsNullOrEmpty(queryPatientProtocolId)) { PatientProtocol biz = new PatientProtocol(); biz.Get(int.Parse(queryPatientProtocolId)); patientProtocolId = biz[PatientProtocol.PatientProtocolId].ToString(); patientStudyId = biz[PatientProtocol.PtProtocolStudyId].ToString(); } else if (!string.IsNullOrEmpty(BaseProtocolId) && !string.IsNullOrEmpty(BaseDecryptedPatientId)) { PatientProtocolDa da = new PatientProtocolDa(); DataTable patientProtocolRecords = da.GetPatientProtocol(int.Parse(BaseDecryptedPatientId), int.Parse(BaseProtocolId)); if (patientProtocolRecords.Rows.Count > 0) { patientProtocolId = patientProtocolRecords.Rows[0][PatientProtocol.PatientProtocolId].ToString(); patientStudyId = patientProtocolRecords.Rows[0][PatientProtocol.PtProtocolStudyId].ToString(); } else { patientProtocolId = string.Empty; patientStudyId = string.Empty; } } else { patientProtocolId = string.Empty; patientStudyId = string.Empty; } // Patient Schema if (!string.IsNullOrEmpty(BaseSchemaId) && !string.IsNullOrEmpty(BaseDecryptedPatientId)) { DataTable dt = ProtocolMgmtDa.GetPatientProtocolSchema(int.Parse(BaseSchemaId), int.Parse(BaseDecryptedPatientId)); if (dt.Rows.Count > 0) { patientSchemaId = dt.Rows[0][PatientSchema.PatientSchemaId].ToString(); } else { patientSchemaId = string.Empty; } } else { patientSchemaId = string.Empty; } }
public PatientSpecimenBasePage() : base() { this.Init += (o, e) => { // set study id if (!string.IsNullOrEmpty(PatientProtocolId)) { int ptProtocolId = int.Parse(PatientProtocolId); PatientProtocol biz = new PatientProtocol(); biz.Get(ptProtocolId); patientStudyId = biz[PatientProtocol.PtProtocolStudyId].ToString(); } }; }
protected override void Page_Load(object sender, EventArgs e) { // always load patient protocol record if (!string.IsNullOrEmpty(PatientProtocolId)) { ptProtocol = new PatientProtocol(); ptProtocol.Get(int.Parse(PatientProtocolId)); } if (!Page.IsPostBack) { PopulatePtProtocolNotes(); BindStatus(); BindVisits(); } }
private void BuildVisitItems(int timelineId) { string datasetSQL = CacheManager.GetDatasetSQL(Session[SessionKey.DatasetId]); int protocolId = int.Parse(BaseProtocolId); int ptProtocolId = int.Parse(PatientList.SelectedValue); PatientProtocol ptProtocol = new PatientProtocol(); ptProtocol.Get(ptProtocolId); int patientId = (int)ptProtocol[PatientProtocol.PatientId]; // build a list of visit items, but restrict to direct Patient child tables var patientTables = BOL.BusinessObject.GetChildTableNames("Patients"); DataTable visitItems = ProtocolMgmtDa.GetPatientFullTimeline(protocolId, patientId, datasetSQL, timelineId); var patientChildRecords = visitItems.AsEnumerable().Where(r => patientTables.Contains(r["DestTable"].ToString())); DataView visitDataSource = (patientChildRecords.Count() > 0 ? patientChildRecords.CopyToDataTable() : new DataTable()).DefaultView; PatientVisitItems.DataSource = visitDataSource; PatientVisitItems.DataBind(); }
/// <summary> /// Populates the patient's baseline form /// </summary> private void PopulateBaselineForm() { int patientId = int.Parse(BaseDecryptedPatientId); int ptProtocolId = int.Parse(PatientProtocolId); var dataEntryControls = PageUtil.GetControls <BaseDataEntryControl>(BaselineFormPanel); // load patient Patient patient = new Patient(); patient.Get(patientId); // load patient protocol PatientProtocol ptProtocol = new PatientProtocol(); ptProtocol.Get(ptProtocolId); PatientProtocolController ptProtocolController = new PatientProtocolController(ptProtocolId); DateTime?onStudyDate = ptProtocolController.GetStatusDate(PatientProtocolController.OnStudy); DateTime?screeningFailedDate = ptProtocolController.GetStatusDate(PatientProtocolController.ScreeningFailed); DateTime?screeningPassedDate = ptProtocolController.GetStatusDate(PatientProtocolController.ScreeningPassed); // determine date ranges DateTime?baselineFromDate = null; DateTime?baselineToDate = onStudyDate ?? screeningFailedDate ?? screeningPassedDate; List <ICaisisInputControl> inputs = new List <ICaisisInputControl>(); // populate components foreach (BaseDataEntryControl control in dataEntryControls) { // set date ranges control.BaselineFromDate = baselineFromDate; // todo??? control.BaselineToDate = baselineToDate; control.Populate(); inputs.AddRange(CICHelper.GetCaisisInputControls(control)); } // add required field foreach (var control in inputs.Where(i => i.Required).OfType <WebControl>()) { control.Attributes["data-required"] = "true"; } }
/// <summary> /// /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void DoSave(object sender, EventArgs e) { try { if (ValidateForm()) { // REQUIRED int protocolId = int.Parse(BaseProtocolId); // STEP 1: Get PatientId Patient patient = new Patient(); int ptId = -1; if (CanViewPatientInfo) { if (AddNewPatient.Checked) { patient[Patient.PtFirstName] = NewFirstName.Value; patient[Patient.PtLastName] = NewLastName.Value; patient[Patient.PtMRN] = NewMRN.Value; // If no name or mrn, enter notes to save record patient[Patient.PtNotes] = "Protocol-Patient"; // insert records using controller PatientController ct = new PatientController(); try { // insert new patient InsertNewPatientRecord(patient); } catch (InvalidScreeningException ex) { throw ex; } // if cannot insert patient, already exits, warn user catch (Exception ex) { throw new InvalidScreeningException("Select a new MRN, another patient with the same MRN already exists in the system."); } //if (patient.RecordCount > 0) if (!patient.IsEmpty) { ptId = int.Parse(patient[Patient.PatientId].ToString()); } } // if using existing patient else if (FindExistingPatient.Checked) { if (!string.IsNullOrEmpty(epid.Value)) { ptId = int.Parse(DecrypyValue(epid.Value)); } } } // if cannnot view PatientInfo, insert blinded info else { patient[Patient.PtFirstName] = string.Empty; patient[Patient.PtLastName] = string.Empty; patient[Patient.PtMRN] = string.Empty; patient[Patient.PtNotes] = "Blinded-Protocol-Patient"; // insert new patient InsertNewPatientRecord(patient); //if (patient.RecordCount > 0) if (!patient.IsEmpty) { ptId = int.Parse(patient[Patient.PatientId].ToString()); } } // STEP 2: Create ParticipantID (if needed) if (ptId != -1) { if (!PatientProtocolController.HasParticipantId(protocolId, ptId)) { PatientProtocolController.CreateParticipantIdIdentifier(protocolId, ptId); } } // VALIDATION: ensure non-duplicate PatientProtocol, via insert new patient int?ptProtocolId = null; var pp = BusinessObject.GetByFields <PatientProtocol>( new Dictionary <string, object> { { PatientProtocol.ProtocolId, protocolId }, { PatientProtocol.PatientId, ptId } } ); if (pp.Count() > 0) { ptProtocolId = (int)pp.First()[PatientProtocol.PatientProtocolId]; } // STEP 3: Determine Pass or Fail, and create relevent records // If screening failed, create empty PatientProtocol record to track screening if (ScreeningFailed.Checked) { PatientProtocol ptProtocol = new PatientProtocol(); if (ptProtocolId.HasValue) { ptProtocol.Get(ptProtocolId.Value); } else { ptProtocol[PatientProtocol.PatientId] = ptId; ptProtocol[PatientProtocol.ProtocolId] = protocolId; ptProtocol[PatientProtocol.PtProtocolScreeningId] = PatientProtocolController.GenerateScreeningId(); ptProtocol.Save(); } PatientProtocolStatus status = new PatientProtocolStatus(); status[PatientProtocolStatus.PatientProtocolId] = ptProtocol[PatientProtocol.PatientProtocolId]; status[PatientProtocolStatus.PtProtocolStatus] = PatientProtocolController.ScreeningFailed; DateTime statusDate = DateTime.Today; if (!string.IsNullOrEmpty(ScreeningDate.Value) && DateTime.TryParse(ScreeningDate.Value, out statusDate)) { status[PatientProtocolStatus.PtProtocolStatusDate] = statusDate; status[PatientProtocolStatus.PtProtocolStatusDateText] = statusDate.ToShortDateString(); } else { status[PatientProtocolStatus.PtProtocolStatusDate] = DateTime.Today; status[PatientProtocolStatus.PtProtocolStatusDateText] = DateTime.Today.ToShortDateString(); } status[PatientProtocolStatus.PtProtocolStatusReason] = ReasonFailed.Value; status[PatientProtocolStatus.PtProtocolStatusNotes] = ReasonFailedNotes.Value; status.Save(); } // If screening passed, create necessary records else if (ScreeningPassed.Checked) { // Create PatientProtocol for Patient PatientProtocol ptProtocol = new PatientProtocol(); if (ptProtocolId.HasValue) { ptProtocol.Get(ptProtocolId.Value); bool doUpdate = false; // update/ insert fields if (ptProtocol.IsNull(PatientProtocol.PtProtocolStudyId)) { ptProtocol[PatientProtocol.PtProtocolStudyId] = StudyID.Value; doUpdate = true; } if (ptProtocol.IsNull(PatientProtocol.PtProtocolScreeningId)) { ptProtocol[PatientProtocol.PtProtocolScreeningId] = PatientProtocolController.GenerateScreeningId(); doUpdate = true; } if (doUpdate) { ptProtocol.Save(); } } else { ptProtocol[PatientProtocol.ProtocolId] = protocolId; ptProtocol[PatientProtocol.PatientId] = ptId; ptProtocol[PatientProtocol.PtProtocolScreeningId] = PatientProtocolController.GenerateScreeningId(); ptProtocol[PatientProtocol.PtProtocolStudyId] = StudyID.Value; ptProtocol.Save(); } // CREATE STUDY ID IDENTIFIER PatientProtocolController.CreateStudyIdIdentifier((int)ptProtocol[ptProtocol.PrimaryKeyName]); // Create Registration Record PatientProtocolRegistration registrationRecord = new PatientProtocolRegistration(); registrationRecord[PatientProtocolRegistration.PatientProtocolId] = ptProtocol[PatientProtocol.PatientProtocolId]; registrationRecord[PatientProtocolRegistration.ConsentedTo] = " "; registrationRecord.Save(); PatientProtocolStatus status = new PatientProtocolStatus(); status[PatientProtocolStatus.PatientProtocolId] = ptProtocol[PatientProtocol.PatientProtocolId]; status[PatientProtocolStatus.PtProtocolStatus] = PatientProtocolController.ScreeningPassed; DateTime statusDate = DateTime.Today; if (!string.IsNullOrEmpty(ScreeningDate.Value) && DateTime.TryParse(ScreeningDate.Value, out statusDate)) { status[PatientProtocolStatus.PtProtocolStatusDate] = statusDate; status[PatientProtocolStatus.PtProtocolStatusDateText] = statusDate.ToShortDateString(); } else { status[PatientProtocolStatus.PtProtocolStatusDate] = DateTime.Today; status[PatientProtocolStatus.PtProtocolStatusDateText] = DateTime.Today.ToShortDateString(); } status[PatientProtocolStatus.PtProtocolStatusNotes] = StudyNodes.Value; status.Save(); } // STEP 4: Register Client Script events // Save and Close if (sender == SaveBtn) { Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "saveAndClose", "saveAndClose();", true); } // Save and Load Registration Interface else if (sender == ContinueBtn) { string script = "if(parent.patientAssigned) { parent.patientAssigned('" + protocolId + "','','" + EncryptValue(ptId.ToString()) + "'); }"; Page.ClientScript.RegisterStartupScript(this.GetType(), "OnPatientAssigned", script, true); } ErrorMessage.Text = ""; } } catch (InvalidScreeningException invalidFormException) { ErrorMessage.Text = "Error: " + invalidFormException.Message; } }
private void InsertDimension(object atts, int patientId, SqlTransaction trans) { DataRow dr; if (atts is XmlNode) { dr = this.AttributesToRow(((XmlNode)atts).Attributes); } else { dr = (DataRow)atts; } string dimType = (string)dr["type"]; switch (dimType) { case "Institution": InstitutionDa ida = new InstitutionDa(); int institutionId = ida.GetPrimKey((string)dr["value"]); this._CheckId(institutionId, dimType, dr); PatientInstitutionDa pida = new PatientInstitutionDa(); if (VerifyUnique((pida.GetPatientInstitution(patientId, institutionId, trans)).Tables[0])) { // NEW CODE, insert record though middle tier PatientInstitution ptInstitution = new PatientInstitution(); ptInstitution[PatientInstitution.PatientId] = patientId; ptInstitution[PatientInstitution.InstitutionId] = institutionId; ptInstitution.Save(); // OLD CODE, inserts now handled by middle tier // pida.InsertPatientInstitution(patientId, institutionId, trans); add trans logic after concurrency fully tested- spy 2/21 // pida.InsertPatientInstitution(patientId, institutionId, trans); } break; case "Physician": PhysicianDa pda = new PhysicianDa(); //to get Physician primary key need to pass first and last name in from dataset defined in XML int physicianId = pda.GetPrimKey((string)dr["value"], (string)dr["value2"]); this._CheckId(physicianId, dimType, dr); PatientPhysicianDa ppda = new PatientPhysicianDa(); if (VerifyUnique((ppda.ValidatePatientPhysician(patientId, physicianId)).Tables[0])) { // NEW CODE, insert record though middle tier PatientPhysician ptPhysician = new PatientPhysician(); ptPhysician[PatientPhysician.PatientId] = patientId; ptPhysician[PatientPhysician.PhysicianId] = physicianId; ptPhysician.Save(); // OLD CODE, inserts now handled by middle tier //should be creating Patient Physician biz object and passing object to PatientPhysicianDa //ppda.InsertPatientPhysicianDimension(patientId, physicianId, _sc.GetUserName(), trans); } break; case "Protocol": ProtocolDa protDa = new ProtocolDa(); int protocolId = protDa.GetPrimKey((string)dr["value"]); this._CheckId(protocolId, dimType, dr); PatientProtocolDa ptProtDa = new PatientProtocolDa(); if (VerifyUnique((ptProtDa.ValidatePatientProtocol(patientId, protocolId)).Tables[0])) { // NEW CODE, insert record though middle tier PatientProtocol ptProtocol = new PatientProtocol(); ptProtocol[PatientProtocol.PatientId] = patientId; ptProtocol[PatientProtocol.ProtocolId] = protocolId; ptProtocol.Save(); // OLD CODE, inserts now handled by middle tier //ptProtDa.InsertPatientProtocolDimension(patientId, protocolId, _sc.GetUserName(), trans); } break; case "Disease": DiseaseDa disDa = new DiseaseDa(); int diseaseId = disDa.GetPrimKey((string)dr["value"]); this._CheckId(diseaseId, dimType, dr); PatientDiseaseDa ptDiseaseDa = new PatientDiseaseDa(); if (VerifyUnique((ptDiseaseDa.GetPatientDisease(patientId, diseaseId)).Tables[0])) { // NEW CODE, insert record though middle tier PatientDisease ptDisease = new PatientDisease(); ptDisease[PatientDisease.PatientId] = patientId; ptDisease[PatientDisease.DiseaseId] = diseaseId; ptDisease.Save(); // OLD CODE, inserts now handled by middle tier //ptDiseaseDa.InsertPatientDisease(patientId, diseaseId, trans); } break; } }
/// <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(); }
private void PopulateForm(int?specimenAccessionId) { bool isNewAccession = !specimenAccessionId.HasValue; int patientId = int.Parse(BaseDecryptedPatientId); int ptProtocolId = int.Parse(PatientProtocolId); // set study id PatientProtocol ptProtocol = new PatientProtocol(); if (!string.IsNullOrEmpty(PatientProtocolId)) { ptProtocol.Get(int.Parse(PatientProtocolId)); PtProtocolStudyId.Value = ptProtocol[PatientProtocol.PtProtocolStudyId].ToString(); } // populate SpecimenAccessions SpecimenAccession sa = new SpecimenAccession(); if (specimenAccessionId.HasValue) { sa.Get(specimenAccessionId.Value); base.PopulateForm(sa); // special case: needle PopulateNeedleUIField(sa); // special case: diagnostics for tissue if (QuerySpecimenType == QUERY_TISSUE) // && !string.IsNullOrEmpty(AccessionProcName.Text) && AccessionProcName.Text.StartsWith("Image-Guided", StringComparison.OrdinalIgnoreCase)) { PopulateDiagnostic(specimenAccessionId.Value); } } // populate Specimens grid DataView specimens; // STEP 1: get all accessions of this type, will filter later on specimens = da.GetSpecimenReport(ptProtocolId, null, QuerySpecimenType).DefaultView; var allSpecimentRefNum = specimens.Table.AsEnumerable().Select(r => r[Specimen.SpecimenReferenceNumber].ToString()).Distinct(); // STEP 2: generate an auto-calculated spec ref num for the patient (exclude currently assigned) autoGeneratedSpecimenRefNum.Clear(); // only auto-generate spec # if filtering by type + visit if (!string.IsNullOrEmpty(QuerySpecimenType) && !string.IsNullOrEmpty(QueryVisitType)) { int totalSpecimens = SpecimensGrid.BlankRows + specimens.Count; int start = 1; // find the max currently assigned reference num for (int seqNum = 1; seqNum <= totalSpecimens; seqNum++) { // check if currently assigned, else add to available bucket if (allSpecimentRefNum.Contains(GetSpecimenReferenceNumber(seqNum + ""))) { start += 1; } } // fill auto ref num autoGeneratedSpecimenRefNum.AddRange(Enumerable.Range(start, totalSpecimens).Select(seqNum => GetSpecimenReferenceNumber(seqNum + ""))); } // when no parent record specified, build estimated reference num, but do not popualte with exisiting data if (!specimenAccessionId.HasValue) { specimens.Table.Clear(); } // build restrictions List <string> restrictions = new List <string>(); // restrict to this accession if (specimenAccessionId.HasValue) { restrictions.Add(Specimen.SpecimenAccessionId + " = " + specimenAccessionId.Value); } // restrict to this type if (!string.IsNullOrEmpty(QuerySpecimenType)) { restrictions.Add(Specimen.SpecimenType + " = '" + QuerySpecimenType + "'"); // restrict to visit (requires specimen type) if (!string.IsNullOrEmpty(QueryVisitType)) { string refNumMatch = GetSpecimenReferenceNumber(""); restrictions.Add(Specimen.SpecimenReferenceNumber + " LIKE '" + PageUtil.EscapeSingleQuotesForSql(refNumMatch) + "%'"); } } if (restrictions.Count() > 0) { specimens.RowFilter = string.Join(" AND ", restrictions.ToArray()); specimens = new DataView(specimens.ToTable()); } else { specimens.RowFilter = ""; } // data binding // adjust subType heading DataControlField subTypeColumn = SpecimensGrid.Columns[1]; DataControlField vialTypeColumn = SpecimensGrid.Columns[2]; DataControlField processingMethodColumn = SpecimensGrid.Columns[3]; DataControlField specimenStatusColumn = SpecimensGrid.Columns[6]; if (QuerySpecimenType == QUERY_TISSUE) { // custom visits ?? bool customVisits = BuildSpecimenVisitTypes(QUERY_TISSUE, sa); subTypeColumn.HeaderText = "Sample Type"; // hide columns from UI foreach (DataControlField column in new DataControlField[] { subTypeColumn, subTypeColumn, vialTypeColumn }) { column.HeaderStyle.CssClass = "hidden"; column.ItemStyle.CssClass = "hidden"; } // set selection in parent Tissue_SpecimenSubType.Value = specimens.Count > 0 ? specimens[0][Specimen.SpecimenSubType].ToString() : ""; // blank rows SpecimensGrid.BlankRows = Math.Max(0, 6 - specimens.Count); SpecimensGrid.VisibleBlankRows = 1; if (SpecimensGrid.BlankRows == 0) { AddBtn.Visible = false; } if (specimens.Count != 0) { SpecimensGrid.VisibleBlankRows = 0; } } else if (QuerySpecimenType == QUERY_BLOOD) { // custom visits ?? bool customVisits = BuildSpecimenVisitTypes(QUERY_BLOOD, sa); // static visits if (!customVisits) { // default accession visit AccessionVisit.Value = "A"; AccessionVisit.Enabled = false; } AddBtn.Visible = true; subTypeColumn.HeaderText = "Tube Use"; // hide columns from UI foreach (DataControlField column in new DataControlField[] { processingMethodColumn }) { column.HeaderStyle.CssClass = "hidden"; column.ItemStyle.CssClass = "hidden"; } // update default blood specimens bloodAutoSpecimens = ProtocolMgmtSpecimenController.GetBloodAutoSpecimenIds(base.ProtocolNumber, (int)ptProtocol[PatientProtocol.PatientProtocolId], PtProtocolStudyId.Value, AccessionVisit.Enabled ? AccessionVisit.Value : ""); SpecimensGrid.BlankRows = Math.Max(0, 15 - specimens.Count); SpecimensGrid.VisibleBlankRows = specimens.Count > 0 ? 0 : (bloodAutoSpecimens.Length > 0 ? bloodAutoSpecimens.Length : 3); AddBtn.Visible = SpecimensGrid.BlankRows > 0; } SpecimensGrid.DataSource = specimens; SpecimensGrid.DataBind(); }