-
Notifications
You must be signed in to change notification settings - Fork 157
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
issue #3242 - scope search-system and search-history for fhirVersion
1. introduce enums and utilities for working with resource type names and fhirVersion values ('4.0' and '4.3') 2. use those to provide a better abstraction for working with the fhir-server-config `fhirServer/resources` property group (ResourcesConfigAdapter) 3. move fhirVersion MIME-type parameter processing into a new JAX-RS RequestFilter FHIRVersionRequestFilter and update tests accordingly 4. update FHIRPersistenceUtil.parseSystemHistoryParameters to take into account the requested fhirVersion and scope the HistoryContext appropriately 5. update SearchUtil.parseQueryParameters to take into account the requested fhirVersion and scope the SearchContext appropriately Signed-off-by: Lee Surprenant <lmsurpre@us.ibm.com>
- Loading branch information
Showing
34 changed files
with
2,146 additions
and
252 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
fhir-config/src/main/java/com/ibm/fhir/config/Interaction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
* (C) Copyright IBM Corp. 2022 | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
package com.ibm.fhir.config; | ||
|
||
public enum Interaction { | ||
CREATE("create"), | ||
DELETE("delete"), | ||
HISTORY("history"), | ||
PATCH("patch"), | ||
READ("read"), | ||
SEARCH("search"), | ||
UPDATE("update"), | ||
VREAD("vread"); | ||
|
||
private final String value; | ||
|
||
Interaction(String value) { | ||
this.value = value; | ||
} | ||
|
||
public String value() { | ||
return value; | ||
} | ||
|
||
public static Interaction from(String value) { | ||
for (Interaction interaction : Interaction.values()) { | ||
if (interaction.value.equals(value)) { | ||
return interaction; | ||
} | ||
} | ||
throw new IllegalArgumentException(value); | ||
} | ||
} |
112 changes: 112 additions & 0 deletions
112
fhir-config/src/main/java/com/ibm/fhir/config/ResourcesConfigAdapter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
/* | ||
* (C) Copyright IBM Corp. 2022 | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
package com.ibm.fhir.config; | ||
|
||
import java.util.Collections; | ||
import java.util.HashMap; | ||
import java.util.LinkedHashSet; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Set; | ||
import java.util.logging.Level; | ||
import java.util.logging.Logger; | ||
|
||
import com.ibm.fhir.config.PropertyGroup.PropertyEntry; | ||
import com.ibm.fhir.core.FHIRVersionParam; | ||
import com.ibm.fhir.core.util.ResourceTypeHelper; | ||
|
||
/** | ||
* An abstraction for the ibm-fhir-server fhirServer/resources property group | ||
*/ | ||
public class ResourcesConfigAdapter { | ||
public static final Logger log = Logger.getLogger(ResourcesConfigAdapter.class.getName()); | ||
|
||
private final Set<String> supportedTypes; | ||
private final Map<Interaction, Set<String>> typesByInteraction = new HashMap<>(); | ||
|
||
public ResourcesConfigAdapter(PropertyGroup resourcesConfig, FHIRVersionParam fhirVersion) throws Exception { | ||
supportedTypes = computeSupportedResourceTypes(resourcesConfig, fhirVersion); | ||
|
||
if (resourcesConfig == null) { | ||
for (Interaction interaction : Interaction.values()) { | ||
typesByInteraction.put(interaction, supportedTypes); | ||
} | ||
return; | ||
} | ||
|
||
for (String resourceType : supportedTypes) { | ||
List<String> interactions = resourcesConfig.getStringListProperty(resourceType + "/" + FHIRConfiguration.PROPERTY_FIELD_RESOURCES_INTERACTIONS); | ||
if (interactions == null) { | ||
interactions = resourcesConfig.getStringListProperty("Resource/" + FHIRConfiguration.PROPERTY_FIELD_RESOURCES_INTERACTIONS); | ||
} | ||
|
||
if (interactions == null) { | ||
for (Interaction interaction : Interaction.values()) { | ||
typesByInteraction.computeIfAbsent(interaction, k -> new LinkedHashSet<>()).add(resourceType); | ||
} | ||
continue; | ||
} | ||
|
||
for (String interactionString : interactions) { | ||
Interaction interaction = Interaction.from(interactionString); | ||
typesByInteraction.computeIfAbsent(interaction, k -> new LinkedHashSet<>()).add(resourceType); | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* @return an immutable, non-null set of supported resource types for the given fhirVersion | ||
* @throws Exception | ||
*/ | ||
public Set<String> getSupportedResourceTypes() { | ||
return supportedTypes; | ||
} | ||
|
||
/** | ||
* @return an immutable, non-null set of resource types that are configured for the given interaction and fhirVersion | ||
*/ | ||
public Set<String> getSupportedResourceTypes(Interaction interaction) { | ||
return typesByInteraction.get(interaction); | ||
} | ||
|
||
/** | ||
* Construct the list of supported resource types from the passed configuration and fhirVersion | ||
* | ||
* @param resourcesConfig | ||
* @param fhirVersion | ||
* @return | ||
* @throws Exception | ||
*/ | ||
private Set<String> computeSupportedResourceTypes(PropertyGroup resourcesConfig, FHIRVersionParam fhirVersion) throws Exception { | ||
Set<String> applicableTypes = ResourceTypeHelper.getResourceTypesFor(fhirVersion); | ||
|
||
if (resourcesConfig == null || resourcesConfig.getBooleanProperty("open", true)) { | ||
return applicableTypes; | ||
} | ||
|
||
Set<String> result = new LinkedHashSet<String>(); | ||
for (PropertyEntry rsrcsEntry : resourcesConfig.getProperties()) { | ||
String name = rsrcsEntry.getName(); | ||
|
||
// Ensure we skip over the special property "open" | ||
// and skip the abstract types Resource and DomainResource | ||
if (FHIRConfiguration.PROPERTY_FIELD_RESOURCES_OPEN.equals(name) || | ||
"Resource".equals(name) || | ||
"DomainResource".equals(name)) { | ||
continue; | ||
} | ||
|
||
if (applicableTypes.contains(name)) { | ||
result.add(name); | ||
} else if (log.isLoggable(Level.FINE)) { | ||
log.fine("Configured resource type '" + name + "' is not valid " | ||
+ "or not applicable for fhirVersion " + fhirVersion.value()); | ||
} | ||
} | ||
|
||
return Collections.unmodifiableSet(result); | ||
} | ||
} |
53 changes: 53 additions & 0 deletions
53
fhir-config/src/test/java/com/ibm/fhir/config/test/ResourcesConfigAdapterTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/* | ||
* (C) Copyright IBM Corp. 2022 | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package com.ibm.fhir.config.test; | ||
|
||
import static org.testng.Assert.assertEquals; | ||
|
||
import java.util.Set; | ||
|
||
import org.testng.annotations.Test; | ||
|
||
import com.ibm.fhir.config.Interaction; | ||
import com.ibm.fhir.config.PropertyGroup; | ||
import com.ibm.fhir.config.ResourcesConfigAdapter; | ||
import com.ibm.fhir.core.FHIRVersionParam; | ||
|
||
import jakarta.json.Json; | ||
import jakarta.json.JsonObject; | ||
|
||
public class ResourcesConfigAdapterTest { | ||
@Test | ||
public void testGetSupportedResourceTypes_r4() throws Exception { | ||
JsonObject json = Json.createObjectBuilder().build(); | ||
PropertyGroup pg = new PropertyGroup(json); | ||
ResourcesConfigAdapter resourcesConfigAdapter = new ResourcesConfigAdapter(pg, FHIRVersionParam.VERSION_40); | ||
|
||
Set<String> supportedResourceTypes = resourcesConfigAdapter.getSupportedResourceTypes(); | ||
assertEquals(supportedResourceTypes.size(), 125); | ||
|
||
for (Interaction interaction : Interaction.values()) { | ||
supportedResourceTypes = resourcesConfigAdapter.getSupportedResourceTypes(interaction); | ||
assertEquals(supportedResourceTypes.size(), 125); | ||
} | ||
} | ||
|
||
@Test | ||
public void testGetSupportedResourceTypes_r4b() throws Exception { | ||
JsonObject json = Json.createObjectBuilder().build(); | ||
PropertyGroup pg = new PropertyGroup(json); | ||
ResourcesConfigAdapter resourcesConfigAdapter = new ResourcesConfigAdapter(pg, FHIRVersionParam.VERSION_43); | ||
|
||
Set<String> supportedResourceTypes = resourcesConfigAdapter.getSupportedResourceTypes(); | ||
assertEquals(supportedResourceTypes.size(), 141); | ||
|
||
for (Interaction interaction : Interaction.values()) { | ||
supportedResourceTypes = resourcesConfigAdapter.getSupportedResourceTypes(interaction); | ||
assertEquals(supportedResourceTypes.size(), 141); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.