diff --git a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/elementmodel/JsonParser.java b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/elementmodel/JsonParser.java index 36c035486..54898341b 100644 --- a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/elementmodel/JsonParser.java +++ b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/elementmodel/JsonParser.java @@ -481,6 +481,8 @@ public class JsonParser extends ParserBase { } else if (propV.hasType(type)) { pvl = new Property(propV.getContext(), propV.getDefinition(), propV.getStructure(), propV.getUtils(), propV.getContextUtils(), type); ok = true; + } else if (propV.getDefinition().getType().size() == 1 && propV.typeIsConsistent(type)) { + pvl = new Property(propV.getContext(), propV.getDefinition(), propV.getStructure(), propV.getUtils(), propV.getContextUtils(), propV.getType()); } else { logError(errors, ValidationMessage.NO_RULE_DATE, line(pv.getValue()), col(pv.getValue()), path, IssueType.STRUCTURE, this.context.formatMessage(I18nConstants.UNRECOGNISED_PROPERTY_TYPE_WRONG, describeType(pv.getValue()), propV.getName(), type, propV.typeSummary()), IssueSeverity.ERROR); } diff --git a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/elementmodel/Property.java b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/elementmodel/Property.java index f707b3f7a..22d3c07ce 100644 --- a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/elementmodel/Property.java +++ b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/elementmodel/Property.java @@ -205,14 +205,35 @@ public class Property { return ed.getType().get(0).getWorkingCode(); } - public boolean hasType(String elementName) { + public boolean typeIsConsistent(String typeName) { + for (TypeRefComponent tr : definition.getType()) { + if (typeName.equals(tr.getWorkingCode()) || typeSpecializes(tr.getWorkingCode(), typeName)) { + return true; + } + } + return false; + } + + + private boolean typeSpecializes(String workingCode, String typeName) { + if ("string".equals(typeName)) { + return Utilities.existsInList(workingCode, "uri", "oid", "canonical", "url", "uuid", "id", "markdown"); + } + if ("integer".equals(typeName)) { + return Utilities.existsInList(workingCode, "positiveInt", "unsignedInt"); + } + return false; + } + + + public boolean hasType(String typeName) { if (type != null) { return false; // ? } else if (definition.getType().size() == 0) { return false; } else if (isJsonPrimitiveChoice()) { for (TypeRefComponent tr : definition.getType()) { - if (elementName.equals(tr.getWorkingCode())) { + if (typeName.equals(tr.getWorkingCode())) { return true; } } @@ -227,7 +248,7 @@ public class Property { if (all) return true; String tail = definition.getPath().substring(definition.getPath().lastIndexOf(".")+1); - if (tail.endsWith("[x]") && elementName.startsWith(tail.substring(0, tail.length()-3))) { + if (tail.endsWith("[x]") && typeName.startsWith(tail.substring(0, tail.length()-3))) { // String name = elementName.substring(tail.length()-3); return true; } else @@ -706,5 +727,5 @@ public class Property { return false; } - + } \ No newline at end of file