Search in sources :

Example 26 with Property

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;
}
Also used : StructureDefinition(org.hl7.fhir.dstu3.model.StructureDefinition) PrimitiveType(org.hl7.fhir.dstu3.model.PrimitiveType) ElementDefinition(org.hl7.fhir.dstu3.model.ElementDefinition) FHIRException(org.hl7.fhir.exceptions.FHIRException) Base(org.hl7.fhir.dstu3.model.Base)

Example 27 with Property

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);
            }
        }
    }
}
Also used : TypeRefComponent(org.hl7.fhir.dstu3.model.ElementDefinition.TypeRefComponent) TTLObject(org.hl7.fhir.dstu3.utils.formats.Turtle.TTLObject) HashSet(java.util.HashSet)

Example 28 with Property

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);
}
Also used : TTLComplex(org.hl7.fhir.dstu3.utils.formats.Turtle.TTLComplex) StructureDefinition(org.hl7.fhir.dstu3.model.StructureDefinition) SpecialElement(org.hl7.fhir.dstu3.elementmodel.Element.SpecialElement) FHIRFormatError(org.hl7.fhir.exceptions.FHIRFormatError) TTLURL(org.hl7.fhir.dstu3.utils.formats.Turtle.TTLURL) TTLObject(org.hl7.fhir.dstu3.utils.formats.Turtle.TTLObject) TTLList(org.hl7.fhir.dstu3.utils.formats.Turtle.TTLList)

Example 29 with Property

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;
}
Also used : StructureDefinition(org.hl7.fhir.dstu3.model.StructureDefinition) SpecialElement(org.hl7.fhir.dstu3.elementmodel.Element.SpecialElement)

Example 30 with Property

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;
}
Also used : StructureDefinition(org.hl7.fhir.dstu3.model.StructureDefinition) SpecialElement(org.hl7.fhir.dstu3.elementmodel.Element.SpecialElement)

Aggregations

ArrayList (java.util.ArrayList)36 FHIRException (org.hl7.fhir.exceptions.FHIRException)35 DefinitionException (org.hl7.fhir.exceptions.DefinitionException)30 JsonElement (com.google.gson.JsonElement)23 FHIRFormatError (org.hl7.fhir.exceptions.FHIRFormatError)21 List (java.util.List)15 StructureDefinition (org.hl7.fhir.dstu3.model.StructureDefinition)15 JsonObject (com.google.gson.JsonObject)14 StructureDefinition (org.hl7.fhir.r4.model.StructureDefinition)14 Complex (org.hl7.fhir.r4.utils.formats.Turtle.Complex)13 StructureDefinition (org.hl7.fhir.r4b.model.StructureDefinition)13 StructureDefinition (org.hl7.fhir.r5.model.StructureDefinition)13 Test (org.junit.jupiter.api.Test)13 ElementDefinition (org.hl7.fhir.dstu3.model.ElementDefinition)11 Map (java.util.Map)10 Property (com.adobe.target.delivery.v1.model.Property)9 TargetDeliveryRequest (com.adobe.target.edge.client.model.TargetDeliveryRequest)9 HashMap (java.util.HashMap)9 Collectors (java.util.stream.Collectors)9 Context (com.adobe.target.delivery.v1.model.Context)8