Class ValidationEngine

  • All Implemented Interfaces:
    org.hl7.fhir.r5.utils.validation.IValidationPolicyAdvisor, org.hl7.fhir.r5.utils.validation.IValidatorResourceFetcher, IPackageInstaller

    public class ValidationEngine
    extends Object
    implements org.hl7.fhir.r5.utils.validation.IValidatorResourceFetcher, org.hl7.fhir.r5.utils.validation.IValidationPolicyAdvisor, IPackageInstaller
    This is just a wrapper around the InstanceValidator class for convenient use

    The following resource formats are supported: XML, JSON, Turtle The following versions are supported: 1.0.2, 1.4.0, 3.0.2, 4.0.1, and current

    Note: the validation engine is intended to be threadsafe To Use:

    1/ Initialize ValidationEngine validator = new ValidationEngine(src); - this must be the packageId of the relevant core specification for the version you want to validate against (e.g. hl7.fhir.r4.core)

    validator.connectToTSServer(txServer); - this is optional; in the absence of a terminology service, snomed, loinc etc will not be validated

    validator.loadIg(src); - call this any number of times for the Implementation Guide(s) of interest. - See https://confluence.hl7.org/display/FHIR/Using+the+FHIR+Validator for documentation about the src parameter (-ig parameter)

    validator.loadQuestionnaire(src) - url or filename of a questionnaire to load. Any loaded questionnaires will be used while validating

    validator.setNative(doNative); - whether to do xml/json/rdf schema validation as well

    You only need to do this initialization once. You can validate as many times as you like

    2. validate validator.validate(src, profiles); - source (as stream, byte[]), or url or filename of a resource to validate. Also validate against any profiles (as canonical URLS, equivalent to listing them in Resource.meta.profile)

    if the source is provided as byte[] or stream, you need to provide a format too, though you can leave that as null, and the validator will guess

    3. Or, instead of validating, transform (see documentation and use in Validator.java)

    Author:
    Grahame Grieve
    • Method Detail

      • validate

        public org.hl7.fhir.r5.model.OperationOutcome validate​(org.hl7.fhir.r5.elementmodel.Manager.FhirFormat format,
                                                               InputStream stream,
                                                               List<String> profiles)
                                                        throws org.hl7.fhir.exceptions.FHIRException,
                                                               IOException,
                                                               org.hl7.fhir.r5.utils.EOperationOutcome
        Throws:
        org.hl7.fhir.exceptions.FHIRException
        IOException
        org.hl7.fhir.r5.utils.EOperationOutcome
      • validate

        public org.hl7.fhir.r5.model.OperationOutcome validate​(byte[] source,
                                                               org.hl7.fhir.r5.elementmodel.Manager.FhirFormat cntType,
                                                               List<String> profiles,
                                                               List<org.hl7.fhir.utilities.validation.ValidationMessage> messages)
                                                        throws org.hl7.fhir.exceptions.FHIRException,
                                                               IOException,
                                                               org.hl7.fhir.r5.utils.EOperationOutcome
        Throws:
        org.hl7.fhir.exceptions.FHIRException
        IOException
        org.hl7.fhir.r5.utils.EOperationOutcome
      • validate

        public org.hl7.fhir.r5.model.OperationOutcome validate​(String location,
                                                               byte[] source,
                                                               org.hl7.fhir.r5.elementmodel.Manager.FhirFormat cntType,
                                                               List<String> profiles,
                                                               org.hl7.fhir.r5.utils.validation.constants.IdStatus resourceIdRule,
                                                               boolean anyExtensionsAllowed,
                                                               org.hl7.fhir.r5.utils.validation.constants.BestPracticeWarningLevel bpWarnings,
                                                               org.hl7.fhir.r5.utils.validation.constants.CheckDisplayOption displayOption)
                                                        throws org.hl7.fhir.exceptions.FHIRException,
                                                               IOException,
                                                               org.hl7.fhir.r5.utils.EOperationOutcome,
                                                               SAXException
        Throws:
        org.hl7.fhir.exceptions.FHIRException
        IOException
        org.hl7.fhir.r5.utils.EOperationOutcome
        SAXException
      • transform

        public org.hl7.fhir.r5.elementmodel.Element transform​(String source,
                                                              String map)
                                                       throws org.hl7.fhir.exceptions.FHIRException,
                                                              IOException
        Throws:
        org.hl7.fhir.exceptions.FHIRException
        IOException
      • compile

        public org.hl7.fhir.r5.model.StructureMap compile​(String mapUri)
                                                   throws org.hl7.fhir.exceptions.FHIRException,
                                                          IOException
        Throws:
        org.hl7.fhir.exceptions.FHIRException
        IOException
      • transform

        public org.hl7.fhir.r5.elementmodel.Element transform​(byte[] source,
                                                              org.hl7.fhir.r5.elementmodel.Manager.FhirFormat cntType,
                                                              String mapUri)
                                                       throws org.hl7.fhir.exceptions.FHIRException,
                                                              IOException
        Throws:
        org.hl7.fhir.exceptions.FHIRException
        IOException
      • generate

        public org.hl7.fhir.r5.model.Resource generate​(String source,
                                                       String version)
                                                throws org.hl7.fhir.exceptions.FHIRException,
                                                       IOException,
                                                       org.hl7.fhir.r5.utils.EOperationOutcome
        Throws:
        org.hl7.fhir.exceptions.FHIRException
        IOException
        org.hl7.fhir.r5.utils.EOperationOutcome
      • genResource

        public void genResource​(org.hl7.fhir.r5.model.Resource res,
                                org.hl7.fhir.r5.renderers.utils.RenderingContext rc)
                         throws IOException,
                                org.hl7.fhir.r5.utils.EOperationOutcome
        Throws:
        IOException
        org.hl7.fhir.r5.utils.EOperationOutcome
      • snapshot

        public org.hl7.fhir.r5.model.StructureDefinition snapshot​(String source,
                                                                  String version)
                                                           throws org.hl7.fhir.exceptions.FHIRException,
                                                                  IOException
        Throws:
        org.hl7.fhir.exceptions.FHIRException
        IOException
      • seeResource

        public void seeResource​(org.hl7.fhir.r5.model.Resource r)
                         throws org.hl7.fhir.exceptions.FHIRException
        Throws:
        org.hl7.fhir.exceptions.FHIRException
      • fetchRaw

        public byte[] fetchRaw​(org.hl7.fhir.r5.utils.validation.IResourceValidator validator,
                               String source)
                        throws IOException
        Specified by:
        fetchRaw in interface org.hl7.fhir.r5.utils.validation.IValidatorResourceFetcher
        Throws:
        IOException
      • fetch

        public org.hl7.fhir.r5.elementmodel.Element fetch​(org.hl7.fhir.r5.utils.validation.IResourceValidator validator,
                                                          Object appContext,
                                                          String url)
                                                   throws org.hl7.fhir.exceptions.FHIRException,
                                                          IOException
        Specified by:
        fetch in interface org.hl7.fhir.r5.utils.validation.IValidatorResourceFetcher
        Throws:
        org.hl7.fhir.exceptions.FHIRException
        IOException
      • policyForReference

        public org.hl7.fhir.r5.utils.validation.constants.ReferenceValidationPolicy policyForReference​(org.hl7.fhir.r5.utils.validation.IResourceValidator validator,
                                                                                                       Object appContext,
                                                                                                       String path,
                                                                                                       String url)
        Specified by:
        policyForReference in interface org.hl7.fhir.r5.utils.validation.IValidationPolicyAdvisor
      • policyForContained

        public org.hl7.fhir.r5.utils.validation.constants.ContainedReferenceValidationPolicy policyForContained​(org.hl7.fhir.r5.utils.validation.IResourceValidator validator,
                                                                                                                Object appContext,
                                                                                                                String containerType,
                                                                                                                String containerId,
                                                                                                                org.hl7.fhir.r5.elementmodel.Element.SpecialElement containingResourceType,
                                                                                                                String path,
                                                                                                                String url)
        Specified by:
        policyForContained in interface org.hl7.fhir.r5.utils.validation.IValidationPolicyAdvisor
      • policyForCodedContent

        public org.hl7.fhir.r5.utils.validation.constants.CodedContentValidationPolicy policyForCodedContent​(org.hl7.fhir.r5.utils.validation.IResourceValidator validator,
                                                                                                             Object appContext,
                                                                                                             String stackPath,
                                                                                                             org.hl7.fhir.r5.model.ElementDefinition definition,
                                                                                                             org.hl7.fhir.r5.model.StructureDefinition structure,
                                                                                                             org.hl7.fhir.r5.utils.validation.constants.BindingKind kind,
                                                                                                             org.hl7.fhir.r5.model.ValueSet valueSet,
                                                                                                             List<String> systems)
        Specified by:
        policyForCodedContent in interface org.hl7.fhir.r5.utils.validation.IValidationPolicyAdvisor
      • resolveURL

        public boolean resolveURL​(org.hl7.fhir.r5.utils.validation.IResourceValidator validator,
                                  Object appContext,
                                  String path,
                                  String url,
                                  String type)
                           throws org.hl7.fhir.exceptions.FHIRException
        Specified by:
        resolveURL in interface org.hl7.fhir.r5.utils.validation.IValidatorResourceFetcher
        Throws:
        org.hl7.fhir.exceptions.FHIRException
      • fetchCanonicalResource

        public org.hl7.fhir.r5.model.CanonicalResource fetchCanonicalResource​(org.hl7.fhir.r5.utils.validation.IResourceValidator validator,
                                                                              String url)
                                                                       throws URISyntaxException
        Specified by:
        fetchCanonicalResource in interface org.hl7.fhir.r5.utils.validation.IValidatorResourceFetcher
        Throws:
        URISyntaxException
      • fetchesCanonicalResource

        public boolean fetchesCanonicalResource​(org.hl7.fhir.r5.utils.validation.IResourceValidator validator,
                                                String url)
        Specified by:
        fetchesCanonicalResource in interface org.hl7.fhir.r5.utils.validation.IValidatorResourceFetcher