Add tests for term svc

This commit is contained in:
James Agnew 2016-06-29 09:56:05 -04:00
parent d7fdaf7618
commit ea99672e6c
5 changed files with 40 additions and 37 deletions

View File

@ -23,21 +23,15 @@ package ca.uhn.fhir.jpa.dao.dstu3;
import static org.apache.commons.lang3.StringUtils.isBlank; import static org.apache.commons.lang3.StringUtils.isBlank;
import static org.apache.commons.lang3.StringUtils.isNotBlank; import static org.apache.commons.lang3.StringUtils.isNotBlank;
import java.nio.file.FileVisitOption;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.Date;
import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
import org.apache.commons.codec.binary.StringUtils; import org.apache.commons.codec.binary.StringUtils;
import org.hl7.fhir.dstu3.exceptions.TerminologyServiceException;
import org.hl7.fhir.dstu3.hapi.validation.HapiWorkerContext; import org.hl7.fhir.dstu3.hapi.validation.HapiWorkerContext;
import org.hl7.fhir.dstu3.hapi.validation.IValidationSupport; import org.hl7.fhir.dstu3.hapi.validation.IValidationSupport;
import org.hl7.fhir.dstu3.hapi.validation.IValidationSupport.CodeValidationResult;
import org.hl7.fhir.dstu3.model.CodeSystem; import org.hl7.fhir.dstu3.model.CodeSystem;
import org.hl7.fhir.dstu3.model.CodeSystem.ConceptDefinitionComponent;
import org.hl7.fhir.dstu3.model.CodeableConcept; import org.hl7.fhir.dstu3.model.CodeableConcept;
import org.hl7.fhir.dstu3.model.Coding; import org.hl7.fhir.dstu3.model.Coding;
import org.hl7.fhir.dstu3.model.IdType; import org.hl7.fhir.dstu3.model.IdType;
@ -46,7 +40,6 @@ import org.hl7.fhir.dstu3.model.ValueSet;
import org.hl7.fhir.dstu3.model.ValueSet.ConceptSetComponent; import org.hl7.fhir.dstu3.model.ValueSet.ConceptSetComponent;
import org.hl7.fhir.dstu3.model.ValueSet.ConceptSetFilterComponent; import org.hl7.fhir.dstu3.model.ValueSet.ConceptSetFilterComponent;
import org.hl7.fhir.dstu3.model.ValueSet.FilterOperator; import org.hl7.fhir.dstu3.model.ValueSet.FilterOperator;
import org.hl7.fhir.dstu3.model.ValueSet.ValueSetExpansionComponent;
import org.hl7.fhir.dstu3.model.ValueSet.ValueSetExpansionContainsComponent; import org.hl7.fhir.dstu3.model.ValueSet.ValueSetExpansionContainsComponent;
import org.hl7.fhir.dstu3.terminologies.ValueSetExpander.ValueSetExpansionOutcome; import org.hl7.fhir.dstu3.terminologies.ValueSetExpander.ValueSetExpansionOutcome;
import org.hl7.fhir.instance.model.api.IIdType; import org.hl7.fhir.instance.model.api.IIdType;
@ -86,12 +79,14 @@ public class FhirResourceDaoValueSetDstu3 extends FhirResourceDaoDstu3<ValueSet>
HapiWorkerContext workerContext = new HapiWorkerContext(getContext(), myValidationSupport); HapiWorkerContext workerContext = new HapiWorkerContext(getContext(), myValidationSupport);
ValueSetExpansionOutcome outcome = workerContext.expand(theSource); ValueSetExpansionOutcome outcome = workerContext.expand(theSource);
ValueSetExpansionComponent expansion = outcome.getValueset().getExpansion(); return outcome.getValueset();
ValueSet retVal = new ValueSet(); // ValueSetExpansionComponent expansion = outcome.getValueset().getExpansion();
retVal.getMeta().setLastUpdated(new Date()); //
retVal.setExpansion(expansion); // ValueSet retVal = new ValueSet();
return retVal; // retVal.getMeta().setLastUpdated(new Date());
// retVal.setExpansion(expansion);
// return retVal;
} }
private void validateIncludes(String name, List<ConceptSetComponent> listToValidate) { private void validateIncludes(String name, List<ConceptSetComponent> listToValidate) {

View File

@ -29,7 +29,6 @@ import java.util.List;
import java.util.Set; import java.util.Set;
import org.apache.lucene.search.Query; import org.apache.lucene.search.Query;
import org.apache.lucene.search.QueryWrapperFilter;
import org.hibernate.search.jpa.FullTextEntityManager; import org.hibernate.search.jpa.FullTextEntityManager;
import org.hibernate.search.jpa.FullTextQuery; import org.hibernate.search.jpa.FullTextQuery;
import org.hibernate.search.query.dsl.BooleanJunction; import org.hibernate.search.query.dsl.BooleanJunction;

View File

@ -34,11 +34,14 @@ import ca.uhn.fhir.jpa.entity.ResourceTable;
import ca.uhn.fhir.jpa.entity.TermCodeSystemVersion; import ca.uhn.fhir.jpa.entity.TermCodeSystemVersion;
import ca.uhn.fhir.jpa.entity.TermConcept; import ca.uhn.fhir.jpa.entity.TermConcept;
import ca.uhn.fhir.jpa.entity.TermConceptParentChildLink.RelationshipTypeEnum; import ca.uhn.fhir.jpa.entity.TermConceptParentChildLink.RelationshipTypeEnum;
import ca.uhn.fhir.parser.IParser;
import ca.uhn.fhir.rest.param.TokenParam; import ca.uhn.fhir.rest.param.TokenParam;
import ca.uhn.fhir.rest.param.TokenParamModifier; import ca.uhn.fhir.rest.param.TokenParamModifier;
import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException; import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException;
import ca.uhn.fhir.rest.server.exceptions.UnprocessableEntityException; import ca.uhn.fhir.rest.server.exceptions.UnprocessableEntityException;
import ca.uhn.fhir.util.TestUtil; import ca.uhn.fhir.util.TestUtil;
import ca.uhn.fhir.validation.FhirValidator;
import ca.uhn.fhir.validation.ValidationResult;
public class FhirResourceDaoDstu3TerminologyTest extends BaseJpaDstu3Test { public class FhirResourceDaoDstu3TerminologyTest extends BaseJpaDstu3Test {
@ -192,14 +195,29 @@ public class FhirResourceDaoDstu3TerminologyTest extends BaseJpaDstu3Test {
exclude.addConcept().setCode("childAAA"); exclude.addConcept().setCode("childAAA");
ValueSet result = myValueSetDao.expand(vs, null); ValueSet result = myValueSetDao.expand(vs, null);
logAndValidateValueSet(result);
String encoded = myFhirCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(result);
ourLog.info(encoded);
ArrayList<String> codes = toCodesContains(result.getExpansion().getContains()); ArrayList<String> codes = toCodesContains(result.getExpansion().getContains());
assertThat(codes, containsInAnyOrder("ParentA", "ParentB", "childAB", "childAAB", "ParentC", "childBA", "childCA")); assertThat(codes, containsInAnyOrder("ParentA", "ParentB", "childAB", "childAAB", "ParentC", "childBA", "childCA"));
} }
private void logAndValidateValueSet(ValueSet theResult) {
IParser parser = myFhirCtx.newXmlParser().setPrettyPrint(true);
String encoded = parser.encodeResourceToString(theResult);
ourLog.info(encoded);
FhirValidator validator = myFhirCtx.newValidator();
validator.setValidateAgainstStandardSchema(true);
validator.setValidateAgainstStandardSchematron(true);
ValidationResult result = validator.validateWithResult(theResult);
if (!result.isSuccessful()) {
ourLog.info(parser.encodeResourceToString(result.toOperationOutcome()));
fail(parser.encodeResourceToString(result.toOperationOutcome()));
}
}
@Test @Test
public void testExpandWithInvalidExclude() { public void testExpandWithInvalidExclude() {
createExternalCsAndLocalVs(); createExternalCsAndLocalVs();
@ -273,9 +291,7 @@ public class FhirResourceDaoDstu3TerminologyTest extends BaseJpaDstu3Test {
include.addFilter().setProperty("display").setOp(FilterOperator.EQUAL).setValue("Parent B"); include.addFilter().setProperty("display").setOp(FilterOperator.EQUAL).setValue("Parent B");
ValueSet result = myValueSetDao.expand(vs, null); ValueSet result = myValueSetDao.expand(vs, null);
logAndValidateValueSet(result);
String encoded = myFhirCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(result);
ourLog.info(encoded);
ArrayList<String> codes = toCodesContains(result.getExpansion().getContains()); ArrayList<String> codes = toCodesContains(result.getExpansion().getContains());
assertThat(codes, containsInAnyOrder("ParentA", "childAA", "childAAA", "ParentB")); assertThat(codes, containsInAnyOrder("ParentA", "childAA", "childAAA", "ParentB"));
@ -295,8 +311,7 @@ public class FhirResourceDaoDstu3TerminologyTest extends BaseJpaDstu3Test {
include.setSystem(URL_MY_CODE_SYSTEM); include.setSystem(URL_MY_CODE_SYSTEM);
include.addFilter().setProperty("display").setOp(FilterOperator.EQUAL).setValue("parent a"); include.addFilter().setProperty("display").setOp(FilterOperator.EQUAL).setValue("parent a");
ValueSet result = myValueSetDao.expand(vs, null); ValueSet result = myValueSetDao.expand(vs, null);
String encoded = myFhirCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(result); logAndValidateValueSet(result);
ourLog.info(encoded);
ArrayList<String> codes = toCodesContains(result.getExpansion().getContains()); ArrayList<String> codes = toCodesContains(result.getExpansion().getContains());
assertThat(codes, containsInAnyOrder("ParentA")); assertThat(codes, containsInAnyOrder("ParentA"));
@ -305,8 +320,7 @@ public class FhirResourceDaoDstu3TerminologyTest extends BaseJpaDstu3Test {
include.setSystem(URL_MY_CODE_SYSTEM); include.setSystem(URL_MY_CODE_SYSTEM);
include.addFilter().setProperty("display").setOp(FilterOperator.EQUAL).setValue("pare"); include.addFilter().setProperty("display").setOp(FilterOperator.EQUAL).setValue("pare");
result = myValueSetDao.expand(vs, null); result = myValueSetDao.expand(vs, null);
encoded = myFhirCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(result); logAndValidateValueSet(result);
ourLog.info(encoded);
codes = toCodesContains(result.getExpansion().getContains()); codes = toCodesContains(result.getExpansion().getContains());
assertThat(codes, containsInAnyOrder("ParentA", "ParentB", "ParentC")); assertThat(codes, containsInAnyOrder("ParentA", "ParentB", "ParentC"));
@ -315,8 +329,7 @@ public class FhirResourceDaoDstu3TerminologyTest extends BaseJpaDstu3Test {
include.setSystem(URL_MY_CODE_SYSTEM); include.setSystem(URL_MY_CODE_SYSTEM);
include.addFilter().setProperty("display:exact").setOp(FilterOperator.EQUAL).setValue("pare"); include.addFilter().setProperty("display:exact").setOp(FilterOperator.EQUAL).setValue("pare");
result = myValueSetDao.expand(vs, null); result = myValueSetDao.expand(vs, null);
encoded = myFhirCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(result); logAndValidateValueSet(result);
ourLog.info(encoded);
codes = toCodesContains(result.getExpansion().getContains()); codes = toCodesContains(result.getExpansion().getContains());
assertThat(codes, empty()); assertThat(codes, empty());
@ -337,9 +350,7 @@ public class FhirResourceDaoDstu3TerminologyTest extends BaseJpaDstu3Test {
include.addFilter().setProperty("display").setOp(FilterOperator.EQUAL).setValue("AAA"); include.addFilter().setProperty("display").setOp(FilterOperator.EQUAL).setValue("AAA");
ValueSet result = myValueSetDao.expand(vs, null); ValueSet result = myValueSetDao.expand(vs, null);
logAndValidateValueSet(result);
String encoded = myFhirCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(result);
ourLog.info(encoded);
ArrayList<String> codes = toCodesContains(result.getExpansion().getContains()); ArrayList<String> codes = toCodesContains(result.getExpansion().getContains());
assertThat(codes, containsInAnyOrder("AAA")); assertThat(codes, containsInAnyOrder("AAA"));
@ -363,9 +374,7 @@ public class FhirResourceDaoDstu3TerminologyTest extends BaseJpaDstu3Test {
include.addConcept().setCode("AB"); include.addConcept().setCode("AB");
ValueSet result = myValueSetDao.expand(vs, null); ValueSet result = myValueSetDao.expand(vs, null);
logAndValidateValueSet(result);
String encoded = myFhirCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(result);
ourLog.info(encoded);
ArrayList<String> codes = toCodesContains(result.getExpansion().getContains()); ArrayList<String> codes = toCodesContains(result.getExpansion().getContains());
assertThat(codes, containsInAnyOrder("A", "AA", "AAA", "AB")); assertThat(codes, containsInAnyOrder("A", "AA", "AAA", "AB"));
@ -393,8 +402,7 @@ public class FhirResourceDaoDstu3TerminologyTest extends BaseJpaDstu3Test {
include.addFilter().setProperty("concept").setOp(FilterOperator.ISA).setValue("ParentA"); include.addFilter().setProperty("concept").setOp(FilterOperator.ISA).setValue("ParentA");
ValueSet result = myValueSetDao.expand(vs, null); ValueSet result = myValueSetDao.expand(vs, null);
String encoded = myFhirCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(result); logAndValidateValueSet(result);
ourLog.info(encoded);
assertEquals(0, result.getExpansion().getContains().size()); assertEquals(0, result.getExpansion().getContains().size());
@ -412,11 +420,11 @@ public class FhirResourceDaoDstu3TerminologyTest extends BaseJpaDstu3Test {
include.setSystem(URL_MY_CODE_SYSTEM); include.setSystem(URL_MY_CODE_SYSTEM);
include.addFilter().setProperty("concept").setOp(FilterOperator.ISA).setValue("ParentA"); include.addFilter().setProperty("concept").setOp(FilterOperator.ISA).setValue("ParentA");
result = myValueSetDao.expand(vs, null); result = myValueSetDao.expand(vs, null);
encoded = myFhirCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(result); logAndValidateValueSet(result);
ourLog.info(encoded);
assertEquals(4, result.getExpansion().getContains().size()); assertEquals(4, result.getExpansion().getContains().size());
String encoded = myFhirCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(result);
assertThat(encoded, containsStringIgnoringCase("<code value=\"childAAB\"/>")); assertThat(encoded, containsStringIgnoringCase("<code value=\"childAAB\"/>"));
} }

View File

@ -43,7 +43,6 @@ import org.hl7.fhir.instance.model.api.IBaseResource;
import ca.uhn.fhir.context.RuntimeResourceDefinition; import ca.uhn.fhir.context.RuntimeResourceDefinition;
import ca.uhn.fhir.context.RuntimeSearchParam; import ca.uhn.fhir.context.RuntimeSearchParam;
import ca.uhn.fhir.model.api.IResource;
import ca.uhn.fhir.model.dstu2.resource.Conformance; import ca.uhn.fhir.model.dstu2.resource.Conformance;
import ca.uhn.fhir.model.dstu2.resource.Conformance.Rest; import ca.uhn.fhir.model.dstu2.resource.Conformance.Rest;
import ca.uhn.fhir.model.dstu2.resource.Conformance.RestResource; import ca.uhn.fhir.model.dstu2.resource.Conformance.RestResource;

View File

@ -45,6 +45,7 @@ import org.apache.commons.lang3.NotImplementedException;
import org.hl7.fhir.dstu3.model.CodeSystem; import org.hl7.fhir.dstu3.model.CodeSystem;
import org.hl7.fhir.dstu3.model.CodeSystem.CodeSystemContentMode; import org.hl7.fhir.dstu3.model.CodeSystem.CodeSystemContentMode;
import org.hl7.fhir.dstu3.model.CodeSystem.ConceptDefinitionComponent; import org.hl7.fhir.dstu3.model.CodeSystem.ConceptDefinitionComponent;
import org.hl7.fhir.dstu3.model.Enumerations.ConformanceResourceStatus;
import org.hl7.fhir.dstu3.model.DateTimeType; import org.hl7.fhir.dstu3.model.DateTimeType;
import org.hl7.fhir.dstu3.model.Factory; import org.hl7.fhir.dstu3.model.Factory;
import org.hl7.fhir.dstu3.model.PrimitiveType; import org.hl7.fhir.dstu3.model.PrimitiveType;
@ -170,6 +171,7 @@ public class ValueSetExpanderSimple implements ValueSetExpander {
focus.setExpansion(new ValueSet.ValueSetExpansionComponent()); focus.setExpansion(new ValueSet.ValueSetExpansionComponent());
focus.getExpansion().setTimestampElement(DateTimeType.now()); focus.getExpansion().setTimestampElement(DateTimeType.now());
focus.getExpansion().setIdentifier(Factory.createUUID()); focus.getExpansion().setIdentifier(Factory.createUUID());
focus.setStatus(ConformanceResourceStatus.ACTIVE);
if (source.hasCompose()) if (source.hasCompose())
handleCompose(source.getCompose(), focus.getExpansion().getParameter()); handleCompose(source.getCompose(), focus.getExpansion().getParameter());