/// <summary> /// Returns a specific field based on selection Criteria /// NOTE: Selection Criteria can be a string such as "MSH.1.16[2]" or an array of Selection Criteria Elements /// </summary> /// <param name="criteria"></param> /// <returns></returns> public HL7Element Element(SearchCriteria criteria) { // Locate required Segment if (criteria == null || criteria.Segment == null) { return(null); } var segmentElements = AllSegments(criteria.Segment); var targetRow = (criteria.SegmentRepetition > 0) ? criteria.SegmentRepetition - 1 : 0; if (targetRow > segmentElements.Count - 1) { return(new HL7Element()); // not found; } if (!criteria.Field.Enabled) { return(segmentElements[targetRow]); //wants only the full segment } // locate the required field, components or subcomponent var makeHeaderAdjustment = (Constants.HeaderTypes.Any(h => h.Equals(criteria.Segment))); SearchCriteriaElement[] newCriteria = new SearchCriteriaElement[3]; for (int i = 1; i < 4; i++) { // Make Adjustment for MSH newCriteria[i - 1] = (i == 1 && criteria.elements[i].Enabled && makeHeaderAdjustment) ? new SearchCriteriaElement(criteria.elements[i].Position - 1, criteria.elements[i].Repetition, criteria.elements[i].Value, true) : criteria.elements[i]; } return(segmentElements[targetRow].Element(newCriteria)); }
private static SearchCriteria Parse(string criteria) { SearchCriteria result = new SearchCriteria(); if (criteria.Length == 0) { return(result); } var searchCriteriaElements = SearchCriteriaElement.Parse(criteria); for (int i = 0; i < 4; i++) { if (searchCriteriaElements.Length > i) { result.elements[i] = searchCriteriaElements[i]; } else { result.elements[i].Enabled = false; } } if (result.Segment.Length == 0 && !result.elements[0].Skip) { throw new ArgumentException("Segment type or wildcard expected"); } return(result); }
public SearchCriteria(string criteria) { var newcriteria = Parse(criteria); /*this.elements = newcriteria.elements;*/ this.Segment = newcriteria.Segment; this.SegmentRepetition = newcriteria.SegmentRepetition; this.Field = newcriteria.Field; this.Component = newcriteria.Component; this.Subcomponent = newcriteria.Subcomponent; this.elements[0].Skip = newcriteria.elements[0].Skip; }
public static SearchCriteriaElement[] Parse(string criteria) { if (criteria.Length == 0) { return(new SearchCriteriaElement[0]); } var separator = '.'; if (criteria.IndexOf("/") > 0) { separator = '/'; } string[] searchFields = criteria.Split(separator); var result = new SearchCriteriaElement[searchFields.Length]; for (int i = 0; i < searchFields.Length; i++) { result[i] = SearchCriteriaElement.ParseElement(searchFields[i]); } return(result); }