From 758c8f12ddde506f4c9f15f3267bebeae1391315 Mon Sep 17 00:00:00 2001 From: ivagulin Date: Mon, 23 Jan 2023 18:25:24 +0300 Subject: [PATCH] fix ValueSet$expand?includeHierarchy=true with fts disabled (#4449) * fix ValueSet$expand?includeHierarchy=true * add test for valuset$expand with hierarchy without hibernate search * move testExpandValueSet_PreExpandedWithHierarchyNoHibernateSearch to FhirResourceDaoR4ValueSetTest, add javadoc * Add credit Co-authored-by: James Agnew --- .../6_4_0/4449-fix-expand-with-hierarchy.yaml | 6 +++ ...ansionComponentWithConceptAccumulator.java | 2 +- .../dao/r4/FhirResourceDaoR4ValueSetTest.java | 46 ++++++++++++++++++- pom.xml | 3 ++ 4 files changed, 54 insertions(+), 3 deletions(-) create mode 100644 hapi-fhir-docs/src/main/resources/ca/uhn/hapi/fhir/changelog/6_4_0/4449-fix-expand-with-hierarchy.yaml diff --git a/hapi-fhir-docs/src/main/resources/ca/uhn/hapi/fhir/changelog/6_4_0/4449-fix-expand-with-hierarchy.yaml b/hapi-fhir-docs/src/main/resources/ca/uhn/hapi/fhir/changelog/6_4_0/4449-fix-expand-with-hierarchy.yaml new file mode 100644 index 00000000000..27dfda8f81f --- /dev/null +++ b/hapi-fhir-docs/src/main/resources/ca/uhn/hapi/fhir/changelog/6_4_0/4449-fix-expand-with-hierarchy.yaml @@ -0,0 +1,6 @@ +--- +type: fix +issue: 4449 +title: "A bug prevented valueset expansion with includeHierarchy=true when lucene/elasticsearch + was not enabled. This has been corrected. Thanks to GitHub user @ivagulin for the + contribution!" diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/term/ValueSetExpansionComponentWithConceptAccumulator.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/term/ValueSetExpansionComponentWithConceptAccumulator.java index a27eebf1907..8dd8ea19016 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/term/ValueSetExpansionComponentWithConceptAccumulator.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/term/ValueSetExpansionComponentWithConceptAccumulator.java @@ -250,7 +250,7 @@ public class ValueSetExpansionComponentWithConceptAccumulator extends ValueSet.V ValueSet.ValueSetExpansionContainsComponent nextContains = this.getContains().get(i); String directParentPidsString = myConceptToSourceDirectParentPids.get(nextContains); - if (isNotBlank(directParentPidsString)) { + if (isNotBlank(directParentPidsString) && !directParentPidsString.equals("NONE")) { List directParentPids = Arrays.stream(directParentPidsString.split(" ")).map(t -> Long.parseLong(t)).collect(Collectors.toList()); boolean firstMatch = false; diff --git a/hapi-fhir-jpaserver-test-r4/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4ValueSetTest.java b/hapi-fhir-jpaserver-test-r4/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4ValueSetTest.java index eeb8b7b77c6..f33bb6b985c 100644 --- a/hapi-fhir-jpaserver-test-r4/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4ValueSetTest.java +++ b/hapi-fhir-jpaserver-test-r4/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4ValueSetTest.java @@ -572,7 +572,49 @@ public class FhirResourceDaoR4ValueSetTest extends BaseJpaR4Test { } + /** See #4449 */ + @Test + public void testExpandValueSet_PreExpandedWithHierarchyNoHibernateSearch() { + CodeSystem cs = new CodeSystem(); + cs.setId("icd10cm"); + cs.setStatus(Enumerations.PublicationStatus.ACTIVE); + cs.setContent(CodeSystem.CodeSystemContentMode.COMPLETE); + cs.setUrl("http://hl7.org/fhir/sid/icd-10-cm"); + cs.setVersion("2021"); + + CodeSystem.ConceptDefinitionComponent parent = cs.addConcept() + .setCode("A00") + .setDisplay("Cholera"); + parent.addConcept() + .setCode("A00.0") + .setDisplay("Cholera due to Vibrio cholerae 01, biovar cholerae"); + parent.addConcept() + .setCode("A00.1") + .setDisplay("Cholera due to Vibrio cholerae 01, biovar eltor"); + myCodeSystemDao.update(cs, mySrd); + + ValueSet vs = new ValueSet(); + vs.setId("icd10cm-valueset"); + vs.setUrl("http://hl7.org/fhir/ValueSet/icd-10-cm"); + vs.setVersion("2021"); + vs.setStatus(Enumerations.PublicationStatus.ACTIVE); + ValueSet.ConceptSetComponent vsInclude = vs.getCompose().addInclude(); + vsInclude.setSystem("http://hl7.org/fhir/sid/icd-10-cm"); + vsInclude.setVersion("2021"); + myValueSetDao.update(vs, mySrd); + + TermReadSvcImpl.setForceDisableHibernateSearchForUnitTest(true); + myTerminologyDeferredStorageSvc.saveAllDeferred(); + myTermSvc.preExpandDeferredValueSetsToTerminologyTables(); + + ValueSetExpansionOptions options = new ValueSetExpansionOptions(); + options.setIncludeHierarchy(true); + ValueSet valueSet = myValueSetDao.expand(vs, options); + + assertNotNull(valueSet); + assertEquals(1, valueSet.getExpansion().getContains().size()); + assertEquals(2, valueSet.getExpansion().getContains().get(0).getContains().size()); + } + } - - diff --git a/pom.xml b/pom.xml index 9206627778a..0b647b02458 100644 --- a/pom.xml +++ b/pom.xml @@ -843,6 +843,9 @@ granadacoder + + ivagulin +