001package org.hl7.fhir.r5.utils.validation;
002
003import java.util.List;
004
005import org.hl7.fhir.r5.elementmodel.Element;
006import org.hl7.fhir.r5.model.ElementDefinition;
007import org.hl7.fhir.r5.model.StructureDefinition;
008import org.hl7.fhir.r5.model.ValueSet;
009import org.hl7.fhir.r5.utils.validation.constants.ContainedReferenceValidationPolicy;
010import org.hl7.fhir.r5.utils.validation.constants.ReferenceValidationPolicy;
011import org.hl7.fhir.r5.utils.validation.constants.CodedContentValidationPolicy;
012import org.hl7.fhir.r5.utils.validation.constants.BindingKind;
013
014public interface IValidationPolicyAdvisor {
015
016  /**
017   *
018   * @param validator
019   * @param appContext What was originally provided from the app for it's context
020   * @param path Path that led us to this resource.
021   * @param url Url of the profile the container resource is being validated against.
022   * @return {@link ReferenceValidationPolicy}
023   */
024  ReferenceValidationPolicy policyForReference(IResourceValidator validator,
025                                               Object appContext,
026                                               String path,
027                                               String url);
028
029  /**
030   * //TODO pass through the actual containing Element as opposed to the type, id
031   * @param validator
032   * @param appContext What was originally provided from the app for it's context
033   * @param containerType Type of the resources that contains the resource being validated
034   * @param containerId Id of the resources that contains the resource being validated
035   * @param containingResourceType Type of the resource that will be validated (BUNDLE_ENTRY, BUNDLE_OUTCOME, CONTAINED_RESOURCE, PARAMETER)
036   * @param path Path that led us to this resource.
037   * @param url Url of the profile the container resource is being validated against.
038   * @return {@link ReferenceValidationPolicy}
039   */
040  ContainedReferenceValidationPolicy policyForContained(IResourceValidator validator,
041                                                        Object appContext,
042                                                        String containerType,
043                                                        String containerId,
044                                                        Element.SpecialElement containingResourceType,
045                                                        String path,
046                                                        String url);
047
048  /**
049   * Called before validating a concept in an instance against the terminology sub-system
050   * 
051   * There's two reasons to use this policy advisor feature:
052   *   - save time by not calling the terminology server for validation that don't bring value to the context calling the validation
053   *   - suppressing known issues from being listed as a problem
054   *   
055   * Note that the terminology subsystem has two parts: a mini-terminology server running inside the 
056   * validator, and then calling out to an external terminology service (usually tx.fhir.org, though you
057   * run your own local copy of this - see https://confluence.hl7.org/display/FHIR/Running+your+own+copy+of+tx.fhir.org).
058   * You can't tell which subsystem will handle the terminology validation directly from the content provided here which
059   * subsystem will be called - you'll haev to investigate based on your set up. (matters, since it makes a huge performance 
060   * difference, though it also depends on caching, and the impact of caching is also not known at this point)
061   *   
062   * @param validator
063   * @param appContext What was originally provided from the app for it's context
064   * @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. 
065   * @param definition the definition being validated against (might be useful: ElementDefinition.base.path, ElementDefinition.type, ElementDefinition.binding
066   * @param structure The structure definition that contains the element definition being validated against (may be from the base spec, may be from a profile)
067   * @param kind The part of the binding being validated
068   * @param valueSet The value set for the binding part that's being validated 
069   * @param systems A list of canonical URls (including versions if known) of the systems in the instance that's being validated. Note that if a plain code is being validated, then there'll be no known system when this is called (systems will be empty, not null) 
070   * @return {@link CodedContentValidationPolicy}
071   */
072  CodedContentValidationPolicy policyForCodedContent(IResourceValidator validator,
073                                                        Object appContext,
074                                                        String stackPath,
075                                                        ElementDefinition definition,
076                                                        StructureDefinition structure,
077                                                        BindingKind kind,
078                                                        ValueSet valueSet,
079                                                        List<String> systems);
080
081  
082}