Class MatchboxEngine

java.lang.Object
org.hl7.fhir.validation.ValidationEngine
ch.ahdis.matchbox.engine.MatchboxEngine
All Implemented Interfaces:
org.hl7.fhir.r5.context.IWorkerContextManager.IPackageLoadingTracker, org.hl7.fhir.r5.utils.validation.IValidationPolicyAdvisor, org.hl7.fhir.r5.utils.validation.IValidatorResourceFetcher, org.hl7.fhir.validation.cli.services.IPackageInstaller
Direct Known Subclasses:
CdaMappingEngine

public class MatchboxEngine extends org.hl7.fhir.validation.ValidationEngine
Base Engine providing functionality on top of the ValdiationEngine
Author:
oliveregger
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static class 
    Builder class to instantiate a MappingEngine

    Nested classes/interfaces inherited from class org.hl7.fhir.validation.ValidationEngine

    org.hl7.fhir.validation.ValidationEngine.IValidationEngineLoader, org.hl7.fhir.validation.ValidationEngine.ValidationEngineBuilder
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected static final org.slf4j.Logger
     
    protected final List<String>
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    MatchboxEngine(@NonNull org.hl7.fhir.validation.ValidationEngine other)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    adds a canonical resource to the loaded packages, please note that it will replace a resource with the same canonical url
    void
    addCanonicalResource(org.hl7.fhir.r4.model.Resource resource)
    adds a canonical resource to the loaded packages, please note that it will replace a resource with the same canonical url for FHIR R4
    void
    addCanonicalResource(org.hl7.fhir.r4b.model.CanonicalResource resource)
    adds a canonical resource to the loaded packages, please note that it will replace a resource with the same canonical url for FHIR R4B
    void
    addCanonicalResource(org.hl7.fhir.r5.model.CanonicalResource resource)
    adds a canonical resource to the loaded packages, please note that it will replace a resource with the same canonical url for FHIR R5
    void
    Adds a text to the list of suppressed validation warning/information-level issues.
    void
    Adds a Regex pattern to the list of suppressed validation warning/information-level issues.
    List<org.hl7.fhir.r5.model.StructureDefinition>
    asSdList(@Nullable List<String> profiles)
    internal use, checks if all profiles can be resolved
    protected List<Pattern>
    Compiles the list of suppressed validation warning/information-level issues into a list of Pattern.
    org.hl7.fhir.r4.model.StructureDefinition
    createSnapshot(org.hl7.fhir.r4.model.StructureDefinition sd)
    creates the snapshot for the provided StructureDefinition
    evaluateFhirPath(@NonNull String input, boolean inputJson, @NonNull String expression)
     
    boolean
    fetchesCanonicalResource(org.hl7.fhir.r5.utils.validation.IResourceValidator validator, String url)
     
    List<org.hl7.fhir.utilities.validation.ValidationMessage>
    filterValidationMessages(@NonNull List<org.hl7.fhir.utilities.validation.ValidationMessage> messages)
    Copies the given list, removes messages if they are warning and match a list of ignored messages.
    org.hl7.fhir.r4.model.Resource
    Returns a canonical resource defined by its url
    org.hl7.fhir.instance.model.api.IBaseResource
    getCanonicalResource(String canonical, String fhirVersion)
    Returns a canonical resource defined by its url
    org.hl7.fhir.instance.model.api.IBaseResource
    Returns a canonical resource defined by its type and uri
    org.hl7.fhir.utilities.npm.FilesystemPackageCacheManager
    A safe getter for the PCM.
    org.hl7.fhir.r4.model.StructureDefinition
    Get the corresponding Struc
    Returns the list of suppressed validation warning/information-level issues.
    void
    loadPackage(@NonNull InputStream inputStream)
    Loads an IG in the engine from its NPM package as an InputStream, its ID and version.
    protected org.hl7.fhir.r4.model.OperationOutcome
    messagesToOutcome(@NonNull List<org.hl7.fhir.utilities.validation.ValidationMessage> messages, @NonNull org.hl7.fhir.r5.context.SimpleWorkerContext context)
    Maps a list of ValidationMessage to an R4 OperationOutcome.
    org.hl7.fhir.r4.model.StructureMap
    parseMap(String content)
    Parses a FHIR Structure Map from the textual representation according to the FHIR Mapping Language grammar (see http://build.fhir.org/mapping-language.html#grammar)
    org.hl7.fhir.r5.model.StructureMap
    parseMapR5(String content)
    Parses a FHIR Structure Map from the textual representation according to the FHIR Mapping Language grammar (see http://build.fhir.org/mapping-language.html#grammar) for FHIR release 5
    transform(String input, boolean inputJson, String mapUri, boolean outputJson)
    Transforms an input with the map identified by the uri to the output defined by the map
    org.hl7.fhir.r5.elementmodel.Element
    transform(org.hl7.fhir.r5.elementmodel.Element src, String mapUri)
    Adapted transform operation from Validation Engine to use patched MatchboxStructureMapUtilities
    org.hl7.fhir.r5.elementmodel.Element
    transform(org.hl7.fhir.utilities.ByteProvider source, org.hl7.fhir.r5.elementmodel.Manager.FhirFormat cntType, String mapUri)
    Adapted transform operation from Validation Engine to use patched MatchboxStructureMapUtilities
    org.hl7.fhir.r4.model.Resource
    transformToFhir(String input, boolean inputJson, String mapUri)
    Transforms an input with the map identified by the uri to the output defined by the map
    org.hl7.fhir.r4.model.OperationOutcome
    validate(@NonNull InputStream stream, @NonNull org.hl7.fhir.r5.elementmodel.Manager.FhirFormat format, @Nullable String profileUrl)
    validates a FHIR resources and provides OperationOutcome as output
    org.hl7.fhir.r4.model.OperationOutcome
    validate(@NonNull org.hl7.fhir.r4.model.Resource resource, @Nullable String profileUrl)
    validates a FHIR resources and provides OperationOutcome as output
    List<org.hl7.fhir.utilities.validation.ValidationMessage>
    validate(@NonNull org.hl7.fhir.r5.elementmodel.Manager.FhirFormat format, @NonNull InputStream stream, @Nullable String profileUrl)
     

    Methods inherited from class org.hl7.fhir.validation.ValidationEngine

    compile, connectToTSServer, connectToTSServer, convert, dropResource, evaluateFhirPath, fetch, fetchCanonicalResource, fetchRaw, generate, genResource, getBestPracticeLevel, getBinaries, getBundleValidationRules, getContext, getExtensionDomains, getFetcher, getFhirPathEngine, getHtmlInMarkdownCheck, getIgLoader, getIgs, getJurisdiction, getLanguage, getLevel, getLocale, getLocator, getMapLog, getPolicyAdvisor, getQuestionnaireMode, getValidationControl, getValidator, getVersion, handleOutput, initContext, isAllowDoubleQuotesInFHIRPath, isAllowExampleUrls, isAnyExtensionsAllowed, isAssumeValidRestReferences, isCheckIPSCodes, isCrumbTrails, isDebug, isDisplayWarnings, isDoImplicitFHIRPathStringConversion, isDoNative, isForPublication, isHintAboutNonMustSupport, isNoExtensibleBindingMessages, isNoInvariantChecks, isNoUnicodeBiDiControlChars, isSecurityChecks, isShowMessagesFromReferences, isShowTimes, isWantInvariantInMessage, loadCanonicalResource, loadPackage, loadProfile, loadResource, packageExists, packageLoaded, policyForCodedContent, policyForContained, policyForReference, prepare, resolveURL, seeResource, setAllowDoubleQuotesInFHIRPath, setAllowExampleUrls, setAnyExtensionsAllowed, setAssumeValidRestReferences, setBestPracticeLevel, setBinaries, setBundleValidationRules, setCheckIPSCodes, setContext, setCrumbTrails, setDebug, setDisplayWarnings, setDoImplicitFHIRPathStringConversion, setDoNative, setExtensionDomains, setFetcher, setFhirPathEngine, setForPublication, setHintAboutNonMustSupport, setHtmlInMarkdownCheck, setIgLoader, setIgs, setJurisdiction, setLanguage, setLevel, setLocale, setLocator, setMapLog, setNoExtensibleBindingMessages, setNoInvariantChecks, setNoUnicodeBiDiControlChars, setPcm, setPolicyAdvisor, setQuestionnaireMode, setSecurityChecks, setShowMessagesFromReferences, setShowTimes, setSnomedExtension, setTerminologyServer, setValidationControl, setVersion, setWantInvariantInMessage, snapshot, transform, transformVersion, validate, validate, validate, validate, validate, validate, validateAsFragments

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • log

      protected static final org.slf4j.Logger log
    • suppressedWarnInfoPatterns

      protected final List<String> suppressedWarnInfoPatterns
  • Constructor Details

    • MatchboxEngine

      public MatchboxEngine(@NonNull org.hl7.fhir.validation.ValidationEngine other) throws org.hl7.fhir.exceptions.FHIRException, IOException
      Throws:
      org.hl7.fhir.exceptions.FHIRException
      IOException
  • Method Details

    • getPcm

      public org.hl7.fhir.utilities.npm.FilesystemPackageCacheManager getPcm()
      A safe getter for the PCM. It has been created in the constructor, so it should be safe to access.
      Overrides:
      getPcm in class org.hl7.fhir.validation.ValidationEngine
    • transformToFhir

      public org.hl7.fhir.r4.model.Resource transformToFhir(String input, boolean inputJson, String mapUri) throws org.hl7.fhir.exceptions.FHIRException, IOException
      Transforms an input with the map identified by the uri to the output defined by the map
      Parameters:
      input - content to be transformed
      inputJson - true if input is in json (if false xml is expected)
      mapUri - canonical url of StructureMap
      Returns:
      FHIR resource
      Throws:
      org.hl7.fhir.exceptions.FHIRException - FHIR Exception
      IOException - IO Exception
    • transform

      public String transform(String input, boolean inputJson, String mapUri, boolean outputJson) throws org.hl7.fhir.exceptions.FHIRException, IOException
      Transforms an input with the map identified by the uri to the output defined by the map
      Parameters:
      input - source in UTF-8 format
      inputJson - if input is in json (or xml)
      mapUri - map to use for transformation
      outputJson - if output is formatted as json (or xml)
      Returns:
      transformed input as string
      Throws:
      org.hl7.fhir.exceptions.FHIRException - FHIR Exception
      IOException - IO Exception
    • transform

      public org.hl7.fhir.r5.elementmodel.Element transform(org.hl7.fhir.utilities.ByteProvider source, org.hl7.fhir.r5.elementmodel.Manager.FhirFormat cntType, String mapUri) throws org.hl7.fhir.exceptions.FHIRException, IOException
      Adapted transform operation from Validation Engine to use patched MatchboxStructureMapUtilities
      Overrides:
      transform in class org.hl7.fhir.validation.ValidationEngine
      Throws:
      org.hl7.fhir.exceptions.FHIRException
      IOException
    • transform

      public org.hl7.fhir.r5.elementmodel.Element transform(org.hl7.fhir.r5.elementmodel.Element src, String mapUri) throws org.hl7.fhir.exceptions.FHIRException, IOException
      Adapted transform operation from Validation Engine to use patched MatchboxStructureMapUtilities
      Parameters:
      src -
      mapUri -
      Returns:
      Throws:
      org.hl7.fhir.exceptions.FHIRException
      IOException
    • addCanonicalResource

      public void addCanonicalResource(InputStream stream) throws org.hl7.fhir.exceptions.FHIRException
      adds a canonical resource to the loaded packages, please note that it will replace a resource with the same canonical url
      Parameters:
      stream - canonical resource to add
      Throws:
      org.hl7.fhir.exceptions.FHIRException - FHIR Exception
    • addCanonicalResource

      public void addCanonicalResource(org.hl7.fhir.r4.model.Resource resource) throws org.hl7.fhir.exceptions.FHIRException
      adds a canonical resource to the loaded packages, please note that it will replace a resource with the same canonical url for FHIR R4
      Parameters:
      resource - canonical resource to add
      Throws:
      org.hl7.fhir.exceptions.FHIRException - FHIR Exception
    • addCanonicalResource

      public void addCanonicalResource(org.hl7.fhir.r4b.model.CanonicalResource resource) throws org.hl7.fhir.exceptions.FHIRException
      adds a canonical resource to the loaded packages, please note that it will replace a resource with the same canonical url for FHIR R4B
      Parameters:
      resource - canonical resource to add
      Throws:
      org.hl7.fhir.exceptions.FHIRException - FHIR Exception
    • addCanonicalResource

      public void addCanonicalResource(org.hl7.fhir.r5.model.CanonicalResource resource) throws org.hl7.fhir.exceptions.FHIRException
      adds a canonical resource to the loaded packages, please note that it will replace a resource with the same canonical url for FHIR R5
      Parameters:
      resource - canonical resource to add
      Throws:
      org.hl7.fhir.exceptions.FHIRException - FHIR Exception
    • validate

      public org.hl7.fhir.r4.model.OperationOutcome validate(@NonNull InputStream stream, @NonNull org.hl7.fhir.r5.elementmodel.Manager.FhirFormat format, @Nullable String profileUrl) throws org.hl7.fhir.exceptions.FHIRException, IOException, org.hl7.fhir.r5.utils.EOperationOutcome
      validates a FHIR resources and provides OperationOutcome as output
      Parameters:
      stream - resource to validate as input stream
      format - format of resource
      profileUrl - profile to validate against
      Returns:
      result as Operation Outcome
      Throws:
      org.hl7.fhir.exceptions.FHIRException - FHIR Exception
      IOException - IO Exception
      org.hl7.fhir.r5.utils.EOperationOutcome - Exception OperationOutcome
    • validate

      public org.hl7.fhir.r4.model.OperationOutcome validate(@NonNull org.hl7.fhir.r4.model.Resource resource, @Nullable String profileUrl) throws org.hl7.fhir.exceptions.FHIRException, IOException, org.hl7.fhir.r5.utils.EOperationOutcome
      validates a FHIR resources and provides OperationOutcome as output
      Parameters:
      resource - FHIR R4 resource
      profileUrl - profile to validate against
      Returns:
      Throws:
      org.hl7.fhir.exceptions.FHIRException - FHIR Exception
      IOException - IO Exception
      org.hl7.fhir.r5.utils.EOperationOutcome
    • validate

      public List<org.hl7.fhir.utilities.validation.ValidationMessage> validate(@NonNull org.hl7.fhir.r5.elementmodel.Manager.FhirFormat format, @NonNull InputStream stream, @Nullable String profileUrl) 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
    • asSdList

      public List<org.hl7.fhir.r5.model.StructureDefinition> asSdList(@Nullable List<String> profiles) throws Error
      internal use, checks if all profiles can be resolved
      Overrides:
      asSdList in class org.hl7.fhir.validation.ValidationEngine
      Parameters:
      profiles - canonical url of profiles (StructureDefinition)
      Returns:
      StructureDefintions
      Throws:
      Error - if profile cannot be resolved
    • getStructureDefinition

      public org.hl7.fhir.r4.model.StructureDefinition getStructureDefinition(String profile)
      Get the corresponding Struc
      Parameters:
      profile -
      Returns:
    • getCanonicalResource

      public org.hl7.fhir.r4.model.Resource getCanonicalResource(String canonical)
      Returns a canonical resource defined by its url
      Parameters:
      canonical -
      Returns:
    • getCanonicalResource

      public org.hl7.fhir.instance.model.api.IBaseResource getCanonicalResource(String canonical, String fhirVersion)
      Returns a canonical resource defined by its url
      Parameters:
      canonical -
      fhirVersion -
      Returns:
    • 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
      Overrides:
      fetchesCanonicalResource in class org.hl7.fhir.validation.ValidationEngine
    • getCanonicalResourceById

      public org.hl7.fhir.instance.model.api.IBaseResource getCanonicalResourceById(String type, @NonNull String id)
      Returns a canonical resource defined by its type and uri
      Parameters:
      type - resource type
      id - resource id
      Returns:
    • parseMapR5

      public org.hl7.fhir.r5.model.StructureMap parseMapR5(String content) throws org.hl7.fhir.exceptions.FHIRException
      Parses a FHIR Structure Map from the textual representation according to the FHIR Mapping Language grammar (see http://build.fhir.org/mapping-language.html#grammar) for FHIR release 5
      Parameters:
      content - FHIR Mapping Language text
      Returns:
      parsed StructureMap resource
      Throws:
      org.hl7.fhir.exceptions.FHIRException - FHIR Exception
    • parseMap

      public org.hl7.fhir.r4.model.StructureMap parseMap(String content) throws org.hl7.fhir.exceptions.FHIRException
      Parses a FHIR Structure Map from the textual representation according to the FHIR Mapping Language grammar (see http://build.fhir.org/mapping-language.html#grammar)
      Parameters:
      content - FHIR Mapping Language text
      Returns:
      parsed StructureMap resource
      Throws:
      org.hl7.fhir.exceptions.FHIRException - FHIR Exception
    • createSnapshot

      public org.hl7.fhir.r4.model.StructureDefinition createSnapshot(org.hl7.fhir.r4.model.StructureDefinition sd) throws org.hl7.fhir.exceptions.FHIRException, IOException
      creates the snapshot for the provided StructureDefinition
      Parameters:
      sd - StructureDefinition with differential
      Returns:
      StructureDefinition with snapshot (differential applied to base definition)
      Throws:
      org.hl7.fhir.exceptions.FHIRException - FHIR Exception
      IOException - IO Exception
    • evaluateFhirPath

      public String evaluateFhirPath(@NonNull String input, boolean inputJson, @NonNull String expression) throws org.hl7.fhir.exceptions.FHIRException, IOException
      Parameters:
      input - input to run fhirpath expression against
      inputJson - if input format is json or xml
      expression - fhirPath expression
      Returns:
      result
      Throws:
      org.hl7.fhir.exceptions.FHIRException - FHIR Exception
      IOException - IO Exception
    • loadPackage

      public void loadPackage(@NonNull InputStream inputStream) throws IOException
      Loads an IG in the engine from its NPM package as an InputStream, its ID and version. The InputStream will be closed by NpmPackage.readStream(java.io.InputStream, java.lang.String, boolean).

      The package dependencies shall be added manually, no recursive loading will be performed.

      Parameters:
      inputStream - The NPM package input stream. It will be closed.
      Throws:
      IOException
    • filterValidationMessages

      public List<org.hl7.fhir.utilities.validation.ValidationMessage> filterValidationMessages(@NonNull List<org.hl7.fhir.utilities.validation.ValidationMessage> messages)
      Copies the given list, removes messages if they are warning and match a list of ignored messages.
      Parameters:
      messages - The original list of validation messages.
      Returns:
      A copy of the message list, without issues that have to be filtered.
    • addSuppressedWarnInfo

      public void addSuppressedWarnInfo(@NonNull String text)
      Adds a text to the list of suppressed validation warning/information-level issues.

      Implementation note: The text is Regex-escaped before being added to the list.

      Parameters:
      text - The text to add.
    • addSuppressedWarnInfoPattern

      public void addSuppressedWarnInfoPattern(@NonNull String pattern)
      Adds a Regex pattern to the list of suppressed validation warning/information-level issues.
      Parameters:
      pattern - The Regex pattern to add.
    • getSuppressedWarnInfoPatterns

      public List<String> getSuppressedWarnInfoPatterns()
      Returns the list of suppressed validation warning/information-level issues.
    • compileSuppressedWarnInfoPatterns

      protected List<Pattern> compileSuppressedWarnInfoPatterns()
      Compiles the list of suppressed validation warning/information-level issues into a list of Pattern.
    • messagesToOutcome

      protected org.hl7.fhir.r4.model.OperationOutcome messagesToOutcome(@NonNull List<org.hl7.fhir.utilities.validation.ValidationMessage> messages, @NonNull org.hl7.fhir.r5.context.SimpleWorkerContext context) throws IOException, org.hl7.fhir.exceptions.FHIRException, org.hl7.fhir.r5.utils.EOperationOutcome
      Maps a list of ValidationMessage to an R4 OperationOutcome.
      Throws:
      IOException
      org.hl7.fhir.exceptions.FHIRException
      org.hl7.fhir.r5.utils.EOperationOutcome