Skip to content

Commit

Permalink
issue #3242 - address review feedback
Browse files Browse the repository at this point in the history
mostly javadoc updates and a couple minor refactorings

Signed-off-by: Lee Surprenant <lmsurpre@us.ibm.com>
  • Loading branch information
lmsurpre committed Apr 21, 2022
1 parent 422e20b commit 377fd33
Show file tree
Hide file tree
Showing 7 changed files with 91 additions and 25 deletions.
2 changes: 1 addition & 1 deletion docs/src/pages/guides/FHIRServerUsersGuide.md
Original file line number Diff line number Diff line change
Expand Up @@ -2273,7 +2273,7 @@ This section contains reference information about each of the configuration prop
|`fhirServer/core/capabilitiesUrl`|null|
|`fhirServer/core/externalBaseUrl`|null|
|`fhirServer/core/ifNoneMatchReturnsNotModified`|false|
|`fhirServer/core/defaultFhirVersion`|null|
|`fhirServer/core/defaultFhirVersion`|4.0|
|`fhirServer/core/useImplicitTypeScopingForWholeSystemInteractions`|true|
|`fhirServer/validation/failFast`|false|
|`fhirServer/term/capabilitiesUrl`|null|
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,8 @@ public static Set<String> getSupportedResourceTypes() {
* @throws IllegalStateException if there is an unexpected issue while processing the config
*/
public static Set<String> getSupportedResourceTypes(FHIRVersionParam fhirVersion) {
PropertyGroup rsrcsGroup = FHIRConfigHelper.getPropertyGroup(FHIRConfiguration.PROPERTY_RESOURCES);
ResourcesConfigAdapter configAdapter = new ResourcesConfigAdapter(rsrcsGroup, fhirVersion);
PropertyGroup resourcesGroup = FHIRConfigHelper.getPropertyGroup(FHIRConfiguration.PROPERTY_RESOURCES);
ResourcesConfigAdapter configAdapter = new ResourcesConfigAdapter(resourcesGroup, fhirVersion);
return configAdapter.getSupportedResourceTypes();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
*/
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"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
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;
Expand Down Expand Up @@ -41,6 +42,13 @@ public class ResourcesConfigAdapter {
private boolean isWholeSystemSearchSupported = true;
private boolean isWholeSystemHistorySupported = true;

/**
* 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) {
supportedTypes = computeSupportedResourceTypes(resourcesConfig, fhirVersion);

Expand Down Expand Up @@ -123,27 +131,27 @@ public Set<String> getSupportedResourceTypes(Interaction interaction) {
private Set<String> computeSupportedResourceTypes(PropertyGroup resourcesConfig, FHIRVersionParam fhirVersion) {
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.value().equals(name) ||
DOMAIN_RESOURCE.value().equals(name)) {
continue;
}
Set<String> result;
if (resourcesConfig == null || resourcesConfig.getBooleanProperty(FHIRConfiguration.PROPERTY_FIELD_RESOURCES_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());
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());
}
}
}

Expand All @@ -156,5 +164,39 @@ public boolean isWholeSystemSearchSupported() {

public boolean isWholeSystemHistorySupported() {
return isWholeSystemHistorySupported;

// 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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,12 @@ public enum FHIRVersionParam {

private final String value;

FHIRVersionParam(String value) {
/**
* Private constructor
*
* @param value the fhirVersion value string
*/
private FHIRVersionParam(String value) {
this.value = value;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
public class ResourceTypeHelper {
private static final Set<ResourceTypeName> REMOVED_RESOURCE_TYPES = collectRemovedResourceTypes();
private static final Set<ResourceTypeName> R4B_ONLY_RESOURCE_TYPES = collectR4bOnlyResourceTypes();

private static final Set<ResourceTypeName> ABSTRACT_TYPES = Collections.unmodifiableSet(new HashSet<>(
Arrays.asList(
ResourceTypeName.RESOURCE,
Expand All @@ -48,6 +47,11 @@ public class ResourceTypeHelper {
.map(ResourceTypeName::value)
.collect(Collectors.toList())));

private static final Set<String> ABSTRACT_RESOURCES = Collections.unmodifiableSet(
ABSTRACT_TYPES.stream()
.map(ResourceTypeName::value)
.collect(Collectors.toSet()));

/**
* @param fhirVersion The value of the MIME-type parameter 'fhirVersion' for the current interaction
* (e.g. "4.3" not "4.3.0")
Expand All @@ -71,6 +75,14 @@ public static Set<String> getNewOrBreakingResourceTypeNames() {
return R4B_ONLY_RESOURCES;
}

/**
* @return the set of resource type names that were either introduced in 4.3.0 (e.g. Ingredient) or changed
* in backwards-incompatible ways in the 4.3.0 release (e.g. Evidence and EvidenceVariable)
*/
public static Set<String> getAbstractResourceTypeNames() {
return ABSTRACT_RESOURCES;
}

private static Set<ResourceTypeName> collectRemovedResourceTypes() {
Set<ResourceTypeName> set = new HashSet<>();
set.add(ResourceTypeName.EFFECT_EVIDENCE_SYNTHESIS);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
import com.ibm.fhir.core.FHIRVersionParam;
import com.ibm.fhir.core.util.ResourceTypeHelper;

/**
* Tests for the ResourceTypeHelper class
*/
public class ResourceTypeHelperTest {
@Test
public void testGetNewOrBreakingResourceTypeNames() {
Expand Down

0 comments on commit 377fd33

Please sign in to comment.