diff --git a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/utils/validation/IResourceValidator.java b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/utils/validation/IResourceValidator.java index 22cd93eb5..aa465b531 100644 --- a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/utils/validation/IResourceValidator.java +++ b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/utils/validation/IResourceValidator.java @@ -35,7 +35,7 @@ import org.hl7.fhir.r5.elementmodel.Manager.FhirFormat; import org.hl7.fhir.r5.model.Coding; import org.hl7.fhir.r5.model.StructureDefinition; import org.hl7.fhir.r5.model.UsageContext; -import org.hl7.fhir.r5.utils.validation.constants.RuleImplementationLevel; +import org.hl7.fhir.r5.utils.validation.constants.BestPracticeWarningLevel; import org.hl7.fhir.r5.utils.validation.constants.CheckDisplayOption; import org.hl7.fhir.r5.utils.validation.constants.IdStatus; import org.hl7.fhir.utilities.json.model.JsonObject; @@ -70,11 +70,8 @@ public interface IResourceValidator { * whether the validator should enforce best practice guidelines * as defined by various HL7 committees */ - RuleImplementationLevel getBestPracticeWarningLevel(); - IResourceValidator setBestPracticeWarningLevel(RuleImplementationLevel value); - - RuleImplementationLevel getVitalSignsProfileCheckLevel(); - IResourceValidator setVitalSignsProfileCheckLevel(RuleImplementationLevel value); + BestPracticeWarningLevel getBestPracticeWarningLevel(); + IResourceValidator setBestPracticeWarningLevel(BestPracticeWarningLevel value); IValidatorResourceFetcher getFetcher(); IResourceValidator setFetcher(IValidatorResourceFetcher value); diff --git a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/utils/validation/IValidationPolicyAdvisor.java b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/utils/validation/IValidationPolicyAdvisor.java index 6f93829c8..19675756e 100644 --- a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/utils/validation/IValidationPolicyAdvisor.java +++ b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/utils/validation/IValidationPolicyAdvisor.java @@ -9,6 +9,8 @@ import org.hl7.fhir.r5.model.StructureDefinition; import org.hl7.fhir.r5.model.ValueSet; import org.hl7.fhir.r5.utils.validation.constants.ContainedReferenceValidationPolicy; import org.hl7.fhir.r5.utils.validation.constants.ReferenceValidationPolicy; +import org.hl7.fhir.utilities.validation.ValidationMessage; +import org.hl7.fhir.validation.instance.BasePolicyAdvisorForMandatoryProfiles; import org.hl7.fhir.r5.utils.validation.constants.CodedContentValidationPolicy; import org.hl7.fhir.r5.utils.validation.IValidationPolicyAdvisor.ElementValidationAction; import org.hl7.fhir.r5.utils.validation.constants.BindingKind; @@ -131,5 +133,41 @@ public interface IValidationPolicyAdvisor { ValueSet valueSet, List systems); + /** + * This is called after a resource has been validated against the base structure, + * but before any profiles specified in .meta.profile or in the parameters are applied. + * This can be used to determine what additional profiles should be applied, for instance + * those derived from the http://hl7.org/fhir/tools/StructureDefinition/profile-mapping extension + * + * Note that the resource is an elementModel resource, not an IBaseResource. This is less convenient to + * read values from, but is the way the internals of the validator works (e.g. the version of the resource + * might be any version from R2-R6) + * + * The base implementation applies the mandatory vital signs to observations that have LOINC or SNOMED CT + * codes that indicate that they are vital signs. Note that these profiles are not optional; all resources + * are required to conform to them. For this reason, if you're providing your own policy advisor, you should + * keep a reference to the default one, or call BasePolicyAdvisorForMandatoryProfiles. You can choose not to, + * but if you do, you are allowing for resources that deviate from the FHIR specification (in a way that the + * community considers clinically unsafe, since it means that software (probably) will miss vital signs for + * patients). + * + * @param validator + * @param appContext What was originally provided from the app for it's context + * @param stackPath The current path for the stack. Note that the because of cross-references and FHIRPath conformsTo() statements, the stack can wind through the content unpredictably. + * @param definition the definition being validated against (might be useful: ElementDefinition.base.path, ElementDefinition.type, ElementDefinition.binding + * @param structure The structure definition that contains the element definition being validated against (may be from the base spec, may be from a profile) + * @param resource The actual resource (as an element model) so that the implementation can inspect the values in order to decide what profiles to apply + * @param valid true if the resource is so far considered valid + * @param messages all the validation messages. Implementations can inspect this, but the real purpose is to populate the messages with information messages explaining why profiles were (or weren't) applied + * @return + */ + List getImpliedProfilesForInstance(IResourceValidator validator, + Object appContext, + String stackPath, + ElementDefinition definition, + StructureDefinition structure, + Element resource, + boolean valid, + List messages); } \ No newline at end of file diff --git a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/utils/validation/constants/RuleImplementationLevel.java b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/utils/validation/constants/BestPracticeWarningLevel.java similarity index 70% rename from org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/utils/validation/constants/RuleImplementationLevel.java rename to org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/utils/validation/constants/BestPracticeWarningLevel.java index a543cb90d..441fadea8 100644 --- a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/utils/validation/constants/RuleImplementationLevel.java +++ b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/utils/validation/constants/BestPracticeWarningLevel.java @@ -1,6 +1,6 @@ package org.hl7.fhir.r5.utils.validation.constants; -public enum RuleImplementationLevel { +public enum BestPracticeWarningLevel { Ignore, Hint, Warning, diff --git a/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/instance/BasePolicyAdvisorForFullValidation.java b/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/instance/BasePolicyAdvisorForFullValidation.java new file mode 100644 index 000000000..0a67ca1e8 --- /dev/null +++ b/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/instance/BasePolicyAdvisorForFullValidation.java @@ -0,0 +1,65 @@ +package org.hl7.fhir.validation.instance; + +import java.util.EnumSet; +import java.util.List; + +import org.hl7.fhir.r5.elementmodel.Element; +import org.hl7.fhir.r5.elementmodel.Element.SpecialElement; +import org.hl7.fhir.r5.model.ElementDefinition; +import org.hl7.fhir.r5.model.StructureDefinition; +import org.hl7.fhir.r5.model.ValueSet; +import org.hl7.fhir.r5.utils.validation.IResourceValidator; +import org.hl7.fhir.r5.utils.validation.IValidationPolicyAdvisor; +import org.hl7.fhir.r5.utils.validation.constants.BindingKind; +import org.hl7.fhir.r5.utils.validation.constants.ContainedReferenceValidationPolicy; +import org.hl7.fhir.r5.utils.validation.constants.ReferenceValidationPolicy; +import org.hl7.fhir.utilities.validation.ValidationMessage; + +public class BasePolicyAdvisorForFullValidation implements IValidationPolicyAdvisor { + + @Override + public ReferenceValidationPolicy policyForReference(IResourceValidator validator, Object appContext, String path, + String url) { + // TODO Auto-generated method stub + return null; + } + + @Override + public ContainedReferenceValidationPolicy policyForContained(IResourceValidator validator, Object appContext, + StructureDefinition structure, ElementDefinition element, String containerType, String containerId, + SpecialElement containingResourceType, String path, String url) { + // TODO Auto-generated method stub + return null; + } + + @Override + public EnumSet policyForResource(IResourceValidator validator, Object appContext, + StructureDefinition type, String path) { + // TODO Auto-generated method stub + return null; + } + + @Override + public EnumSet policyForElement(IResourceValidator validator, Object appContext, + StructureDefinition structure, ElementDefinition element, String path) { + // TODO Auto-generated method stub + return null; + } + + @Override + public EnumSet policyForCodedContent(IResourceValidator validator, Object appContext, + String stackPath, ElementDefinition definition, StructureDefinition structure, BindingKind kind, + AdditionalBindingPurpose purpose, ValueSet valueSet, List systems) { + // TODO Auto-generated method stub + return null; + } + + @Override + public List getImpliedProfilesForInstance(IResourceValidator validator, Object appContext, + String stackPath, ElementDefinition definition, StructureDefinition structure, Element resource, boolean valid, + List messages) { + // TODO Auto-generated method stub + return null; + } + +}