update parsers to record the element format for logical model validation
This commit is contained in:
parent
6c08e58d7a
commit
1ba4d276c0
|
@ -38,6 +38,7 @@ import org.apache.commons.lang3.Validate;
|
|||
import org.hl7.fhir.exceptions.FHIRException;
|
||||
import org.hl7.fhir.r5.conformance.profile.ProfileUtilities;
|
||||
import org.hl7.fhir.r5.context.ContextUtilities;
|
||||
import org.hl7.fhir.r5.elementmodel.Manager.FhirFormat;
|
||||
import org.hl7.fhir.r5.extensions.ExtensionsUtils;
|
||||
import org.hl7.fhir.r5.model.Base;
|
||||
import org.hl7.fhir.r5.model.DataType;
|
||||
|
@ -130,6 +131,7 @@ public class Element extends Base implements NamedItem {
|
|||
private boolean isNull;
|
||||
private Base source;
|
||||
private boolean ignorePropertyOrder;
|
||||
private FhirFormat format;
|
||||
|
||||
public Element(String name) {
|
||||
super();
|
||||
|
@ -421,7 +423,7 @@ public class Element extends Base implements NamedItem {
|
|||
childForValue = child;
|
||||
break;
|
||||
} else {
|
||||
Element ne = new Element(child);
|
||||
Element ne = new Element(child).setFormat(format);
|
||||
children.add(ne);
|
||||
numberChildren();
|
||||
childForValue = ne;
|
||||
|
@ -442,7 +444,7 @@ public class Element extends Base implements NamedItem {
|
|||
if (t >= i)
|
||||
i = t+1;
|
||||
if (p.getName().equals(name) || p.getName().equals(name+"[x]")) {
|
||||
Element ne = new Element(name, p);
|
||||
Element ne = new Element(name, p).setFormat(format);
|
||||
children.add(i, ne);
|
||||
childForValue = ne;
|
||||
break;
|
||||
|
@ -504,7 +506,7 @@ public class Element extends Base implements NamedItem {
|
|||
if (!child.isList()) {
|
||||
return child;
|
||||
} else {
|
||||
Element ne = new Element(child);
|
||||
Element ne = new Element(child).setFormat(format);
|
||||
children.add(ne);
|
||||
numberChildren();
|
||||
return ne;
|
||||
|
@ -514,7 +516,7 @@ public class Element extends Base implements NamedItem {
|
|||
|
||||
for (Property p : property.getChildProperties(this.name, type)) {
|
||||
if (p.getName().equals(name)) {
|
||||
Element ne = new Element(name, p);
|
||||
Element ne = new Element(name, p).setFormat(format);
|
||||
children.add(ne);
|
||||
return ne;
|
||||
} else if (p.getDefinition().isChoice() && name.startsWith(p.getName().replace("[x]", ""))) {
|
||||
|
@ -522,7 +524,7 @@ public class Element extends Base implements NamedItem {
|
|||
if (property.getContext().isPrimitiveType(Utilities.uncapitalize(type))) {
|
||||
type = Utilities.uncapitalize(type);
|
||||
}
|
||||
Element ne = new Element(name, p);
|
||||
Element ne = new Element(name, p).setFormat(format);
|
||||
ne.setType(type);
|
||||
children.add(ne);
|
||||
return ne;
|
||||
|
@ -546,7 +548,7 @@ public class Element extends Base implements NamedItem {
|
|||
|
||||
for (Property p : property.getChildProperties(this.name, type)) {
|
||||
if (p.getName().equals(name)) {
|
||||
Element ne = new Element(name, p);
|
||||
Element ne = new Element(name, p).setFormat(format);
|
||||
children.add(ne);
|
||||
return ne;
|
||||
}
|
||||
|
@ -1295,7 +1297,7 @@ public class Element extends Base implements NamedItem {
|
|||
if (!p.isList() && hasChild(name)) {
|
||||
throw new Error(name+" on "+this.name+" is not a list, so can't add an element");
|
||||
}
|
||||
Element ne = new Element(name, p);
|
||||
Element ne = new Element(name, p).setFormat(format);
|
||||
children.add(ne);
|
||||
return ne;
|
||||
}
|
||||
|
@ -1344,6 +1346,7 @@ public class Element extends Base implements NamedItem {
|
|||
dest.instanceId = instanceId;
|
||||
dest.isNull = isNull;
|
||||
dest.source = source;
|
||||
dest.format = format;
|
||||
}
|
||||
|
||||
public Base setProperty(String name, Base value) throws FHIRException {
|
||||
|
@ -1466,4 +1469,13 @@ public class Element extends Base implements NamedItem {
|
|||
}
|
||||
}
|
||||
|
||||
public FhirFormat getFormat() {
|
||||
return format;
|
||||
}
|
||||
|
||||
public Element setFormat(FhirFormat format) {
|
||||
this.format = format;
|
||||
return this;
|
||||
}
|
||||
|
||||
}
|
|
@ -52,6 +52,7 @@ import org.hl7.fhir.r5.conformance.profile.ProfileUtilities;
|
|||
import org.hl7.fhir.r5.context.ContextUtilities;
|
||||
import org.hl7.fhir.r5.context.IWorkerContext;
|
||||
import org.hl7.fhir.r5.elementmodel.Element.SpecialElement;
|
||||
import org.hl7.fhir.r5.elementmodel.Manager.FhirFormat;
|
||||
import org.hl7.fhir.r5.formats.IParser.OutputStyle;
|
||||
import org.hl7.fhir.r5.formats.JsonCreator;
|
||||
import org.hl7.fhir.r5.formats.JsonCreatorCanonical;
|
||||
|
@ -108,7 +109,7 @@ public class JsonParser extends ParserBase {
|
|||
// if (sd == null)
|
||||
// return null;
|
||||
//
|
||||
// Element result = new Element(type, new Property(context, sd.getSnapshot().getElement().get(0), sd, this.profileUtilities));
|
||||
// Element result = new Element(type, new Property(context, sd.getSnapshot().getElement().get(0), sd, this.profileUtilities)).setFormat(FhirFormat.JSON);
|
||||
// result.setPath(type);
|
||||
// checkObject(obj, result, path);
|
||||
// result.setType(type);
|
||||
|
@ -179,7 +180,7 @@ public class JsonParser extends ParserBase {
|
|||
name = sd.getType();
|
||||
path = sd.getTypeTail();
|
||||
}
|
||||
baseElement = new Element(name, new Property(context, sd.getSnapshot().getElement().get(0), sd, this.profileUtilities));
|
||||
baseElement = new Element(name, new Property(context, sd.getSnapshot().getElement().get(0), sd, this.profileUtilities)).setFormat(FhirFormat.JSON);
|
||||
checkObject(errors, object, baseElement, path);
|
||||
baseElement.markLocation(line(object), col(object));
|
||||
baseElement.setType(name);
|
||||
|
@ -433,12 +434,12 @@ public class JsonParser extends ParserBase {
|
|||
String npathArr = path+"."+property.getName()+"["+i+"]";
|
||||
String fpathArr = element.getPath()+"."+property.getName()+"["+i+"]";
|
||||
|
||||
Element n = new Element(name, property).markLocation(line(pv.getValue()), col(pv.getValue()));
|
||||
Element n = new Element(name, property).markLocation(line(pv.getValue()), col(pv.getValue())).setFormat(FhirFormat.JSON);
|
||||
n.setPath(fpath);
|
||||
element.getChildren().add(n);
|
||||
// handle the key
|
||||
String fpathKey = fpathArr+"."+propK.getName();
|
||||
Element nKey = new Element(code, propK).markLocation(line(pv.getValue()), col(pv.getValue()));
|
||||
Element nKey = new Element(code, propK).markLocation(line(pv.getValue()), col(pv.getValue())).setFormat(FhirFormat.JSON);
|
||||
checkComments(errors, pv.getValue(), n, fpathArr);
|
||||
nKey.setPath(fpathKey);
|
||||
n.getChildren().add(nKey);
|
||||
|
@ -524,7 +525,7 @@ public class JsonParser extends ParserBase {
|
|||
}
|
||||
if (e instanceof JsonObject) {
|
||||
JsonObject child = (JsonObject) e;
|
||||
Element n = new Element(name, property).markLocation(line(child), col(child));
|
||||
Element n = new Element(name, property).markLocation(line(child), col(child)).setFormat(FhirFormat.JSON);
|
||||
n.setPath(fpath);
|
||||
checkComments(errors, commentContext, n, commentPath);
|
||||
checkObject(errors, child, n, npath);
|
||||
|
@ -537,7 +538,7 @@ public class JsonParser extends ParserBase {
|
|||
} else if (property.isNullable() && e instanceof JsonNull) {
|
||||
// we create an element marked as a null element so we know something was present
|
||||
JsonNull child = (JsonNull) e;
|
||||
Element n = new Element(name, property).markLocation(line(child), col(child));
|
||||
Element n = new Element(name, property).markLocation(line(child), col(child)).setFormat(FhirFormat.JSON);
|
||||
checkComments(errors, commentContext, n, commentPath);
|
||||
checkComments(errors, child, n, fpath);
|
||||
n.setPath(fpath);
|
||||
|
@ -632,7 +633,7 @@ public class JsonParser extends ParserBase {
|
|||
} else if (fork != null && !(fork instanceof JsonObject)) {
|
||||
logError(errors, ValidationMessage.NO_RULE_DATE, line(fork), col(fork), npath, IssueType.INVALID, context.formatMessage(I18nConstants.THIS_PROPERTY_MUST_BE_AN_OBJECT_NOT_, describe(fork), name, npath), IssueSeverity.ERROR);
|
||||
} else {
|
||||
Element n = new Element(isJsonName ? property.getName() : name, property).markLocation(line(main != null ? main : fork), col(main != null ? main : fork));
|
||||
Element n = new Element(isJsonName ? property.getName() : name, property).markLocation(line(main != null ? main : fork), col(main != null ? main : fork)).setFormat(FhirFormat.JSON);
|
||||
if (main != null) {
|
||||
checkComments(errors, main, n, npath);
|
||||
}
|
||||
|
|
|
@ -45,6 +45,7 @@ import org.hl7.fhir.exceptions.FHIRException;
|
|||
import org.hl7.fhir.exceptions.FHIRFormatError;
|
||||
import org.hl7.fhir.r5.context.IWorkerContext;
|
||||
import org.hl7.fhir.r5.elementmodel.Element.SpecialElement;
|
||||
import org.hl7.fhir.r5.elementmodel.Manager.FhirFormat;
|
||||
import org.hl7.fhir.r5.formats.IParser.OutputStyle;
|
||||
import org.hl7.fhir.r5.model.ElementDefinition.TypeRefComponent;
|
||||
import org.hl7.fhir.r5.model.StructureDefinition;
|
||||
|
@ -150,7 +151,7 @@ public class TurtleParser extends ParserBase {
|
|||
if (sd == null)
|
||||
return null;
|
||||
|
||||
Element result = new Element(name, new Property(context, sd.getSnapshot().getElement().get(0), sd));
|
||||
Element result = new Element(name, new Property(context, sd.getSnapshot().getElement().get(0), sd)).setFormat(FhirFormat.TURTLE);
|
||||
result.markLocation(cmp.getLine(), cmp.getCol());
|
||||
result.setType(name);
|
||||
parseChildren(errors, src, path, cmp, result, false);
|
||||
|
@ -210,7 +211,7 @@ public class TurtleParser extends ParserBase {
|
|||
parseResource(errors, src, npath, object, element, property, name, e);
|
||||
else if (e instanceof TTLComplex) {
|
||||
TTLComplex child = (TTLComplex) e;
|
||||
Element n = new Element(tail(name), property).markLocation(e.getLine(), e.getCol());
|
||||
Element n = new Element(tail(name), property).markLocation(e.getLine(), e.getCol()).setFormat(FhirFormat.TURTLE);
|
||||
element.getChildren().add(n);
|
||||
if (property.isPrimitive(property.getType(tail(name)))) {
|
||||
parseChildren(errors, src, npath, child, n, true);
|
||||
|
@ -276,7 +277,7 @@ public class TurtleParser extends ParserBase {
|
|||
if (sd == null)
|
||||
return;
|
||||
|
||||
Element n = new Element(tail(name), property).markLocation(object.getLine(), object.getCol());
|
||||
Element n = new Element(tail(name), property).markLocation(object.getLine(), object.getCol()).setFormat(FhirFormat.TURTLE);
|
||||
element.getChildren().add(n);
|
||||
n.updateProperty(new Property(this.context, sd.getSnapshot().getElement().get(0), sd), SpecialElement.fromProperty(n.getProperty()), property);
|
||||
n.setType(rt);
|
||||
|
|
|
@ -57,6 +57,7 @@ import org.hl7.fhir.exceptions.FHIRFormatError;
|
|||
import org.hl7.fhir.r5.conformance.profile.ProfileUtilities;
|
||||
import org.hl7.fhir.r5.context.IWorkerContext;
|
||||
import org.hl7.fhir.r5.elementmodel.Element.SpecialElement;
|
||||
import org.hl7.fhir.r5.elementmodel.Manager.FhirFormat;
|
||||
import org.hl7.fhir.r5.formats.FormatUtilities;
|
||||
import org.hl7.fhir.r5.formats.IParser.OutputStyle;
|
||||
import org.hl7.fhir.r5.model.DateTimeType;
|
||||
|
@ -228,7 +229,7 @@ public class XmlParser extends ParserBase {
|
|||
if (sd == null)
|
||||
return null;
|
||||
|
||||
Element result = new Element(element.getLocalName(), new Property(context, sd.getSnapshot().getElement().get(0), sd));
|
||||
Element result = new Element(element.getLocalName(), new Property(context, sd.getSnapshot().getElement().get(0), sd)).setFormat(FhirFormat.XML);
|
||||
result.setPath(element.getLocalName());
|
||||
checkElement(errors, element, path, result.getProperty());
|
||||
result.markLocation(line(element, false), col(element, false));
|
||||
|
@ -288,7 +289,7 @@ public class XmlParser extends ParserBase {
|
|||
|
||||
public Element parse(List<ValidationMessage> errors, org.w3c.dom.Element base, String type) throws Exception {
|
||||
StructureDefinition sd = getDefinition(errors, 0, 0, FormatUtilities.FHIR_NS, type);
|
||||
Element result = new Element(base.getLocalName(), new Property(context, sd.getSnapshot().getElement().get(0), sd));
|
||||
Element result = new Element(base.getLocalName(), new Property(context, sd.getSnapshot().getElement().get(0), sd)).setFormat(FhirFormat.XML);
|
||||
result.setPath(base.getLocalName());
|
||||
String path = "/"+pathPrefix(base.getNamespaceURI())+base.getLocalName();
|
||||
checkElement(errors, base, path, result.getProperty());
|
||||
|
@ -311,16 +312,16 @@ public class XmlParser extends ParserBase {
|
|||
if (property != null) {
|
||||
if ("ED.data[x]".equals(property.getDefinition().getId()) || (property.getDefinition()!=null && property.getDefinition().getBase()!=null && "ED.data[x]".equals(property.getDefinition().getBase().getPath()))) {
|
||||
if ("B64".equals(node.getAttribute("representation"))) {
|
||||
Element n = new Element("dataBase64Binary", property, "base64Binary", text).markLocation(line, col);
|
||||
Element n = new Element("dataBase64Binary", property, "base64Binary", text).markLocation(line, col).setFormat(FhirFormat.XML);
|
||||
n.setPath(element.getPath()+"."+property.getName());
|
||||
element.getChildren().add(n);
|
||||
} else {
|
||||
Element n = new Element("dataString", property, "string", text).markLocation(line, col);
|
||||
Element n = new Element("dataString", property, "string", text).markLocation(line, col).setFormat(FhirFormat.XML);
|
||||
n.setPath(element.getPath()+"."+property.getName());
|
||||
element.getChildren().add(n);
|
||||
}
|
||||
} else {
|
||||
Element n = new Element(property.getName(), property, property.getType(), text).markLocation(line, col);
|
||||
Element n = new Element(property.getName(), property, property.getType(), text).markLocation(line, col).setFormat(FhirFormat.XML);
|
||||
n.setPath(element.getPath()+"."+property.getName());
|
||||
element.getChildren().add(n);
|
||||
}
|
||||
|
@ -368,7 +369,7 @@ public class XmlParser extends ParserBase {
|
|||
vl = av.split(" ");
|
||||
}
|
||||
for (String v : vl) {
|
||||
Element n = new Element(property.getName(), property, property.getType(), v).markLocation(line, col);
|
||||
Element n = new Element(property.getName(), property, property.getType(), v).markLocation(line, col).setFormat(FhirFormat.XML);
|
||||
n.setPath(element.getPath()+"."+property.getName());
|
||||
element.getChildren().add(n);
|
||||
}
|
||||
|
@ -415,12 +416,12 @@ public class XmlParser extends ParserBase {
|
|||
}
|
||||
}
|
||||
}
|
||||
Element n = new Element(property.getName(), property, "xhtml", new XhtmlComposer(XhtmlComposer.XML, false).compose(xhtml)).setXhtml(xhtml).markLocation(line(child, false), col(child, false));
|
||||
Element n = new Element(property.getName(), property, "xhtml", new XhtmlComposer(XhtmlComposer.XML, false).compose(xhtml)).setXhtml(xhtml).markLocation(line(child, false), col(child, false)).setFormat(FhirFormat.XML);
|
||||
n.setPath(element.getPath()+"."+property.getName());
|
||||
element.getChildren().add(n);
|
||||
} else {
|
||||
String npath = path+"/"+pathPrefix(child.getNamespaceURI())+child.getLocalName();
|
||||
Element n = new Element(child.getLocalName(), property).markLocation(line(child, false), col(child, false));
|
||||
Element n = new Element(child.getLocalName(), property).markLocation(line(child, false), col(child, false)).setFormat(FhirFormat.XML);
|
||||
if (property.isList()) {
|
||||
n.setPath(element.getPath()+"."+property.getName()+"["+repeatCount+"]");
|
||||
} else {
|
||||
|
|
Loading…
Reference in New Issue