// To use a custom database schema with the Database Manager, you must define a custom MyPrepareSearch method // and assign it to the StorageDatabaseManager.PrepareSearch delegate. After doing this, the search fields in the Database Manager //will properly refine any database manager search. The MyPrepareSearch() method gets the search fields specified in the database manager // by calling StorageDatabaseManager.GetDicomQueryParams(). This returns any query parameters specified. // The MyPrepareSearch() method then needs to create a MatchingParameterCollection that corresponds to the specified search. // Note that the database manager search fields correspond to items contained in the patient, study, and series tables only. // There are no search fields that correspond to the image table. // Therefore MyPrepareSearch() only needs to add MyPatient, MyStudy, and MySeries objects to the MatchingParameterList. // For more details, see the "Changing the LEAD Medical Storage Server to use a different database schema" tutorial. private void MyPrepareSearch(MatchingParameterCollection matchingCollection) { DicomQueryParams q = __DbManager.GetDicomQueryParams(); try { MatchingParameterList matchingList = new MatchingParameterList(); MyPatient patient = new MyPatient(); MyStudy study = new MyStudy(); MySeries series = new MySeries(); matchingList.Add(patient); matchingList.Add(study); matchingList.Add(series); matchingCollection.Add(matchingList); study.StudyAccessionNumber = q.AccessionNumber; patient.PatientIdentification = q.PatientId; if (!string.IsNullOrEmpty(q.PatientName.FamilyName)) { patient.PatientName = q.PatientName.FamilyName.TrimEnd('*') + "*"; } if (!string.IsNullOrEmpty(q.PatientName.GivenName)) { patient.PatientName = q.PatientName.GivenName.TrimEnd('*') + "*"; } if (!string.IsNullOrEmpty(q.Modalities)) { series.SeriesModality = q.Modalities.Replace(",", "\\"); } ; if (!string.IsNullOrEmpty(q.SeriesDescription)) { series.SeriesSeriesDescription = q.SeriesDescription.TrimEnd('*') + "*"; } if (!string.IsNullOrEmpty(q.ReferringPhysiciansName.FamilyName)) { study.StudyReferringPhysiciansName = q.ReferringPhysiciansName.FamilyName.TrimEnd('*') + "*"; } ; if (!string.IsNullOrEmpty(q.ReferringPhysiciansName.GivenName)) { study.StudyReferringPhysiciansName = q.ReferringPhysiciansName.GivenName.TrimEnd('*') + "*"; } ; if (q.StudyFromChecked || q.StudyToChecked) { DateRange studyDateRange = new DateRange(); if (q.StudyFromChecked) { studyDateRange.StartDate = q.StudyFromDate; } if (q.StudyToChecked) { studyDateRange.EndDate = q.StudyToDate; } study.StudyStudyDate = studyDateRange; } if (q.StorageDateChecked) { MyInstance instance = new MyInstance(); DateRange dateRange = new DateRange(); DateRangeFilter StorageDateRangeFilter = q.StorageDateRange; string startDate = StorageDateRangeFilter.DateRangeFrom; string endDate = StorageDateRangeFilter.DateRangeTo; if (StorageDateRangeFilter.SelectedDateFilter == DateRangeFilter.RangeFilterType.DateRange) { if (!string.IsNullOrEmpty(startDate)) { dateRange.StartDate = DateTime.Parse(startDate); } if (!string.IsNullOrEmpty(endDate)) { dateRange.EndDate = DateTime.Parse(endDate); } } else if (StorageDateRangeFilter.SelectedDateFilter == DateRangeFilter.RangeFilterType.Months) { DateTime lastMonthsDate = DateTime.Now.SubtractMonths(Convert.ToInt32(StorageDateRangeFilter.LastMonths)); dateRange.StartDate = lastMonthsDate; dateRange.EndDate = DateTime.Now; } else { TimeSpan subtractionDays = new TimeSpan(Convert.ToInt32(StorageDateRangeFilter.LastDays), DateTime.Now.Hour, DateTime.Now.Minute, DateTime.Now.Second, DateTime.Now.Millisecond); dateRange.StartDate = DateTime.Now.Subtract(subtractionDays); dateRange.EndDate = DateTime.Now; } instance.ImageLastStoreDate = dateRange; matchingList.Add(instance); } study.StudyStudyId = q.StudyId; } catch (Exception exception) { throw exception; } finally { // do nothing ; } }
// Returns a DataSet that reflects the existence of PatientID, StudyInstanceUID, SeriesInstanceUID, and SOPInstanceUID // * If the patient does not exist, returns an empty DataSet // * If patient exists but no study returns a DataSet where MyPatientTable has row with PatientID of DicomDataSet // * If patient exists, study exists but no series, returns a DataSet that has PatientID (MyPatientTable), and StudyInstanceUID (MyStudyTable) // * If patient, study, series exist but no Instance, returns a DataSet with PatientID, StudyInstanceUID, and SeriesInstanceUID // * If patinet, study series, instance exist, returns empty dataset private DataSet GetUpdateDataSet ( DicomDataSet ds, bool updateExistentPatient, bool updateExistentStudy, bool updateExistentSeries, bool updateExistentInstances ) { MatchingParameterCollection matchingEntitiesCollection = new MatchingParameterCollection(); MatchingParameterList matchingEntitiesList = new MatchingParameterList(); matchingEntitiesCollection.Add(matchingEntitiesList); MyInstance instance = new MyInstance(); instance.SOPInstanceUID = ds.MyGetStringValue(DicomTag.SOPInstanceUID); bool instanceExists = IsCompositeInstancesExists(instance.SOPInstanceUID); if (instanceExists) { matchingEntitiesList.Add(instance); DeleteInstance(matchingEntitiesCollection); matchingEntitiesList.Remove(instance); instanceExists = false; } MyPatient patient = new MyPatient(); patient.PatientIdentification = ds.MyGetStringValue(DicomTag.PatientID); if (null != patient.PatientIdentification) { matchingEntitiesList.Add(patient); } bool patientExist = IsPatientsExists(patient.PatientIdentification); if (updateExistentPatient && patientExist) { // case #1 return(QueryCompositeInstances(matchingEntitiesCollection)); } else if (!patientExist) { // case #2 return(new MyDataSet()); } else { // case #3 // (!updateExistentPatient) && (patientExist) // int ? patientId = GetIntValue(patient.PatientIdentification); MyStudy study = new MyStudy(); study.StudyStudyInstanceUID = ds.MyGetStringValue(DicomTag.StudyInstanceUID); if (null != study.StudyStudyInstanceUID) { matchingEntitiesList.Add(study); } bool studyExists = IsStudyExists(study.StudyStudyInstanceUID); if (updateExistentStudy && studyExists) { return(QueryCompositeInstances(matchingEntitiesCollection)); } else if (!studyExists) { if (matchingEntitiesList.Contains(study)) { matchingEntitiesList.Remove(study); } return(QueryPatients(matchingEntitiesCollection)); } else { MySeries series = new MySeries(); series.SeriesSeriesInstanceUID = ds.MyGetStringValue(DicomTag.SeriesInstanceUID); if (!string.IsNullOrEmpty(series.SeriesSeriesInstanceUID)) { matchingEntitiesList.Add(series); } bool seriesExists = IsSeriesExists(series.SeriesSeriesInstanceUID); if (updateExistentSeries && seriesExists) { return(QueryCompositeInstances(matchingEntitiesCollection)); } else if (!seriesExists) { if (matchingEntitiesList.Contains(series)) { matchingEntitiesList.Remove(series); } return(QueryStudies(matchingEntitiesCollection)); } else { if (!string.IsNullOrEmpty(instance.SOPInstanceUID)) { matchingEntitiesList.Add(instance); } if (updateExistentInstances && instanceExists) { return(QueryCompositeInstances(matchingEntitiesCollection)); } else { MyDataSet.MyPatientTableRow patientRow; MyDataSet.MyStudyTableRow studyRow; MyDataSet.MySeriesTableRow seriesRow; MyDataSet myDataSet = new MyDataSet(); myDataSet.EnforceConstraints = false; myDataSet.MyPatientTable.BeginLoadData(); myDataSet.MyStudyTable.BeginLoadData(); myDataSet.MySeriesTable.BeginLoadData(); myDataSet.MyInstanceTable.BeginLoadData(); patientRow = myDataSet.MyPatientTable.AddMyPatientTableRow(patient.PatientIdentification, string.Empty, DateTime.MinValue, string.Empty, string.Empty); //if (patientId != null) //{ // patientRow.PatientId = patientId.Value; //} //dicomDataSet.MyPatientTable.Rows[0]["PatientId"] = patientId; studyRow = myDataSet.MyStudyTable.AddMyStudyTableRow(patientRow, study.StudyStudyInstanceUID, DateTime.MinValue, string.Empty, string.Empty, string.Empty, string.Empty); seriesRow = myDataSet.MySeriesTable.AddMySeriesTableRow( studyRow, series.SeriesSeriesInstanceUID, string.Empty, 0, string.Empty, DateTime.MinValue, string.Empty); //1. if updateInstance and instance exist not valid (will be in the above IF //2. if updateInstance and instance NOT exist don't fill from Db //3. if NOT updateInstance and instance exist then insert SOP Instance UID //4. if NOT updateInstnace and NOT instance exist then don't fill from Db //case 3 above if (instanceExists) { myDataSet.MyInstanceTable.AddMyInstanceTableRow(seriesRow, instance.SOPInstanceUID, 0, DateTime.MinValue, string.Empty, string.Empty, 0, 0, 0); } myDataSet.AcceptChanges(); myDataSet.MyPatientTable.EndLoadData(); myDataSet.MyStudyTable.EndLoadData(); myDataSet.MySeriesTable.EndLoadData(); myDataSet.MyInstanceTable.EndLoadData(); myDataSet.EnforceConstraints = true; return(myDataSet); } } } } }