Search in sources :

Example 56 with ResourceDefn

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

the class Regenerator method generateOperation.

private void generateOperation(String root, ResourceDefn r, Operation op) throws IOException {
    OperationDefinition opd = op.getResource().copy();
    opd.setId(r.getName() + "-" + op.getName());
    opd.setUrl("http://hl7.org/fhir/build/OperationDefinition/" + opd.getId());
    if (!Utilities.noString(op.getFooter())) {
        opd.addExtension(BuildExtensions.EXT_FOOTER, new MarkdownType(op.getFooter()));
    }
    if (!Utilities.noString(op.getFooter2())) {
        opd.addExtension(BuildExtensions.EXT_FOOTER2, new MarkdownType(op.getFooter2()));
    }
    for (OperationExample opex : op.getExamples()) {
        Extension ex = new Extension(BuildExtensions.EXT_OP_EXAMPLE);
        if (!Utilities.noString(opex.getContent())) {
            ex.addExtension(BuildExtensions.EXT_OP_EXAMPLE_CONTENT, new StringType(opex.getContent()));
        }
        if (!Utilities.noString(opex.getComment())) {
            ex.addExtension(BuildExtensions.EXT_OP_EXAMPLE_COMMENT, new StringType(opex.getComment()));
        }
        ex.addExtension(BuildExtensions.EXT_OP_EXAMPLE_RESPONSE, new BooleanType(opex.isResponse()));
        ex.addExtension(BuildExtensions.EXT_OP_EXAMPLE_LIST, new IntegerType(1));
        opd.addExtension(ex);
    }
    for (OperationExample opex : op.getExamples2()) {
        Extension ex = new Extension(BuildExtensions.EXT_OP_EXAMPLE);
        if (!Utilities.noString(opex.getContent())) {
            ex.addExtension(BuildExtensions.EXT_OP_EXAMPLE_CONTENT, new StringType(opex.getContent()));
        }
        if (!Utilities.noString(opex.getComment())) {
            ex.addExtension(BuildExtensions.EXT_OP_EXAMPLE_COMMENT, new StringType(opex.getComment()));
        }
        ex.addExtension(BuildExtensions.EXT_OP_EXAMPLE_RESPONSE, new BooleanType(opex.isResponse()));
        ex.addExtension(BuildExtensions.EXT_OP_EXAMPLE_LIST, new IntegerType(2));
        opd.addExtension(ex);
    }
    File fn = new File(Utilities.path(root, opd.fhirType().toLowerCase() + "-" + opd.getId() + ".gen.xml"));
    new XmlParser().setOutputStyle(OutputStyle.PRETTY).compose(new FileOutputStream(fn), opd);
    fn.setLastModified(r.getTimestamp());
}
Also used : Extension(org.hl7.fhir.r5.model.Extension) IntegerType(org.hl7.fhir.r5.model.IntegerType) XmlParser(org.hl7.fhir.r5.formats.XmlParser) OperationExample(org.hl7.fhir.definitions.model.Operation.OperationExample) StringType(org.hl7.fhir.r5.model.StringType) FileOutputStream(java.io.FileOutputStream) BooleanType(org.hl7.fhir.r5.model.BooleanType) MarkdownType(org.hl7.fhir.r5.model.MarkdownType) OperationDefinition(org.hl7.fhir.r5.model.OperationDefinition) File(java.io.File)

Example 57 with ResourceDefn

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

the class Regenerator method generatePacks.

public void generatePacks(ResourceDefn r, String root) throws IOException {
    ListResource list = new ListResource();
    list.setId(r.getName() + "-packs");
    list.setStatus(ListStatus.CURRENT);
    list.setMode(ListMode.WORKING);
    // }
    for (Profile p : r.getConformancePackages()) {
        ListResourceEntryComponent li = list.addEntry();
        li.getItem().setReference("ImplementationGuide/" + r.getName() + "-" + p.getCategory());
    }
    File fn = new File(Utilities.path(root, list.fhirType().toLowerCase() + "-" + list.getId() + ".gen.xml"));
    new XmlParser().setOutputStyle(OutputStyle.PRETTY).compose(new FileOutputStream(fn), list);
    fn.setLastModified(r.getTimestamp());
    // }
    for (Profile p : r.getConformancePackages()) {
        generateCP(root, r, p);
    }
}
Also used : XmlParser(org.hl7.fhir.r5.formats.XmlParser) ListResourceEntryComponent(org.hl7.fhir.r5.model.ListResource.ListResourceEntryComponent) FileOutputStream(java.io.FileOutputStream) ListResource(org.hl7.fhir.r5.model.ListResource) File(java.io.File) Profile(org.hl7.fhir.definitions.model.Profile)

Example 58 with ResourceDefn

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

the class XSDBaseGenerator method genResource.

private void genResource(String name, ResourceDefn res) throws Exception {
    enums.clear();
    enumDefs.clear();
    boolean isBase = Utilities.noString(res.getRoot().typeCode());
    write("  <xs:complexType name=\"" + name + "\">\r\n");
    write("    <xs:annotation>\r\n");
    write("      <xs:documentation xml:lang=\"en\">" + Utilities.escapeXml(res.getDefinition()) + "</xs:documentation>\r\n");
    write("    </xs:annotation>\r\n");
    if (!isBase) {
        write("    <xs:complexContent>\r\n");
        write("      <xs:extension base=\"" + res.getRoot().typeCode() + "\">\r\n");
    }
    if (!res.isInterface()) {
        write("        <xs:sequence>\r\n");
        for (ElementDefn e : res.getRoot().getElements()) {
            generateElement(res.getRoot(), e, null, null);
        }
        write("        </xs:sequence>\r\n");
    }
    if (!isBase) {
        write("      </xs:extension>\r\n");
        write("    </xs:complexContent>\r\n");
    }
    write("  </xs:complexType>\r\n");
    genRegex();
    while (!structures.isEmpty()) {
        String s = structures.keySet().iterator().next();
        generateType(res.getRoot(), s, structures.get(s));
        structures.remove(s);
    }
    for (BindingSpecification en : enums) {
        generateEnum(en);
    }
    genRegex();
}
Also used : ElementDefn(org.hl7.fhir.definitions.model.ElementDefn) BindingSpecification(org.hl7.fhir.definitions.model.BindingSpecification)

Example 59 with ResourceDefn

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

the class XSDBaseGenerator method generate.

public void generate(String version, String genDate, boolean outer) throws Exception {
    if (outer) {
        write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n");
        write("<!-- \r\n");
        write(Config.FULL_LICENSE_CODE);
        write("\r\n");
        write("  Generated on " + genDate + " for FHIR v" + version + " \r\n");
        write("\r\n");
        write("  Note: the schemas &amp; schematrons do not contain all of the rules about what makes resources\r\n");
        write("  valid. Implementers will still need to be familiar with the content of the specification and with\r\n");
        write("  any profiles that apply to the resources in order to make a conformant implementation.\r\n");
        write("\r\n");
        write("-->\r\n");
        write("<xs:schema xmlns:xs=\"http://www.w3.org/2001/XMLSchema\" xmlns=\"http://hl7.org/fhir\" xmlns:xhtml=\"http://www.w3.org/1999/xhtml\" " + "targetNamespace=\"http://hl7.org/fhir\" elementFormDefault=\"qualified\" version=\"1.0\">\r\n");
    }
    write("  <xs:import namespace=\"http://www.w3.org/XML/1998/namespace\" schemaLocation=\"xml.xsd\"/>\r\n");
    write("  <xs:import namespace=\"http://www.w3.org/1999/xhtml\" schemaLocation=\"fhir-xhtml.xsd\"/>\r\n");
    if (outer)
        write("  <xs:include schemaLocation=\"fhir-all.xsd\"/>\r\n");
    // genElementRoot();
    write("\r\n");
    genPrimitives();
    write("\r\n");
    genResourceReference();
    genResourceContainer();
    for (ElementDefn e : definitions.getInfrastructure().values()) genInfrastructure(e);
    for (ElementDefn e : definitions.getTypes().values()) genType(e);
    for (String n : definitions.getBaseResources().keySet()) {
        ResourceDefn r = definitions.getBaseResources().get(n);
        if (r.isAbstract()) {
            genResource(n, r);
        }
    }
    // todo: what to do about this?
    for (BindingSpecification b : definitions.getCommonBindings().values()) if (((b.getUseContexts().size() > 1 || b.isShared()) && isEnum(b)))
        generateEnum(b);
    if (outer) {
        write("</xs:schema>\r\n");
        writer.flush();
    }
}
Also used : ElementDefn(org.hl7.fhir.definitions.model.ElementDefn) BindingSpecification(org.hl7.fhir.definitions.model.BindingSpecification) ResourceDefn(org.hl7.fhir.definitions.model.ResourceDefn)

Example 60 with ResourceDefn

use of org.hl7.fhir.definitions.model.ResourceDefn 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)

Aggregations

ResourceDefn (org.hl7.fhir.definitions.model.ResourceDefn)75 CommaSeparatedStringBuilder (org.hl7.fhir.utilities.CommaSeparatedStringBuilder)42 ArrayList (java.util.ArrayList)38 FHIRException (org.hl7.fhir.exceptions.FHIRException)36 ElementDefn (org.hl7.fhir.definitions.model.ElementDefn)31 StructureDefinition (org.hl7.fhir.r5.model.StructureDefinition)28 File (java.io.File)26 FileOutputStream (java.io.FileOutputStream)25 CSFile (org.hl7.fhir.utilities.CSFile)24 XmlParser (org.hl7.fhir.r5.formats.XmlParser)22 FileNotFoundException (java.io.FileNotFoundException)20 IOException (java.io.IOException)20 Example (org.hl7.fhir.definitions.model.Example)20 Profile (org.hl7.fhir.definitions.model.Profile)20 ContactPoint (org.hl7.fhir.r5.model.ContactPoint)18 IniFile (org.hl7.fhir.utilities.IniFile)18 ImplementationGuideDefn (org.hl7.fhir.definitions.model.ImplementationGuideDefn)16 TransformerException (javax.xml.transform.TransformerException)15 TextFile (org.hl7.fhir.utilities.TextFile)15 SearchParameterDefn (org.hl7.fhir.definitions.model.SearchParameterDefn)14