Search in sources :

Example 26 with XmlParser

use of org.hl7.fhir.dstu2.formats.XmlParser 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 27 with XmlParser

use of org.hl7.fhir.dstu2.formats.XmlParser 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 28 with XmlParser

use of org.hl7.fhir.dstu2.formats.XmlParser 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 29 with XmlParser

use of org.hl7.fhir.dstu2.formats.XmlParser in project kindling by HL7.

the class Publisher method buildLoincExample.

private String buildLoincExample(String filename) throws FileNotFoundException, Exception {
    LoincToDEConvertor conv = new LoincToDEConvertor();
    conv.setDefinitions(Utilities.path(page.getFolders().srcDir, "loinc", "loincS.xml"));
    conv.process();
    IParser xml = new XmlParser().setOutputStyle(OutputStyle.PRETTY);
    FileOutputStream s = new FileOutputStream(Utilities.path(page.getFolders().dstDir, filename + ".xml"));
    xml.compose(s, conv.getBundle());
    s.close();
    IParser json = new JsonParser().setOutputStyle(OutputStyle.PRETTY);
    s = new FileOutputStream(Utilities.path(page.getFolders().dstDir, filename + ".json"));
    json.compose(s, conv.getBundle());
    s.close();
    return "Loinc Narrative";
}
Also used : XmlParser(org.hl7.fhir.r5.formats.XmlParser) FileOutputStream(java.io.FileOutputStream) LoincToDEConvertor(org.hl7.fhir.r5.terminologies.LoincToDEConvertor) IParser(org.hl7.fhir.r5.formats.IParser) JsonParser(org.hl7.fhir.r5.formats.JsonParser)

Example 30 with XmlParser

use of org.hl7.fhir.dstu2.formats.XmlParser in project kindling by HL7.

the class Publisher method produceTypeProfile.

private void produceTypeProfile(TypeDefn type) throws Exception {
    // ProfileDefn p = new ProfileDefn();
    // p.putMetadata("id", type.getName());
    // p.putMetadata("name", "Basic StructureDefinition for " + type.getName());
    // p.putMetadata("author.name", "FHIR Specification");
    // p.putMetadata("author.ref", "http://hl7.org/fhir");
    // p.putMetadata("description", "Basic StructureDefinition for " + type.getName() + " for validation support");
    // p.putMetadata("status", "draft");
    // p.putMetadata("date", new SimpleDateFormat("yyyy-MM-dd", new Locale("en", "US")).format(new Date()));
    // p.getElements().add(type);
    // ProfileGenerator pgen = new ProfileGenerator(page.getDefinitions());
    // String fn = "type-" + type.getName() + ".profile.xml";
    // StructureDefinition rp = pgen.generate(p, "type-" + type.getName() + ".profile", "<div>Type definition for " + type.getName() + " from <a href=\"http://hl7.org/fhir/datatypes.html#" + type.getName()
    // + "\">FHIR Specification</a></div>");
    String fn = type.getName().toLowerCase() + ".profile.xml";
    StructureDefinition rp = type.getProfile();
    FileOutputStream s = new FileOutputStream(page.getFolders().dstDir + fn);
    new XmlParser().setOutputStyle(OutputStyle.PRETTY).compose(s, rp);
    s.close();
    s = new FileOutputStream(page.getFolders().dstDir + Utilities.changeFileExt(fn, ".canonical.xml"));
    new XmlParser().setOutputStyle(OutputStyle.CANONICAL).compose(s, rp);
    s.close();
    s = new FileOutputStream(page.getFolders().dstDir + Utilities.changeFileExt(fn, ".json"));
    new JsonParser().setOutputStyle(OutputStyle.PRETTY).compose(s, rp);
    s.close();
    s = new FileOutputStream(page.getFolders().dstDir + Utilities.changeFileExt(fn, ".canonical.json"));
    new JsonParser().setOutputStyle(OutputStyle.CANONICAL).compose(s, rp);
    s.close();
    Utilities.copyFile(new CSFile(page.getFolders().dstDir + fn), new CSFile(Utilities.path(page.getFolders().dstDir, "examples", fn)));
    addToResourceFeed(rp, page.getTypeBundle(), fn);
    // saveAsPureHtml(rp, new FileOutputStream(page.getFolders().dstDir+ "html"
    // + File.separator + "datatypes.html"));
    cloneToXhtml(type.getName().toLowerCase() + ".profile", "StructureDefinition for " + type.getName(), false, "profile-instance:type:" + type.getName(), "Type", null, wg("mnm"));
    jsonToXhtml(type.getName().toLowerCase() + ".profile", "StructureDefinition for " + type.getName(), resource2Json(rp), "profile-instance:type:" + type.getName(), "Type", null, wg("mnm"));
    ttlToXhtml(type.getName().toLowerCase() + ".profile", "StructureDefinition for " + type.getName(), resource2Ttl(rp), "profile-instance:type:" + type.getName(), "Type", null, wg("mnm"));
    String shex = new ShExGenerator(page.getWorkerContext()).generate(HTMLLinkPolicy.NONE, rp);
    TextFile.stringToFile(shex, Utilities.changeFileExt(page.getFolders().dstDir + fn, ".shex"));
    shexToXhtml(type.getName().toLowerCase(), "ShEx statement for " + type.getName(), shex, "profile-instance:type:" + type.getName(), "Type", null, wg("mnm"));
}
Also used : XmlParser(org.hl7.fhir.r5.formats.XmlParser) StructureDefinition(org.hl7.fhir.r5.model.StructureDefinition) FileOutputStream(java.io.FileOutputStream) CSFile(org.hl7.fhir.utilities.CSFile) JsonParser(org.hl7.fhir.r5.formats.JsonParser) ShExGenerator(org.hl7.fhir.r5.conformance.ShExGenerator)

Aggregations

FileOutputStream (java.io.FileOutputStream)130 XmlParser (org.hl7.fhir.r5.formats.XmlParser)97 FHIRException (org.hl7.fhir.exceptions.FHIRException)84 FileInputStream (java.io.FileInputStream)77 File (java.io.File)64 IOException (java.io.IOException)59 CSFileInputStream (org.hl7.fhir.utilities.CSFileInputStream)51 CSFile (org.hl7.fhir.utilities.CSFile)48 JsonParser (org.hl7.fhir.r5.formats.JsonParser)45 ArrayList (java.util.ArrayList)35 XmlParser (org.hl7.fhir.dstu3.formats.XmlParser)35 TextFile (org.hl7.fhir.utilities.TextFile)33 XmlParser (org.hl7.fhir.r4.formats.XmlParser)31 FileNotFoundException (java.io.FileNotFoundException)27 ByteArrayOutputStream (java.io.ByteArrayOutputStream)24 Resource (org.hl7.fhir.r5.model.Resource)24 XmlParser (org.hl7.fhir.r4b.formats.XmlParser)23 StructureDefinition (org.hl7.fhir.r5.model.StructureDefinition)22 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)19 NotImplementedException (org.apache.commons.lang3.NotImplementedException)19