Package ch.ahdis.matchbox.engine
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 ClassesModifier and TypeClassDescriptionstatic classBuilder class to instantiate a MappingEngineNested classes/interfaces inherited from class org.hl7.fhir.validation.ValidationEngine
org.hl7.fhir.validation.ValidationEngine.IValidationEngineLoader, org.hl7.fhir.validation.ValidationEngine.ValidationEngineBuilder -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static final org.slf4j.Logger -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddCanonicalResource(InputStream stream) adds a canonical resource to the loaded packages, please note that it will replace a resource with the same canonical urlvoidaddCanonicalResource(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 R4voidaddCanonicalResource(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 R4BvoidaddCanonicalResource(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 R5voidaddSuppressedWarnInfo(@NonNull String text) Adds a text to the list of suppressed validation warning/information-level issues.voidaddSuppressedWarnInfoPattern(@NonNull String pattern) Adds a Regex pattern to the list of suppressed validation warning/information-level issues.List<org.hl7.fhir.r5.model.StructureDefinition>internal use, checks if all profiles can be resolvedCompiles the list of suppressed validation warning/information-level issues into a list ofPattern.org.hl7.fhir.r4.model.StructureDefinitioncreateSnapshot(org.hl7.fhir.r4.model.StructureDefinition sd) creates the snapshot for the provided StructureDefinitionevaluateFhirPath(@NonNull String input, boolean inputJson, @NonNull String expression) booleanfetchesCanonicalResource(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.ResourcegetCanonicalResource(String canonical) Returns a canonical resource defined by its urlorg.hl7.fhir.instance.model.api.IBaseResourcegetCanonicalResource(String canonical, String fhirVersion) Returns a canonical resource defined by its urlorg.hl7.fhir.instance.model.api.IBaseResourcegetCanonicalResourceById(String type, @NonNull String id) Returns a canonical resource defined by its type and uriorg.hl7.fhir.utilities.npm.FilesystemPackageCacheManagergetPcm()A safe getter for the PCM.org.hl7.fhir.r4.model.StructureDefinitiongetStructureDefinition(String profile) Get the corresponding StrucReturns the list of suppressed validation warning/information-level issues.voidloadPackage(@NonNull InputStream inputStream) Loads an IG in the engine from its NPM package as anInputStream, its ID and version.protected org.hl7.fhir.r4.model.OperationOutcomemessagesToOutcome(@NonNull List<org.hl7.fhir.utilities.validation.ValidationMessage> messages, @NonNull org.hl7.fhir.r5.context.SimpleWorkerContext context) Maps a list ofValidationMessageto an R4OperationOutcome.org.hl7.fhir.r4.model.StructureMapParses 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.StructureMapparseMapR5(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 5Transforms an input with the map identified by the uri to the output defined by the maporg.hl7.fhir.r5.elementmodel.ElementAdapted transform operation from Validation Engine to use patched MatchboxStructureMapUtilitiesorg.hl7.fhir.r5.elementmodel.Elementtransform(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 MatchboxStructureMapUtilitiesorg.hl7.fhir.r4.model.ResourcetransformToFhir(String input, boolean inputJson, String mapUri) Transforms an input with the map identified by the uri to the output defined by the maporg.hl7.fhir.r4.model.OperationOutcomevalidate(@NonNull InputStream stream, @NonNull org.hl7.fhir.r5.elementmodel.Manager.FhirFormat format, @Nullable String profileUrl) validates a FHIR resources and provides OperationOutcome as outputorg.hl7.fhir.r4.model.OperationOutcomevalidates a FHIR resources and provides OperationOutcome as outputList<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
-
Field Details
-
log
protected static final org.slf4j.Logger log -
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.FHIRExceptionIOException
-
-
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:
getPcmin classorg.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 transformedinputJson- 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 ExceptionIOException- 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 formatinputJson- if input is in json (or xml)mapUri- map to use for transformationoutputJson- if output is formatted as json (or xml)- Returns:
- transformed input as string
- Throws:
org.hl7.fhir.exceptions.FHIRException- FHIR ExceptionIOException- 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:
transformin classorg.hl7.fhir.validation.ValidationEngine- Throws:
org.hl7.fhir.exceptions.FHIRExceptionIOException
-
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.FHIRExceptionIOException
-
addCanonicalResource
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 streamformat- format of resourceprofileUrl- profile to validate against- Returns:
- result as Operation Outcome
- Throws:
org.hl7.fhir.exceptions.FHIRException- FHIR ExceptionIOException- IO Exceptionorg.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 resourceprofileUrl- profile to validate against- Returns:
- Throws:
org.hl7.fhir.exceptions.FHIRException- FHIR ExceptionIOException- IO Exceptionorg.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.FHIRExceptionIOExceptionorg.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:
asSdListin classorg.hl7.fhir.validation.ValidationEngine- Parameters:
profiles- canonical url of profiles (StructureDefinition)- Returns:
- StructureDefintions
- Throws:
Error- if profile cannot be resolved
-
getStructureDefinition
Get the corresponding Struc- Parameters:
profile-- Returns:
-
getCanonicalResource
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:
fetchesCanonicalResourcein interfaceorg.hl7.fhir.r5.utils.validation.IValidatorResourceFetcher- Overrides:
fetchesCanonicalResourcein classorg.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 typeid- 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 ExceptionIOException- 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 againstinputJson- if input format is json or xmlexpression- fhirPath expression- Returns:
- result
- Throws:
org.hl7.fhir.exceptions.FHIRException- FHIR ExceptionIOException- IO Exception
-
loadPackage
Loads an IG in the engine from its NPM package as anInputStream, its ID and version. TheInputStreamwill be closed byNpmPackage.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
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
Adds a Regex pattern to the list of suppressed validation warning/information-level issues.- Parameters:
pattern- The Regex pattern to add.
-
getSuppressedWarnInfoPatterns
Returns the list of suppressed validation warning/information-level issues. -
compileSuppressedWarnInfoPatterns
Compiles the list of suppressed validation warning/information-level issues into a list ofPattern. -
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 ofValidationMessageto an R4OperationOutcome.- Throws:
IOExceptionorg.hl7.fhir.exceptions.FHIRExceptionorg.hl7.fhir.r5.utils.EOperationOutcome
-