Skip to content

Commit

Permalink
Merge branch 'master' of github.com:hapifhir/hapi-fhir-jpaserver-starter
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesagnew committed May 19, 2021
2 parents b14d575 + fe54a8d commit ea335fd
Show file tree
Hide file tree
Showing 13 changed files with 255 additions and 144 deletions.
3 changes: 1 addition & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@
<parent>
<groupId>ca.uhn.hapi.fhir</groupId>
<artifactId>hapi-fhir</artifactId>
<!-- FIMXME KBD Change this to 5.3.0 BEFORE merging this code to master ! -->
<version>5.3.0</version>
<version>5.4.0</version>
</parent>

<artifactId>hapi-fhir-jpaserver-starter</artifactId>
Expand Down
24 changes: 12 additions & 12 deletions src/main/java/ca/uhn/fhir/jpa/mdm/MdmConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import ca.uhn.fhir.mdm.api.IMdmSettings;
import ca.uhn.fhir.mdm.rules.config.MdmRuleValidator;
import ca.uhn.fhir.mdm.rules.config.MdmSettings;
import ca.uhn.fhir.rest.server.util.ISearchParamRetriever;
import ca.uhn.fhir.rest.server.util.ISearchParamRegistry;
import com.google.common.base.Charsets;
import org.apache.commons.io.IOUtils;
import org.springframework.beans.factory.annotation.Autowired;
Expand All @@ -29,17 +29,17 @@
@Import({MdmConsumerConfig.class, MdmSubmitterConfig.class})
public class MdmConfig {

@Bean
MdmRuleValidator mdmRuleValidator(FhirContext theFhirContext, ISearchParamRetriever theSearchParamRetriever) {
return new MdmRuleValidator(theFhirContext, theSearchParamRetriever);
}
@Bean
MdmRuleValidator mdmRuleValidator(FhirContext theFhirContext, ISearchParamRegistry theSearchParamRegistry) {
return new MdmRuleValidator(theFhirContext, theSearchParamRegistry);
}

@Bean
IMdmSettings mdmSettings(@Autowired MdmRuleValidator theMdmRuleValidator, AppProperties appProperties) throws IOException {
DefaultResourceLoader resourceLoader = new DefaultResourceLoader();
Resource resource = resourceLoader.getResource("mdm-rules.json");
String json = IOUtils.toString(resource.getInputStream(), Charsets.UTF_8);
return new MdmSettings(theMdmRuleValidator).setEnabled(appProperties.getMdm_enabled()).setScriptText(json);
}
@Bean
IMdmSettings mdmSettings(@Autowired MdmRuleValidator theMdmRuleValidator, AppProperties appProperties) throws IOException {
DefaultResourceLoader resourceLoader = new DefaultResourceLoader();
Resource resource = resourceLoader.getResource("mdm-rules.json");
String json = IOUtils.toString(resource.getInputStream(), Charsets.UTF_8);
return new MdmSettings(theMdmRuleValidator).setEnabled(appProperties.getMdm_enabled()).setScriptText(json);
}

}
29 changes: 29 additions & 0 deletions src/main/java/ca/uhn/fhir/jpa/starter/AppProperties.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public class AppProperties {
private Boolean allow_placeholder_references = true;
private Boolean auto_create_placeholder_reference_targets = false;
private Boolean enable_index_missing_fields = false;
private Boolean enable_index_contained_resource = false;
private Boolean enable_repository_validating_interceptor = false;
private Boolean enforce_referential_integrity_on_delete = true;
private Boolean enforce_referential_integrity_on_write = true;
Expand Down Expand Up @@ -67,6 +68,9 @@ public class AppProperties {
private Boolean lastn_enabled = false;
private NormalizedQuantitySearchLevel normalized_quantity_search_level = NormalizedQuantitySearchLevel.NORMALIZED_QUANTITY_SEARCH_NOT_SUPPORTED;

private Integer search_coord_core_pool_size = 20;
private Integer search_coord_max_pool_size = 100;
private Integer search_coord_queue_capacity = 200;
private Boolean use_apache_address_strategy = false;
private Boolean use_apache_address_strategy_https = false;

Expand Down Expand Up @@ -273,6 +277,14 @@ public void setEnable_index_missing_fields(Boolean enable_index_missing_fields)
this.enable_index_missing_fields = enable_index_missing_fields;
}

public Boolean getEnable_index_contained_resource() {
return enable_index_contained_resource;
}

public void setEnable_index_contained_resource(Boolean enable_index_contained_resource) {
this.enable_index_contained_resource = enable_index_contained_resource;
}

public Boolean getEnable_repository_validating_interceptor() {
return enable_repository_validating_interceptor;
}
Expand Down Expand Up @@ -441,6 +453,23 @@ public void setNormalized_quantity_search_level(NormalizedQuantitySearchLevel no
this.normalized_quantity_search_level = normalized_quantity_search_level;
}

public Integer getSearch_coord_core_pool_size() { return search_coord_core_pool_size; }

public void setSearch_coord_core_pool_size(Integer search_coord_core_pool_size) {
this.search_coord_core_pool_size = search_coord_core_pool_size;
}

public Integer getSearch_coord_max_pool_size() { return search_coord_max_pool_size; }

public void setSearch_coord_max_pool_size(Integer search_coord_max_pool_size) {
this.search_coord_max_pool_size = search_coord_max_pool_size;
}

public Integer getSearch_coord_queue_capacity() { return search_coord_queue_capacity; }

public void setSearch_coord_queue_capacity(Integer search_coord_queue_capacity) {
this.search_coord_queue_capacity = search_coord_queue_capacity;
}

public static class Cors {
private Boolean allow_Credentials = true;
Expand Down
63 changes: 30 additions & 33 deletions src/main/java/ca/uhn/fhir/jpa/starter/BaseJpaRestfulServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,38 +2,46 @@

import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.context.FhirVersionEnum;
import ca.uhn.fhir.context.support.IValidationSupport;
import ca.uhn.fhir.cql.common.provider.CqlProviderLoader;
import ca.uhn.fhir.interceptor.api.IInterceptorBroadcaster;
import ca.uhn.fhir.interceptor.api.IInterceptorService;
import ca.uhn.fhir.jpa.api.config.DaoConfig;
import ca.uhn.fhir.jpa.api.dao.DaoRegistry;
import ca.uhn.fhir.jpa.api.dao.IFhirSystemDao;
import ca.uhn.fhir.jpa.binstore.BinaryStorageInterceptor;
import ca.uhn.fhir.jpa.bulk.provider.BulkDataExportProvider;
import ca.uhn.fhir.jpa.bulk.export.provider.BulkDataExportProvider;
import ca.uhn.fhir.jpa.interceptor.CascadingDeleteInterceptor;
import ca.uhn.fhir.jpa.packages.IPackageInstallerSvc;
import ca.uhn.fhir.jpa.packages.PackageInstallOutcomeJson;
import ca.uhn.fhir.jpa.packages.PackageInstallationSpec;
import ca.uhn.fhir.jpa.partition.PartitionManagementProvider;
import ca.uhn.fhir.jpa.provider.*;
import ca.uhn.fhir.jpa.provider.GraphQLProvider;
import ca.uhn.fhir.jpa.provider.IJpaSystemProvider;
import ca.uhn.fhir.jpa.provider.JpaCapabilityStatementProvider;
import ca.uhn.fhir.jpa.provider.JpaConformanceProviderDstu2;
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.r4.JpaConformanceProviderR4;
import ca.uhn.fhir.jpa.provider.r5.JpaConformanceProviderR5;
import ca.uhn.fhir.jpa.search.DatabaseBackedPagingProvider;
import ca.uhn.fhir.jpa.searchparam.registry.ISearchParamRegistry;
import ca.uhn.fhir.jpa.subscription.util.SubscriptionDebugLogInterceptor;
import ca.uhn.fhir.narrative.DefaultThymeleafNarrativeGenerator;
import ca.uhn.fhir.narrative.INarrativeGenerator;
import ca.uhn.fhir.narrative2.NullNarrativeGenerator;
import ca.uhn.fhir.rest.server.ApacheProxyAddressStrategy;
import ca.uhn.fhir.rest.server.ETagSupportEnum;
import ca.uhn.fhir.rest.server.HardcodedServerAddressStrategy;
import ca.uhn.fhir.rest.server.ApacheProxyAddressStrategy;
import ca.uhn.fhir.rest.server.IncomingRequestAddressStrategy;
import ca.uhn.fhir.rest.server.RestfulServer;
import ca.uhn.fhir.rest.server.interceptor.*;
import ca.uhn.fhir.rest.server.interceptor.CorsInterceptor;
import ca.uhn.fhir.rest.server.interceptor.FhirPathFilterInterceptor;
import ca.uhn.fhir.rest.server.interceptor.LoggingInterceptor;
import ca.uhn.fhir.rest.server.interceptor.RequestValidatingInterceptor;
import ca.uhn.fhir.rest.server.interceptor.ResponseHighlighterInterceptor;
import ca.uhn.fhir.rest.server.interceptor.ResponseValidatingInterceptor;
import ca.uhn.fhir.rest.server.interceptor.partition.RequestTenantPartitionInterceptor;
import ca.uhn.fhir.rest.server.provider.ResourceProviderFactory;
import ca.uhn.fhir.rest.server.tenant.UrlBaseTenantIdentificationStrategy;
import ca.uhn.fhir.rest.server.util.ISearchParamRegistry;
import ca.uhn.fhir.validation.IValidatorModule;
import ca.uhn.fhir.validation.ResultSeverityEnum;
import com.google.common.base.Strings;
Expand All @@ -44,73 +52,60 @@
import org.springframework.web.cors.CorsConfiguration;

import javax.servlet.ServletException;
import java.util.*;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.stream.Collectors;

public class BaseJpaRestfulServer extends RestfulServer {

private static final long serialVersionUID = 1L;
@Autowired
DaoRegistry daoRegistry;

@Autowired
DaoConfig daoConfig;

@Autowired
ISearchParamRegistry searchParamRegistry;

@Autowired
IFhirSystemDao fhirSystemDao;

@Autowired
ResourceProviderFactory resourceProviders;

@Autowired
IJpaSystemProvider jpaSystemProvider;

@Autowired
IInterceptorBroadcaster interceptorBroadcaster;

@Autowired
DatabaseBackedPagingProvider databaseBackedPagingProvider;

@Autowired
IInterceptorService interceptorService;

@Autowired
IValidatorModule validatorModule;

@Autowired
Optional<GraphQLProvider> graphQLProvider;

@Autowired
BulkDataExportProvider bulkDataExportProvider;

@Autowired
PartitionManagementProvider partitionManagementProvider;

@Autowired
BinaryStorageInterceptor binaryStorageInterceptor;

@Autowired
IPackageInstallerSvc packageInstallerSvc;

@Autowired
AppProperties appProperties;

@Autowired
ApplicationContext myApplicationContext;

@Autowired(required = false)
IRepositoryValidationInterceptorFactory factory;

// These are set only if the features are enabled
private CqlProviderLoader cqlProviderLoader;
@Autowired
private IValidationSupport myValidationSupport;

public BaseJpaRestfulServer() {
}

private static final long serialVersionUID = 1L;

@SuppressWarnings("unchecked")
@Override
protected void initialize() throws ServletException {
Expand Down Expand Up @@ -158,14 +153,14 @@ protected void initialize() throws ServletException {
setServerConformanceProvider(confProvider);
} else if (fhirVersion == FhirVersionEnum.R4) {

JpaConformanceProviderR4 confProvider = new JpaConformanceProviderR4(this, fhirSystemDao,
daoConfig, searchParamRegistry);
JpaCapabilityStatementProvider confProvider = new JpaCapabilityStatementProvider(this, fhirSystemDao,
daoConfig, searchParamRegistry, myValidationSupport);
confProvider.setImplementationDescription("HAPI FHIR R4 Server");
setServerConformanceProvider(confProvider);
} else if (fhirVersion == FhirVersionEnum.R5) {

JpaConformanceProviderR5 confProvider = new JpaConformanceProviderR5(this, fhirSystemDao,
daoConfig, searchParamRegistry);
JpaCapabilityStatementProvider confProvider = new JpaCapabilityStatementProvider(this, fhirSystemDao,
daoConfig, searchParamRegistry, myValidationSupport);
confProvider.setImplementationDescription("HAPI FHIR R5 Server");
setServerConformanceProvider(confProvider);
} else {
Expand Down Expand Up @@ -384,5 +379,7 @@ protected void initialize() throws ServletException {
}

daoConfig.getModelConfig().setNormalizedQuantitySearchLevel(appProperties.getNormalized_quantity_search_level());

daoConfig.getModelConfig().setIndexOnContainedResources(appProperties.getEnable_index_contained_resource());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -183,4 +183,4 @@ private static void addAll(Map<String, Object> aBase, Map<String, Object> aToBeA
aBase.put(entry.getKey(), entry.getValue());
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ public FhirServerConfigCommon(AppProperties appProperties) {
if (appProperties.getSubscription().getEmail() != null) {
ourLog.info("Email subscriptions enabled");
}

if (appProperties.getEnable_index_contained_resource() == Boolean.TRUE) {
ourLog.info("Indexed on contained resource enabled");
}
}

/**
Expand Down Expand Up @@ -163,6 +167,8 @@ public ModelConfig modelConfig(AppProperties appProperties) {
}

modelConfig.setNormalizedQuantitySearchLevel(appProperties.getNormalized_quantity_search_level());

modelConfig.setIndexOnContainedResources(appProperties.getEnable_index_contained_resource());
return modelConfig;
}

Expand Down
14 changes: 14 additions & 0 deletions src/main/java/ca/uhn/fhir/jpa/starter/FhirServerConfigDstu2.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import org.springframework.orm.jpa.JpaTransactionManager;
import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;

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

Expand All @@ -31,6 +32,19 @@ public class FhirServerConfigDstu2 extends BaseJavaConfigDstu2 {
@Autowired
AppProperties appProperties;

@PostConstruct
public void initSettings() {
if(appProperties.getSearch_coord_core_pool_size() != null) {
setSearchCoordCorePoolSize(appProperties.getSearch_coord_core_pool_size());
}
if(appProperties.getSearch_coord_max_pool_size() != null) {
setSearchCoordMaxPoolSize(appProperties.getSearch_coord_max_pool_size());
}
if(appProperties.getSearch_coord_queue_capacity() != null) {
setSearchCoordQueueCapacity(appProperties.getSearch_coord_queue_capacity());
}
}

@Override
public DatabaseBackedPagingProvider databaseBackedPagingProvider() {
DatabaseBackedPagingProvider pagingProvider = super.databaseBackedPagingProvider();
Expand Down
22 changes: 21 additions & 1 deletion src/main/java/ca/uhn/fhir/jpa/starter/FhirServerConfigDstu3.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import org.springframework.orm.jpa.JpaTransactionManager;
import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;

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

Expand All @@ -29,6 +30,20 @@ public class FhirServerConfigDstu3 extends BaseJavaConfigDstu3 {
@Autowired
AppProperties appProperties;

@PostConstruct
public void initSettings() {
if(appProperties.getSearch_coord_core_pool_size() != null) {
setSearchCoordCorePoolSize(appProperties.getSearch_coord_core_pool_size());
}
if(appProperties.getSearch_coord_max_pool_size() != null) {
setSearchCoordMaxPoolSize(appProperties.getSearch_coord_max_pool_size());
}
if(appProperties.getSearch_coord_queue_capacity() != null) {
setSearchCoordQueueCapacity(appProperties.getSearch_coord_queue_capacity());
}
}


@Override
public DatabaseBackedPagingProvider databaseBackedPagingProvider() {
DatabaseBackedPagingProvider pagingProvider = super.databaseBackedPagingProvider();
Expand Down Expand Up @@ -68,7 +83,12 @@ public JpaTransactionManager hapiTransactionManager(EntityManagerFactory entityM
public ElasticsearchSvcImpl elasticsearchSvc() {
if (EnvironmentHelper.isElasticsearchEnabled(configurableEnvironment)) {
String elasticsearchUrl = EnvironmentHelper.getElasticsearchServerUrl(configurableEnvironment);
String elasticsearchHost = elasticsearchUrl.substring(elasticsearchUrl.indexOf("://")+3, elasticsearchUrl.lastIndexOf(":"));
String elasticsearchHost;
if (elasticsearchUrl.startsWith("http")) {
elasticsearchHost = elasticsearchUrl.substring(elasticsearchUrl.indexOf("://") + 3, elasticsearchUrl.lastIndexOf(":"));
} else {
elasticsearchHost = elasticsearchUrl.substring(0, elasticsearchUrl.indexOf(":"));
}
String elasticsearchUsername = EnvironmentHelper.getElasticsearchServerUsername(configurableEnvironment);
String elasticsearchPassword = EnvironmentHelper.getElasticsearchServerPassword(configurableEnvironment);
int elasticsearchPort = Integer.parseInt(elasticsearchUrl.substring(elasticsearchUrl.lastIndexOf(":")+1));
Expand Down
14 changes: 14 additions & 0 deletions src/main/java/ca/uhn/fhir/jpa/starter/FhirServerConfigR4.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import org.springframework.orm.jpa.JpaTransactionManager;
import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;

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

Expand All @@ -31,6 +32,19 @@ public class FhirServerConfigR4 extends BaseJavaConfigR4 {
@Autowired
AppProperties appProperties;

@PostConstruct
public void initSettings() {
if(appProperties.getSearch_coord_core_pool_size() != null) {
setSearchCoordCorePoolSize(appProperties.getSearch_coord_core_pool_size());
}
if(appProperties.getSearch_coord_max_pool_size() != null) {
setSearchCoordMaxPoolSize(appProperties.getSearch_coord_max_pool_size());
}
if(appProperties.getSearch_coord_queue_capacity() != null) {
setSearchCoordQueueCapacity(appProperties.getSearch_coord_queue_capacity());
}
}

@Override
public DatabaseBackedPagingProvider databaseBackedPagingProvider() {
DatabaseBackedPagingProvider pagingProvider = super.databaseBackedPagingProvider();
Expand Down
Loading

0 comments on commit ea335fd

Please sign in to comment.