Skip to content

Commit

Permalink
Merge pull request #132 from DBCG/fix-130-retrieve-with-empty-valueset
Browse files Browse the repository at this point in the history
#130: Fixed retrieve with an empty value set returning all data inste…
  • Loading branch information
c-schuler authored Sep 10, 2019
2 parents a028c58 + a9ba097 commit 1361213
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 14 deletions.
34 changes: 25 additions & 9 deletions src/main/java/org/opencds/cqf/providers/JpaDataProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,28 +67,44 @@ public synchronized Iterable<Object> retrieve(String context, Object contextValu
}
}

boolean noResults = false;
if (codePath != null && !codePath.equals("")) {

if (valueSet != null && terminologyProvider != null && expandValueSets) {
ValueSetInfo valueSetInfo = new ValueSetInfo().withId(valueSet);
codes = terminologyProvider.expand(valueSetInfo);
}
else if (valueSet != null) {
map.add(convertPathToSearchParam(dataType, codePath), new TokenParam(null, valueSet).setModifier(TokenParamModifier.IN));
if (valueSet != null) {
if (expandValueSets) {
if (terminologyProvider == null) {
throw new IllegalArgumentException("Expand value sets cannot be used without a terminology provider and no terminology provider is set.");
}
ValueSetInfo valueSetInfo = new ValueSetInfo().withId(valueSet);
codes = terminologyProvider.expand(valueSetInfo);
}
else {
map.add(convertPathToSearchParam(dataType, codePath), new TokenParam(null, valueSet).setModifier(TokenParamModifier.IN));
}
}

if (codes != null) {
TokenOrListParam codeParams = new TokenOrListParam();
int codeCount = 0;
for (Code code : codes) {
codeCount++;
codeParams.addOr(new TokenParam(code.getSystem(), code.getCode()));
}
map.add(convertPathToSearchParam(dataType, codePath), codeParams);
if (codeParams.getListAsCodings().size() > 1023)
{
BooleanQuery.setMaxClauseCount(codeParams.getListAsCodings().size());
if (codeCount == 0) {
noResults = true;
}
if (codeCount > 1023) {
BooleanQuery.setMaxClauseCount(codeCount);
}
}
}

// If the retrieve is filtered to a value set that has no codes, there are no possible satisfying results, don't even search, just return empty
if (noResults) {
return new ArrayList();
}

if (dateRange != null) {
DateParam low = null;
DateParam high = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,19 +50,22 @@ public synchronized boolean in(Code code, ValueSetInfo valueSet) throws Resource
public synchronized Iterable<Code> expand(ValueSetInfo valueSet) throws ResourceNotFoundException {
List<Code> codes = new ArrayList<>();
boolean needsExpand = false;
ValueSet vs;
ValueSet vs = null;
if (valueSet.getId().startsWith("http://") || valueSet.getId().startsWith("https://")) {
if (valueSet.getVersion() != null || (valueSet.getCodeSystems() != null && valueSet.getCodeSystems().size() > 0)) {
throw new UnsupportedOperationException(String.format("Could not expand value set %s; version and code system bindings are not supported at this time.", valueSet.getId()));
}
IBundleProvider bundleProvider = valueSetResourceProvider.getDao().search(new SearchParameterMap().add(ValueSet.SP_URL, new UriParam(valueSet.getId())));
List<IBaseResource> valueSets = bundleProvider.getResources(0, bundleProvider.size());
if (!valueSets.isEmpty() && valueSets.size() == 1) {
if (valueSets.isEmpty()) {
throw new IllegalArgumentException(String.format("Could not resolve value set %s.", valueSet.getId()));
}
else if (valueSets.size() == 1) {
vs = (ValueSet) valueSets.get(0);
}
else if (valueSets.size() > 1) {
throw new IllegalArgumentException("Found more than 1 ValueSet with url: " + valueSet.getId());
}
else {
vs = null;
}
}
else {
vs = valueSetResourceProvider.getDao().read(new IdType(valueSet.getId()));
Expand Down

0 comments on commit 1361213

Please sign in to comment.