From 3cf3f7d5d6180d98ad184b524646fb6432e8058f Mon Sep 17 00:00:00 2001 From: Anthony Sute Date: Mon, 6 Aug 2018 12:50:50 -0400 Subject: [PATCH 1/4] Fixes for issue #1048. FhirInstanceValidator::validate() now looking in meta/profile section of request prior to calling InstanceValidator::validate(). --- .../validation/FhirInstanceValidator.java | 94 +++++++++++++++---- 1 file changed, 75 insertions(+), 19 deletions(-) diff --git a/hapi-fhir-validation/src/main/java/org/hl7/fhir/dstu3/hapi/validation/FhirInstanceValidator.java b/hapi-fhir-validation/src/main/java/org/hl7/fhir/dstu3/hapi/validation/FhirInstanceValidator.java index 15ffcf08901..002023e6f0c 100644 --- a/hapi-fhir-validation/src/main/java/org/hl7/fhir/dstu3/hapi/validation/FhirInstanceValidator.java +++ b/hapi-fhir-validation/src/main/java/org/hl7/fhir/dstu3/hapi/validation/FhirInstanceValidator.java @@ -11,6 +11,8 @@ import com.github.benmanes.caffeine.cache.Caffeine; import com.github.benmanes.caffeine.cache.LoadingCache; import com.google.gson.Gson; import com.google.gson.GsonBuilder; +import com.google.gson.JsonArray; +import com.google.gson.JsonElement; import com.google.gson.JsonObject; import org.apache.commons.lang3.Validate; import org.apache.commons.lang3.builder.EqualsBuilder; @@ -19,7 +21,12 @@ import org.fhir.ucum.UcumService; import org.hl7.fhir.convertors.VersionConvertor_30_40; import org.hl7.fhir.dstu3.hapi.ctx.HapiWorkerContext; import org.hl7.fhir.dstu3.hapi.ctx.IValidationSupport; -import org.hl7.fhir.dstu3.model.*; +import org.hl7.fhir.dstu3.model.CodeSystem; +import org.hl7.fhir.dstu3.model.CodeableConcept; +import org.hl7.fhir.dstu3.model.Coding; +import org.hl7.fhir.dstu3.model.Questionnaire; +import org.hl7.fhir.dstu3.model.StructureDefinition; +import org.hl7.fhir.dstu3.model.ValueSet; import org.hl7.fhir.exceptions.FHIRException; import org.hl7.fhir.exceptions.TerminologyServiceException; import org.hl7.fhir.r4.context.IWorkerContext; @@ -40,11 +47,16 @@ import org.w3c.dom.Element; import org.w3c.dom.NodeList; import org.xml.sax.InputSource; +import java.io.StringReader; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashSet; +import java.util.List; +import java.util.Set; +import java.util.concurrent.TimeUnit; + import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; -import java.io.StringReader; -import java.util.*; -import java.util.concurrent.TimeUnit; public class FhirInstanceValidator extends BaseValidatorBridge implements IValidatorModule { @@ -92,6 +104,28 @@ public class FhirInstanceValidator extends BaseValidatorBridge implements IValid return root.getLocalName(); } + private ArrayList determineIfProfilesSpecified(Document theDocument) + { + ArrayList profileNames = new ArrayList(); + NodeList list = theDocument.getChildNodes().item(0).getChildNodes(); + for (int i = 0; i < list.getLength(); i++) { + if (list.item(i).getNodeName().compareToIgnoreCase("meta") == 0) + { + NodeList metaList = list.item(i).getChildNodes(); + for (int j = 0; j < metaList.getLength(); j++) + { + if (metaList.item(j).getNodeName().compareToIgnoreCase("profile") == 0) + { + String[] components = metaList.item(j).getAttributes().item(0).getNodeValue().split("/"); + profileNames.add(components[components.length - 1]); + } + } + break; + } + } + return profileNames; + } + private StructureDefinition findStructureDefinitionForResourceName(final FhirContext theCtx, String resourceName) { String sdName = "http://hl7.org/fhir/StructureDefinition/" + resourceName; StructureDefinition profile = myStructureDefintion != null ? myStructureDefintion : myValidationSupport.fetchStructureDefinition(theCtx, sdName); @@ -225,27 +259,49 @@ public class FhirInstanceValidator extends BaseValidatorBridge implements IValid return Collections.singletonList(m); } - String resourceName = determineResourceName(document); - StructureDefinition profile = findStructureDefinitionForResourceName(theCtx, resourceName); - if (profile != null) { - try { - v.validate(null, messages, document, profile.getUrl()); - } catch (Exception e) { - ourLog.error("Failure during validation", e); - throw new InternalErrorException("Unexpected failure while validating resource", e); + // Determine if meta/profiles are present... + ArrayList resourceNames = determineIfProfilesSpecified(document); + if (resourceNames.isEmpty()) + { + resourceNames.add(determineResourceName(document)); + } + + for (String resourceName : resourceNames) { + StructureDefinition profile = findStructureDefinitionForResourceName(theCtx, resourceName); + if (profile != null) { + try { + v.validate(null, messages, document, profile.getUrl()); + } catch (Exception e) { + ourLog.error("Failure during validation", e); + throw new InternalErrorException("Unexpected failure while validating resource", e); + } } } } else if (theEncoding == EncodingEnum.JSON) { Gson gson = new GsonBuilder().create(); JsonObject json = gson.fromJson(theInput, JsonObject.class); - String resourceName = json.get("resourceType").getAsString(); - StructureDefinition profile = findStructureDefinitionForResourceName(theCtx, resourceName); - if (profile != null) { - try { - v.validate(null, messages, json, profile.getUrl()); - } catch (Exception e) { - throw new InternalErrorException("Unexpected failure while validating resource", e); + ArrayList resourceNames = new ArrayList(); + JsonArray profiles = null; + try { + profiles = json.getAsJsonObject("meta").getAsJsonArray("profile"); + for (JsonElement element : profiles) + { + String[] components = element.getAsString().split("/"); + resourceNames.add(components[components.length - 1]); + } + } catch (Exception e) { + resourceNames.add(json.get("resourceType").getAsString()); + } + + for (String resourceName : resourceNames) { + StructureDefinition profile = findStructureDefinitionForResourceName(theCtx, resourceName); + if (profile != null) { + try { + v.validate(null, messages, json, profile.getUrl()); + } catch (Exception e) { + throw new InternalErrorException("Unexpected failure while validating resource", e); + } } } } else { From 0fdcad0985d805f18f78d9c4bd19a07feb2c38f0 Mon Sep 17 00:00:00 2001 From: Anthony Sute Date: Mon, 6 Aug 2018 13:17:51 -0400 Subject: [PATCH 2/4] Second pull request for fixes for issue #1048. --- .../validation/FhirInstanceValidator.java | 102 ++++++++++++---- .../validation/FhirInstanceValidator.java | 112 +++++++++++++----- 2 files changed, 163 insertions(+), 51 deletions(-) diff --git a/hapi-fhir-validation/src/main/java/org/hl7/fhir/instance/hapi/validation/FhirInstanceValidator.java b/hapi-fhir-validation/src/main/java/org/hl7/fhir/instance/hapi/validation/FhirInstanceValidator.java index da68e54a301..64f8f641732 100644 --- a/hapi-fhir-validation/src/main/java/org/hl7/fhir/instance/hapi/validation/FhirInstanceValidator.java +++ b/hapi-fhir-validation/src/main/java/org/hl7/fhir/instance/hapi/validation/FhirInstanceValidator.java @@ -1,6 +1,12 @@ package org.hl7.fhir.instance.hapi.validation; -import ca.uhn.fhir.context.*; +import static org.apache.commons.lang3.StringUtils.isBlank; + +import ca.uhn.fhir.context.BaseRuntimeElementDefinition; +import ca.uhn.fhir.context.ConfigurationException; +import ca.uhn.fhir.context.FhirContext; +import ca.uhn.fhir.context.FhirVersionEnum; +import ca.uhn.fhir.context.RuntimePrimitiveDatatypeDefinition; import ca.uhn.fhir.rest.api.EncodingEnum; import ca.uhn.fhir.rest.server.exceptions.InternalErrorException; import ca.uhn.fhir.validation.IValidationContext; @@ -10,6 +16,8 @@ import com.github.benmanes.caffeine.cache.Caffeine; import com.github.benmanes.caffeine.cache.LoadingCache; import com.google.gson.Gson; import com.google.gson.GsonBuilder; +import com.google.gson.JsonArray; +import com.google.gson.JsonElement; import com.google.gson.JsonObject; import org.apache.commons.io.IOUtils; import org.apache.commons.lang3.Validate; @@ -20,7 +28,12 @@ import org.hl7.fhir.convertors.VersionConvertorAdvisor40; import org.hl7.fhir.convertors.VersionConvertor_10_40; import org.hl7.fhir.exceptions.FHIRException; import org.hl7.fhir.exceptions.TerminologyServiceException; -import org.hl7.fhir.instance.model.*; +import org.hl7.fhir.instance.model.CodeableConcept; +import org.hl7.fhir.instance.model.Coding; +import org.hl7.fhir.instance.model.Questionnaire; +import org.hl7.fhir.instance.model.Resource; +import org.hl7.fhir.instance.model.StructureDefinition; +import org.hl7.fhir.instance.model.ValueSet; import org.hl7.fhir.r4.context.IWorkerContext; import org.hl7.fhir.r4.formats.IParser; import org.hl7.fhir.r4.formats.ParserType; @@ -40,15 +53,18 @@ import org.w3c.dom.Element; import org.w3c.dom.NodeList; import org.xml.sax.InputSource; -import javax.xml.parsers.DocumentBuilder; -import javax.xml.parsers.DocumentBuilderFactory; import java.io.IOException; import java.io.InputStream; import java.io.StringReader; -import java.util.*; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashSet; +import java.util.List; +import java.util.Set; import java.util.concurrent.TimeUnit; -import static org.apache.commons.lang3.StringUtils.isBlank; +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; public class FhirInstanceValidator extends BaseValidatorBridge implements IValidatorModule { @@ -128,6 +144,28 @@ public class FhirInstanceValidator extends BaseValidatorBridge implements IValid return root.getLocalName(); } + private ArrayList determineIfProfilesSpecified(Document theDocument) + { + ArrayList profileNames = new ArrayList(); + NodeList list = theDocument.getChildNodes().item(0).getChildNodes(); + for (int i = 0; i < list.getLength(); i++) { + if (list.item(i).getNodeName().compareToIgnoreCase("meta") == 0) + { + NodeList metaList = list.item(i).getChildNodes(); + for (int j = 0; j < metaList.getLength(); j++) + { + if (metaList.item(j).getNodeName().compareToIgnoreCase("profile") == 0) + { + String[] components = metaList.item(j).getAttributes().item(0).getNodeValue().split("/"); + profileNames.add(components[components.length - 1]); + } + } + break; + } + } + return profileNames; + } + private StructureDefinition findStructureDefinitionForResourceName(final FhirContext theCtx, String resourceName) { String sdName = "http://hl7.org/fhir/StructureDefinition/" + resourceName; StructureDefinition profile = myStructureDefintion != null ? myStructureDefintion : myValidationSupport.fetchResource(theCtx, StructureDefinition.class, sdName); @@ -257,27 +295,49 @@ public class FhirInstanceValidator extends BaseValidatorBridge implements IValid return Collections.singletonList(m); } - String resourceName = determineResourceName(document); - StructureDefinition profile = findStructureDefinitionForResourceName(theCtx, resourceName); - if (profile != null) { - try { - v.validate(null, messages, document, profile.getUrl()); - } catch (Exception e) { - ourLog.error("Failure during validation", e); - throw new InternalErrorException("Unexpected failure while validating resource", e); + // Determine if meta/profiles are present... + ArrayList resourceNames = determineIfProfilesSpecified(document); + if (resourceNames.isEmpty()) + { + resourceNames.add(determineResourceName(document)); + } + + for (String resourceName : resourceNames) { + StructureDefinition profile = findStructureDefinitionForResourceName(theCtx, resourceName); + if (profile != null) { + try { + v.validate(null, messages, document, profile.getUrl()); + } catch (Exception e) { + ourLog.error("Failure during validation", e); + throw new InternalErrorException("Unexpected failure while validating resource", e); + } } } } else if (theEncoding == EncodingEnum.JSON) { Gson gson = new GsonBuilder().create(); JsonObject json = gson.fromJson(theInput, JsonObject.class); - String resourceName = json.get("resourceType").getAsString(); - StructureDefinition profile = findStructureDefinitionForResourceName(theCtx, resourceName); - if (profile != null) { - try { - v.validate(null, messages, json, profile.getUrl()); - } catch (Exception e) { - throw new InternalErrorException("Unexpected failure while validating resource", e); + ArrayList resourceNames = new ArrayList(); + JsonArray profiles = null; + try { + profiles = json.getAsJsonObject("meta").getAsJsonArray("profile"); + for (JsonElement element : profiles) + { + String[] components = element.getAsString().split("/"); + resourceNames.add(components[components.length - 1]); + } + } catch (Exception e) { + resourceNames.add(json.get("resourceType").getAsString()); + } + + for (String resourceName : resourceNames) { + StructureDefinition profile = findStructureDefinitionForResourceName(theCtx, resourceName); + if (profile != null) { + try { + v.validate(null, messages, json, profile.getUrl()); + } catch (Exception e) { + throw new InternalErrorException("Unexpected failure while validating resource", e); + } } } } else { diff --git a/hapi-fhir-validation/src/main/java/org/hl7/fhir/r4/hapi/validation/FhirInstanceValidator.java b/hapi-fhir-validation/src/main/java/org/hl7/fhir/r4/hapi/validation/FhirInstanceValidator.java index 0a36ae5200b..36235ec395a 100644 --- a/hapi-fhir-validation/src/main/java/org/hl7/fhir/r4/hapi/validation/FhirInstanceValidator.java +++ b/hapi-fhir-validation/src/main/java/org/hl7/fhir/r4/hapi/validation/FhirInstanceValidator.java @@ -1,15 +1,24 @@ package org.hl7.fhir.r4.hapi.validation; -import java.io.StringReader; -import java.util.*; - -import javax.xml.parsers.DocumentBuilder; -import javax.xml.parsers.DocumentBuilderFactory; - +import ca.uhn.fhir.context.ConfigurationException; +import ca.uhn.fhir.context.FhirContext; +import ca.uhn.fhir.rest.api.EncodingEnum; +import ca.uhn.fhir.rest.server.exceptions.InternalErrorException; +import ca.uhn.fhir.validation.IValidationContext; +import ca.uhn.fhir.validation.IValidatorModule; +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; +import com.google.gson.JsonArray; +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; import org.apache.commons.lang3.Validate; import org.hl7.fhir.exceptions.PathEngineException; -import org.hl7.fhir.r4.hapi.ctx.*; -import org.hl7.fhir.r4.model.*; +import org.hl7.fhir.r4.hapi.ctx.DefaultProfileValidationSupport; +import org.hl7.fhir.r4.hapi.ctx.HapiWorkerContext; +import org.hl7.fhir.r4.hapi.ctx.IValidationSupport; +import org.hl7.fhir.r4.model.Base; +import org.hl7.fhir.r4.model.StructureDefinition; +import org.hl7.fhir.r4.model.TypeDetails; import org.hl7.fhir.r4.utils.FHIRPathEngine.IEvaluationContext; import org.hl7.fhir.r4.utils.IResourceValidator.BestPracticeWarningLevel; import org.hl7.fhir.r4.utils.IResourceValidator.IdStatus; @@ -21,14 +30,13 @@ import org.w3c.dom.Element; import org.w3c.dom.NodeList; import org.xml.sax.InputSource; -import com.google.gson.*; +import java.io.StringReader; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; -import ca.uhn.fhir.context.ConfigurationException; -import ca.uhn.fhir.context.FhirContext; -import ca.uhn.fhir.rest.api.EncodingEnum; -import ca.uhn.fhir.rest.server.exceptions.InternalErrorException; -import ca.uhn.fhir.validation.IValidationContext; -import ca.uhn.fhir.validation.IValidatorModule; +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; public class FhirInstanceValidator extends BaseValidatorBridge implements IValidatorModule { @@ -77,6 +85,28 @@ public class FhirInstanceValidator extends BaseValidatorBridge implements IValid return root.getLocalName(); } + private ArrayList determineIfProfilesSpecified(Document theDocument) + { + ArrayList profileNames = new ArrayList(); + NodeList list = theDocument.getChildNodes().item(0).getChildNodes(); + for (int i = 0; i < list.getLength(); i++) { + if (list.item(i).getNodeName().compareToIgnoreCase("meta") == 0) + { + NodeList metaList = list.item(i).getChildNodes(); + for (int j = 0; j < metaList.getLength(); j++) + { + if (metaList.item(j).getNodeName().compareToIgnoreCase("profile") == 0) + { + String[] components = metaList.item(j).getAttributes().item(0).getNodeValue().split("/"); + profileNames.add(components[components.length - 1]); + } + } + break; + } + } + return profileNames; + } + private StructureDefinition findStructureDefinitionForResourceName(final FhirContext theCtx, String resourceName) { String sdName = "http://hl7.org/fhir/StructureDefinition/" + resourceName; StructureDefinition profile = myStructureDefintion != null ? myStructureDefintion : myValidationSupport.fetchStructureDefinition(theCtx, sdName); @@ -200,27 +230,49 @@ public class FhirInstanceValidator extends BaseValidatorBridge implements IValid return Collections.singletonList(m); } - String resourceName = determineResourceName(document); - StructureDefinition profile = findStructureDefinitionForResourceName(theCtx, resourceName); - if (profile != null) { - try { - v.validate(null, messages, document, profile); - } catch (Exception e) { - throw new InternalErrorException("Unexpected failure while validating resource", e); + // Determine if meta/profiles are present... + ArrayList resourceNames = determineIfProfilesSpecified(document); + if (resourceNames.isEmpty()) + { + resourceNames.add(determineResourceName(document)); + } + + for (String resourceName : resourceNames) { + StructureDefinition profile = findStructureDefinitionForResourceName(theCtx, resourceName); + if (profile != null) { + try { + v.validate(null, messages, document, profile.getUrl()); + } catch (Exception e) { + ourLog.error("Failure during validation", e); + throw new InternalErrorException("Unexpected failure while validating resource", e); + } } } } else if (theEncoding == EncodingEnum.JSON) { Gson gson = new GsonBuilder().create(); JsonObject json = gson.fromJson(theInput, JsonObject.class); - String resourceName = json.get("resourceType").getAsString(); - StructureDefinition profile = findStructureDefinitionForResourceName(theCtx, resourceName); - if (profile != null) { - try { - v.validate(null, messages, json, profile); - } catch (Exception e) { - ourLog.error("Failure during validation", e); - throw new InternalErrorException("Unexpected failure while validating resource", e); + ArrayList resourceNames = new ArrayList(); + JsonArray profiles = null; + try { + profiles = json.getAsJsonObject("meta").getAsJsonArray("profile"); + for (JsonElement element : profiles) + { + String[] components = element.getAsString().split("/"); + resourceNames.add(components[components.length - 1]); + } + } catch (Exception e) { + resourceNames.add(json.get("resourceType").getAsString()); + } + + for (String resourceName : resourceNames) { + StructureDefinition profile = findStructureDefinitionForResourceName(theCtx, resourceName); + if (profile != null) { + try { + v.validate(null, messages, json, profile.getUrl()); + } catch (Exception e) { + throw new InternalErrorException("Unexpected failure while validating resource", e); + } } } } else { From 5ef647840b72e01d3912d38d1c816c0d7669272d Mon Sep 17 00:00:00 2001 From: Anthony Sute Date: Fri, 10 Aug 2018 11:47:53 -0400 Subject: [PATCH 3/4] Follow-up fixes for unit tests for issue #1048. --- .../validation/FhirInstanceValidator.java | 53 +++++++++++++-- .../validation/FhirInstanceValidator.java | 53 +++++++++++++-- .../validation/FhirInstanceValidator.java | 53 +++++++++++++-- .../FhirInstanceValidatorDstu3Test.java | 63 +++++++++++++---- .../FhirInstanceValidatorR4Test.java | 68 +++++++++++++++---- 5 files changed, 250 insertions(+), 40 deletions(-) diff --git a/hapi-fhir-validation/src/main/java/org/hl7/fhir/dstu3/hapi/validation/FhirInstanceValidator.java b/hapi-fhir-validation/src/main/java/org/hl7/fhir/dstu3/hapi/validation/FhirInstanceValidator.java index 002023e6f0c..8545e6dd3ab 100644 --- a/hapi-fhir-validation/src/main/java/org/hl7/fhir/dstu3/hapi/validation/FhirInstanceValidator.java +++ b/hapi-fhir-validation/src/main/java/org/hl7/fhir/dstu3/hapi/validation/FhirInstanceValidator.java @@ -48,6 +48,8 @@ import org.w3c.dom.NodeList; import org.xml.sax.InputSource; import java.io.StringReader; +import java.net.MalformedURLException; +import java.net.URL; import java.util.ArrayList; import java.util.Collections; import java.util.HashSet; @@ -116,8 +118,7 @@ public class FhirInstanceValidator extends BaseValidatorBridge implements IValid { if (metaList.item(j).getNodeName().compareToIgnoreCase("profile") == 0) { - String[] components = metaList.item(j).getAttributes().item(0).getNodeValue().split("/"); - profileNames.add(components[components.length - 1]); + profileNames.add(metaList.item(j).getAttributes().item(0).getNodeValue()); } } break; @@ -127,7 +128,26 @@ public class FhirInstanceValidator extends BaseValidatorBridge implements IValid } private StructureDefinition findStructureDefinitionForResourceName(final FhirContext theCtx, String resourceName) { - String sdName = "http://hl7.org/fhir/StructureDefinition/" + resourceName; + String sdName = null; + try { + // Test if a URL was passed in specifying the structure definition and test if "StructureDefinition" is part of the URL + URL testIfUrl = new URL(resourceName); + if (resourceName.toLowerCase().contains("structuredefinition")) + { + sdName = resourceName; + } + else + { + ourLog.error(String.format("Structure definition URL must contain the text, \"StructureDefinition\", URL=%s", + resourceName)); + throw new InternalErrorException(String.format("Structure definition URL must contain the text, \"StructureDefinition\", URL=%s", + resourceName)); + } + } + catch (MalformedURLException e) + { + sdName = "http://hl7.org/fhir/StructureDefinition/" + resourceName; + } StructureDefinition profile = myStructureDefintion != null ? myStructureDefintion : myValidationSupport.fetchStructureDefinition(theCtx, sdName); return profile; } @@ -276,6 +296,18 @@ public class FhirInstanceValidator extends BaseValidatorBridge implements IValid throw new InternalErrorException("Unexpected failure while validating resource", e); } } + else + { + profile = findStructureDefinitionForResourceName(theCtx, determineResourceName(document)); + if (profile != null) { + try { + v.validate(null, messages, document, profile.getUrl()); + } catch (Exception e) { + ourLog.error("Failure during validation", e); + throw new InternalErrorException("Unexpected failure while validating resource", e); + } + } + } } } else if (theEncoding == EncodingEnum.JSON) { Gson gson = new GsonBuilder().create(); @@ -287,8 +319,7 @@ public class FhirInstanceValidator extends BaseValidatorBridge implements IValid profiles = json.getAsJsonObject("meta").getAsJsonArray("profile"); for (JsonElement element : profiles) { - String[] components = element.getAsString().split("/"); - resourceNames.add(components[components.length - 1]); + resourceNames.add(element.getAsString()); } } catch (Exception e) { resourceNames.add(json.get("resourceType").getAsString()); @@ -303,6 +334,18 @@ public class FhirInstanceValidator extends BaseValidatorBridge implements IValid throw new InternalErrorException("Unexpected failure while validating resource", e); } } + else + { + profile = findStructureDefinitionForResourceName(theCtx, json.get("resourceType").getAsString()); + if (profile != null) { + try { + v.validate(null, messages, json, profile.getUrl()); + } catch (Exception e) { + ourLog.error("Failure during validation", e); + throw new InternalErrorException("Unexpected failure while validating resource", e); + } + } + } } } else { throw new IllegalArgumentException("Unknown encoding: " + theEncoding); diff --git a/hapi-fhir-validation/src/main/java/org/hl7/fhir/instance/hapi/validation/FhirInstanceValidator.java b/hapi-fhir-validation/src/main/java/org/hl7/fhir/instance/hapi/validation/FhirInstanceValidator.java index 64f8f641732..0b6db8c6426 100644 --- a/hapi-fhir-validation/src/main/java/org/hl7/fhir/instance/hapi/validation/FhirInstanceValidator.java +++ b/hapi-fhir-validation/src/main/java/org/hl7/fhir/instance/hapi/validation/FhirInstanceValidator.java @@ -56,6 +56,8 @@ import org.xml.sax.InputSource; import java.io.IOException; import java.io.InputStream; import java.io.StringReader; +import java.net.MalformedURLException; +import java.net.URL; import java.util.ArrayList; import java.util.Collections; import java.util.HashSet; @@ -156,8 +158,7 @@ public class FhirInstanceValidator extends BaseValidatorBridge implements IValid { if (metaList.item(j).getNodeName().compareToIgnoreCase("profile") == 0) { - String[] components = metaList.item(j).getAttributes().item(0).getNodeValue().split("/"); - profileNames.add(components[components.length - 1]); + profileNames.add(metaList.item(j).getAttributes().item(0).getNodeValue()); } } break; @@ -167,7 +168,26 @@ public class FhirInstanceValidator extends BaseValidatorBridge implements IValid } private StructureDefinition findStructureDefinitionForResourceName(final FhirContext theCtx, String resourceName) { - String sdName = "http://hl7.org/fhir/StructureDefinition/" + resourceName; + String sdName = null; + try { + // Test if a URL was passed in specifying the structure definition and test if "StructureDefinition" is part of the URL + URL testIfUrl = new URL(resourceName); + if (resourceName.toLowerCase().contains("structuredefinition")) + { + sdName = resourceName; + } + else + { + ourLog.error(String.format("Structure definition URL must contain the text, \"StructureDefinition\", URL=%s", + resourceName)); + throw new InternalErrorException(String.format("Structure definition URL must contain the text, \"StructureDefinition\", URL=%s", + resourceName)); + } + } + catch (MalformedURLException e) + { + sdName = "http://hl7.org/fhir/StructureDefinition/" + resourceName; + } StructureDefinition profile = myStructureDefintion != null ? myStructureDefintion : myValidationSupport.fetchResource(theCtx, StructureDefinition.class, sdName); return profile; } @@ -312,6 +332,18 @@ public class FhirInstanceValidator extends BaseValidatorBridge implements IValid throw new InternalErrorException("Unexpected failure while validating resource", e); } } + else + { + profile = findStructureDefinitionForResourceName(theCtx, determineResourceName(document)); + if (profile != null) { + try { + v.validate(null, messages, document, profile.getUrl()); + } catch (Exception e) { + ourLog.error("Failure during validation", e); + throw new InternalErrorException("Unexpected failure while validating resource", e); + } + } + } } } else if (theEncoding == EncodingEnum.JSON) { Gson gson = new GsonBuilder().create(); @@ -323,8 +355,7 @@ public class FhirInstanceValidator extends BaseValidatorBridge implements IValid profiles = json.getAsJsonObject("meta").getAsJsonArray("profile"); for (JsonElement element : profiles) { - String[] components = element.getAsString().split("/"); - resourceNames.add(components[components.length - 1]); + resourceNames.add(element.getAsString()); } } catch (Exception e) { resourceNames.add(json.get("resourceType").getAsString()); @@ -339,6 +370,18 @@ public class FhirInstanceValidator extends BaseValidatorBridge implements IValid throw new InternalErrorException("Unexpected failure while validating resource", e); } } + else + { + profile = findStructureDefinitionForResourceName(theCtx, json.get("resourceType").getAsString()); + if (profile != null) { + try { + v.validate(null, messages, json, profile.getUrl()); + } catch (Exception e) { + ourLog.error("Failure during validation", e); + throw new InternalErrorException("Unexpected failure while validating resource", e); + } + } + } } } else { throw new IllegalArgumentException("Unknown encoding: " + theEncoding); diff --git a/hapi-fhir-validation/src/main/java/org/hl7/fhir/r4/hapi/validation/FhirInstanceValidator.java b/hapi-fhir-validation/src/main/java/org/hl7/fhir/r4/hapi/validation/FhirInstanceValidator.java index 36235ec395a..26c6afed371 100644 --- a/hapi-fhir-validation/src/main/java/org/hl7/fhir/r4/hapi/validation/FhirInstanceValidator.java +++ b/hapi-fhir-validation/src/main/java/org/hl7/fhir/r4/hapi/validation/FhirInstanceValidator.java @@ -31,6 +31,8 @@ import org.w3c.dom.NodeList; import org.xml.sax.InputSource; import java.io.StringReader; +import java.net.MalformedURLException; +import java.net.URL; import java.util.ArrayList; import java.util.Collections; import java.util.List; @@ -97,8 +99,7 @@ public class FhirInstanceValidator extends BaseValidatorBridge implements IValid { if (metaList.item(j).getNodeName().compareToIgnoreCase("profile") == 0) { - String[] components = metaList.item(j).getAttributes().item(0).getNodeValue().split("/"); - profileNames.add(components[components.length - 1]); + profileNames.add(metaList.item(j).getAttributes().item(0).getNodeValue()); } } break; @@ -108,7 +109,26 @@ public class FhirInstanceValidator extends BaseValidatorBridge implements IValid } private StructureDefinition findStructureDefinitionForResourceName(final FhirContext theCtx, String resourceName) { - String sdName = "http://hl7.org/fhir/StructureDefinition/" + resourceName; + String sdName = null; + try { + // Test if a URL was passed in specifying the structure definition and test if "StructureDefinition" is part of the URL + URL testIfUrl = new URL(resourceName); + if (resourceName.toLowerCase().contains("structuredefinition")) + { + sdName = resourceName; + } + else + { + ourLog.error(String.format("Structure definition URL must contain the text, \"StructureDefinition\", URL=%s", + resourceName)); + throw new InternalErrorException(String.format("Structure definition URL must contain the text, \"StructureDefinition\", URL=%s", + resourceName)); + } + } + catch (MalformedURLException e) + { + sdName = "http://hl7.org/fhir/StructureDefinition/" + resourceName; + } StructureDefinition profile = myStructureDefintion != null ? myStructureDefintion : myValidationSupport.fetchStructureDefinition(theCtx, sdName); return profile; } @@ -247,6 +267,18 @@ public class FhirInstanceValidator extends BaseValidatorBridge implements IValid throw new InternalErrorException("Unexpected failure while validating resource", e); } } + else + { + profile = findStructureDefinitionForResourceName(theCtx, determineResourceName(document)); + if (profile != null) { + try { + v.validate(null, messages, document, profile.getUrl()); + } catch (Exception e) { + ourLog.error("Failure during validation", e); + throw new InternalErrorException("Unexpected failure while validating resource", e); + } + } + } } } else if (theEncoding == EncodingEnum.JSON) { Gson gson = new GsonBuilder().create(); @@ -258,8 +290,7 @@ public class FhirInstanceValidator extends BaseValidatorBridge implements IValid profiles = json.getAsJsonObject("meta").getAsJsonArray("profile"); for (JsonElement element : profiles) { - String[] components = element.getAsString().split("/"); - resourceNames.add(components[components.length - 1]); + resourceNames.add(element.getAsString()); } } catch (Exception e) { resourceNames.add(json.get("resourceType").getAsString()); @@ -274,6 +305,18 @@ public class FhirInstanceValidator extends BaseValidatorBridge implements IValid throw new InternalErrorException("Unexpected failure while validating resource", e); } } + else + { + profile = findStructureDefinitionForResourceName(theCtx, json.get("resourceType").getAsString()); + if (profile != null) { + try { + v.validate(null, messages, json, profile.getUrl()); + } catch (Exception e) { + ourLog.error("Failure during validation", e); + throw new InternalErrorException("Unexpected failure while validating resource", e); + } + } + } } } else { throw new IllegalArgumentException("Unknown encoding: " + theEncoding); diff --git a/hapi-fhir-validation/src/test/java/org/hl7/fhir/dstu3/hapi/validation/FhirInstanceValidatorDstu3Test.java b/hapi-fhir-validation/src/test/java/org/hl7/fhir/dstu3/hapi/validation/FhirInstanceValidatorDstu3Test.java index 75a548bc53b..0313a4208dc 100644 --- a/hapi-fhir-validation/src/test/java/org/hl7/fhir/dstu3/hapi/validation/FhirInstanceValidatorDstu3Test.java +++ b/hapi-fhir-validation/src/test/java/org/hl7/fhir/dstu3/hapi/validation/FhirInstanceValidatorDstu3Test.java @@ -1,5 +1,20 @@ package org.hl7.fhir.dstu3.hapi.validation; +import static org.hamcrest.Matchers.containsString; +import static org.hamcrest.Matchers.empty; +import static org.hamcrest.Matchers.greaterThan; +import static org.hamcrest.Matchers.hasSize; +import static org.hamcrest.Matchers.lessThan; +import static org.hamcrest.Matchers.not; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertThat; +import static org.junit.Assert.assertTrue; +import static org.mockito.ArgumentMatchers.nullable; +import static org.mockito.Matchers.any; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.util.TestUtil; import ca.uhn.fhir.validation.FhirValidator; @@ -11,19 +26,44 @@ import org.apache.commons.io.IOUtils; import org.hl7.fhir.dstu3.hapi.ctx.HapiWorkerContext; import org.hl7.fhir.dstu3.hapi.ctx.IValidationSupport; import org.hl7.fhir.dstu3.hapi.ctx.IValidationSupport.CodeValidationResult; -import org.hl7.fhir.dstu3.model.*; +import org.hl7.fhir.dstu3.model.Base; +import org.hl7.fhir.dstu3.model.BooleanType; +import org.hl7.fhir.dstu3.model.Bundle; import org.hl7.fhir.dstu3.model.Bundle.BundleEntryComponent; +import org.hl7.fhir.dstu3.model.CodeSystem; import org.hl7.fhir.dstu3.model.CodeSystem.ConceptDefinitionComponent; +import org.hl7.fhir.dstu3.model.CodeType; +import org.hl7.fhir.dstu3.model.CodeableConcept; +import org.hl7.fhir.dstu3.model.Coding; +import org.hl7.fhir.dstu3.model.ContactPoint; +import org.hl7.fhir.dstu3.model.DateTimeType; import org.hl7.fhir.dstu3.model.Enumerations.PublicationStatus; +import org.hl7.fhir.dstu3.model.Extension; +import org.hl7.fhir.dstu3.model.Goal; +import org.hl7.fhir.dstu3.model.ImagingStudy; +import org.hl7.fhir.dstu3.model.Observation; import org.hl7.fhir.dstu3.model.Observation.ObservationStatus; +import org.hl7.fhir.dstu3.model.Patient; +import org.hl7.fhir.dstu3.model.Period; +import org.hl7.fhir.dstu3.model.Procedure; +import org.hl7.fhir.dstu3.model.Questionnaire; import org.hl7.fhir.dstu3.model.Questionnaire.QuestionnaireItemComponent; import org.hl7.fhir.dstu3.model.Questionnaire.QuestionnaireItemType; +import org.hl7.fhir.dstu3.model.Reference; +import org.hl7.fhir.dstu3.model.RelatedPerson; +import org.hl7.fhir.dstu3.model.StringType; +import org.hl7.fhir.dstu3.model.StructureDefinition; import org.hl7.fhir.dstu3.model.StructureDefinition.StructureDefinitionKind; +import org.hl7.fhir.dstu3.model.ValueSet; import org.hl7.fhir.dstu3.model.ValueSet.ConceptSetComponent; import org.hl7.fhir.dstu3.model.ValueSet.ValueSetExpansionComponent; import org.hl7.fhir.dstu3.utils.FHIRPathEngine; import org.hl7.fhir.instance.model.api.IBaseResource; -import org.junit.*; +import org.junit.AfterClass; +import org.junit.Before; +import org.junit.Ignore; +import org.junit.Rule; +import org.junit.Test; import org.junit.rules.TestRule; import org.junit.rules.TestWatcher; import org.junit.runner.Description; @@ -32,16 +72,15 @@ import org.mockito.stubbing.Answer; import java.io.IOException; import java.io.InputStream; -import java.util.*; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.TreeSet; import java.util.zip.GZIPInputStream; -import static org.hamcrest.Matchers.*; -import static org.junit.Assert.*; -import static org.mockito.ArgumentMatchers.nullable; -import static org.mockito.Matchers.any; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - public class FhirInstanceValidatorDstu3Test { private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(FhirInstanceValidatorDstu3Test.class); @@ -845,7 +884,7 @@ public class FhirInstanceValidatorDstu3Test { addValidConcept("http://loinc.org", "12345"); Observation input = new Observation(); - input.getMeta().addProfile("http://foo/myprofile"); + input.getMeta().addProfile("http://foo/structuredefinition/myprofile"); input.getCode().addCoding().setSystem("http://loinc.org").setCode("12345"); input.setStatus(ObservationStatus.FINAL); @@ -854,7 +893,7 @@ public class FhirInstanceValidatorDstu3Test { ValidationResult output = myVal.validateWithResult(input); List errors = logResultsAndReturnNonInformationalOnes(output); assertEquals(errors.toString(), 1, errors.size()); - assertEquals("StructureDefinition reference \"http://foo/myprofile\" could not be resolved", errors.get(0).getMessage()); + assertEquals("StructureDefinition reference \"http://foo/structuredefinition/myprofile\" could not be resolved", errors.get(0).getMessage()); } @Test diff --git a/hapi-fhir-validation/src/test/java/org/hl7/fhir/r4/validation/FhirInstanceValidatorR4Test.java b/hapi-fhir-validation/src/test/java/org/hl7/fhir/r4/validation/FhirInstanceValidatorR4Test.java index 4c852810973..36fd0b3eeef 100644 --- a/hapi-fhir-validation/src/test/java/org/hl7/fhir/r4/validation/FhirInstanceValidatorR4Test.java +++ b/hapi-fhir-validation/src/test/java/org/hl7/fhir/r4/validation/FhirInstanceValidatorR4Test.java @@ -1,5 +1,20 @@ package org.hl7.fhir.r4.validation; +import static org.hamcrest.Matchers.containsString; +import static org.hamcrest.Matchers.empty; +import static org.hamcrest.Matchers.greaterThan; +import static org.hamcrest.Matchers.hasItem; +import static org.hamcrest.Matchers.hasSize; +import static org.hamcrest.Matchers.lessThan; +import static org.hamcrest.Matchers.not; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertThat; +import static org.junit.Assert.assertTrue; +import static org.mockito.ArgumentMatchers.nullable; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.rest.api.Constants; import ca.uhn.fhir.util.TestUtil; @@ -15,20 +30,48 @@ import org.hl7.fhir.exceptions.FHIRException; import org.hl7.fhir.instance.model.api.IBaseResource; import org.hl7.fhir.r4.conformance.ProfileUtilities; import org.hl7.fhir.r4.context.IWorkerContext; -import org.hl7.fhir.r4.hapi.ctx.*; +import org.hl7.fhir.r4.hapi.ctx.DefaultProfileValidationSupport; +import org.hl7.fhir.r4.hapi.ctx.HapiWorkerContext; +import org.hl7.fhir.r4.hapi.ctx.IValidationSupport; import org.hl7.fhir.r4.hapi.ctx.IValidationSupport.CodeValidationResult; +import org.hl7.fhir.r4.hapi.ctx.PrePopulatedValidationSupport; +import org.hl7.fhir.r4.hapi.ctx.ValidationSupportChain; import org.hl7.fhir.r4.hapi.validation.FhirInstanceValidator; -import org.hl7.fhir.r4.model.*; +import org.hl7.fhir.r4.model.Base; +import org.hl7.fhir.r4.model.Base64BinaryType; +import org.hl7.fhir.r4.model.BooleanType; +import org.hl7.fhir.r4.model.Bundle; import org.hl7.fhir.r4.model.Bundle.BundleEntryComponent; +import org.hl7.fhir.r4.model.CodeSystem; import org.hl7.fhir.r4.model.CodeSystem.ConceptDefinitionComponent; +import org.hl7.fhir.r4.model.CodeType; +import org.hl7.fhir.r4.model.Consent; +import org.hl7.fhir.r4.model.ContactPoint; +import org.hl7.fhir.r4.model.DateTimeType; +import org.hl7.fhir.r4.model.Extension; +import org.hl7.fhir.r4.model.Media; +import org.hl7.fhir.r4.model.Observation; import org.hl7.fhir.r4.model.Observation.ObservationStatus; +import org.hl7.fhir.r4.model.Patient; +import org.hl7.fhir.r4.model.Period; +import org.hl7.fhir.r4.model.Practitioner; +import org.hl7.fhir.r4.model.Procedure; +import org.hl7.fhir.r4.model.QuestionnaireResponse; +import org.hl7.fhir.r4.model.Reference; +import org.hl7.fhir.r4.model.RelatedPerson; +import org.hl7.fhir.r4.model.StringType; +import org.hl7.fhir.r4.model.StructureDefinition; import org.hl7.fhir.r4.model.StructureDefinition.StructureDefinitionKind; import org.hl7.fhir.r4.model.ValueSet.ConceptSetComponent; import org.hl7.fhir.r4.model.ValueSet.ValueSetExpansionComponent; import org.hl7.fhir.r4.utils.FHIRPathEngine; import org.hl7.fhir.r4.utils.IResourceValidator; import org.hl7.fhir.utilities.validation.ValidationMessage; -import org.junit.*; +import org.junit.AfterClass; +import org.junit.Before; +import org.junit.Ignore; +import org.junit.Rule; +import org.junit.Test; import org.junit.rules.TestRule; import org.junit.rules.TestWatcher; import org.junit.runner.Description; @@ -37,17 +80,16 @@ import org.mockito.stubbing.Answer; import java.io.IOException; import java.io.InputStream; -import java.util.*; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.TreeSet; import java.util.stream.Collectors; import java.util.zip.GZIPInputStream; -import static org.hamcrest.Matchers.*; -import static org.junit.Assert.*; -import static org.mockito.ArgumentMatchers.nullable; -import static org.mockito.Matchers.any; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - public class FhirInstanceValidatorR4Test { private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(FhirInstanceValidatorR4Test.class); @@ -909,7 +951,7 @@ public class FhirInstanceValidatorR4Test { addValidConcept("http://loinc.org", "12345"); Observation input = new Observation(); - input.getMeta().addProfile("http://foo/myprofile"); + input.getMeta().addProfile("http://foo/structuredefinition/myprofile"); input.getCode().addCoding().setSystem("http://loinc.org").setCode("12345"); input.setStatus(ObservationStatus.FINAL); @@ -918,7 +960,7 @@ public class FhirInstanceValidatorR4Test { ValidationResult output = myVal.validateWithResult(input); List errors = logResultsAndReturnNonInformationalOnes(output); assertEquals(errors.toString(), 1, errors.size()); - assertEquals("StructureDefinition reference \"http://foo/myprofile\" could not be resolved", errors.get(0).getMessage()); + assertEquals("StructureDefinition reference \"http://foo/structuredefinition/myprofile\" could not be resolved", errors.get(0).getMessage()); } @Test From 416054ddffece1ae9322aa2b99945e2194c41e85 Mon Sep 17 00:00:00 2001 From: Anthony Sute Date: Fri, 10 Aug 2018 12:51:12 -0400 Subject: [PATCH 4/4] Fixes for issue #1048 --- .../FhirResourceDaoDstu2ValidateTest.java | 33 ++++++++++------ .../FhirResourceDaoDstu3ValidateTest.java | 32 +++++++++++----- .../dao/r4/FhirResourceDaoR4ValidateTest.java | 38 +++++++++++++------ 3 files changed, 70 insertions(+), 33 deletions(-) diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu2/FhirResourceDaoDstu2ValidateTest.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu2/FhirResourceDaoDstu2ValidateTest.java index d484407c1aa..84b30edf618 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu2/FhirResourceDaoDstu2ValidateTest.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu2/FhirResourceDaoDstu2ValidateTest.java @@ -4,23 +4,34 @@ import static org.hamcrest.Matchers.containsString; import static org.junit.Assert.assertThat; import static org.junit.Assert.fail; -import java.io.IOException; -import java.util.Arrays; - -import org.hl7.fhir.instance.model.api.IIdType; -import org.junit.*; -import org.junit.Test; - import ca.uhn.fhir.jpa.dao.DaoConfig; import ca.uhn.fhir.model.api.IResource; import ca.uhn.fhir.model.api.ResourceMetadataKeyEnum; -import ca.uhn.fhir.model.dstu2.resource.*; +import ca.uhn.fhir.model.dstu2.resource.Bundle; import ca.uhn.fhir.model.dstu2.resource.Bundle.Entry; +import ca.uhn.fhir.model.dstu2.resource.Observation; +import ca.uhn.fhir.model.dstu2.resource.OperationOutcome; +import ca.uhn.fhir.model.dstu2.resource.Organization; +import ca.uhn.fhir.model.dstu2.resource.Patient; +import ca.uhn.fhir.model.dstu2.resource.StructureDefinition; +import ca.uhn.fhir.model.dstu2.resource.ValueSet; import ca.uhn.fhir.model.dstu2.valueset.ObservationStatusEnum; import ca.uhn.fhir.model.primitive.IdDt; -import ca.uhn.fhir.rest.api.*; -import ca.uhn.fhir.rest.server.exceptions.*; +import ca.uhn.fhir.rest.api.EncodingEnum; +import ca.uhn.fhir.rest.api.MethodOutcome; +import ca.uhn.fhir.rest.api.ValidationModeEnum; +import ca.uhn.fhir.rest.server.exceptions.PreconditionFailedException; +import ca.uhn.fhir.rest.server.exceptions.ResourceVersionConflictException; +import ca.uhn.fhir.rest.server.exceptions.UnprocessableEntityException; import ca.uhn.fhir.util.TestUtil; +import org.hl7.fhir.instance.model.api.IIdType; +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Before; +import org.junit.Test; + +import java.io.IOException; +import java.util.Arrays; public class FhirResourceDaoDstu2ValidateTest extends BaseJpaDstu2Test { private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(FhirResourceDaoDstu2ValidateTest.class); @@ -122,7 +133,7 @@ public class FhirResourceDaoDstu2ValidateTest extends BaseJpaDstu2Test { String methodName = "testValidateResourceContainingProfileDeclarationInvalid"; Observation input = new Observation(); - String profileUri = "http://example.com/" + methodName; + String profileUri = "http://example.com/StructureDefinition/" + methodName; ResourceMetadataKeyEnum.PROFILES.put(input, Arrays.asList(new IdDt(profileUri))); input.addIdentifier().setSystem("http://acme").setValue("12345"); diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoDstu3ValidateTest.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoDstu3ValidateTest.java index 87969b57c10..fa2e085d3e0 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoDstu3ValidateTest.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoDstu3ValidateTest.java @@ -4,21 +4,33 @@ import static org.hamcrest.Matchers.containsString; import static org.junit.Assert.assertThat; import static org.junit.Assert.fail; -import java.io.IOException; -import java.nio.charset.StandardCharsets; - +import ca.uhn.fhir.rest.api.EncodingEnum; +import ca.uhn.fhir.rest.api.MethodOutcome; +import ca.uhn.fhir.rest.api.ValidationModeEnum; +import ca.uhn.fhir.rest.server.exceptions.PreconditionFailedException; +import ca.uhn.fhir.rest.server.exceptions.ResourceVersionConflictException; +import ca.uhn.fhir.rest.server.exceptions.UnprocessableEntityException; +import ca.uhn.fhir.util.StopWatch; +import ca.uhn.fhir.util.TestUtil; import org.apache.commons.io.IOUtils; -import org.hl7.fhir.dstu3.model.*; +import org.hl7.fhir.dstu3.model.Bundle; import org.hl7.fhir.dstu3.model.Bundle.BundleEntryComponent; +import org.hl7.fhir.dstu3.model.IdType; +import org.hl7.fhir.dstu3.model.Observation; import org.hl7.fhir.dstu3.model.Observation.ObservationStatus; +import org.hl7.fhir.dstu3.model.OperationOutcome; +import org.hl7.fhir.dstu3.model.Organization; +import org.hl7.fhir.dstu3.model.Patient; +import org.hl7.fhir.dstu3.model.StructureDefinition; +import org.hl7.fhir.dstu3.model.ValueSet; import org.hl7.fhir.instance.model.api.IBaseResource; import org.hl7.fhir.instance.model.api.IIdType; -import org.junit.*; +import org.junit.AfterClass; +import org.junit.Ignore; +import org.junit.Test; -import ca.uhn.fhir.util.StopWatch; -import ca.uhn.fhir.rest.api.*; -import ca.uhn.fhir.rest.server.exceptions.*; -import ca.uhn.fhir.util.TestUtil; +import java.io.IOException; +import java.nio.charset.StandardCharsets; public class FhirResourceDaoDstu3ValidateTest extends BaseJpaDstu3Test { private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(FhirResourceDaoDstu3ValidateTest.class); @@ -153,7 +165,7 @@ public class FhirResourceDaoDstu3ValidateTest extends BaseJpaDstu3Test { String methodName = "testValidateResourceContainingProfileDeclarationInvalid"; Observation input = new Observation(); - String profileUri = "http://example.com/" + methodName; + String profileUri = "http://example.com/StructureDefinition/" + methodName; input.getMeta().getProfile().add(new IdType(profileUri)); input.addIdentifier().setSystem("http://acme").setValue("12345"); diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4ValidateTest.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4ValidateTest.java index b5d8aa2ab56..5e5e9957c97 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4ValidateTest.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4ValidateTest.java @@ -4,21 +4,35 @@ import static org.hamcrest.Matchers.containsString; import static org.junit.Assert.assertThat; import static org.junit.Assert.fail; -import java.io.IOException; -import java.nio.charset.StandardCharsets; - +import ca.uhn.fhir.rest.api.EncodingEnum; +import ca.uhn.fhir.rest.api.MethodOutcome; +import ca.uhn.fhir.rest.api.ValidationModeEnum; +import ca.uhn.fhir.rest.server.exceptions.PreconditionFailedException; +import ca.uhn.fhir.rest.server.exceptions.ResourceGoneException; +import ca.uhn.fhir.rest.server.exceptions.ResourceVersionConflictException; +import ca.uhn.fhir.rest.server.exceptions.UnprocessableEntityException; +import ca.uhn.fhir.util.StopWatch; +import ca.uhn.fhir.util.TestUtil; import org.apache.commons.io.IOUtils; -import org.hl7.fhir.r4.model.*; -import org.hl7.fhir.r4.model.Bundle.BundleEntryComponent; -import org.hl7.fhir.r4.model.Observation.ObservationStatus; import org.hl7.fhir.instance.model.api.IBaseResource; import org.hl7.fhir.instance.model.api.IIdType; -import org.junit.*; +import org.hl7.fhir.r4.model.Bundle; +import org.hl7.fhir.r4.model.Bundle.BundleEntryComponent; +import org.hl7.fhir.r4.model.CanonicalType; +import org.hl7.fhir.r4.model.IdType; +import org.hl7.fhir.r4.model.Observation; +import org.hl7.fhir.r4.model.Observation.ObservationStatus; +import org.hl7.fhir.r4.model.OperationOutcome; +import org.hl7.fhir.r4.model.Organization; +import org.hl7.fhir.r4.model.Patient; +import org.hl7.fhir.r4.model.StructureDefinition; +import org.hl7.fhir.r4.model.ValueSet; +import org.junit.AfterClass; +import org.junit.Ignore; +import org.junit.Test; -import ca.uhn.fhir.util.StopWatch; -import ca.uhn.fhir.rest.api.*; -import ca.uhn.fhir.rest.server.exceptions.*; -import ca.uhn.fhir.util.TestUtil; +import java.io.IOException; +import java.nio.charset.StandardCharsets; public class FhirResourceDaoR4ValidateTest extends BaseJpaR4Test { private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(FhirResourceDaoR4ValidateTest.class); @@ -153,7 +167,7 @@ public class FhirResourceDaoR4ValidateTest extends BaseJpaR4Test { String methodName = "testValidateResourceContainingProfileDeclarationInvalid"; Observation input = new Observation(); - String profileUri = "http://example.com/" + methodName; + String profileUri = "http://example.com/StructureDefinition/" + methodName; input.getMeta().getProfile().add(new CanonicalType(profileUri)); input.addIdentifier().setSystem("http://acme").setValue("12345");