Add settings for CDS Hooks and use latest hapi-fhir-cr configs

This commit is contained in:
Brenin Rhodes
2023-10-19 06:50:29 -06:00
parent 6d10c0bade
commit 408da72cf4
15 changed files with 474 additions and 538 deletions

View File

@@ -0,0 +1,14 @@
package ca.uhn.fhir.jpa.starter.cdshooks;
import org.springframework.context.annotation.Condition;
import org.springframework.context.annotation.ConditionContext;
import org.springframework.core.type.AnnotatedTypeMetadata;
public class CdsHooksConfigCondition implements Condition {
@Override
public boolean matches(ConditionContext theConditionContext, AnnotatedTypeMetadata theAnnotatedTypeMetadata) {
String property = theConditionContext.getEnvironment().getProperty("hapi.fhir.cdshooks.enabled");
return Boolean.parseBoolean(property);
}
}

View File

@@ -0,0 +1,27 @@
package ca.uhn.fhir.jpa.starter.cdshooks;
import org.springframework.boot.context.properties.ConfigurationProperties;
@ConfigurationProperties(prefix = "hapi.fhir.cdshooks")
public class CdsHooksProperties {
private boolean enabled;
public boolean isEnabled() {
return enabled;
}
public void setEnabled(boolean enabled) {
this.enabled = enabled;
}
private String clientIdHeaderName;
public String getClientIdHeaderName() {
return clientIdHeaderName;
}
public void setClientIdHeaderName(String clientIdHeaderName) {
this.clientIdHeaderName = clientIdHeaderName;
}
}

View File

@@ -37,6 +37,8 @@ public class CdsHooksServlet extends HttpServlet {
@Autowired
private AppProperties appProperties;
@Autowired
private ProviderConfiguration providerConfiguration;
@Autowired
ICdsServiceRegistry cdsServiceRegistry;
@Autowired
RestfulServer restfulServer;
@@ -44,6 +46,10 @@ public class CdsHooksServlet extends HttpServlet {
@Qualifier(CDS_HOOKS_OBJECT_MAPPER_FACTORY)
ObjectMapper objectMapper;
protected ProviderConfiguration getProviderConfiguration() {
return this.providerConfiguration;
}
// CORS Pre-flight
@Override
protected void doOptions(HttpServletRequest req, HttpServletResponse resp) {
@@ -103,26 +109,12 @@ public class CdsHooksServlet extends HttpServlet {
private void logRequestInfo(CdsServiceRequestJson request, String jsonRequest) {
logger.info(jsonRequest);
logger.info("cds-hooks hook instance: {}", request.getHookInstance());
// logger.info("cds-hooks maxCodesPerQuery: {}", this.getProviderConfiguration().getMaxCodesPerQuery());
// logger.info("cds-hooks expandValueSets: {}", this.getProviderConfiguration().getExpandValueSets());
// logger.info("cds-hooks queryBatchThreshold: {}", this.getProviderConfiguration().getQueryBatchThreshold());
// logger.info("cds-hooks searchStyle: {}", this.getProviderConfiguration().getSearchStyle());
// logger.info("cds-hooks prefetch maxUriLength: {}", this.getProviderConfiguration().getMaxUriLength());
logger.info("cds-hooks local server address: {}", appProperties.getServer_address());
logger.info("cds-hooks fhir server address: {}", request.getFhirServer());
// logger.info("cds-hooks cql_logging_enabled: {}", this.getProviderConfiguration().getCqlLoggingEnabled());
logger.info("cds-hooks cql_logging_enabled: {}", this.getProviderConfiguration().getCqlLoggingEnabled());
}
private CdsServicesJson getServices() {
return cdsServiceRegistry.getCdsServicesJson();
}
// public DebugMap getDebugMap() {
// DebugMap debugMap = new DebugMap();
// if (cqlProperties.getCqlRuntimeOptions().isDebugLoggingEnabled()) {
// // getOptions().getCqlEngineOptions().isDebugLoggingEnabled()) {
// debugMap.setIsLoggingEnabled(true);
// }
// return debugMap;
// }
}

View File

@@ -0,0 +1,29 @@
package ca.uhn.fhir.jpa.starter.cdshooks;
import ca.uhn.fhir.jpa.starter.cr.CrProperties;
public class ProviderConfiguration {
public static final ProviderConfiguration DEFAULT_PROVIDER_CONFIGURATION = new ProviderConfiguration(false, "client_id");
private final String clientIdHeaderName;
private final boolean cqlLoggingEnabled;
public ProviderConfiguration(boolean cqlLoggingEnabled, String clientIdHeaderName) {
this.cqlLoggingEnabled = cqlLoggingEnabled;
this.clientIdHeaderName = clientIdHeaderName;
}
public ProviderConfiguration(CdsHooksProperties cdsProperties, CrProperties crProperties) {
this.clientIdHeaderName = cdsProperties.getClientIdHeaderName();
this.cqlLoggingEnabled = crProperties.isCqlRuntimeDebugLoggingEnabled();
}
public String getClientIdHeaderName() {
return this.clientIdHeaderName;
}
public boolean getCqlLoggingEnabled() {
return this.cqlLoggingEnabled;
}
}

View File

@@ -4,16 +4,33 @@ import org.hl7.fhir.instance.model.api.IBaseResource;
import org.springframework.beans.factory.config.AutowireCapableBeanFactory;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Conditional;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import ca.uhn.fhir.jpa.starter.cr.CrConfigCondition;
import ca.uhn.fhir.jpa.starter.cr.CrProperties;
import ca.uhn.hapi.fhir.cdshooks.api.ICdsHooksDaoAuthorizationSvc;
import ca.uhn.hapi.fhir.cdshooks.config.CdsHooksConfig;
import ca.uhn.hapi.fhir.cdshooks.svc.CdsHooksContextBooter;
import ca.uhn.hapi.fhir.cdshooks.svc.cr.CdsCrSettings;
@Configuration
@Conditional({ CdsHooksConfigCondition.class, CrConfigCondition.class })
@Import(CdsHooksConfig.class)
public class StarterCdsHooksConfig {
@Bean
public CdsHooksProperties cdsHooksProperties() {
return new CdsHooksProperties();
}
@Bean
public CdsCrSettings cdsCrSettings(CdsHooksProperties cdsHooksProperties) {
CdsCrSettings settings = CdsCrSettings.getDefault();
settings.setClientIdHeaderName(cdsHooksProperties.getClientIdHeaderName());
return settings;
}
@Bean
public CdsHooksContextBooter cdsHooksContextBooter() {
// ourLog.info("No Spring Context provided. Assuming all CDS Services will be registered dynamically.");
@@ -25,6 +42,11 @@ public class StarterCdsHooksConfig {
public void authorizePreShow(IBaseResource theResource) {}
}
@Bean
public ProviderConfiguration providerConfiguration(CdsHooksProperties cdsProperties, CrProperties crProperties) {
return new ProviderConfiguration(cdsProperties, crProperties);
}
@Bean
ICdsHooksDaoAuthorizationSvc cdsHooksDaoAuthorizationSvc() {
return new CdsHooksDaoAuthorizationSvc();