Skip to content

Commit

Permalink
issue #3805 - fixed extensions check
Browse files Browse the repository at this point in the history
  • Loading branch information
PrasannaHegde1 committed Jul 29, 2022
1 parent bfdf4f5 commit fba6063
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import static com.ibm.fhir.path.util.FHIRPathUtil.getSingleton;
import static com.ibm.fhir.path.util.FHIRPathUtil.hasStringValue;
import static com.ibm.fhir.path.util.FHIRPathUtil.isSingleton;
import static com.ibm.fhir.path.util.FHIRPathUtil.isStringSubType;

import java.util.Collection;
import java.util.List;
Expand Down Expand Up @@ -40,14 +41,8 @@ public Collection<FHIRPathNode> apply(EvaluationContext evaluationContext, Colle

} else if (!hasStringValue(context)) {
FHIRPathNode node = getSingleton(context);
FHIRPathType nodeChildType =
node.children() != null && !node.children().isEmpty()
&& node.children().iterator().hasNext() && node.children().iterator().next().type() != null ? node.children().iterator().next().type() : FHIRPathType.FHIR_ANY;

if (nodeChildType == FHIRPathType.FHIR_EXTENSION) {
if( logger.isLoggable(Level.FINE) ) {
logger.fine(String.format("collection item is of extension type %s", node.type().getName()));
}
if (isStringSubType(node)) {
logger.fine("collection item does not have a value, returning empty");
return empty();
}
throw new IllegalArgumentException("Input collection item must be of type String, but found '"+node.type().getName()+ "'");
Expand Down
17 changes: 17 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 @@ -1238,4 +1238,21 @@ public static com.ibm.fhir.model.type.String getDisplay(FHIRPathTree tree, FHIRP
}
return null;
}

/**
* returns true if the node is a String or if FHIR element can be automatically converted to System.String
* https://www.hl7.org/fhir/fhirpath.html#types
* @param node
* @return boolean
*/
public static boolean isStringSubType(FHIRPathNode node) {
return node.type() == FHIRPathType.FHIR_STRING
|| node.type() == FHIRPathType.FHIR_URI
|| node.type() == FHIRPathType.FHIR_CODE
|| node.type() == FHIRPathType.FHIR_OID
|| node.type() == FHIRPathType.FHIR_ID // included for consistency with spec
|| node.type() == FHIRPathType.FHIR_UUID
|| node.type() == FHIRPathType.FHIR_MARKDOWN
|| node.type() == FHIRPathType.FHIR_BASE64BINARY;
}
}

0 comments on commit fba6063

Please sign in to comment.