Skip to content

Commit

Permalink
issue #1351 - Update config with resources group for search parameters
Browse files Browse the repository at this point in the history
Signed-off-by: Troy Biesterfeld <tbieste@us.ibm.com>
  • Loading branch information
tbieste committed Oct 15, 2020
1 parent 9ec0c79 commit 8398b13
Show file tree
Hide file tree
Showing 10 changed files with 235 additions and 115 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,13 @@ public class FHIRConfiguration {
public static final String PROPERTY_CAPABILITY_STATEMENT_CACHE = "fhirServer/core/capabilityStatementCacheTimeout";
public static final String PROPERTY_EXTENDED_CODEABLE_CONCEPT_VALIDATION = "fhirServer/core/extendedCodeableConceptValidation";

public static final String PROPERTY_SEARCH_PARAMETER_FILTER = "fhirServer/searchParameterFilter";

// Resources properties
public static final String PROPERTY_RESOURCES = "fhirServer/resources";
public static final String PROPERTY_FIELD_RESOURCES_INCLUDE_OMITTED = "includeOmittedResourceTypes";
public static final String PROPERTY_FIELD_RESOURCES_SEARCH_PARAMETERS = "searchParameters";
public static final String PROPERTY_FIELD_RESOURCES_SEARCH_PARAMETER_URL = "url";
public static final String PROPERTY_FIELD_RESOURCES_SEARCH_PARAMETER_REQUIRED = "required";

// Auth and security properties
public static final String PROPERTY_SECURITY_CORS = "fhirServer/security/cors";
public static final String PROPERTY_SECURITY_BASIC_ENABLED = "fhirServer/security/basic/enabled";
Expand Down
100 changes: 60 additions & 40 deletions fhir-search/src/main/java/com/ibm/fhir/search/util/SearchUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -258,9 +258,9 @@ private static Collection<SearchParameter> filterSearchParameters(Map<String, Li
String resourceType, Collection<SearchParameter> unfilteredSearchParameters) {
List<SearchParameter> results = new ArrayList<>();

// First, retrieve the filter rule (list of SP names to be included) for the specified resource type.
// First, retrieve the filter rule (list of SP urls to be included) for the specified resource type.
// We know that the SearchParameters in the unfiltered list are all associated with this resource type,
// so we can use this same "name list" for each Search Parameter in the unfiltered list.
// so we can use this same "url list" for each Search Parameter in the unfiltered list.
List<String> includedSPs = filterRules.get(resourceType);

if (includedSPs == null) {
Expand All @@ -271,7 +271,7 @@ private static Collection<SearchParameter> filterSearchParameters(Map<String, Li
// If we found a non-empty list of search parameter names to filter on,
// then do the filtering. Otherwise, we're just going to return an empty list.
if (includedSPs != null && !includedSPs.isEmpty()) {
// If "*" is contained in the included SP names, then we can just return the unfiltered list
// If "*" is contained in the included SP urls, then we can just return the unfiltered list
// now, since everything in the list will be included anyway.
if (includedSPs.contains(SearchConstants.WILDCARD_FILTER)) {
return unfilteredSearchParameters;
Expand All @@ -282,11 +282,10 @@ private static Collection<SearchParameter> filterSearchParameters(Map<String, Li
else {
for (SearchParameter sp : unfilteredSearchParameters) {

String name = sp.getCode().getValue();
if (includedSPs.contains(name)) {
String url = sp.getUrl().getValue();
if (includedSPs.contains(url)) {
results.add(sp);
}

}
}
}
Expand All @@ -296,51 +295,72 @@ private static Collection<SearchParameter> filterSearchParameters(Map<String, Li

/**
* Retrieves the search parameter filtering rules for the current tenant.
*
* @throws Exception
* @return map of resource types to allowed search parameters URLs,
* and may include '*' for resource type or search parameter URL.
* @throws Exception an exception
*/
@SuppressWarnings("unchecked")
private static Map<String, List<String>> getFilterRules() throws Exception {
Map<String, List<String>> result = new HashMap<>();

// Retrieve the "searchParameterFilter" config property group.
PropertyGroup spFilter = FHIRConfigHelper.getPropertyGroup(FHIRConfiguration.PROPERTY_SEARCH_PARAMETER_FILTER);
List<PropertyEntry> ruleEntries = null;
if (spFilter != null) {
ruleEntries = spFilter.getProperties();
}

// If we have a non-empty set of filter rules, then walk through them and populate our map.
if (ruleEntries != null && !ruleEntries.isEmpty()) {
for (PropertyEntry ruleEntry : ruleEntries) {
String resourceType = ruleEntry.getName();

// Make sure the value is a List<String>.
if (ruleEntry.getValue() instanceof List<?>) {
for (Object listMember : (List<?>) ruleEntry.getValue()) {
if (!(listMember instanceof String)) {
boolean includeOmittedRsrcTypes = true;

// Retrieve the "resources" config property group.
PropertyGroup rsrcsGroup = FHIRConfigHelper.getPropertyGroup(FHIRConfiguration.PROPERTY_RESOURCES);
if (rsrcsGroup != null) {
List<PropertyEntry> rsrcsEntries = rsrcsGroup.getProperties();
if (rsrcsEntries != null && !rsrcsEntries.isEmpty()) {
for (PropertyEntry rsrcsEntry : rsrcsEntries) {

// Check special property for including omitted resource types
if (FHIRConfiguration.PROPERTY_FIELD_RESOURCES_INCLUDE_OMITTED.equals(rsrcsEntry.getName())) {
if (rsrcsEntry.getValue() instanceof Boolean) {
includeOmittedRsrcTypes = (Boolean) rsrcsEntry.getValue();
}
else {
throw SearchExceptionUtil.buildNewIllegalStateException();
}
}

// Add the rule entry to our map, keyed by resource type.
List<String> stringList = (List<String>) ruleEntry.getValue();
result.put(resourceType, stringList);
} else {
throw SearchExceptionUtil.buildNewIllegalStateException();
else {
String resourceType = rsrcsEntry.getName();
PropertyGroup resourceTypeGroup = (PropertyGroup) rsrcsEntry.getValue();
if (resourceTypeGroup != null) {
List<String> searchParameterUrls = new ArrayList<>();

// Get search parameters
PropertyGroup spGroup = resourceTypeGroup.getPropertyGroup(FHIRConfiguration.PROPERTY_FIELD_RESOURCES_SEARCH_PARAMETERS);
if (spGroup != null) {
List<PropertyEntry> spEntries = spGroup.getProperties();
if (spEntries != null && !spEntries.isEmpty()) {
for (PropertyEntry spEntry : spEntries) {

PropertyGroup spValueGroup = (PropertyGroup) spEntry.getValue();
if (spValueGroup != null) {
String url = spValueGroup.getStringProperty(FHIRConfiguration.PROPERTY_FIELD_RESOURCES_SEARCH_PARAMETER_URL);
if (url == null) {
throw SearchExceptionUtil.buildNewIllegalStateException();
}
searchParameterUrls.add(url);
}
}
}
}
else {
searchParameterUrls.add(SearchConstants.WILDCARD);
}
result.put(resourceType, searchParameterUrls);
}
}
}
}
} else {
// The current tenant doesn't have any filter rules defined, so
// we'll just fabricate one that includes all search parameters:
// <pre>{ "*": ["*"] }</pre>
List<String> list = new ArrayList<>();
list.add(SearchConstants.WILDCARD);
result.put(SearchConstants.WILDCARD, list);
}

if (includeOmittedRsrcTypes) {
// All other resource types include all search parameters
result.put(SearchConstants.WILDCARD, Collections.singletonList(SearchConstants.WILDCARD));
}

return result;
}

/**
* Returns the SearchParameter map (keyed by resource type) for the specified
* tenant-id, or null if there are no SearchParameters for the tenant.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
{
"__comment": "FHIR Server configuration",
"fhirServer": {
"_comment": "Just hiding this property because 'include-all' should be the default",
"_searchParameterFilter": {
"*": "*"
}
}
}
Original file line number Diff line number Diff line change
@@ -1,23 +1,41 @@
{
"__comment": "FHIR Server configuration",
"fhirServer": {
"searchParameterFilter": {
"Device": [
"patient",
"organization"
],
"Observation": [
"code"
],
"Patient": [
"active",
"address",
"birthdate",
"name"
],
"*": [
"*"
]
"resources": {
"includeOmittedResourceTypes": true,
"Device": {
"searchParameters": {
"patient": {
"url": "http://hl7.org/fhir/SearchParameter/Device-patient"
},
"organization": {
"url": "http://hl7.org/fhir/SearchParameter/Device-organization"
}
}
},
"Observation": {
"searchParameters": {
"code": {
"url": "http://hl7.org/fhir/SearchParameter/clinical-code"
}
}
},
"Patient": {
"searchParameters": {
"active": {
"url": "http://hl7.org/fhir/SearchParameter/Patient-active"
},
"address": {
"url": "http://hl7.org/fhir/SearchParameter/individual-address"
},
"birthdate": {
"url": "http://hl7.org/fhir/SearchParameter/individual-birthdate"
},
"name": {
"url": "http://hl7.org/fhir/SearchParameter/Patient-name"
}
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
{
"__comment": "FHIR Server configuration",
"fhirServer": {
"_comment": "include all search parameters for all resource types (default)",
"searchParameterFilter": {
"*": ["*"]
}
}
}
Original file line number Diff line number Diff line change
@@ -1,23 +1,41 @@
{
"__comment": "FHIR Server configuration",
"fhirServer": {
"searchParameterFilter": {
"Device": [
"patient",
"organization"
],
"Observation": [
"code"
],
"Patient": [
"active",
"address",
"birthdate",
"name"
],
"*": [
"*"
]
"resources": {
"includeOmittedResourceTypes": true,
"Device": {
"searchParameters": {
"patient": {
"url": "http://hl7.org/fhir/SearchParameter/Device-patient"
},
"organization": {
"url": "http://hl7.org/fhir/SearchParameter/Device-organization"
}
}
},
"Observation": {
"searchParameters": {
"code": {
"url": "http://hl7.org/fhir/SearchParameter/clinical-code"
}
}
},
"Patient": {
"searchParameters": {
"active": {
"url": "http://hl7.org/fhir/SearchParameter/Patient-active"
},
"address": {
"url": "http://hl7.org/fhir/SearchParameter/individual-address"
},
"birthdate": {
"url": "http://hl7.org/fhir/SearchParameter/individual-birthdate"
},
"name": {
"url": "http://hl7.org/fhir/SearchParameter/Patient-name"
}
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,23 +1,41 @@
{
"__comment": "FHIR Server configuration",
"fhirServer": {
"searchParameterFilter": {
"Device": [
"patient",
"organization"
],
"Observation": [
"code"
],
"Patient": [
"active",
"address",
"birthdate",
"name"
],
"*": [
"*"
]
"resources": {
"includeOmittedResourceTypes": true,
"Device": {
"searchParameters": {
"patient": {
"url": "http://hl7.org/fhir/SearchParameter/Device-patient"
},
"organization": {
"url": "http://hl7.org/fhir/SearchParameter/Device-organization"
}
}
},
"Observation": {
"searchParameters": {
"code": {
"url": "http://hl7.org/fhir/SearchParameter/clinical-code"
}
}
},
"Patient": {
"searchParameters": {
"active": {
"url": "http://hl7.org/fhir/SearchParameter/Patient-active"
},
"address": {
"url": "http://hl7.org/fhir/SearchParameter/individual-address"
},
"birthdate": {
"url": "http://hl7.org/fhir/SearchParameter/individual-birthdate"
},
"name": {
"url": "http://hl7.org/fhir/SearchParameter/Patient-name"
}
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
{
"__comment": "FHIR Server configuration",
"fhirServer": {
"_comment": "Just hiding this property because 'include-all' should be the default",
"_searchParameterFilter": {
"*": "*"
}
}
}
Loading

0 comments on commit 8398b13

Please sign in to comment.