Skip to content

Commit

Permalink
Issue #2162 - miscellaneous updates
Browse files Browse the repository at this point in the history
Signed-off-by: John T.E. Timm <johntimm@us.ibm.com>
  • Loading branch information
JohnTimm committed Apr 7, 2021
1 parent 83d6560 commit 28680ec
Show file tree
Hide file tree
Showing 27 changed files with 339 additions and 157 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* (C) Copyright IBM Corp. 2020
* (C) Copyright IBM Corp. 2020, 2021
*
* SPDX-License-Identifier: Apache-2.0
*/
Expand Down Expand Up @@ -33,7 +33,7 @@
import com.ibm.fhir.path.FHIRPathNode;
import com.ibm.fhir.path.FHIRPathResourceNode;
import com.ibm.fhir.path.evaluator.FHIRPathEvaluator.EvaluationContext;
import com.ibm.fhir.term.spi.ExpansionParameters;
import com.ibm.fhir.term.service.ExpansionParameters;

public class ExpandFunction extends FHIRPathAbstractTermFunction {
@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* (C) Copyright IBM Corp. 2020
* (C) Copyright IBM Corp. 2020, 2021
*
* SPDX-License-Identifier: Apache-2.0
*/
Expand Down Expand Up @@ -29,8 +29,8 @@
import com.ibm.fhir.path.FHIRPathNode;
import com.ibm.fhir.path.FHIRPathResourceNode;
import com.ibm.fhir.path.evaluator.FHIRPathEvaluator.EvaluationContext;
import com.ibm.fhir.term.spi.LookupOutcome;
import com.ibm.fhir.term.spi.LookupParameters;
import com.ibm.fhir.term.service.LookupOutcome;
import com.ibm.fhir.term.service.LookupParameters;

public class LookupFunction extends FHIRPathAbstractTermFunction {
@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* (C) Copyright IBM Corp. 2019, 2020
* (C) Copyright IBM Corp. 2019, 2021
*
* SPDX-License-Identifier: Apache-2.0
*/
Expand Down Expand Up @@ -40,7 +40,7 @@
import com.ibm.fhir.path.FHIRPathType;
import com.ibm.fhir.path.evaluator.FHIRPathEvaluator.EvaluationContext;
import com.ibm.fhir.term.service.FHIRTermService;
import com.ibm.fhir.term.spi.ValidationOutcome;
import com.ibm.fhir.term.service.ValidationOutcome;

/**
* Implementation of the 'memberOf' FHIRPath function per: <a href="http://hl7.org/fhir/fhirpath.html#functions">http://hl7.org/fhir/fhirpath.html#functions</a>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* (C) Copyright IBM Corp. 2020
* (C) Copyright IBM Corp. 2020, 2021
*
* SPDX-License-Identifier: Apache-2.0
*/
Expand Down Expand Up @@ -31,8 +31,8 @@
import com.ibm.fhir.path.FHIRPathNode;
import com.ibm.fhir.path.FHIRPathResourceNode;
import com.ibm.fhir.path.evaluator.FHIRPathEvaluator.EvaluationContext;
import com.ibm.fhir.term.spi.TranslationOutcome;
import com.ibm.fhir.term.spi.TranslationParameters;
import com.ibm.fhir.term.service.TranslationOutcome;
import com.ibm.fhir.term.service.TranslationParameters;

public class TranslateFunction extends FHIRPathAbstractTermFunction {
@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* (C) Copyright IBM Corp. 2020
* (C) Copyright IBM Corp. 2020, 2021
*
* SPDX-License-Identifier: Apache-2.0
*/
Expand Down Expand Up @@ -33,8 +33,8 @@
import com.ibm.fhir.path.FHIRPathNode;
import com.ibm.fhir.path.FHIRPathResourceNode;
import com.ibm.fhir.path.evaluator.FHIRPathEvaluator.EvaluationContext;
import com.ibm.fhir.term.spi.ValidationOutcome;
import com.ibm.fhir.term.spi.ValidationParameters;
import com.ibm.fhir.term.service.ValidationOutcome;
import com.ibm.fhir.term.service.ValidationParameters;

public class ValidateCSFunction extends FHIRPathAbstractTermFunction {
@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* (C) Copyright IBM Corp. 2020
* (C) Copyright IBM Corp. 2020, 2021
*
* SPDX-License-Identifier: Apache-2.0
*/
Expand Down Expand Up @@ -33,8 +33,8 @@
import com.ibm.fhir.path.FHIRPathNode;
import com.ibm.fhir.path.FHIRPathResourceNode;
import com.ibm.fhir.path.evaluator.FHIRPathEvaluator.EvaluationContext;
import com.ibm.fhir.term.spi.ValidationOutcome;
import com.ibm.fhir.term.spi.ValidationParameters;
import com.ibm.fhir.term.service.ValidationOutcome;
import com.ibm.fhir.term.service.ValidationParameters;

public class ValidateVSFunction extends FHIRPathAbstractTermFunction {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.function.Function;
import java.util.stream.Collectors;

import org.apache.commons.configuration.Configuration;
Expand Down Expand Up @@ -116,16 +116,6 @@ public Set<Concept> closure(CodeSystem codeSystem, Code code) {
return concepts;
}

@Override
public Map<Code, Set<Concept>> closure(CodeSystem codeSystem, Set<Code> codes) {
Map<Code, Set<Concept>> result = new LinkedHashMap<>();
for (Code code : codes) {
Set<Concept> closure = closure(codeSystem, code);
result.put(code, closure);
}
return result;
}

@Override
public Concept getConcept(CodeSystem codeSystem, Code code) {
checkArguments(codeSystem, code);
Expand All @@ -134,16 +124,21 @@ public Concept getConcept(CodeSystem codeSystem, Code code) {

@Override
public Set<Concept> getConcepts(CodeSystem codeSystem) {
return getConcepts(codeSystem, Function.identity());
}

@Override
public <R> Set<R> getConcepts(CodeSystem codeSystem, Function<Concept, ? extends R> mapper) {
checkArgument(codeSystem);

Set<Concept> concepts = new LinkedHashSet<>(getCount(codeSystem));
Set<R> concepts = new LinkedHashSet<>(getCount(codeSystem));

GraphTraversal<Vertex, Vertex> g = hasVersion(hasUrl(vertices(), codeSystem.getUrl()), codeSystem.getVersion())
.out("concept")
.timeLimit(timeLimit);
TimeLimitStep<?> timeLimitStep = getTimeLimitStep(g);

g.elementMap().toStream().forEach(elementMap -> concepts.add(createConcept(elementMap)));
g.elementMap().toStream().forEach(elementMap -> concepts.add(mapper.apply(createConcept(elementMap))));

checkTimeLimit(timeLimitStep);

Expand All @@ -152,9 +147,14 @@ public Set<Concept> getConcepts(CodeSystem codeSystem) {

@Override
public Set<Concept> getConcepts(CodeSystem codeSystem, List<Filter> filters) {
return getConcepts(codeSystem, filters, Function.identity());
}

@Override
public <R> Set<R> getConcepts(CodeSystem codeSystem, List<Filter> filters, Function<Concept, ? extends R> mapper) {
checkArguments(codeSystem, filters);

Set<Concept> concepts = new LinkedHashSet<>();
Set<R> concepts = new LinkedHashSet<>();

GraphTraversal<Vertex, Vertex> g = vertices();

Expand Down Expand Up @@ -203,7 +203,7 @@ public Set<Concept> getConcepts(CodeSystem codeSystem, List<Filter> filters) {
g = g.timeLimit(timeLimit);
TimeLimitStep<?> timeLimitStep = getTimeLimitStep(g);

g.elementMap().toStream().forEach(elementMap -> concepts.add(createConcept(elementMap)));
g.elementMap().toStream().forEach(elementMap -> concepts.add(mapper.apply(createConcept(elementMap))));

checkTimeLimit(timeLimitStep);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
import com.ibm.fhir.registry.resource.FHIRRegistryResource;
import com.ibm.fhir.term.registry.ImplicitValueSetRegistryResourceProvider;
import com.ibm.fhir.term.service.FHIRTermService;
import com.ibm.fhir.term.spi.ValidationOutcome;
import com.ibm.fhir.term.service.ValidationOutcome;

public class SnomedRegistryResourceProvider extends ImplicitValueSetRegistryResourceProvider {
private static final Logger log = Logger.getLogger(SnomedRegistryResourceProvider.class.getName());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
/*
* (C) Copyright IBM Corp. 2020
* (C) Copyright IBM Corp. 2020, 2021
*
* SPDX-License-Identifier: Apache-2.0
*/

package com.ibm.fhir.term.spi;
package com.ibm.fhir.term.service;

import static com.ibm.fhir.term.service.util.FHIRTermServiceUtil.getParameter;
import static com.ibm.fhir.term.service.util.FHIRTermServiceUtil.getParameters;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.util.ServiceLoader;
import java.util.Set;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.function.Function;
import java.util.stream.Collectors;

import com.ibm.fhir.model.resource.CodeSystem;
Expand All @@ -39,18 +40,11 @@
import com.ibm.fhir.model.type.Uri;
import com.ibm.fhir.model.type.code.CodeSystemHierarchyMeaning;
import com.ibm.fhir.model.type.code.ConceptSubsumptionOutcome;
import com.ibm.fhir.term.service.LookupOutcome.Designation;
import com.ibm.fhir.term.service.LookupOutcome.Property;
import com.ibm.fhir.term.service.TranslationOutcome.Match;
import com.ibm.fhir.term.service.provider.RegistryTermServiceProvider;
import com.ibm.fhir.term.spi.ExpansionParameters;
import com.ibm.fhir.term.spi.FHIRTermServiceProvider;
import com.ibm.fhir.term.spi.LookupOutcome;
import com.ibm.fhir.term.spi.LookupOutcome.Designation;
import com.ibm.fhir.term.spi.LookupOutcome.Property;
import com.ibm.fhir.term.spi.LookupParameters;
import com.ibm.fhir.term.spi.TranslationOutcome;
import com.ibm.fhir.term.spi.TranslationOutcome.Match;
import com.ibm.fhir.term.spi.TranslationParameters;
import com.ibm.fhir.term.spi.ValidationOutcome;
import com.ibm.fhir.term.spi.ValidationParameters;
import com.ibm.fhir.term.util.CodeSystemSupport;
import com.ibm.fhir.term.util.ValueSetSupport;

Expand Down Expand Up @@ -267,14 +261,31 @@ public Concept getConcept(CodeSystem codeSystem, Code code) {
* hierarchies have been flattened.
*
* @param codeSystem
* the code system
* the code system containing the set of Concept instances to be flattened
* @return
* flattened list of Concept instances for the given code system
* flattened set of Concept instances for the given code system
*/
public Set<Concept> getConcepts(CodeSystem codeSystem) {
return findProvider(codeSystem).getConcepts(codeSystem);
}

/**
* Get a set containing {@link R} instances mapped from concepts where all structural
* hierarchies have been flattened.
*
* @param <R>
* the element type of the result set
* @param codeSystem
* the code system containing the set of Concept instances to be flattened
* @param mapper
* the function to be applied
* @return
* flattened set of {@link R} instances mapped from concepts for the given code system
*/
public <R> Set<R> getConcepts(CodeSystem codeSystem, Function<Concept, ? extends R> mapper) {
return findProvider(codeSystem).getConcepts(codeSystem, mapper);
}

/**
* Get a set containing {@link CodeSystem.Concept} instances where all structural
* hierarchies have been flattened and filtered by the given set of value set include filters.
Expand All @@ -290,6 +301,25 @@ public Set<Concept> getConcepts(CodeSystem codeSystem, List<Filter> filters) {
return findProvider(codeSystem).getConcepts(codeSystem, filters);
}

/**
* Get a set containing {@link R} instances mapped from concepts where all structural
* hierarchies have been flattened and filtered by the given set of value set include filters.
*
* @param <R>
* the element type of the result set
* @param codeSystem
* the code system containing the set of Concept instances to be flattened / filtered
* @param filters
* the value set include filters
* @param mapper
* the function to be applied
* @return
* flattened / filtered set of {@link R} instances mapped from concepts for the given code system
*/
public <R> Set<R> getConcepts(CodeSystem codeSystem, List<Filter> filters, Function<Concept, ? extends R> mapper) {
return findProvider(codeSystem).getConcepts(codeSystem, filters, mapper);
}

/**
* Indicates whether the given code system contains a concept with the specified code.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* SPDX-License-Identifier: Apache-2.0
*/

package com.ibm.fhir.term.spi;
package com.ibm.fhir.term.service;

import static com.ibm.fhir.model.type.String.string;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
/*
* (C) Copyright IBM Corp. 2020
* (C) Copyright IBM Corp. 2020, 2021
*
* SPDX-License-Identifier: Apache-2.0
*/

package com.ibm.fhir.term.spi;
package com.ibm.fhir.term.service;

import static com.ibm.fhir.term.service.util.FHIRTermServiceUtil.getParameter;
import static com.ibm.fhir.term.service.util.FHIRTermServiceUtil.getParameters;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
/*
* (C) Copyright IBM Corp. 2020
* (C) Copyright IBM Corp. 2020, 2021
*
* SPDX-License-Identifier: Apache-2.0
*/

package com.ibm.fhir.term.spi;
package com.ibm.fhir.term.service;

import static com.ibm.fhir.model.type.String.string;

Expand All @@ -21,7 +21,7 @@
import com.ibm.fhir.model.type.String;
import com.ibm.fhir.model.type.Uri;
import com.ibm.fhir.model.type.code.ConceptMapEquivalence;
import com.ibm.fhir.term.spi.TranslationOutcome.Match.Product;
import com.ibm.fhir.term.service.TranslationOutcome.Match.Product;

/**
* This class is used to represent the outcome of the translate operation:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
/*
* (C) Copyright IBM Corp. 2020
* (C) Copyright IBM Corp. 2020, 2021
*
* SPDX-License-Identifier: Apache-2.0
*/

package com.ibm.fhir.term.spi;
package com.ibm.fhir.term.service;

import static com.ibm.fhir.term.service.util.FHIRTermServiceUtil.getParameter;
import static com.ibm.fhir.term.service.util.FHIRTermServiceUtil.getParameters;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
/*
* (C) Copyright IBM Corp. 2020
* (C) Copyright IBM Corp. 2020, 2021
*
* SPDX-License-Identifier: Apache-2.0
*/

package com.ibm.fhir.term.spi;
package com.ibm.fhir.term.service;

import static com.ibm.fhir.model.type.String.string;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
/*
* (C) Copyright IBM Corp. 2020
* (C) Copyright IBM Corp. 2020, 2021
*
* SPDX-License-Identifier: Apache-2.0
*/

package com.ibm.fhir.term.spi;
package com.ibm.fhir.term.service;

import static com.ibm.fhir.term.service.util.FHIRTermServiceUtil.getParameter;

Expand Down
Loading

0 comments on commit 28680ec

Please sign in to comment.