diff --git a/hapi-fhir-validation/src/main/java/org/hl7/fhir/dstu3/validation/InstanceValidator.java b/hapi-fhir-validation/src/main/java/org/hl7/fhir/dstu3/validation/InstanceValidator.java index b0b1826613e..1b388001c7e 100644 --- a/hapi-fhir-validation/src/main/java/org/hl7/fhir/dstu3/validation/InstanceValidator.java +++ b/hapi-fhir-validation/src/main/java/org/hl7/fhir/dstu3/validation/InstanceValidator.java @@ -105,7 +105,6 @@ import org.w3c.dom.Node; import com.google.gson.Gson; import com.google.gson.JsonObject; -import com.google.gson.stream.JsonWriter; import ca.uhn.fhir.util.ObjectUtil; @@ -293,6 +292,8 @@ public class InstanceValidator extends BaseValidator implements IResourceValidat source = Source.InstanceValidator; } + + @Override public boolean isNoInvariantChecks() { return noInvariantChecks; @@ -1357,19 +1358,33 @@ public class InstanceValidator extends BaseValidator implements IResourceValidat checkFixedValue(errors, path + ".denominator", focus.getNamedChild("denominator"), fixed.getDenominator(), "denominator", focus); } + private Reference readAsReference(Element item) { + Reference r = new Reference(); + r.setDisplay(item.getNamedChildValue("display")); + r.setReference(item.getNamedChildValue("reference")); + List identifier = item.getChildrenByName("identifier"); + if (identifier.isEmpty() == false) { + r.setIdentifier(readAsIdentifier(identifier.get(0))); + } + return r; + } + private Identifier readAsIdentifier(Element item) { + Identifier r = new Identifier(); + r.setSystem(item.getNamedChildValue("system")); + r.setValue(item.getNamedChildValue("value")); + return r; + } + private void checkReference(Object appContext, List errors, String path, Element element, StructureDefinition profile, ElementDefinition container, String parentType, NodeStack stack) throws FHIRException, IOException { - String ref = null; - try { - // Do this inside a try because invalid instances might provide more than one reference. - ref = element.getNamedChildValue("reference"); - } catch (Error e) { - - } - if (Utilities.noString(ref)) { - // todo - what should we do in this case? - warning(errors, IssueType.STRUCTURE, element.line(), element.col(), path, !Utilities.noString(element.getNamedChildValue("display")), "A Reference without an actual reference should have a display"); - return; - } + Reference reference = readAsReference(element); + + String ref = reference.getReference(); + if (Utilities.noString(ref)) { + if (Utilities.noString(reference.getIdentifier().getSystem()) && Utilities.noString(reference.getIdentifier().getValue())) { + warning(errors, IssueType.STRUCTURE, element.line(), element.col(), path, !Utilities.noString(element.getNamedChildValue("display")), "A Reference without an actual reference or identifier should have a display"); + } + return; + } Element we = localResolve(ref, stack, errors, path); String refType;