Search in sources :

Example 71 with Value

use of org.hl7.fhir.utilities.graphql.Value in project kindling by HL7.

the class XmlSpecGenerator method renderType.

private String renderType(int indent, DataType value) throws Exception {
    StringBuilder b = new StringBuilder();
    for (int i = 0; i < indent - 2; i++) b.append(" ");
    String ind = b.toString();
    XmlParser xml = new XmlParser();
    ByteArrayOutputStream bs = new ByteArrayOutputStream();
    xml.setOutputStyle(OutputStyle.PRETTY);
    xml.compose(bs, null, value);
    bs.close();
    String[] result = bs.toString().split("\\r?\\n");
    b = new StringBuilder();
    for (String s : result) {
        if (// eliminate the wrapper content
        s.startsWith(" "))
            b.append("\r\n  " + ind + Utilities.escapeXml(s));
    }
    return b.toString() + "\r\n" + ind;
}
Also used : XmlParser(org.hl7.fhir.r5.formats.XmlParser) CommaSeparatedStringBuilder(org.hl7.fhir.utilities.CommaSeparatedStringBuilder) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Example 72 with Value

use of org.hl7.fhir.utilities.graphql.Value 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 73 with Value

use of org.hl7.fhir.utilities.graphql.Value in project kindling by HL7.

the class XSDGenerator method generateEnum.

private void generateEnum(String en) throws IOException {
    if (allenums.contains(en))
        return;
    allenums.add(en);
    write("  <xs:simpleType name=\"" + en + "-list\">\r\n");
    write("    <xs:restriction base=\"code-primitive\">\r\n");
    ValueSet vs = enums.get(en);
    vs.setUserData(ToolResourceUtilities.NAME_VS_USE_MARKER, true);
    ValueSet ex = workerContext.expandVS(vs, true, false).getValueset();
    for (ValueSetExpansionContainsComponent cc : ex.getExpansion().getContains()) {
        genIncludedCode(cc);
    }
    write("    </xs:restriction>\r\n");
    write("  </xs:simpleType>\r\n");
    write("  <xs:complexType name=\"" + en + "\">\r\n");
    write("    <xs:annotation>\r\n");
    write("      <xs:documentation xml:lang=\"en\">" + Utilities.escapeXml(enumDefs.get(en)) + "</xs:documentation>\r\n");
    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");
    write("      <xs:extension base=\"Element\">\r\n");
    write("        <xs:attribute name=\"value\" type=\"" + en + "-list\" use=\"optional\"/>\r\n");
    write("      </xs:extension>\r\n");
    write("    </xs:complexContent>\r\n");
    write("  </xs:complexType>\r\n");
}
Also used : ValueSetExpansionContainsComponent(org.hl7.fhir.r5.model.ValueSet.ValueSetExpansionContainsComponent) ValueSet(org.hl7.fhir.r5.model.ValueSet)

Example 74 with Value

use of org.hl7.fhir.utilities.graphql.Value in project kindling by HL7.

the class JsonLDDefinitionsGenerator method generate.

// private String genDate;
// private String version;
// private BuildWorkerContext workerContext;
public void generate(Definitions definitions, IniFile ini, String tmpResDir, String dstDir, String srcDir, FHIRVersion version, String genDate, BuildWorkerContext workerContext) throws Exception {
    // this.genDate = genDate;
    // this.version = version;
    // this.workerContext = workerContext;
    JsonObject defn = new JsonObject();
    JsonObject context = new JsonObject();
    defn.add("@context", context);
    defn.addProperty("@id", "http://hl7.org/fhir/");
    context.addProperty("fhir", "http://hl7.org/fhir/");
    context.addProperty("xsd", "http://www.w3.org/2001/XMLSchema#");
    // properties for primitives, helpers, format features
    addProperty(context, "value", "fhir:value", "xsd:string");
    addProperty(context, "decimal", "fhir:value", "xsd:decimal");
    addProperty(context, "integer", "fhir:value", "xsd:integer");
    if (!version.isR4B()) {
        addProperty(context, "integer64", "fhir:value", "xsd:string");
    }
    addProperty(context, "boolean", "fhir:value", "xsd:boolean");
    addProperty(context, "binary", "fhir:value", "xsd:base64Binary");
    addProperty(context, "date", "fhir:value", "xsd:date");
    addProperty(context, "dateTime", "fhir:value", "xsd:dateTime");
    addProperty(context, "gYearMonth", "fhir:value", "xsd:gYearMonth");
    addProperty(context, "gYear", "fhir:value", "xsd:gYear");
    addProperty(context, "link", "fhir:link", "@id");
    addProperty(context, "concept", "fhir:concept", "@id");
    addProperty(context, "index", "fhir:index", "xsd:integer");
    addProperty(context, "role", "fhir:nodeRole", "@id");
    // elements defined in FHIR:
    for (TypeRef tr : definitions.getKnownTypes()) {
        if (!definitions.hasPrimitiveType(tr.getName()) && !tr.getName().equals("SimpleQuantity") && !tr.getName().equals("MoneyQuantity")) {
            TypeDefn root = definitions.getElementDefn(tr.getName());
            new JsonLDGenerator(definitions, workerContext, definitions.getKnownTypes()).generate(context, root, version, genDate);
        }
    }
    List<String> names = new ArrayList<String>();
    names.addAll(definitions.getResources().keySet());
    names.addAll(definitions.getBaseResources().keySet());
    names.add("Parameters");
    Collections.sort(names);
    for (String name : names) {
        ResourceDefn root = definitions.getResourceByName(name);
        new JsonLDGenerator(definitions, workerContext, definitions.getKnownTypes()).generate(context, root.getRoot(), version, genDate);
    }
    save(defn, dstDir + "fhir.jsonld");
}
Also used : TypeDefn(org.hl7.fhir.definitions.model.TypeDefn) TypeRef(org.hl7.fhir.definitions.model.TypeRef) ArrayList(java.util.ArrayList) JsonObject(com.google.gson.JsonObject) ResourceDefn(org.hl7.fhir.definitions.model.ResourceDefn)

Example 75 with Value

use of org.hl7.fhir.utilities.graphql.Value 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)

Aggregations

Test (org.junit.jupiter.api.Test)222 ArrayList (java.util.ArrayList)183 FHIRException (org.hl7.fhir.exceptions.FHIRException)107 List (java.util.List)97 DisplayName (org.junit.jupiter.api.DisplayName)96 XhtmlNode (org.hl7.fhir.utilities.xhtml.XhtmlNode)89 CodeableConcept (org.hl7.fhir.r4.model.CodeableConcept)85 Complex (org.hl7.fhir.r4.utils.formats.Turtle.Complex)70 Identifier (org.hl7.fhir.r4.model.Identifier)69 Test (org.junit.Test)66 Complex (org.hl7.fhir.dstu2016may.formats.RdfGenerator.Complex)64 Complex (org.hl7.fhir.dstu3.utils.formats.Turtle.Complex)54 IOException (java.io.IOException)52 Bundle (org.hl7.fhir.r4.model.Bundle)49 Coding (org.hl7.fhir.r4.model.Coding)49 ValueSet (org.hl7.fhir.r5.model.ValueSet)48 PathEngineException (org.hl7.fhir.exceptions.PathEngineException)46 Resource (org.hl7.fhir.r4.model.Resource)46 BigDecimal (java.math.BigDecimal)45 BundleEntryComponent (org.hl7.fhir.r4.model.Bundle.BundleEntryComponent)44