Skip to content

Commit

Permalink
issue #3242 - update $everything to use ResourcesConfigAdapter
Browse files Browse the repository at this point in the history
1. add the FHIRVersionParam to the OperationContext
2. use that with a ResourcesConfigAdapter to get the list of applicable
resource types in EverythingOperation.getDefaultIncludedResourceTypes

Signed-off-by: Lee Surprenant <lmsurpre@us.ibm.com>
  • Loading branch information
lmsurpre committed Mar 9, 2022
1 parent a3a4ded commit 7bc561c
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 20 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* (C) Copyright IBM Corp. 2017, 2021
* (C) Copyright IBM Corp. 2017, 2022
*
* SPDX-License-Identifier: Apache-2.0
*/
Expand Down Expand Up @@ -84,6 +84,11 @@ public enum Type { SYSTEM, RESOURCE_TYPE, INSTANCE }
*/
public static final String PROPNAME_RESPONSE_PARAMETERS = "RESPONSE_PARAMETERS";

/**
* The FHIRVersionParam for this invocation
*/
public static final String PROPNAME_FHIR_VERSION = "FHIR_VERSION";

private final Type type;
private final String code;
private Map<String, Object> properties = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2623,6 +2623,7 @@ private void setOperationContextProperties(FHIROperationContext operationContext
operationContext.setProperty(FHIROperationContext.PROPNAME_REQUEST_BASE_URI, getRequestBaseUri(resourceTypeName));
operationContext.setProperty(FHIROperationContext.PROPNAME_REQUEST_PARAMETERS, requestParameters);
operationContext.setProperty(FHIROperationContext.PROPNAME_PERSISTENCE_IMPL, persistence);
operationContext.setProperty(FHIROperationContext.PROPNAME_FHIR_VERSION, fhirVersion);
}

@Override
Expand Down Expand Up @@ -2991,6 +2992,7 @@ public void validateInteraction(Interaction interaction, String resourceType) th
List<String> interactions = null;
boolean resourceValid = true;

// TODO: replace with ResourcesConfigAdapter
// Retrieve the interaction configuration
try {
StringBuilder defaultInteractionsConfigPath = new StringBuilder(FHIRConfiguration.PROPERTY_RESOURCES).append("/Resource/")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,11 @@
import com.ibm.fhir.config.FHIRConfigHelper;
import com.ibm.fhir.config.FHIRConfiguration;
import com.ibm.fhir.config.FHIRRequestContext;
import com.ibm.fhir.config.Interaction;
import com.ibm.fhir.config.PropertyGroup;
import com.ibm.fhir.config.ResourcesConfigAdapter;
import com.ibm.fhir.core.FHIRConstants;
import com.ibm.fhir.core.FHIRVersionParam;
import com.ibm.fhir.core.HTTPHandlingPreference;
import com.ibm.fhir.exception.FHIROperationException;
import com.ibm.fhir.model.resource.Bundle;
Expand Down Expand Up @@ -225,7 +228,8 @@ protected Parameters doInvoke(FHIROperationContext operationContext, Class<? ext

List<String> defaultResourceTypes = new ArrayList<String>(0);
try {
defaultResourceTypes = getDefaultIncludedResourceTypes(resourceHelper);
FHIRVersionParam fhirVersion = (FHIRVersionParam) operationContext.getProperty(FHIROperationContext.PROPNAME_FHIR_VERSION);
defaultResourceTypes = getDefaultIncludedResourceTypes(resourceHelper, fhirVersion);
} catch (FHIRSearchException e) {
throw new Error("There has been an error retrieving the list of included resources of the $everything operation.", e);
}
Expand Down Expand Up @@ -395,22 +399,14 @@ protected List<String> getOverridenIncludedResourceTypes(Parameters parameters,
* @return the list of patient subresources that will be included in the $everything operation
* @throws FHIRSearchException
*/
private List<String> getDefaultIncludedResourceTypes(FHIRResourceHelpers resourceHelper) throws FHIRSearchException {
private List<String> getDefaultIncludedResourceTypes(FHIRResourceHelpers resourceHelper, FHIRVersionParam fhirVersion) throws FHIRSearchException {
List<String> resourceTypes = new ArrayList<>(compartmentHelper.getCompartmentResourceTypes(PATIENT));

try {
List<String> supportedResourceTypes = FHIRConfigHelper.getSupportedResourceTypes();
// Examine the resource types to see if they support SEARCH
for (String resourceType: supportedResourceTypes) {
try {
resourceHelper.validateInteraction(FHIRResourceHelpers.Interaction.SEARCH, resourceType);
} catch (FHIROperationException e) {
if (LOG.isLoggable(Level.FINE)) {
LOG.fine("Removing resourceType " + resourceType + " because it does not support SEARCH");
}
supportedResourceTypes.remove(resourceType);
}
}
PropertyGroup resourcesGroup = FHIRConfigHelper.getPropertyGroup(FHIRConfiguration.PROPERTY_RESOURCES);
ResourcesConfigAdapter configAdapter = new ResourcesConfigAdapter(resourcesGroup, fhirVersion);
Set<String> supportedResourceTypes = configAdapter.getSupportedResourceTypes(Interaction.SEARCH);

if (LOG.isLoggable(Level.FINE)) {
StringBuilder resourceTypeBuilder = new StringBuilder(supportedResourceTypes.size());
resourceTypeBuilder.append("supportedResourceTypes are: ");
Expand All @@ -421,12 +417,10 @@ private List<String> getDefaultIncludedResourceTypes(FHIRResourceHelpers resourc
LOG.fine(resourceTypeBuilder.toString());
}

// Need to have this if check to support server config files that do not specify resources
if (!supportedResourceTypes.isEmpty()) {
resourceTypes.retainAll(supportedResourceTypes);
}
resourceTypes.retainAll(supportedResourceTypes);
} catch (Exception e) {
FHIRSearchException exceptionWithIssue = new FHIRSearchException("There has been an error retrieving the list of supported resource types of the $everything operation.", e);
FHIRSearchException exceptionWithIssue = new FHIRSearchException("There has been an error retrieving the list "
+ "of supported resource types for the $everything operation.", e);
LOG.throwing(this.getClass().getName(), "doInvoke", exceptionWithIssue);
throw exceptionWithIssue;
}
Expand Down

0 comments on commit 7bc561c

Please sign in to comment.