Skip to content

Commit

Permalink
Issue #2292 - additional 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 May 10, 2021
1 parent 30b5f79 commit 93e7daf
Show file tree
Hide file tree
Showing 4 changed files with 124 additions and 109 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@

import static com.ibm.fhir.core.util.URLSupport.parseQuery;
import static com.ibm.fhir.model.type.String.string;
import static com.ibm.fhir.model.util.ModelSupport.FHIR_STRING;
import static com.ibm.fhir.path.util.FHIRPathUtil.getDisplay;
import static com.ibm.fhir.path.util.FHIRPathUtil.getElementNode;
import static com.ibm.fhir.path.util.FHIRPathUtil.getResourceNode;
import static com.ibm.fhir.path.util.FHIRPathUtil.getSingleton;
import static com.ibm.fhir.path.util.FHIRPathUtil.getString;
import static com.ibm.fhir.path.util.FHIRPathUtil.getSystem;
import static com.ibm.fhir.path.util.FHIRPathUtil.getVersion;
import static com.ibm.fhir.path.util.FHIRPathUtil.isElementNode;
import static com.ibm.fhir.path.util.FHIRPathUtil.isResourceNode;
import static com.ibm.fhir.path.util.FHIRPathUtil.isSingleton;
Expand All @@ -33,11 +35,9 @@
import com.ibm.fhir.model.type.CodeableConcept;
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.path.FHIRPathElementNode;
import com.ibm.fhir.path.FHIRPathNode;
import com.ibm.fhir.path.FHIRPathTree;
import com.ibm.fhir.path.FHIRPathType;
import com.ibm.fhir.path.evaluator.FHIRPathEvaluator.EvaluationContext;
import com.ibm.fhir.path.util.FHIRPathUtil;
import com.ibm.fhir.registry.FHIRRegistry;
Expand Down Expand Up @@ -107,16 +107,6 @@ protected Coding getCoding(FHIRPathTree tree, FHIRPathElementNode codedElementNo
.build();
}

protected com.ibm.fhir.model.type.String getDisplay(FHIRPathTree tree, FHIRPathElementNode codedElementNode) {
if (tree != null) {
FHIRPathNode displayNode = tree.getSibling(codedElementNode, "display");
if (displayNode != null && FHIRPathType.FHIR_STRING.equals(displayNode.type())) {
return displayNode.asElementNode().element().as(FHIR_STRING);
}
}
return null;
}

protected Parameters getParameters(List<Collection<FHIRPathNode>> arguments) {
if (arguments.size() == getMaxArity()) {
String params = getString(arguments.get(arguments.size() - 1));
Expand All @@ -137,26 +127,6 @@ protected <T extends Resource> T getResource(List<Collection<FHIRPathNode>> argu
return null;
}

protected Uri getSystem(FHIRPathTree tree, FHIRPathElementNode codedElementNode) {
if (tree != null) {
FHIRPathNode systemNode = tree.getSibling(codedElementNode, "system");
if (systemNode != null && FHIRPathType.FHIR_URI.equals(systemNode.type())) {
return systemNode.asElementNode().element().as(Uri.class);
}
}
return null;
}

protected com.ibm.fhir.model.type.String getVersion(FHIRPathTree tree, FHIRPathElementNode codedElementNode) {
if (tree != null) {
FHIRPathNode versionNode = tree.getSibling(codedElementNode, "version");
if (versionNode != null && FHIRPathType.FHIR_STRING.equals(versionNode.type())) {
return versionNode.asElementNode().element().as(FHIR_STRING);
}
}
return null;
}

private Parameters buildParameters(Map<String, List<String>> queryParameters) {
return Parameters.builder()
.id("InputParameters")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,11 @@
import static com.ibm.fhir.path.evaluator.FHIRPathEvaluator.SINGLETON_FALSE;
import static com.ibm.fhir.path.evaluator.FHIRPathEvaluator.SINGLETON_TRUE;
import static com.ibm.fhir.path.util.FHIRPathUtil.empty;
import static com.ibm.fhir.path.util.FHIRPathUtil.getDisplay;
import static com.ibm.fhir.path.util.FHIRPathUtil.getElementNode;
import static com.ibm.fhir.path.util.FHIRPathUtil.getString;
import static com.ibm.fhir.path.util.FHIRPathUtil.getSystem;
import static com.ibm.fhir.path.util.FHIRPathUtil.getVersion;
import static com.ibm.fhir.path.util.FHIRPathUtil.isCodedElementNode;
import static com.ibm.fhir.path.util.FHIRPathUtil.isQuantityNode;
import static com.ibm.fhir.path.util.FHIRPathUtil.isStringElementNode;
Expand Down Expand Up @@ -40,7 +43,6 @@
import com.ibm.fhir.path.FHIRPathElementNode;
import com.ibm.fhir.path.FHIRPathNode;
import com.ibm.fhir.path.FHIRPathTree;
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.service.ValidationOutcome;
Expand Down Expand Up @@ -110,9 +112,12 @@ public Collection<FHIRPathNode> apply(EvaluationContext evaluationContext, Colle
try {
// Validate against expanded value set
if (element.is(Code.class)) {
Uri system = getSystem(evaluationContext.getTree(), elementNode);
FHIRPathTree tree = evaluationContext.getTree();
Uri system = getSystem(tree, elementNode);
com.ibm.fhir.model.type.String version = getVersion(tree, elementNode);
Code code = element.as(Code.class);
if ((system != null && validateCode(service, valueSet, system, null, code, null, evaluationContext, elementNode, strength)) ||
com.ibm.fhir.model.type.String display = getDisplay(tree, elementNode);
if ((system != null && validateCode(service, valueSet, system, version, code, display, evaluationContext, elementNode, strength)) ||
(system == null && validateCode(service, valueSet, code, evaluationContext, elementNode, strength))) {
return SINGLETON_TRUE;
}
Expand Down Expand Up @@ -277,26 +282,6 @@ private Collection<FHIRPathNode> membershipCheckFailed(EvaluationContext evaluat
return SINGLETON_FALSE;
}

/**
* Get the URI-typed sibling of the given element node with name "system".
*
* @param tree
* the tree
* @param elementNode
* the element node
* @return
* the URI-typed sibling of the given element node with name "system", or null if no such sibling exists
*/
private Uri getSystem(FHIRPathTree tree, FHIRPathElementNode elementNode) {
if (tree != null) {
FHIRPathNode systemNode = tree.getSibling(elementNode, "system");
if (systemNode != null && FHIRPathType.FHIR_URI.equals(systemNode.type())) {
return systemNode.asElementNode().element().as(Uri.class);
}
}
return null;
}

private boolean convertsToCodeSystemValidateCode(ValueSet valueSet, CodeableConcept codeableConcept) {
if (codeableConcept.getCoding().isEmpty()) {
return false;
Expand Down
60 changes: 60 additions & 0 deletions fhir-path/src/main/java/com/ibm/fhir/path/util/FHIRPathUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -1157,4 +1157,64 @@ private static List<FHIRPathResourceNode> getResourceNodes(FHIRPathTree tree, FH
}
return Collections.emptyList();
}

/**
* Get the URI-typed sibling of the given element node with name "system".
*
* @param tree
* the tree
* @param elementNode
* the element node
* @return
* the URI-typed sibling of the given element node with name "system", or null if no such sibling exists
*/
public static Uri getSystem(FHIRPathTree tree, FHIRPathElementNode elementNode) {
if (tree != null) {
FHIRPathNode systemNode = tree.getSibling(elementNode, "system");
if (systemNode != null && FHIRPathType.FHIR_URI.equals(systemNode.type())) {
return systemNode.asElementNode().element().as(Uri.class);
}
}
return null;
}

/**
* Get the String-typed sibling of the given element node with name "version".
*
* @param tree
* the tree
* @param elementNode
* the element node
* @return
* the String-typed sibling of the given element node with name "version", or null if no such sibling exists
*/
public static com.ibm.fhir.model.type.String getVersion(FHIRPathTree tree, FHIRPathElementNode elementNode) {
if (tree != null) {
FHIRPathNode versionNode = tree.getSibling(elementNode, "version");
if (versionNode != null && FHIRPathType.FHIR_STRING.equals(versionNode.type())) {
return versionNode.asElementNode().element().as(FHIR_STRING);
}
}
return null;
}

/**
* Get the String-typed sibling of the given element node with name "display".
*
* @param tree
* the tree
* @param elementNode
* the element node
* @return
* the String-typed sibling of the given element node with name "display", or null if no such sibling exists
*/
public static com.ibm.fhir.model.type.String getDisplay(FHIRPathTree tree, FHIRPathElementNode elementNode) {
if (tree != null) {
FHIRPathNode displayNode = tree.getSibling(elementNode, "display");
if (displayNode != null && FHIRPathType.FHIR_STRING.equals(displayNode.type())) {
return displayNode.asElementNode().element().as(FHIR_STRING);
}
}
return null;
}
}
Loading

0 comments on commit 93e7daf

Please sign in to comment.