update search parameters for eval resources to systemRequestDetails for partitioned environment

This commit is contained in:
justin.mckelvy 2023-05-10 07:29:30 -06:00
parent 648d14c52c
commit 57a29b5955
4 changed files with 61 additions and 25 deletions

View File

@ -19,30 +19,38 @@
*/
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) {
public HapiFhirDal(DaoRegistry theDaoRegistry, RequestDetails theRequestDetails, BaseRequestPartitionHelperSvc theBaseRequestPartitionHelperSvc) {
this.myDaoRegistry = theDaoRegistry;
this.myRequestDetails = theRequestDetails;
this.myBaseRequestPartitionHelperSvc = theBaseRequestPartitionHelperSvc;
}
@Override
@ -76,9 +84,20 @@ 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);
}
}

View File

@ -19,10 +19,13 @@
*/
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;
@ -47,17 +50,18 @@ public class HapiFhirRetrieveProvider extends SearchParamFhirRetrieveProvider im
private final DaoRegistry myDaoRegistry;
private final RequestDetails myRequestDetails;
protected final BaseRequestPartitionHelperSvc myBaseRequestPartitionHelperSvc;
public HapiFhirRetrieveProvider(DaoRegistry theDaoRegistry, SearchParameterResolver theSearchParameterResolver) {
this(theDaoRegistry, theSearchParameterResolver, new SystemRequestDetails());
public HapiFhirRetrieveProvider(DaoRegistry theDaoRegistry, SearchParameterResolver theSearchParameterResolver, BaseRequestPartitionHelperSvc theBaseRequestPartitionHelperSvc) {
this(theDaoRegistry, theSearchParameterResolver, new SystemRequestDetails(), theBaseRequestPartitionHelperSvc);
}
public HapiFhirRetrieveProvider(DaoRegistry registry, SearchParameterResolver searchParameterResolver,
RequestDetails requestDetails) {
public HapiFhirRetrieveProvider(DaoRegistry theRegistry, SearchParameterResolver searchParameterResolver,
RequestDetails theRequestDetails, BaseRequestPartitionHelperSvc theBaseRequestPartitionHelperSvc) {
super(searchParameterResolver);
this.myDaoRegistry = registry;
this.myRequestDetails = requestDetails;
this.myDaoRegistry = theRegistry;
this.myRequestDetails = theRequestDetails;
this.myBaseRequestPartitionHelperSvc = theBaseRequestPartitionHelperSvc;
}
/**
@ -67,7 +71,6 @@ 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) {
@ -138,11 +141,11 @@ public class HapiFhirRetrieveProvider extends SearchParamFhirRetrieveProvider im
return new QueryIterable(dataType, queries, this::executeQuery);
}
protected Iterable<IBaseResource> executeQuery(String dataType, SearchParameterMap map) {
protected Iterable<IBaseResource> executeQuery(String theDataType, SearchParameterMap theSearchParameterMap) {
ca.uhn.fhir.jpa.searchparam.SearchParameterMap hapiMap = new ca.uhn.fhir.jpa.searchparam.SearchParameterMap();
try {
for (Map.Entry<String, List<List<IQueryParameterType>>> entry : map.entrySet()) {
for (Map.Entry<String, List<List<IQueryParameterType>>> entry : theSearchParameterMap.entrySet()) {
hapiMap.put(entry.getKey(), entry.getValue());
}
@ -151,7 +154,13 @@ public class HapiFhirRetrieveProvider extends SearchParamFhirRetrieveProvider im
logger.warn("Error converting search parameter map", e);
}
return search(getClass(dataType), hapiMap, myRequestDetails);
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);
}
@Override

View File

@ -19,8 +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.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;
@ -62,7 +64,12 @@ public class HapiLibrarySourceProvider
LibraryContentType theLibraryContentType) {
String name = theLibraryIdentifier.getId();
String version = theLibraryIdentifier.getVersion();
var libraries = search(getClass("Library"), Searches.byName(name), myRequestDetails);
// needed for partitioned environment
SystemRequestDetails systemRequestDetails = new SystemRequestDetails();
systemRequestDetails.setRequestPartitionId(RequestPartitionId.defaultPartition());
var libraries = search(getClass("Library"), Searches.byName(name), systemRequestDetails);
var libraryList = new ArrayList<IBaseResource>();
for(var l:libraries){
libraryList.add(l);

View File

@ -38,6 +38,7 @@ 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;
@ -166,15 +167,15 @@ public abstract class BaseClinicalReasoningConfig {
}
@Bean
IFhirDalFactory fhirDalFactory(DaoRegistry theDaoRegistry) {
return rd -> new HapiFhirDal(theDaoRegistry, rd);
IFhirDalFactory fhirDalFactory(DaoRegistry theDaoRegistry, BaseRequestPartitionHelperSvc theBaseRequestPartitionHelperSvc) {
return rd -> new HapiFhirDal(theDaoRegistry, rd, theBaseRequestPartitionHelperSvc);
}
@Bean
IDataProviderFactory dataProviderFactory(ModelResolver theModelResolver, DaoRegistry theDaoRegistry,
SearchParameterResolver theSearchParameterResolver) {
SearchParameterResolver theSearchParameterResolver, BaseRequestPartitionHelperSvc theBaseRequestPartitionHelperSvc) {
return (rd, t) -> {
HapiFhirRetrieveProvider provider = new HapiFhirRetrieveProvider(theDaoRegistry, theSearchParameterResolver, rd);
HapiFhirRetrieveProvider provider = new HapiFhirRetrieveProvider(theDaoRegistry, theSearchParameterResolver, rd, theBaseRequestPartitionHelperSvc);
if (t != null) {
provider.setTerminologyProvider(t);
provider.setExpandValueSets(true);
@ -205,8 +206,8 @@ public abstract class BaseClinicalReasoningConfig {
@Bean
public HapiFhirRetrieveProvider fhirRetrieveProvider(DaoRegistry theDaoRegistry,
SearchParameterResolver theSearchParameterResolver) {
return new HapiFhirRetrieveProvider(theDaoRegistry, theSearchParameterResolver);
SearchParameterResolver theSearchParameterResolver, BaseRequestPartitionHelperSvc theBaseRequestPartitionHelperSvc) {
return new HapiFhirRetrieveProvider(theDaoRegistry, theSearchParameterResolver, theBaseRequestPartitionHelperSvc);
}
@Bean