Customize concept display in value set expansion (#2282)

* fix issue #2280

* revert the indentation back.

* revert-back untouched changes.
This commit is contained in:
Hanan Awwad 2021-02-07 19:29:05 +02:00 committed by GitHub
parent c69d741b43
commit 6384067e50
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 43 additions and 3 deletions

View File

@ -575,7 +575,7 @@ public abstract class BaseTermReadSvcImpl implements ITermReadSvc {
//-- this is quick solution, may need to revisit //-- this is quick solution, may need to revisit
if (!applyFilter(display, filterDisplayValue)) if (!applyFilter(display, filterDisplayValue))
continue; continue;
Long conceptPid = conceptView.getConceptPid(); Long conceptPid = conceptView.getConceptPid();
if (!pidToConcept.containsKey(conceptPid)) { if (!pidToConcept.containsKey(conceptPid)) {
FhirVersionIndependentConcept concept = new FhirVersionIndependentConcept(system, code, display); 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) { public boolean applyFilter(final String theDisplay, final String theFilterDisplay) {
//-- safety check only, no need to apply filter //-- safety check only, no need to apply filter
if (theDisplay == null || theFilterDisplay == null) if (theDisplay == null || theFilterDisplay == null)
return true; return true;
@ -654,7 +654,7 @@ public abstract class BaseTermReadSvcImpl implements ITermReadSvc {
// -- sentence case // -- sentence case
if (startsWithIgnoreCase(theDisplay, theFilterDisplay)) if (startsWithIgnoreCase(theDisplay, theFilterDisplay))
return true; return true;
//-- token case //-- token case
if (startsWithByWordBoundaries(theDisplay, theFilterDisplay)) return true; if (startsWithByWordBoundaries(theDisplay, theFilterDisplay)) return true;
@ -1019,6 +1019,12 @@ public abstract class BaseTermReadSvcImpl implements ITermReadSvc {
for (TermConcept concept: termConcepts) { for (TermConcept concept: termConcepts) {
count.incrementAndGet(); count.incrementAndGet();
countForBatch.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); boolean added = addCodeIfNotAlreadyAdded(theValueSetCodeAccumulator, theAddedCodes, concept, theAdd, includeOrExcludeVersion);
if (added) { if (added) {
delta++; 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 * Helper method which builds a predicate for the expansion
*/ */

View File

@ -330,6 +330,33 @@ public class FhirResourceDaoR4TerminologyTest extends BaseJpaR4Test {
assertEquals("Invalid filter, must have fields populated: property op value", e.getMessage()); 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<String> codes = toCodesContains(result.getExpansion().getContains());
assertThat(codes, containsInAnyOrder("hello", "goodbye"));
for (ValueSetExpansionContainsComponent vsConcept : result.getExpansion().getContains()){
assertTrue(vsConcept.getDisplay().contains("VS"));
}
}
@Test @Test
public void testExpandWithCodesAndDisplayFilterBlank() { public void testExpandWithCodesAndDisplayFilterBlank() {