diff --git a/fhir-term-graph/src/main/java/com/ibm/fhir/term/graph/provider/GraphTermServiceProvider.java b/fhir-term-graph/src/main/java/com/ibm/fhir/term/graph/provider/GraphTermServiceProvider.java index 4c192c85cf9..4a1d31fe44e 100644 --- a/fhir-term-graph/src/main/java/com/ibm/fhir/term/graph/provider/GraphTermServiceProvider.java +++ b/fhir-term-graph/src/main/java/com/ibm/fhir/term/graph/provider/GraphTermServiceProvider.java @@ -28,9 +28,11 @@ import com.ibm.fhir.model.resource.CodeSystem; import com.ibm.fhir.model.resource.CodeSystem.Concept; import com.ibm.fhir.model.resource.CodeSystem.Concept.Designation; +import com.ibm.fhir.model.resource.CodeSystem.Concept.Property; import com.ibm.fhir.model.resource.ValueSet.Compose.Include.Filter; import com.ibm.fhir.model.type.Code; import com.ibm.fhir.model.type.Coding; +import com.ibm.fhir.model.type.Element; import com.ibm.fhir.model.type.Uri; import com.ibm.fhir.term.graph.FHIRTermGraph; import com.ibm.fhir.term.graph.FHIRTermGraphFactory; @@ -63,10 +65,10 @@ public boolean hasConcept(CodeSystem codeSystem, Code code) { @Override public Concept getConcept(CodeSystem codeSystem, Code code) { Objects.requireNonNull(codeSystem.getUrl(), "CodeSystem.url"); - return getConcept(codeSystem, code, true); + return getConcept(codeSystem, code, true, true); } - private Concept getConcept(CodeSystem codeSystem, Code code, boolean includeDesignations) { + private Concept getConcept(CodeSystem codeSystem, Code code, boolean includeDesignations, boolean includeProperties) { Objects.requireNonNull(codeSystem.getUrl(), "CodeSystem.url"); return createConcept( codeSystem, @@ -74,7 +76,8 @@ private Concept getConcept(CodeSystem codeSystem, Code code, boolean includeDesi whereCodeSystem(hasCode(g.V(), code.getValue(), isCaseSensitive(codeSystem)), codeSystem) .elementMap() .tryNext(), - includeDesignations); + includeDesignations, + includeProperties); } @Override @@ -112,7 +115,7 @@ public Set getConcepts(CodeSystem codeSystem, List filters) { public Set closure(CodeSystem codeSystem, Code code) { Objects.requireNonNull(codeSystem.getUrl(), "CodeSystem.url"); Set concepts = new LinkedHashSet<>(); - concepts.add(getConcept(codeSystem, code, false)); + concepts.add(getConcept(codeSystem, code, false, false)); whereCodeSystem(hasCode(g.V(), code.getValue(), isCaseSensitive(codeSystem)), codeSystem) .repeat(__.in("isA") .simplePath() @@ -164,22 +167,23 @@ private GraphTraversal whereCodeSystem(GraphTraversal> optional, boolean includeDesignations) { + private Concept createConcept(CodeSystem codeSystem, String code, Optional> optional, boolean includeDesignations, boolean includeProperties) { if (optional.isPresent()) { - return createConcept(optional.get(), includeDesignations ? getDesignations(codeSystem, code) : Collections.emptyList()); + return createConcept(optional.get(), includeDesignations ? getDesignations(codeSystem, code) : Collections.emptyList(), includeProperties ? getProperties(codeSystem, code) : Collections.emptyList()); } return null; } private Concept createConcept(Map elementMap) { - return createConcept(elementMap, Collections.emptyList()); + return createConcept(elementMap, Collections.emptyList(), Collections.emptyList()); } - private Concept createConcept(Map elementMap, List designations) { + private Concept createConcept(Map elementMap, List designations, List properties) { return Concept.builder() .code(Code.of((String) elementMap.get("code"))) .display(string((String) elementMap.get("display"))) .designation(designations) + .property(properties) .build(); } @@ -210,6 +214,33 @@ private List getDesignations(CodeSystem codeSystem, String code) { return designations; } + private List getProperties(CodeSystem codeSystem, String code) { + Objects.requireNonNull(codeSystem.getUrl(), "CodeSystem.url"); + List properties = new ArrayList<>(); + whereCodeSystem(hasCode(g.V(), code, isCaseSensitive(codeSystem)), codeSystem) + .out("property_") + .elementMap() + .toStream() + .forEach(elementMap -> properties.add(createProperty(elementMap))); + return properties; + } + + private Property createProperty(Map elementMap) { + return Property.builder() + .code(Code.of((String) elementMap.get("code"))) + .value(getElement(elementMap)) + .build(); + } + + private Element getElement(Map elementMap) { + for (Object value : elementMap.values()) { + if (value instanceof Element) { + return (Element) value; + } + } + return null; + } + private String getDesignationUseSystem(CodeSystem codeSystem) { Objects.requireNonNull(codeSystem.getUrl(), "CodeSystem.url"); Optional> optional = hasVersion(hasUrl(g.V(), codeSystem.getUrl()), codeSystem.getVersion()) diff --git a/fhir-term-graph/src/test/java/com/ibm/fhir/term/graph/test/CodeSystemTermGraphLoaderTest.java b/fhir-term-graph/src/test/java/com/ibm/fhir/term/graph/test/CodeSystemTermGraphLoaderTest.java index ee191698e93..0f7dd1883ca 100644 --- a/fhir-term-graph/src/test/java/com/ibm/fhir/term/graph/test/CodeSystemTermGraphLoaderTest.java +++ b/fhir-term-graph/src/test/java/com/ibm/fhir/term/graph/test/CodeSystemTermGraphLoaderTest.java @@ -29,6 +29,7 @@ public static void main(String[] args) throws Exception { GraphTermServiceProvider provider = new GraphTermServiceProvider(new PropertiesConfiguration("conf/local-graph.properties")); System.out.println(provider.subsumes(codeSystem, Code.of("m"), Code.of("p"))); + System.out.println(provider.getConcept(codeSystem, Code.of("o"))); provider.getGraph().close(); } }