-
Notifications
You must be signed in to change notification settings - Fork 160
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
issue #3448 - convert property-based concept hiearchies in getConcepts
1. added `hasPropertyHierarchy` and `convertToSimpleCodeSystem` utilities to CodeSystemSupport. the conversion utility uses JGraphT to simplify the creation of an acyclic directed graph and then traverses that structure to build an updated CodeSystem resource with nested concepts. this allows the rest of our CodeSystemSupport to stay the same. 2. call `convertToSimpleCodeSystem` from RegistryTermServiceProvider.getConcepts to convert property-based hierarchy into the more-common nested concept flavor so that we can use our existing CodeSystemSupport filter approach for CodeSystems in the registry 3. added hand-crafted CodeSystem resources that test parent-to-child and child-to-parent edges with the conversion logic 4. added tests to verify our updated expansions match the expansions from tx.fhir.org for select ValueSets that draw from polyhierarchical CodeSystems like v3-ActCode and v3-RoleCode Signed-off-by: Lee Surprenant <[email protected]>
- Loading branch information
Showing
20 changed files
with
3,278 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 79 additions & 0 deletions
79
.../fhir-term/src/test/java/com/ibm/fhir/term/service/test/HL7TermValueSetExpansionTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
/* | ||
* (C) Copyright IBM Corp. 2022 | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
package com.ibm.fhir.term.service.test; | ||
|
||
import static org.testng.Assert.assertNotNull; | ||
import static org.testng.Assert.assertTrue; | ||
|
||
import java.io.Reader; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.util.HashSet; | ||
import java.util.Set; | ||
import java.util.stream.Collectors; | ||
|
||
import org.testng.annotations.Test; | ||
|
||
import com.ibm.fhir.model.format.Format; | ||
import com.ibm.fhir.model.parser.FHIRParser; | ||
import com.ibm.fhir.model.resource.ValueSet; | ||
import com.ibm.fhir.term.util.ValueSetSupport; | ||
|
||
public class HL7TermValueSetExpansionTest { | ||
FHIRParser parser = FHIRParser.parser(Format.JSON); | ||
|
||
/** | ||
* Compare FHIRTermService ValueSet expansion to expanded ValueSets obtained from https://tx.fhir.org | ||
* | ||
* Note: tx.fhir.org has seems to have some stale expansions. In all of the following cases, our expansion | ||
* differed and I think our expansion is right for the version of the hl7.terminology package we're using (3.1.0). | ||
* | ||
* <ul> | ||
* <li> ValueSet-parent-relationship-codes.json | ||
* <li> ValueSet-v3-Confidentiality.json | ||
* <li> ValueSet-v3-PurposeOfUse.json | ||
* </ul> | ||
*/ | ||
@Test | ||
void testHl7TermValueSetExpansion() throws Exception { | ||
Path expandedValueSetsDir = Path.of("src/test/resources/tx-expanded-valuesets"); | ||
|
||
Set<Path> valueSetFiles = Files.list(expandedValueSetsDir).collect(Collectors.toSet()); | ||
for (Path path : valueSetFiles) { | ||
try (Reader reader = Files.newBufferedReader(path)) { | ||
ValueSet txExpandedValueSet = parser.parse(reader); | ||
String url = txExpandedValueSet.getUrl().getValue(); | ||
|
||
// the version might not match, but these ValueSets shouldn't change much and so thats probably ok | ||
ValueSet ourValueSet = ValueSetSupport.getValueSet(url); | ||
ValueSet ourExpandedValueSet = ValueSetSupport.expand(ourValueSet); | ||
|
||
ValueSet.Expansion ourExpansion = ourExpandedValueSet.getExpansion(); | ||
assertNotNull(ourExpansion); | ||
|
||
Set<String> ourConcepts = new HashSet<>(); | ||
for (ValueSet.Expansion.Contains concept : ourExpandedValueSet.getExpansion().getContains()) { | ||
ourConcepts.add(concept.getSystem().getValue() + "|" + concept.getCode().getValue()); | ||
} | ||
|
||
Set<String> theirConcepts = new HashSet<>(); | ||
for (ValueSet.Expansion.Contains concept : txExpandedValueSet.getExpansion().getContains()) { | ||
theirConcepts.add(concept.getSystem().getValue() + "|" + concept.getCode().getValue()); | ||
} | ||
|
||
Set<String> diffSet; | ||
|
||
diffSet = new HashSet<>(theirConcepts); | ||
diffSet.removeAll(ourConcepts); | ||
assertTrue(diffSet.isEmpty(), "all their codes are in our set: " + diffSet.toString()); | ||
|
||
diffSet = new HashSet<>(ourConcepts); | ||
diffSet.removeAll(theirConcepts); | ||
assertTrue(diffSet.isEmpty(), "all our codes are in their set: " + diffSet.toString()); | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.