Search in sources :

Example 21 with DefinitionException

use of org.hl7.fhir.exceptions.DefinitionException in project org.hl7.fhir.core by hapifhir.

the class JsonParser method parseChildComplexInstance.

private void parseChildComplexInstance(String npath, JsonObject object, Element context, Property property, String name, JsonElement e) throws FHIRFormatError, DefinitionException {
    if (e instanceof JsonObject) {
        JsonObject child = (JsonObject) e;
        Element n = new Element(name, property).markLocation(line(child), col(child));
        checkObject(child, npath);
        context.getChildren().add(n);
        if (property.isResource())
            parseResource(npath, child, n, property);
        else
            parseChildren(npath, child, n, false);
    } else
        logError(line(e), col(e), npath, IssueType.INVALID, "This property must be " + (property.isList() ? "an Array" : "an Object") + ", not a " + e.getClass().getName(), IssueSeverity.ERROR);
}
Also used : JsonElement(com.google.gson.JsonElement) SpecialElement(org.hl7.fhir.dstu3.elementmodel.Element.SpecialElement) JsonObject(com.google.gson.JsonObject)

Example 22 with DefinitionException

use of org.hl7.fhir.exceptions.DefinitionException in project org.hl7.fhir.core by hapifhir.

the class JsonParser method parseResource.

private void parseResource(String npath, JsonObject res, Element parent, Property elementProperty) throws DefinitionException, FHIRFormatError {
    JsonElement rt = res.get("resourceType");
    if (rt == null) {
        logError(line(res), col(res), npath, IssueType.INVALID, "Unable to find resourceType property", IssueSeverity.FATAL);
    } else {
        String name = rt.getAsString();
        StructureDefinition sd = context.fetchTypeDefinition(name);
        if (sd == null)
            throw new FHIRFormatError("Contained resource does not appear to be a FHIR resource (unknown name '" + name + "')");
        parent.updateProperty(new Property(context, sd.getSnapshot().getElement().get(0), sd), SpecialElement.fromProperty(parent.getProperty()), elementProperty);
        parent.setType(name);
        parseChildren(npath, res, parent, true);
    }
}
Also used : StructureDefinition(org.hl7.fhir.dstu3.model.StructureDefinition) JsonElement(com.google.gson.JsonElement) FHIRFormatError(org.hl7.fhir.exceptions.FHIRFormatError)

Example 23 with DefinitionException

use of org.hl7.fhir.exceptions.DefinitionException 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 24 with DefinitionException

use of org.hl7.fhir.exceptions.DefinitionException 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 25 with DefinitionException

use of org.hl7.fhir.exceptions.DefinitionException 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)

Aggregations

DefinitionException (org.hl7.fhir.exceptions.DefinitionException)186 ArrayList (java.util.ArrayList)99 XhtmlNode (org.hl7.fhir.utilities.xhtml.XhtmlNode)91 FHIRException (org.hl7.fhir.exceptions.FHIRException)50 StructureDefinition (org.hl7.fhir.r5.model.StructureDefinition)38 FHIRFormatError (org.hl7.fhir.exceptions.FHIRFormatError)32 ElementDefinition (org.hl7.fhir.r5.model.ElementDefinition)29 ValidationMessage (org.hl7.fhir.utilities.validation.ValidationMessage)29 StructureDefinition (org.hl7.fhir.r4b.model.StructureDefinition)28 IOException (java.io.IOException)27 HashMap (java.util.HashMap)24 StructureDefinition (org.hl7.fhir.dstu3.model.StructureDefinition)23 ElementDefinition (org.hl7.fhir.r4b.model.ElementDefinition)20 ElementDefinition (org.hl7.fhir.dstu3.model.ElementDefinition)17 StructureDefinition (org.hl7.fhir.r4.model.StructureDefinition)17 ElementDefinition (org.hl7.fhir.r4.model.ElementDefinition)16 XhtmlParser (org.hl7.fhir.utilities.xhtml.XhtmlParser)16 CommaSeparatedStringBuilder (org.hl7.fhir.utilities.CommaSeparatedStringBuilder)14 StructureDefinition (org.hl7.fhir.dstu2016may.model.StructureDefinition)13 StructureDefinition (org.hl7.fhir.dstu2.model.StructureDefinition)12