-
Notifications
You must be signed in to change notification settings - Fork 161
issues 3242 and 3265 - scope search-system and search-history for fhirVersion #3268
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
0b11970
issue #3242 - introduce defaultFhirVersion config property
lmsurpre 9710705
issue #3265 - checkType throws instead of logging for abstract types
lmsurpre 44841c9
issue #3242 - scope search-system and search-history for fhirVersion
lmsurpre 2430a86
issue #3242 - update $everything to use ResourcesConfigAdapter
lmsurpre 053f2ea
issue #3242 - address review feedback
lmsurpre c4d5ef9
issue #3242 - get fhirVersion from Content-Type for create/update
lmsurpre 7790091
resolve TODO about PlanDefinition and ActivityDefintion
lmsurpre 1496f69
Address more review comments
lmsurpre File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
40 changes: 40 additions & 0 deletions
40
fhir-config/src/main/java/com/ibm/fhir/config/Interaction.java
This file contains hidden or 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,40 @@ | ||
| /* | ||
| * (C) Copyright IBM Corp. 2022 | ||
| * | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
| package com.ibm.fhir.config; | ||
|
|
||
| /** | ||
| * Interaction constants to the allowed values of the | ||
| * fhirServer/resources/[resourceType]/interactions config property | ||
| */ | ||
| 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); | ||
| } | ||
| } | ||
130 changes: 130 additions & 0 deletions
130
fhir-config/src/main/java/com/ibm/fhir/config/ResourcesConfigAdapter.java
This file contains hidden or 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,130 @@ | ||
| /* | ||
| * (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.Map.Entry; | ||
| 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; | ||
|
|
||
| /** | ||
| * Public constructor | ||
| * | ||
| * @param resourcesConfig a PropertyGroup instance for the fhirServer/resources property group | ||
| * @param fhirVersion a FHIRVersionParam with the fhirVersion to use for computing the applicable resource types | ||
| * @throws Exception | ||
| */ | ||
| public ResourcesConfigAdapter(PropertyGroup resourcesConfig, FHIRVersionParam fhirVersion) throws Exception { | ||
|
lmsurpre marked this conversation as resolved.
|
||
| supportedTypes = computeSupportedResourceTypes(resourcesConfig, fhirVersion); | ||
| typesByInteraction = computeTypesByInteraction(resourcesConfig); | ||
| } | ||
|
|
||
| /** | ||
| * @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); | ||
|
|
||
| Set<String> result; | ||
| if (resourcesConfig == null || resourcesConfig.getBooleanProperty("open", true)) { | ||
| result = applicableTypes; | ||
| } else { | ||
| 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) || | ||
| ResourceTypeHelper.getAbstractResourceTypeNames().contains(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); | ||
| } | ||
|
|
||
| // note that this private method depends on the member supportedTypes having already been computed | ||
| private Map<Interaction, Set<String>> computeTypesByInteraction(PropertyGroup resourcesConfig) throws Exception { | ||
| Map<Interaction, Set<String>> typeMap = new HashMap<>(); | ||
| if (resourcesConfig == null) { | ||
| for (Interaction interaction : Interaction.values()) { | ||
| typeMap.put(interaction, supportedTypes); | ||
| } | ||
| } else { | ||
| 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()) { | ||
| typeMap.computeIfAbsent(interaction, k -> new LinkedHashSet<>()).add(resourceType); | ||
| } | ||
| continue; | ||
| } | ||
|
|
||
| for (String interactionString : interactions) { | ||
| Interaction interaction = Interaction.from(interactionString); | ||
| typeMap.computeIfAbsent(interaction, k -> new LinkedHashSet<>()).add(resourceType); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| Map<Interaction, Set<String>> finalMap = new HashMap<>(); | ||
| for (Entry<Interaction, Set<String>> entry : typeMap.entrySet()) { | ||
| finalMap.put(entry.getKey(), Collections.unmodifiableSet(entry.getValue())); | ||
| } | ||
| return Collections.unmodifiableMap(finalMap); | ||
| } | ||
| } | ||
53 changes: 53 additions & 0 deletions
53
fhir-config/src/test/java/com/ibm/fhir/config/test/ResourcesConfigAdapterTest.java
This file contains hidden or 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); | ||
| } | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.