Skip to content

Commit

Permalink
Merge pull request #260 from DBCG/feature-springify
Browse files Browse the repository at this point in the history
Springify all the providers and cds-hooks servlet
  • Loading branch information
JPercival authored Oct 6, 2020
2 parents 1dd7a17 + 7ece7e4 commit df2359d
Show file tree
Hide file tree
Showing 43 changed files with 469 additions and 428 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,15 @@
import java.sql.Driver;

import org.apache.commons.dbcp2.BasicDataSource;
import org.opencds.cqf.cds.providers.ProviderConfiguration;
import org.opencds.cqf.cql.engine.fhir.searchparam.SearchParameterResolver;
import org.springframework.beans.factory.annotation.Autowire;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.transaction.annotation.EnableTransactionManagement;

import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.jpa.api.config.DaoConfig;
import ca.uhn.fhir.jpa.model.config.PartitionSettings;
import ca.uhn.fhir.jpa.model.entity.ModelConfig;
Expand All @@ -17,6 +21,7 @@

@Configuration
@EnableTransactionManagement
@ComponentScan(basePackages = "org.opencds.cqf.common")
public class FhirServerConfig {

private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(FhirServerConfig.class);
Expand Down Expand Up @@ -123,5 +128,19 @@ public ResponseHighlighterInterceptor responseHighlighterInterceptor() {
@Bean
public PartitionSettings partitionSettings() {
return new PartitionSettings();
}
}

@Bean()
public ProviderConfiguration providerConfiguration() {
return new ProviderConfiguration(
HapiProperties.getCdsHooksFhirServerExpandValueSets(),
HapiProperties.getCdsHooksFhirServerMaxCodesPerQuery(),
HapiProperties.getCdsHooksFhirServerSearchStyleEnum(),
HapiProperties.getCdsHooksPreFetchMaxUriLength());
}

@Bean()
public SearchParameterResolver searchParameterResolver(FhirContext fhirContext) {
return new SearchParameterResolver(fhirContext);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,29 @@
import java.util.Map;
import java.util.stream.Collectors;

import javax.inject.Inject;

import org.hl7.fhir.instance.model.api.IBaseResource;
import org.opencds.cqf.cql.engine.fhir.retrieve.SearchParamFhirRetrieveProvider;
import org.opencds.cqf.cql.engine.fhir.searchparam.SearchParameterMap;
import org.opencds.cqf.cql.engine.fhir.searchparam.SearchParameterResolver;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import ca.uhn.fhir.jpa.api.dao.DaoRegistry;
import ca.uhn.fhir.jpa.api.dao.IFhirResourceDao;
import ca.uhn.fhir.model.api.IQueryParameterType;
import ca.uhn.fhir.rest.api.server.IBundleProvider;

@Component
public class JpaFhirRetrieveProvider extends SearchParamFhirRetrieveProvider {

private static final Logger logger = LoggerFactory.getLogger(JpaFhirRetrieveProvider.class);

DaoRegistry registry;

@Inject
public JpaFhirRetrieveProvider(DaoRegistry registry, SearchParameterResolver searchParameterResolver) {
super(searchParameterResolver);
this.registry = registry;
Expand Down
6 changes: 6 additions & 0 deletions dstu3/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,11 @@
<artifactId>common</artifactId>
<version>${project.version}</version>
</dependency>

<dependency>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
<version>8.0.1</version>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -1,11 +1,26 @@
package org.opencds.cqf.dstu3.config;

import java.util.ArrayList;
import java.util.List;

import javax.persistence.EntityManagerFactory;
import javax.sql.DataSource;

import org.opencds.cqf.common.config.HapiProperties;
import org.opencds.cqf.dstu3.providers.ActivityDefinitionApplyProvider;
import org.opencds.cqf.dstu3.providers.ApplyCqlOperationProvider;
import org.opencds.cqf.dstu3.providers.CacheValueSetsProvider;
import org.opencds.cqf.dstu3.providers.CodeSystemUpdateProvider;
import org.opencds.cqf.dstu3.providers.CqlExecutionProvider;
import org.opencds.cqf.dstu3.providers.LibraryOperationsProvider;
import org.opencds.cqf.dstu3.providers.MeasureOperationsProvider;
import org.opencds.cqf.dstu3.providers.ObservationProvider;
import org.opencds.cqf.dstu3.providers.PlanDefinitionApplyProvider;
import org.opencds.cqf.dstu3.providers.QuestionnaireProvider;
import org.opencds.cqf.tooling.library.stu3.NarrativeProvider;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.orm.jpa.JpaTransactionManager;
import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
Expand All @@ -17,6 +32,7 @@
import ca.uhn.fhir.jpa.search.DatabaseBackedPagingProvider;

@Configuration
@ComponentScan(basePackages = "org.opencds.cqf.dstu3")
public class FhirServerConfigDstu3 extends BaseJavaConfigDstu3 {
protected final DataSource myDataSource;

Expand Down Expand Up @@ -71,4 +87,37 @@ public JpaTransactionManager transactionManager(EntityManagerFactory entityManag
retVal.setEntityManagerFactory(entityManagerFactory);
return retVal;
}

@Bean(name= "myOperationProvidersDstu3")
public List<Class<?>> operationProviders() {
// TODO: Make this registry dynamic
// Scan an interface, create a plugin-api, etc.
// Basically, anything that's not included in base HAPI and implements an operation.
List<Class<?>> classes = new ArrayList<>();
classes.add(ActivityDefinitionApplyProvider.class);
classes.add(ApplyCqlOperationProvider.class);
classes.add(CacheValueSetsProvider.class);
classes.add(CodeSystemUpdateProvider.class);
classes.add(CqlExecutionProvider.class);
classes.add(LibraryOperationsProvider.class);
classes.add(MeasureOperationsProvider.class);
classes.add(PlanDefinitionApplyProvider.class);

// The plugin API will need to a way to determine whether a particular
// service should be registered
if(HapiProperties.getQuestionnaireResponseExtractEnabled()) {
classes.add(QuestionnaireProvider.class);
};

if (HapiProperties.getObservationTransformEnabled()) {
classes.add(ObservationProvider.class);
}

return classes;
}

@Bean()
public NarrativeProvider narrativeProvider() {
return new NarrativeProvider();
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.opencds.cqf.dstu3.evaluation;

import javax.inject.Inject;

import org.opencds.cqf.common.evaluation.EvaluationProviderFactory;
import org.opencds.cqf.common.helpers.ClientHelper;
import org.opencds.cqf.common.providers.Dstu3ApelonFhirTerminologyProvider;
Expand All @@ -10,6 +12,7 @@
import org.opencds.cqf.cql.engine.fhir.searchparam.SearchParameterResolver;
import org.opencds.cqf.cql.engine.fhir.terminology.Dstu3FhirTerminologyProvider;
import org.opencds.cqf.cql.engine.terminology.TerminologyProvider;
import org.springframework.stereotype.Component;

import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.jpa.api.dao.DaoRegistry;
Expand All @@ -18,13 +21,15 @@

// This class is a relatively dumb factory for data providers. It supports only
// creating JPA providers for FHIR and only basic auth for terminology
@Component
public class ProviderFactory implements EvaluationProviderFactory {

DaoRegistry registry;
TerminologyProvider defaultTerminologyProvider;
FhirContext fhirContext;
ISearchParamRegistry searchParamRegistry;

@Inject
public ProviderFactory(FhirContext fhirContext, DaoRegistry registry,
TerminologyProvider defaultTerminologyProvider) {
this.defaultTerminologyProvider = defaultTerminologyProvider;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import java.util.Collections;
import java.util.List;

import javax.inject.Inject;

import org.hl7.fhir.dstu3.model.ActivityDefinition;
import org.hl7.fhir.dstu3.model.Attachment;
import org.hl7.fhir.dstu3.model.BooleanType;
Expand All @@ -24,6 +26,7 @@
import org.opencds.cqf.cql.engine.fhir.model.Dstu3FhirModelResolver;
import org.opencds.cqf.cql.engine.model.ModelResolver;
import org.opencds.cqf.dstu3.helpers.Helper;
import org.springframework.stereotype.Component;

import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.jpa.api.dao.IFhirResourceDao;
Expand All @@ -35,12 +38,14 @@
/**
* Created by Bryn on 1/16/2017.
*/
@Component
public class ActivityDefinitionApplyProvider {

private CqlExecutionProvider executionProvider;
private ModelResolver modelResolver;
private IFhirResourceDao<ActivityDefinition> activityDefinitionDao;

@Inject
public ActivityDefinitionApplyProvider(FhirContext fhirContext, CqlExecutionProvider executionProvider,
IFhirResourceDao<ActivityDefinition> activityDefinitionDao) {
this.modelResolver = new Dstu3FhirModelResolver();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import java.util.Date;
import java.util.List;

import javax.inject.Inject;

import org.cqframework.cql.cql2elm.LibraryManager;
import org.cqframework.cql.cql2elm.ModelManager;
import org.cqframework.cql.elm.execution.Library;
Expand All @@ -26,19 +28,22 @@
import org.opencds.cqf.common.helpers.TranslatorHelper;
import org.opencds.cqf.cql.engine.execution.Context;
import org.opencds.cqf.cql.engine.runtime.DateTime;
import org.springframework.stereotype.Component;

import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.jpa.api.dao.IFhirResourceDao;
import ca.uhn.fhir.rest.annotation.IdParam;
import ca.uhn.fhir.rest.annotation.Operation;
import ca.uhn.fhir.rest.annotation.OperationParam;

@Component
public class ApplyCqlOperationProvider {

private EvaluationProviderFactory providerFactory;
private IFhirResourceDao<Bundle> bundleDao;
FhirContext context;

@Inject
public ApplyCqlOperationProvider(EvaluationProviderFactory providerFactory, IFhirResourceDao<Bundle> bundleDao, FhirContext context) {
this.providerFactory = providerFactory;
this.bundleDao = bundleDao;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@
import java.util.HashMap;
import java.util.Map;

import javax.inject.Inject;

import org.hl7.fhir.dstu3.model.Bundle;
import org.hl7.fhir.dstu3.model.Endpoint;
import org.hl7.fhir.dstu3.model.IdType;
import org.hl7.fhir.dstu3.model.Parameters;
import org.hl7.fhir.dstu3.model.Resource;
import org.hl7.fhir.dstu3.model.ValueSet;
import org.opencds.cqf.dstu3.helpers.Helper;
import org.springframework.stereotype.Component;

import ca.uhn.fhir.jpa.api.dao.IFhirResourceDao;
import ca.uhn.fhir.jpa.api.dao.IFhirSystemDao;
Expand All @@ -24,11 +27,13 @@
import ca.uhn.fhir.rest.param.StringOrListParam;
import ca.uhn.fhir.rest.param.StringParam;

@Component
public class CacheValueSetsProvider {

private IFhirSystemDao<Bundle, ?> systemDao;
private IFhirResourceDao<Endpoint> endpointDao;

@Inject
public CacheValueSetsProvider(IFhirSystemDao<Bundle, ?> systemDao, IFhirResourceDao<Endpoint> endpointDao) {
this.systemDao = systemDao;
this.endpointDao = endpointDao;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,16 @@
import java.util.Set;
import java.util.stream.Collectors;

import javax.inject.Inject;

import org.hl7.fhir.dstu3.model.CodeSystem;
import org.hl7.fhir.dstu3.model.Enumerations;
import org.hl7.fhir.dstu3.model.IdType;
import org.hl7.fhir.dstu3.model.OperationOutcome;
import org.hl7.fhir.dstu3.model.ValueSet;
import org.opencds.cqf.dstu3.builders.OperationOutcomeBuilder;
import org.opencds.cqf.dstu3.builders.RandomIdBuilder;
import org.springframework.stereotype.Component;

import ca.uhn.fhir.jpa.api.dao.IFhirResourceDao;
import ca.uhn.fhir.jpa.searchparam.SearchParameterMap;
Expand All @@ -24,10 +27,12 @@
import ca.uhn.fhir.rest.api.server.IBundleProvider;
import ca.uhn.fhir.rest.param.UriParam;

@Component
public class CodeSystemUpdateProvider {
private IFhirResourceDao<ValueSet> valueSetDao;
private IFhirResourceDao<CodeSystem> codeSystemDao;

@Inject
public CodeSystemUpdateProvider(IFhirResourceDao<ValueSet> valueSetDao,
IFhirResourceDao<CodeSystem> codeSystemDao) {
this.valueSetDao = valueSetDao;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,18 @@
package org.opencds.cqf.dstu3.providers;

import ca.uhn.fhir.jpa.api.config.DaoConfig;
import ca.uhn.fhir.jpa.api.dao.IFhirSystemDao;
import javax.servlet.http.HttpServletRequest;

import org.hl7.fhir.dstu3.model.CapabilityStatement;
import org.hl7.fhir.dstu3.model.Extension;
import org.hl7.fhir.dstu3.model.StringType;
import org.opencds.cqf.dstu3.servlet.BaseServlet;

import ca.uhn.fhir.jpa.provider.dstu3.JpaConformanceProviderDstu3;
import ca.uhn.fhir.jpa.searchparam.registry.ISearchParamRegistry;
import ca.uhn.fhir.rest.annotation.Metadata;
import ca.uhn.fhir.rest.api.server.RequestDetails;
import ca.uhn.fhir.rest.server.RestfulServer;
import org.hl7.fhir.dstu3.model.*;
import org.opencds.cqf.dstu3.servlet.BaseServlet;

import javax.servlet.http.HttpServletRequest;

public class CqfRulerJpaConformanceProviderDstu3 extends JpaConformanceProviderDstu3 {

public CqfRulerJpaConformanceProviderDstu3(RestfulServer theRestfulServer, IFhirSystemDao<Bundle, Meta> theSystemDao, DaoConfig theDaoConfig, ISearchParamRegistry theSearchParamRegistry) {
super(theRestfulServer, theSystemDao, theDaoConfig, theSearchParamRegistry);
}

@Metadata
@Override
public CapabilityStatement getServerConformance(HttpServletRequest theRequest, RequestDetails theRequestDetails) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import java.util.List;
import java.util.Map;

import javax.inject.Inject;

import org.apache.commons.lang3.tuple.Triple;
import org.cqframework.cql.cql2elm.CqlTranslator;
import org.cqframework.cql.cql2elm.CqlTranslatorException;
Expand Down Expand Up @@ -37,17 +39,20 @@
import org.opencds.cqf.cql.engine.terminology.TerminologyProvider;
import org.opencds.cqf.dstu3.helpers.FhirMeasureBundler;
import org.opencds.cqf.dstu3.helpers.LibraryHelper;
import org.springframework.stereotype.Component;

import ca.uhn.fhir.rest.annotation.Operation;
import ca.uhn.fhir.rest.annotation.OperationParam;

/**
* Created by Bryn on 1/16/2017.
*/
@Component
public class CqlExecutionProvider {
private EvaluationProviderFactory providerFactory;
private LibraryResolutionProvider<Library> libraryResolutionProvider;

@Inject
public CqlExecutionProvider(LibraryResolutionProvider<Library> libraryResolutionProvider,
EvaluationProviderFactory providerFactory) {
this.providerFactory = providerFactory;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,10 @@
import org.opencds.cqf.tooling.measure.stu3.CqfMeasure;
import org.opencds.cqf.tooling.measure.stu3.TerminologyRef;
import org.opencds.cqf.tooling.measure.stu3.TerminologyRef.TerminologyRefType;
import org.springframework.stereotype.Component;
import org.opencds.cqf.tooling.measure.stu3.VersionedTerminologyRef;

@Component
public class DataRequirementsProvider {

// For creating the CQF measure we need to:
Expand Down
Loading

0 comments on commit df2359d

Please sign in to comment.