Search in sources :

Example 41 with ElementDefn

use of org.hl7.fhir.definitions.model.ElementDefn in project kindling by HL7.

the class XSDGenerator method generateType.

private void generateType(ElementDefn root, String name, ElementDefn struc, boolean isResource) throws IOException, Exception {
    write("  <xs:complexType name=\"" + name + "\">\r\n");
    write("    <xs:annotation>\r\n");
    write("      <xs:documentation xml:lang=\"en\">" + Utilities.escapeXml(root.getDefinition()) + "</xs:documentation>\r\n");
    if (isResource)
        write("      <xs:documentation xml:lang=\"en\">If the element is present, it must have either a @value, an @id, or extensions</xs:documentation>\r\n");
    write("    </xs:annotation>\r\n");
    write("    <xs:complexContent>\r\n");
    if (isResource)
        write("      <xs:extension base=\"" + root.typeCode() + "\">\r\n");
    else
        write("      <xs:extension base=\"BackboneElement\">\r\n");
    write("        <xs:sequence>\r\n");
    for (ElementDefn e : struc.getElements()) {
        if (e.getName().equals("[type]"))
            generateAny(root, e);
        else
            generateElement(root, e);
    }
    write("        </xs:sequence>\r\n");
    write("      </xs:extension>\r\n");
    write("    </xs:complexContent>\r\n");
    write("  </xs:complexType>\r\n");
}
Also used : ElementDefn(org.hl7.fhir.definitions.model.ElementDefn)

Example 42 with ElementDefn

use of org.hl7.fhir.definitions.model.ElementDefn in project kindling by HL7.

the class JsonLDGenerator method scanTypes.

// 
// private CharSequence nameForType(String type) {
// if (definitions.getConstraints().containsKey(type))
// return definitions.getConstraints().get(type).getBaseType();
// else
// return Utilities.capitalize(type);
// }
private void scanTypes(ElementDefn root, ElementDefn focus) {
    for (ElementDefn e : focus.getElements()) {
        if (e.getTypes().size() == 0 && e.getElements().size() > 0) {
            String tn = e.getPath();
            structures.add(e);
            typenames.add(tn);
            types.put(e, tn);
            scanTypes(root, e);
        }
    }
}
Also used : ElementDefn(org.hl7.fhir.definitions.model.ElementDefn)

Example 43 with ElementDefn

use of org.hl7.fhir.definitions.model.ElementDefn in project kindling by HL7.

the class XSDBaseGenerator method genInfrastructure.

private void genInfrastructure(ElementDefn elem) throws Exception {
    enums.clear();
    enumDefs.clear();
    String name = elem.getName();
    write("  <xs:complexType name=\"" + name + "\">\r\n");
    write("    <xs:annotation>\r\n");
    write("      <xs:documentation xml:lang=\"en\">" + Utilities.escapeXml(elem.getDefinition()) + "</xs:documentation>\r\n");
    write("      <xs:documentation xml:lang=\"en\">If the element is present, it must have a value for at least one of the defined elements, an @id referenced from the Narrative, or extensions</xs:documentation>\r\n");
    write("    </xs:annotation>\r\n");
    if (!elem.getName().equals("Base")) {
        write("    <xs:complexContent>\r\n");
        write("      <xs:extension base=\"" + getParentType(elem) + "\">\r\n");
    }
    write("        <xs:sequence>\r\n");
    for (ElementDefn e : elem.getElements()) {
        if (!e.isXmlAttribute()) {
            if (e.getName().equals("[type]"))
                generateAny(elem, e, null, null);
            else
                generateElement(elem, e, null, null);
        }
    }
    write("        </xs:sequence>\r\n");
    for (ElementDefn e : elem.getElements()) {
        if (e.isXmlAttribute()) {
            generateAttribute(elem, e, null);
        }
    }
    if (!elem.getName().equals("Base")) {
        write("      </xs:extension>\r\n");
        write("    </xs:complexContent>\r\n");
    }
    write("  </xs:complexType>\r\n");
    while (!structures.isEmpty()) {
        String s = structures.keySet().iterator().next();
        generateType(elem, s, structures.get(s));
        structures.remove(s);
    }
    for (BindingSpecification en : enums) {
        generateEnum(en);
    }
}
Also used : ElementDefn(org.hl7.fhir.definitions.model.ElementDefn) BindingSpecification(org.hl7.fhir.definitions.model.BindingSpecification)

Example 44 with ElementDefn

use of org.hl7.fhir.definitions.model.ElementDefn in project kindling by HL7.

the class XVerPathsGenerator method process.

private void process(ElementDefn ed, String path) {
    ElementInfo ei = new ElementInfo();
    ei.path = path;
    r5List.add(ei);
    ElementInfo r4 = r4List.get(path);
    if (ed.getTypes().size() > 0) {
        // leaf
        for (TypeRef tr : ed.getTypes()) {
            if (r4 == null || !r4.types.contains(tr.summary())) {
                ei.types.add(tr.summary());
            }
        }
    } else {
        for (ElementDefn child : ed.getElements()) {
            if (r4 == null || !r4.elements.contains(child.getName())) {
                ei.elements.add(child.getName());
            }
            process(child, path + "." + child.getName());
        }
    }
}
Also used : TypeRef(org.hl7.fhir.definitions.model.TypeRef) ElementDefn(org.hl7.fhir.definitions.model.ElementDefn)

Example 45 with ElementDefn

use of org.hl7.fhir.definitions.model.ElementDefn in project kindling by HL7.

the class XVerPathsGenerator method execute.

public void execute() throws IOException {
    // load the R4 content; can't be an extension if it already matches R4
    loadR4();
    // iterate all the elements, building a list
    for (String s : sorted(definitions.getTypes().keySet())) {
        ElementDefn ed = definitions.getTypes().get(s);
        process(ed);
    }
    for (String s : sorted(definitions.getBaseResources().keySet())) {
        ResourceDefn ed = definitions.getBaseResources().get(s);
        process(ed.getRoot());
    }
    for (String s : sorted(definitions.getResources().keySet())) {
        ResourceDefn ed = definitions.getResources().get(s);
        process(ed.getRoot());
    }
    StringBuilder r5 = new StringBuilder();
    r5.append("{\r\n");
    int i = 0;
    for (ElementInfo ei : r5List) {
        r5.append(" \"" + ei.path + "\": { ");
        if (ei.types.size() > 0) {
            r5.append("\"types\": [");
            boolean first = true;
            for (String s : ei.types) {
                if (first)
                    first = false;
                else
                    r5.append(", ");
                r5.append("\"" + s + "\"");
            }
            r5.append("]");
        } else if (ei.elements.size() > 0) {
            r5.append("\"elements\": [");
            boolean first = true;
            for (String s : ei.elements) {
                if (first)
                    first = false;
                else
                    r5.append(", ");
                r5.append("\"" + s + "\"");
            }
            r5.append("]");
        }
        i++;
        if (i == r5List.size()) {
            r5.append(" }\r\n");
        } else {
            r5.append(" },\r\n");
        }
    }
    r5.append("}\r\n");
    TextFile.stringToFile(r5.toString(), dest);
}
Also used : ElementDefn(org.hl7.fhir.definitions.model.ElementDefn) ResourceDefn(org.hl7.fhir.definitions.model.ResourceDefn)

Aggregations

ElementDefn (org.hl7.fhir.definitions.model.ElementDefn)100 TypeRef (org.hl7.fhir.definitions.model.TypeRef)35 ArrayList (java.util.ArrayList)28 FHIRException (org.hl7.fhir.exceptions.FHIRException)28 CommaSeparatedStringBuilder (org.hl7.fhir.utilities.CommaSeparatedStringBuilder)21 ResourceDefn (org.hl7.fhir.definitions.model.ResourceDefn)19 Invariant (org.hl7.fhir.definitions.model.Invariant)16 IOException (java.io.IOException)14 BindingSpecification (org.hl7.fhir.definitions.model.BindingSpecification)11 FileNotFoundException (java.io.FileNotFoundException)10 URISyntaxException (java.net.URISyntaxException)10 StructureDefinition (org.hl7.fhir.r5.model.StructureDefinition)10 ProfiledType (org.hl7.fhir.definitions.model.ProfiledType)9 TransformerException (javax.xml.transform.TransformerException)8 ElementDefinition (org.hl7.fhir.r5.model.ElementDefinition)8 TransformerConfigurationException (javax.xml.transform.TransformerConfigurationException)7 NotImplementedException (org.apache.commons.lang3.NotImplementedException)7 UcumException (org.fhir.ucum.UcumException)7 TypeParser (org.hl7.fhir.definitions.parsers.TypeParser)7 DefinitionException (org.hl7.fhir.exceptions.DefinitionException)7