private static bool IsWildCardCriteria(string criteria, QueryablePropertyInfo column) { foreach (string excludeVR in WildcardExcludedVRs) { if (0 == String.Compare(excludeVR, column.Path.ValueRepresentation.Name, true)) { return(false); } } return(ContainsWildcardCharacters(criteria)); }
private static string ConvertCriteria(string criteria, QueryablePropertyInfo property) { if (String.IsNullOrEmpty(criteria)) //Universal matching. { return(""); } StandardizeCriteria(ref criteria); if (property.Path.Equals(DicomTags.ModalitiesInStudy)) { return(ConvertModalitiesInStudyCriteria(criteria, property.ColumnName)); } else if (property.Path.ValueRepresentation.Name == "UI") { return(ConvertListOfUidCriteria(criteria, property.ColumnName)); } else if (property.Path.ValueRepresentation.Name == "DA") { return(ConvertDateCriteria(criteria, property.ColumnName)); } else if (property.Path.ValueRepresentation.Name == "TM") { // Unsupported at this time. //ConvertTimeCriteria(...) } else if (property.Path.ValueRepresentation.Name == "DT") { // Unsupported at this time. //ConvertDateTimeCriteria(...) } else if (IsWildCardCriteria(criteria, property)) { return(ConvertWildCardCriteria(criteria, property.ColumnName)); } else { return(ConvertSingleValueCriteria(criteria, property.ColumnName)); } return(""); }
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 static bool AnyMatch(QueryablePropertyInfo property, IEnumerable <string> criteriaValues, IEnumerable <string> testValues) { bool testsPerformed = false; foreach (string criteria in criteriaValues) { if (String.IsNullOrEmpty(criteria)) { continue; } foreach (string test in testValues) { if (String.IsNullOrEmpty(test)) { continue; } if (property.Path.ValueRepresentation == DicomVr.UIvr) //list of uid matching. { testsPerformed = true; //any matching uid is considered a match. if (test.Equals(criteria)) { return(true); } } else if (property.Path.ValueRepresentation == DicomVr.DAvr) { //The raw Patient's Birth Date is in the database, and we could post-filter it, but it's optional, //so we'll leave it for now. The only other date/time value we support querying on is Study Date, //which is done in Hql. return(true); } else if (property.Path.ValueRepresentation == DicomVr.TMvr) { //TODO: to be totally compliant, we should be post-filtering on Study Time (it's in the database, but in raw form). return(true); } else if (property.Path.ValueRepresentation == DicomVr.DTvr) { //We currently don't post-filter on this VR, so it's 'optional' according to Dicom and is a match. return(true); } else if (IsWildCardCriteria(criteria, property)) // wildcard matching. { //Note: wildcard matching is supposed to be case-sensitive (except for PN) according to Dicom. //However, in practice, it's a pain for the user; for example, when searching by Study Description. testsPerformed = true; string criteriaTest = criteria.Replace("*", ".*"); //zero or more characters criteriaTest = criteriaTest.Replace("?", "."); //single character criteriaTest = String.Format("^{0}", criteriaTest); //match at beginning //a match on any of the values is considered a match. if (Regex.IsMatch(test, criteriaTest, RegexOptions.IgnoreCase)) { return(true); } } else { //Note: single value matching is supposed to be case-sensitive (except for PN) according to Dicom. //However, in practice, it's a pain for the user; for example, when searching by Study Description. testsPerformed = true; if (string.Compare(criteria, test, true) == 0) //single value matching. { return(true); } } } } //if no tests were performed, then it's considered a match. return(!testsPerformed); }