Add graphql and _filter support

This commit is contained in:
jamesagnew
2019-08-13 08:18:02 -04:00
parent 447c2531c5
commit 657eaf7758
4 changed files with 37 additions and 17 deletions

View File

@@ -111,6 +111,8 @@ public class FhirServerConfigCommon {
retVal.addSupportedSubscriptionType(Subscription.SubscriptionChannelType.WEBSOCKET); retVal.addSupportedSubscriptionType(Subscription.SubscriptionChannelType.WEBSOCKET);
} }
retVal.setFilterParameterEnabled(HapiProperties.getFilterSearchEnabled());
return retVal; return retVal;
} }

View File

@@ -6,8 +6,8 @@ import ca.uhn.fhir.rest.api.EncodingEnum;
import ca.uhn.fhir.rest.server.ETagSupportEnum; import ca.uhn.fhir.rest.server.ETagSupportEnum;
import com.google.common.annotations.VisibleForTesting; import com.google.common.annotations.VisibleForTesting;
import java.io.InputStream;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.InputStream;
import java.util.Arrays; import java.util.Arrays;
import java.util.Properties; import java.util.Properties;
import java.util.Set; import java.util.Set;
@@ -16,6 +16,7 @@ import java.util.stream.Collectors;
import static org.apache.commons.lang3.StringUtils.*; import static org.apache.commons.lang3.StringUtils.*;
public class HapiProperties { public class HapiProperties {
public static final String BINARY_STORAGE_ENABLED = "binary_storage.enabled";
static final String ALLOW_EXTERNAL_REFERENCES = "allow_external_references"; static final String ALLOW_EXTERNAL_REFERENCES = "allow_external_references";
static final String ALLOW_MULTIPLE_DELETE = "allow_multiple_delete"; static final String ALLOW_MULTIPLE_DELETE = "allow_multiple_delete";
static final String ALLOW_PLACEHOLDER_REFERENCES = "allow_placeholder_references"; static final String ALLOW_PLACEHOLDER_REFERENCES = "allow_placeholder_references";
@@ -51,10 +52,10 @@ public class HapiProperties {
static final String ALLOW_CONTAINS_SEARCHES = "allow_contains_searches"; static final String ALLOW_CONTAINS_SEARCHES = "allow_contains_searches";
static final String ALLOW_OVERRIDE_DEFAULT_SEARCH_PARAMS = "allow_override_default_search_params"; static final String ALLOW_OVERRIDE_DEFAULT_SEARCH_PARAMS = "allow_override_default_search_params";
static final String EMAIL_FROM = "email.from"; static final String EMAIL_FROM = "email.from";
public static final String BINARY_STORAGE_ENABLED = "binary_storage.enabled";
private static final String VALIDATE_REQUESTS_ENABLED = "validation.requests.enabled"; private static final String VALIDATE_REQUESTS_ENABLED = "validation.requests.enabled";
private static final String VALIDATE_RESPONSES_ENABLED = "validation.responses.enabled"; private static final String VALIDATE_RESPONSES_ENABLED = "validation.responses.enabled";
private static final String FILTER_SEARCH_ENABLED = "filter_search.enabled";
private static final String GRAPHQL_ENABLED = "graphql.enabled";
private static Properties properties; private static Properties properties;
/* /*
@@ -77,7 +78,7 @@ public class HapiProperties {
public static Properties getProperties() { public static Properties getProperties() {
if (properties == null) { if (properties == null) {
// Load the configurable properties file // Load the configurable properties file
try (InputStream in = HapiProperties.class.getClassLoader().getResourceAsStream(HAPI_PROPERTIES)){ try (InputStream in = HapiProperties.class.getClassLoader().getResourceAsStream(HAPI_PROPERTIES)) {
HapiProperties.properties = new Properties(); HapiProperties.properties = new Properties();
HapiProperties.properties.load(in); HapiProperties.properties.load(in);
} catch (Exception e) { } catch (Exception e) {
@@ -85,7 +86,7 @@ public class HapiProperties {
} }
Properties overrideProps = loadOverrideProperties(); Properties overrideProps = loadOverrideProperties();
if(overrideProps != null) { if (overrideProps != null) {
properties.putAll(overrideProps); properties.putAll(overrideProps);
} }
} }
@@ -96,17 +97,17 @@ public class HapiProperties {
/** /**
* If a configuration file path is explicitly specified via -Dhapi.properties=<path>, the properties there will * If a configuration file path is explicitly specified via -Dhapi.properties=<path>, the properties there will
* be used to override the entries in the default hapi.properties file (currently under WEB-INF/classes) * be used to override the entries in the default hapi.properties file (currently under WEB-INF/classes)
*
* @return properties loaded from the explicitly specified configuraiton file if there is one, or null otherwise. * @return properties loaded from the explicitly specified configuraiton file if there is one, or null otherwise.
*/ */
private static Properties loadOverrideProperties() { private static Properties loadOverrideProperties() {
String confFile = System.getProperty(HAPI_PROPERTIES); String confFile = System.getProperty(HAPI_PROPERTIES);
if(confFile != null) { if (confFile != null) {
try { try {
Properties props = new Properties(); Properties props = new Properties();
props.load(new FileInputStream(confFile)); props.load(new FileInputStream(confFile));
return props; return props;
} } catch (Exception e) {
catch (Exception e) {
throw new ConfigurationException("Could not load HAPI properties file: " + confFile, e); throw new ConfigurationException("Could not load HAPI properties file: " + confFile, e);
} }
} }
@@ -287,8 +288,8 @@ public class HapiProperties {
public static Set<String> getSupportedResourceTypes() { public static Set<String> getSupportedResourceTypes() {
String[] types = defaultString(getProperty("supported_resource_types")).split(","); String[] types = defaultString(getProperty("supported_resource_types")).split(",");
return Arrays.stream(types) return Arrays.stream(types)
.map(t->trim(t)) .map(t -> trim(t))
.filter(t->isNotBlank(t)) .filter(t -> isNotBlank(t))
.collect(Collectors.toSet()); .collect(Collectors.toSet());
} }
@@ -358,7 +359,16 @@ public class HapiProperties {
} }
public static boolean getValidateResponsesEnabled() { public static boolean getValidateResponsesEnabled() {
return HapiProperties.getBooleanProperty(VALIDATE_REQUESTS_ENABLED, false); return HapiProperties.getBooleanProperty(VALIDATE_RESPONSES_ENABLED, false);
}
public static boolean getFilterSearchEnabled() {
return HapiProperties.getBooleanProperty(FILTER_SEARCH_ENABLED, true);
}
public static boolean getGraphqlEnabled() {
return HapiProperties.getBooleanProperty(GRAPHQL_ENABLED, true);
} }
} }

View File

@@ -9,10 +9,7 @@ import ca.uhn.fhir.jpa.dao.DaoConfig;
import ca.uhn.fhir.jpa.dao.DaoRegistry; import ca.uhn.fhir.jpa.dao.DaoRegistry;
import ca.uhn.fhir.jpa.dao.IFhirSystemDao; import ca.uhn.fhir.jpa.dao.IFhirSystemDao;
import ca.uhn.fhir.jpa.interceptor.CascadingDeleteInterceptor; import ca.uhn.fhir.jpa.interceptor.CascadingDeleteInterceptor;
import ca.uhn.fhir.jpa.provider.JpaConformanceProviderDstu2; import ca.uhn.fhir.jpa.provider.*;
import ca.uhn.fhir.jpa.provider.JpaSystemProviderDstu2;
import ca.uhn.fhir.jpa.provider.SubscriptionTriggeringProvider;
import ca.uhn.fhir.jpa.provider.TerminologyUploaderProvider;
import ca.uhn.fhir.jpa.provider.dstu3.JpaConformanceProviderDstu3; import ca.uhn.fhir.jpa.provider.dstu3.JpaConformanceProviderDstu3;
import ca.uhn.fhir.jpa.provider.dstu3.JpaSystemProviderDstu3; import ca.uhn.fhir.jpa.provider.dstu3.JpaSystemProviderDstu3;
import ca.uhn.fhir.jpa.provider.r4.JpaConformanceProviderR4; import ca.uhn.fhir.jpa.provider.r4.JpaConformanceProviderR4;
@@ -54,7 +51,6 @@ public class JpaRestfulServer extends RestfulServer {
* specified in the properties file. * specified in the properties file.
*/ */
ApplicationContext appCtx = (ApplicationContext) getServletContext().getAttribute("org.springframework.web.context.WebApplicationContext.ROOT"); ApplicationContext appCtx = (ApplicationContext) getServletContext().getAttribute("org.springframework.web.context.WebApplicationContext.ROOT");
// Customize supported resource types // Customize supported resource types
Set<String> supportedResourceTypes = HapiProperties.getSupportedResourceTypes(); Set<String> supportedResourceTypes = HapiProperties.getSupportedResourceTypes();
if (!supportedResourceTypes.isEmpty()) { if (!supportedResourceTypes.isEmpty()) {
@@ -281,6 +277,13 @@ public class JpaRestfulServer extends RestfulServer {
} }
} }
// GraphQL
if (HapiProperties.getGraphqlEnabled()) {
if (fhirVersion.isEqualOrNewerThan(FhirVersionEnum.DSTU3)) {
registerProvider(appCtx.getBean(GraphQLProvider.class));
}
}
} }
} }

View File

@@ -47,6 +47,11 @@ validation.requests.enabled=false
# Should outgoing responses be validated # Should outgoing responses be validated
validation.responses.enabled=false validation.responses.enabled=false
###################################################
# Search Features
###################################################
filter_search.enabled=true
graphql.enabled=true
################################################### ###################################################
# Supported Resources # Supported Resources