-
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 #3390 - whole-system interactions use config
* Introduce the ResourceTypeName enum in fhir-core and ResourcesConfigAdapter in fhir-config * Use ResourcesConfigAdapter from whole-system search, whole-system history, $everything, and $export I also started on #3319 - system-search now supports multiple instances of the `_type` parameter Signed-off-by: Lee Surprenant <lmsurpre@us.ibm.com>
- Loading branch information
Showing
30 changed files
with
1,725 additions
and
323 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
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); | ||
} | ||
} |
114 changes: 114 additions & 0 deletions
114
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,114 @@ | ||
/* | ||
* (C) Copyright IBM Corp. 2022 | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
package com.ibm.fhir.config; | ||
|
||
import java.util.Arrays; | ||
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 java.util.stream.Collectors; | ||
|
||
import com.ibm.fhir.config.PropertyGroup.PropertyEntry; | ||
import com.ibm.fhir.core.ResourceTypeName; | ||
|
||
/** | ||
* An abstraction for the ibm-fhir-server fhirServer/resources property group | ||
*/ | ||
public class ResourcesConfigAdapter { | ||
public static final Logger log = Logger.getLogger(ResourcesConfigAdapter.class.getName()); | ||
|
||
public static final Set<String> ALL_CONCRETE_TYPES = Arrays.stream(ResourceTypeName.values()) | ||
.filter(v -> v != ResourceTypeName.RESOURCE && v != ResourceTypeName.DOMAIN_RESOURCE) | ||
.map(v -> v.value()) | ||
.collect(Collectors.toSet()); | ||
|
||
private final Set<String> supportedTypes; | ||
private final Map<Interaction, Set<String>> typesByInteraction = new HashMap<>(); | ||
|
||
public ResourcesConfigAdapter(PropertyGroup resourcesConfig) throws Exception { | ||
supportedTypes = computeSupportedResourceTypes(resourcesConfig); | ||
|
||
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 concrete supported resource types | ||
* @throws Exception | ||
*/ | ||
public Set<String> getSupportedResourceTypes() { | ||
return supportedTypes; | ||
} | ||
|
||
/** | ||
* @return an immutable, non-null set of concrete resource types that are configured for the given interaction | ||
*/ | ||
public Set<String> getSupportedResourceTypes(Interaction interaction) { | ||
return typesByInteraction.get(interaction); | ||
} | ||
|
||
/** | ||
* Construct the list of concrete supported resource types from the passed configuration | ||
* | ||
* @param resourcesConfig | ||
* @return | ||
* @throws Exception | ||
*/ | ||
private Set<String> computeSupportedResourceTypes(PropertyGroup resourcesConfig) throws Exception { | ||
if (resourcesConfig == null || resourcesConfig.getBooleanProperty("open", true)) { | ||
return ALL_CONCRETE_TYPES; | ||
} | ||
|
||
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 (ALL_CONCRETE_TYPES.contains(name)) { | ||
result.add(name); | ||
} else if (log.isLoggable(Level.FINE)) { | ||
log.fine("Configured resource type '" + name + "' is not valid."); | ||
} | ||
} | ||
|
||
return Collections.unmodifiableSet(result); | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
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,39 @@ | ||
/* | ||
* (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 jakarta.json.Json; | ||
import jakarta.json.JsonObject; | ||
|
||
public class ResourcesConfigAdapterTest { | ||
@Test | ||
public void testGetSupportedResourceTypes() throws Exception { | ||
JsonObject json = Json.createObjectBuilder().build(); | ||
PropertyGroup pg = new PropertyGroup(json); | ||
ResourcesConfigAdapter resourcesConfigAdapter = new ResourcesConfigAdapter(pg); | ||
|
||
Set<String> supportedResourceTypes = resourcesConfigAdapter.getSupportedResourceTypes(); | ||
assertEquals(supportedResourceTypes.size(), 141); | ||
|
||
System.out.println(supportedResourceTypes); | ||
|
||
for (Interaction interaction : Interaction.values()) { | ||
supportedResourceTypes = resourcesConfigAdapter.getSupportedResourceTypes(interaction); | ||
assertEquals(supportedResourceTypes.size(), 141); | ||
} | ||
} | ||
} |
Oops, something went wrong.