remove BaseRequestPartitionHelperSvc

This commit is contained in:
justin.mckelvy 2023-05-16 13:07:00 -06:00
parent 83aee91b72
commit 6747111c10
4 changed files with 25 additions and 62 deletions

View File

@ -19,38 +19,30 @@
*/
package ca.uhn.fhir.cr.common;
import ca.uhn.fhir.interceptor.model.RequestPartitionId;
import ca.uhn.fhir.jpa.api.dao.DaoRegistry;
import ca.uhn.fhir.jpa.partition.BaseRequestPartitionHelperSvc;
import ca.uhn.fhir.jpa.searchparam.SearchParameterMap;
import ca.uhn.fhir.rest.api.server.RequestDetails;
import ca.uhn.fhir.rest.api.server.SystemRequestDetails;
import ca.uhn.fhir.rest.param.UriParam;
import org.hl7.fhir.instance.model.api.IBaseResource;
import org.hl7.fhir.instance.model.api.IIdType;
import org.opencds.cqf.cql.evaluator.fhir.dal.FhirDal;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@SuppressWarnings("unchecked")
/**
* This class leverages DaoRegistry from Hapi-fhir to implement CRUD FHIR API operations constrained to provide only the operations necessary for the cql-evaluator modules to function.
**/
public class HapiFhirDal implements FhirDal {
private static Logger logger = LoggerFactory.getLogger(HapiFhirDal.class);
protected final DaoRegistry myDaoRegistry;
protected final RequestDetails myRequestDetails;
protected final BaseRequestPartitionHelperSvc myBaseRequestPartitionHelperSvc;
public HapiFhirDal(DaoRegistry theDaoRegistry, BaseRequestPartitionHelperSvc theBaseRequestPartitionHelperSvc) {
this(theDaoRegistry,null, theBaseRequestPartitionHelperSvc);
public HapiFhirDal(DaoRegistry theDaoRegistry) {
this(theDaoRegistry,null);
}
public HapiFhirDal(DaoRegistry theDaoRegistry, RequestDetails theRequestDetails, BaseRequestPartitionHelperSvc theBaseRequestPartitionHelperSvc) {
public HapiFhirDal(DaoRegistry theDaoRegistry, RequestDetails theRequestDetails) {
this.myDaoRegistry = theDaoRegistry;
this.myRequestDetails = theRequestDetails;
this.myBaseRequestPartitionHelperSvc = theBaseRequestPartitionHelperSvc;
}
@Override
@ -84,20 +76,9 @@ public class HapiFhirDal implements FhirDal {
@Override
public Iterable<IBaseResource> searchByUrl(String theResourceType, String theUrl) {
if(myBaseRequestPartitionHelperSvc.isResourcePartitionable(theResourceType)){
var b = this.myDaoRegistry.getResourceDao(theResourceType)
.search(new SearchParameterMap().add("url", new UriParam(theUrl)), myRequestDetails);
return new BundleIterable(myRequestDetails, b);
} else {
//In Partitioned deployment certain resources are only available in default partition
SystemRequestDetails systemRequestDetails = new SystemRequestDetails();
systemRequestDetails.setRequestPartitionId(RequestPartitionId.defaultPartition());
var b = this.myDaoRegistry.getResourceDao(theResourceType)
.search(new SearchParameterMap().add("url", new UriParam(theUrl)), systemRequestDetails);
return new BundleIterable(systemRequestDetails, b);
}
var b = this.myDaoRegistry.getResourceDao(theResourceType)
.search(new SearchParameterMap().add("url", new UriParam(theUrl)), myRequestDetails);
return new BundleIterable(myRequestDetails, b);
}

View File

@ -19,13 +19,10 @@
*/
package ca.uhn.fhir.cr.common;
import ca.uhn.fhir.interceptor.model.RequestPartitionId;
import ca.uhn.fhir.jpa.api.dao.DaoRegistry;
import ca.uhn.fhir.jpa.partition.BaseRequestPartitionHelperSvc;
import ca.uhn.fhir.model.api.IQueryParameterType;
import ca.uhn.fhir.rest.api.server.RequestDetails;
import ca.uhn.fhir.rest.api.server.SystemRequestDetails;
import ca.uhn.fhir.rest.param.UriParam;
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;
@ -50,18 +47,17 @@ public class HapiFhirRetrieveProvider extends SearchParamFhirRetrieveProvider im
private final DaoRegistry myDaoRegistry;
private final RequestDetails myRequestDetails;
protected final BaseRequestPartitionHelperSvc myBaseRequestPartitionHelperSvc;
public HapiFhirRetrieveProvider(DaoRegistry theDaoRegistry, SearchParameterResolver theSearchParameterResolver, BaseRequestPartitionHelperSvc theBaseRequestPartitionHelperSvc) {
this(theDaoRegistry, theSearchParameterResolver, new SystemRequestDetails(), theBaseRequestPartitionHelperSvc);
public HapiFhirRetrieveProvider(DaoRegistry theDaoRegistry, SearchParameterResolver theSearchParameterResolver) {
this(theDaoRegistry, theSearchParameterResolver, new SystemRequestDetails());
}
public HapiFhirRetrieveProvider(DaoRegistry theRegistry, SearchParameterResolver searchParameterResolver,
RequestDetails theRequestDetails, BaseRequestPartitionHelperSvc theBaseRequestPartitionHelperSvc) {
public HapiFhirRetrieveProvider(DaoRegistry registry, SearchParameterResolver searchParameterResolver,
RequestDetails requestDetails) {
super(searchParameterResolver);
this.myDaoRegistry = theRegistry;
this.myRequestDetails = theRequestDetails;
this.myBaseRequestPartitionHelperSvc = theBaseRequestPartitionHelperSvc;
this.myDaoRegistry = registry;
this.myRequestDetails = requestDetails;
}
/**
@ -71,6 +67,7 @@ public class HapiFhirRetrieveProvider extends SearchParamFhirRetrieveProvider im
private final String dataType;
private final List<SearchParameterMap> queries;
private final BiFunction<String, SearchParameterMap, Iterable<IBaseResource>> queryFunc;
public QueryIterable(String dataType, List<SearchParameterMap> queries, BiFunction<String, SearchParameterMap, Iterable<IBaseResource>> queryFunc) {
@ -141,11 +138,11 @@ public class HapiFhirRetrieveProvider extends SearchParamFhirRetrieveProvider im
return new QueryIterable(dataType, queries, this::executeQuery);
}
protected Iterable<IBaseResource> executeQuery(String theDataType, SearchParameterMap theSearchParameterMap) {
protected Iterable<IBaseResource> executeQuery(String dataType, SearchParameterMap map) {
ca.uhn.fhir.jpa.searchparam.SearchParameterMap hapiMap = new ca.uhn.fhir.jpa.searchparam.SearchParameterMap();
try {
for (Map.Entry<String, List<List<IQueryParameterType>>> entry : theSearchParameterMap.entrySet()) {
for (Map.Entry<String, List<List<IQueryParameterType>>> entry : map.entrySet()) {
hapiMap.put(entry.getKey(), entry.getValue());
}
@ -154,13 +151,7 @@ public class HapiFhirRetrieveProvider extends SearchParamFhirRetrieveProvider im
logger.warn("Error converting search parameter map", e);
}
SystemRequestDetails systemRequestDetails = new SystemRequestDetails();
if(!myBaseRequestPartitionHelperSvc.isResourcePartitionable(theDataType)){
//if non-partitionable datatype, set to default partition
systemRequestDetails.setRequestPartitionId(RequestPartitionId.defaultPartition());
}
return search(getClass(theDataType), hapiMap, systemRequestDetails);
return search(getClass(dataType), hapiMap, myRequestDetails);
}
@Override

View File

@ -19,10 +19,8 @@
*/
package ca.uhn.fhir.cr.common;
import ca.uhn.fhir.interceptor.model.RequestPartitionId;
import ca.uhn.fhir.jpa.api.dao.DaoRegistry;
import ca.uhn.fhir.rest.api.server.RequestDetails;
import ca.uhn.fhir.rest.api.server.SystemRequestDetails;
import org.cqframework.cql.cql2elm.LibraryContentType;
import org.cqframework.cql.cql2elm.LibrarySourceProvider;
import org.hl7.elm.r1.VersionedIdentifier;
@ -64,12 +62,7 @@ public class HapiLibrarySourceProvider
LibraryContentType theLibraryContentType) {
String name = theLibraryIdentifier.getId();
String version = theLibraryIdentifier.getVersion();
// needed for partitioned environment
SystemRequestDetails systemRequestDetails = new SystemRequestDetails();
systemRequestDetails.setRequestPartitionId(RequestPartitionId.defaultPartition());
var libraries = search(getClass("Library"), Searches.byName(name), systemRequestDetails);
var libraries = search(getClass("Library"), Searches.byName(name), myRequestDetails);
var libraryList = new ArrayList<IBaseResource>();
for(var l:libraries){
libraryList.add(l);

View File

@ -38,7 +38,6 @@ import ca.uhn.fhir.cr.common.ITerminologyProviderFactory;
import ca.uhn.fhir.i18n.Msg;
import ca.uhn.fhir.jpa.api.dao.DaoRegistry;
import ca.uhn.fhir.jpa.cache.IResourceChangeListenerRegistry;
import ca.uhn.fhir.jpa.partition.BaseRequestPartitionHelperSvc;
import ca.uhn.fhir.jpa.searchparam.SearchParameterMap;
import ca.uhn.fhir.rest.server.provider.ResourceProviderFactory;
import org.cqframework.cql.cql2elm.CqlTranslatorOptions;
@ -58,7 +57,6 @@ import org.opencds.cqf.cql.evaluator.CqlOptions;
import org.opencds.cqf.cql.evaluator.builder.DataProviderComponents;
import org.opencds.cqf.cql.evaluator.builder.EndpointInfo;
import org.opencds.cqf.cql.evaluator.cql2elm.util.LibraryVersionSelector;
import org.opencds.cqf.cql.evaluator.engine.execution.CacheAwareLibraryLoaderDecorator;
import org.opencds.cqf.cql.evaluator.engine.execution.TranslatingLibraryLoader;
import org.opencds.cqf.cql.evaluator.engine.model.CachingModelResolverDecorator;
import org.opencds.cqf.cql.evaluator.engine.retrieve.BundleRetrieveProvider;
@ -170,15 +168,15 @@ public abstract class BaseClinicalReasoningConfig {
}
@Bean
IFhirDalFactory fhirDalFactory(DaoRegistry theDaoRegistry, BaseRequestPartitionHelperSvc theBaseRequestPartitionHelperSvc) {
return rd -> new HapiFhirDal(theDaoRegistry, rd, theBaseRequestPartitionHelperSvc);
IFhirDalFactory fhirDalFactory(DaoRegistry theDaoRegistry) {
return rd -> new HapiFhirDal(theDaoRegistry, rd);
}
@Bean
IDataProviderFactory dataProviderFactory(ModelResolver theModelResolver, DaoRegistry theDaoRegistry,
SearchParameterResolver theSearchParameterResolver, BaseRequestPartitionHelperSvc theBaseRequestPartitionHelperSvc) {
SearchParameterResolver theSearchParameterResolver) {
return (rd, t) -> {
HapiFhirRetrieveProvider provider = new HapiFhirRetrieveProvider(theDaoRegistry, theSearchParameterResolver, rd, theBaseRequestPartitionHelperSvc);
HapiFhirRetrieveProvider provider = new HapiFhirRetrieveProvider(theDaoRegistry, theSearchParameterResolver, rd);
if (t != null) {
provider.setTerminologyProvider(t);
provider.setExpandValueSets(true);
@ -209,8 +207,8 @@ public abstract class BaseClinicalReasoningConfig {
@Bean
public HapiFhirRetrieveProvider fhirRetrieveProvider(DaoRegistry theDaoRegistry,
SearchParameterResolver theSearchParameterResolver, BaseRequestPartitionHelperSvc theBaseRequestPartitionHelperSvc) {
return new HapiFhirRetrieveProvider(theDaoRegistry, theSearchParameterResolver, theBaseRequestPartitionHelperSvc);
SearchParameterResolver theSearchParameterResolver) {
return new HapiFhirRetrieveProvider(theDaoRegistry, theSearchParameterResolver);
}
@Bean