Fixed bug for large ValueSet expansion with URL parameter; return 404 for unknown ValueSets.

This commit is contained in:
Diederik Muylwyk 2019-09-09 18:41:00 -04:00
parent 2052df3152
commit 7e76c1893f
3 changed files with 44 additions and 19 deletions

View File

@ -488,7 +488,7 @@ public abstract class BaseHapiTerminologySvcImpl implements IHapiTerminologySvc,
}
if (!optionalTermValueSet.isPresent()) {
ourLog.warn("ValueSet is not present in terminology tables. Will perform in-memory expansion without parameters. Will schedule this ValueSet for pre-expansion. {}", getValueSetInfo(theValueSetToExpand));
ourLog.warn("ValueSet is not present in terminology tables. Will perform in-memory expansion without parameters. {}", getValueSetInfo(theValueSetToExpand));
return expandValueSet(theValueSetToExpand); // In-memory expansion.
}
@ -947,8 +947,7 @@ public abstract class BaseHapiTerminologySvcImpl implements IHapiTerminologySvc,
Optional<TermValueSet> optionalTermValueSet = myValueSetDao.findByResourcePid(valueSetResourcePid);
if (!optionalTermValueSet.isPresent()) {
ourLog.warn("ValueSet is not present in terminology tables. Will perform in-memory code validation. Will schedule this ValueSet for pre-expansion. {}", getValueSetInfo(theValueSet));
myDeferredValueSets.add(theValueSet);
ourLog.warn("ValueSet is not present in terminology tables. Will perform in-memory code validation. {}", getValueSetInfo(theValueSet));
return false;
}

View File

@ -9,6 +9,7 @@ import ca.uhn.fhir.jpa.entity.TermConceptParentChildLink.RelationshipTypeEnum;
import ca.uhn.fhir.jpa.model.entity.ResourceTable;
import ca.uhn.fhir.jpa.term.IHapiTerminologySvc;
import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException;
import ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException;
import ca.uhn.fhir.rest.server.servlet.ServletRequestDetails;
import ca.uhn.fhir.util.TestUtil;
import ca.uhn.fhir.util.UrlUtil;
@ -311,8 +312,7 @@ public class ResourceProviderR4ValueSetTest extends BaseResourceProviderR4Test {
.operation()
.onType(ValueSet.class)
.named("expand")
// .withParameter(Parameters.class, "url", new UriType("http://www.healthintersections.com.au/fhir/ValueSet/extensional-case-2")) //FIXME: DM
.withParameter(Parameters.class, "url", new UriType("http://www.healthintersections.com.au/fhir/ValueSet/bogus"))
.withParameter(Parameters.class, "url", new UriType("http://www.healthintersections.com.au/fhir/ValueSet/extensional-case-2"))
.execute();
ValueSet expanded = (ValueSet) respParam.getParameter().get(0).getResource();
@ -325,21 +325,34 @@ public class ResourceProviderR4ValueSetTest extends BaseResourceProviderR4Test {
}
@Test
public void testExpandByUrlWithPreExpansion() throws Exception {//FIXME: DM
public void testExpandByUrlWithBogusUrl() throws Exception {
loadAndPersistCodeSystemAndValueSet(HttpVerb.POST);
try {
ourClient
.operation()
.onType(ValueSet.class)
.named("expand")
.withParameter(Parameters.class, "url", new UriType("http://www.healthintersections.com.au/fhir/ValueSet/bogus"))
.execute();
} catch (ResourceNotFoundException e) {
assertEquals(404, e.getStatusCode());
assertEquals("HTTP 404 Not Found: Unknown ValueSet: http%3A%2F%2Fwww.healthintersections.com.au%2Ffhir%2FValueSet%2Fbogus", e.getMessage());
}
}
@Test
public void testExpandByUrlWithPreExpansion() throws Exception {
myDaoConfig.setPreExpandValueSetsExperimental(true);
ourLog.info("DIEDERIK - before loading CD and VS");
loadAndPersistCodeSystemAndValueSet(HttpVerb.POST);
ourLog.info("DIEDERIK - after loading CD and VS; before pre-expansion");
myTermSvc.preExpandDeferredValueSetsToTerminologyTables();
ourLog.info("DIEDERIK - after pre-expansion");
Parameters respParam = ourClient
.operation()
.onType(ValueSet.class)
.named("expand")
// .withParameter(Parameters.class, "url", new UriType("http://www.healthintersections.com.au/fhir/ValueSet/extensional-case-2")) //FIXME: DM
.withParameter(Parameters.class, "url", new UriType("http://www.healthintersections.com.au/fhir/ValueSet/bogus"))
.withParameter(Parameters.class, "url", new UriType("http://www.healthintersections.com.au/fhir/ValueSet/extensional-case-2"))
.execute();
ValueSet expanded = (ValueSet) respParam.getParameter().get(0).getResource();
@ -351,6 +364,26 @@ public class ResourceProviderR4ValueSetTest extends BaseResourceProviderR4Test {
}
@Test
public void testExpandByUrlWithPreExpansionAndBogusUrl() throws Exception {
myDaoConfig.setPreExpandValueSetsExperimental(true);
loadAndPersistCodeSystemAndValueSet(HttpVerb.POST);
myTermSvc.preExpandDeferredValueSetsToTerminologyTables();
try {
Parameters respParam = ourClient
.operation()
.onType(ValueSet.class)
.named("expand")
.withParameter(Parameters.class, "url", new UriType("http://www.healthintersections.com.au/fhir/ValueSet/bogus"))
.execute();
} catch (ResourceNotFoundException e) {
assertEquals(404, e.getStatusCode());
assertEquals("HTTP 404 Not Found: Unknown ValueSet: http%3A%2F%2Fwww.healthintersections.com.au%2Ffhir%2FValueSet%2Fbogus", e.getMessage());
}
}
@Test
public void testExpandByValueSet() throws IOException {
loadAndPersistCodeSystem(HttpVerb.POST);

View File

@ -885,19 +885,12 @@ public class TerminologySvcImplR4Test extends BaseJpaR4Test {
assertEquals("Systolic blood pressure 8 hour minimum", containsComponent.getDisplay());
assertFalse(containsComponent.hasDesignation());
myTermSvc.saveDeferred();
myTermSvc.preExpandDeferredValueSetsToTerminologyTables();
expandedValueSet = myTermSvc.expandValueSet(valueSet, myDaoConfig.getPreExpandValueSetsDefaultOffsetExperimental(), myDaoConfig.getPreExpandValueSetsDefaultCountExperimental());
ourLog.info("Expanded ValueSet:\n" + myFhirCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(expandedValueSet));
assertEquals(codeSystem.getConcept().size(), expandedValueSet.getExpansion().getTotal());
assertEquals(myDaoConfig.getPreExpandValueSetsDefaultOffsetExperimental(), expandedValueSet.getExpansion().getOffset());
assertEquals(2, expandedValueSet.getExpansion().getParameter().size());
assertEquals("offset", expandedValueSet.getExpansion().getParameter().get(0).getName());
assertEquals(0, expandedValueSet.getExpansion().getParameter().get(0).getValueIntegerType().getValue().intValue());
assertEquals("count", expandedValueSet.getExpansion().getParameter().get(1).getName());
assertEquals(1000, expandedValueSet.getExpansion().getParameter().get(1).getValueIntegerType().getValue().intValue());
assertEquals(0, expandedValueSet.getExpansion().getParameter().size());
assertEquals(codeSystem.getConcept().size(), expandedValueSet.getExpansion().getContains().size());