Search in sources :

Example 11 with TTLObject

use of org.hl7.fhir.utilities.turtle.Turtle.TTLObject 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 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, "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.r4.utils.formats.Turtle.TTLComplex) StructureDefinition(org.hl7.fhir.r4.model.StructureDefinition) SpecialElement(org.hl7.fhir.r4.elementmodel.Element.SpecialElement) FHIRFormatError(org.hl7.fhir.exceptions.FHIRFormatError) TTLURL(org.hl7.fhir.r4.utils.formats.Turtle.TTLURL) TTLObject(org.hl7.fhir.r4.utils.formats.Turtle.TTLObject) TTLList(org.hl7.fhir.r4.utils.formats.Turtle.TTLList)

Example 12 with TTLObject

use of org.hl7.fhir.utilities.turtle.Turtle.TTLObject in project org.hl7.fhir.core by hapifhir.

the class TurtleParser method parse.

private Element parse(Turtle src, TTLComplex cmp) throws FHIRFormatError, DefinitionException {
    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, "Unknown resource type (missing rdfs:type)", 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, "Unexpected datatype for rdfs:type)", 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;
}
Also used : StructureDefinition(org.hl7.fhir.dstu3.model.StructureDefinition) SpecialElement(org.hl7.fhir.dstu3.elementmodel.Element.SpecialElement) 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 13 with TTLObject

use of org.hl7.fhir.utilities.turtle.Turtle.TTLObject in project org.hl7.fhir.core by hapifhir.

the class TurtleParser method parseChild.

private void parseChild(Turtle src, TTLComplex object, Element context, Set<String> processed, Property property, String path, String name) throws FHIRFormatError, DefinitionException {
    processed.add(name);
    String npath = path + "/" + property.getName();
    TTLObject e = object.getPredicates().get(FHIR_URI_BASE + name);
    if (e == null)
        return;
    if (property.isList() && (e instanceof TTLList)) {
        TTLList arr = (TTLList) e;
        for (TTLObject am : arr.getList()) {
            parseChildInstance(src, npath, object, context, property, name, am);
        }
    } else {
        parseChildInstance(src, npath, object, context, property, name, e);
    }
}
Also used : TTLObject(org.hl7.fhir.dstu3.utils.formats.Turtle.TTLObject) TTLList(org.hl7.fhir.dstu3.utils.formats.Turtle.TTLList)

Example 14 with TTLObject

use of org.hl7.fhir.utilities.turtle.Turtle.TTLObject in project org.hl7.fhir.core by hapifhir.

the class TurtleParser method parseChild.

private void parseChild(Turtle src, TTLComplex object, Element context, Set<String> processed, Property property, String path, String name) throws FHIRException {
    processed.add(name);
    String npath = path + "/" + property.getName();
    TTLObject e = object.getPredicates().get(FHIR_URI_BASE + name);
    if (e == null)
        return;
    if (property.isList() && (e instanceof TTLList)) {
        TTLList arr = (TTLList) e;
        for (TTLObject am : arr.getList()) {
            parseChildInstance(src, npath, object, context, property, name, am);
        }
    } else {
        parseChildInstance(src, npath, object, context, property, name, e);
    }
}
Also used : TTLObject(org.hl7.fhir.utilities.turtle.Turtle.TTLObject) TTLList(org.hl7.fhir.utilities.turtle.Turtle.TTLList)

Example 15 with TTLObject

use of org.hl7.fhir.utilities.turtle.Turtle.TTLObject in project org.hl7.fhir.core by hapifhir.

the class TurtleParser method parseChild.

private void parseChild(Turtle src, TTLComplex object, Element context, Set<String> processed, Property property, String path, String name) throws FHIRException {
    processed.add(name);
    String npath = path + "/" + property.getName();
    TTLObject e = object.getPredicates().get(FHIR_URI_BASE + name);
    if (e == null)
        return;
    if (property.isList() && (e instanceof TTLList)) {
        TTLList arr = (TTLList) e;
        for (TTLObject am : arr.getList()) {
            parseChildInstance(src, npath, object, context, property, name, am);
        }
    } else {
        parseChildInstance(src, npath, object, context, property, name, e);
    }
}
Also used : TTLObject(org.hl7.fhir.utilities.turtle.Turtle.TTLObject) TTLList(org.hl7.fhir.utilities.turtle.Turtle.TTLList)

Aggregations

TTLObject (org.hl7.fhir.utilities.turtle.Turtle.TTLObject)8 TTLList (org.hl7.fhir.utilities.turtle.Turtle.TTLList)6 HashSet (java.util.HashSet)4 TTLObject (org.hl7.fhir.dstu3.utils.formats.Turtle.TTLObject)4 FHIRFormatError (org.hl7.fhir.exceptions.FHIRFormatError)4 TTLObject (org.hl7.fhir.r4.utils.formats.Turtle.TTLObject)4 TTLURL (org.hl7.fhir.utilities.turtle.Turtle.TTLURL)4 TTLList (org.hl7.fhir.dstu3.utils.formats.Turtle.TTLList)3 TTLList (org.hl7.fhir.r4.utils.formats.Turtle.TTLList)3 SpecialElement (org.hl7.fhir.dstu3.elementmodel.Element.SpecialElement)2 StructureDefinition (org.hl7.fhir.dstu3.model.StructureDefinition)2 TTLURL (org.hl7.fhir.dstu3.utils.formats.Turtle.TTLURL)2 SpecialElement (org.hl7.fhir.r4.elementmodel.Element.SpecialElement)2 StructureDefinition (org.hl7.fhir.r4.model.StructureDefinition)2 TTLURL (org.hl7.fhir.r4.utils.formats.Turtle.TTLURL)2 SpecialElement (org.hl7.fhir.r4b.elementmodel.Element.SpecialElement)2 NamedElement (org.hl7.fhir.r4b.elementmodel.ParserBase.NamedElement)2 StructureDefinition (org.hl7.fhir.r4b.model.StructureDefinition)2 SpecialElement (org.hl7.fhir.r5.elementmodel.Element.SpecialElement)2 NamedElement (org.hl7.fhir.r5.elementmodel.ParserBase.NamedElement)2