From 6384067e5057b4553a946133103fcf2579613a37 Mon Sep 17 00:00:00 2001 From: Hanan Awwad Date: Sun, 7 Feb 2021 19:29:05 +0200 Subject: [PATCH] Customize concept display in value set expansion (#2282) * fix issue #2280 * revert the indentation back. * revert-back untouched changes. --- .../fhir/jpa/term/BaseTermReadSvcImpl.java | 19 ++++++++++--- .../r4/FhirResourceDaoR4TerminologyTest.java | 27 +++++++++++++++++++ 2 files changed, 43 insertions(+), 3 deletions(-) diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/term/BaseTermReadSvcImpl.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/term/BaseTermReadSvcImpl.java index 1a78e39863d..d139c249513 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/term/BaseTermReadSvcImpl.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/term/BaseTermReadSvcImpl.java @@ -575,7 +575,7 @@ public abstract class BaseTermReadSvcImpl implements ITermReadSvc { //-- this is quick solution, may need to revisit if (!applyFilter(display, filterDisplayValue)) continue; - + Long conceptPid = conceptView.getConceptPid(); if (!pidToConcept.containsKey(conceptPid)) { FhirVersionIndependentConcept concept = new FhirVersionIndependentConcept(system, code, display); @@ -646,7 +646,7 @@ public abstract class BaseTermReadSvcImpl implements ITermReadSvc { } public boolean applyFilter(final String theDisplay, final String theFilterDisplay) { - + //-- safety check only, no need to apply filter if (theDisplay == null || theFilterDisplay == null) return true; @@ -654,7 +654,7 @@ public abstract class BaseTermReadSvcImpl implements ITermReadSvc { // -- sentence case if (startsWithIgnoreCase(theDisplay, theFilterDisplay)) return true; - + //-- token case if (startsWithByWordBoundaries(theDisplay, theFilterDisplay)) return true; @@ -1019,6 +1019,12 @@ public abstract class BaseTermReadSvcImpl implements ITermReadSvc { for (TermConcept concept: termConcepts) { count.incrementAndGet(); countForBatch.incrementAndGet(); + if (theAdd && expansionStep != null) { + ValueSet.ConceptReferenceComponent theIncludeConcept = getMatchedConceptIncludedInValueSet(theIncludeOrExclude, concept); + if (theIncludeConcept != null && isNotBlank(theIncludeConcept.getDisplay())) { + concept.setDisplay(theIncludeConcept.getDisplay()); + } + } boolean added = addCodeIfNotAlreadyAdded(theValueSetCodeAccumulator, theAddedCodes, concept, theAdd, includeOrExcludeVersion); if (added) { delta++; @@ -1036,6 +1042,13 @@ public abstract class BaseTermReadSvcImpl implements ITermReadSvc { } } + private ValueSet.ConceptReferenceComponent getMatchedConceptIncludedInValueSet(ValueSet.ConceptSetComponent theIncludeOrExclude, TermConcept concept) { + ValueSet.ConceptReferenceComponent theIncludeConcept = theIncludeOrExclude.getConcept().stream().filter(includedConcept -> + includedConcept.getCode().equalsIgnoreCase(concept.getCode()) + ).findFirst().orElse(null); + return theIncludeConcept; + } + /** * Helper method which builds a predicate for the expansion */ diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4TerminologyTest.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4TerminologyTest.java index b1887af5705..5c653decb9a 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4TerminologyTest.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4TerminologyTest.java @@ -330,6 +330,33 @@ public class FhirResourceDaoR4TerminologyTest extends BaseJpaR4Test { assertEquals("Invalid filter, must have fields populated: property op value", e.getMessage()); } } + @Test + public void testExpandWithIncludeConceptHaveCodeAndDisplay() { + CodeSystem codeSystem = createExternalCsDogs(); + + ValueSet valueSet = new ValueSet(); + valueSet.setUrl(URL_MY_VALUE_SET); + valueSet.getCompose() + .addInclude() + .setSystem(codeSystem.getUrl()) + .addConcept(new ConceptReferenceComponent().setCode("hello").setDisplay("Display-VS")) + .addConcept(new ConceptReferenceComponent().setCode("goodbye").setDisplay("Goodbye-VS")); + + myValueSetDao.create(valueSet, mySrd); + + ValueSet result = myValueSetDao.expand(valueSet, ""); + logAndValidateValueSet(result); + + assertEquals(2, result.getExpansion().getTotal()); + ArrayList codes = toCodesContains(result.getExpansion().getContains()); + assertThat(codes, containsInAnyOrder("hello", "goodbye")); + for (ValueSetExpansionContainsComponent vsConcept : result.getExpansion().getContains()){ + assertTrue(vsConcept.getDisplay().contains("VS")); + } + + + } + @Test public void testExpandWithCodesAndDisplayFilterBlank() {