Skip to content

Commit

Permalink
Expose hapi-fhir-storage-cr config to downstream modules for testing (#…
Browse files Browse the repository at this point in the history
…6272)

* Ensure IRepositoryFactory returns a Repository, and not a HapiFhirRepository.

* Rename test so that it will run from Maven and the pipeline since it didn't before.  Fix small bug that made the test error out.

* Move TestCrConfig and TestCrR4Config to main source folder.  Extract TestHapiFhirCrPartitionConfig as separate test config to be used only in the test source folder.  Add Maven compile dependency to hapi-fhir-jpaserver-base in order to ensure that moved Config classes will compile.

* Add possible code change to RequestDetailsClone to clone partition info.

* Introduce separate factory interface for Repository to preserve backward compatibility.

* Remove IRepositoryFactoryForInterface.

* Spotless

* Add javadoc.

* Get rid of TODO.

* Restore RepositoryConfig to master.

* Move test config to different packages.

* Leverage use of new RepositoryFactoryForRepositoryInterface for CrR4Config and RepositoryFactoryForRepositoryInterface.

* Ensure CrR4Config and RepositoryConfig make use of new RepositoryFactoryForRepositoryInterface.

* Add copyright header

* Add @FunctionalInterface to factory.
  • Loading branch information
lukedegruchy authored Sep 19, 2024
1 parent 1fad912 commit fb93c3d
Show file tree
Hide file tree
Showing 11 changed files with 149 additions and 16 deletions.
14 changes: 14 additions & 0 deletions hapi-fhir-storage-cr/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,20 @@
<artifactId>jakarta.xml.bind-api</artifactId>
</dependency>

<!-- For test CR config that's exported to downstream modules -->
<dependency>
<groupId>ca.uhn.hapi.fhir</groupId>
<artifactId>hapi-fhir-jpaserver-base</artifactId>
<version>${project.version}</version>
<exclusions>
<!-- prevent conflict with other version of this dependency sourced from elsewhere -->
<exclusion>
<groupId>org.glassfish</groupId>
<artifactId>jakarta.json</artifactId>
</exclusion>
</exclusions>
</dependency>

<!-- test -->
<dependency>
<groupId>org.testcontainers</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@

import ca.uhn.fhir.cr.repo.HapiFhirRepository;
import ca.uhn.fhir.rest.api.server.RequestDetails;
import com.google.common.annotations.Beta;

@FunctionalInterface
@Beta
public interface IRepositoryFactory {
HapiFhirRepository create(RequestDetails theRequestDetails);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*-
* #%L
* HAPI FHIR - Clinical Reasoning
* %%
* Copyright (C) 2014 - 2024 Smile CDR, Inc.
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* #L%
*/
package ca.uhn.fhir.cr.common;

import ca.uhn.fhir.rest.api.server.RequestDetails;
import org.opencds.cqf.fhir.api.Repository;

/**
* Factory interface to return a {@link Repository} from a {@link RequestDetails}
*/
@FunctionalInterface
public interface RepositoryFactoryForRepositoryInterface {
Repository create(RequestDetails theRequestDetails);
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
package ca.uhn.fhir.cr.config;

import ca.uhn.fhir.cr.common.IRepositoryFactory;
import ca.uhn.fhir.cr.common.RepositoryFactoryForRepositoryInterface;
import ca.uhn.fhir.cr.repo.HapiFhirRepository;
import ca.uhn.fhir.jpa.api.dao.DaoRegistry;
import ca.uhn.fhir.rest.server.RestfulServer;
Expand All @@ -28,8 +29,15 @@

@Configuration
public class RepositoryConfig {

@Bean
IRepositoryFactory repositoryFactory(DaoRegistry theDaoRegistry, RestfulServer theRestfulServer) {
return rd -> new HapiFhirRepository(theDaoRegistry, rd, theRestfulServer);
}

@Bean
RepositoryFactoryForRepositoryInterface repositoryFactoryForInterface(
DaoRegistry theDaoRegistry, RestfulServer theRestfulServer) {
return rd -> new HapiFhirRepository(theDaoRegistry, rd, theRestfulServer);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.context.FhirVersionEnum;
import ca.uhn.fhir.cr.common.IRepositoryFactory;
import ca.uhn.fhir.cr.common.RepositoryFactoryForRepositoryInterface;
import ca.uhn.fhir.cr.config.ProviderLoader;
import ca.uhn.fhir.cr.config.ProviderSelector;
import ca.uhn.fhir.cr.config.RepositoryConfig;
Expand Down Expand Up @@ -66,7 +67,8 @@ public class CrR4Config {

@Bean
IMeasureServiceFactory r4MeasureServiceFactory(
IRepositoryFactory theRepositoryFactory, MeasureEvaluationOptions theEvaluationOptions) {
RepositoryFactoryForRepositoryInterface theRepositoryFactory,
MeasureEvaluationOptions theEvaluationOptions) {
return rd -> new R4MeasureService(theRepositoryFactory.create(rd), theEvaluationOptions);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,23 @@
package ca.uhn.fhir.cr;
/*-
* #%L
* HAPI FHIR - Clinical Reasoning
* %%
* Copyright (C) 2014 - 2024 Smile CDR, Inc.
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* #L%
*/
package ca.uhn.fhir.cr.config.test;

import org.cqframework.cql.cql2elm.CqlCompilerException;
import org.cqframework.cql.cql2elm.CqlCompilerOptions;
Expand All @@ -7,7 +26,9 @@
import org.opencds.cqf.fhir.cql.CqlEngineOptions;
import org.opencds.cqf.fhir.cql.CqlOptions;


/**
* Common CQL properties shared with downstream modules.
*/
public class TestCqlProperties {

//cql settings
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,23 @@
package ca.uhn.fhir.cr;
/*-
* #%L
* HAPI FHIR - Clinical Reasoning
* %%
* Copyright (C) 2014 - 2024 Smile CDR, Inc.
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* #L%
*/
package ca.uhn.fhir.cr.config.test;

import ca.uhn.fhir.batch2.jobs.reindex.ReindexProvider;
import ca.uhn.fhir.context.FhirContext;
Expand Down Expand Up @@ -47,6 +66,9 @@
import java.util.concurrent.ConcurrentHashMap;


/**
* Common hapi-fhir clinical reasoning config shared with downstream modules.
*/
@Configuration
@Import({SubscriptionSubmitterConfig.class, SubscriptionChannelConfig.class})
public class TestCrConfig {
Expand Down Expand Up @@ -77,7 +99,9 @@ public RestfulServer restfulServer(IFhirSystemDao<?, ?> fhirSystemDao, DaoRegist
}
@Bean
public TestCqlProperties testCqlProperties(){
return new TestCqlProperties();}
return new TestCqlProperties();
}

@Bean
public JpaStorageSettings storageSettings() {
JpaStorageSettings storageSettings = new JpaStorageSettings();
Expand All @@ -87,12 +111,6 @@ public JpaStorageSettings storageSettings() {
storageSettings.setResourceClientIdStrategy(JpaStorageSettings.ClientIdStrategyEnum.ANY);
return storageSettings;
}

@Bean
public PartitionHelper partitionHelper() {
return new PartitionHelper();
}

@Bean
public ModelManager modelManager(Map<ModelIdentifier, Model> theGlobalModelCache) {
return new ModelManager(theGlobalModelCache);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,28 @@
package ca.uhn.fhir.cr.r4;
/*-
* #%L
* HAPI FHIR - Clinical Reasoning
* %%
* Copyright (C) 2014 - 2024 Smile CDR, Inc.
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* #L%
*/
package ca.uhn.fhir.cr.config.test.r4;

import ca.uhn.fhir.cr.TestCqlProperties;
import ca.uhn.fhir.cr.TestCrConfig;
import ca.uhn.fhir.cr.common.CqlThreadFactory;
import ca.uhn.fhir.cr.config.r4.CrR4Config;
import ca.uhn.fhir.cr.config.test.TestCqlProperties;
import ca.uhn.fhir.cr.config.test.TestCrConfig;
import org.cqframework.cql.cql2elm.CqlCompilerOptions;
import org.cqframework.cql.cql2elm.model.CompiledLibrary;
import org.cqframework.cql.cql2elm.model.Model;
Expand All @@ -30,6 +49,9 @@
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
* Common hapi-fhir clinical reasoning config specifically for R4 shared with downstream modules.
*/
@Configuration
@Import({TestCrConfig.class, CrR4Config.class})
public class TestCrR4Config {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package ca.uhn.fhir.cr;

import org.springframework.context.annotation.Bean;

public class TestHapiFhirCrPartitionConfig {
@Bean
public PartitionHelper partitionHelper() {
return new PartitionHelper();
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package ca.uhn.fhir.cr.dstu3;

import ca.uhn.fhir.cr.TestCqlProperties;
import ca.uhn.fhir.cr.TestCrConfig;
import ca.uhn.fhir.cr.TestHapiFhirCrPartitionConfig;
import ca.uhn.fhir.cr.config.test.TestCqlProperties;
import ca.uhn.fhir.cr.config.dstu3.CrDstu3Config;
import ca.uhn.fhir.cr.config.test.TestCrConfig;
import org.cqframework.cql.cql2elm.CqlCompilerOptions;
import org.cqframework.cql.cql2elm.model.CompiledLibrary;
import org.cqframework.cql.cql2elm.model.Model;
Expand All @@ -26,6 +27,7 @@

@Configuration
@Import({
TestHapiFhirCrPartitionConfig.class,
TestCrConfig.class,
CrDstu3Config.class
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@

import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.cr.IResourceLoader;
import ca.uhn.fhir.cr.TestHapiFhirCrPartitionConfig;
import ca.uhn.fhir.cr.config.r4.ApplyOperationConfig;
import ca.uhn.fhir.cr.config.r4.ExtractOperationConfig;
import ca.uhn.fhir.cr.config.r4.PackageOperationConfig;
import ca.uhn.fhir.cr.config.r4.PopulateOperationConfig;
import ca.uhn.fhir.cr.config.test.r4.TestCrR4Config;
import ca.uhn.fhir.jpa.api.config.JpaStorageSettings;
import ca.uhn.fhir.jpa.api.dao.DaoRegistry;
import ca.uhn.fhir.jpa.search.DatabaseBackedPagingProvider;
Expand Down Expand Up @@ -38,6 +40,7 @@


@ContextConfiguration(classes = {
TestHapiFhirCrPartitionConfig.class,
TestCrR4Config.class,
ApplyOperationConfig.class,
ExtractOperationConfig.class,
Expand Down

0 comments on commit fb93c3d

Please sign in to comment.