use of org.hl7.fhir.dstu2.model.Property in project org.hl7.fhir.core by hapifhir.
the class ObjectConverter method convertElement.
private Element convertElement(Property property, Base base) throws FHIRException {
if (base == null)
return null;
String tn = base.fhirType();
StructureDefinition sd = context.fetchTypeDefinition(tn);
if (sd == null)
throw new FHIRException("Unable to find definition for type " + tn);
Element res = new Element(property.getName(), property);
if (sd.getKind() == StructureDefinitionKind.PRIMITIVETYPE)
res.setValue(((PrimitiveType) base).asStringValue());
List<ElementDefinition> children = ProfileUtilities.getChildMap(sd, sd.getSnapshot().getElementFirstRep());
for (ElementDefinition child : children) {
String n = tail(child.getPath());
if (sd.getKind() != StructureDefinitionKind.PRIMITIVETYPE || !"value".equals(n)) {
Base[] values = base.getProperty(n.hashCode(), n, false);
if (values != null)
for (Base value : values) {
res.getChildren().add(convertElement(new Property(context, child, sd), value));
}
}
}
return res;
}
use of org.hl7.fhir.dstu2.model.Property in project org.hl7.fhir.core by hapifhir.
the class TurtleParser method parseChildren.
private void parseChildren(Turtle src, String path, TTLComplex object, Element context, boolean primitive) throws FHIRFormatError, DefinitionException {
List<Property> properties = context.getProperty().getChildProperties(context.getName(), null);
Set<String> processed = new HashSet<String>();
if (primitive)
processed.add(FHIR_URI_BASE + "value");
// first pass: process the properties
for (Property property : properties) {
if (property.isChoice()) {
for (TypeRefComponent type : property.getDefinition().getType()) {
String eName = property.getName().substring(0, property.getName().length() - 3) + Utilities.capitalize(type.getCode());
parseChild(src, object, context, processed, property, path, getFormalName(property, eName));
}
} else {
parseChild(src, object, context, processed, property, path, getFormalName(property));
}
}
// second pass: check for things not processed
if (policy != ValidationPolicy.NONE) {
for (String u : object.getPredicates().keySet()) {
if (!processed.contains(u)) {
TTLObject n = object.getPredicates().get(u);
logError(n.getLine(), n.getCol(), path, IssueType.STRUCTURE, "Unrecognised predicate '" + u + "'", IssueSeverity.ERROR);
}
}
}
}
use of org.hl7.fhir.dstu2.model.Property in project org.hl7.fhir.core by hapifhir.
the class TurtleParser method parseResource.
private void parseResource(Turtle src, String npath, TTLComplex object, Element context, Property property, String name, TTLObject e) throws FHIRFormatError, DefinitionException {
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, "reference to " + url + " cannot be resolved", IssueSeverity.FATAL);
return;
}
} else
throw new FHIRFormatError("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, "Unknown resource type (missing rdfs:type)", 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, "Unexpected datatype for rdfs:type)", 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());
context.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.dstu2.model.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, name);
if (sd == null)
return null;
Element result = new Element(element.getLocalName(), new Property(context, sd.getSnapshot().getElement().get(0), sd));
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.dstu2.model.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));
String path = "/" + pathPrefix(base.getNamespaceURI()) + base.getLocalName();
checkElement(base, path, result.getProperty());
result.setType(base.getLocalName());
parseChildren(path, base, result);
result.numberChildren();
return result;
}
Aggregations