public IHttpActionResult GetTemplates( [FromUri(Name = "_id")] int?templateId = null, [FromUri(Name = "name")] string name = null, [FromUri(Name = "_summary")] SummaryType?summary = null) { var uri = HttpContext.Current != null && HttpContext.Current.Request != null ? HttpContext.Current.Request.Url : new Uri(AppSettings.DefaultBaseUrl); var templates = this.tdb.Templates.Where(y => y.TemplateType.ImplementationGuideType == this.implementationGuideType); StructureDefinitionExporter exporter = new StructureDefinitionExporter(this.tdb, uri.Scheme, uri.Authority); if (!CheckPoint.Instance.IsDataAdmin) { User currentUser = CheckPoint.Instance.GetUser(this.tdb); templates = (from t in templates join vtp in this.tdb.ViewTemplatePermissions on t.Id equals vtp.TemplateId where vtp.UserId == currentUser.Id select t); } if (templateId != null) { templates = templates.Where(y => y.Id == templateId); } if (!string.IsNullOrEmpty(name)) { templates = templates.Where(y => y.Name.ToLower().Contains(name.ToLower())); } Bundle bundle = new Bundle() { Type = Bundle.BundleType.BatchResponse }; foreach (var template in templates) { SimpleSchema schema = SimplifiedSchemaContext.GetSimplifiedSchema(HttpContext.Current, template.ImplementationGuideType); schema = schema.GetSchemaFromContext(template.PrimaryContextType); bool isMatch = true; StructureDefinition strucDef = exporter.Convert(template, schema, summary); var fullUrl = string.Format("{0}://{1}/api/FHIR2/StructureDefinition/{2}", this.Request.RequestUri.Scheme, this.Request.RequestUri.Authority, template.Id); // Skip adding the structure definition to the response if a criteria rules it out foreach (var queryParam in this.Request.GetQueryNameValuePairs()) { if (queryParam.Key == "_id" || queryParam.Key == "name" || queryParam.Key == "_format" || queryParam.Key == "_summary") { continue; } if (queryParam.Key.Contains(".")) { throw new NotSupportedException(App_GlobalResources.TrifoliaLang.FHIRSearchCriteriaNotSupported); } var propertyDef = strucDef.GetType().GetProperty(queryParam.Key, System.Reflection.BindingFlags.IgnoreCase | System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance); if (propertyDef == null) { continue; } var value = propertyDef.GetValue(strucDef); var valueString = value != null?value.ToString() : string.Empty; if (valueString != queryParam.Value) { isMatch = false; } } if (isMatch) { bundle.AddResourceEntry(strucDef, fullUrl); } } return(Content <Bundle>(HttpStatusCode.OK, bundle)); }