* Add post-fetch filtering to bulk export * Add changelog * Add validator * Test fixes * Test fix * Review comments for #4772 * Commit fix
This commit is contained in:
parent
f6094eed47
commit
f9de5c918e
|
@ -4,6 +4,6 @@ issue: 4772
|
||||||
title: "A new optional parameter called `_typePostFetchFilterUrl` has been added to the
|
title: "A new optional parameter called `_typePostFetchFilterUrl` has been added to the
|
||||||
Bulk Export `$export`
|
Bulk Export `$export`
|
||||||
operation parameters. This parameter allows filters to be specified that will be applied
|
operation parameters. This parameter allows filters to be specified that will be applied
|
||||||
in-memory to the resources after that have been initially fetched by the database. This can
|
in-memory to the resources after they have been initially fetched by the database. This can
|
||||||
be used to allow complex filters which only remove small numbers of resources to be
|
be used to allow complex filters which only remove small numbers of resources to be
|
||||||
efficiently applied against large datasets."
|
efficiently applied against large datasets."
|
||||||
|
|
|
@ -136,7 +136,6 @@ public class ExpandResourcesStep implements IJobStepWorker<BulkExportJobParamete
|
||||||
ListMultimap<String, String> resources = encodeToString(allResources, parameters);
|
ListMultimap<String, String> resources = encodeToString(allResources, parameters);
|
||||||
|
|
||||||
// set to datasink
|
// set to datasink
|
||||||
if (!resources.isEmpty()) {
|
|
||||||
for (String nextResourceType : resources.keySet()) {
|
for (String nextResourceType : resources.keySet()) {
|
||||||
|
|
||||||
ExpandedResourcesList output = new ExpandedResourcesList();
|
ExpandedResourcesList output = new ExpandedResourcesList();
|
||||||
|
@ -149,7 +148,6 @@ public class ExpandResourcesStep implements IJobStepWorker<BulkExportJobParamete
|
||||||
idList.getResourceType());
|
idList.getResourceType());
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// and return
|
// and return
|
||||||
return RunOutcome.SUCCESS;
|
return RunOutcome.SUCCESS;
|
||||||
|
@ -158,25 +156,7 @@ public class ExpandResourcesStep implements IJobStepWorker<BulkExportJobParamete
|
||||||
private void applyPostFetchFiltering(List<IBaseResource> theResources, List<String> thePostFetchFilterUrls, String theInstanceId, String theChunkId) {
|
private void applyPostFetchFiltering(List<IBaseResource> theResources, List<String> thePostFetchFilterUrls, String theInstanceId, String theChunkId) {
|
||||||
int numRemoved = 0;
|
int numRemoved = 0;
|
||||||
for (Iterator<IBaseResource> iter = theResources.iterator(); iter.hasNext(); ) {
|
for (Iterator<IBaseResource> iter = theResources.iterator(); iter.hasNext(); ) {
|
||||||
IBaseResource nextResource = iter.next();
|
boolean matched = applyPostFetchFilteringForSingleResource(thePostFetchFilterUrls, iter);
|
||||||
String nextResourceType = myFhirContext.getResourceType(nextResource);
|
|
||||||
boolean matched = false;
|
|
||||||
|
|
||||||
for (String nextPostFetchFilterUrl : thePostFetchFilterUrls) {
|
|
||||||
// TODO: JA in next ticket - Add validation to the filter URLs when the job is submitted
|
|
||||||
// We should make sure that the format is [resourceType]?[at least one param] and that
|
|
||||||
// the param can be evaluated by the in memory matcher
|
|
||||||
if (nextPostFetchFilterUrl.contains("?")) {
|
|
||||||
String resourceType = nextPostFetchFilterUrl.substring(0, nextPostFetchFilterUrl.indexOf('?'));
|
|
||||||
if (nextResourceType.equals(resourceType)) {
|
|
||||||
InMemoryMatchResult matchResult = myInMemoryResourceMatcher.match(nextPostFetchFilterUrl, nextResource, null, new SystemRequestDetails());
|
|
||||||
if (matchResult.matched()) {
|
|
||||||
matched = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!matched) {
|
if (!matched) {
|
||||||
iter.remove();
|
iter.remove();
|
||||||
|
@ -189,6 +169,24 @@ public class ExpandResourcesStep implements IJobStepWorker<BulkExportJobParamete
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean applyPostFetchFilteringForSingleResource(List<String> thePostFetchFilterUrls, Iterator<IBaseResource> iter) {
|
||||||
|
IBaseResource nextResource = iter.next();
|
||||||
|
String nextResourceType = myFhirContext.getResourceType(nextResource);
|
||||||
|
|
||||||
|
for (String nextPostFetchFilterUrl : thePostFetchFilterUrls) {
|
||||||
|
if (nextPostFetchFilterUrl.contains("?")) {
|
||||||
|
String resourceType = nextPostFetchFilterUrl.substring(0, nextPostFetchFilterUrl.indexOf('?'));
|
||||||
|
if (nextResourceType.equals(resourceType)) {
|
||||||
|
InMemoryMatchResult matchResult = myInMemoryResourceMatcher.match(nextPostFetchFilterUrl, nextResource, null, new SystemRequestDetails());
|
||||||
|
if (matchResult.matched()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
private List<IBaseResource> fetchAllResources(ResourceIdList theIds, RequestPartitionId theRequestPartitionId) {
|
private List<IBaseResource> fetchAllResources(ResourceIdList theIds, RequestPartitionId theRequestPartitionId) {
|
||||||
ArrayListMultimap<String, String> typeToIds = ArrayListMultimap.create();
|
ArrayListMultimap<String, String> typeToIds = ArrayListMultimap.create();
|
||||||
theIds.getIds().forEach(t -> typeToIds.put(t.getResourceType(), t.getId()));
|
theIds.getIds().forEach(t -> typeToIds.put(t.getResourceType(), t.getId()));
|
||||||
|
|
|
@ -48,6 +48,9 @@ public class BulkExportParameters extends Batch2BaseJobParameters {
|
||||||
*/
|
*/
|
||||||
private List<String> myFilters;
|
private List<String> myFilters;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* URLs to be applied by the inMemoryMatcher after the SQL select
|
||||||
|
*/
|
||||||
private List<String> myPostFetchFilterUrls;
|
private List<String> myPostFetchFilterUrls;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue