use of org.hl7.fhir.r5.elementmodel.Property in project org.hl7.fhir.core by hapifhir.
the class TurtleParser method parseResource.
private void parseResource(Turtle src, String npath, TTLComplex object, Element element, Property property, String name, TTLObject e) throws FHIRException {
TTLComplex obj;
if (e instanceof TTLComplex)
obj = (TTLComplex) e;
else if (e instanceof TTLURL) {
String url = ((TTLURL) e).getUri();
obj = src.getObject(url);
if (obj == null) {
logError(e.getLine(), e.getCol(), npath, IssueType.INVALID, context.formatMessage(I18nConstants.REFERENCE_TO__CANNOT_BE_RESOLVED, url), IssueSeverity.FATAL);
return;
}
} else
throw new FHIRFormatError(context.formatMessage(I18nConstants.WRONG_TYPE_FOR_RESOURCE));
TTLObject type = obj.getPredicates().get("http://www.w3.org/2000/01/rdf-schema#type");
if (type == null) {
logError(object.getLine(), object.getCol(), npath, IssueType.INVALID, context.formatMessage(I18nConstants.UNKNOWN_RESOURCE_TYPE_MISSING_RDFSTYPE), IssueSeverity.FATAL);
return;
}
if (type instanceof TTLList) {
// this is actually broken - really we have to look through the structure definitions at this point
for (TTLObject tobj : ((TTLList) type).getList()) {
if (tobj instanceof TTLURL && ((TTLURL) tobj).getUri().startsWith(FHIR_URI_BASE)) {
type = tobj;
break;
}
}
}
if (!(type instanceof TTLURL)) {
logError(object.getLine(), object.getCol(), npath, IssueType.INVALID, context.formatMessage(I18nConstants.UNEXPECTED_DATATYPE_FOR_RDFSTYPE), IssueSeverity.FATAL);
return;
}
String rt = ((TTLURL) type).getUri();
String ns = rt.substring(0, rt.lastIndexOf("/"));
rt = rt.substring(rt.lastIndexOf("/") + 1);
StructureDefinition sd = getDefinition(object.getLine(), object.getCol(), ns, rt);
if (sd == null)
return;
Element n = new Element(tail(name), property).markLocation(object.getLine(), object.getCol());
element.getChildren().add(n);
n.updateProperty(new Property(this.context, sd.getSnapshot().getElement().get(0), sd), SpecialElement.fromProperty(n.getProperty()), property);
n.setType(rt);
parseChildren(src, npath, obj, n, false);
}
use of org.hl7.fhir.r5.elementmodel.Property in project org.hl7.fhir.core by hapifhir.
the class TurtleParser method parse.
private Element parse(Turtle src, TTLComplex cmp) throws FHIRException {
TTLObject type = cmp.getPredicates().get("http://www.w3.org/2000/01/rdf-schema#type");
if (type == null) {
logError(cmp.getLine(), cmp.getCol(), "(document)", IssueType.INVALID, context.formatMessage(I18nConstants.UNKNOWN_RESOURCE_TYPE_MISSING_RDFSTYPE), IssueSeverity.FATAL);
return null;
}
if (type instanceof TTLList) {
// this is actually broken - really we have to look through the structure definitions at this point
for (TTLObject obj : ((TTLList) type).getList()) {
if (obj instanceof TTLURL && ((TTLURL) obj).getUri().startsWith(FHIR_URI_BASE)) {
type = obj;
break;
}
}
}
if (!(type instanceof TTLURL)) {
logError(cmp.getLine(), cmp.getCol(), "(document)", IssueType.INVALID, context.formatMessage(I18nConstants.UNEXPECTED_DATATYPE_FOR_RDFSTYPE), IssueSeverity.FATAL);
return null;
}
String name = ((TTLURL) type).getUri();
String ns = name.substring(0, name.lastIndexOf("/"));
name = name.substring(name.lastIndexOf("/") + 1);
String path = "/" + name;
StructureDefinition sd = getDefinition(cmp.getLine(), cmp.getCol(), ns, name);
if (sd == null)
return null;
Element result = new Element(name, new Property(context, sd.getSnapshot().getElement().get(0), sd));
result.markLocation(cmp.getLine(), cmp.getCol());
result.setType(name);
parseChildren(src, path, cmp, result, false);
result.numberChildren();
return result;
}
use of org.hl7.fhir.r5.elementmodel.Property in project org.hl7.fhir.core by hapifhir.
the class XmlParser method parse.
public Element parse(org.w3c.dom.Element element) throws FHIRFormatError, DefinitionException, FHIRException, IOException {
String ns = element.getNamespaceURI();
String name = element.getLocalName();
String path = "/" + pathPrefix(ns) + name;
StructureDefinition sd = getDefinition(line(element), col(element), (ns == null ? "noNamespace" : ns), name);
if (sd == null)
return null;
Element result = new Element(element.getLocalName(), new Property(context, sd.getSnapshot().getElement().get(0), sd));
result.setPath(element.getLocalName());
checkElement(element, path, result.getProperty());
result.markLocation(line(element), col(element));
result.setType(element.getLocalName());
parseChildren(path, element, result);
result.numberChildren();
return result;
}
use of org.hl7.fhir.r5.elementmodel.Property in project org.hl7.fhir.core by hapifhir.
the class XmlParser method parse.
public Element parse(org.w3c.dom.Element base, String type) throws Exception {
StructureDefinition sd = getDefinition(0, 0, FormatUtilities.FHIR_NS, type);
Element result = new Element(base.getLocalName(), new Property(context, sd.getSnapshot().getElement().get(0), sd));
result.setPath(base.getLocalName());
String path = "/" + pathPrefix(base.getNamespaceURI()) + base.getLocalName();
checkElement(base, path, result.getProperty());
result.setType(base.getLocalName());
parseChildren(path, base, result);
result.numberChildren();
return result;
}
use of org.hl7.fhir.r5.elementmodel.Property in project org.hl7.fhir.core by hapifhir.
the class Property method getChildProperties.
protected List<Property> getChildProperties(String elementName, String statedType) throws FHIRException {
ElementDefinition ed = definition;
StructureDefinition sd = structure;
List<ElementDefinition> children = profileUtilities.getChildMap(sd, ed);
String url = null;
if (children.isEmpty() || isElementWithOnlyExtension(ed, children)) {
// ok, find the right definitions
String t = null;
if (ed.getType().size() == 1)
t = ed.getType().get(0).getWorkingCode();
else if (ed.getType().size() == 0)
throw new Error("types == 0, and no children found on " + getDefinition().getPath());
else {
t = ed.getType().get(0).getWorkingCode();
boolean all = true;
for (TypeRefComponent tr : ed.getType()) {
if (!tr.getWorkingCode().equals(t)) {
all = false;
break;
}
}
if (!all) {
// ok, it's polymorphic
if (ed.hasRepresentation(PropertyRepresentation.TYPEATTR)) {
t = statedType;
if (t == null && ToolingExtensions.hasExtension(ed, "http://hl7.org/fhir/StructureDefinition/elementdefinition-defaulttype"))
t = ToolingExtensions.readStringExtension(ed, "http://hl7.org/fhir/StructureDefinition/elementdefinition-defaulttype");
boolean ok = false;
for (TypeRefComponent tr : ed.getType()) {
if (tr.getWorkingCode().equals(t))
ok = true;
if (Utilities.isAbsoluteUrl(tr.getWorkingCode())) {
StructureDefinition sdt = context.fetchResource(StructureDefinition.class, tr.getWorkingCode());
if (sdt != null && sdt.getType().equals(t)) {
url = tr.getWorkingCode();
ok = true;
}
}
if (ok)
break;
}
if (!ok)
throw new DefinitionException("Type '" + t + "' is not an acceptable type for '" + elementName + "' on property " + definition.getPath());
} else {
t = elementName.substring(tail(ed.getPath()).length() - 3);
if (isPrimitive(lowFirst(t)))
t = lowFirst(t);
}
}
}
if (!"xhtml".equals(t)) {
for (TypeRefComponent aType : ed.getType()) {
if (aType.getWorkingCode().equals(t)) {
if (aType.hasProfile()) {
assert aType.getProfile().size() == 1;
url = aType.getProfile().get(0).getValue();
} else {
url = ProfileUtilities.sdNs(t, context.getOverrideVersionNs());
}
break;
}
}
if (url == null)
throw new FHIRException("Unable to find type " + t + " for element " + elementName + " with path " + ed.getPath());
sd = context.fetchResource(StructureDefinition.class, url);
if (sd == null)
throw new DefinitionException("Unable to find type '" + t + "' for name '" + elementName + "' on property " + definition.getPath());
children = profileUtilities.getChildMap(sd, sd.getSnapshot().getElement().get(0));
}
}
List<Property> properties = new ArrayList<Property>();
for (ElementDefinition child : children) {
properties.add(new Property(context, child, sd, this.profileUtilities));
}
return properties;
}
Aggregations