Merge pull request #1124 from hapifhir/gg-202302-fhirpath-type

Gg 202302 fhirpath type
This commit is contained in:
Grahame Grieve 2023-02-20 17:29:56 +11:00 committed by GitHub
commit b5669231e8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 65 additions and 11 deletions

View File

@ -34,7 +34,11 @@ package org.hl7.fhir.r5.model;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Set;
import org.hl7.fhir.r5.model.Enumerations.*;
import org.hl7.fhir.r5.utils.ToolingExtensions;
import org.hl7.fhir.utilities.StandardsStatus;
import org.hl7.fhir.instance.model.api.IBaseBackboneElement;
import org.hl7.fhir.exceptions.FHIRException;
import org.hl7.fhir.instance.model.api.ICompositeType;
@ -467,7 +471,7 @@ public void checkNoModifiers(String noun, String verb) throws FHIRException {
}
}
public Resource getContained(String ref) {
public Resource getContained(String ref) {
if (ref == null)
return null;
@ -509,6 +513,15 @@ public void checkNoModifiers(String noun, String verb) throws FHIRException {
}
return Collections.unmodifiableList(retVal);
}
public StandardsStatus getStandardsStatus() {
return ToolingExtensions.getStandardsStatus(this);
}
public void setStandardsStatus(StandardsStatus status) {
ToolingExtensions.setStandardsStatus(this, status, null);
}
// end addition
}

View File

@ -34,8 +34,11 @@ package org.hl7.fhir.r5.model;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import org.hl7.fhir.utilities.StandardsStatus;
import org.hl7.fhir.utilities.Utilities;
import org.hl7.fhir.r5.model.Enumerations.*;
import org.hl7.fhir.r5.utils.ToolingExtensions;
import org.hl7.fhir.instance.model.api.IBaseDatatypeElement;
import org.hl7.fhir.exceptions.FHIRException;
import org.hl7.fhir.instance.model.api.ICompositeType;
@ -430,6 +433,15 @@ public abstract class Element extends Base implements IBaseHasExtensions, IBaseE
return ext.get(0).getValue().primitiveValue();
}
public StandardsStatus getStandardsStatus() {
return ToolingExtensions.getStandardsStatus(this);
}
public void setStandardsStatus(StandardsStatus status) {
ToolingExtensions.setStandardsStatus(this, status, null);
}
// end addition
}

View File

@ -595,6 +595,7 @@ public class FHIRPathEngine {
* @if the path is not valid
*/
public TypeDetails check(Object appContext, String resourceType, String context, ExpressionNode expr, Set<ElementDefinition> elementDependencies) throws FHIRLexerException, PathEngineException, DefinitionException {
// if context is a path that refers to a type, do that conversion now
TypeDetails types;
if (context == null) {
@ -629,6 +630,32 @@ public class FHIRPathEngine {
return executeType(new ExecutionTypeContext(appContext, resourceType, types, types), types, expr, elementDependencies, true);
}
/**
* check that paths referred to in the ExpressionNode are valid
*
* xPathStartsWithValueRef is a hack work around for the fact that FHIR Path sometimes needs a different starting point than the xpath
*
* returns a list of the possible types that might be returned by executing the ExpressionNode against a particular context
*
* @throws DefinitionException
* @throws PathEngineException
* @if the path is not valid
*/
public TypeDetails check(Object appContext, String resourceType, List<String> resourceTypes, ExpressionNode expr, Set<ElementDefinition> elementDependencies) throws FHIRLexerException, PathEngineException, DefinitionException {
// if context is a path that refers to a type, do that conversion now
TypeDetails types = null;
for (String rt : resourceTypes) {
if (types == null) {
types = new TypeDetails(CollectionStatus.SINGLETON, rt);
} else {
types.addType(rt);
}
}
return executeType(new ExecutionTypeContext(appContext, resourceType, types, types), types, expr, elementDependencies, true);
}
private FHIRException makeExceptionPlural(Integer num, ExpressionNode holder, String constName, Object... args) {
String fmt = worker.formatMessagePlural(num, constName, args);
@ -3343,11 +3370,19 @@ public class FHIRPathEngine {
return new TypeDetails(CollectionStatus.SINGLETON, TypeDetails.FP_DateTime);
case Resolve : {
checkContextReference(focus, "resolve", exp);
return new TypeDetails(CollectionStatus.SINGLETON, "DomainResource");
return new TypeDetails(CollectionStatus.ORDERED, "DomainResource");
}
case Extension : {
checkParamTypes(exp, exp.getFunction().toCode(), paramTypes, new TypeDetails(CollectionStatus.SINGLETON, TypeDetails.FP_String));
return new TypeDetails(CollectionStatus.SINGLETON, "Extension");
checkParamTypes(exp, exp.getFunction().toCode(), paramTypes, new TypeDetails(CollectionStatus.SINGLETON, TypeDetails.FP_String));
ExpressionNode p = exp.getParameters().get(0);
if (p.getKind() == Kind.Constant && p.getConstant() != null) {
String url = exp.getParameters().get(0).getConstant().primitiveValue();
StructureDefinition sd = worker.fetchResource(StructureDefinition.class, url);
if (sd != null) {
return new TypeDetails(CollectionStatus.ORDERED, new ProfiledType(url));
}
return new TypeDetails(CollectionStatus.SINGLETON, "Extension");
}
}
case AnyTrue:
return new TypeDetails(CollectionStatus.SINGLETON, TypeDetails.FP_Boolean);

View File

@ -27,19 +27,13 @@ public class PackageClient {
private PackageServer server;
private String cacheFolder;
private String address;
public PackageClient(PackageServer server) {
super();
this.server = server;
address = server.getUrl();
try {
cacheFolder = Utilities.path(System.getProperty("user.home"), ".fhir", "package-client");
Utilities.createDirectory(cacheFolder);
} catch (IOException e) {
}
address = this.server.getUrl();
}
public boolean exists(String id, String ver) throws IOException {