Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@
import org.hl7.fhir.r4.model.IdType;
import org.hl7.fhir.r4.model.ValueSet;

import java.util.Collections;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;

public class FhirPathR4 implements IFhirPath {

Expand Down Expand Up @@ -101,7 +103,10 @@ public List<Base> resolveConstant(
boolean beforeContext,
boolean explicitConstant)
throws PathEngineException {
return null;
return Collections.unmodifiableList(
theEvaluationContext.resolveConstant(appContext, name, beforeContext).stream()
.map(Base.class::cast)
.collect(Collectors.toList()));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public class FhirInstanceValidator extends BaseValidatorBridge implements IInsta
private IValidatorResourceFetcher validatorResourceFetcher;
private IValidationPolicyAdvisor validatorPolicyAdvisor = new FhirDefaultPolicyAdvisor();
private boolean myAllowExamples;
private FHIRPathEngine.IEvaluationContext evaluationContext;

/**
* Constructor
Expand Down Expand Up @@ -253,6 +254,7 @@ protected List<ValidationMessage> validate(IValidationContext<?> theValidationCt
.setValidatorResourceFetcher(getValidatorResourceFetcher())
.setAssumeValidRestReferences(isAssumeValidRestReferences())
.setAllowExamples(isAllowExamples())
.setEvaluationContext(getEvaluationContext())
.validate(wrappedWorkerContext, theValidationCtx);
}

Expand Down Expand Up @@ -296,6 +298,14 @@ public void setAssumeValidRestReferences(boolean assumeValidRestReferences) {
this.assumeValidRestReferences = assumeValidRestReferences;
}

public FHIRPathEngine.IEvaluationContext getEvaluationContext() {
return evaluationContext;
}

public void setEvaluationContext(FHIRPathEngine.IEvaluationContext evaluationContext) {
this.evaluationContext = evaluationContext;
}

/**
* Clear any cached data held by the validator or any of its internal stores. This is mostly intended
* for unit tests, but could be used for production uses too.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ class ValidatorWrapper {
private Collection<? extends String> myExtensionDomains;
private IValidatorResourceFetcher myValidatorResourceFetcher;
private IValidationPolicyAdvisor myValidationPolicyAdvisor;
private FHIRPathEngine.IEvaluationContext evaluationContext;
private boolean myAllowExamples;

/**
Expand Down Expand Up @@ -123,17 +124,14 @@ public ValidatorWrapper setValidatorResourceFetcher(IValidatorResourceFetcher va
return this;
}

public ValidatorWrapper setEvaluationContext(FHIRPathEngine.IEvaluationContext evaluationContext) {
this.evaluationContext = evaluationContext;
return this;
}

public List<ValidationMessage> validate(
IWorkerContext theWorkerContext, IValidationContext<?> theValidationContext) {
InstanceValidator v;
FHIRPathEngine.IEvaluationContext evaluationCtx = new FhirInstanceValidator.NullEvaluationContext();
XVerExtensionManager xverManager = new XVerExtensionManager(theWorkerContext);
try {
v = new InstanceValidator(
theWorkerContext, evaluationCtx, xverManager, new ValidatorSession(), new ValidatorSettings());
} catch (Exception e) {
throw new ConfigurationException(Msg.code(648) + e.getMessage(), e);
}
InstanceValidator v = getInstanceValidator(theWorkerContext);

v.setAssumeValidRestReferences(isAssumeValidRestReferences());
v.setBestPracticeWarningLevel(myBestPracticeWarningLevel);
Expand Down Expand Up @@ -235,6 +233,24 @@ public List<ValidationMessage> validate(
return messages;
}

private InstanceValidator getInstanceValidator(IWorkerContext theWorkerContext) {
InstanceValidator v;
FHIRPathEngine.IEvaluationContext evaluationCtx;
if (evaluationContext == null) {}
evaluationCtx = new FhirInstanceValidator.NullEvaluationContext();
if (evaluationContext != null) {
evaluationCtx = evaluationContext;
}
XVerExtensionManager xverManager = new XVerExtensionManager(theWorkerContext);
try {
v = new InstanceValidator(
theWorkerContext, evaluationCtx, xverManager, new ValidatorSession(), new ValidatorSettings());
} catch (Exception e) {
throw new ConfigurationException(Msg.code(648) + e.getMessage(), e);
}
return v;
}

private ReaderInputStream constructNewReaderInputStream(Reader theReader) {
try {
return ReaderInputStream.builder()
Expand Down
Loading