Merge pull request #1421 from hapifhir/2023-08-gg-fhirpath-validation-fixes

2023 08 gg fhirpath validation fixes
This commit is contained in:
Grahame Grieve 2023-08-31 14:23:53 +02:00 committed by GitHub
commit ab8f84f492
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
39 changed files with 858 additions and 710 deletions

View File

@ -37,7 +37,9 @@ import org.hl7.fhir.dstu3.model.TimeType;
import org.hl7.fhir.dstu3.model.TypeDetails;
import org.hl7.fhir.dstu3.model.TypeDetails.ProfiledType;
import org.hl7.fhir.dstu3.utils.FHIRLexer.FHIRLexerException;
import org.hl7.fhir.dstu3.utils.FHIRPathEngine.IEvaluationContext.FunctionDetails;
import org.hl7.fhir.dstu3.utils.FHIRPathUtilityClasses.FunctionDetails;
import org.hl7.fhir.dstu3.utils.FHIRPathUtilityClasses.ExecutionContext;
import org.hl7.fhir.dstu3.utils.FHIRPathUtilityClasses.ExecutionTypeContext;
import org.hl7.fhir.exceptions.DefinitionException;
import org.hl7.fhir.exceptions.FHIRException;
import org.hl7.fhir.exceptions.PathEngineException;
@ -93,27 +95,7 @@ public class FHIRPathEngine {
// 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
public interface IEvaluationContext {
public class FunctionDetails {
private String description;
private int minParameters;
private int maxParameters;
public FunctionDetails(String description, int minParameters, int maxParameters) {
super();
this.description = description;
this.minParameters = minParameters;
this.maxParameters = maxParameters;
}
public String getDescription() {
return description;
}
public int getMinParameters() {
return minParameters;
}
public int getMaxParameters() {
return maxParameters;
}
}
/**
* A constant reference - e.g. a reference to a name that must be resolved in context.
@ -554,63 +536,6 @@ public class FHIRPathEngine {
return "";
}
private class ExecutionContext {
private Object appInfo;
private Base resource;
private Base context;
private Base thisItem;
private Map<String, Base> aliases;
public ExecutionContext(Object appInfo, Base resource, Base context, Map<String, Base> aliases, Base thisItem) {
this.appInfo = appInfo;
this.context = context;
this.resource = resource;
this.aliases = aliases;
this.thisItem = thisItem;
}
public Base getResource() {
return resource;
}
public Base getThisItem() {
return thisItem;
}
public void addAlias(String name, List<Base> focus) throws FHIRException {
if (aliases == null)
aliases = new HashMap<String, Base>();
else
aliases = new HashMap<String, Base>(aliases); // clone it, since it's going to change
if (focus.size() > 1)
throw new FHIRException("Attempt to alias a collection, not a singleton");
aliases.put(name, focus.size() == 0 ? null : focus.get(0));
}
public Base getAlias(String name) {
return aliases == null ? null : aliases.get(name);
}
}
private class ExecutionTypeContext {
private Object appInfo;
private String resource;
private String context;
private TypeDetails thisItem;
public ExecutionTypeContext(Object appInfo, String resource, String context, TypeDetails thisItem) {
super();
this.appInfo = appInfo;
this.resource = resource;
this.context = context;
this.thisItem = thisItem;
}
public String getResource() {
return resource;
}
public TypeDetails getThisItem() {
return thisItem;
}
}
private ExpressionNode parseExpression(FHIRLexer lexer, boolean proximal) throws FHIRLexerException {
ExpressionNode result = new ExpressionNode(lexer.nextId());
SourceLocation c = lexer.getCurrentStartLocation();
@ -1048,7 +973,7 @@ public class FHIRPathEngine {
} else if (constant.startsWith("%")) {
return resolveConstant(context, constant);
} else if (constant.startsWith("@")) {
return processDateConstant(context.appInfo, constant.substring(1));
return processDateConstant(context.getAppInfo(), constant.substring(1));
} else {
return new StringType(constant);
}
@ -1081,11 +1006,11 @@ public class FHIRPathEngine {
else if (s.equals("%ucum"))
return new StringType("http://unitsofmeasure.org");
else if (s.equals("%resource")) {
if (context.resource == null)
if (context.getResource() == null)
throw new PathEngineException("Cannot use %resource in this context");
return context.resource;
return context.getResource();
} else if (s.equals("%context")) {
return context.context;
return context.getContext();
} else if (s.equals("%us-zip"))
return new StringType("[0-9]{5}(-[0-9]{4}){0,1}");
else if (s.startsWith("%\"vs-"))
@ -1097,7 +1022,7 @@ public class FHIRPathEngine {
else if (hostServices == null)
throw new PathEngineException("Unknown fixed constant '"+s+"'");
else
return hostServices.resolveConstant(context.appInfo, s.substring(1));
return hostServices.resolveConstant(context.getAppInfo(), s.substring(1));
}
@ -1776,11 +1701,11 @@ public class FHIRPathEngine {
else if (s.equals("%ucum"))
return new TypeDetails(CollectionStatus.SINGLETON, "string");
else if (s.equals("%resource")) {
if (context.resource == null)
if (context.getResource() == null)
throw new PathEngineException("%resource cannot be used in this context");
return new TypeDetails(CollectionStatus.SINGLETON, context.resource);
return new TypeDetails(CollectionStatus.SINGLETON, context.getResource());
} else if (s.equals("%context")) {
return new TypeDetails(CollectionStatus.SINGLETON, context.context);
return new TypeDetails(CollectionStatus.SINGLETON, context.getContext());
} else if (s.equals("%map-codes"))
return new TypeDetails(CollectionStatus.SINGLETON, "string");
else if (s.equals("%us-zip"))
@ -1794,7 +1719,7 @@ public class FHIRPathEngine {
else if (hostServices == null)
throw new PathEngineException("Unknown fixed constant type for '"+s+"'");
else
return hostServices.resolveConstantType(context.appInfo, s);
return hostServices.resolveConstantType(context.getAppInfo(), s);
}
private List<Base> execute(ExecutionContext context, Base item, ExpressionNode exp, boolean atEntry) throws FHIRException {
@ -1804,8 +1729,8 @@ public class FHIRPathEngine {
result.add(item);
} else
getChildrenByName(item, exp.getName(), result);
if (result.size() == 0 && atEntry && context.appInfo != null) {
Base temp = hostServices.resolveConstant(context.appInfo, exp.getName());
if (result.size() == 0 && atEntry && context.getAppInfo() != null) {
Base temp = hostServices.resolveConstant(context.getAppInfo(), exp.getName());
if (temp != null) {
result.add(temp);
}
@ -1816,7 +1741,7 @@ public class FHIRPathEngine {
private TypeDetails executeContextType(ExecutionTypeContext context, String name) throws PathEngineException, DefinitionException {
if (hostServices == null)
throw new PathEngineException("Unable to resolve context reference since no host services are provided");
return hostServices.resolveConstantType(context.appInfo, name);
return hostServices.resolveConstantType(context.getAppInfo(), name);
}
private TypeDetails executeType(String type, ExpressionNode exp, boolean atEntry) throws PathEngineException, DefinitionException {
@ -2003,7 +1928,7 @@ public class FHIRPathEngine {
checkParamTypes(exp.getFunction().toCode(), paramTypes, new TypeDetails(CollectionStatus.SINGLETON, "string"));
return focus;
case Custom : {
return hostServices.checkFunction(context.appInfo, exp.getName(), paramTypes);
return hostServices.checkFunction(context.getAppInfo(), exp.getName(), paramTypes);
}
default:
break;
@ -2120,7 +2045,7 @@ public class FHIRPathEngine {
List<List<Base>> params = new ArrayList<List<Base>>();
for (ExpressionNode p : exp.getParameters())
params.add(execute(context, focus, p, true));
return hostServices.executeFunction(context.appInfo, exp.getName(), params);
return hostServices.executeFunction(context.getAppInfo(), exp.getName(), params);
}
default:
throw new Error("not Implemented yet");
@ -2181,11 +2106,11 @@ public class FHIRPathEngine {
private ExecutionContext changeThis(ExecutionContext context, Base newThis) {
return new ExecutionContext(context.appInfo, context.resource, context.context, context.aliases, newThis);
return new ExecutionContext(context.getAppInfo(), context.getResource(), context.getContext(), context.getAliases(), newThis);
}
private ExecutionTypeContext changeThis(ExecutionTypeContext context, TypeDetails newThis) {
return new ExecutionTypeContext(context.appInfo, context.resource, context.context, newThis);
return new ExecutionTypeContext(context.getAppInfo(), context.getResource(), context.getContext(), newThis);
}
@ -2467,13 +2392,13 @@ public class FHIRPathEngine {
}
Base res = null;
if (s.startsWith("#")) {
Property p = context.resource.getChildByName("contained");
Property p = context.getResource().getChildByName("contained");
for (Base c : p.getValues()) {
if (s.equals(c.getIdBase()))
res = c;
}
} else if (hostServices != null) {
res = hostServices.resolveReference(context.appInfo, s);
res = hostServices.resolveReference(context.getAppInfo(), s);
}
if (res != null)
result.add(res);
@ -2699,7 +2624,7 @@ public class FHIRPathEngine {
return makeBoolean(!convertToBoolean(focus));
}
public class ElementDefinitionMatch {
private class ElementDefinitionMatch {
private ElementDefinition definition;
private String fixedType;
public ElementDefinitionMatch(ElementDefinition definition, String fixedType) {

View File

@ -0,0 +1,110 @@
package org.hl7.fhir.dstu3.utils;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.hl7.fhir.dstu3.model.Base;
import org.hl7.fhir.dstu3.model.TypeDetails;
import org.hl7.fhir.exceptions.FHIRException;
public class FHIRPathUtilityClasses {
public static class ExecutionContext {
private Object appInfo;
private Base resource;
private Base context;
private Base thisItem;
private Map<String, Base> aliases;
public ExecutionContext(Object appInfo, Base resource, Base context, Map<String, Base> aliases, Base thisItem) {
this.appInfo = appInfo;
this.context = context;
this.resource = resource;
this.aliases = aliases;
this.thisItem = thisItem;
}
public Base getResource() {
return resource;
}
public Base getThisItem() {
return thisItem;
}
public void addAlias(String name, List<Base> focus) throws FHIRException {
if (aliases == null)
aliases = new HashMap<String, Base>();
else
aliases = new HashMap<String, Base>(aliases); // clone it, since it's going to change
if (focus.size() > 1)
throw new FHIRException("Attempt to alias a collection, not a singleton");
aliases.put(name, focus.size() == 0 ? null : focus.get(0));
}
public Base getAlias(String name) {
return aliases == null ? null : aliases.get(name);
}
public Object getAppInfo() {
return appInfo;
}
public Base getContext() {
return context;
}
public Map<String, Base> getAliases() {
return aliases;
}
}
public static class ExecutionTypeContext {
private Object appInfo;
private String resource;
private String context;
private TypeDetails thisItem;
public ExecutionTypeContext(Object appInfo, String resource, String context, TypeDetails thisItem) {
super();
this.appInfo = appInfo;
this.resource = resource;
this.context = context;
this.thisItem = thisItem;
}
public String getResource() {
return resource;
}
public TypeDetails getThisItem() {
return thisItem;
}
public Object getAppInfo() {
return appInfo;
}
public String getContext() {
return context;
}
}
public static class FunctionDetails {
private String description;
private int minParameters;
private int maxParameters;
public FunctionDetails(String description, int minParameters, int maxParameters) {
super();
this.description = description;
this.minParameters = minParameters;
this.maxParameters = maxParameters;
}
public String getDescription() {
return description;
}
public int getMinParameters() {
return minParameters;
}
public int getMaxParameters() {
return maxParameters;
}
}
}

View File

@ -108,6 +108,7 @@ import org.hl7.fhir.dstu3.model.ValueSet.ValueSetExpansionContainsComponent;
import org.hl7.fhir.dstu3.terminologies.ValueSetExpander.ValueSetExpansionOutcome;
import org.hl7.fhir.dstu3.utils.FHIRLexer.FHIRLexerException;
import org.hl7.fhir.dstu3.utils.FHIRPathEngine.IEvaluationContext;
import org.hl7.fhir.dstu3.utils.FHIRPathUtilityClasses.FunctionDetails;
import org.hl7.fhir.exceptions.DefinitionException;
import org.hl7.fhir.exceptions.FHIRException;
import org.hl7.fhir.exceptions.FHIRFormatError;

View File

@ -31,6 +31,7 @@ import org.hl7.fhir.dstu3.test.support.TestingUtilities;
import org.hl7.fhir.dstu3.utils.CodingUtilities;
import org.hl7.fhir.dstu3.utils.FHIRPathEngine;
import org.hl7.fhir.dstu3.utils.FHIRPathEngine.IEvaluationContext;
import org.hl7.fhir.dstu3.utils.FHIRPathUtilityClasses.FunctionDetails;
import org.hl7.fhir.exceptions.DefinitionException;
import org.hl7.fhir.exceptions.FHIRException;
import org.hl7.fhir.exceptions.FHIRFormatError;

View File

@ -56,7 +56,10 @@ import org.hl7.fhir.r4.model.TypeDetails;
import org.hl7.fhir.r4.model.TypeDetails.ProfiledType;
import org.hl7.fhir.r4.model.ValueSet;
import org.hl7.fhir.r4.utils.FHIRLexer.FHIRLexerException;
import org.hl7.fhir.r4.utils.FHIRPathEngine.IEvaluationContext.FunctionDetails;
import org.hl7.fhir.r4.utils.FHIRPathUtilityClasses.FHIRConstant;
import org.hl7.fhir.r4.utils.FHIRPathUtilityClasses.ClassTypeInfo;
import org.hl7.fhir.r4.utils.FHIRPathUtilityClasses.TypedElementDefinition;
import org.hl7.fhir.r4.utils.FHIRPathUtilityClasses.FunctionDetails;
import org.hl7.fhir.utilities.CommaSeparatedStringBuilder;
import org.hl7.fhir.utilities.MergedList;
import org.hl7.fhir.utilities.MergedList.MergeNode;
@ -110,167 +113,6 @@ public class FHIRPathEngine {
private enum Equality {
Null, True, False
}
private class FHIRConstant extends Base {
private static final long serialVersionUID = -8933773658248269439L;
private String value;
public FHIRConstant(String value) {
this.value = value;
}
@Override
public String fhirType() {
return "%constant";
}
@Override
protected void listChildren(List<Property> result) {
}
@Override
public String getIdBase() {
return null;
}
@Override
public void setIdBase(String value) {
}
public String getValue() {
return value;
}
@Override
public String primitiveValue() {
return value;
}
@Override
public Base copy() {
throw new Error("Not Implemented");
}
}
private class ClassTypeInfo extends Base {
private static final long serialVersionUID = 4909223114071029317L;
private Base instance;
public ClassTypeInfo(Base instance) {
super();
this.instance = instance;
}
@Override
public String fhirType() {
return "ClassInfo";
}
@Override
protected void listChildren(List<Property> result) {
}
@Override
public String getIdBase() {
return null;
}
@Override
public void setIdBase(String value) {
}
public Base[] getProperty(int hash, String name, boolean checkValid) throws FHIRException {
if (name.equals("name")) {
return new Base[] { new StringType(getName()) };
} else if (name.equals("namespace")) {
return new Base[] { new StringType(getNamespace()) };
} else {
return super.getProperty(hash, name, checkValid);
}
}
private String getNamespace() {
if ((instance instanceof Resource)) {
return "FHIR";
} else if (!(instance instanceof Element) || ((Element) instance).isDisallowExtensions()) {
return "System";
} else {
return "FHIR";
}
}
private String getName() {
if ((instance instanceof Resource)) {
return instance.fhirType();
} else if (!(instance instanceof Element) || ((Element) instance).isDisallowExtensions()) {
return Utilities.capitalize(instance.fhirType());
} else {
return instance.fhirType();
}
}
@Override
public Base copy() {
throw new Error("Not Implemented");
}
}
public static class TypedElementDefinition {
private ElementDefinition element;
private String type;
private StructureDefinition src;
public TypedElementDefinition(StructureDefinition src, ElementDefinition element, String type) {
super();
this.element = element;
this.type = type;
this.src = src;
}
public TypedElementDefinition(ElementDefinition element) {
super();
this.element = element;
}
public ElementDefinition getElement() {
return element;
}
public String getType() {
return type;
}
public List<TypeRefComponent> getTypes() {
List<TypeRefComponent> res = new ArrayList<ElementDefinition.TypeRefComponent>();
for (TypeRefComponent tr : element.getType()) {
if (type == null || type.equals(tr.getCode())) {
res.add(tr);
}
}
return res;
}
public boolean hasType(String tn) {
if (type != null) {
return tn.equals(type);
} else {
for (TypeRefComponent t : element.getType()) {
if (tn.equals(t.getCode())) {
return true;
}
}
return false;
}
}
public StructureDefinition getSrc() {
return src;
}
}
private IWorkerContext worker;
private IEvaluationContext hostServices;
private StringBuilder log = new StringBuilder();
@ -292,31 +134,7 @@ public class FHIRPathEngine {
// defined in the specification
// the application can implement them by providing a constant resolver
public interface IEvaluationContext {
public class FunctionDetails {
private String description;
private int minParameters;
private int maxParameters;
public FunctionDetails(String description, int minParameters, int maxParameters) {
super();
this.description = description;
this.minParameters = minParameters;
this.maxParameters = maxParameters;
}
public String getDescription() {
return description;
}
public int getMinParameters() {
return minParameters;
}
public int getMaxParameters() {
return maxParameters;
}
}
/**
* A constant reference - e.g. a reference to a name that must be resolved in
@ -6129,7 +5947,7 @@ public class FHIRPathEngine {
return result;
}
public class ElementDefinitionMatch {
private class ElementDefinitionMatch {
private ElementDefinition definition;
private String fixedType;
@ -6492,7 +6310,6 @@ public class FHIRPathEngine {
List<ElementDefinition> childDefinitions = profileUtilities.getChildMap(sd, element.getElement());
for (ElementDefinition t : childDefinitions) {
if (t.getPath().endsWith(".extension") && t.hasSliceName()) {
System.out.println("t: " + t.getId());
StructureDefinition exsd = (t.getType() == null || t.getType().isEmpty()
|| t.getType().get(0).getProfile().isEmpty()) ? null
: worker.fetchResource(StructureDefinition.class,

View File

@ -0,0 +1,210 @@
package org.hl7.fhir.r4.utils;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.hl7.fhir.exceptions.FHIRException;
import org.hl7.fhir.r4.model.Base;
import org.hl7.fhir.r4.model.Element;
import org.hl7.fhir.r4.model.ElementDefinition;
import org.hl7.fhir.r4.model.IntegerType;
import org.hl7.fhir.r4.model.Property;
import org.hl7.fhir.r4.model.Resource;
import org.hl7.fhir.r4.model.StringType;
import org.hl7.fhir.r4.model.StructureDefinition;
import org.hl7.fhir.r4.model.TypeDetails;
import org.hl7.fhir.r4.model.ElementDefinition.TypeRefComponent;
import org.hl7.fhir.utilities.Utilities;
import org.hl7.fhir.utilities.i18n.I18nConstants;
public class FHIRPathUtilityClasses {
public static class FHIRConstant extends Base {
private static final long serialVersionUID = -8933773658248269439L;
private String value;
public FHIRConstant(String value) {
this.value = value;
}
@Override
public String fhirType() {
return "%constant";
}
@Override
protected void listChildren(List<Property> result) {
}
@Override
public String getIdBase() {
return null;
}
@Override
public void setIdBase(String value) {
}
public String getValue() {
return value;
}
@Override
public String primitiveValue() {
return value;
}
@Override
public Base copy() {
throw new Error("Not Implemented");
}
}
public static class ClassTypeInfo extends Base {
private static final long serialVersionUID = 4909223114071029317L;
private Base instance;
public ClassTypeInfo(Base instance) {
super();
this.instance = instance;
}
@Override
public String fhirType() {
return "ClassInfo";
}
@Override
protected void listChildren(List<Property> result) {
}
@Override
public String getIdBase() {
return null;
}
@Override
public void setIdBase(String value) {
}
public Base[] getProperty(int hash, String name, boolean checkValid) throws FHIRException {
if (name.equals("name")) {
return new Base[] { new StringType(getName()) };
} else if (name.equals("namespace")) {
return new Base[] { new StringType(getNamespace()) };
} else {
return super.getProperty(hash, name, checkValid);
}
}
private String getNamespace() {
if ((instance instanceof Resource)) {
return "FHIR";
} else if (!(instance instanceof Element) || ((Element) instance).isDisallowExtensions()) {
return "System";
} else {
return "FHIR";
}
}
private String getName() {
if ((instance instanceof Resource)) {
return instance.fhirType();
} else if (!(instance instanceof Element) || ((Element) instance).isDisallowExtensions()) {
return Utilities.capitalize(instance.fhirType());
} else {
return instance.fhirType();
}
}
@Override
public Base copy() {
throw new Error("Not Implemented");
}
}
public static class TypedElementDefinition {
private ElementDefinition element;
private String type;
private StructureDefinition src;
public TypedElementDefinition(StructureDefinition src, ElementDefinition element, String type) {
super();
this.element = element;
this.type = type;
this.src = src;
}
public TypedElementDefinition(ElementDefinition element) {
super();
this.element = element;
}
public ElementDefinition getElement() {
return element;
}
public String getType() {
return type;
}
public List<TypeRefComponent> getTypes() {
List<TypeRefComponent> res = new ArrayList<ElementDefinition.TypeRefComponent>();
for (TypeRefComponent tr : element.getType()) {
if (type == null || type.equals(tr.getCode())) {
res.add(tr);
}
}
return res;
}
public boolean hasType(String tn) {
if (type != null) {
return tn.equals(type);
} else {
for (TypeRefComponent t : element.getType()) {
if (tn.equals(t.getCode())) {
return true;
}
}
return false;
}
}
public StructureDefinition getSrc() {
return src;
}
}
public static class FunctionDetails {
private String description;
private int minParameters;
private int maxParameters;
public FunctionDetails(String description, int minParameters, int maxParameters) {
super();
this.description = description;
this.minParameters = minParameters;
this.maxParameters = maxParameters;
}
public String getDescription() {
return description;
}
public int getMinParameters() {
return minParameters;
}
public int getMaxParameters() {
return maxParameters;
}
}
}

View File

@ -46,6 +46,7 @@ import org.hl7.fhir.r4.model.TypeDetails;
import org.hl7.fhir.r4.model.ValueSet;
import org.hl7.fhir.r4.utils.FHIRPathEngine.ExpressionNodeWithOffset;
import org.hl7.fhir.r4.utils.FHIRPathEngine.IEvaluationContext;
import org.hl7.fhir.r4.utils.FHIRPathUtilityClasses.FunctionDetails;
import org.hl7.fhir.utilities.Utilities;
public class LiquidEngine implements IEvaluationContext {

View File

@ -114,6 +114,7 @@ import org.hl7.fhir.r4.model.ValueSet.ValueSetExpansionContainsComponent;
import org.hl7.fhir.r4.terminologies.ValueSetExpander.ValueSetExpansionOutcome;
import org.hl7.fhir.r4.utils.FHIRLexer.FHIRLexerException;
import org.hl7.fhir.r4.utils.FHIRPathEngine.IEvaluationContext;
import org.hl7.fhir.r4.utils.FHIRPathUtilityClasses.FunctionDetails;
import org.hl7.fhir.r4.utils.validation.IResourceValidator;
import org.hl7.fhir.utilities.CommaSeparatedStringBuilder;
import org.hl7.fhir.utilities.TerminologyServiceOptions;

View File

@ -34,6 +34,7 @@ import org.hl7.fhir.r4.model.ValueSet;
import org.hl7.fhir.r4.test.utils.TestingUtilities;
import org.hl7.fhir.r4.utils.FHIRPathEngine;
import org.hl7.fhir.r4.utils.FHIRPathEngine.IEvaluationContext;
import org.hl7.fhir.r4.utils.FHIRPathUtilityClasses.FunctionDetails;
import org.hl7.fhir.utilities.Utilities;
import org.hl7.fhir.utilities.xml.XMLUtil;
import org.junit.jupiter.api.Assertions;

View File

@ -33,6 +33,7 @@ import org.hl7.fhir.r4.model.ValueSet;
import org.hl7.fhir.r4.test.utils.TestingUtilities;
import org.hl7.fhir.r4.utils.FHIRPathEngine;
import org.hl7.fhir.r4.utils.FHIRPathEngine.IEvaluationContext;
import org.hl7.fhir.r4.utils.FHIRPathUtilityClasses.FunctionDetails;
import org.hl7.fhir.r4.utils.NarrativeGenerator;
import org.hl7.fhir.r4.utils.validation.IResourceValidator;
import org.hl7.fhir.utilities.Utilities;

View File

@ -31,6 +31,7 @@ import org.hl7.fhir.r4b.model.Tuple;
import org.hl7.fhir.r4b.model.TypeDetails;
import org.hl7.fhir.r4b.model.ValueSet;
import org.hl7.fhir.r4b.utils.FHIRPathEngine.IEvaluationContext;
import org.hl7.fhir.r4b.utils.FHIRPathUtilityClasses.FunctionDetails;
import org.hl7.fhir.r4b.utils.LiquidEngine;
import org.hl7.fhir.r4b.utils.LiquidEngine.LiquidDocument;
import org.hl7.fhir.utilities.TextFile;

View File

@ -1711,9 +1711,6 @@ public class ProfileUtilities extends TranslatingUtilities {
iter.remove();
}
}
// System.out.println("!!: Extension Error at "+cpath+": Allowed Types not sliced = "+allowedTypes+". !Extension!!");
// throw new Error("Extension Error at "+cpath+": Allowed Types not sliced = "+allowedTypes+". !Extension!!");
} else {
e.getSlicing().setRules(SlicingRules.OPEN);
}

View File

@ -321,8 +321,6 @@ public abstract class TerminologyRenderer extends ResourceRenderer {
XhtmlNode a = li.ah(value);
a.tx("SNOMED-CT");
} else {
if (value.startsWith("http://hl7.org") && !Utilities.existsInList(value, "http://hl7.org/fhir/sid/icd-10-us"))
System.out.println("Unable to resolve value set " + value);
li.addText(value);
}
}

View File

@ -57,7 +57,10 @@ import org.hl7.fhir.r4b.model.TypeDetails;
import org.hl7.fhir.r4b.model.TypeDetails.ProfiledType;
import org.hl7.fhir.r4b.model.ValueSet;
import org.hl7.fhir.r4b.utils.FHIRLexer.FHIRLexerException;
import org.hl7.fhir.r4b.utils.FHIRPathEngine.IEvaluationContext.FunctionDetails;
import org.hl7.fhir.r4b.utils.FHIRPathUtilityClasses.FHIRConstant;
import org.hl7.fhir.r4b.utils.FHIRPathUtilityClasses.ClassTypeInfo;
import org.hl7.fhir.r4b.utils.FHIRPathUtilityClasses.TypedElementDefinition;
import org.hl7.fhir.r4b.utils.FHIRPathUtilityClasses.FunctionDetails;
import org.hl7.fhir.utilities.CommaSeparatedStringBuilder;
import org.hl7.fhir.utilities.MergedList;
import org.hl7.fhir.utilities.MergedList.MergeNode;
@ -112,160 +115,6 @@ public class FHIRPathEngine {
Null, True, False
}
private class FHIRConstant extends Base {
private static final long serialVersionUID = -8933773658248269439L;
private String value;
public FHIRConstant(String value) {
this.value = value;
}
@Override
public String fhirType() {
return "%constant";
}
@Override
protected void listChildren(List<Property> result) {
}
@Override
public String getIdBase() {
return null;
}
@Override
public void setIdBase(String value) {
}
public String getValue() {
return value;
}
@Override
public String primitiveValue() {
return value;
}
@Override
public Base copy() {
throw new Error("Not Implemented");
}
}
private class ClassTypeInfo extends Base {
private static final long serialVersionUID = 4909223114071029317L;
private Base instance;
public ClassTypeInfo(Base instance) {
super();
this.instance = instance;
}
@Override
public String fhirType() {
return "ClassInfo";
}
@Override
protected void listChildren(List<Property> result) {
}
@Override
public String getIdBase() {
return null;
}
@Override
public void setIdBase(String value) {
}
public Base[] getProperty(int hash, String name, boolean checkValid) throws FHIRException {
if (name.equals("name")) {
return new Base[] { new StringType(getName()) };
} else if (name.equals("namespace")) {
return new Base[] { new StringType(getNamespace()) };
} else {
return super.getProperty(hash, name, checkValid);
}
}
private String getNamespace() {
if ((instance instanceof Resource)) {
return "FHIR";
} else if (!(instance instanceof Element) || ((Element) instance).isDisallowExtensions()) {
return "System";
} else {
return "FHIR";
}
}
private String getName() {
if ((instance instanceof Resource)) {
return instance.fhirType();
} else if (!(instance instanceof Element) || ((Element) instance).isDisallowExtensions()) {
return Utilities.capitalize(instance.fhirType());
} else {
return instance.fhirType();
}
}
@Override
public Base copy() {
throw new Error("Not Implemented");
}
}
public static class TypedElementDefinition {
private ElementDefinition element;
private String type;
public TypedElementDefinition(ElementDefinition element, String type) {
super();
this.element = element;
this.type = type;
}
public TypedElementDefinition(ElementDefinition element) {
super();
this.element = element;
}
public ElementDefinition getElement() {
return element;
}
public String getType() {
return type;
}
public List<TypeRefComponent> getTypes() {
List<TypeRefComponent> res = new ArrayList<ElementDefinition.TypeRefComponent>();
for (TypeRefComponent tr : element.getType()) {
if (type == null || type.equals(tr.getCode())) {
res.add(tr);
}
}
return res;
}
public boolean hasType(String tn) {
if (type != null) {
return tn.equals(type);
} else {
for (TypeRefComponent t : element.getType()) {
if (tn.equals(t.getCode())) {
return true;
}
}
return false;
}
}
}
private IWorkerContext worker;
private IEvaluationContext hostServices;
private StringBuilder log = new StringBuilder();
@ -288,32 +137,7 @@ public class FHIRPathEngine {
// defined in the specification
// the application can implement them by providing a constant resolver
public interface IEvaluationContext {
public class FunctionDetails {
private String description;
private int minParameters;
private int maxParameters;
public FunctionDetails(String description, int minParameters, int maxParameters) {
super();
this.description = description;
this.minParameters = minParameters;
this.maxParameters = maxParameters;
}
public String getDescription() {
return description;
}
public int getMinParameters() {
return minParameters;
}
public int getMaxParameters() {
return maxParameters;
}
}
/**
* A constant reference - e.g. a reference to a name that must be resolved in
* context. The % will be removed from the constant name before this is invoked.
@ -6126,7 +5950,7 @@ public class FHIRPathEngine {
return result;
}
public class ElementDefinitionMatch {
private class ElementDefinitionMatch {
private ElementDefinition definition;
private String fixedType;
@ -6489,7 +6313,6 @@ public class FHIRPathEngine {
List<ElementDefinition> childDefinitions = profileUtilities.getChildMap(sd, element.getElement());
for (ElementDefinition t : childDefinitions) {
if (t.getPath().endsWith(".extension") && t.hasSliceName()) {
System.out.println("t: " + t.getId());
StructureDefinition exsd = (t.getType() == null || t.getType().isEmpty()
|| t.getType().get(0).getProfile().isEmpty()) ? null
: worker.fetchResource(StructureDefinition.class,

View File

@ -0,0 +1,198 @@
package org.hl7.fhir.r4b.utils;
import java.util.ArrayList;
import java.util.List;
import org.hl7.fhir.exceptions.FHIRException;
import org.hl7.fhir.r4b.model.Base;
import org.hl7.fhir.r4b.model.Element;
import org.hl7.fhir.r4b.model.ElementDefinition;
import org.hl7.fhir.r4b.model.Property;
import org.hl7.fhir.r4b.model.Resource;
import org.hl7.fhir.r4b.model.StringType;
import org.hl7.fhir.r4b.model.ElementDefinition.TypeRefComponent;
import org.hl7.fhir.utilities.Utilities;
public class FHIRPathUtilityClasses {
public static class FHIRConstant extends Base {
private static final long serialVersionUID = -8933773658248269439L;
private String value;
public FHIRConstant(String value) {
this.value = value;
}
@Override
public String fhirType() {
return "%constant";
}
@Override
protected void listChildren(List<Property> result) {
}
@Override
public String getIdBase() {
return null;
}
@Override
public void setIdBase(String value) {
}
public String getValue() {
return value;
}
@Override
public String primitiveValue() {
return value;
}
@Override
public Base copy() {
throw new Error("Not Implemented");
}
}
public static class ClassTypeInfo extends Base {
private static final long serialVersionUID = 4909223114071029317L;
private Base instance;
public ClassTypeInfo(Base instance) {
super();
this.instance = instance;
}
@Override
public String fhirType() {
return "ClassInfo";
}
@Override
protected void listChildren(List<Property> result) {
}
@Override
public String getIdBase() {
return null;
}
@Override
public void setIdBase(String value) {
}
public Base[] getProperty(int hash, String name, boolean checkValid) throws FHIRException {
if (name.equals("name")) {
return new Base[] { new StringType(getName()) };
} else if (name.equals("namespace")) {
return new Base[] { new StringType(getNamespace()) };
} else {
return super.getProperty(hash, name, checkValid);
}
}
private String getNamespace() {
if ((instance instanceof Resource)) {
return "FHIR";
} else if (!(instance instanceof Element) || ((Element) instance).isDisallowExtensions()) {
return "System";
} else {
return "FHIR";
}
}
private String getName() {
if ((instance instanceof Resource)) {
return instance.fhirType();
} else if (!(instance instanceof Element) || ((Element) instance).isDisallowExtensions()) {
return Utilities.capitalize(instance.fhirType());
} else {
return instance.fhirType();
}
}
@Override
public Base copy() {
throw new Error("Not Implemented");
}
}
public static class TypedElementDefinition {
private ElementDefinition element;
private String type;
public TypedElementDefinition(ElementDefinition element, String type) {
super();
this.element = element;
this.type = type;
}
public TypedElementDefinition(ElementDefinition element) {
super();
this.element = element;
}
public ElementDefinition getElement() {
return element;
}
public String getType() {
return type;
}
public List<TypeRefComponent> getTypes() {
List<TypeRefComponent> res = new ArrayList<ElementDefinition.TypeRefComponent>();
for (TypeRefComponent tr : element.getType()) {
if (type == null || type.equals(tr.getCode())) {
res.add(tr);
}
}
return res;
}
public boolean hasType(String tn) {
if (type != null) {
return tn.equals(type);
} else {
for (TypeRefComponent t : element.getType()) {
if (tn.equals(t.getCode())) {
return true;
}
}
return false;
}
}
}
public static class FunctionDetails {
private String description;
private int minParameters;
private int maxParameters;
public FunctionDetails(String description, int minParameters, int maxParameters) {
super();
this.description = description;
this.minParameters = minParameters;
this.maxParameters = maxParameters;
}
public String getDescription() {
return description;
}
public int getMinParameters() {
return minParameters;
}
public int getMaxParameters() {
return maxParameters;
}
}
}

View File

@ -49,6 +49,7 @@ import org.hl7.fhir.r4b.model.TypeDetails;
import org.hl7.fhir.r4b.model.ValueSet;
import org.hl7.fhir.r4b.utils.FHIRPathEngine.ExpressionNodeWithOffset;
import org.hl7.fhir.r4b.utils.FHIRPathEngine.IEvaluationContext;
import org.hl7.fhir.r4b.utils.FHIRPathUtilityClasses.FunctionDetails;
import org.hl7.fhir.utilities.Utilities;
import org.hl7.fhir.utilities.i18n.I18nConstants;
import org.hl7.fhir.utilities.xhtml.NodeType;

View File

@ -9,6 +9,7 @@ import org.hl7.fhir.r4b.model.Resource;
import org.hl7.fhir.r4b.model.TypeDetails;
import org.hl7.fhir.r4b.model.ValueSet;
import org.hl7.fhir.r4b.utils.FHIRPathEngine;
import org.hl7.fhir.r4b.utils.FHIRPathUtilityClasses.FunctionDetails;
import org.hl7.fhir.r4b.utils.validation.IResourceValidator;
import org.hl7.fhir.utilities.validation.ValidationMessage;

View File

@ -68,6 +68,7 @@ import org.hl7.fhir.r4b.utils.FHIRLexer;
import org.hl7.fhir.r4b.utils.FHIRLexer.FHIRLexerException;
import org.hl7.fhir.r4b.utils.FHIRPathEngine;
import org.hl7.fhir.r4b.utils.FHIRPathEngine.IEvaluationContext;
import org.hl7.fhir.r4b.utils.FHIRPathUtilityClasses.FunctionDetails;
import org.hl7.fhir.r4b.utils.ToolingExtensions;
import org.hl7.fhir.r4b.utils.validation.IResourceValidator;
import org.hl7.fhir.utilities.CommaSeparatedStringBuilder;

View File

@ -18,6 +18,7 @@ import org.hl7.fhir.r4b.test.FHIRPathTests.TestResultType;
import org.hl7.fhir.r4b.test.utils.TestingUtilities;
import org.hl7.fhir.r4b.utils.FHIRPathEngine;
import org.hl7.fhir.r4b.utils.FHIRPathEngine.IEvaluationContext;
import org.hl7.fhir.r4b.utils.FHIRPathUtilityClasses.FunctionDetails;
import org.hl7.fhir.utilities.Utilities;
import org.hl7.fhir.utilities.xml.XMLUtil;
import org.junit.jupiter.api.Assertions;

View File

@ -39,6 +39,7 @@ import org.hl7.fhir.r4b.model.ValueSet;
import org.hl7.fhir.r4b.test.utils.TestingUtilities;
import org.hl7.fhir.r4b.utils.FHIRPathEngine;
import org.hl7.fhir.r4b.utils.FHIRPathEngine.IEvaluationContext;
import org.hl7.fhir.r4b.utils.FHIRPathUtilityClasses.FunctionDetails;
import org.hl7.fhir.r4b.utils.validation.IResourceValidator;
import org.hl7.fhir.r4b.utils.XVerExtensionManager;
import org.hl7.fhir.utilities.Utilities;

View File

@ -30,6 +30,7 @@ import org.hl7.fhir.r5.model.Tuple;
import org.hl7.fhir.r5.model.TypeDetails;
import org.hl7.fhir.r5.model.ValueSet;
import org.hl7.fhir.r5.utils.FHIRPathEngine.IEvaluationContext;
import org.hl7.fhir.r5.utils.FHIRPathUtilityClasses.FunctionDetails;
import org.hl7.fhir.r5.utils.LiquidEngine;
import org.hl7.fhir.r5.utils.LiquidEngine.LiquidDocument;
import org.hl7.fhir.utilities.TextFile;

View File

@ -200,9 +200,6 @@ public class ProfilePathProcessor {
"diff = " + cursors.diffCursor + " (" + profileUtilities.descED(getDifferential().getElement(), cursors.diffCursor) + ") to " + getDiffLimit() + " (" + profileUtilities.descED(getDifferential().getElement(), getDiffLimit()) + ") " +
"(slicingDone = " + getSlicing().isDone() + ") (diffpath= " + (getDifferential().getElement().size() > cursors.diffCursor ? getDifferential().getElement().get(cursors.diffCursor).getPath() : "n/a") + ")");
String path = cursors.diffCursor >=0 && cursors.diffCursor < getDifferential().getElement().size() ? getDifferential().getElement().get(cursors.diffCursor).present() : null;
// if (path != null && path.contains(":populationBasis")) {
// System.out.println("!");
// }
}
}
@ -547,9 +544,6 @@ public class ProfilePathProcessor {
iter.remove();
}
}
// System.out.println("!!: Extension Error at "+cpath+": Allowed Types not sliced = "+allowedTypes+". !Extension!!");
// throw new Error("Extension Error at "+cpath+": Allowed Types not sliced = "+allowedTypes+". !Extension!!");
} else {
elementDefinition.getSlicing().setRules(ElementDefinition.SlicingRules.OPEN);
}
@ -914,7 +908,7 @@ public class ProfilePathProcessor {
int newBaseLimit = newBaseCursor;
while (newBaseLimit < cursors.base.getElement().size() && cursors.base.getElement().get(newBaseLimit).getPath().startsWith(tgt.getElement().getPath() + "."))
newBaseLimit++;
System.out.println("Test!");
// System.out.println("Test!");
this
.incrementDebugIndent()

View File

@ -263,7 +263,7 @@ public class CanonicalResourceManager<T extends CanonicalResource> {
public void see(CachedCanonicalResource<T> cr) {
// -- 1. exit conditions -----------------------------------------------------------------------------
// ignore UTG NUCC erroneous code system
if (cr.getPackageInfo() != null
&& cr.getPackageInfo().getId() != null

View File

@ -1417,9 +1417,6 @@ public class Element extends Base {
return webPath;
}
public void setWebPath(String webPath) {
if (webPath != null && webPath.startsWith("file:")) {
System.out.println("!"); // FIXME
}
this.webPath = webPath;
}

View File

@ -3516,7 +3516,7 @@ public class StructureDefinitionRenderer extends ResourceRenderer {
if (d.getMustHaveValue()) {
tableRow(tbl, "Primitive Value", "elementdefinition.html#primitives", strikethrough, "This primitive type must have a value (the value must be present, and cannot be replaced by an extension)");
} else if (d.hasValueAlternatives()) {
tableRow(tbl, "Primitive Value", "elementdefinition.html#primitives", strikethrough, renderCanonicalList(d.getValueAlternatives()));
tableRow(tbl, "Primitive Value", "elementdefinition.html#primitives", strikethrough, renderCanonicalList("This primitive type may be present, or absent if replaced by one of the following extensions: ", d.getValueAlternatives()));
} else if (hasPrimitiveTypes(d)) {
tableRow(tbl, "Primitive Value", "elementdefinition.html#primitives", strikethrough, "This primitive element may be present, or absent, or replaced by an extension");
}
@ -3537,11 +3537,11 @@ public class StructureDefinitionRenderer extends ResourceRenderer {
if (root && sd.hasExtension(ToolingExtensions.EXT_SD_IMPOSE_PROFILE)) {
tableRow(tbl, "Impose Profile", "http://hl7.org/fhir/extensions/StructureDefinition-structuredefinition-imposeProfile.html", strikethrough,
renderCanonicalListExt(sd.getExtensionsByUrl(ToolingExtensions.EXT_SD_IMPOSE_PROFILE)));
renderCanonicalListExt("This profile also requires that the instance also conform this additional profile: ", sd.getExtensionsByUrl(ToolingExtensions.EXT_SD_IMPOSE_PROFILE)));
}
if (root && sd.hasExtension(ToolingExtensions.EXT_SD_COMPLIES_WITH_PROFILE)) {
tableRow(tbl, "Complies with Profile", "http://hl7.org/fhir/extensions/StructureDefinition-structuredefinition-compliesWithProfile.html", strikethrough,
renderCanonicalListExt(sd.getExtensionsByUrl(ToolingExtensions.EXT_SD_COMPLIES_WITH_PROFILE)));
renderCanonicalListExt("This profile compiles with the profile ", sd.getExtensionsByUrl(ToolingExtensions.EXT_SD_COMPLIES_WITH_PROFILE)));
}
tableRow(tbl, "Obligations", null, strikethrough, describeObligations(d, root, sd));
@ -3810,19 +3810,19 @@ public class StructureDefinitionRenderer extends ResourceRenderer {
}
private XhtmlNode renderCanonicalListExt(List<Extension> list) {
private XhtmlNode renderCanonicalListExt(String text, List<Extension> list) {
List<CanonicalType> clist = new ArrayList<>();
for (Extension ext : list) {
if (ext.hasValueCanonicalType()) {
clist.add(ext.getValueCanonicalType());
}
}
return renderCanonicalList(clist);
return renderCanonicalList(text, clist);
}
private XhtmlNode renderCanonicalList(List<CanonicalType> list) {
private XhtmlNode renderCanonicalList(String text, List<CanonicalType> list) {
XhtmlNode ret = new XhtmlNode(NodeType.Element, "div");
ret.tx("This primitive type may be present, or absent, or replaced by one of the following extensions: ");
ret.tx(text);
var ul = ret.ul();
for (CanonicalType ct : list) {
CanonicalResource cr = (CanonicalResource) context.getContext().fetchResource(Resource.class, ct.getValue());

View File

@ -61,7 +61,10 @@ import org.hl7.fhir.r5.model.TypeDetails;
import org.hl7.fhir.r5.model.TypeDetails.ProfiledType;
import org.hl7.fhir.r5.model.ValueSet;
import org.hl7.fhir.r5.utils.FHIRLexer.FHIRLexerException;
import org.hl7.fhir.r5.utils.FHIRPathEngine.IEvaluationContext.FunctionDetails;
import org.hl7.fhir.r5.utils.FHIRPathUtilityClasses.FHIRConstant;
import org.hl7.fhir.r5.utils.FHIRPathUtilityClasses.ClassTypeInfo;
import org.hl7.fhir.r5.utils.FHIRPathUtilityClasses.FunctionDetails;
import org.hl7.fhir.r5.utils.FHIRPathUtilityClasses.TypedElementDefinition;
import org.hl7.fhir.utilities.CommaSeparatedStringBuilder;
import org.hl7.fhir.utilities.MarkDownProcessor;
import org.hl7.fhir.utilities.MergedList;
@ -115,157 +118,7 @@ import ca.uhn.fhir.util.ElementUtil;
public class FHIRPathEngine {
private enum Equality { Null, True, False }
private static class FHIRConstant extends Base {
private static final long serialVersionUID = -8933773658248269439L;
private String value;
public FHIRConstant(String value) {
this.value = value;
}
@Override
public String fhirType() {
return "%constant";
}
@Override
protected void listChildren(List<Property> result) {
}
@Override
public String getIdBase() {
return null;
}
@Override
public void setIdBase(String value) {
}
public String getValue() {
return value;
}
@Override
public String primitiveValue() {
return value;
}
@Override
public Base copy() {
throw new Error("Not Implemented");
}
}
private static class ClassTypeInfo extends Base {
private static final long serialVersionUID = 4909223114071029317L;
private Base instance;
public ClassTypeInfo(Base instance) {
super();
this.instance = instance;
}
@Override
public String fhirType() {
return "ClassInfo";
}
@Override
protected void listChildren(List<Property> result) {
}
@Override
public String getIdBase() {
return null;
}
@Override
public void setIdBase(String value) {
}
public Base[] getProperty(int hash, String name, boolean checkValid) throws FHIRException {
if (name.equals("name")) {
return new Base[]{new StringType(getName())};
} else if (name.equals("namespace")) {
return new Base[]{new StringType(getNamespace())};
} else {
return super.getProperty(hash, name, checkValid);
}
}
private String getNamespace() {
if ((instance instanceof Resource)) {
return "FHIR";
} else if (!(instance instanceof Element) || ((Element)instance).isDisallowExtensions()) {
return "System";
} else {
return "FHIR";
}
}
private String getName() {
if ((instance instanceof Resource)) {
return instance.fhirType();
} else if (!(instance instanceof Element) || ((Element)instance).isDisallowExtensions()) {
return Utilities.capitalize(instance.fhirType());
} else {
return instance.fhirType();
}
}
@Override
public Base copy() {
throw new Error("Not Implemented");
}
}
public static class TypedElementDefinition {
private ElementDefinition element;
private String type;
private StructureDefinition src;
public TypedElementDefinition(StructureDefinition src, ElementDefinition element, String type) {
super();
this.element = element;
this.type = type;
this.src = src;
}
public TypedElementDefinition(ElementDefinition element) {
super();
this.element = element;
}
public ElementDefinition getElement() {
return element;
}
public String getType() {
return type;
}
public List<TypeRefComponent> getTypes() {
List<TypeRefComponent> res = new ArrayList<ElementDefinition.TypeRefComponent>();
for (TypeRefComponent tr : element.getType()) {
if (type == null || type.equals(tr.getCode())) {
res.add(tr);
}
}
return res;
}
public boolean hasType(String tn) {
if (type != null) {
return tn.equals(type);
} else {
for (TypeRefComponent t : element.getType()) {
if (tn.equals(t.getCode())) {
return true;
}
}
return false;
}
}
public StructureDefinition getSrc() {
return src;
}
}
private IWorkerContext worker;
private IEvaluationContext hostServices;
private StringBuilder log = new StringBuilder();
@ -286,27 +139,6 @@ public class FHIRPathEngine {
// 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
public interface IEvaluationContext {
public class FunctionDetails {
private String description;
private int minParameters;
private int maxParameters;
public FunctionDetails(String description, int minParameters, int maxParameters) {
super();
this.description = description;
this.minParameters = minParameters;
this.maxParameters = maxParameters;
}
public String getDescription() {
return description;
}
public int getMinParameters() {
return minParameters;
}
public int getMaxParameters() {
return maxParameters;
}
}
/**
* A constant reference - e.g. a reference to a name that must be resolved in context.
@ -612,7 +444,7 @@ public class FHIRPathEngine {
if (context == null) {
types = null; // this is a special case; the first path reference will have to resolve to something in the context
} else if (!context.contains(".")) {
StructureDefinition sd = worker.fetchTypeDefinition(resourceType);
StructureDefinition sd = worker.fetchTypeDefinition(context);
if (sd == null) {
throw makeException(expr, I18nConstants.FHIRPATH_UNKNOWN_CONTEXT, context);
}
@ -5909,7 +5741,7 @@ public class FHIRPathEngine {
return result;
}
public static class ElementDefinitionMatch {
private class ElementDefinitionMatch {
private ElementDefinition definition;
private ElementDefinition sourceDefinition; // if there was a content reference
private String fixedType;

View File

@ -0,0 +1,192 @@
package org.hl7.fhir.r5.utils;
import java.util.ArrayList;
import java.util.List;
import org.hl7.fhir.exceptions.FHIRException;
import org.hl7.fhir.r5.model.Base;
import org.hl7.fhir.r5.model.Element;
import org.hl7.fhir.r5.model.ElementDefinition;
import org.hl7.fhir.r5.model.Property;
import org.hl7.fhir.r5.model.Resource;
import org.hl7.fhir.r5.model.StringType;
import org.hl7.fhir.r5.model.StructureDefinition;
import org.hl7.fhir.r5.model.ElementDefinition.TypeRefComponent;
import org.hl7.fhir.utilities.Utilities;
public class FHIRPathUtilityClasses {
public static class FHIRConstant extends Base {
private static final long serialVersionUID = -8933773658248269439L;
private String value;
public FHIRConstant(String value) {
this.value = value;
}
@Override
public String fhirType() {
return "%constant";
}
@Override
protected void listChildren(List<Property> result) {
}
@Override
public String getIdBase() {
return null;
}
@Override
public void setIdBase(String value) {
}
public String getValue() {
return value;
}
@Override
public String primitiveValue() {
return value;
}
@Override
public Base copy() {
throw new Error("Not Implemented");
}
}
public static class ClassTypeInfo extends Base {
private static final long serialVersionUID = 4909223114071029317L;
private Base instance;
public ClassTypeInfo(Base instance) {
super();
this.instance = instance;
}
@Override
public String fhirType() {
return "ClassInfo";
}
@Override
protected void listChildren(List<Property> result) {
}
@Override
public String getIdBase() {
return null;
}
@Override
public void setIdBase(String value) {
}
public Base[] getProperty(int hash, String name, boolean checkValid) throws FHIRException {
if (name.equals("name")) {
return new Base[]{new StringType(getName())};
} else if (name.equals("namespace")) {
return new Base[]{new StringType(getNamespace())};
} else {
return super.getProperty(hash, name, checkValid);
}
}
private String getNamespace() {
if ((instance instanceof Resource)) {
return "FHIR";
} else if (!(instance instanceof Element) || ((Element)instance).isDisallowExtensions()) {
return "System";
} else {
return "FHIR";
}
}
private String getName() {
if ((instance instanceof Resource)) {
return instance.fhirType();
} else if (!(instance instanceof Element) || ((Element)instance).isDisallowExtensions()) {
return Utilities.capitalize(instance.fhirType());
} else {
return instance.fhirType();
}
}
@Override
public Base copy() {
throw new Error("Not Implemented");
}
}
public static class TypedElementDefinition {
private ElementDefinition element;
private String type;
private StructureDefinition src;
public TypedElementDefinition(StructureDefinition src, ElementDefinition element, String type) {
super();
this.element = element;
this.type = type;
this.src = src;
}
public TypedElementDefinition(ElementDefinition element) {
super();
this.element = element;
}
public ElementDefinition getElement() {
return element;
}
public String getType() {
return type;
}
public List<TypeRefComponent> getTypes() {
List<TypeRefComponent> res = new ArrayList<ElementDefinition.TypeRefComponent>();
for (TypeRefComponent tr : element.getType()) {
if (type == null || type.equals(tr.getCode())) {
res.add(tr);
}
}
return res;
}
public boolean hasType(String tn) {
if (type != null) {
return tn.equals(type);
} else {
for (TypeRefComponent t : element.getType()) {
if (tn.equals(t.getCode())) {
return true;
}
}
return false;
}
}
public StructureDefinition getSrc() {
return src;
}
}
public static class FunctionDetails {
private String description;
private int minParameters;
private int maxParameters;
public FunctionDetails(String description, int minParameters, int maxParameters) {
super();
this.description = description;
this.minParameters = minParameters;
this.maxParameters = maxParameters;
}
public String getDescription() {
return description;
}
public int getMinParameters() {
return minParameters;
}
public int getMaxParameters() {
return maxParameters;
}
}
}

View File

@ -46,6 +46,7 @@ import org.hl7.fhir.r5.model.TypeDetails;
import org.hl7.fhir.r5.model.ValueSet;
import org.hl7.fhir.r5.utils.FHIRPathEngine.ExpressionNodeWithOffset;
import org.hl7.fhir.r5.utils.FHIRPathEngine.IEvaluationContext;
import org.hl7.fhir.r5.utils.FHIRPathUtilityClasses.FunctionDetails;
import org.hl7.fhir.utilities.Utilities;
import org.hl7.fhir.utilities.i18n.I18nConstants;
import org.hl7.fhir.utilities.xhtml.NodeType;

View File

@ -9,6 +9,7 @@ import org.hl7.fhir.r5.model.Resource;
import org.hl7.fhir.r5.model.TypeDetails;
import org.hl7.fhir.r5.model.ValueSet;
import org.hl7.fhir.r5.utils.FHIRPathEngine;
import org.hl7.fhir.r5.utils.FHIRPathUtilityClasses.FunctionDetails;
import org.hl7.fhir.r5.utils.validation.IResourceValidator;
import org.hl7.fhir.utilities.validation.ValidationMessage;

View File

@ -20,6 +20,7 @@ import org.hl7.fhir.r5.model.*;
import org.hl7.fhir.r5.test.utils.TestingUtilities;
import org.hl7.fhir.r5.utils.FHIRPathEngine;
import org.hl7.fhir.r5.utils.FHIRPathEngine.IEvaluationContext;
import org.hl7.fhir.r5.utils.FHIRPathUtilityClasses.FunctionDetails;
import org.hl7.fhir.utilities.Utilities;
import org.hl7.fhir.utilities.xml.XMLUtil;
import org.junit.jupiter.api.Assertions;

View File

@ -40,6 +40,7 @@ import org.hl7.fhir.r5.renderers.utils.RenderingContext.ResourceRendererMode;
import org.hl7.fhir.r5.test.utils.TestingUtilities;
import org.hl7.fhir.r5.utils.FHIRPathEngine;
import org.hl7.fhir.r5.utils.FHIRPathEngine.IEvaluationContext;
import org.hl7.fhir.r5.utils.FHIRPathUtilityClasses.FunctionDetails;
import org.hl7.fhir.r5.utils.XVerExtensionManager;
import org.hl7.fhir.r5.utils.validation.IResourceValidator;
import org.hl7.fhir.utilities.Utilities;

View File

@ -23,6 +23,7 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.LinkedList;
import java.util.List;
import java.util.Set;
@ -65,6 +66,7 @@ import javax.annotation.Nullable;
import org.apache.commons.io.FileUtils;
import org.hl7.fhir.exceptions.FHIRException;
import org.hl7.fhir.utilities.FileNotifier.FileNotifier2;
import org.hl7.fhir.utilities.Utilities.CaseInsensitiveSorter;
import org.hl7.fhir.utilities.settings.FhirSettings;
public class Utilities {
@ -1306,6 +1308,21 @@ public class Utilities {
return id.matches("[A-Za-z0-9\\-\\.]{1,64}");
}
public static class CaseInsensitiveSorter implements Comparator<String> {
@Override
public int compare(String o1, String o2) {
return o1.compareToIgnoreCase(o2);
}
}
public static List<String> sortedCaseInsensitive(Collection<String> set) {
List<String> list = new ArrayList<>();
list.addAll(set);
Collections.sort(list, new CaseInsensitiveSorter());
return list;
}
public static List<String> sorted(Collection<String> set) {
List<String> list = new ArrayList<>();
list.addAll(set);

View File

@ -1932,8 +1932,6 @@ public class TurtleTests {
@Test
public void test_bundle_example() throws FileNotFoundException, IOException, Exception {
if (!BaseTestingUtilities.silent)
System.out.println("bundle-example.ttl");
new Turtle().parse(BaseTestingUtilities.loadTestResource("r5", "bundle-example.ttl"));
}

View File

@ -6,6 +6,7 @@ public class TimeTracker {
private long sdTime = 0;
private long loadTime = 0;
private long fpeTime = 0;
private long specTime = 0;
public long getOverall() {
return overall;
@ -22,6 +23,10 @@ public class TimeTracker {
public long getFpeTime() {
return fpeTime;
}
public long getSpecTime() {
return specTime;
}
public void load(long start) {
loadTime = loadTime + (System.nanoTime() - start);
@ -45,11 +50,16 @@ public class TimeTracker {
fpeTime = fpeTime + (System.nanoTime() - start);
}
public void spec(long start) {
specTime = specTime + (System.nanoTime() - start);
}
public void reset() {
overall = 0;
txTime = 0;
sdTime = 0;
loadTime = 0;
fpeTime = 0;
specTime = 0;
}
}

View File

@ -155,7 +155,8 @@ import org.hl7.fhir.r5.utils.BuildExtensions;
import org.hl7.fhir.r5.utils.FHIRLexer.FHIRLexerException;
import org.hl7.fhir.r5.utils.FHIRPathEngine;
import org.hl7.fhir.r5.utils.FHIRPathEngine.IEvaluationContext;
import org.hl7.fhir.r5.utils.FHIRPathEngine.TypedElementDefinition;
import org.hl7.fhir.r5.utils.FHIRPathUtilityClasses.FunctionDetails;
import org.hl7.fhir.r5.utils.FHIRPathUtilityClasses.TypedElementDefinition;
import org.hl7.fhir.r5.utils.ResourceUtilities;
import org.hl7.fhir.r5.utils.ToolingExtensions;
import org.hl7.fhir.r5.utils.XVerExtensionManager;
@ -5201,44 +5202,50 @@ public class InstanceValidator extends BaseValidator implements IResourceValidat
}
public boolean checkSpecials(ValidatorHostContext hostContext, List<ValidationMessage> errors, Element element, NodeStack stack, boolean checkSpecials, PercentageTracker pct, ValidationMode mode) {
if (VersionUtilities.getCanonicalResourceNames(context.getVersion()).contains(element.getType())) {
Base base = element.getExtensionValue(ToolingExtensions.EXT_STANDARDS_STATUS);
String standardsStatus = base != null && base.isPrimitive() ? base.primitiveValue() : null;
String status = element.getNamedChildValue("status");
if (!Utilities.noString(status) && !Utilities.noString(standardsStatus)) {
if (warning(errors, "2023-08-14", IssueType.BUSINESSRULE, element.line(), element.col(), stack.getLiteralPath(), statusCodesConsistent(status, standardsStatus), I18nConstants.VALIDATION_VAL_STATUS_INCONSISTENT, status, standardsStatus)) {
hint(errors, "2023-08-14", IssueType.BUSINESSRULE, element.line(), element.col(), stack.getLiteralPath(), statusCodesDeeplyConsistent(status, standardsStatus), I18nConstants.VALIDATION_VAL_STATUS_INCONSISTENT_HINT, status, standardsStatus);
long t = System.nanoTime();
try {
if (VersionUtilities.getCanonicalResourceNames(context.getVersion()).contains(element.getType())) {
Base base = element.getExtensionValue(ToolingExtensions.EXT_STANDARDS_STATUS);
String standardsStatus = base != null && base.isPrimitive() ? base.primitiveValue() : null;
String status = element.getNamedChildValue("status");
if (!Utilities.noString(status) && !Utilities.noString(standardsStatus)) {
if (warning(errors, "2023-08-14", IssueType.BUSINESSRULE, element.line(), element.col(), stack.getLiteralPath(), statusCodesConsistent(status, standardsStatus), I18nConstants.VALIDATION_VAL_STATUS_INCONSISTENT, status, standardsStatus)) {
hint(errors, "2023-08-14", IssueType.BUSINESSRULE, element.line(), element.col(), stack.getLiteralPath(), statusCodesDeeplyConsistent(status, standardsStatus), I18nConstants.VALIDATION_VAL_STATUS_INCONSISTENT_HINT, status, standardsStatus);
}
}
}
}
if (element.getType().equals(BUNDLE)) {
return new BundleValidator(this, serverBase).validateBundle(errors, element, stack, checkSpecials, hostContext, pct, mode);
} else if (element.getType().equals("Observation")) {
return validateObservation(errors, element, stack);
} else if (element.getType().equals("Questionnaire")) {
return new QuestionnaireValidator(this, myEnableWhenEvaluator, fpe, questionnaireMode).validateQuestionannaire(errors, element, element, stack);
} else if (element.getType().equals("QuestionnaireResponse")) {
return new QuestionnaireValidator(this, myEnableWhenEvaluator, fpe, questionnaireMode).validateQuestionannaireResponse(hostContext, errors, element, stack);
} else if (element.getType().equals("Measure")) {
return new MeasureValidator(this).validateMeasure(hostContext, errors, element, stack);
} else if (element.getType().equals("MeasureReport")) {
return new MeasureValidator(this).validateMeasureReport(hostContext, errors, element, stack);
} else if (element.getType().equals("CapabilityStatement")) {
return validateCapabilityStatement(errors, element, stack);
} else if (element.getType().equals("CodeSystem")) {
return new CodeSystemValidator(this).validateCodeSystem(errors, element, stack, baseOptions.withLanguage(stack.getWorkingLang()));
} else if (element.getType().equals("ConceptMap")) {
return new ConceptMapValidator(this).validateConceptMap(errors, element, stack, baseOptions.withLanguage(stack.getWorkingLang()));
} else if (element.getType().equals("SearchParameter")) {
return new SearchParameterValidator(this, fpe).validateSearchParameter(errors, element, stack);
} else if (element.getType().equals("StructureDefinition")) {
return new StructureDefinitionValidator(this, fpe, wantCheckSnapshotUnchanged).validateStructureDefinition(errors, element, stack);
} else if (element.getType().equals("StructureMap")) {
return new StructureMapValidator(this, fpe, profileUtilities).validateStructureMap(errors, element, stack);
} else if (element.getType().equals("ValueSet")) {
return new ValueSetValidator(this).validateValueSet(errors, element, stack);
} else {
return true;
if (element.getType().equals(BUNDLE)) {
return new BundleValidator(this, serverBase).validateBundle(errors, element, stack, checkSpecials, hostContext, pct, mode);
} else if (element.getType().equals("Observation")) {
return validateObservation(errors, element, stack);
} else if (element.getType().equals("Questionnaire")) {
return new QuestionnaireValidator(this, myEnableWhenEvaluator, fpe, questionnaireMode).validateQuestionannaire(errors, element, element, stack);
} else if (element.getType().equals("QuestionnaireResponse")) {
return new QuestionnaireValidator(this, myEnableWhenEvaluator, fpe, questionnaireMode).validateQuestionannaireResponse(hostContext, errors, element, stack);
} else if (element.getType().equals("Measure")) {
return new MeasureValidator(this).validateMeasure(hostContext, errors, element, stack);
} else if (element.getType().equals("MeasureReport")) {
return new MeasureValidator(this).validateMeasureReport(hostContext, errors, element, stack);
} else if (element.getType().equals("CapabilityStatement")) {
return validateCapabilityStatement(errors, element, stack);
} else if (element.getType().equals("CodeSystem")) {
return new CodeSystemValidator(this).validateCodeSystem(errors, element, stack, baseOptions.withLanguage(stack.getWorkingLang()));
} else if (element.getType().equals("ConceptMap")) {
return new ConceptMapValidator(this).validateConceptMap(errors, element, stack, baseOptions.withLanguage(stack.getWorkingLang()));
} else if (element.getType().equals("SearchParameter")) {
return new SearchParameterValidator(this, fpe).validateSearchParameter(errors, element, stack);
} else if (element.getType().equals("StructureDefinition")) {
return new StructureDefinitionValidator(this, fpe, wantCheckSnapshotUnchanged).validateStructureDefinition(errors, element, stack);
} else if (element.getType().equals("StructureMap")) {
return new StructureMapValidator(this, fpe, profileUtilities).validateStructureMap(errors, element, stack);
} else if (element.getType().equals("ValueSet")) {
return new ValueSetValidator(this).validateValueSet(errors, element, stack);
} else {
return true;
}
} finally {
timeTracker.spec(t);
}
}
@ -6534,7 +6541,7 @@ public class InstanceValidator extends BaseValidator implements IResourceValidat
public String reportTimes() {
String s = String.format("Times (ms): overall = %d, tx = %d, sd = %d, load = %d, fpe = %d", timeTracker.getOverall() / 1000000, timeTracker.getTxTime() / 1000000, timeTracker.getSdTime() / 1000000, timeTracker.getLoadTime() / 1000000, timeTracker.getFpeTime() / 1000000);
String s = String.format("Times (ms): overall = %d:4, tx = %d, sd = %d, load = %d, fpe = %d, spec = %d", timeTracker.getOverall() / 1000000, timeTracker.getTxTime() / 1000000, timeTracker.getSdTime() / 1000000, timeTracker.getLoadTime() / 1000000, timeTracker.getFpeTime() / 1000000, timeTracker.getSpecTime() / 1000000);
timeTracker.reset();
return s;
}

View File

@ -536,7 +536,11 @@ public class StructureDefinitionValidator extends BaseValidator {
types.add(elements.get(0).getNamedChildValue("path"));
}
List<String> warnings = new ArrayList<>();
fpe.checkOnTypes(invariant, rootPath, types, fpe.parse(exp), warnings);
if (Utilities.existsInList(rootPath, context.getResourceNames())) {
fpe.checkOnTypes(invariant, rootPath, types, fpe.parse(exp), warnings);
} else {
fpe.checkOnTypes(invariant, "DomainResource", types, fpe.parse(exp), warnings);
}
for (String s : warnings) {
warning(errors, "2023-07-27", IssueType.BUSINESSRULE, stack, false, key+": "+s);
}

View File

@ -37,6 +37,7 @@ import org.hl7.fhir.r5.renderers.utils.RenderingContext.ResourceRendererMode;
import org.hl7.fhir.r5.test.utils.TestingUtilities;
import org.hl7.fhir.r5.utils.FHIRPathEngine;
import org.hl7.fhir.r5.utils.FHIRPathEngine.IEvaluationContext;
import org.hl7.fhir.r5.utils.FHIRPathUtilityClasses.FunctionDetails;
import org.hl7.fhir.r5.utils.validation.IResourceValidator;
import org.hl7.fhir.utilities.Utilities;
import org.hl7.fhir.utilities.validation.ValidationMessage;

View File

@ -52,6 +52,7 @@ import org.hl7.fhir.r5.model.ValueSet;
import org.hl7.fhir.r5.test.utils.TestingUtilities;
import org.hl7.fhir.r5.utils.FHIRPathEngine;
import org.hl7.fhir.r5.utils.FHIRPathEngine.IEvaluationContext;
import org.hl7.fhir.r5.utils.FHIRPathUtilityClasses.FunctionDetails;
import org.hl7.fhir.r5.utils.OperationOutcomeUtilities;
import org.hl7.fhir.r5.utils.validation.BundleValidationRule;
import org.hl7.fhir.r5.utils.validation.IResourceValidator;

View File

@ -20,7 +20,7 @@
<properties>
<guava_version>32.0.1-jre</guava_version>
<hapi_fhir_version>6.4.1</hapi_fhir_version>
<validator_test_case_version>1.4.1</validator_test_case_version>
<validator_test_case_version>1.4.2-SNAPSHOT</validator_test_case_version>
<jackson_version>2.15.2</jackson_version>
<junit_jupiter_version>5.9.2</junit_jupiter_version>
<junit_platform_launcher_version>1.8.2</junit_platform_launcher_version>