/// <summary> /// Applies the current filter settings to an esql object query dynamically. /// </summary> /// <param name="filters">The filters.</param> /// <param name="baseQuery">The base object query.</param> /// <returns>ObjectQuery{Ticket}.</returns> public static ObjectQuery<Ticket> ApplyToQuery(this ICollection<UserTicketListFilterColumn> filters, ObjectQuery<Ticket> baseQuery) { var filterColumns = filters.ToList(); if (filterColumns.Count > 0) { var fkeys = new string[filterColumns.Count]; var fParams = new ObjectParameter[filterColumns.Count]; for (var i = 0; i < filterColumns.Count; i++) { string optr; var filterColumn = filterColumns[i]; if (filterColumn.ColumnValue == DBNull.Value) { optr = (filterColumn.UseEqualityComparison.HasValue && !filterColumn.UseEqualityComparison.Value) ? "IS NOT" : "IS"; } else { optr = (filterColumn.UseEqualityComparison.HasValue && !filterColumn.UseEqualityComparison.Value) ? "!=" : "="; } fkeys[i] = string.Format("it.{0} {1} {2}", filterColumn.ColumnName, optr, "@" + filterColumn.ColumnName); //most of the time esql works with whatever type of param value you pass in, but // enums in our collection are serialized to/from json as integers. // Check if enum, and explicitly convert int value to the correct enum value if (filterColumn.ColumnValueType != null && filterColumn.ColumnValueType.IsEnum) { filterColumn.ColumnValue = Enum.Parse(filterColumn.ColumnValueType, filterColumn.ColumnValue.ToString()); } //assigning the type in ctor, then value directly as a param works around issues when the colum val is null. fParams[i] = new ObjectParameter(filterColumn.ColumnName, filterColumn.ColumnValueType) { Value = filterColumn.ColumnValue }; } var wString = string.Join(" and ", fkeys); baseQuery = baseQuery.Where(wString, fParams); } return baseQuery; }
private void OnReceiveStudyLevelQuery(DicomServer server, byte presentationId, DicomMessage message) { var tagList = new List<DicomTag>(); using (var pacsContext = new PacsContext()) { var adapter = (IObjectContextAdapter)pacsContext; var query = new ObjectQuery<Study>("Studies", adapter.ObjectContext); DicomAttributeCollection data = message.DataSet; foreach (DicomAttribute attrib in message.DataSet) { tagList.Add(attrib.Tag); if (!attrib.IsNull) { switch (attrib.Tag.TagValue) { case DicomTags.StudyInstanceUid: { var cond = QueryHelper.SetStringArrayCondition("StudyInstanceUid", (string[])data[DicomTags.StudyInstanceUid].Values); if (!string.IsNullOrEmpty(cond)) { query = query.Where(cond); } } break; case DicomTags.PatientsName: { var cond = QueryHelper.SetStringCondition("PatientName", data[DicomTags.PatientsName].GetString(0, string .Empty)); if (!string.IsNullOrEmpty(cond)) { query = query.Where(cond); } break; } case DicomTags.PatientId: { var cond = QueryHelper.SetStringCondition("PatientId", data[DicomTags.PatientId].GetString(0, string .Empty)); break; } case DicomTags.PatientsBirthDate: { var cond = QueryHelper.SetRangeCondition("PatientBirthDate", data[DicomTags.PatientsBirthDate].GetString (0, string.Empty)); query = query.Where(cond); break; } case DicomTags.PatientsSex: { var cond = QueryHelper.SetStringCondition("PatientSex", data[DicomTags.PatientsSex].GetString(0, string .Empty)); query = query.Where(cond); } break; case DicomTags.StudyDate: { var cond = QueryHelper.SetRangeCondition("StudyDate", data[DicomTags.StudyDate].GetString(0, string .Empty)); query = query.Where(cond); } break; case DicomTags.StudyTime: { var cond = QueryHelper.SetRangeCondition("StudyTime", data[DicomTags.StudyTime].GetString(0, string .Empty)); query = query.Where(cond); } break; case DicomTags.AccessionNumber: { var cond = QueryHelper.SetStringCondition("AccessionNumber", data[DicomTags.AccessionNumber].GetString( 0, string.Empty)); query = query.Where(cond); } break; case DicomTags.StudyId: { var cond = QueryHelper.SetStringCondition("StudyId", data[DicomTags.StudyId].GetString(0, string.Empty)); query = query.Where(cond); } break; case DicomTags.StudyDescription: { var cond = QueryHelper.SetStringCondition("StudyDescription", data[DicomTags.StudyDescription].GetString(0, string.Empty)); query = query.Where(cond); } break; case DicomTags.ReferringPhysiciansName: { var cond = QueryHelper.SetStringCondition("RefPhysician", data[DicomTags.ReferringPhysiciansName] .GetString(0, string.Empty)); query = query.Where(cond); } break; case DicomTags.ModalitiesInStudy: break; default: break; } } } int resultCount = 0; try { foreach (Study study in query) { if (_cancelReceived) { throw new DicomException("DICOM C-Cancel Received"); } resultCount++; if (DicomSetting.Default.MaxQueryResponses != -1 && DicomSetting.Default.MaxQueryResponses < resultCount) { SendBufferedResponses(server, presentationId, message); throw new DicomException("Maximum Configured Query Responses Exceeded: " + resultCount); } var response = new DicomMessage(); PopulateStudy(response, tagList, study); _responseQueue.Enqueue(response); if (_responseQueue.Count >= DicomSetting.Default.BufferedQueryResponses) { SendBufferedResponses(server, presentationId, message); } } SendBufferedResponses(server, presentationId, message); } catch (Exception e) { if (_cancelReceived) { var errorResponse = new DicomMessage(); server.SendCFindResponse(presentationId, message.MessageId, errorResponse, DicomStatuses.Cancel); } return; } } var finalResponse = new DicomMessage(); server.SendCFindResponse(presentationId, message.MessageId, finalResponse, DicomStatuses.Success); }
private void OnReceiveSeriesLevelQuery(DicomServer server, byte presentationId, DicomMessage message) { var tagList = new List<DicomTag>(); using (var pacsContext = new PacsContext()) { var adapter = (IObjectContextAdapter)pacsContext; var query = new ObjectQuery<Series>("Series", adapter.ObjectContext); DicomAttributeCollection data = message.DataSet; foreach (DicomAttribute attrib in data) { tagList.Add(attrib.Tag); if (!attrib.IsNull) { switch (attrib.Tag.TagValue) { case DicomTags.StudyInstanceUid: { var uids = data[DicomTags.StudyInstanceUid].GetString(0, string.Empty); IQueryable<int> studyQuery = from s in pacsContext.Studies where uids.Contains(s.StudyUid) select s.Id; var result = studyQuery.ToArray(); if (result.Length == 0) { server.SendCFindResponse(presentationId, message.MessageId, new DicomMessage(), DicomStatuses.Success); return; } query = query.Where(QueryHelper.SetIntArrayCondition("StudyForeignKey", result)); } break; case DicomTags.SeriesInstanceUid: { var cond = QueryHelper.SetStringArrayCondition("SeriesUid", (string[]) data[DicomTags.SeriesInstanceUid] .Values); query = query.Where(cond); } break; case DicomTags.Modality: { var cond = QueryHelper.SetStringCondition("Modality", data[DicomTags.Modality].GetString(0, string .Empty)); query = query.Where(cond); } break; case DicomTags.SeriesNumber: { var cond = QueryHelper.SetStringCondition("SeriesNumber", data[DicomTags.SeriesNumber].GetString(0, string .Empty)); query = query.Where(cond); } break; case DicomTags.SeriesDescription: { var cond = QueryHelper.SetStringCondition("SeriesDescription", data[DicomTags.StudyDescription].GetString (0, string.Empty)); query = query.Where(cond); } break; case DicomTags.PerformedProcedureStepStartDate: { var cond = QueryHelper.SetRangeCondition("PerformedProcedureStepStartDate", data[ DicomTags .PerformedProcedureStepStartDate] .GetString(0, string.Empty)); query = query.Where(cond); } break; case DicomTags.PerformedProcedureStepStartTime: { var cond = QueryHelper.SetRangeCondition("PerformedProcedureStepStartTime", data[ DicomTags .PerformedProcedureStepStartTime] .GetString(0, string.Empty)); query = query.Where(cond); } break; case DicomTags.RequestAttributesSequence: // todo break; default: break; } } } int resultCount = 0; try { foreach (Series series in query) { if (_cancelReceived) { throw new DicomException("DICOM C-Cancel Received"); } resultCount++; if (DicomSetting.Default.MaxQueryResponses != -1 && DicomSetting.Default.MaxQueryResponses < resultCount) { SendBufferedResponses(server, presentationId, message); throw new DicomException("Maximum Configured Query Responses Exceeded: " + resultCount); } var response = new DicomMessage(); PopulateSeries(message, response, tagList, series); _responseQueue.Enqueue(response); if (_responseQueue.Count >= DicomSetting.Default.BufferedQueryResponses) { SendBufferedResponses(server, presentationId, message); } } SendBufferedResponses(server, presentationId, message); } catch (Exception e) { if (_cancelReceived) { var errorResponse = new DicomMessage(); server.SendCFindResponse(presentationId, message.MessageId, errorResponse, DicomStatuses.Cancel); } } } var finalResponse = new DicomMessage(); server.SendCFindResponse(presentationId, message.MessageId, finalResponse, DicomStatuses.Success); }
private void OnReceivePatientQuery(DicomServer server, byte presentationId, DicomMessage message) { var tagList = new List<DicomTag>(); using (var pacsContext = new PacsContext()) { var adapter = (IObjectContextAdapter)pacsContext; var query = new ObjectQuery<Patient>("Patients", adapter.ObjectContext); DicomAttributeCollection data = message.DataSet; foreach (DicomAttribute attribute in data) { tagList.Add(attribute.Tag); if (!attribute.IsNull) { switch (attribute.Tag.TagValue) { case DicomTags.PatientsName: { var cond = QueryHelper.SetStringCondition("PatientName", data[DicomTags.PatientsName].GetString(0, string.Empty)); query = query.Where(cond); break; } case DicomTags.PatientId: { var cond = QueryHelper.SetStringCondition("PatientId", data[DicomTags.PatientId].GetString(0, string.Empty)); query = query.Where(cond); break; } case DicomTags.IssuerOfPatientId: { var cond = QueryHelper.SetStringCondition("Issuer", data[DicomTags.IssuerOfPatientId] .GetString(0, string.Empty)); } break; case DicomTags.PatientsSex: break; case DicomTags.PatientsBirthDate: { var cond = QueryHelper.SetStringArrayCondition("PatientBirthDate", (string[]) data[DicomTags.PatientsBirthDate] .Values); query = query.Where(cond); } break; default: break; } } } int resultCount = 0; try { foreach (Patient patient in query) { if (_cancelReceived) { throw new DicomException("DICOM C-Cancel Received"); } resultCount++; if (DicomSetting.Default.MaxQueryResponses != -1 && DicomSetting.Default.MaxQueryResponses < resultCount) { SendBufferedResponses(server, presentationId, message); throw new DicomException("Maximum Configured Query Responses Exceeded: " + resultCount); } var response = new DicomMessage(); PopulatePatient(response, tagList, patient); _responseQueue.Enqueue(response); if (_responseQueue.Count >= DicomSetting.Default.BufferedQueryResponses) { SendBufferedResponses(server, presentationId, message); } } SendBufferedResponses(server, presentationId, message); } catch (Exception e) { if (_cancelReceived) { var errorResponse = new DicomMessage(); server.SendCFindResponse(presentationId, message.MessageId, errorResponse, DicomStatuses.Cancel); } } } var finalResponse = new DicomMessage(); server.SendCFindResponse(presentationId, message.MessageId, finalResponse, DicomStatuses.Success); }