asList = null;
+ if (thePerformanceOptions != null) {
+ asList = Arrays.asList(thePerformanceOptions);
+ }
+ setPerformanceOptions(asList);
+ }
+
/**
* Returns the scanned runtime model for the given type. This is an advanced feature which is generally only needed
* for extending the core library.
*/
public RuntimeResourceDefinition getResourceDefinition(final Class extends IBaseResource> theResourceType) {
validateInitialized();
- if (theResourceType == null) {
- throw new NullPointerException("theResourceType can not be null");
- }
+ Validate.notNull(theResourceType, "theResourceType can not be null");
+
if (Modifier.isAbstract(theResourceType.getModifiers())) {
throw new IllegalArgumentException("Can not scan abstract or interface class (resource definitions must be concrete classes): " + theResourceType.getName());
}
@@ -544,16 +562,37 @@ public class FhirContext {
/**
* Returns the validation support module configured for this context, creating a default
- * implementation if no module has been passed in via the {@link #setValidationSupport(IContextValidationSupport)}
+ * implementation if no module has been passed in via the {@link #setValidationSupport(IValidationSupport)}
* method
*
- * @see #setValidationSupport(IContextValidationSupport)
+ * @see #setValidationSupport(IValidationSupport)
*/
- public IContextValidationSupport, ?, ?, ?, ?, ?> getValidationSupport() {
- if (myValidationSupport == null) {
- myValidationSupport = myVersion.createValidationSupport();
+ public IValidationSupport getValidationSupport() {
+ IValidationSupport retVal = myValidationSupport;
+ if (retVal == null) {
+ retVal = new DefaultProfileValidationSupport(this);
+
+ /*
+ * If hapi-fhir-validation is on the classpath, we can create a much more robust
+ * validation chain using the classes found in that package
+ */
+ String inMemoryTermSvcType = "org.hl7.fhir.common.hapi.validation.support.InMemoryTerminologyServerValidationSupport";
+ String commonCodeSystemsSupportType = "org.hl7.fhir.common.hapi.validation.support.CommonCodeSystemsTerminologyService";
+ if (ReflectionUtil.typeExists(inMemoryTermSvcType)) {
+ IValidationSupport inMemoryTermSvc = ReflectionUtil.newInstanceOrReturnNull(inMemoryTermSvcType, IValidationSupport.class, new Class>[]{FhirContext.class}, new Object[]{this});
+ IValidationSupport commonCodeSystemsSupport = ReflectionUtil.newInstanceOrReturnNull(commonCodeSystemsSupportType, IValidationSupport.class, new Class>[]{FhirContext.class}, new Object[]{this});
+ retVal = ReflectionUtil.newInstanceOrReturnNull("org.hl7.fhir.common.hapi.validation.support.ValidationSupportChain", IValidationSupport.class, new Class>[]{IValidationSupport[].class}, new Object[]{new IValidationSupport[]{
+ retVal,
+ inMemoryTermSvc,
+ commonCodeSystemsSupport
+ }});
+ assert retVal != null : "Failed to instantiate " + "org.hl7.fhir.common.hapi.validation.support.ValidationSupportChain";
+ }
+
+
+ myValidationSupport = retVal;
}
- return myValidationSupport;
+ return retVal;
}
/**
@@ -561,7 +600,7 @@ public class FhirContext {
* is used to supply underlying infrastructure such as conformance resources (StructureDefinition, ValueSet, etc)
* as well as to provide terminology services to modules such as the validator and FluentPath executor
*/
- public void setValidationSupport(IContextValidationSupport, ?, ?, ?, ?, ?> theValidationSupport) {
+ public void setValidationSupport(IValidationSupport theValidationSupport) {
myValidationSupport = theValidationSupport;
}
@@ -588,10 +627,10 @@ public class FhirContext {
/**
* Creates a new FluentPath engine which can be used to exvaluate
* path expressions over FHIR resources. Note that this engine will use the
- * {@link IContextValidationSupport context validation support} module which is
+ * {@link IValidationSupport context validation support} module which is
* configured on the context at the time this method is called.
*
- * In other words, call {@link #setValidationSupport(IContextValidationSupport)} before
+ * In other words, call {@link #setValidationSupport(IValidationSupport)} before
* calling {@link #newFluentPath()}
*
*
@@ -642,7 +681,6 @@ public class FhirContext {
return new RDFParser(this, myParserErrorHandler, Lang.TURTLE);
}
-
/**
* Instantiates a new client instance. This method requires an interface which is defined specifically for your use
* cases to contain methods for each of the RESTful operations you wish to implement (e.g. "read ImagingStudy",
@@ -862,19 +900,6 @@ public class FhirContext {
myParserErrorHandler = theParserErrorHandler;
}
- /**
- * Sets the configured performance options
- *
- * @see PerformanceOptionsEnum for a list of available options
- */
- public void setPerformanceOptions(final PerformanceOptionsEnum... thePerformanceOptions) {
- Collection asList = null;
- if (thePerformanceOptions != null) {
- asList = Arrays.asList(thePerformanceOptions);
- }
- setPerformanceOptions(asList);
- }
-
@SuppressWarnings({"cast"})
private List> toElementList(final Collection> theResourceTypes) {
if (theResourceTypes == null) {
diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/FhirVersionEnum.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/FhirVersionEnum.java
index c86822c8639..92d0600a42d 100644
--- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/FhirVersionEnum.java
+++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/FhirVersionEnum.java
@@ -4,7 +4,7 @@ package ca.uhn.fhir.context;
* #%L
* HAPI FHIR - Core Library
* %%
- * Copyright (C) 2014 - 2019 University Health Network
+ * Copyright (C) 2014 - 2020 University Health Network
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -190,7 +190,7 @@ public enum FhirVersionEnum {
Class> c = Class.forName("org.hl7.fhir.dstu3.model.Constants");
myVersion = (String) c.getDeclaredField("VERSION").get(null);
} catch (Exception e) {
- myVersion = "3.0.1";
+ myVersion = "3.0.2";
}
}
@@ -210,7 +210,7 @@ public enum FhirVersionEnum {
Class> c = Class.forName("org.hl7.fhir.r4.model.Constants");
myVersion = (String) c.getDeclaredField("VERSION").get(null);
} catch (Exception e) {
- myVersion = "4.0.0";
+ myVersion = "4.0.2";
}
}
diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/IRuntimeDatatypeDefinition.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/IRuntimeDatatypeDefinition.java
index ed436b512c6..51e401a91a6 100644
--- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/IRuntimeDatatypeDefinition.java
+++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/IRuntimeDatatypeDefinition.java
@@ -7,7 +7,7 @@ import org.hl7.fhir.instance.model.api.IBaseDatatype;
* #%L
* HAPI FHIR - Core Library
* %%
- * Copyright (C) 2014 - 2019 University Health Network
+ * Copyright (C) 2014 - 2020 University Health Network
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/ModelScanner.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/ModelScanner.java
index e5554769f37..31e54b50006 100644
--- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/ModelScanner.java
+++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/ModelScanner.java
@@ -4,7 +4,7 @@ package ca.uhn.fhir.context;
* #%L
* HAPI FHIR - Core Library
* %%
- * Copyright (C) 2014 - 2019 University Health Network
+ * Copyright (C) 2014 - 2020 University Health Network
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/ParserOptions.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/ParserOptions.java
index b2530c58345..901df5dfbc0 100644
--- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/ParserOptions.java
+++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/ParserOptions.java
@@ -4,7 +4,7 @@ package ca.uhn.fhir.context;
* #%L
* HAPI FHIR - Core Library
* %%
- * Copyright (C) 2014 - 2019 University Health Network
+ * Copyright (C) 2014 - 2020 University Health Network
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/PerformanceOptionsEnum.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/PerformanceOptionsEnum.java
index ad3b40ab260..7053a7f6a8a 100644
--- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/PerformanceOptionsEnum.java
+++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/PerformanceOptionsEnum.java
@@ -4,7 +4,7 @@ package ca.uhn.fhir.context;
* #%L
* HAPI FHIR - Core Library
* %%
- * Copyright (C) 2014 - 2019 University Health Network
+ * Copyright (C) 2014 - 2020 University Health Network
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeChildAny.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeChildAny.java
index edbb1e05efd..866464cc9f6 100644
--- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeChildAny.java
+++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeChildAny.java
@@ -4,7 +4,7 @@ package ca.uhn.fhir.context;
* #%L
* HAPI FHIR - Core Library
* %%
- * Copyright (C) 2014 - 2019 University Health Network
+ * Copyright (C) 2014 - 2020 University Health Network
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeChildChoiceDefinition.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeChildChoiceDefinition.java
index 2c39f35ece8..780ee69e4c8 100644
--- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeChildChoiceDefinition.java
+++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeChildChoiceDefinition.java
@@ -4,7 +4,7 @@ package ca.uhn.fhir.context;
* #%L
* HAPI FHIR - Core Library
* %%
- * Copyright (C) 2014 - 2019 University Health Network
+ * Copyright (C) 2014 - 2020 University Health Network
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeChildCompositeBoundDatatypeDefinition.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeChildCompositeBoundDatatypeDefinition.java
index 3bae1009352..fd5677536ad 100644
--- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeChildCompositeBoundDatatypeDefinition.java
+++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeChildCompositeBoundDatatypeDefinition.java
@@ -4,7 +4,7 @@ package ca.uhn.fhir.context;
* #%L
* HAPI FHIR - Core Library
* %%
- * Copyright (C) 2014 - 2019 University Health Network
+ * Copyright (C) 2014 - 2020 University Health Network
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeChildCompositeDatatypeDefinition.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeChildCompositeDatatypeDefinition.java
index 3003bd6aa70..1d43662f6f1 100644
--- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeChildCompositeDatatypeDefinition.java
+++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeChildCompositeDatatypeDefinition.java
@@ -4,7 +4,7 @@ package ca.uhn.fhir.context;
* #%L
* HAPI FHIR - Core Library
* %%
- * Copyright (C) 2014 - 2019 University Health Network
+ * Copyright (C) 2014 - 2020 University Health Network
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeChildContainedResources.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeChildContainedResources.java
index 51c9208523f..1632ab44a70 100644
--- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeChildContainedResources.java
+++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeChildContainedResources.java
@@ -4,7 +4,7 @@ package ca.uhn.fhir.context;
* #%L
* HAPI FHIR - Core Library
* %%
- * Copyright (C) 2014 - 2019 University Health Network
+ * Copyright (C) 2014 - 2020 University Health Network
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeChildDeclaredExtensionDefinition.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeChildDeclaredExtensionDefinition.java
index 44ec4d3834c..d3f141bad09 100644
--- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeChildDeclaredExtensionDefinition.java
+++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeChildDeclaredExtensionDefinition.java
@@ -4,7 +4,7 @@ package ca.uhn.fhir.context;
* #%L
* HAPI FHIR - Core Library
* %%
- * Copyright (C) 2014 - 2019 University Health Network
+ * Copyright (C) 2014 - 2020 University Health Network
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeChildDirectResource.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeChildDirectResource.java
index 47ed6916aa6..40ed06214ef 100644
--- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeChildDirectResource.java
+++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeChildDirectResource.java
@@ -4,7 +4,7 @@ package ca.uhn.fhir.context;
* #%L
* HAPI FHIR - Core Library
* %%
- * Copyright (C) 2014 - 2019 University Health Network
+ * Copyright (C) 2014 - 2020 University Health Network
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeChildExtension.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeChildExtension.java
index a1734ef3deb..35e3bfb60de 100644
--- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeChildExtension.java
+++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeChildExtension.java
@@ -4,7 +4,7 @@ package ca.uhn.fhir.context;
* #%L
* HAPI FHIR - Core Library
* %%
- * Copyright (C) 2014 - 2019 University Health Network
+ * Copyright (C) 2014 - 2020 University Health Network
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeChildNarrativeDefinition.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeChildNarrativeDefinition.java
index 86d4d11f767..6566ca67186 100644
--- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeChildNarrativeDefinition.java
+++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeChildNarrativeDefinition.java
@@ -4,7 +4,7 @@ package ca.uhn.fhir.context;
* #%L
* HAPI FHIR - Core Library
* %%
- * Copyright (C) 2014 - 2019 University Health Network
+ * Copyright (C) 2014 - 2020 University Health Network
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeChildPrimitiveBoundCodeDatatypeDefinition.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeChildPrimitiveBoundCodeDatatypeDefinition.java
index 0efaa40f01e..e3be1b255ab 100644
--- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeChildPrimitiveBoundCodeDatatypeDefinition.java
+++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeChildPrimitiveBoundCodeDatatypeDefinition.java
@@ -4,7 +4,7 @@ package ca.uhn.fhir.context;
* #%L
* HAPI FHIR - Core Library
* %%
- * Copyright (C) 2014 - 2019 University Health Network
+ * Copyright (C) 2014 - 2020 University Health Network
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeChildPrimitiveDatatypeDefinition.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeChildPrimitiveDatatypeDefinition.java
index 61cb14d4546..1383e597505 100644
--- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeChildPrimitiveDatatypeDefinition.java
+++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeChildPrimitiveDatatypeDefinition.java
@@ -4,7 +4,7 @@ package ca.uhn.fhir.context;
* #%L
* HAPI FHIR - Core Library
* %%
- * Copyright (C) 2014 - 2019 University Health Network
+ * Copyright (C) 2014 - 2020 University Health Network
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeChildPrimitiveEnumerationDatatypeDefinition.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeChildPrimitiveEnumerationDatatypeDefinition.java
index 6468439c982..01cdb367799 100644
--- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeChildPrimitiveEnumerationDatatypeDefinition.java
+++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeChildPrimitiveEnumerationDatatypeDefinition.java
@@ -4,7 +4,7 @@ package ca.uhn.fhir.context;
* #%L
* HAPI FHIR - Core Library
* %%
- * Copyright (C) 2014 - 2019 University Health Network
+ * Copyright (C) 2014 - 2020 University Health Network
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeChildResourceBlockDefinition.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeChildResourceBlockDefinition.java
index e4882faee54..2c45a2b78ea 100644
--- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeChildResourceBlockDefinition.java
+++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeChildResourceBlockDefinition.java
@@ -4,7 +4,7 @@ package ca.uhn.fhir.context;
* #%L
* HAPI FHIR - Core Library
* %%
- * Copyright (C) 2014 - 2019 University Health Network
+ * Copyright (C) 2014 - 2020 University Health Network
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeChildResourceDefinition.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeChildResourceDefinition.java
index 1ff9f49e9af..10dfa1fbbb1 100644
--- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeChildResourceDefinition.java
+++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeChildResourceDefinition.java
@@ -4,7 +4,7 @@ package ca.uhn.fhir.context;
* #%L
* HAPI FHIR - Core Library
* %%
- * Copyright (C) 2014 - 2019 University Health Network
+ * Copyright (C) 2014 - 2020 University Health Network
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeChildUndeclaredExtensionDefinition.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeChildUndeclaredExtensionDefinition.java
index 06ed342f512..d59538db803 100644
--- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeChildUndeclaredExtensionDefinition.java
+++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeChildUndeclaredExtensionDefinition.java
@@ -4,7 +4,7 @@ package ca.uhn.fhir.context;
* #%L
* HAPI FHIR - Core Library
* %%
- * Copyright (C) 2014 - 2019 University Health Network
+ * Copyright (C) 2014 - 2020 University Health Network
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeCompositeDatatypeDefinition.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeCompositeDatatypeDefinition.java
index 9c74ab42943..88417fa6a24 100644
--- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeCompositeDatatypeDefinition.java
+++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeCompositeDatatypeDefinition.java
@@ -4,7 +4,7 @@ package ca.uhn.fhir.context;
* #%L
* HAPI FHIR - Core Library
* %%
- * Copyright (C) 2014 - 2019 University Health Network
+ * Copyright (C) 2014 - 2020 University Health Network
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeElemContainedResourceList.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeElemContainedResourceList.java
index 7fe75bd697f..38af8284168 100644
--- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeElemContainedResourceList.java
+++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeElemContainedResourceList.java
@@ -4,7 +4,7 @@ package ca.uhn.fhir.context;
* #%L
* HAPI FHIR - Core Library
* %%
- * Copyright (C) 2014 - 2019 University Health Network
+ * Copyright (C) 2014 - 2020 University Health Network
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeElemContainedResources.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeElemContainedResources.java
index 0f759cc73c6..ba22b6085ef 100644
--- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeElemContainedResources.java
+++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeElemContainedResources.java
@@ -4,7 +4,7 @@ package ca.uhn.fhir.context;
* #%L
* HAPI FHIR - Core Library
* %%
- * Copyright (C) 2014 - 2019 University Health Network
+ * Copyright (C) 2014 - 2020 University Health Network
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeElementDirectResource.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeElementDirectResource.java
index 7d69ece0f0d..8cfd145a6cb 100644
--- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeElementDirectResource.java
+++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeElementDirectResource.java
@@ -4,7 +4,7 @@ package ca.uhn.fhir.context;
* #%L
* HAPI FHIR - Core Library
* %%
- * Copyright (C) 2014 - 2019 University Health Network
+ * Copyright (C) 2014 - 2020 University Health Network
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeExtensionDtDefinition.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeExtensionDtDefinition.java
index cfc8df5e087..585f9088784 100644
--- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeExtensionDtDefinition.java
+++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeExtensionDtDefinition.java
@@ -4,7 +4,7 @@ package ca.uhn.fhir.context;
* #%L
* HAPI FHIR - Core Library
* %%
- * Copyright (C) 2014 - 2019 University Health Network
+ * Copyright (C) 2014 - 2020 University Health Network
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeIdDatatypeDefinition.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeIdDatatypeDefinition.java
index ab470575381..968de942d9c 100644
--- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeIdDatatypeDefinition.java
+++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeIdDatatypeDefinition.java
@@ -4,7 +4,7 @@ package ca.uhn.fhir.context;
* #%L
* HAPI FHIR - Core Library
* %%
- * Copyright (C) 2014 - 2019 University Health Network
+ * Copyright (C) 2014 - 2020 University Health Network
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimePrimitiveDatatypeDefinition.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimePrimitiveDatatypeDefinition.java
index b50a8a33516..287cf0aead9 100644
--- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimePrimitiveDatatypeDefinition.java
+++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimePrimitiveDatatypeDefinition.java
@@ -4,7 +4,7 @@ package ca.uhn.fhir.context;
* #%L
* HAPI FHIR - Core Library
* %%
- * Copyright (C) 2014 - 2019 University Health Network
+ * Copyright (C) 2014 - 2020 University Health Network
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimePrimitiveDatatypeNarrativeDefinition.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimePrimitiveDatatypeNarrativeDefinition.java
index f649d112805..4f3f3f188bf 100644
--- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimePrimitiveDatatypeNarrativeDefinition.java
+++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimePrimitiveDatatypeNarrativeDefinition.java
@@ -4,7 +4,7 @@ package ca.uhn.fhir.context;
* #%L
* HAPI FHIR - Core Library
* %%
- * Copyright (C) 2014 - 2019 University Health Network
+ * Copyright (C) 2014 - 2020 University Health Network
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimePrimitiveDatatypeXhtmlHl7OrgDefinition.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimePrimitiveDatatypeXhtmlHl7OrgDefinition.java
index c5d99fa7740..7987e3e5924 100644
--- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimePrimitiveDatatypeXhtmlHl7OrgDefinition.java
+++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimePrimitiveDatatypeXhtmlHl7OrgDefinition.java
@@ -4,7 +4,7 @@ package ca.uhn.fhir.context;
* #%L
* HAPI FHIR - Core Library
* %%
- * Copyright (C) 2014 - 2019 University Health Network
+ * Copyright (C) 2014 - 2020 University Health Network
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeResourceBlockDefinition.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeResourceBlockDefinition.java
index d7983895f91..f21157cab78 100644
--- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeResourceBlockDefinition.java
+++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeResourceBlockDefinition.java
@@ -6,7 +6,7 @@ import java.util.Map;
* #%L
* HAPI FHIR - Core Library
* %%
- * Copyright (C) 2014 - 2019 University Health Network
+ * Copyright (C) 2014 - 2020 University Health Network
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeResourceDefinition.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeResourceDefinition.java
index 273060db8f1..bd8a538121f 100644
--- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeResourceDefinition.java
+++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeResourceDefinition.java
@@ -4,7 +4,7 @@ package ca.uhn.fhir.context;
* #%L
* HAPI FHIR - Core Library
* %%
- * Copyright (C) 2014 - 2019 University Health Network
+ * Copyright (C) 2014 - 2020 University Health Network
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeSearchParam.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeSearchParam.java
index 5ce2dd6594f..c7312354925 100644
--- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeSearchParam.java
+++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeSearchParam.java
@@ -27,7 +27,7 @@ import static org.apache.commons.lang3.StringUtils.trim;
* #%L
* HAPI FHIR - Core Library
* %%
- * Copyright (C) 2014 - 2019 University Health Network
+ * Copyright (C) 2014 - 2020 University Health Network
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/api/AddProfileTagEnum.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/api/AddProfileTagEnum.java
index 4e23a50c1b7..72a1111a5ec 100644
--- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/api/AddProfileTagEnum.java
+++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/api/AddProfileTagEnum.java
@@ -6,7 +6,7 @@ import ca.uhn.fhir.context.FhirContext;
* #%L
* HAPI FHIR - Core Library
* %%
- * Copyright (C) 2014 - 2019 University Health Network
+ * Copyright (C) 2014 - 2020 University Health Network
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/api/BundleInclusionRule.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/api/BundleInclusionRule.java
index 34194885f2c..0a46a6ba521 100644
--- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/api/BundleInclusionRule.java
+++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/api/BundleInclusionRule.java
@@ -4,7 +4,7 @@ package ca.uhn.fhir.context.api;
* #%L
* HAPI FHIR - Core Library
* %%
- * Copyright (C) 2014 - 2019 University Health Network
+ * Copyright (C) 2014 - 2020 University Health Network
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/support/ConceptValidationOptions.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/support/ConceptValidationOptions.java
new file mode 100644
index 00000000000..7d1d3f2d135
--- /dev/null
+++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/support/ConceptValidationOptions.java
@@ -0,0 +1,36 @@
+package ca.uhn.fhir.context.support;
+
+/*-
+ * #%L
+ * HAPI FHIR - Core Library
+ * %%
+ * Copyright (C) 2014 - 2020 University Health Network
+ * %%
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * #L%
+ */
+
+public class ConceptValidationOptions {
+
+ public boolean isInferSystem() {
+ return myInferSystem;
+ }
+
+ public ConceptValidationOptions setInferSystem(boolean theInferSystem) {
+ myInferSystem = theInferSystem;
+ return this;
+ }
+
+ private boolean myInferSystem;
+
+}
diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/support/DefaultProfileValidationSupport.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/support/DefaultProfileValidationSupport.java
new file mode 100644
index 00000000000..3498ac29df0
--- /dev/null
+++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/support/DefaultProfileValidationSupport.java
@@ -0,0 +1,354 @@
+package ca.uhn.fhir.context.support;
+
+/*-
+ * #%L
+ * HAPI FHIR - Core Library
+ * %%
+ * Copyright (C) 2014 - 2020 University Health Network
+ * %%
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * #L%
+ */
+
+import ca.uhn.fhir.context.ConfigurationException;
+import ca.uhn.fhir.context.FhirContext;
+import ca.uhn.fhir.context.RuntimeResourceDefinition;
+import ca.uhn.fhir.rest.api.Constants;
+import ca.uhn.fhir.util.BundleUtil;
+import org.apache.commons.lang3.StringUtils;
+import org.hl7.fhir.instance.model.api.IBase;
+import org.hl7.fhir.instance.model.api.IBaseBundle;
+import org.hl7.fhir.instance.model.api.IBaseResource;
+import org.hl7.fhir.instance.model.api.IPrimitiveType;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import java.util.Properties;
+
+import static org.apache.commons.lang3.StringUtils.isNotBlank;
+
+public class DefaultProfileValidationSupport implements IValidationSupport {
+
+ private static final String URL_PREFIX_STRUCTURE_DEFINITION = "http://hl7.org/fhir/StructureDefinition/";
+ private static final String URL_PREFIX_STRUCTURE_DEFINITION_BASE = "http://hl7.org/fhir/";
+ private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(DefaultProfileValidationSupport.class);
+ private final FhirContext myCtx;
+
+ private Map myCodeSystems;
+ private Map myStructureDefinitions;
+ private Map myValueSets;
+ private List myTerminologyResources;
+ private List myStructureDefinitionResources;
+
+ /**
+ * Constructor
+ *
+ * @param theFhirContext The context to use
+ */
+ public DefaultProfileValidationSupport(FhirContext theFhirContext) {
+ myCtx = theFhirContext;
+ }
+
+
+ private void initializeResourceLists() {
+
+ if (myTerminologyResources != null && myStructureDefinitionResources != null) {
+ return;
+ }
+
+ List terminologyResources = new ArrayList<>();
+ List structureDefinitionResources = new ArrayList<>();
+ switch (getFhirContext().getVersion().getVersion()) {
+ case DSTU2:
+ case DSTU2_HL7ORG:
+ terminologyResources.add("/org/hl7/fhir/instance/model/valueset/valuesets.xml");
+ terminologyResources.add("/org/hl7/fhir/instance/model/valueset/v2-tables.xml");
+ terminologyResources.add("/org/hl7/fhir/instance/model/valueset/v3-codesystems.xml");
+ Properties profileNameProperties = new Properties();
+ try {
+ profileNameProperties.load(DefaultProfileValidationSupport.class.getResourceAsStream("/org/hl7/fhir/instance/model/profile/profiles.properties"));
+ for (Object nextKey : profileNameProperties.keySet()) {
+ structureDefinitionResources.add("/org/hl7/fhir/instance/model/profile/" + nextKey);
+ }
+ } catch (IOException e) {
+ throw new ConfigurationException(e);
+ }
+ break;
+ case DSTU2_1:
+ terminologyResources.add("/org/hl7/fhir/dstu2016may/model/valueset/valuesets.xml");
+ terminologyResources.add("/org/hl7/fhir/dstu2016may/model/valueset/v2-tables.xml");
+ terminologyResources.add("/org/hl7/fhir/dstu2016may/model/valueset/v3-codesystems.xml");
+ structureDefinitionResources.add("/org/hl7/fhir/dstu2016may/model/profile/profiles-resources.xml");
+ structureDefinitionResources.add("/org/hl7/fhir/dstu2016may/model/profile/profiles-types.xml");
+ structureDefinitionResources.add("/org/hl7/fhir/dstu2016may/model/profile/profiles-others.xml");
+ break;
+ case DSTU3:
+ terminologyResources.add("/org/hl7/fhir/dstu3/model/valueset/valuesets.xml");
+ terminologyResources.add("/org/hl7/fhir/dstu3/model/valueset/v2-tables.xml");
+ terminologyResources.add("/org/hl7/fhir/dstu3/model/valueset/v3-codesystems.xml");
+ structureDefinitionResources.add("/org/hl7/fhir/dstu3/model/profile/profiles-resources.xml");
+ structureDefinitionResources.add("/org/hl7/fhir/dstu3/model/profile/profiles-types.xml");
+ structureDefinitionResources.add("/org/hl7/fhir/dstu3/model/profile/profiles-others.xml");
+ structureDefinitionResources.add("/org/hl7/fhir/dstu3/model/extension/extension-definitions.xml");
+ break;
+ case R4:
+ terminologyResources.add("/org/hl7/fhir/r4/model/valueset/valuesets.xml");
+ terminologyResources.add("/org/hl7/fhir/r4/model/valueset/v2-tables.xml");
+ terminologyResources.add("/org/hl7/fhir/r4/model/valueset/v3-codesystems.xml");
+ structureDefinitionResources.add("/org/hl7/fhir/r4/model/profile/profiles-resources.xml");
+ structureDefinitionResources.add("/org/hl7/fhir/r4/model/profile/profiles-types.xml");
+ structureDefinitionResources.add("/org/hl7/fhir/r4/model/profile/profiles-others.xml");
+ structureDefinitionResources.add("/org/hl7/fhir/r4/model/extension/extension-definitions.xml");
+ break;
+ case R5:
+ structureDefinitionResources.add("/org/hl7/fhir/r5/model/profile/profiles-resources.xml");
+ structureDefinitionResources.add("/org/hl7/fhir/r5/model/profile/profiles-types.xml");
+ structureDefinitionResources.add("/org/hl7/fhir/r5/model/profile/profiles-others.xml");
+ structureDefinitionResources.add("/org/hl7/fhir/r5/model/extension/extension-definitions.xml");
+ terminologyResources.add("/org/hl7/fhir/r5/model/valueset/valuesets.xml");
+ terminologyResources.add("/org/hl7/fhir/r5/model/valueset/v2-tables.xml");
+ terminologyResources.add("/org/hl7/fhir/r5/model/valueset/v3-codesystems.xml");
+ break;
+ }
+
+ myTerminologyResources = terminologyResources;
+ myStructureDefinitionResources = structureDefinitionResources;
+ }
+
+
+ @Override
+ public List fetchAllConformanceResources() {
+ ArrayList retVal = new ArrayList<>();
+ retVal.addAll(myCodeSystems.values());
+ retVal.addAll(myStructureDefinitions.values());
+ retVal.addAll(myValueSets.values());
+ return retVal;
+ }
+
+ @Override
+ public List fetchAllStructureDefinitions() {
+ return toList(provideStructureDefinitionMap());
+ }
+
+
+ @Override
+ public IBaseResource fetchCodeSystem(String theSystem) {
+ return fetchCodeSystemOrValueSet(theSystem, true);
+ }
+
+ private IBaseResource fetchCodeSystemOrValueSet(String theSystem, boolean codeSystem) {
+ synchronized (this) {
+ Map codeSystems = myCodeSystems;
+ Map valueSets = myValueSets;
+ if (codeSystems == null || valueSets == null) {
+ codeSystems = new HashMap<>();
+ valueSets = new HashMap<>();
+
+ initializeResourceLists();
+ for (String next : myTerminologyResources) {
+ loadCodeSystems(codeSystems, valueSets, next);
+ }
+
+ myCodeSystems = codeSystems;
+ myValueSets = valueSets;
+ }
+
+ // System can take the form "http://url|version"
+ String system = theSystem;
+ if (system.contains("|")) {
+ String version = system.substring(system.indexOf('|') + 1);
+ if (version.matches("^[0-9.]+$")) {
+ system = system.substring(0, system.indexOf('|'));
+ }
+ }
+
+ if (codeSystem) {
+ return codeSystems.get(system);
+ } else {
+ return valueSets.get(system);
+ }
+ }
+ }
+
+ @Override
+ public IBaseResource fetchStructureDefinition(String theUrl) {
+ String url = theUrl;
+ if (url.startsWith(URL_PREFIX_STRUCTURE_DEFINITION)) {
+ // no change
+ } else if (url.indexOf('/') == -1) {
+ url = URL_PREFIX_STRUCTURE_DEFINITION + url;
+ } else if (StringUtils.countMatches(url, '/') == 1) {
+ url = URL_PREFIX_STRUCTURE_DEFINITION_BASE + url;
+ }
+ Map structureDefinitionMap = provideStructureDefinitionMap();
+ IBaseResource retVal = structureDefinitionMap.get(url);
+ return retVal;
+ }
+
+ @Override
+ public IBaseResource fetchValueSet(String theUrl) {
+ IBaseResource retVal = fetchCodeSystemOrValueSet(theUrl, false);
+ return retVal;
+ }
+
+ public void flush() {
+ myCodeSystems = null;
+ myStructureDefinitions = null;
+ }
+
+ @Override
+ public FhirContext getFhirContext() {
+ return myCtx;
+ }
+
+ private Map provideStructureDefinitionMap() {
+ Map structureDefinitions = myStructureDefinitions;
+ if (structureDefinitions == null) {
+ structureDefinitions = new HashMap<>();
+
+ initializeResourceLists();
+ for (String next : myStructureDefinitionResources) {
+ loadStructureDefinitions(structureDefinitions, next);
+ }
+
+ myStructureDefinitions = structureDefinitions;
+ }
+ return structureDefinitions;
+ }
+
+ private void loadCodeSystems(Map theCodeSystems, Map theValueSets, String theClasspath) {
+ ourLog.info("Loading CodeSystem/ValueSet from classpath: {}", theClasspath);
+ InputStream inputStream = DefaultProfileValidationSupport.class.getResourceAsStream(theClasspath);
+ InputStreamReader reader = null;
+ if (inputStream != null) {
+ try {
+ reader = new InputStreamReader(inputStream, Constants.CHARSET_UTF8);
+ List resources = parseBundle(reader);
+ for (IBaseResource next : resources) {
+
+ RuntimeResourceDefinition nextDef = getFhirContext().getResourceDefinition(next);
+ Map map = null;
+ switch (nextDef.getName()) {
+ case "CodeSystem":
+ map = theCodeSystems;
+ break;
+ case "ValueSet":
+ map = theValueSets;
+ break;
+ }
+
+ if (map != null) {
+ String urlValueString = getConformanceResourceUrl(next);
+ if (isNotBlank(urlValueString)) {
+ map.put(urlValueString, next);
+ }
+
+ switch (myCtx.getVersion().getVersion()) {
+ case DSTU2:
+ case DSTU2_HL7ORG:
+
+ IPrimitiveType> codeSystem = myCtx.newTerser().getSingleValueOrNull(next, "ValueSet.codeSystem.system", IPrimitiveType.class);
+ if (codeSystem != null && isNotBlank(codeSystem.getValueAsString())) {
+ theCodeSystems.put(codeSystem.getValueAsString(), next);
+ }
+
+ break;
+
+ default:
+ case DSTU2_1:
+ case DSTU3:
+ case R4:
+ case R5:
+ break;
+ }
+ }
+
+
+ }
+ } finally {
+ try {
+ if (reader != null) {
+ reader.close();
+ }
+ inputStream.close();
+ } catch (IOException e) {
+ ourLog.warn("Failure closing stream", e);
+ }
+ }
+ } else {
+ ourLog.warn("Unable to load resource: {}", theClasspath);
+ }
+ }
+
+ private void loadStructureDefinitions(Map theCodeSystems, String theClasspath) {
+ ourLog.info("Loading structure definitions from classpath: {}", theClasspath);
+ try (InputStream valuesetText = DefaultProfileValidationSupport.class.getResourceAsStream(theClasspath)) {
+ if (valuesetText != null) {
+ try (InputStreamReader reader = new InputStreamReader(valuesetText, Constants.CHARSET_UTF8)) {
+
+ List resources = parseBundle(reader);
+ for (IBaseResource next : resources) {
+
+ String nextType = getFhirContext().getResourceDefinition(next).getName();
+ if ("StructureDefinition".equals(nextType)) {
+
+ String url = getConformanceResourceUrl(next);
+ if (isNotBlank(url)) {
+ theCodeSystems.put(url, next);
+ }
+
+ }
+
+ }
+ }
+ } else {
+ ourLog.warn("Unable to load resource: {}", theClasspath);
+ }
+ } catch (IOException theE) {
+ ourLog.warn("Unable to load resource: {}", theClasspath);
+ }
+ }
+
+ private String getConformanceResourceUrl(IBaseResource theResource) {
+ String urlValueString = null;
+ Optional urlValue = getFhirContext().getResourceDefinition(theResource).getChildByName("url").getAccessor().getFirstValueOrNull(theResource);
+ if (urlValue.isPresent()) {
+ IPrimitiveType> urlValueType = (IPrimitiveType>) urlValue.get();
+ urlValueString = urlValueType.getValueAsString();
+ }
+ return urlValueString;
+ }
+
+ private List parseBundle(InputStreamReader theReader) {
+ IBaseResource parsedObject = getFhirContext().newXmlParser().parseResource(theReader);
+ if (parsedObject instanceof IBaseBundle) {
+ IBaseBundle bundle = (IBaseBundle) parsedObject;
+ return BundleUtil.toListOfResources(getFhirContext(), bundle);
+ } else {
+ return Collections.singletonList(parsedObject);
+ }
+ }
+
+ static List toList(Map theMap) {
+ ArrayList retVal = new ArrayList<>(theMap.values());
+ return (List) Collections.unmodifiableList(retVal);
+ }
+
+}
diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/support/IContextValidationSupport.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/support/IValidationSupport.java
similarity index 50%
rename from hapi-fhir-base/src/main/java/ca/uhn/fhir/context/support/IContextValidationSupport.java
rename to hapi-fhir-base/src/main/java/ca/uhn/fhir/context/support/IValidationSupport.java
index 0dabbd54e7f..fc5089e2163 100644
--- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/support/IContextValidationSupport.java
+++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/support/IValidationSupport.java
@@ -4,7 +4,7 @@ package ca.uhn.fhir.context.support;
* #%L
* HAPI FHIR - Core Library
* %%
- * Copyright (C) 2014 - 2019 University Health Network
+ * Copyright (C) 2014 - 2020 University Health Network
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -23,12 +23,14 @@ package ca.uhn.fhir.context.support;
import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException;
import ca.uhn.fhir.util.ParametersUtil;
+import org.apache.commons.lang3.Validate;
import org.hl7.fhir.instance.model.api.IBase;
import org.hl7.fhir.instance.model.api.IBaseParameters;
import org.hl7.fhir.instance.model.api.IBaseResource;
import org.hl7.fhir.instance.model.api.IPrimitiveType;
import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
@@ -42,33 +44,63 @@ import static org.apache.commons.lang3.StringUtils.isNotBlank;
* various functions that can be provided by validation and terminology
* services.
*
+ * This interface is invoked directly by internal parts of the HAPI FHIR API, including the
+ * Validator and the FHIRPath evaluator. It is used to supply artifacts required for validation
+ * (e.g. StructureDefinition resources, ValueSet resources, etc.) and also to provide
+ * terminology functions such as code validation, ValueSet expansion, etc.
+ *
+ *
* Implementations are not required to implement all of the functions
* in this interface; in fact it is expected that most won't. Any
* methods which are not implemented may simply return null
- * and calling code is expected to be able to handle this.
+ * and calling code is expected to be able to handle this. Generally, a
+ * series of implementations of this interface will be joined together using
+ * the
+ * ValidationSupportChain
+ * class.
*
+ *
+ * See Validation Support Modules
+ * for information on how to assemble and configure implementations of this interface. See also
+ * the org.hl7.fhir.common.hapi.validation.support
+ * package summary
+ * in the hapi-fhir-validation
module for many implementations of this interface.
+ *
+ *
+ * @since 5.0.0
*/
-public interface IContextValidationSupport {
+public interface IValidationSupport {
+ String URL_PREFIX_VALUE_SET = "http://hl7.org/fhir/ValueSet/";
+
/**
* Expands the given portion of a ValueSet
*
- * @param theInclude The portion to include
- * @return The expansion
+ * @param theRootValidationSupport The validation support module will be passed in to this method. This is convenient in cases where the operation needs to make calls to
+ * other method in the support chain, so that they can be passed through the entire chain. Implementations of this interface may always safely ignore this parameter.
+ * @param theExpansionOptions If provided (may be null
), contains options controlling the expansion
+ * @param theValueSetToExpand The valueset that should be expanded
+ * @return The expansion, or null
*/
- EVS_OUT expandValueSet(FhirContext theContext, EVS_IN theInclude);
+ default ValueSetExpansionOutcome expandValueSet(IValidationSupport theRootValidationSupport, @Nullable ValueSetExpansionOptions theExpansionOptions, @Nonnull IBaseResource theValueSetToExpand) {
+ return null;
+ }
/**
* Load and return all conformance resources associated with this
* validation support module. This method may return null if it doesn't
* make sense for a given module.
*/
- List fetchAllConformanceResources(FhirContext theContext);
+ default List fetchAllConformanceResources() {
+ return null;
+ }
/**
* Load and return all possible structure definitions
*/
- List fetchAllStructureDefinitions(FhirContext theContext);
+ default List fetchAllStructureDefinitions() {
+ return null;
+ }
/**
* Fetch a code system by ID
@@ -76,70 +108,146 @@ public interface IContextValidationSupport
* @param theSystem The code system
* @return The valueset (must not be null, but can be an empty ValueSet)
*/
- CST fetchCodeSystem(FhirContext theContext, String theSystem);
+ default IBaseResource fetchCodeSystem(String theSystem) {
+ return null;
+ }
/**
* Loads a resource needed by the validation (a StructureDefinition, or a
* ValueSet)
*
- * @param theContext The HAPI FHIR Context object current in use by the validator
- * @param theClass The type of the resource to load
- * @param theUri The resource URI
+ * @param theClass The type of the resource to load
+ * @param theUri The resource URI
* @return Returns the resource, or null
if no resource with the
* given URI can be found
*/
- T fetchResource(FhirContext theContext, Class theClass, String theUri);
+ default T fetchResource(Class theClass, String theUri) {
+ Validate.notNull(theClass, "theClass must not be null or blank");
+ Validate.notBlank(theUri, "theUri must not be null or blank");
- SDT fetchStructureDefinition(FhirContext theCtx, String theUrl);
+ switch (getFhirContext().getResourceDefinition(theClass).getName()) {
+ case "StructureDefinition":
+ return theClass.cast(fetchStructureDefinition(theUri));
+ case "ValueSet":
+ return theClass.cast(fetchValueSet(theUri));
+ case "CodeSystem":
+ return theClass.cast(fetchCodeSystem(theUri));
+ }
+
+ if (theUri.startsWith(URL_PREFIX_VALUE_SET)) {
+ return theClass.cast(fetchValueSet(theUri));
+ }
+
+ return null;
+ }
+
+ default IBaseResource fetchStructureDefinition(String theUrl) {
+ return null;
+ }
/**
* Returns true
if codes in the given code system can be expanded
* or validated
*
- * @param theSystem The URI for the code system, e.g. "http://loinc.org"
+ * @param theRootValidationSupport The validation support module will be passed in to this method. This is convenient in cases where the operation needs to make calls to
+ * other method in the support chain, so that they can be passed through the entire chain. Implementations of this interface may always safely ignore this parameter.
+ * @param theSystem The URI for the code system, e.g. "http://loinc.org"
* @return Returns true
if codes in the given code system can be
* validated
*/
- boolean isCodeSystemSupported(FhirContext theContext, String theSystem);
+ default boolean isCodeSystemSupported(IValidationSupport theRootValidationSupport, String theSystem) {
+ return false;
+ }
/**
* Fetch the given ValueSet by URL
*/
- IBaseResource fetchValueSet(FhirContext theContext, String theValueSetUrl);
+ default IBaseResource fetchValueSet(String theValueSetUrl) {
+ return null;
+ }
/**
* Validates that the given code exists and if possible returns a display
* name. This method is called to check codes which are found in "example"
* binding fields (e.g. Observation.code
in the default profile.
*
- * @param theCodeSystem The code system, e.g. "http://loinc.org
"
- * @param theCode The code, e.g. "1234-5
"
- * @param theDisplay The display name, if it should also be validated
+ * @param theRootValidationSupport The validation support module will be passed in to this method. This is convenient in cases where the operation needs to make calls to
+ * other method in the support chain, so that they can be passed through the entire chain. Implementations of this interface may always safely ignore this parameter.
+ * @param theOptions Provides options controlling the validation
+ * @param theCodeSystem The code system, e.g. "http://loinc.org
"
+ * @param theCode The code, e.g. "1234-5
"
+ * @param theDisplay The display name, if it should also be validated
* @return Returns a validation result object
*/
- CodeValidationResult validateCode(FhirContext theContext, String theCodeSystem, String theCode, String theDisplay, String theValueSetUrl);
+ default CodeValidationResult validateCode(IValidationSupport theRootValidationSupport, ConceptValidationOptions theOptions, String theCodeSystem, String theCode, String theDisplay, String theValueSetUrl) {
+ return null;
+ }
/**
* Validates that the given code exists and if possible returns a display
* name. This method is called to check codes which are found in "example"
* binding fields (e.g. Observation.code
in the default profile.
*
- * @param theCodeSystem The code system, e.g. "http://loinc.org
"
- * @param theCode The code, e.g. "1234-5
"
- * @param theDisplay The display name, if it should also be validated
- * @param theValueSet The ValueSet to validate against. Must not be null, and must be a ValueSet resource.
+ * @param theRootValidationSupport The validation support module will be passed in to this method. This is convenient in cases where the operation needs to make calls to
+ * other method in the support chain, so that they can be passed through the entire chain. Implementations of this interface may always safely ignore this parameter.
+ * @param theCodeSystem The code system, e.g. "http://loinc.org
"
+ * @param theCode The code, e.g. "1234-5
"
+ * @param theDisplay The display name, if it should also be validated
+ * @param theValueSet The ValueSet to validate against. Must not be null, and must be a ValueSet resource.
* @return Returns a validation result object, or null
if this validation support module can not handle this kind of request
*/
- default CodeValidationResult validateCodeInValueSet(FhirContext theContext, String theCodeSystem, String theCode, String theDisplay, @Nonnull IBaseResource theValueSet) { return null; }
+ default CodeValidationResult validateCodeInValueSet(IValidationSupport theRootValidationSupport, ConceptValidationOptions theOptions, String theCodeSystem, String theCode, String theDisplay, @Nonnull IBaseResource theValueSet) {
+ return null;
+ }
/**
* Look up a code using the system and code value
*
- * @param theContext The FHIR context
- * @param theSystem The CodeSystem URL
- * @param theCode The code
+ * @param theRootValidationSupport The validation support module will be passed in to this method. This is convenient in cases where the operation needs to make calls to
+ * other method in the support chain, so that they can be passed through the entire chain. Implementations of this interface may always safely ignore this parameter.
+ * @param theSystem The CodeSystem URL
+ * @param theCode The code
*/
- LookupCodeResult lookupCode(FhirContext theContext, String theSystem, String theCode);
+ default LookupCodeResult lookupCode(IValidationSupport theRootValidationSupport, String theSystem, String theCode) {
+ return null;
+ }
+
+ /**
+ * Returns true
if the given valueset can be validated by the given
+ * validation support module
+ *
+ * @param theRootValidationSupport The validation support module will be passed in to this method. This is convenient in cases where the operation needs to make calls to
+ * other method in the support chain, so that they can be passed through the entire chain. Implementations of this interface may always safely ignore this parameter.
+ * @param theValueSetUrl The ValueSet canonical URL
+ */
+ default boolean isValueSetSupported(IValidationSupport theRootValidationSupport, String theValueSetUrl) {
+ return false;
+ }
+
+ /**
+ * Generate a snapshot from the given differential profile.
+ *
+ * @param theRootValidationSupport The validation support module will be passed in to this method. This is convenient in cases where the operation needs to make calls to
+ * other method in the support chain, so that they can be passed through the entire chain. Implementations of this interface may always safely ignore this parameter.
+ * @return Returns null if this module does not know how to handle this request
+ */
+ default IBaseResource generateSnapshot(IValidationSupport theRootValidationSupport, IBaseResource theInput, String theUrl, String theWebUrl, String theProfileName) {
+ return null;
+ }
+
+ /**
+ * Returns the FHIR Context associated with this module
+ */
+ FhirContext getFhirContext();
+
+ /**
+ * This method clears any temporary caches within the validation support. It is mainly intended for unit tests,
+ * but could be used in non-test scenarios as well.
+ */
+ default void invalidateCaches() {
+ // nothing
+ }
+
class ConceptDesignation {
private String myLanguage;
@@ -257,59 +365,83 @@ public interface IContextValidationSupport
}
}
+ enum IssueSeverity {
+ /**
+ * The issue caused the action to fail, and no further checking could be performed.
+ */
+ FATAL,
+ /**
+ * The issue is sufficiently important to cause the action to fail.
+ */
+ ERROR,
+ /**
+ * The issue is not important enough to cause the action to fail, but may cause it to be performed suboptimally or in a way that is not as desired.
+ */
+ WARNING,
+ /**
+ * The issue has no relation to the degree of success of the action.
+ */
+ INFORMATION
+ }
+
class CodeValidationResult {
- private IBase myDefinition;
+ private String myCode;
private String myMessage;
- private Enum mySeverity;
+ private IssueSeverity mySeverity;
private String myCodeSystemName;
private String myCodeSystemVersion;
private List