public static string BuildHqlQuery <T>(QueryCriteria queryCriteria) { StringBuilder hqlQuery = new StringBuilder(1024); hqlQuery.AppendFormat(" FROM {0} ", typeof(T).Name); bool whereClauseAdded = false; foreach (KeyValuePair <DicomTagPath, string> criteria in queryCriteria) { if (criteria.Value.Length > 0) { QueryablePropertyInfo property = QueryableProperties <Study> .GetProperty(criteria.Key); if (property == null || property.IsHigherLevelUnique || property.PostFilterOnly) { continue; } string hqlCriteria = ConvertCriteria(criteria.Value, property); if (hqlCriteria.Length == 0) { continue; } if (whereClauseAdded) { hqlQuery.AppendFormat(" AND "); } else { hqlQuery.AppendFormat("WHERE "); whereClauseAdded = true; } hqlQuery.AppendFormat("({0})", hqlCriteria); } } return(hqlQuery.ToString()); }
private DicomAttributeCollection GetResult(T candidate) { DicomAttributeCollection result = new DicomAttributeCollection(); string specificCharacterSet = _getSpecificCharacterSetDelegate(candidate); if (!String.IsNullOrEmpty(specificCharacterSet)) { result.SpecificCharacterSet = specificCharacterSet; result[DicomTags.SpecificCharacterSet].SetStringValue(specificCharacterSet); } result.ValidateVrLengths = false; result.ValidateVrValues = false; foreach (QueryablePropertyInfo property in QueryableProperties <T> .GetProperties()) { string criteria = _queryCriteria[property.Path]; bool includeResult = property.IsUnique || property.IsHigherLevelUnique || criteria != null; if (!includeResult) { continue; } object propertyValue = property.ReturnProperty.GetValue(candidate, null); string[] testValues = Convert.ToStringArray(propertyValue, property.ReturnPropertyConverter); if (criteria == null) { criteria = ""; } bool isModalitiesInStudy = property.Path.Equals(DicomTags.ModalitiesInStudy); bool containsWildcards = ContainsWildcardCharacters(criteria); //special case, we post-filter modalities in study when it contains wildcards b/c the hql query won't //always produce exactly the right results. This will never happen anyway. bool query = !String.IsNullOrEmpty(criteria) && ((!property.IsHigherLevelUnique && property.PostFilterOnly) || (isModalitiesInStudy && containsWildcards)); if (query) { string[] criteriaValues; if (property.AllowListMatching) { criteriaValues = DicomStringHelper.GetStringArray(criteria); } else { criteriaValues = new string[] { criteria } }; //When something doesn't match, the candidate is not a match, and the result is filtered out. if (!AnyMatch(property, criteriaValues, testValues)) { return(null); } } string resultValue = DicomStringHelper.GetDicomStringArray(testValues); AddValueToResult(property.Path, resultValue, result); } return(result); }