update new FHIRPath for older versions

This commit is contained in:
Grahame Grieve 2023-01-19 07:57:05 +11:00
parent 26027fa3d6
commit 7cc01ef7db
2 changed files with 15 additions and 2 deletions

View File

@ -263,6 +263,7 @@ public class FHIRPathEngine {
private boolean allowPolymorphicNames;
private boolean doImplicitStringConversion;
private boolean liquidMode; // in liquid mode, || terminates the expression and hands the parser back to the host
private boolean doNotEnforceAsSingletonRule;
// if the fhir path expressions are allowed to use constants beyond those defined in the specification
// the application can implement them by providing a constant resolver
@ -456,6 +457,14 @@ public class FHIRPathEngine {
this.doImplicitStringConversion = doImplicitStringConversion;
}
public boolean isDoNotEnforceAsSingletonRule() {
return doNotEnforceAsSingletonRule;
}
public void setDoNotEnforceAsSingletonRule(boolean doNotEnforceAsSingletonRule) {
this.doNotEnforceAsSingletonRule = doNotEnforceAsSingletonRule;
}
// --- public API -------------------------------------------------------
/**
* Parse a path for later use using execute
@ -1791,7 +1800,7 @@ public class FHIRPathEngine {
if (!isKnownType(tn)) {
throw new PathEngineException("The type "+tn+" is not valid");
}
if (left.size() > 1) {
if (!doNotEnforceAsSingletonRule && left.size() > 1) {
throw new PathEngineException("Attempt to use as on more than one item ("+left.size()+")");
}
for (Base nextLeft : left) {
@ -1806,6 +1815,9 @@ public class FHIRPathEngine {
private boolean isKnownType(String tn) {
if (!tn.contains(".")) {
if (Utilities.existsInList(tn, "String", "Boolean", "Integer", "Decimal", "Quantity", "DateTime", "Time", "SimpleTypeInfo", "ClassInfo")) {
return true;
}
try {
return worker.fetchTypeDefinition(tn) != null;
} catch (Exception e) {
@ -4586,7 +4598,7 @@ public class FHIRPathEngine {
if (!isKnownType(tn)) {
throw new PathEngineException("The type "+tn+" is not valid");
}
if (focus.size() > 1) {
if (!doNotEnforceAsSingletonRule && focus.size() > 1) {
throw new PathEngineException("Attempt to use as() on more than one item ("+focus.size()+")");
}

View File

@ -480,6 +480,7 @@ public class InstanceValidator extends BaseValidator implements IResourceValidat
if (theContext.getVersion().startsWith("3.0") || theContext.getVersion().startsWith("1.0"))
fpe.setLegacyMode(true);
source = Source.InstanceValidator;
fpe.setDoNotEnforceAsSingletonRule(!VersionUtilities.isR5VerOrLater(theContext.getVersion()));
}
@Override