Im 20201028 fix versioned valueset expansions (#2151)

* Fixes to ValueSet expansion for cases where CodeSystem is versioned.

* Fixes to ValueSet expansion for case where URL and filter parameters specified.

* Restore maven-wrapper.properties file inadvertently deleted from GitHub.

* Fix JUnit tests and ValueSet exclude.

Co-authored-by: ianmarshall <ian@simpatico.ai>
This commit is contained in:
IanMMarshall 2020-11-04 16:36:43 -05:00 committed by GitHub
parent 228e75b501
commit 38a975f09d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
17 changed files with 1722 additions and 134 deletions

View File

@ -41,12 +41,18 @@ public interface ITermValueSetConceptDao extends JpaRepository<TermValueSetConce
@Query("SELECT vsc FROM TermValueSetConcept vsc WHERE vsc.myValueSetPid = :pid AND vsc.mySystem = :system_url AND vsc.myCode = :codeval")
Optional<TermValueSetConcept> findByTermValueSetIdSystemAndCode(@Param("pid") Long theValueSetId, @Param("system_url") String theSystem, @Param("codeval") String theCode);
@Query("SELECT vsc FROM TermValueSetConcept vsc WHERE vsc.myValueSetPid = :pid AND vsc.mySystem = :system_url AND vsc.mySystemVer = :system_version AND vsc.myCode = :codeval")
Optional<TermValueSetConcept> findByTermValueSetIdSystemAndCodeWithVersion(@Param("pid") Long theValueSetId, @Param("system_url") String theSystem, @Param("system_version") String theSystemVersion, @Param("codeval") String theCode);
@Query("SELECT vsc FROM TermValueSetConcept vsc WHERE vsc.myValueSet.myResourcePid = :resource_pid AND vsc.myCode = :codeval")
List<TermValueSetConcept> findByValueSetResourcePidAndCode(@Param("resource_pid") Long theValueSetId, @Param("codeval") String theCode);
@Query("SELECT vsc FROM TermValueSetConcept vsc WHERE vsc.myValueSet.myResourcePid = :resource_pid AND vsc.mySystem = :system_url AND vsc.myCode = :codeval")
Optional<TermValueSetConcept> findByValueSetResourcePidSystemAndCode(@Param("resource_pid") Long theValueSetId, @Param("system_url") String theSystem, @Param("codeval") String theCode);
@Query("SELECT vsc FROM TermValueSetConcept vsc WHERE vsc.myValueSet.myResourcePid = :resource_pid AND vsc.mySystem = :system_url AND vsc.mySystemVer = :system_version AND vsc.myCode = :codeval")
Optional<TermValueSetConcept> findByValueSetResourcePidSystemAndCodeWithVersion(@Param("resource_pid") Long theValueSetId, @Param("system_url") String theSystem, @Param("system_version") String theSystemVersion, @Param("codeval") String theCode);
@Query("SELECT vsc.myId FROM TermValueSetConcept vsc WHERE vsc.myValueSetPid = :pid ORDER BY vsc.myId")
List<Long> findIdsByTermValueSetId(@Param("pid") Long theValueSetId);

View File

@ -101,7 +101,7 @@ public class FhirResourceDaoValueSetDstu3 extends BaseHapiFhirResourceDao<ValueS
private void validateIncludes(String name, List<ConceptSetComponent> listToValidate) {
for (ConceptSetComponent nextExclude : listToValidate) {
if (isBlank(nextExclude.getSystem()) && !ElementUtil.isEmpty(nextExclude.getConcept(), nextExclude.getFilter())) {
if (isBlank(nextExclude.getSystem()) && nextExclude.getValueSet().isEmpty() && !ElementUtil.isEmpty(nextExclude.getConcept(), nextExclude.getFilter())) {
throw new InvalidRequestException("ValueSet contains " + name + " criteria with no system defined");
}
}
@ -116,14 +116,13 @@ public class FhirResourceDaoValueSetDstu3 extends BaseHapiFhirResourceDao<ValueS
ValueSet source = new ValueSet();
source.setUrl(theUri);
source.getCompose().addInclude().addValueSet(theUri);
if (isNotBlank(theFilter)) {
ConceptSetComponent include = source.getCompose().addInclude();
ConceptSetFilterComponent filter = include.addFilter();
ConceptSetFilterComponent filter = source.getCompose().addInclude().addValueSet(theUri).addFilter();
filter.setProperty("display");
filter.setOp(FilterOperator.EQUAL);
filter.setValue(theFilter);
} else {
source.getCompose().addInclude().addValueSet(theUri);
}
return doExpand(source);
@ -150,14 +149,13 @@ public class FhirResourceDaoValueSetDstu3 extends BaseHapiFhirResourceDao<ValueS
ValueSet source = new ValueSet();
source.setUrl(theUri);
source.getCompose().addInclude().addValueSet(theUri);
if (isNotBlank(theFilter)) {
ConceptSetComponent include = source.getCompose().addInclude();
ConceptSetFilterComponent filter = include.addFilter();
ConceptSetFilterComponent filter = source.getCompose().addInclude().addValueSet(theUri).addFilter();
filter.setProperty("display");
filter.setOp(FilterOperator.EQUAL);
filter.setValue(theFilter);
} else {
source.getCompose().addInclude().addValueSet(theUri);
}
return doExpand(source, theOffset, theCount);

View File

@ -99,14 +99,13 @@ public class FhirResourceDaoValueSetR4 extends BaseHapiFhirResourceDao<ValueSet>
ValueSet source = new ValueSet();
source.setUrl(theUri);
source.getCompose().addInclude().addValueSet(theUri);
if (isNotBlank(theFilter)) {
ConceptSetComponent include = source.getCompose().addInclude();
ConceptSetFilterComponent filter = include.addFilter();
ConceptSetFilterComponent filter = source.getCompose().addInclude().addValueSet(theUri).addFilter();
filter.setProperty("display");
filter.setOp(FilterOperator.EQUAL);
filter.setValue(theFilter);
} else {
source.getCompose().addInclude().addValueSet(theUri);
}
return doExpand(source);
@ -133,14 +132,13 @@ public class FhirResourceDaoValueSetR4 extends BaseHapiFhirResourceDao<ValueSet>
ValueSet source = new ValueSet();
source.setUrl(theUri);
source.getCompose().addInclude().addValueSet(theUri);
if (isNotBlank(theFilter)) {
ConceptSetComponent include = source.getCompose().addInclude();
ConceptSetFilterComponent filter = include.addFilter();
ConceptSetFilterComponent filter = source.getCompose().addInclude().addValueSet(theUri).addFilter();
filter.setProperty("display");
filter.setOp(FilterOperator.EQUAL);
filter.setValue(theFilter);
} else {
source.getCompose().addInclude().addValueSet(theUri);
}
return doExpand(source, theOffset, theCount);

View File

@ -99,14 +99,13 @@ public class FhirResourceDaoValueSetR5 extends BaseHapiFhirResourceDao<ValueSet>
ValueSet source = new ValueSet();
source.setUrl(theUri);
source.getCompose().addInclude().addValueSet(theUri);
if (isNotBlank(theFilter)) {
ConceptSetComponent include = source.getCompose().addInclude();
ConceptSetFilterComponent filter = include.addFilter();
ConceptSetFilterComponent filter = source.getCompose().addInclude().addValueSet(theUri).addFilter();
filter.setProperty("display");
filter.setOp(Enumerations.FilterOperator.EQUAL);
filter.setValue(theFilter);
} else {
source.getCompose().addInclude().addValueSet(theUri);
}
ValueSet retVal = doExpand(source);
@ -134,14 +133,13 @@ public class FhirResourceDaoValueSetR5 extends BaseHapiFhirResourceDao<ValueSet>
ValueSet source = new ValueSet();
source.setUrl(theUri);
source.getCompose().addInclude().addValueSet(theUri);
if (isNotBlank(theFilter)) {
ConceptSetComponent include = source.getCompose().addInclude();
ConceptSetFilterComponent filter = include.addFilter();
ConceptSetFilterComponent filter = source.getCompose().addInclude().addValueSet(theUri).addFilter();
filter.setProperty("display");
filter.setOp(Enumerations.FilterOperator.EQUAL);
filter.setValue(theFilter);
} else {
source.getCompose().addInclude().addValueSet(theUri);
}
return doExpand(source, theOffset, theCount);

View File

@ -40,7 +40,7 @@ import static org.apache.commons.lang3.StringUtils.length;
* bork up migration tasks.
*/
@Table(name = "TRM_VALUESET_CONCEPT", uniqueConstraints = {
@UniqueConstraint(name = "IDX_VS_CONCEPT_CS_CD", columnNames = {"VALUESET_PID", "SYSTEM_URL", "CODEVAL"}),
@UniqueConstraint(name = "IDX_VS_CONCEPT_CS_CD", columnNames = {"VALUESET_PID", "SYSTEM_URL", "SYSTEM_VER", "CODEVAL"}),
@UniqueConstraint(name = "IDX_VS_CONCEPT_ORDER", columnNames = {"VALUESET_PID", "VALUESET_ORDER"})
})
@Entity()
@ -72,6 +72,9 @@ public class TermValueSetConcept implements Serializable {
@Column(name = "SYSTEM_URL", nullable = false, length = TermCodeSystem.MAX_URL_LENGTH)
private String mySystem;
@Column(name = "SYSTEM_VER", nullable = true, length = TermCodeSystemVersion.MAX_VERSION_LENGTH)
private String mySystemVer;
@Column(name = "CODEVAL", nullable = false, length = TermConcept.MAX_CODE_LENGTH)
private String myCode;
@ -134,6 +137,17 @@ public class TermValueSetConcept implements Serializable {
return this;
}
public String getSystemVersion() {
return mySystemVer;
}
public TermValueSetConcept setSystemVersion(String theSystemVersion) {
ValidateUtil.isNotTooLongOrThrowIllegalArgument(theSystemVersion, TermCodeSystemVersion.MAX_VERSION_LENGTH,
"System version exceeds maximum length (" + TermCodeSystemVersion.MAX_VERSION_LENGTH + "): " + length(theSystemVersion));
mySystemVer = theSystemVersion;
return this;
}
public String getCode() {
return myCode;
}

View File

@ -248,14 +248,13 @@ public abstract class BaseTermReadSvcImpl implements ITermReadSvc {
return cs != null;
}
private void addCodeIfNotAlreadyAdded(IValueSetConceptAccumulator theValueSetCodeAccumulator, Set<String> theAddedCodes, TermConcept theConcept, boolean theAdd, AtomicInteger theCodeCounter) {
private void addCodeIfNotAlreadyAdded(IValueSetConceptAccumulator theValueSetCodeAccumulator, Set<String> theAddedCodes, TermConcept theConcept, boolean theAdd, AtomicInteger theCodeCounter, String theValueSetIncludeVersion) {
String codeSystem = theConcept.getCodeSystemVersion().getCodeSystem().getCodeSystemUri();
String codeSystemVersion = theConcept.getCodeSystemVersion().getCodeSystemVersionId();
String code = theConcept.getCode();
String display = theConcept.getDisplay();
Collection<TermConceptDesignation> designations = theConcept.getDesignations();
if (StringUtils.isNotEmpty(codeSystemVersion)) {
addCodeIfNotAlreadyAdded(theValueSetCodeAccumulator, theAddedCodes, designations, theAdd, theCodeCounter, codeSystem + "|" + codeSystemVersion, code, display);
if (StringUtils.isNotEmpty(theValueSetIncludeVersion)) {
addCodeIfNotAlreadyAdded(theValueSetCodeAccumulator, theAddedCodes, designations, theAdd, theCodeCounter, codeSystem + "|" + theValueSetIncludeVersion, code, display);
} else {
addCodeIfNotAlreadyAdded(theValueSetCodeAccumulator, theAddedCodes, designations, theAdd, theCodeCounter, codeSystem, code, display);
}
@ -264,12 +263,12 @@ public abstract class BaseTermReadSvcImpl implements ITermReadSvc {
private void addCodeIfNotAlreadyAdded(IValueSetConceptAccumulator theValueSetCodeAccumulator, Set<String> theAddedCodes, Collection<TermConceptDesignation> theDesignations, boolean theAdd, AtomicInteger theCodeCounter, String theCodeSystem, String theCodeSystemVersion, String theCode, String theDisplay) {
if (StringUtils.isNotEmpty(theCodeSystemVersion)) {
if (isNoneBlank(theCodeSystem, theCode)) {
if (theAdd && theAddedCodes.add(theCodeSystem + "|" + theCode + "|" + theCodeSystemVersion)) {
if (theAdd && theAddedCodes.add(theCodeSystem + "|" + theCode)) {
theValueSetCodeAccumulator.includeConceptWithDesignations(theCodeSystem + "|" + theCodeSystemVersion, theCode, theDisplay, theDesignations);
theCodeCounter.incrementAndGet();
}
if (!theAdd && theAddedCodes.remove(theCodeSystem + "|" + theCode + "|" + theCodeSystemVersion)) {
if (!theAdd && theAddedCodes.remove(theCodeSystem + "|" + theCode)) {
theValueSetCodeAccumulator.excludeConcept(theCodeSystem + "|" + theCodeSystemVersion, theCode);
theCodeCounter.decrementAndGet();
}
@ -785,7 +784,7 @@ public abstract class BaseTermReadSvcImpl implements ITermReadSvc {
myConceptDao
.findByCodeSystemAndCode(termCodeSystemVersion, nextConcept.getCode())
.ifPresent(concept ->
addCodeIfNotAlreadyAdded(theValueSetCodeAccumulator, theAddedCodes, concept, theAdd, theCodeCounter)
addCodeIfNotAlreadyAdded(theValueSetCodeAccumulator, theAddedCodes, concept, theAdd, theCodeCounter, nextConcept.getSystemVersion())
);
} else {
// This will happen if we're expanding against a built-in (part of FHIR) ValueSet that
@ -812,12 +811,12 @@ public abstract class BaseTermReadSvcImpl implements ITermReadSvc {
@Nonnull
private Boolean expandValueSetHandleIncludeOrExcludeUsingDatabase(IValueSetConceptAccumulator theValueSetCodeAccumulator, Set<String> theAddedCodes, ValueSet.ConceptSetComponent theIncludeOrExclude, boolean theAdd, AtomicInteger theCodeCounter, int theQueryIndex, FhirVersionIndependentConcept theWantConceptOrNull, String theSystem, TermCodeSystem theCs) {
String codeSystemVersion = theIncludeOrExclude.getVersion();
String includeOrExcludeVersion = theIncludeOrExclude.getVersion();
TermCodeSystemVersion csv;
if (isEmpty(codeSystemVersion)) {
if (isEmpty(includeOrExcludeVersion)) {
csv = theCs.getCurrentVersion();
} else {
csv = myCodeSystemVersionDao.findByCodeSystemPidAndVersion(theCs.getPid(), codeSystemVersion);
csv = myCodeSystemVersionDao.findByCodeSystemPidAndVersion(theCs.getPid(), includeOrExcludeVersion);
}
FullTextEntityManager em = org.hibernate.search.jpa.Search.getFullTextEntityManager(myEntityManager);
@ -846,8 +845,8 @@ public abstract class BaseTermReadSvcImpl implements ITermReadSvc {
* Filters
*/
String codeSystemUrlAndVersion;
if (codeSystemVersion != null) {
codeSystemUrlAndVersion = theSystem + "|" + codeSystemVersion;
if (includeOrExcludeVersion != null) {
codeSystemUrlAndVersion = theSystem + "|" + includeOrExcludeVersion;
} else {
codeSystemUrlAndVersion = theSystem;
}
@ -926,7 +925,7 @@ public abstract class BaseTermReadSvcImpl implements ITermReadSvc {
countForBatch.incrementAndGet();
TermConcept concept = (TermConcept) next;
try {
addCodeIfNotAlreadyAdded(theValueSetCodeAccumulator, theAddedCodes, concept, theAdd, theCodeCounter);
addCodeIfNotAlreadyAdded(theValueSetCodeAccumulator, theAddedCodes, concept, theAdd, theCodeCounter, includeOrExcludeVersion);
} catch (ExpansionTooCostlyException e) {
return false;
}
@ -1278,7 +1277,7 @@ public abstract class BaseTermReadSvcImpl implements ITermReadSvc {
if (theInclude.getConcept().isEmpty()) {
for (TermConcept next : theVersion.getConcepts()) {
addCodeIfNotAlreadyAdded(theValueSetCodeAccumulator, theAddedCodes, null, theAdd, theCodeCounter, theSystem, theVersion.getCodeSystemVersionId(), next.getCode(), next.getDisplay());
addCodeIfNotAlreadyAdded(theValueSetCodeAccumulator, theAddedCodes, null, theAdd, theCodeCounter, theSystem, theInclude.getVersion(), next.getCode(), next.getDisplay());
}
}
@ -1286,7 +1285,7 @@ public abstract class BaseTermReadSvcImpl implements ITermReadSvc {
if (!theSystem.equals(theInclude.getSystem()) && isNotBlank(theSystem)) {
continue;
}
addCodeIfNotAlreadyAdded(theValueSetCodeAccumulator, theAddedCodes, null, theAdd, theCodeCounter, theSystem, theVersion.getCodeSystemVersionId(), next.getCode(), next.getDisplay());
addCodeIfNotAlreadyAdded(theValueSetCodeAccumulator, theAddedCodes, null, theAdd, theCodeCounter, theSystem, theInclude.getVersion(), next.getCode(), next.getDisplay());
}
@ -1378,7 +1377,15 @@ public abstract class BaseTermReadSvcImpl implements ITermReadSvc {
private List<TermValueSetConcept> findByValueSetResourcePidSystemAndCode(ResourcePersistentId theResourcePid, String theSystem, String theCode) {
List<TermValueSetConcept> retVal = new ArrayList<>();
Optional<TermValueSetConcept> optionalTermValueSetConcept = myValueSetConceptDao.findByValueSetResourcePidSystemAndCode(theResourcePid.getIdAsLong(), theSystem, theCode);
Optional<TermValueSetConcept> optionalTermValueSetConcept;
int versionIndex = theSystem.indexOf("|");
if (versionIndex >= 0) {
String systemUrl = theSystem.substring(0, versionIndex);
String systemVersion = theSystem.substring(versionIndex+1);
optionalTermValueSetConcept = myValueSetConceptDao.findByValueSetResourcePidSystemAndCodeWithVersion(theResourcePid.getIdAsLong(), systemUrl, systemVersion, theCode);
} else {
optionalTermValueSetConcept = myValueSetConceptDao.findByValueSetResourcePidSystemAndCode(theResourcePid.getIdAsLong(), theSystem, theCode);
}
optionalTermValueSetConcept.ifPresent(retVal::add);
return retVal;
}

View File

@ -87,7 +87,15 @@ public class ValueSetConceptAccumulator implements IValueSetConceptAccumulator {
}
// Get existing entity so it can be deleted.
Optional<TermValueSetConcept> optionalConcept = myValueSetConceptDao.findByTermValueSetIdSystemAndCode(myTermValueSet.getId(), theSystem, theCode);
Optional<TermValueSetConcept> optionalConcept;
int versionIdx = theSystem.indexOf("|");
if (versionIdx >= 0) {
String systemUrl = theSystem.substring(0,versionIdx);
String systemVersion = theSystem.substring(versionIdx+1);
optionalConcept = myValueSetConceptDao.findByTermValueSetIdSystemAndCodeWithVersion(myTermValueSet.getId(), systemUrl, systemVersion,theCode);
} else {
optionalConcept = myValueSetConceptDao.findByTermValueSetIdSystemAndCode(myTermValueSet.getId(), theSystem, theCode);
}
if (optionalConcept.isPresent()) {
TermValueSetConcept concept = optionalConcept.get();
@ -115,7 +123,13 @@ public class ValueSetConceptAccumulator implements IValueSetConceptAccumulator {
TermValueSetConcept concept = new TermValueSetConcept();
concept.setValueSet(myTermValueSet);
concept.setOrder(myConceptsSaved);
concept.setSystem(theSystem);
int versionIndex = theSystem.indexOf("|");
if (versionIndex >= 0) {
concept.setSystem(theSystem.substring(0, versionIndex));
concept.setSystemVersion(theSystem.substring(versionIndex+1));
} else {
concept.setSystem(theSystem);
}
concept.setCode(theCode);
if (isNotBlank(theDisplay)) {
concept.setDisplay(theDisplay);

View File

@ -50,6 +50,7 @@ import java.util.List;
import static ca.uhn.fhir.jpa.dao.dstu3.FhirResourceDaoDstu3TerminologyTest.URL_MY_CODE_SYSTEM;
import static ca.uhn.fhir.jpa.dao.dstu3.FhirResourceDaoDstu3TerminologyTest.URL_MY_VALUE_SET;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.stringContainsInOrder;
import static org.junit.jupiter.api.Assertions.*;
public class ResourceProviderDstu3ValueSetTest extends BaseResourceProviderDstu3Test {
@ -833,6 +834,50 @@ public class ResourceProviderDstu3ValueSetTest extends BaseResourceProviderDstu3
assertEquals("Male", ((StringType) respParam.getParameter().get(1).getValue()).getValue());
}
@Test
public void testExpandByValueSetWithFilter() throws IOException {
loadAndPersistCodeSystem();
ValueSet toExpand = loadResourceFromClasspath(ValueSet.class, "/extensional-case-3-vs.xml");
Parameters respParam = ourClient
.operation()
.onType(ValueSet.class)
.named("expand")
.withParameter(Parameters.class, "valueSet", toExpand)
.andParameter("filter", new StringType("blood"))
.execute();
ValueSet expanded = (ValueSet) respParam.getParameter().get(0).getResource();
String resp = myFhirCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(expanded);
ourLog.info(resp);
assertThat(resp, stringContainsInOrder(
"<code value=\"11378-7\"/>",
"<display value=\"Systolic blood pressure at First encounter\"/>"));
}
@Test
public void testExpandByUrlWithFilter() throws Exception {
loadAndPersistCodeSystemAndValueSet();
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"))
.andParameter("filter", new StringType("first"))
.execute();
ValueSet expanded = (ValueSet) respParam.getParameter().get(0).getResource();
String resp = myFhirCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(expanded);
ourLog.info(resp);
assertThat(resp, stringContainsInOrder(
"<code value=\"11378-7\"/>",
"<display value=\"Systolic blood pressure at First encounter\"/>"));
}
@AfterEach
public void afterResetPreExpansionDefault() {
myDaoConfig.setPreExpandValueSets(new DaoConfig().isPreExpandValueSets());

View File

@ -1112,7 +1112,8 @@ public class ResourceProviderDstu3ValueSetVersionedTest extends BaseResourceProv
TermValueSetConcept concept = termValueSet.getConcepts().get(0);
ourLog.info("Concept:\n" + concept.toString());
assertEquals("http://acme.org|1", concept.getSystem());
assertEquals("http://acme.org", concept.getSystem());
assertEquals("1", concept.getSystemVersion());
assertEquals("8450-9", concept.getCode());
assertEquals("Systolic blood pressure--expiration", concept.getDisplay());
assertEquals(2, concept.getDesignations().size());
@ -1134,7 +1135,8 @@ public class ResourceProviderDstu3ValueSetVersionedTest extends BaseResourceProv
concept = termValueSet.getConcepts().get(1);
ourLog.info("Concept:\n" + concept.toString());
assertEquals("http://acme.org|1", concept.getSystem());
assertEquals("http://acme.org", concept.getSystem());
assertEquals("1", concept.getSystemVersion());
assertEquals("11378-7", concept.getCode());
assertEquals("Systolic blood pressure at First encounter", concept.getDisplay());
assertEquals(0, concept.getDesignations().size());
@ -1144,7 +1146,8 @@ public class ResourceProviderDstu3ValueSetVersionedTest extends BaseResourceProv
concept = termValueSet.getConcepts().get(22);
ourLog.info("Concept:\n" + concept.toString());
assertEquals("http://acme.org|1", concept.getSystem());
assertEquals("http://acme.org", concept.getSystem());
assertEquals("1", concept.getSystemVersion());
assertEquals("8491-3", concept.getCode());
assertEquals("Systolic blood pressure 1 hour minimum", concept.getDisplay());
assertEquals(1, concept.getDesignations().size());
@ -1159,7 +1162,8 @@ public class ResourceProviderDstu3ValueSetVersionedTest extends BaseResourceProv
concept = termValueSet.getConcepts().get(23);
ourLog.info("Concept:\n" + concept.toString());
assertEquals("http://acme.org|1", concept.getSystem());
assertEquals("http://acme.org", concept.getSystem());
assertEquals("1", concept.getSystemVersion());
assertEquals("8492-1", concept.getCode());
assertEquals("Systolic blood pressure 8 hour minimum", concept.getDisplay());
assertEquals(0, concept.getDesignations().size());
@ -1185,7 +1189,8 @@ public class ResourceProviderDstu3ValueSetVersionedTest extends BaseResourceProv
TermValueSetConcept concept = termValueSet.getConcepts().get(0);
ourLog.info("Concept:\n" + concept.toString());
assertEquals("http://acme.org|2", concept.getSystem());
assertEquals("http://acme.org", concept.getSystem());
assertEquals("2", concept.getSystemVersion());
assertEquals("8450-9", concept.getCode());
assertEquals("Systolic blood pressure--expiration v2", concept.getDisplay());
assertEquals(2, concept.getDesignations().size());
@ -1207,7 +1212,8 @@ public class ResourceProviderDstu3ValueSetVersionedTest extends BaseResourceProv
concept = termValueSet.getConcepts().get(1);
ourLog.info("Concept:\n" + concept.toString());
assertEquals("http://acme.org|2", concept.getSystem());
assertEquals("http://acme.org", concept.getSystem());
assertEquals("2", concept.getSystemVersion());
assertEquals("11378-7", concept.getCode());
assertEquals("Systolic blood pressure at First encounter v2", concept.getDisplay());
assertEquals(0, concept.getDesignations().size());
@ -1217,7 +1223,8 @@ public class ResourceProviderDstu3ValueSetVersionedTest extends BaseResourceProv
concept = termValueSet.getConcepts().get(22);
ourLog.info("Concept:\n" + concept.toString());
assertEquals("http://acme.org|2", concept.getSystem());
assertEquals("http://acme.org", concept.getSystem());
assertEquals("2", concept.getSystemVersion());
assertEquals("8491-3", concept.getCode());
assertEquals("Systolic blood pressure 1 hour minimum v2", concept.getDisplay());
assertEquals(1, concept.getDesignations().size());
@ -1232,7 +1239,8 @@ public class ResourceProviderDstu3ValueSetVersionedTest extends BaseResourceProv
concept = termValueSet.getConcepts().get(23);
ourLog.info("Concept:\n" + concept.toString());
assertEquals("http://acme.org|2", concept.getSystem());
assertEquals("http://acme.org", concept.getSystem());
assertEquals("2", concept.getSystemVersion());
assertEquals("8492-1", concept.getCode());
assertEquals("Systolic blood pressure 8 hour minimum v2", concept.getDisplay());
assertEquals(0, concept.getDesignations().size());

View File

@ -55,7 +55,7 @@ public class ResourceProviderR4CodeSystemTest extends BaseResourceProviderR4Test
@Test
public void testLookupOnExternalCode() {
ResourceProviderR4ValueSetTest.createExternalCs(myCodeSystemDao, myResourceTableDao, myTermCodeSystemStorageSvc, mySrd);
ResourceProviderR4ValueSetNoVerCSNoVerTest.createExternalCs(myCodeSystemDao, myResourceTableDao, myTermCodeSystemStorageSvc, mySrd);
Parameters respParam = myClient
.operation()

View File

@ -89,8 +89,8 @@ public class ResourceProviderR4CodeSystemVersionedTest extends BaseResourceProvi
@Test
public void testLookupOnExternalCodeMultiVersion() {
ResourceProviderR4ValueSetVersionedTest.createExternalCs(myCodeSystemDao, myResourceTableDao, myTermCodeSystemStorageSvc, mySrd, "1");
ResourceProviderR4ValueSetVersionedTest.createExternalCs(myCodeSystemDao, myResourceTableDao, myTermCodeSystemStorageSvc, mySrd, "2");
ResourceProviderR4ValueSetVerCSVerTest.createExternalCs(myCodeSystemDao, myResourceTableDao, myTermCodeSystemStorageSvc, mySrd, "1");
ResourceProviderR4ValueSetVerCSVerTest.createExternalCs(myCodeSystemDao, myResourceTableDao, myTermCodeSystemStorageSvc, mySrd, "2");
// First test with no version specified (should return from last version created)
Parameters respParam = myClient

View File

@ -64,15 +64,14 @@ import static org.hamcrest.Matchers.containsStringIgnoringCase;
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.assertSame;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;
public class ResourceProviderR4ValueSetTest extends BaseResourceProviderR4Test {
public class ResourceProviderR4ValueSetNoVerCSNoVerTest extends BaseResourceProviderR4Test {
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(ResourceProviderR4ValueSetTest.class);
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(ResourceProviderR4ValueSetNoVerCSNoVerTest.class);
private IIdType myExtensionalCsId;
private IIdType myExtensionalVsId;
private IIdType myLocalValueSetId;
@ -923,9 +922,19 @@ public class ResourceProviderR4ValueSetTest extends BaseResourceProviderR4Test {
}
@Test
public void testValidateCodeOperationByCodeAndSystemInstance() throws Exception {
public void testValidateCodeOperationByCodeAndSystemInstanceBeforeExpand() throws Exception {
loadAndPersistCodeSystemAndValueSet();
testValidateCodeOperationByCodeAndSystemInstance();
}
@Test
public void testValidateCodeOperationByCodeAndSystemInstanceAfterExpand() throws Exception {
loadAndPersistCodeSystemAndValueSet();
myTermSvc.preExpandDeferredValueSetsToTerminologyTables();
testValidateCodeOperationByCodeAndSystemInstance();
}
private void testValidateCodeOperationByCodeAndSystemInstance() throws Exception {
Parameters respParam = myClient
.operation()
.onInstance(myExtensionalVsId)
@ -941,10 +950,50 @@ public class ResourceProviderR4ValueSetTest extends BaseResourceProviderR4Test {
}
@Test
public void testValidateCodeOperationByCodeAndSystemInstanceOnType() throws IOException {
public void testValidateCodeOperationByCodeAndSystemBeforeExpand() throws Exception {
loadAndPersistCodeSystemAndValueSet();
testValidateCodeOperationByCodeAndSystem();
}
@Test
public void testValidateCodeOperationByCodeAndSystemAfterExpand() throws Exception {
loadAndPersistCodeSystemAndValueSet();
myTermSvc.preExpandDeferredValueSetsToTerminologyTables();
testValidateCodeOperationByCodeAndSystem();
}
private void testValidateCodeOperationByCodeAndSystem() throws Exception {
Parameters respParam = myClient
.operation()
.onType(ValueSet.class)
.named("validate-code")
.withParameter(Parameters.class, "code", new CodeType("8450-9"))
.andParameter("system", new UriType("http://acme.org"))
.andParameter("url", new UriType("http://www.healthintersections.com.au/fhir/ValueSet/extensional-case-2"))
.execute();
String resp = myFhirCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(respParam);
ourLog.info(resp);
assertEquals(true, ((BooleanType) respParam.getParameter().get(0).getValue()).booleanValue());
}
@Test
public void testValidateCodeOperationByCodeAndSystemInstanceOnTypeBeforeExpand() throws IOException {
createLocalCs();
createLocalVsWithIncludeConcept();
testValidateCodeOperationByCodeAndSystemInstanceOnType();
}
@Test
public void testValidateCodeOperationByCodeAndSystemInstanceOnTypeAfterExpand() throws IOException {
createLocalCs();
createLocalVsWithIncludeConcept();
myTermSvc.preExpandDeferredValueSetsToTerminologyTables();
testValidateCodeOperationByCodeAndSystemInstanceOnType();
}
private void testValidateCodeOperationByCodeAndSystemInstanceOnType() throws IOException {
String url = ourServerBase +
"/ValueSet/" + myLocalValueSetId.getIdPart() + "/$validate-code?system=" +
UrlUtil.escapeUrlParam(URL_MY_CODE_SYSTEM) +
@ -962,10 +1011,21 @@ public class ResourceProviderR4ValueSetTest extends BaseResourceProviderR4Test {
}
@Test
public void testValidateCodeOperationByCodeAndSystemInstanceOnInstance() throws IOException {
public void testValidateCodeOperationByCodeAndSystemInstanceOnInstanceBeforeExpand() throws IOException {
createLocalCs();
createLocalVsWithIncludeConcept();
testValidateCodeOperationByCodeAndSystemInstanceOnInstance();
}
@Test
public void testValidateCodeOperationByCodeAndSystemInstanceOnInstanceAfterExpand() throws IOException {
createLocalCs();
createLocalVsWithIncludeConcept();
myTermSvc.preExpandDeferredValueSetsToTerminologyTables();
testValidateCodeOperationByCodeAndSystemInstanceOnInstance();
}
private void testValidateCodeOperationByCodeAndSystemInstanceOnInstance() throws IOException {
String url = ourServerBase +
"/ValueSet/" + myLocalValueSetId.getIdPart() + "/$validate-code?system=" +
UrlUtil.escapeUrlParam(URL_MY_CODE_SYSTEM) +
@ -985,9 +1045,19 @@ public class ResourceProviderR4ValueSetTest extends BaseResourceProviderR4Test {
}
@Test
public void testValidateCodeOperationByCodeAndSystemType() throws Exception {
public void testValidateCodeOperationByCodeAndSystemTypeBeforeExpand() throws Exception {
loadAndPersistCodeSystemAndValueSet();
testValidateCodeOperationByCodeAndSystemType();
}
@Test
public void testValidateCodeOperationByCodeAndSystemTypeAfterExpand() throws Exception {
loadAndPersistCodeSystemAndValueSet();
myTermSvc.preExpandDeferredValueSetsToTerminologyTables();
testValidateCodeOperationByCodeAndSystemType();
}
private void testValidateCodeOperationByCodeAndSystemType() throws Exception {
Parameters respParam = myClient
.operation()
.onInstance(myExtensionalVsId)
@ -1089,9 +1159,63 @@ public class ResourceProviderR4ValueSetTest extends BaseResourceProviderR4Test {
}
@Test
public void testValidateCodeOperationByCoding() throws Exception {
public void testValidateCodeOperationByCodingBeforeExpand() throws Exception {
loadAndPersistCodeSystemAndValueSet();
testValidateCodeOperationByCoding();
}
@Test
public void testValidateCodeOperationByCodingAfterExpand() throws Exception {
loadAndPersistCodeSystemAndValueSet();
myTermSvc.preExpandDeferredValueSetsToTerminologyTables();
testValidateCodeOperationByCoding();
}
@Test
public void testExpandByValueSetWithFilter() throws IOException {
loadAndPersistCodeSystem();
ValueSet toExpand = loadResourceFromClasspath(ValueSet.class, "/extensional-case-3-vs.xml");
Parameters respParam = myClient
.operation()
.onType(ValueSet.class)
.named("expand")
.withParameter(Parameters.class, "valueSet", toExpand)
.andParameter("filter", new StringType("blood"))
.execute();
ValueSet expanded = (ValueSet) respParam.getParameter().get(0).getResource();
String resp = myFhirCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(expanded);
ourLog.info(resp);
assertThat(resp, stringContainsInOrder(
"<code value=\"11378-7\"/>",
"<display value=\"Systolic blood pressure at First encounter\"/>"));
}
@Test
public void testExpandByUrlWithFilter() throws Exception {
loadAndPersistCodeSystemAndValueSet();
Parameters respParam = myClient
.operation()
.onType(ValueSet.class)
.named("expand")
.withParameter(Parameters.class, "url", new UriType("http://www.healthintersections.com.au/fhir/ValueSet/extensional-case-2"))
.andParameter("filter", new StringType("first"))
.execute();
ValueSet expanded = (ValueSet) respParam.getParameter().get(0).getResource();
String resp = myFhirCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(expanded);
ourLog.info(resp);
assertThat(resp, stringContainsInOrder(
"<code value=\"11378-7\"/>",
"<display value=\"Systolic blood pressure at First encounter\"/>"));
}
private void testValidateCodeOperationByCoding() throws Exception {
Coding codingToValidate = new Coding("http://acme.org", "8495-4", "Systolic blood pressure 24 hour minimum");
// With correct system version specified. Should pass.
@ -1110,8 +1234,6 @@ public class ResourceProviderR4ValueSetTest extends BaseResourceProviderR4Test {
}
private boolean clearDeferredStorageQueue() {
if(!myTerminologyDeferredStorageSvc.isStorageQueueEmpty()) {

View File

@ -12,25 +12,19 @@ import ca.uhn.fhir.jpa.entity.TermValueSetConceptDesignation;
import ca.uhn.fhir.jpa.entity.TermValueSetPreExpansionStatusEnum;
import ca.uhn.fhir.jpa.model.entity.ResourceTable;
import ca.uhn.fhir.jpa.term.api.ITermCodeSystemStorageSvc;
import ca.uhn.fhir.jpa.term.api.ITermReadSvc;
import ca.uhn.fhir.rest.api.server.storage.ResourcePersistentId;
import ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException;
import ca.uhn.fhir.rest.server.exceptions.UnprocessableEntityException;
import ca.uhn.fhir.rest.server.servlet.ServletRequestDetails;
import ca.uhn.fhir.util.UrlUtil;
import com.google.common.base.Charsets;
import org.apache.commons.io.IOUtils;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.hl7.fhir.instance.model.api.IIdType;
import org.hl7.fhir.r4.model.BooleanType;
import org.hl7.fhir.r4.model.Bundle;
import org.hl7.fhir.r4.model.CodeSystem;
import org.hl7.fhir.r4.model.CodeSystem.CodeSystemContentMode;
import org.hl7.fhir.r4.model.CodeSystem.ConceptDefinitionComponent;
import org.hl7.fhir.r4.model.CodeType;
import org.hl7.fhir.r4.model.CodeableConcept;
import org.hl7.fhir.r4.model.Coding;
import org.hl7.fhir.r4.model.Enumerations;
import org.hl7.fhir.r4.model.IdType;
import org.hl7.fhir.r4.model.Parameters;
import org.hl7.fhir.r4.model.StringType;
@ -41,6 +35,7 @@ import org.hl7.fhir.r4.model.ValueSet.FilterOperator;
import org.hl7.fhir.r4.model.codesystems.HttpVerb;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Slice;
import org.springframework.transaction.TransactionStatus;
@ -66,9 +61,9 @@ import static org.junit.jupiter.api.Assertions.assertSame;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;
public class ResourceProviderR4ValueSetVersionedTest extends BaseResourceProviderR4Test {
public class ResourceProviderR4ValueSetVerCSVerTest extends BaseResourceProviderR4Test {
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(ResourceProviderR4ValueSetVersionedTest.class);
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(ResourceProviderR4ValueSetVerCSVerTest.class);
private IIdType myExtensionalCsId_v1;
private IIdType myExtensionalCsId_v2;
private IIdType myExtensionalVsId_v1;
@ -79,6 +74,8 @@ public class ResourceProviderR4ValueSetVersionedTest extends BaseResourceProvide
private Long myExtensionalVsIdOnResourceTable_v2;
private ValueSet myLocalVs_v1;
private ValueSet myLocalVs_v2;
@Autowired
private ITermReadSvc myTermReadSvc;
private void loadAndPersistCodeSystemAndValueSet() throws IOException {
loadAndPersistCodeSystem();
@ -191,46 +188,6 @@ public class ResourceProviderR4ValueSetVersionedTest extends BaseResourceProvide
}
private void createLocalCs() {
CodeSystem codeSystem = new CodeSystem();
codeSystem.setUrl(URL_MY_CODE_SYSTEM);
codeSystem.setContent(CodeSystemContentMode.COMPLETE);
codeSystem
.addConcept().setCode("A").setDisplay("Code A")
.addConcept(new ConceptDefinitionComponent().setCode("AA").setDisplay("Code AA")
.addConcept(new ConceptDefinitionComponent().setCode("AAA").setDisplay("Code AAA"))
)
.addConcept(new ConceptDefinitionComponent().setCode("AB").setDisplay("Code AB"));
codeSystem
.addConcept().setCode("B").setDisplay("Code B")
.addConcept(new ConceptDefinitionComponent().setCode("BA").setDisplay("Code BA"))
.addConcept(new ConceptDefinitionComponent().setCode("BB").setDisplay("Code BB"));
myCodeSystemDao.create(codeSystem, mySrd);
}
private void createLocalVsWithIncludeConcept() {
myLocalVs_v1 = new ValueSet();
myLocalVs_v1.setUrl(URL_MY_VALUE_SET);
myLocalVs_v1.setVersion("1");
ConceptSetComponent include = myLocalVs_v1.getCompose().addInclude();
include.setSystem(URL_MY_CODE_SYSTEM);
include.setVersion("1");
include.addConcept().setCode("A").setDisplay("A v1");
include.addConcept().setCode("AA").setDisplay("AA v1");
myLocalValueSetId_v1 = myValueSetDao.create(myLocalVs_v1, mySrd).getId().toUnqualifiedVersionless();
myLocalVs_v2 = new ValueSet();
myLocalVs_v2.setUrl(URL_MY_VALUE_SET);
myLocalVs_v2.setVersion("2");
include = myLocalVs_v2.getCompose().addInclude();
include.setSystem(URL_MY_CODE_SYSTEM);
include.setVersion("2");
include.addConcept().setCode("A").setDisplay("A v2");
include.addConcept().setCode("AA").setDisplay("AA v2");
myLocalValueSetId_v2 = myValueSetDao.create(myLocalVs_v2, mySrd).getId().toUnqualifiedVersionless();
}
private ValueSet createLocalVs(String theCodeSystemUrl, String theValueSetVersion) {
ValueSet myLocalVs = new ValueSet();
myLocalVs.setUrl(URL_MY_VALUE_SET);
@ -1105,7 +1062,8 @@ public class ResourceProviderR4ValueSetVersionedTest extends BaseResourceProvide
TermValueSetConcept concept = termValueSet.getConcepts().get(0);
ourLog.info("Concept:\n" + concept.toString());
assertEquals("http://acme.org|1", concept.getSystem());
assertEquals("http://acme.org", concept.getSystem());
assertEquals("1", concept.getSystemVersion());
assertEquals("8450-9", concept.getCode());
assertEquals("Systolic blood pressure--expiration", concept.getDisplay());
assertEquals(2, concept.getDesignations().size());
@ -1127,7 +1085,8 @@ public class ResourceProviderR4ValueSetVersionedTest extends BaseResourceProvide
concept = termValueSet.getConcepts().get(1);
ourLog.info("Concept:\n" + concept.toString());
assertEquals("http://acme.org|1", concept.getSystem());
assertEquals("http://acme.org", concept.getSystem());
assertEquals("1", concept.getSystemVersion());
assertEquals("11378-7", concept.getCode());
assertEquals("Systolic blood pressure at First encounter", concept.getDisplay());
assertEquals(0, concept.getDesignations().size());
@ -1137,7 +1096,8 @@ public class ResourceProviderR4ValueSetVersionedTest extends BaseResourceProvide
concept = termValueSet.getConcepts().get(22);
ourLog.info("Concept:\n" + concept.toString());
assertEquals("http://acme.org|1", concept.getSystem());
assertEquals("http://acme.org", concept.getSystem());
assertEquals("1", concept.getSystemVersion());
assertEquals("8491-3", concept.getCode());
assertEquals("Systolic blood pressure 1 hour minimum", concept.getDisplay());
assertEquals(1, concept.getDesignations().size());
@ -1152,7 +1112,8 @@ public class ResourceProviderR4ValueSetVersionedTest extends BaseResourceProvide
concept = termValueSet.getConcepts().get(23);
ourLog.info("Concept:\n" + concept.toString());
assertEquals("http://acme.org|1", concept.getSystem());
assertEquals("http://acme.org", concept.getSystem());
assertEquals("1", concept.getSystemVersion());
assertEquals("8492-1", concept.getCode());
assertEquals("Systolic blood pressure 8 hour minimum", concept.getDisplay());
assertEquals(0, concept.getDesignations().size());
@ -1178,7 +1139,8 @@ public class ResourceProviderR4ValueSetVersionedTest extends BaseResourceProvide
TermValueSetConcept concept = termValueSet.getConcepts().get(0);
ourLog.info("Concept:\n" + concept.toString());
assertEquals("http://acme.org|2", concept.getSystem());
assertEquals("http://acme.org", concept.getSystem());
assertEquals("2", concept.getSystemVersion());
assertEquals("8450-9", concept.getCode());
assertEquals("Systolic blood pressure--expiration v2", concept.getDisplay());
assertEquals(2, concept.getDesignations().size());
@ -1200,7 +1162,8 @@ public class ResourceProviderR4ValueSetVersionedTest extends BaseResourceProvide
concept = termValueSet.getConcepts().get(1);
ourLog.info("Concept:\n" + concept.toString());
assertEquals("http://acme.org|2", concept.getSystem());
assertEquals("http://acme.org", concept.getSystem());
assertEquals("2", concept.getSystemVersion());
assertEquals("11378-7", concept.getCode());
assertEquals("Systolic blood pressure at First encounter v2", concept.getDisplay());
assertEquals(0, concept.getDesignations().size());
@ -1210,7 +1173,8 @@ public class ResourceProviderR4ValueSetVersionedTest extends BaseResourceProvide
concept = termValueSet.getConcepts().get(22);
ourLog.info("Concept:\n" + concept.toString());
assertEquals("http://acme.org|2", concept.getSystem());
assertEquals("http://acme.org", concept.getSystem());
assertEquals("2", concept.getSystemVersion());
assertEquals("8491-3", concept.getCode());
assertEquals("Systolic blood pressure 1 hour minimum v2", concept.getDisplay());
assertEquals(1, concept.getDesignations().size());
@ -1225,7 +1189,8 @@ public class ResourceProviderR4ValueSetVersionedTest extends BaseResourceProvide
concept = termValueSet.getConcepts().get(23);
ourLog.info("Concept:\n" + concept.toString());
assertEquals("http://acme.org|2", concept.getSystem());
assertEquals("http://acme.org", concept.getSystem());
assertEquals("2", concept.getSystemVersion());
assertEquals("8492-1", concept.getCode());
assertEquals("Systolic blood pressure 8 hour minimum v2", concept.getDisplay());
assertEquals(0, concept.getDesignations().size());
@ -1234,8 +1199,19 @@ public class ResourceProviderR4ValueSetVersionedTest extends BaseResourceProvide
}
@Test
public void testValidateCodeOperationByCodeAndSystem() throws Exception {
public void testValidateCodeOperationByCodeAndSystemBeforeExpand() throws Exception {
loadAndPersistCodeSystemAndValueSet();
testValidateCodeOperationByCodeAndSystem();
}
@Test
public void testValidateCodeOperationByCodeAndSystemAfterExpand() throws Exception {
loadAndPersistCodeSystemAndValueSet();
myTermReadSvc.preExpandDeferredValueSetsToTerminologyTables();
testValidateCodeOperationByCodeAndSystem();
}
private void testValidateCodeOperationByCodeAndSystem() throws Exception {
// With correct system version specified. Should pass.
Parameters respParam = myClient
@ -1270,6 +1246,37 @@ public class ResourceProviderR4ValueSetVersionedTest extends BaseResourceProvide
assertTrue(((BooleanType) respParam.getParameter().get(0).getValue()).booleanValue());
// With no ValueSet version specified and latest code system version. Should pass.
respParam = myClient
.operation()
.onType(ValueSet.class)
.named("validate-code")
.withParameter(Parameters.class, "code", new CodeType("8495-4"))
.andParameter("system", new UriType("http://acme.org"))
.andParameter("systemVersion", new StringType("2"))
.andParameter("url", new UriType("http://www.healthintersections.com.au/fhir/ValueSet/extensional-case-2"))
.execute();
resp = myFhirCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(respParam);
ourLog.info(resp);
assertTrue(((BooleanType) respParam.getParameter().get(0).getValue()).booleanValue());
// With no ValueSet version specified and no code system version. Should pass.
respParam = myClient
.operation()
.onType(ValueSet.class)
.named("validate-code")
.withParameter(Parameters.class, "code", new CodeType("8495-4"))
.andParameter("system", new UriType("http://acme.org"))
.andParameter("url", new UriType("http://www.healthintersections.com.au/fhir/ValueSet/extensional-case-2"))
.execute();
resp = myFhirCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(respParam);
ourLog.info(resp);
assertTrue(((BooleanType) respParam.getParameter().get(0).getValue()).booleanValue());
// With incorrect version specified. Should fail.
respParam = myClient
.operation()
@ -1303,12 +1310,38 @@ public class ResourceProviderR4ValueSetVersionedTest extends BaseResourceProvide
assertFalse(((BooleanType) respParam.getParameter().get(0).getValue()).booleanValue());
// With no ValueSet version specified and older code system version. Should fail.
respParam = myClient
.operation()
.onType(ValueSet.class)
.named("validate-code")
.withParameter(Parameters.class, "code", new CodeType("8495-4"))
.andParameter("system", new UriType("http://acme.org"))
.andParameter("systemVersion", new StringType("1"))
.andParameter("url", new UriType("http://www.healthintersections.com.au/fhir/ValueSet/extensional-case-2"))
.execute();
resp = myFhirCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(respParam);
ourLog.info(resp);
assertFalse(((BooleanType) respParam.getParameter().get(0).getValue()).booleanValue());
}
@Test
public void testValidateCodeOperationOnInstanceByCodeAndSystem() throws Exception {
public void testValidateCodeOperationOnInstanceByCodeAndSystemBeforeExpand() throws Exception {
loadAndPersistCodeSystemAndValueSet();
testValidateCodeOperationOnInstanceByCodeAndSystem();
}
@Test
public void testValidateCodeOperationOnInstanceByCodeAndSystemAfterExpand() throws Exception {
loadAndPersistCodeSystemAndValueSet();
myTermReadSvc.preExpandDeferredValueSetsToTerminologyTables();
testValidateCodeOperationOnInstanceByCodeAndSystem();
}
private void testValidateCodeOperationOnInstanceByCodeAndSystem() throws Exception {
// With correct system version specified. Should pass.
Parameters respParam = myClient
.operation()
@ -1338,6 +1371,35 @@ public class ResourceProviderR4ValueSetVersionedTest extends BaseResourceProvide
assertTrue(((BooleanType) respParam.getParameter().get(0).getValue()).booleanValue());
assertTrue(((BooleanType) respParam.getParameter().get(0).getValue()).booleanValue());
// With no CodeSystem version specified. Should pass as the code and system exist in both ValueSet versions.
respParam = myClient
.operation()
.onInstance(myExtensionalVsId_v2)
.named("validate-code")
.withParameter(Parameters.class, "code", new CodeType("8495-4"))
.andParameter("system", new UriType("http://acme.org"))
.execute();
resp = myFhirCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(respParam);
ourLog.info(resp);
assertTrue(((BooleanType) respParam.getParameter().get(0).getValue()).booleanValue());
respParam = myClient
.operation()
.onInstance(myExtensionalVsId_v1)
.named("validate-code")
.withParameter(Parameters.class, "code", new CodeType("8495-4"))
.andParameter("system", new UriType("http://acme.org"))
.execute();
resp = myFhirCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(respParam);
ourLog.info(resp);
assertTrue(((BooleanType) respParam.getParameter().get(0).getValue()).booleanValue());
// With incorrect version specified. Should fail.
respParam = myClient
.operation()
@ -1370,15 +1432,27 @@ public class ResourceProviderR4ValueSetVersionedTest extends BaseResourceProvide
}
@Test
public void testValidateCodeOperationByCoding() throws Exception {
public void testValidateCodeOperationByCodingBeforeExpand() throws Exception {
loadAndPersistCodeSystemAndValueSet();
testValidateCodeOperationByCoding();
}
@Test
public void testValidateCodeOperationByCodingAfterExpand() throws Exception {
loadAndPersistCodeSystemAndValueSet();
myTermReadSvc.preExpandDeferredValueSetsToTerminologyTables();
testValidateCodeOperationByCoding();
}
private void testValidateCodeOperationByCoding() throws Exception {
Coding codingToValidate_v1 = new Coding("http://acme.org", "8495-4", "Systolic blood pressure 24 hour minimum");
codingToValidate_v1.setVersion("1");
Coding codingToValidate_v2 = new Coding("http://acme.org", "8495-4", "Systolic blood pressure 24 hour minimum v2");
codingToValidate_v2.setVersion("2");
Coding codingToValidate_noV = new Coding("http://acme.org", "8495-4", null);
// With correct system version specified. Should pass.
Parameters respParam = myClient
.operation()
@ -1408,6 +1482,20 @@ public class ResourceProviderR4ValueSetVersionedTest extends BaseResourceProvide
assertTrue(((BooleanType) respParam.getParameter().get(0).getValue()).booleanValue());
// With no ValueSet version, and newer CodeSystem version. Should pass.
respParam = myClient
.operation()
.onType(ValueSet.class)
.named("validate-code")
.withParameter(Parameters.class, "coding", codingToValidate_v2)
.andParameter("url", new UriType("http://www.healthintersections.com.au/fhir/ValueSet/extensional-case-2"))
.execute();
resp = myFhirCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(respParam);
ourLog.info(resp);
assertTrue(((BooleanType) respParam.getParameter().get(0).getValue()).booleanValue());
// With incorrect version specified. Should fail.
respParam = myClient
.operation()
@ -1437,11 +1525,78 @@ public class ResourceProviderR4ValueSetVersionedTest extends BaseResourceProvide
assertFalse(((BooleanType) respParam.getParameter().get(0).getValue()).booleanValue());
// With no ValueSet version and older CodeSystem version. Should fail.
respParam = myClient
.operation()
.onType(ValueSet.class)
.named("validate-code")
.withParameter(Parameters.class, "coding", codingToValidate_v1)
.andParameter("url", new UriType("http://www.healthintersections.com.au/fhir/ValueSet/extensional-case-2"))
.execute();
resp = myFhirCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(respParam);
ourLog.info(resp);
assertFalse(((BooleanType) respParam.getParameter().get(0).getValue()).booleanValue());
// With no CodeSystem version. Should pass, regardless of ValueSet version.
respParam = myClient
.operation()
.onType(ValueSet.class)
.named("validate-code")
.withParameter(Parameters.class, "coding", codingToValidate_noV)
.andParameter("url", new UriType("http://www.healthintersections.com.au/fhir/ValueSet/extensional-case-2"))
.andParameter("valueSetVersion", new StringType("1"))
.execute();
resp = myFhirCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(respParam);
ourLog.info(resp);
assertTrue(((BooleanType) respParam.getParameter().get(0).getValue()).booleanValue());
respParam = myClient
.operation()
.onType(ValueSet.class)
.named("validate-code")
.withParameter(Parameters.class, "coding", codingToValidate_noV)
.andParameter("url", new UriType("http://www.healthintersections.com.au/fhir/ValueSet/extensional-case-2"))
.andParameter("valueSetVersion", new StringType("2"))
.execute();
resp = myFhirCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(respParam);
ourLog.info(resp);
assertTrue(((BooleanType) respParam.getParameter().get(0).getValue()).booleanValue());
respParam = myClient
.operation()
.onType(ValueSet.class)
.named("validate-code")
.withParameter(Parameters.class, "coding", codingToValidate_noV)
.andParameter("url", new UriType("http://www.healthintersections.com.au/fhir/ValueSet/extensional-case-2"))
.execute();
resp = myFhirCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(respParam);
ourLog.info(resp);
assertTrue(((BooleanType) respParam.getParameter().get(0).getValue()).booleanValue());
}
@Test
public void testValidateCodeOperationByCodeableConceptBeforeExpand() throws Exception {
loadAndPersistCodeSystemAndValueSet();
testValidateCodeOperationByCodeableConcept();
}
@Test
public void testValidateCodeOperationByCodeableConcept() throws Exception {
public void testValidateCodeOperationByCodeableConceptAfterExpand() throws Exception {
loadAndPersistCodeSystemAndValueSet();
myTermReadSvc.preExpandDeferredValueSetsToTerminologyTables();
testValidateCodeOperationByCodeableConcept();
}
private void testValidateCodeOperationByCodeableConcept() throws Exception {
Coding codingToValidate = new Coding("http://acme.org", "8495-4", "Systolic blood pressure 24 hour minimum");
codingToValidate.setVersion("1");
@ -1451,6 +1606,9 @@ public class ResourceProviderR4ValueSetVersionedTest extends BaseResourceProvide
codingToValidate.setVersion("2");
CodeableConcept codeableConceptToValidate_v2 = new CodeableConcept(codingToValidate);
codingToValidate = new Coding("http://acme.org", "8495-4", null);
CodeableConcept codeableConceptToValidate_noV = new CodeableConcept(codingToValidate);
// With correct system version specified. Should pass.
Parameters respParam = myClient
.operation()
@ -1480,6 +1638,20 @@ public class ResourceProviderR4ValueSetVersionedTest extends BaseResourceProvide
assertTrue(((BooleanType) respParam.getParameter().get(0).getValue()).booleanValue());
// With no ValueSet version and latest CodeSystem version. Should pass.
respParam = myClient
.operation()
.onType(ValueSet.class)
.named("validate-code")
.withParameter(Parameters.class, "codeableConcept", codeableConceptToValidate_v2)
.andParameter("url", new UriType("http://www.healthintersections.com.au/fhir/ValueSet/extensional-case-2"))
.execute();
resp = myFhirCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(respParam);
ourLog.info(resp);
assertTrue(((BooleanType) respParam.getParameter().get(0).getValue()).booleanValue());
// With incorrect version specified. Should fail.
respParam = myClient
.operation()
@ -1509,6 +1681,62 @@ public class ResourceProviderR4ValueSetVersionedTest extends BaseResourceProvide
assertFalse(((BooleanType) respParam.getParameter().get(0).getValue()).booleanValue());
// With no ValueSet version and older CodeSystem version. Should fail.
respParam = myClient
.operation()
.onType(ValueSet.class)
.named("validate-code")
.withParameter(Parameters.class, "codeableConcept", codeableConceptToValidate_v1)
.andParameter("url", new UriType("http://www.healthintersections.com.au/fhir/ValueSet/extensional-case-2"))
.execute();
resp = myFhirCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(respParam);
ourLog.info(resp);
assertFalse(((BooleanType) respParam.getParameter().get(0).getValue()).booleanValue());
// With no CodeSystem version. Should pass for all ValueSet versions.
respParam = myClient
.operation()
.onType(ValueSet.class)
.named("validate-code")
.withParameter(Parameters.class, "codeableConcept", codeableConceptToValidate_noV)
.andParameter("url", new UriType("http://www.healthintersections.com.au/fhir/ValueSet/extensional-case-2"))
.andParameter("valueSetVersion", new StringType("1"))
.execute();
resp = myFhirCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(respParam);
ourLog.info(resp);
assertTrue(((BooleanType) respParam.getParameter().get(0).getValue()).booleanValue());
respParam = myClient
.operation()
.onType(ValueSet.class)
.named("validate-code")
.withParameter(Parameters.class, "codeableConcept", codeableConceptToValidate_noV)
.andParameter("url", new UriType("http://www.healthintersections.com.au/fhir/ValueSet/extensional-case-2"))
.andParameter("valueSetVersion", new StringType("2"))
.execute();
resp = myFhirCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(respParam);
ourLog.info(resp);
assertTrue(((BooleanType) respParam.getParameter().get(0).getValue()).booleanValue());
respParam = myClient
.operation()
.onType(ValueSet.class)
.named("validate-code")
.withParameter(Parameters.class, "codeableConcept", codeableConceptToValidate_noV)
.andParameter("url", new UriType("http://www.healthintersections.com.au/fhir/ValueSet/extensional-case-2"))
.execute();
resp = myFhirCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(respParam);
ourLog.info(resp);
assertTrue(((BooleanType) respParam.getParameter().get(0).getValue()).booleanValue());
}
private boolean clearDeferredStorageQueue() {

View File

@ -1417,6 +1417,50 @@ public class ResourceProviderR5ValueSetTest extends BaseResourceProviderR5Test {
}
@Test
public void testExpandByValueSetWithFilter() throws IOException {
loadAndPersistCodeSystem(HTTPVerb.POST);
ValueSet toExpand = loadResourceFromClasspath(ValueSet.class, "/extensional-case-3-vs.xml");
Parameters respParam = myClient
.operation()
.onType(ValueSet.class)
.named("expand")
.withParameter(Parameters.class, "valueSet", toExpand)
.andParameter("filter", new StringType("blood"))
.execute();
ValueSet expanded = (ValueSet) respParam.getParameter().get(0).getResource();
String resp = myFhirCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(expanded);
ourLog.info(resp);
assertThat(resp, stringContainsInOrder(
"<code value=\"11378-7\"/>",
"<display value=\"Systolic blood pressure at First encounter\"/>"));
}
@Test
public void testExpandByUrlWithFilter() throws Exception {
loadAndPersistCodeSystemAndValueSet(HTTPVerb.POST);
Parameters respParam = myClient
.operation()
.onType(ValueSet.class)
.named("expand")
.withParameter(Parameters.class, "url", new UriType("http://www.healthintersections.com.au/fhir/ValueSet/extensional-case-2"))
.andParameter("filter", new StringType("first"))
.execute();
ValueSet expanded = (ValueSet) respParam.getParameter().get(0).getResource();
String resp = myFhirCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(expanded);
ourLog.info(resp);
assertThat(resp, stringContainsInOrder(
"<code value=\"11378-7\"/>",
"<display value=\"Systolic blood pressure at First encounter\"/>"));
}
@AfterEach
public void afterResetPreExpansionDefault() {
myDaoConfig.setPreExpandValueSets(new DaoConfig().isPreExpandValueSets());

View File

@ -1099,7 +1099,8 @@ public class ResourceProviderR5ValueSetVersionedTest extends BaseResourceProvide
TermValueSetConcept concept = termValueSet.getConcepts().get(0);
ourLog.info("Concept:\n" + concept.toString());
assertEquals("http://acme.org|1", concept.getSystem());
assertEquals("http://acme.org", concept.getSystem());
assertEquals("1", concept.getSystemVersion());
assertEquals("8450-9", concept.getCode());
assertEquals("Systolic blood pressure--expiration", concept.getDisplay());
assertEquals(2, concept.getDesignations().size());
@ -1121,7 +1122,8 @@ public class ResourceProviderR5ValueSetVersionedTest extends BaseResourceProvide
concept = termValueSet.getConcepts().get(1);
ourLog.info("Concept:\n" + concept.toString());
assertEquals("http://acme.org|1", concept.getSystem());
assertEquals("http://acme.org", concept.getSystem());
assertEquals("1", concept.getSystemVersion());
assertEquals("11378-7", concept.getCode());
assertEquals("Systolic blood pressure at First encounter", concept.getDisplay());
assertEquals(0, concept.getDesignations().size());
@ -1131,7 +1133,8 @@ public class ResourceProviderR5ValueSetVersionedTest extends BaseResourceProvide
concept = termValueSet.getConcepts().get(22);
ourLog.info("Concept:\n" + concept.toString());
assertEquals("http://acme.org|1", concept.getSystem());
assertEquals("http://acme.org", concept.getSystem());
assertEquals("1", concept.getSystemVersion());
assertEquals("8491-3", concept.getCode());
assertEquals("Systolic blood pressure 1 hour minimum", concept.getDisplay());
assertEquals(1, concept.getDesignations().size());
@ -1146,7 +1149,8 @@ public class ResourceProviderR5ValueSetVersionedTest extends BaseResourceProvide
concept = termValueSet.getConcepts().get(23);
ourLog.info("Concept:\n" + concept.toString());
assertEquals("http://acme.org|1", concept.getSystem());
assertEquals("http://acme.org", concept.getSystem());
assertEquals("1", concept.getSystemVersion());
assertEquals("8492-1", concept.getCode());
assertEquals("Systolic blood pressure 8 hour minimum", concept.getDisplay());
assertEquals(0, concept.getDesignations().size());
@ -1172,7 +1176,8 @@ public class ResourceProviderR5ValueSetVersionedTest extends BaseResourceProvide
TermValueSetConcept concept = termValueSet.getConcepts().get(0);
ourLog.info("Concept:\n" + concept.toString());
assertEquals("http://acme.org|2", concept.getSystem());
assertEquals("http://acme.org", concept.getSystem());
assertEquals("2", concept.getSystemVersion());
assertEquals("8450-9", concept.getCode());
assertEquals("Systolic blood pressure--expiration v2", concept.getDisplay());
assertEquals(2, concept.getDesignations().size());
@ -1194,7 +1199,8 @@ public class ResourceProviderR5ValueSetVersionedTest extends BaseResourceProvide
concept = termValueSet.getConcepts().get(1);
ourLog.info("Concept:\n" + concept.toString());
assertEquals("http://acme.org|2", concept.getSystem());
assertEquals("http://acme.org", concept.getSystem());
assertEquals("2", concept.getSystemVersion());
assertEquals("11378-7", concept.getCode());
assertEquals("Systolic blood pressure at First encounter v2", concept.getDisplay());
assertEquals(0, concept.getDesignations().size());
@ -1204,7 +1210,8 @@ public class ResourceProviderR5ValueSetVersionedTest extends BaseResourceProvide
concept = termValueSet.getConcepts().get(22);
ourLog.info("Concept:\n" + concept.toString());
assertEquals("http://acme.org|2", concept.getSystem());
assertEquals("http://acme.org", concept.getSystem());
assertEquals("2", concept.getSystemVersion());
assertEquals("8491-3", concept.getCode());
assertEquals("Systolic blood pressure 1 hour minimum v2", concept.getDisplay());
assertEquals(1, concept.getDesignations().size());
@ -1219,7 +1226,8 @@ public class ResourceProviderR5ValueSetVersionedTest extends BaseResourceProvide
concept = termValueSet.getConcepts().get(23);
ourLog.info("Concept:\n" + concept.toString());
assertEquals("http://acme.org|2", concept.getSystem());
assertEquals("http://acme.org", concept.getSystem());
assertEquals("2", concept.getSystemVersion());
assertEquals("8492-1", concept.getCode());
assertEquals("Systolic blood pressure 8 hour minimum v2", concept.getDisplay());
assertEquals(0, concept.getDesignations().size());

View File

@ -21,6 +21,7 @@ package ca.uhn.fhir.jpa.migrate.tasks;
*/
import ca.uhn.fhir.jpa.entity.EmpiLink;
import ca.uhn.fhir.jpa.entity.TermCodeSystemVersion;
import ca.uhn.fhir.jpa.entity.TermConceptMap;
import ca.uhn.fhir.jpa.entity.TermValueSet;
import ca.uhn.fhir.jpa.migrate.DriverTypeEnum;
@ -157,6 +158,12 @@ public class HapiFhirJpaMigrationTasks extends BaseMigrationTasks<VersionEnum> {
trmValueSet.addColumn("20200923.2", "VER").nullable().type(ColumnTypeEnum.STRING, TermValueSet.MAX_VER_LENGTH);
trmValueSet.dropIndex("20200923.3", "IDX_VALUESET_URL");
trmValueSet.addIndex("20200923.4", "IDX_VALUESET_URL").unique(true).withColumns("URL", "VER");
//Term ValueSet Component add system version
Builder.BuilderWithTableName trmValueSetComp = version.onTable("TRM_VALUESET_CONCEPT");
trmValueSetComp.addColumn("20201028.1", "SYSTEM_VER").nullable().type(ColumnTypeEnum.STRING, TermCodeSystemVersion.MAX_VERSION_LENGTH);
trmValueSetComp.dropIndex("20201028.2", "IDX_VS_CONCEPT_CS_CD");
trmValueSetComp.addIndex("20201028.3", "IDX_VS_CONCEPT_CS_CD").unique(true).withColumns("VALUESET_PID", "SYSTEM_URL", "SYSTEM_VER", "CODEVAL");
}
protected void init510_20200725() {