mirror of
https://github.com/hapifhir/hapi-fhir.git
synced 2025-02-17 02:15:22 +00:00
Additional tests.
This commit is contained in:
parent
732624bfaf
commit
e86d9deaac
@ -126,8 +126,7 @@ public class FhirResourceDaoValueSetDstu3 extends BaseHapiFhirResourceDao<ValueS
|
||||
filter.setValue(theFilter);
|
||||
}
|
||||
|
||||
ValueSet retVal = doExpand(source);
|
||||
return retVal;
|
||||
return doExpand(source);
|
||||
|
||||
// if (defaultValueSet != null) {
|
||||
// source = getContext().newJsonParser().parseResource(ValueSet.class, getContext().newJsonParser().encodeResourceToString(defaultValueSet));
|
||||
@ -161,8 +160,7 @@ public class FhirResourceDaoValueSetDstu3 extends BaseHapiFhirResourceDao<ValueS
|
||||
filter.setValue(theFilter);
|
||||
}
|
||||
|
||||
ValueSet retVal = doExpand(source, theOffset, theCount);
|
||||
return retVal;
|
||||
return doExpand(source, theOffset, theCount);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -40,6 +40,7 @@ import org.hl7.fhir.r4.model.Coding;
|
||||
import org.hl7.fhir.r4.model.IntegerType;
|
||||
import org.hl7.fhir.r4.model.ValueSet;
|
||||
import org.hl7.fhir.r4.model.ValueSet.ConceptSetComponent;
|
||||
import org.hl7.fhir.r4.model.ValueSet.ConceptSetFilterComponent;
|
||||
import org.hl7.fhir.r4.model.ValueSet.FilterOperator;
|
||||
import org.hl7.fhir.r4.model.ValueSet.ValueSetExpansionContainsComponent;
|
||||
|
||||
@ -102,7 +103,7 @@ public class FhirResourceDaoValueSetR4 extends BaseHapiFhirResourceDao<ValueSet>
|
||||
|
||||
if (isNotBlank(theFilter)) {
|
||||
ConceptSetComponent include = source.getCompose().addInclude();
|
||||
ValueSet.ConceptSetFilterComponent filter = include.addFilter();
|
||||
ConceptSetFilterComponent filter = include.addFilter();
|
||||
filter.setProperty("display");
|
||||
filter.setOp(FilterOperator.EQUAL);
|
||||
filter.setValue(theFilter);
|
||||
@ -135,10 +136,10 @@ public class FhirResourceDaoValueSetR4 extends BaseHapiFhirResourceDao<ValueSet>
|
||||
source.getCompose().addInclude().addValueSet(theUri);
|
||||
|
||||
if (isNotBlank(theFilter)) {
|
||||
ValueSet.ConceptSetComponent include = source.getCompose().addInclude();
|
||||
ValueSet.ConceptSetFilterComponent filter = include.addFilter();
|
||||
ConceptSetComponent include = source.getCompose().addInclude();
|
||||
ConceptSetFilterComponent filter = include.addFilter();
|
||||
filter.setProperty("display");
|
||||
filter.setOp(ValueSet.FilterOperator.EQUAL);
|
||||
filter.setOp(FilterOperator.EQUAL);
|
||||
filter.setValue(theFilter);
|
||||
}
|
||||
|
||||
|
@ -40,6 +40,7 @@ import org.hl7.fhir.r5.model.Enumerations;
|
||||
import org.hl7.fhir.r5.model.IntegerType;
|
||||
import org.hl7.fhir.r5.model.ValueSet;
|
||||
import org.hl7.fhir.r5.model.ValueSet.ConceptSetComponent;
|
||||
import org.hl7.fhir.r5.model.ValueSet.ConceptSetFilterComponent;
|
||||
import org.hl7.fhir.r5.model.ValueSet.ValueSetExpansionContainsComponent;
|
||||
|
||||
import java.util.Date;
|
||||
@ -102,13 +103,14 @@ public class FhirResourceDaoValueSetR5 extends BaseHapiFhirResourceDao<ValueSet>
|
||||
|
||||
if (isNotBlank(theFilter)) {
|
||||
ConceptSetComponent include = source.getCompose().addInclude();
|
||||
ValueSet.ConceptSetFilterComponent filter = include.addFilter();
|
||||
ConceptSetFilterComponent filter = include.addFilter();
|
||||
filter.setProperty("display");
|
||||
filter.setOp(Enumerations.FilterOperator.EQUAL);
|
||||
filter.setValue(theFilter);
|
||||
}
|
||||
|
||||
return doExpand(source);
|
||||
ValueSet retVal = doExpand(source);
|
||||
return retVal;
|
||||
|
||||
// if (defaultValueSet != null) {
|
||||
// source = getContext().newJsonParser().parseResource(ValueSet.class, getContext().newJsonParser().encodeResourceToString(defaultValueSet));
|
||||
@ -135,8 +137,8 @@ public class FhirResourceDaoValueSetR5 extends BaseHapiFhirResourceDao<ValueSet>
|
||||
source.getCompose().addInclude().addValueSet(theUri);
|
||||
|
||||
if (isNotBlank(theFilter)) {
|
||||
ValueSet.ConceptSetComponent include = source.getCompose().addInclude();
|
||||
ValueSet.ConceptSetFilterComponent filter = include.addFilter();
|
||||
ConceptSetComponent include = source.getCompose().addInclude();
|
||||
ConceptSetFilterComponent filter = include.addFilter();
|
||||
filter.setProperty("display");
|
||||
filter.setOp(Enumerations.FilterOperator.EQUAL);
|
||||
filter.setValue(theFilter);
|
||||
|
@ -59,7 +59,7 @@ public class BaseJpaResourceProviderCodeSystemR5 extends JpaResourceProviderR5<C
|
||||
@OperationParam(name="code", min=0, max=1) CodeType theCode,
|
||||
@OperationParam(name="system", min=0, max=1) UriType theSystem,
|
||||
@OperationParam(name="coding", min=0, max=1) Coding theCoding,
|
||||
@OperationParam(name="version", min=0, max=1) org.hl7.fhir.r4.model.StringType theVersion,
|
||||
@OperationParam(name="version", min=0, max=1) StringType theVersion,
|
||||
@OperationParam(name = "property", min = 0, max = OperationParam.MAX_UNLIMITED) List<CodeType> theProperties,
|
||||
RequestDetails theRequestDetails
|
||||
) {
|
||||
|
@ -142,4 +142,10 @@ public class TermReadSvcR5 extends BaseTermReadSvcImpl implements IValidationSup
|
||||
org.hl7.fhir.r4.model.ValueSet valueSetR4 = toCanonicalValueSet(valueSet);
|
||||
return super.isValueSetPreExpandedForCodeValidation(valueSetR4);
|
||||
}
|
||||
|
||||
@Override
|
||||
public LookupCodeResult lookupCode(ValidationSupportContext theValidationSupportContext, String theSystem, String theCode) {
|
||||
return super.lookupCode(theSystem, theCode);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
package ca.uhn.fhir.jpa.dao.dstu2;
|
||||
|
||||
import ca.uhn.fhir.context.support.IValidationSupport;
|
||||
import ca.uhn.fhir.jpa.api.dao.IFhirResourceDaoCodeSystem;
|
||||
import ca.uhn.fhir.model.dstu2.composite.CodeableConceptDt;
|
||||
import ca.uhn.fhir.model.dstu2.composite.CodingDt;
|
||||
import ca.uhn.fhir.model.dstu2.resource.ValueSet;
|
||||
@ -21,7 +22,9 @@ import static org.hamcrest.Matchers.not;
|
||||
import static org.hamcrest.Matchers.stringContainsInOrder;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
|
||||
|
||||
public class FhirResourceDaoValueSetDstu2Test extends BaseJpaDstu2Test {
|
||||
@ -229,5 +232,15 @@ public class FhirResourceDaoValueSetDstu2Test extends BaseJpaDstu2Test {
|
||||
assertThat(resp, not(containsString("<code value=\"8450-9\"/>")));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValidateCodeForCodeSystemOperationNotSupported() {
|
||||
try {
|
||||
((IFhirResourceDaoCodeSystem)myValueSetDao).validateCode(null, null, null, null, null, null, null, null);
|
||||
fail();
|
||||
} catch (UnsupportedOperationException theE) {
|
||||
assertNotNull(theE);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,7 +1,6 @@
|
||||
package ca.uhn.fhir.jpa.dao.dstu3;
|
||||
|
||||
import ca.uhn.fhir.jpa.term.TermReindexingSvcImpl;
|
||||
import ca.uhn.fhir.util.TestUtil;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.hl7.fhir.dstu3.model.CodeSystem;
|
||||
import org.hl7.fhir.dstu3.model.Enumerations;
|
||||
@ -13,6 +12,8 @@ import java.nio.charset.StandardCharsets;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
|
||||
public class FhirResourceDaoDstu3CodeSystemTest extends BaseJpaDstu3Test {
|
||||
@AfterAll
|
||||
@ -77,5 +78,17 @@ public class FhirResourceDaoDstu3CodeSystemTest extends BaseJpaDstu3Test {
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValidateCodeForCodeSystemOperationNotSupported() {
|
||||
try {
|
||||
myCodeSystemDao.validateCode(null, null, null, null, null, null, null, null);
|
||||
fail();
|
||||
} catch (UnsupportedOperationException theE) {
|
||||
assertNotNull(theE);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
@ -9,14 +9,12 @@ import org.junit.jupiter.api.AfterAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
public class FhirResourceDaoR4CodeSystemTest extends BaseJpaR4Test {
|
||||
|
||||
|
@ -337,6 +337,34 @@ public class FhirResourceDaoR4SearchWithLuceneDisabledTest extends BaseJpaTest {
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExpandValueSetContainingSystemIncludeAndExcludeWithNoCodes() throws IOException {
|
||||
CodeSystem cs = loadResourceFromClasspath(CodeSystem.class, "/r4/iar/CodeSystem-iar-citizenship-status.xml");
|
||||
myCodeSystemDao.create(cs);
|
||||
|
||||
ValueSet vs = loadResourceFromClasspath(ValueSet.class, "/r4/iar/ValueSet-iar-citizenship-status.xml");
|
||||
ValueSet.ConceptSetComponent excludeComponent = new ValueSet.ConceptSetComponent().setSystem("http://ccim.on.ca/fhir/iar/CodeSystem/iar-citizenship-status");
|
||||
excludeComponent.addConcept().setCode("REF");
|
||||
vs.getCompose().addExclude(excludeComponent);
|
||||
myValueSetDao.create(vs);
|
||||
|
||||
CodeSystem cs2 = loadResourceFromClasspath(CodeSystem.class, "/extensional-case-3-cs.xml");
|
||||
myCodeSystemDao.create(cs2);
|
||||
|
||||
ValueSet vs2 = loadResourceFromClasspath(ValueSet.class, "/extensional-case-3-vs-with-exclude.xml");
|
||||
myValueSetDao.create(vs2);
|
||||
|
||||
ValueSet expansion = myValueSetDao.expandByIdentifier("http://ccim.on.ca/fhir/iar/ValueSet/iar-citizenship-status", null);
|
||||
ourLog.info(myFhirCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(expansion));
|
||||
|
||||
assertEquals(5, expansion.getExpansion().getContains().size());
|
||||
|
||||
ValueSet expansion2 = myValueSetDao.expandByIdentifier("http://www.healthintersections.com.au/fhir/ValueSet/extensional-case-2", null);
|
||||
ourLog.info(myFhirCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(expansion2));
|
||||
|
||||
assertEquals(22, expansion2.getExpansion().getContains().size());
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,175 @@
|
||||
package ca.uhn.fhir.jpa.dao.r5;
|
||||
|
||||
import ca.uhn.fhir.jpa.model.entity.ResourceTable;
|
||||
import ca.uhn.fhir.jpa.term.TermReindexingSvcImpl;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.hl7.fhir.instance.model.api.IIdType;
|
||||
import org.hl7.fhir.r5.model.CodeSystem;
|
||||
import org.junit.jupiter.api.AfterAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
|
||||
public class FhirResourceDaoR5CodeSystemTest extends BaseJpaR5Test {
|
||||
|
||||
@Test
|
||||
public void testDeleteLargeCompleteCodeSystem() {
|
||||
|
||||
IIdType id = createLargeCodeSystem(null);
|
||||
|
||||
runInTransaction(() -> {
|
||||
assertEquals(1, myTermCodeSystemDao.count());
|
||||
assertNotNull(myTermCodeSystemDao.findByCodeSystemUri("http://foo"));
|
||||
assertEquals(1, myTermCodeSystemVersionDao.count());
|
||||
assertEquals(222, myTermConceptDao.count());
|
||||
});
|
||||
|
||||
myCodeSystemDao.delete(id);
|
||||
|
||||
// Nothing is deleted initially but the URI is changed so it can't be found
|
||||
runInTransaction(() -> {
|
||||
assertEquals(1, myTermCodeSystemDao.count());
|
||||
assertNull(myTermCodeSystemDao.findByCodeSystemUri("http://foo"));
|
||||
assertEquals(1, myTermCodeSystemVersionDao.count());
|
||||
assertEquals(222, myTermConceptDao.count());
|
||||
});
|
||||
|
||||
// Now the background scheduler will do its thing
|
||||
myTermDeferredStorageSvc.saveDeferred();
|
||||
runInTransaction(() -> {
|
||||
assertEquals(1, myTermCodeSystemDao.count());
|
||||
assertEquals(0, myTermCodeSystemVersionDao.count());
|
||||
assertEquals(0, myTermConceptDao.count());
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeleteCodeSystemVersion() {
|
||||
|
||||
// Create code system with two versions.
|
||||
IIdType id_first = createLargeCodeSystem("1");
|
||||
|
||||
runInTransaction(() -> {
|
||||
assertEquals(1, myTermCodeSystemDao.count());
|
||||
assertNotNull(myTermCodeSystemDao.findByCodeSystemUri("http://foo"));
|
||||
assertEquals(1, myTermCodeSystemVersionDao.count());
|
||||
List<ResourceTable> resourceList = myResourceTableDao.findAll();
|
||||
assertEquals(222, myTermConceptDao.count());
|
||||
assertEquals(1, resourceList.size());
|
||||
assertNull(resourceList.get(0).getDeleted());
|
||||
});
|
||||
|
||||
IIdType id_second = createLargeCodeSystem("2");
|
||||
|
||||
runInTransaction(() -> {
|
||||
assertEquals(1, myTermCodeSystemDao.count());
|
||||
assertNotNull(myTermCodeSystemDao.findByCodeSystemUri("http://foo"));
|
||||
assertEquals(2, myTermCodeSystemVersionDao.count());
|
||||
assertEquals(444, myTermConceptDao.count());
|
||||
List<ResourceTable> resourceList = myResourceTableDao.findAll();
|
||||
assertEquals(2, resourceList.size());
|
||||
long active = resourceList
|
||||
.stream()
|
||||
.filter(t -> t.getDeleted() == null).count();
|
||||
assertEquals(2, active);
|
||||
});
|
||||
|
||||
// Attempt to delete first version
|
||||
myCodeSystemDao.delete(id_first, mySrd);
|
||||
|
||||
// Only the resource will be deleted initially
|
||||
runInTransaction(() -> {
|
||||
assertEquals(1, myTermCodeSystemDao.count());
|
||||
assertNotNull(myTermCodeSystemDao.findByCodeSystemUri("http://foo"));
|
||||
assertEquals(2, myTermCodeSystemVersionDao.count());
|
||||
assertEquals(444, myTermConceptDao.count());
|
||||
List<ResourceTable> resourceList = myResourceTableDao.findAll();
|
||||
assertEquals(2, resourceList.size());
|
||||
long active = resourceList
|
||||
.stream()
|
||||
.filter(t -> t.getDeleted() == null).count();
|
||||
assertEquals(1, active);
|
||||
});
|
||||
|
||||
// Now the background scheduler will do its thing
|
||||
myTermDeferredStorageSvc.saveDeferred();
|
||||
|
||||
// Entities for first resource should be gone now.
|
||||
runInTransaction(() -> {
|
||||
assertEquals(1, myTermCodeSystemDao.count());
|
||||
assertNotNull(myTermCodeSystemDao.findByCodeSystemUri("http://foo"));
|
||||
assertEquals(1, myTermCodeSystemVersionDao.count());
|
||||
assertEquals(222, myTermConceptDao.count());
|
||||
List<ResourceTable> resourceList = myResourceTableDao.findAll();
|
||||
assertEquals(2, resourceList.size());
|
||||
long active = resourceList
|
||||
.stream()
|
||||
.filter(t -> t.getDeleted() == null).count();
|
||||
assertEquals(1, active);
|
||||
});
|
||||
|
||||
// Attempt to delete second version
|
||||
myCodeSystemDao.delete(id_second, mySrd);
|
||||
|
||||
// Only the resource will be deleted initially, but the URL for the TermCodeSystem will be cleared and not searchable.
|
||||
runInTransaction(() -> {
|
||||
assertEquals(1, myTermCodeSystemDao.count());
|
||||
assertNull(myTermCodeSystemDao.findByCodeSystemUri("http://foo"));
|
||||
assertEquals(1, myTermCodeSystemVersionDao.count());
|
||||
assertEquals(222, myTermConceptDao.count());
|
||||
List<ResourceTable> resourceList = myResourceTableDao.findAll();
|
||||
assertEquals(2, resourceList.size());
|
||||
long active = resourceList
|
||||
.stream()
|
||||
.filter(t -> t.getDeleted() == null).count();
|
||||
assertEquals(0, active);
|
||||
});
|
||||
|
||||
// Now the background scheduler will do its thing
|
||||
myTermDeferredStorageSvc.saveDeferred();
|
||||
|
||||
// The remaining versions and Code System entities should be gone now.
|
||||
runInTransaction(() -> {
|
||||
assertEquals(1, myTermCodeSystemDao.count());
|
||||
assertNull(myTermCodeSystemDao.findByCodeSystemUri("http://foo"));
|
||||
assertEquals(0, myTermCodeSystemVersionDao.count());
|
||||
List<ResourceTable> resourceList = myResourceTableDao.findAll();
|
||||
assertEquals(2, resourceList.size());
|
||||
long active = resourceList
|
||||
.stream()
|
||||
.filter(t -> t.getDeleted() == null).count();
|
||||
assertEquals(0, active);
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
private IIdType createLargeCodeSystem(String theVersion) {
|
||||
CodeSystem cs = new CodeSystem();
|
||||
cs.setContent(CodeSystem.CodeSystemContentMode.COMPLETE);
|
||||
cs.setUrl("http://foo");
|
||||
if (theVersion != null) {
|
||||
cs.setVersion(theVersion);
|
||||
}
|
||||
for (int i = 0; i < 222; i++) {
|
||||
cs.addConcept().setCode("CODE" + i);
|
||||
}
|
||||
IIdType id = myCodeSystemDao.create(cs).getId().toUnqualifiedVersionless();
|
||||
myTermDeferredStorageSvc.saveDeferred();
|
||||
myTermDeferredStorageSvc.saveDeferred();
|
||||
return id;
|
||||
}
|
||||
|
||||
@AfterAll
|
||||
public static void afterClassClearContext() {
|
||||
TermReindexingSvcImpl.setForceSaveDeferredAlwaysForUnitTest(false);
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -2,6 +2,12 @@ package ca.uhn.fhir.jpa.provider.r5;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import ca.uhn.fhir.jpa.api.model.DaoMethodOutcome;
|
||||
import ca.uhn.fhir.jpa.model.entity.ResourceTable;
|
||||
import ca.uhn.fhir.jpa.model.util.JpaConstants;
|
||||
import org.hl7.fhir.r4.model.codesystems.ConceptSubsumptionOutcome;
|
||||
import org.hl7.fhir.r5.model.Enumerations;
|
||||
import org.hl7.fhir.r5.model.Coding;
|
||||
import org.hl7.fhir.r5.model.BooleanType;
|
||||
import org.hl7.fhir.r5.model.CodeSystem;
|
||||
import org.hl7.fhir.r5.model.CodeSystem.ConceptDefinitionComponent;
|
||||
@ -9,12 +15,40 @@ import org.hl7.fhir.r5.model.CodeType;
|
||||
import org.hl7.fhir.r5.model.Parameters;
|
||||
import org.hl7.fhir.r5.model.StringType;
|
||||
import org.hl7.fhir.r5.model.UriType;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class ResourceProviderR5CodeSystemTest extends BaseResourceProviderR5Test {
|
||||
private static final String SYSTEM_PARENTCHILD = "http://parentchild";
|
||||
private static final Logger ourLog = LoggerFactory.getLogger(ResourceProviderR5CodeSystemTest.class);
|
||||
private Long parentChildCsId;
|
||||
|
||||
@BeforeEach
|
||||
@Transactional
|
||||
public void before02() throws IOException {
|
||||
CodeSystem cs = loadResourceFromClasspath(CodeSystem.class, "/extensional-case-3-cs.xml");
|
||||
myCodeSystemDao.create(cs, mySrd);
|
||||
|
||||
CodeSystem parentChildCs = new CodeSystem();
|
||||
parentChildCs.setUrl(SYSTEM_PARENTCHILD);
|
||||
parentChildCs.setName("Parent Child CodeSystem");
|
||||
parentChildCs.setStatus(Enumerations.PublicationStatus.ACTIVE);
|
||||
parentChildCs.setContent(CodeSystem.CodeSystemContentMode.COMPLETE);
|
||||
parentChildCs.setHierarchyMeaning(CodeSystem.CodeSystemHierarchyMeaning.ISA);
|
||||
|
||||
CodeSystem.ConceptDefinitionComponent parentA = parentChildCs.addConcept().setCode("ParentA").setDisplay("Parent A");
|
||||
parentA.addConcept().setCode("ChildAA").setDisplay("Child AA");
|
||||
parentChildCs.addConcept().setCode("ParentB").setDisplay("Parent B");
|
||||
|
||||
DaoMethodOutcome parentChildCsOutcome = myCodeSystemDao.create(parentChildCs);
|
||||
parentChildCsId = ((ResourceTable)parentChildCsOutcome.getEntity()).getId();
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValidateCodeWithUrlAndVersion_v1() {
|
||||
@ -36,7 +70,47 @@ public class ResourceProviderR5CodeSystemTest extends BaseResourceProviderR5Test
|
||||
assertEquals(true, ((BooleanType) respParam.getParameter().get(0).getValue()).booleanValue());
|
||||
assertEquals("Code v1 display", ((StringType) respParam.getParameter().get(1).getValue()).getValueAsString());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testLookupOperationByCodeAndSystemUserDefinedCode() {
|
||||
Parameters respParam = myClient
|
||||
.operation()
|
||||
.onType(CodeSystem.class)
|
||||
.named("lookup")
|
||||
.withParameter(Parameters.class, "code", new CodeType("8450-9"))
|
||||
.andParameter("system", new UriType("http://acme.org"))
|
||||
.execute();
|
||||
|
||||
String resp = myFhirCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(respParam);
|
||||
ourLog.info(resp);
|
||||
|
||||
assertEquals("name", respParam.getParameter().get(0).getName());
|
||||
assertEquals(("ACME Codes"), ((StringType) respParam.getParameter().get(0).getValue()).getValue());
|
||||
assertEquals("display", respParam.getParameter().get(1).getName());
|
||||
assertEquals(("Systolic blood pressure--expiration"), ((StringType) respParam.getParameter().get(1).getValue()).getValue());
|
||||
assertEquals("abstract", respParam.getParameter().get(2).getName());
|
||||
assertEquals(false, ((BooleanType) respParam.getParameter().get(2).getValue()).getValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSubsumesOnCodes_Subsumes() {
|
||||
Parameters respParam = myClient
|
||||
.operation()
|
||||
.onType(CodeSystem.class)
|
||||
.named(JpaConstants.OPERATION_SUBSUMES)
|
||||
.withParameter(Parameters.class, "codeA", new CodeType("ChildAA"))
|
||||
.andParameter("codeB", new CodeType("ParentA"))
|
||||
.andParameter("system", new UriType(SYSTEM_PARENTCHILD))
|
||||
.execute();
|
||||
|
||||
String resp = myFhirCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(respParam);
|
||||
ourLog.info(resp);
|
||||
|
||||
assertEquals(1, respParam.getParameter().size());
|
||||
assertEquals("outcome", respParam.getParameter().get(0).getName());
|
||||
assertEquals(ConceptSubsumptionOutcome.SUBSUMES.toCode(), ((CodeType) respParam.getParameter().get(0).getValue()).getValue());
|
||||
}
|
||||
|
||||
private void createCodeSystem(String url, String version, String code, String display) {
|
||||
|
||||
CodeSystem codeSystem = new CodeSystem();
|
||||
@ -55,4 +129,27 @@ public class ResourceProviderR5CodeSystemTest extends BaseResourceProviderR5Test
|
||||
|
||||
myCodeSystemDao.create(codeSystem, mySrd);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLookupOperationByCoding() throws IOException {
|
||||
|
||||
Parameters respParam = myClient
|
||||
.operation()
|
||||
.onType(CodeSystem.class)
|
||||
.named("lookup")
|
||||
.withParameter(Parameters.class, "coding", new Coding().setSystem("http://acme.org").setCode("8450-9"))
|
||||
.execute();
|
||||
|
||||
String resp = myFhirCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(respParam);
|
||||
ourLog.info(resp);
|
||||
|
||||
assertEquals("name", respParam.getParameter().get(0).getName());
|
||||
assertEquals(("ACME Codes"), ((StringType) respParam.getParameter().get(0).getValue()).getValue());
|
||||
assertEquals("display", respParam.getParameter().get(1).getName());
|
||||
assertEquals(("Systolic blood pressure--expiration"), ((StringType) respParam.getParameter().get(1).getValue()).getValue());
|
||||
assertEquals("abstract", respParam.getParameter().get(2).getName());
|
||||
assertEquals(false, ((BooleanType) respParam.getParameter().get(2).getValue()).getValue());
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,273 @@
|
||||
package ca.uhn.fhir.jpa.provider.r5;
|
||||
|
||||
import ca.uhn.fhir.jpa.api.model.DaoMethodOutcome;
|
||||
import ca.uhn.fhir.jpa.model.entity.ResourceTable;
|
||||
import ca.uhn.fhir.jpa.model.util.JpaConstants;
|
||||
import org.hl7.fhir.r4.model.codesystems.ConceptSubsumptionOutcome;
|
||||
import org.hl7.fhir.r5.model.CodeType;
|
||||
import org.hl7.fhir.r5.model.UriType;
|
||||
import org.hl7.fhir.r5.model.Enumerations;
|
||||
import org.hl7.fhir.r5.model.BooleanType;
|
||||
import org.hl7.fhir.r5.model.Coding;
|
||||
import org.hl7.fhir.r5.model.Parameters;
|
||||
import org.hl7.fhir.r5.model.StringType;
|
||||
import org.hl7.fhir.r5.model.CodeSystem;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
public class ResourceProviderR5CodeSystemVersionedTest extends BaseResourceProviderR5Test {
|
||||
|
||||
private static final String SYSTEM_PARENTCHILD = "http://parentchild";
|
||||
private static final Logger ourLog = LoggerFactory.getLogger(ResourceProviderR5CodeSystemVersionedTest.class);
|
||||
|
||||
private long parentChildCs1Id;
|
||||
private long parentChildCs2Id;
|
||||
|
||||
@BeforeEach
|
||||
@Transactional
|
||||
public void before02() throws IOException {
|
||||
CodeSystem cs = loadResourceFromClasspath(CodeSystem.class, "/extensional-case-3-cs.xml");
|
||||
cs.setVersion("1");
|
||||
for(CodeSystem.ConceptDefinitionComponent conceptDefinitionComponent : cs.getConcept()) {
|
||||
conceptDefinitionComponent.setDisplay(conceptDefinitionComponent.getDisplay() + " v1");
|
||||
}
|
||||
myCodeSystemDao.create(cs, mySrd);
|
||||
|
||||
cs = loadResourceFromClasspath(CodeSystem.class, "/extensional-case-3-cs.xml");
|
||||
cs.setVersion("2");
|
||||
for(CodeSystem.ConceptDefinitionComponent conceptDefinitionComponent : cs.getConcept()) {
|
||||
conceptDefinitionComponent.setDisplay(conceptDefinitionComponent.getDisplay() + " v2");
|
||||
}
|
||||
myCodeSystemDao.create(cs, mySrd);
|
||||
|
||||
CodeSystem parentChildCs = new CodeSystem();
|
||||
parentChildCs.setUrl(SYSTEM_PARENTCHILD);
|
||||
parentChildCs.setVersion("1");
|
||||
parentChildCs.setName("Parent Child CodeSystem 1");
|
||||
parentChildCs.setStatus(Enumerations.PublicationStatus.ACTIVE);
|
||||
parentChildCs.setContent(CodeSystem.CodeSystemContentMode.COMPLETE);
|
||||
parentChildCs.setHierarchyMeaning(CodeSystem.CodeSystemHierarchyMeaning.ISA);
|
||||
|
||||
CodeSystem.ConceptDefinitionComponent parentA = parentChildCs.addConcept().setCode("ParentA").setDisplay("Parent A");
|
||||
parentA.addConcept().setCode("ChildAA").setDisplay("Child AA");
|
||||
parentA.addConcept().setCode("ParentC").setDisplay("Parent C");
|
||||
parentChildCs.addConcept().setCode("ParentB").setDisplay("Parent B");
|
||||
|
||||
DaoMethodOutcome parentChildCsOutcome = myCodeSystemDao.create(parentChildCs);
|
||||
parentChildCs1Id = ((ResourceTable)parentChildCsOutcome.getEntity()).getId();
|
||||
|
||||
parentChildCs = new CodeSystem();
|
||||
parentChildCs.setVersion("2");
|
||||
parentChildCs.setName("Parent Child CodeSystem 2");
|
||||
parentChildCs.setUrl(SYSTEM_PARENTCHILD);
|
||||
parentChildCs.setStatus(Enumerations.PublicationStatus.ACTIVE);
|
||||
parentChildCs.setContent(CodeSystem.CodeSystemContentMode.COMPLETE);
|
||||
parentChildCs.setHierarchyMeaning(CodeSystem.CodeSystemHierarchyMeaning.ISA);
|
||||
|
||||
parentA = parentChildCs.addConcept().setCode("ParentA").setDisplay("Parent A v2");
|
||||
parentA.addConcept().setCode("ChildAA").setDisplay("Child AA v2");
|
||||
parentA.addConcept().setCode("ParentB").setDisplay("Parent B v2");
|
||||
parentChildCs.addConcept().setCode("ParentC").setDisplay("Parent C v2");
|
||||
|
||||
parentChildCsOutcome = myCodeSystemDao.create(parentChildCs);
|
||||
parentChildCs2Id = ((ResourceTable)parentChildCsOutcome.getEntity()).getId();
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLookupOperationByCoding() {
|
||||
// First test with no version specified (should return from last version created)
|
||||
Parameters respParam = myClient
|
||||
.operation()
|
||||
.onType(CodeSystem.class)
|
||||
.named("lookup")
|
||||
.withParameter(Parameters.class, "coding", new Coding().setSystem("http://acme.org").setCode("8450-9"))
|
||||
.execute();
|
||||
|
||||
String resp = myFhirCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(respParam);
|
||||
ourLog.info(resp);
|
||||
|
||||
assertEquals("name", respParam.getParameter().get(0).getName());
|
||||
assertEquals(("ACME Codes"), ((StringType) respParam.getParameter().get(0).getValue()).getValue());
|
||||
assertEquals("version", respParam.getParameter().get(1).getName());
|
||||
assertEquals("2", ((StringType) respParam.getParameter().get(1).getValue()).getValue());
|
||||
assertEquals("display", respParam.getParameter().get(2).getName());
|
||||
assertEquals(("Systolic blood pressure--expiration v2"), ((StringType) respParam.getParameter().get(2).getValue()).getValue());
|
||||
assertEquals("abstract", respParam.getParameter().get(3).getName());
|
||||
assertEquals(false, ((BooleanType) respParam.getParameter().get(3).getValue()).getValue());
|
||||
|
||||
// Test with version set to 1
|
||||
respParam = myClient
|
||||
.operation()
|
||||
.onType(CodeSystem.class)
|
||||
.named("lookup")
|
||||
.withParameter(Parameters.class, "coding", new Coding().setSystem("http://acme.org").setCode("8450-9").setVersion("1"))
|
||||
.execute();
|
||||
|
||||
resp = myFhirCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(respParam);
|
||||
ourLog.info(resp);
|
||||
|
||||
assertEquals("name", respParam.getParameter().get(0).getName());
|
||||
assertEquals(("ACME Codes"), ((StringType) respParam.getParameter().get(0).getValue()).getValue());
|
||||
assertEquals("version", respParam.getParameter().get(1).getName());
|
||||
assertEquals("1", ((StringType) respParam.getParameter().get(1).getValue()).getValue());
|
||||
assertEquals("display", respParam.getParameter().get(2).getName());
|
||||
assertEquals(("Systolic blood pressure--expiration v1"), ((StringType) respParam.getParameter().get(2).getValue()).getValue());
|
||||
assertEquals("abstract", respParam.getParameter().get(3).getName());
|
||||
assertEquals(false, ((BooleanType) respParam.getParameter().get(3).getValue()).getValue());
|
||||
|
||||
// Test with version set to 2
|
||||
respParam = myClient
|
||||
.operation()
|
||||
.onType(CodeSystem.class)
|
||||
.named("lookup")
|
||||
.withParameter(Parameters.class, "coding", new Coding().setSystem("http://acme.org").setCode("8450-9").setVersion("2"))
|
||||
.execute();
|
||||
|
||||
resp = myFhirCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(respParam);
|
||||
ourLog.info(resp);
|
||||
|
||||
assertEquals("name", respParam.getParameter().get(0).getName());
|
||||
assertEquals(("ACME Codes"), ((StringType) respParam.getParameter().get(0).getValue()).getValue());
|
||||
assertEquals("version", respParam.getParameter().get(1).getName());
|
||||
assertEquals("2", ((StringType) respParam.getParameter().get(1).getValue()).getValue());
|
||||
assertEquals("display", respParam.getParameter().get(2).getName());
|
||||
assertEquals(("Systolic blood pressure--expiration v2"), ((StringType) respParam.getParameter().get(2).getValue()).getValue());
|
||||
assertEquals("abstract", respParam.getParameter().get(3).getName());
|
||||
assertEquals(false, ((BooleanType) respParam.getParameter().get(3).getValue()).getValue());
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLookupOperationByCodeAndSystemUserDefinedCode() {
|
||||
// First test with no version specified (should return from last version created)
|
||||
Parameters respParam = myClient
|
||||
.operation()
|
||||
.onType(CodeSystem.class)
|
||||
.named("lookup")
|
||||
.withParameter(Parameters.class, "code", new CodeType("8450-9"))
|
||||
.andParameter("system", new UriType("http://acme.org"))
|
||||
.execute();
|
||||
|
||||
String resp = myFhirCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(respParam);
|
||||
ourLog.info(resp);
|
||||
|
||||
assertEquals("name", respParam.getParameter().get(0).getName());
|
||||
assertEquals(("ACME Codes"), ((StringType) respParam.getParameter().get(0).getValue()).getValue());
|
||||
assertEquals("version", respParam.getParameter().get(1).getName());
|
||||
assertEquals("2", ((StringType) respParam.getParameter().get(1).getValue()).getValue());
|
||||
assertEquals("display", respParam.getParameter().get(2).getName());
|
||||
assertEquals(("Systolic blood pressure--expiration v2"), ((StringType) respParam.getParameter().get(2).getValue()).getValue());
|
||||
assertEquals("abstract", respParam.getParameter().get(3).getName());
|
||||
assertEquals(false, ((BooleanType) respParam.getParameter().get(3).getValue()).getValue());
|
||||
|
||||
// Test with version 1 specified.
|
||||
respParam = myClient
|
||||
.operation()
|
||||
.onType(CodeSystem.class)
|
||||
.named("lookup")
|
||||
.withParameter(Parameters.class, "code", new CodeType("8450-9"))
|
||||
.andParameter("system", new UriType("http://acme.org"))
|
||||
.andParameter("version", new StringType("1"))
|
||||
.execute();
|
||||
|
||||
resp = myFhirCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(respParam);
|
||||
ourLog.info(resp);
|
||||
|
||||
assertEquals("name", respParam.getParameter().get(0).getName());
|
||||
assertEquals(("ACME Codes"), ((StringType) respParam.getParameter().get(0).getValue()).getValue());
|
||||
assertEquals("version", respParam.getParameter().get(1).getName());
|
||||
assertEquals("1", ((StringType) respParam.getParameter().get(1).getValue()).getValue());
|
||||
assertEquals("display", respParam.getParameter().get(2).getName());
|
||||
assertEquals(("Systolic blood pressure--expiration v1"), ((StringType) respParam.getParameter().get(2).getValue()).getValue());
|
||||
assertEquals("abstract", respParam.getParameter().get(3).getName());
|
||||
assertEquals(false, ((BooleanType) respParam.getParameter().get(3).getValue()).getValue());
|
||||
|
||||
// Test with version 2 specified
|
||||
respParam = myClient
|
||||
.operation()
|
||||
.onType(CodeSystem.class)
|
||||
.named("lookup")
|
||||
.withParameter(Parameters.class, "code", new CodeType("8450-9"))
|
||||
.andParameter("system", new UriType("http://acme.org"))
|
||||
.andParameter("version", new StringType("2"))
|
||||
.execute();
|
||||
|
||||
resp = myFhirCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(respParam);
|
||||
ourLog.info(resp);
|
||||
|
||||
assertEquals("name", respParam.getParameter().get(0).getName());
|
||||
assertEquals(("ACME Codes"), ((StringType) respParam.getParameter().get(0).getValue()).getValue());
|
||||
assertEquals("version", respParam.getParameter().get(1).getName());
|
||||
assertEquals("2", ((StringType) respParam.getParameter().get(1).getValue()).getValue());
|
||||
assertEquals("display", respParam.getParameter().get(2).getName());
|
||||
assertEquals(("Systolic blood pressure--expiration v2"), ((StringType) respParam.getParameter().get(2).getValue()).getValue());
|
||||
assertEquals("abstract", respParam.getParameter().get(3).getName());
|
||||
assertEquals(false, ((BooleanType) respParam.getParameter().get(3).getValue()).getValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSubsumesOnCodes_Subsumes() {
|
||||
// First test with no version specified (should return result for last version created).
|
||||
Parameters respParam = myClient
|
||||
.operation()
|
||||
.onType(CodeSystem.class)
|
||||
.named(JpaConstants.OPERATION_SUBSUMES)
|
||||
.withParameter(Parameters.class, "codeA", new CodeType("ParentB"))
|
||||
.andParameter("codeB", new CodeType("ParentA"))
|
||||
.andParameter("system", new UriType(SYSTEM_PARENTCHILD))
|
||||
.execute();
|
||||
|
||||
String resp = myFhirCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(respParam);
|
||||
ourLog.info(resp);
|
||||
|
||||
assertEquals(1, respParam.getParameter().size());
|
||||
assertEquals("outcome", respParam.getParameter().get(0).getName());
|
||||
assertEquals(ConceptSubsumptionOutcome.SUBSUMES.toCode(), ((CodeType) respParam.getParameter().get(0).getValue()).getValue());
|
||||
|
||||
// Test with version set to 1.
|
||||
respParam = myClient
|
||||
.operation()
|
||||
.onType(CodeSystem.class)
|
||||
.named(JpaConstants.OPERATION_SUBSUMES)
|
||||
.withParameter(Parameters.class, "codeA", new CodeType("ParentC"))
|
||||
.andParameter("codeB", new CodeType("ParentA"))
|
||||
.andParameter("system", new UriType(SYSTEM_PARENTCHILD))
|
||||
.andParameter("version", new StringType("1"))
|
||||
.execute();
|
||||
|
||||
resp = myFhirCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(respParam);
|
||||
ourLog.info(resp);
|
||||
|
||||
assertEquals(1, respParam.getParameter().size());
|
||||
assertEquals("outcome", respParam.getParameter().get(0).getName());
|
||||
assertEquals(ConceptSubsumptionOutcome.SUBSUMES.toCode(), ((CodeType) respParam.getParameter().get(0).getValue()).getValue());
|
||||
|
||||
// Test with version set to 2.
|
||||
respParam = myClient
|
||||
.operation()
|
||||
.onType(CodeSystem.class)
|
||||
.named(JpaConstants.OPERATION_SUBSUMES)
|
||||
.withParameter(Parameters.class, "codeA", new CodeType("ParentB"))
|
||||
.andParameter("codeB", new CodeType("ParentA"))
|
||||
.andParameter("system", new UriType(SYSTEM_PARENTCHILD))
|
||||
.andParameter("version", new StringType("2"))
|
||||
.execute();
|
||||
|
||||
resp = myFhirCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(respParam);
|
||||
ourLog.info(resp);
|
||||
|
||||
assertEquals(1, respParam.getParameter().size());
|
||||
assertEquals("outcome", respParam.getParameter().get(0).getName());
|
||||
assertEquals(ConceptSubsumptionOutcome.SUBSUMES.toCode(), ((CodeType) respParam.getParameter().get(0).getValue()).getValue());
|
||||
|
||||
}
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user