Search in sources :

Example 11 with RdfParser

use of org.hl7.fhir.r5.formats.RdfParser in project kindling by HL7.

the class Publisher method generateConformanceStatement.

private void generateConformanceStatement(boolean full, String name, boolean register) throws Exception {
    pgen = new ProfileGenerator(page.getDefinitions(), page.getWorkerContext(), page, page.getGenDate(), page.getVersion(), dataElements, fpUsages, page.getFolders().rootDir, page.getUml(), page.getRc());
    CapabilityStatement cpbs = new CapabilityStatement();
    cpbs.setId(FormatUtilities.makeId(name));
    cpbs.setUrl("http://hl7.org/fhir/CapabilityStatement/" + name);
    cpbs.setVersion(page.getVersion().toCode());
    cpbs.setName("Base FHIR Capability Statement " + (full ? "(Full)" : "(Empty)"));
    cpbs.setStatus(PublicationStatus.DRAFT);
    cpbs.setExperimental(true);
    cpbs.setDate(page.getGenDate().getTime());
    cpbs.setPublisher("FHIR Project Team");
    cpbs.addContact().getTelecom().add(Factory.newContactPoint(ContactPointSystem.URL, "http://hl7.org/fhir"));
    cpbs.setKind(CapabilityStatementKind.CAPABILITY);
    cpbs.setSoftware(new CapabilityStatementSoftwareComponent());
    cpbs.getSoftware().setName("Insert your software name here...");
    cpbs.setFhirVersion(page.getVersion());
    cpbs.getFormat().add(Factory.newCode("xml"));
    cpbs.getFormat().add(Factory.newCode("json"));
    CapabilityStatementRestComponent rest = new CapabilityStatement.CapabilityStatementRestComponent();
    cpbs.getRest().add(rest);
    rest.setMode(RestfulCapabilityMode.SERVER);
    if (full) {
        rest.setDocumentation("All the functionality defined in FHIR");
        cpbs.setDescription("This is the base Capability Statement for FHIR. It represents a server that provides the full set of functionality defined by FHIR. It is provided to use as a template for system designers to build their own Capability Statements from");
    } else {
        rest.setDocumentation("An empty Capability Statement");
        cpbs.setDescription("This is the base Capability Statement for FHIR. It represents a server that provides the none of the functionality defined by FHIR. It is provided to use as a template for system designers to build their own Capability Statements from. A capability statement has to contain something, so this contains a read of a Capability Statement");
    }
    rest.setSecurity(new CapabilityStatementRestSecurityComponent());
    rest.getSecurity().setCors(true);
    rest.getSecurity().addService().setText("See http://docs.smarthealthit.org/").addCoding().setSystem("http://terminology.hl7.org/CodeSystem/restful-security-service").setCode("SMART-on-FHIR").setDisplay("SMART-on-FHIR");
    rest.getSecurity().setDescription("This is the Capability Statement to declare that the server supports SMART-on-FHIR. See the SMART-on-FHIR docs for the extension that would go with such a server");
    if (full) {
        for (String rn : page.getDefinitions().sortedResourceNames()) {
            ResourceDefn rd = page.getDefinitions().getResourceByName(rn);
            CapabilityStatementRestResourceComponent res = new CapabilityStatement.CapabilityStatementRestResourceComponent();
            rest.getResource().add(res);
            res.setType(rn);
            res.setProfile("http://hl7.org/fhir/StructureDefinition/" + rn);
            genConfInteraction(cpbs, res, TypeRestfulInteraction.READ, "Implemented per the specification (or Insert other doco here)");
            genConfInteraction(cpbs, res, TypeRestfulInteraction.VREAD, "Implemented per the specification (or Insert other doco here)");
            genConfInteraction(cpbs, res, TypeRestfulInteraction.UPDATE, "Implemented per the specification (or Insert other doco here)");
            genConfInteraction(cpbs, res, TypeRestfulInteraction.DELETE, "Implemented per the specification (or Insert other doco here)");
            genConfInteraction(cpbs, res, TypeRestfulInteraction.HISTORYINSTANCE, "Implemented per the specification (or Insert other doco here)");
            genConfInteraction(cpbs, res, TypeRestfulInteraction.HISTORYTYPE, "Implemented per the specification (or Insert other doco here)");
            genConfInteraction(cpbs, res, TypeRestfulInteraction.CREATE, "Implemented per the specification (or Insert other doco here)");
            genConfInteraction(cpbs, res, TypeRestfulInteraction.SEARCHTYPE, "Implemented per the specification (or Insert other doco here)");
            res.setConditionalCreate(true);
            res.setConditionalUpdate(true);
            res.setConditionalDelete(ConditionalDeleteStatus.MULTIPLE);
            res.addReferencePolicy(ReferenceHandlingPolicy.LITERAL);
            res.addReferencePolicy(ReferenceHandlingPolicy.LOGICAL);
            for (SearchParameterDefn i : rd.getSearchParams().values()) {
                res.getSearchParam().add(makeSearchParam(rn, i));
                if (i.getType().equals(SearchType.reference))
                    res.getSearchInclude().add(new StringType(rn + "." + i.getCode()));
            }
            for (String rni : page.getDefinitions().sortedResourceNames()) {
                ResourceDefn rdi = page.getDefinitions().getResourceByName(rni);
                for (SearchParameterDefn ii : rdi.getSearchParams().values()) {
                    if (ii.getType().equals(SearchType.reference) && ii.getTargets().contains(rn))
                        res.getSearchRevInclude().add(new StringType(rni + "." + ii.getCode()));
                }
            }
        }
        genConfInteraction(cpbs, rest, SystemRestfulInteraction.TRANSACTION, "Implemented per the specification (or Insert other doco here)");
        genConfInteraction(cpbs, rest, SystemRestfulInteraction.BATCH, "Implemented per the specification (or Insert other doco here)");
        genConfInteraction(cpbs, rest, SystemRestfulInteraction.HISTORYSYSTEM, "Implemented per the specification (or Insert other doco here)");
        genConfInteraction(cpbs, rest, SystemRestfulInteraction.SEARCHSYSTEM, "Implemented per the specification (or Insert other doco here)");
        for (ResourceDefn rd : page.getDefinitions().getBaseResources().values()) {
            for (SearchParameterDefn i : rd.getSearchParams().values()) rest.getSearchParam().add(makeSearchParam(rd.getName(), i));
            rest.getSearchParam().add(makeSearchParam("something", SearchParamType.STRING, "id", "some doco"));
            rest.getSearchParam().add(makeSearchParam("_list", SearchParamType.TOKEN, "Resource-list", "Retrieval of resources that are referenced by a List resource"));
            rest.getSearchParam().add(makeSearchParam("_has", SearchParamType.COMPOSITE, "Resource-has", "Provides support for reverse chaining"));
            rest.getSearchParam().add(makeSearchParam("_type", SearchParamType.TOKEN, "Resource-type", "Type of resource (when doing cross-resource search"));
            rest.getSearchParam().add(makeSearchParam("_sort", SearchParamType.TOKEN, "Resource-source", "How to sort the resources when returning"));
            rest.getSearchParam().add(makeSearchParam("_count", SearchParamType.NUMBER, "Resource-count", "How many resources to return"));
            rest.getSearchParam().add(makeSearchParam("_include", SearchParamType.TOKEN, "Resource-include", "Control over returning additional resources (see spec)"));
            rest.getSearchParam().add(makeSearchParam("_revinclude", SearchParamType.TOKEN, "Resource-revinclude", "Control over returning additional resources (see spec)"));
            rest.getSearchParam().add(makeSearchParam("_summary", SearchParamType.TOKEN, "Resource-summary", "What kind of information to return"));
            rest.getSearchParam().add(makeSearchParam("_elements", SearchParamType.STRING, "Resource-elements", "What kind of information to return"));
            rest.getSearchParam().add(makeSearchParam("_contained", SearchParamType.TOKEN, "Resource-contained", "Managing search into contained resources"));
            rest.getSearchParam().add(makeSearchParam("_containedType", SearchParamType.TOKEN, "Resource-containedType", "Managing search into contained resources"));
            for (Operation op : rd.getOperations()) rest.addOperation().setName(op.getName()).setDefinition("http://hl7.org/fhir/OperationDefinition/" + rd.getName().toLowerCase() + "-" + op.getName());
        }
        for (String rn : page.getDefinitions().sortedResourceNames()) {
            ResourceDefn r = page.getDefinitions().getResourceByName(rn);
            for (Operation op : r.getOperations()) rest.addOperation().setName(op.getName()).setDefinition("http://hl7.org/fhir/OperationDefinition/" + r.getName().toLowerCase() + "-" + op.getName());
        }
    } else {
    // don't add anything - the metadata operation is implicit
    // CapabilityStatementRestResourceComponent res = new CapabilityStatement.CapabilityStatementRestResourceComponent();
    // rest.getResource().add(res);
    // res.setType("CapabilityStatement");
    // genConfInteraction(cpbs, res, TypeRestfulInteraction.READ, "Read CapabilityStatement Resource");
    }
    if (register) {
        RenderingContext lrc = page.getRc().copy().setLocalPrefix("").setTooCostlyNoteEmpty(PageProcessor.TOO_MANY_CODES_TEXT_EMPTY).setTooCostlyNoteNotEmpty(PageProcessor.TOO_MANY_CODES_TEXT_NOT_EMPTY);
        RendererFactory.factory(cpbs, lrc).render(cpbs);
        FileOutputStream s = new FileOutputStream(page.getFolders().dstDir + "capabilitystatement-" + name + ".xml");
        new XmlParser().setOutputStyle(OutputStyle.PRETTY).compose(s, cpbs);
        s.close();
        s = new FileOutputStream(page.getFolders().dstDir + "capabilitystatement-" + name + ".canonical.xml");
        new XmlParser().setOutputStyle(OutputStyle.CANONICAL).compose(s, cpbs);
        s.close();
        cloneToXhtml("capabilitystatement-" + name + "", "Basic Capability Statement", true, "resource-instance:CapabilityStatement", "Capability Statement", null, wg("fhir"));
        s = new FileOutputStream(page.getFolders().dstDir + "capabilitystatement-" + name + ".json");
        new JsonParser().setOutputStyle(OutputStyle.PRETTY).compose(s, cpbs);
        s.close();
        s = new FileOutputStream(page.getFolders().dstDir + "capabilitystatement-" + name + ".canonical.json");
        new JsonParser().setOutputStyle(OutputStyle.CANONICAL).compose(s, cpbs);
        s.close();
        jsonToXhtml("capabilitystatement-" + name, "Base Capability Statement", resource2Json(cpbs), "resource-instance:CapabilityStatement", "Capability Statement", null, wg("fhir"));
        s = new FileOutputStream(page.getFolders().dstDir + "capabilitystatement-" + name + ".ttl");
        new RdfParser().setOutputStyle(OutputStyle.PRETTY).compose(s, cpbs);
        s.close();
        ttlToXhtml("capabilitystatement-" + name, "Base Capability Statement", resource2Ttl(cpbs), "resource-instance:CapabilityStatement", "Capability Statement", null, wg("fhir"));
        Utilities.copyFile(new CSFile(page.getFolders().dstDir + "capabilitystatement-" + name + ".xml"), new CSFile(page.getFolders().dstDir + "examples" + File.separator + "capabilitystatement-" + name + ".xml"));
    }
    if (buildFlags.get("all")) {
        RenderingContext lrc = page.getRc().copy().setLocalPrefix("");
        RendererFactory.factory(cpbs, lrc).render(cpbs);
        deletefromFeed(ResourceType.CapabilityStatement, name, page.getResourceBundle());
        addToResourceFeed(cpbs, page.getResourceBundle());
    }
}
Also used : RenderingContext(org.hl7.fhir.r5.renderers.utils.RenderingContext) XmlParser(org.hl7.fhir.r5.formats.XmlParser) ProfileGenerator(org.hl7.fhir.definitions.generators.specification.ProfileGenerator) StringType(org.hl7.fhir.r5.model.StringType) SearchParameterDefn(org.hl7.fhir.definitions.model.SearchParameterDefn) Operation(org.hl7.fhir.definitions.model.Operation) CSFile(org.hl7.fhir.utilities.CSFile) ResourceDefn(org.hl7.fhir.definitions.model.ResourceDefn) CapabilityStatementRestSecurityComponent(org.hl7.fhir.r5.model.CapabilityStatement.CapabilityStatementRestSecurityComponent) FileOutputStream(java.io.FileOutputStream) CapabilityStatement(org.hl7.fhir.r5.model.CapabilityStatement) CapabilityStatementSoftwareComponent(org.hl7.fhir.r5.model.CapabilityStatement.CapabilityStatementSoftwareComponent) CapabilityStatementRestComponent(org.hl7.fhir.r5.model.CapabilityStatement.CapabilityStatementRestComponent) CapabilityStatementRestResourceComponent(org.hl7.fhir.r5.model.CapabilityStatement.CapabilityStatementRestResourceComponent) JsonParser(org.hl7.fhir.r5.formats.JsonParser) RdfParser(org.hl7.fhir.r5.formats.RdfParser)

Example 12 with RdfParser

use of org.hl7.fhir.r5.formats.RdfParser in project kindling by HL7.

the class Publisher method produceOperation.

private void produceOperation(ImplementationGuideDefn ig, String name, String id, ResourceDefn resource, Operation op, SectionTracker st) throws Exception {
    OperationDefinition opd = new ProfileGenerator(page.getDefinitions(), page.getWorkerContext(), page, page.getGenDate(), page.getVersion(), dataElements, fpUsages, page.getFolders().rootDir, page.getUml(), page.getRc()).generate(name, id, resource.getName(), op, resource);
    String dir = ig == null ? "" : ig.getCode() + File.separator;
    FileOutputStream s = new FileOutputStream(page.getFolders().dstDir + dir + "operation-" + name + ".xml");
    new XmlParser().setOutputStyle(OutputStyle.PRETTY).compose(s, opd);
    s.close();
    s = new FileOutputStream(page.getFolders().dstDir + dir + "operation-" + name + ".canonical.xml");
    new XmlParser().setOutputStyle(OutputStyle.CANONICAL).compose(s, opd);
    s.close();
    cloneToXhtml(dir + "operation-" + name + "", "Operation Definition", true, "resource-instance:OperationDefinition", "Operation definition", resource, resource.getWg());
    s = new FileOutputStream(page.getFolders().dstDir + dir + "operation-" + name + ".json");
    new JsonParser().setOutputStyle(OutputStyle.PRETTY).compose(s, opd);
    s.close();
    s = new FileOutputStream(page.getFolders().dstDir + dir + "operation-" + name + ".canonical.json");
    new JsonParser().setOutputStyle(OutputStyle.CANONICAL).compose(s, opd);
    s.close();
    jsonToXhtml(dir + "operation-" + name, "Operation Definition", resource2Json(opd), "resource-instance:OperationDefinition", "Operation definition", resource, resource.getWg());
    s = new FileOutputStream(page.getFolders().dstDir + dir + "operation-" + name + ".ttl");
    new RdfParser().setOutputStyle(OutputStyle.PRETTY).compose(s, opd);
    s.close();
    ttlToXhtml(dir + "operation-" + name, "Operation Definition", resource2Ttl(opd), "resource-instance:OperationDefinition", "Operation definition", resource, resource.getWg());
    Utilities.copyFile(new CSFile(page.getFolders().dstDir + dir + "operation-" + name + ".xml"), new CSFile(page.getFolders().dstDir + "examples" + File.separator + "operation-" + name + ".xml"));
    if (buildFlags.get("all")) {
        addToResourceFeed(opd, page.getResourceBundle(), name);
        page.getWorkerContext().cacheResource(opd);
    }
    // now we create a page for the operation
    String fnp = resource.getName().toLowerCase() + "-operation-" + op.getName().toLowerCase() + ".html";
    String src = TextFile.fileToString(page.getFolders().templateDir + "template-operation.html");
    src = page.processPageIncludes(fnp, src, "res-Operations", null, "operation-" + name + ".html", op.getResource(), null, "Operation Definition", op, ig, resource, resource.getWg());
    TextFile.stringToFile(insertSectionNumbers(src, st, fnp, 0, null), page.getFolders().dstDir + fnp);
    page.getHTMLChecker().registerFile(fnp, "Operation " + op.getName() + " for " + resource.getName(), HTMLLinkChecker.XHTML_TYPE, true);
    // now, we create an html page from the narrative
    String html = TextFile.fileToString(page.getFolders().templateDir + "template-example.html").replace("<%example%>", new XhtmlComposer(XhtmlComposer.HTML).compose(opd.getText().getDiv()));
    html = page.processPageIncludes(dir + "operation-" + name + ".html", html, "resource-instance:OperationDefinition", null, null, null, "Operation Definition", ig, resource, resource.getWg());
    TextFile.stringToFile(html, page.getFolders().dstDir + dir + "operation-" + name + ".html");
    page.getHTMLChecker().registerFile(dir + "operation-" + name + ".html", "Operation " + op.getName(), HTMLLinkChecker.XHTML_TYPE, true);
// head =
// "<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\">\r\n<head>\r\n <title>"+Utilities.escapeXml(e.getDescription())+"</title>\r\n <link rel=\"Stylesheet\" href=\"fhir.css\" type=\"text/css\" media=\"screen\"/>\r\n"+
// "</head>\r\n<body>\r\n<p>&nbsp;</p>\r\n<p>"+Utilities.escapeXml(e.getDescription())+"</p>\r\n"+
// "<p><a href=\""+n+".xml.html\">XML</a> <a href=\""+n+".json.html\">JSON</a></p>\r\n";
// tail = "\r\n</body>\r\n</html>\r\n";
// TextFile.stringToFile(head+narrative+tail, page.getFolders().dstDir + n +
// ".html");
}
Also used : XmlParser(org.hl7.fhir.r5.formats.XmlParser) ProfileGenerator(org.hl7.fhir.definitions.generators.specification.ProfileGenerator) FileOutputStream(java.io.FileOutputStream) XhtmlComposer(org.hl7.fhir.utilities.xhtml.XhtmlComposer) CSFile(org.hl7.fhir.utilities.CSFile) OperationDefinition(org.hl7.fhir.r5.model.OperationDefinition) JsonParser(org.hl7.fhir.r5.formats.JsonParser) RdfParser(org.hl7.fhir.r5.formats.RdfParser)

Example 13 with RdfParser

use of org.hl7.fhir.r5.formats.RdfParser in project kindling by HL7.

the class Publisher method produceLogicalModel.

private void produceLogicalModel(LogicalModel lm, ImplementationGuideDefn ig) throws Exception {
    String n = lm.getId();
    Map<String, String> examples = new HashMap<String, String>();
    File tmp = Utilities.createTempFile("tmp", ".tmp");
    TerminologyNotesGenerator tgen = new TerminologyNotesGenerator(new FileOutputStream(tmp), page);
    if (lm.hasResource())
        tgen.generate("", lm.getResource().getRoot());
    else
        tgen.generate("", lm.getDefinition());
    tgen.close();
    String tx = TextFile.fileToString(tmp.getAbsolutePath());
    DictHTMLGenerator dgen = new DictHTMLGenerator(new FileOutputStream(tmp), page, "");
    if (lm.hasResource())
        dgen.generate(lm.getResource().getRoot());
    else
        dgen.generate(lm.getDefinition());
    dgen.close();
    String dict = TextFile.fileToString(tmp.getAbsolutePath());
    MappingsGenerator mgen = new MappingsGenerator(page.getDefinitions());
    if (lm.hasResource())
        mgen.generate(lm.getResource());
    else
        mgen.generate(lm.getDefinition());
    String mappings = mgen.getMappings();
    String mappingsList = mgen.getMappingsList();
    SvgGenerator svg = new SvgGenerator(page, "", lm.getLayout(), true, false, page.getVersion());
    String fn = ig.getPrefix() + n;
    if (lm.hasResource())
        svg.generate(lm.getResource(), page.getFolders().dstDir + fn + ".svg", "2");
    else
        svg.generate(lm.getDefinition(), page.getFolders().dstDir + fn + ".svg", "2");
    String prefix = page.getBreadCrumbManager().getIndexPrefixForReference(lm.getId() + ".html");
    SectionTracker st = new SectionTracker(prefix, true);
    st.start("");
    page.getSectionTrackerCache().put(fn, st);
    if (lm.getDefinition() != null) {
        new XmlParser().setOutputStyle(OutputStyle.PRETTY).compose(new FileOutputStream(Utilities.path(page.getFolders().dstDir, ig.getPrefix(), n + ".xml")), lm.getDefinition());
        cloneToXhtml(ig.getPrefix() + n, "Logical Model " + lm.getDefinition().getName(), true, "logical-model", lm.getDefinition().getName(), null, lm.getWg());
        new JsonParser().setOutputStyle(OutputStyle.PRETTY).compose(new FileOutputStream(Utilities.path(page.getFolders().dstDir, ig.getPrefix(), n + ".json")), lm.getDefinition());
        jsonToXhtml(ig.getPrefix() + n, "Logical Model " + lm.getDefinition().getName(), new JsonParser().setOutputStyle(OutputStyle.PRETTY).composeString(lm.getDefinition()), "logical-model", lm.getDefinition().getName(), null, lm.getWg());
        ttlToXhtml(ig.getPrefix() + n, "Logical Model " + lm.getDefinition().getName(), new RdfParser().setOutputStyle(OutputStyle.PRETTY).composeString(lm.getDefinition()), "logical-model", lm.getDefinition().getName(), null, lm.getWg());
    }
    if (lm.getWg() != null && lm.getResource().getWg() == null)
        lm.getResource().setWg(lm.getWg());
    String template = "template-logical";
    String src = TextFile.fileToString(page.getFolders().templateDir + template + ".html");
    Map<String, String> values = new HashMap<String, String>();
    if (lm.hasResource())
        src = insertSectionNumbers(page.processResourceIncludes(n, lm.getResource(), "", "", "", tx, dict, src, mappings, mappingsList, "resource", n + ".html", ig, values, lm.getWg(), examples), st, n + ".html", ig.getLevel(), null);
    else
        src = insertSectionNumbers(new LogicalModelProcessor(n, page, ig, lm.getDefinition().getId(), "logical-model", n + ".html", lm.getDefinition(), tx, dict, examples, ig.getLogicalModels(), page.getDefinitions(), page.getVersion()).process(src), st, n + ".html", ig.getLevel(), null);
    TextFile.stringToFile(src, page.getFolders().dstDir + fn + ".html");
    page.getHTMLChecker().registerFile(fn + ".html", "Base Page for " + n, HTMLLinkChecker.XHTML_TYPE, true);
    src = TextFile.fileToString(page.getFolders().templateDir + "template-logical-definitions.html");
    if (lm.hasResource())
        TextFile.stringToFile(insertSectionNumbers(page.processResourceIncludes(n, lm.getResource(), "", "", "", tx, dict, src, mappings, mappingsList, "res-Detailed Descriptions", n + "-definitions.html", ig, values, lm.getWg(), examples), st, n + "-definitions.html", ig.getLevel(), null), page.getFolders().dstDir + fn + "-definitions.html");
    else
        TextFile.stringToFile(insertSectionNumbers(new LogicalModelProcessor(n, page, ig, lm.getDefinition().getId(), "logical-model", n + ".html", lm.getDefinition(), tx, dict, examples, ig.getLogicalModels(), page.getDefinitions(), page.getVersion()).process(src), st, n + "-definitions.html", ig.getLevel(), null), page.getFolders().dstDir + fn + "-definitions.html");
    page.getHTMLChecker().registerFile(fn + "-definitions.html", "Detailed Descriptions for " + (lm.hasResource() ? lm.getResource().getName() : lm.getDefinition().getName()), HTMLLinkChecker.XHTML_TYPE, true);
    src = TextFile.fileToString(page.getFolders().templateDir + "template-logical-examples.html");
    if (lm.hasResource())
        TextFile.stringToFile(insertSectionNumbers(page.processResourceIncludes(n, lm.getResource(), "", "", "", tx, dict, src, mappings, mappingsList, "resource", n + ".html", ig, values, lm.getWg(), examples), st, n + ".html", ig.getLevel(), null), page.getFolders().dstDir + fn + "-implementations.html");
    else
        TextFile.stringToFile(insertSectionNumbers(new LogicalModelProcessor(n, page, ig, lm.getDefinition().getId(), "logical-model", n + ".html", lm.getDefinition(), tx, dict, examples, ig.getLogicalModels(), page.getDefinitions(), page.getVersion()).process(src), st, n + "-implementations.html", ig.getLevel(), null), page.getFolders().dstDir + fn + "-implementations.html");
    page.getHTMLChecker().registerFile(fn + "-implementations.html", "Implementations for " + (lm.hasResource() ? lm.getResource().getName() : lm.getDefinition().getName()), HTMLLinkChecker.XHTML_TYPE, true);
    src = TextFile.fileToString(page.getFolders().templateDir + "template-logical-mappings.html");
    if (lm.hasResource())
        TextFile.stringToFile(insertSectionNumbers(page.processResourceIncludes(n, lm.getResource(), "", "", "", tx, dict, src, mappings, mappingsList, "res-Mappings", n + "-mappings.html", ig, values, lm.getWg(), examples), st, n + "-mappings.html", ig.getLevel(), null), page.getFolders().dstDir + fn + "-mappings.html");
    else
        TextFile.stringToFile(insertSectionNumbers(new LogicalModelProcessor(n, page, ig, lm.getDefinition().getId(), "logical-model", n + ".html", lm.getDefinition(), tx, dict, examples, ig.getLogicalModels(), page.getDefinitions(), page.getVersion()).process(src), st, n + "-mappings.html", ig.getLevel(), null), page.getFolders().dstDir + fn + "-mappings.html");
    page.getHTMLChecker().registerFile(fn + "-mappings.html", "Formal Mappings for " + n, HTMLLinkChecker.XHTML_TYPE, true);
    src = TextFile.fileToString(page.getFolders().templateDir + "template-logical-analysis.html");
    if (lm.hasResource())
        TextFile.stringToFile(insertSectionNumbers(page.processResourceIncludes(n, lm.getResource(), "", "", "", tx, dict, src, mappings, mappingsList, "res-Analysis", n + "-analysis.html", ig, values, lm.getWg(), examples), st, n + "-analysis.html", ig.getLevel(), null), page.getFolders().dstDir + fn + "-analysis.html");
    else
        TextFile.stringToFile(insertSectionNumbers(new LogicalModelProcessor(n, page, ig, lm.getDefinition().getId(), "logical-model", n + ".html", lm.getDefinition(), tx, dict, examples, ig.getLogicalModels(), page.getDefinitions(), page.getVersion()).process(src), st, n + "-analysis.html", ig.getLevel(), null), page.getFolders().dstDir + fn + "-analysis.html");
    page.getHTMLChecker().registerFile(fn + "-analysis.html", "Analysis for " + n, HTMLLinkChecker.XHTML_TYPE, true);
    tmp.delete();
}
Also used : XmlParser(org.hl7.fhir.r5.formats.XmlParser) LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap) TerminologyNotesGenerator(org.hl7.fhir.definitions.generators.specification.TerminologyNotesGenerator) DictHTMLGenerator(org.hl7.fhir.definitions.generators.specification.DictHTMLGenerator) MappingsGenerator(org.hl7.fhir.definitions.generators.specification.MappingsGenerator) SvgGenerator(org.hl7.fhir.definitions.generators.specification.SvgGenerator) FileOutputStream(java.io.FileOutputStream) IniFile(org.hl7.fhir.utilities.IniFile) File(java.io.File) CSFile(org.hl7.fhir.utilities.CSFile) TextFile(org.hl7.fhir.utilities.TextFile) JsonParser(org.hl7.fhir.r5.formats.JsonParser) RdfParser(org.hl7.fhir.r5.formats.RdfParser)

Example 14 with RdfParser

use of org.hl7.fhir.r5.formats.RdfParser in project org.hl7.fhir.core by hapifhir.

the class ToolsHelper method executeJson.

public String executeJson(String[] args) throws IOException, FHIRException {
    FileInputStream in;
    File source = new CSFile(args[1]);
    File dest = new CSFile(args[2]);
    File destc = new CSFile(Utilities.changeFileExt(args[2], ".canonical.json"));
    File destt = new CSFile(args[2] + ".tmp");
    File destr = new CSFile(Utilities.changeFileExt(args[2], ".ttl"));
    if (!source.exists())
        throw new FHIRException("Source File \"" + source.getAbsolutePath() + "\" not found");
    in = new CSFileInputStream(source);
    XmlParser p = new XmlParser();
    Resource rf = p.parse(in);
    JsonParser json = new JsonParser();
    json.setOutputStyle(OutputStyle.PRETTY);
    FileOutputStream s = new FileOutputStream(dest);
    json.compose(s, rf);
    s.close();
    json.setOutputStyle(OutputStyle.CANONICAL);
    s = new FileOutputStream(destc);
    json.compose(s, rf);
    s.close();
    json.setSuppressXhtml("Snipped for Brevity");
    json.setOutputStyle(OutputStyle.PRETTY);
    s = new FileOutputStream(destt);
    json.compose(s, rf);
    s.close();
    RdfParserBase rdf = new RdfParser();
    s = new FileOutputStream(destr);
    rdf.compose(s, rf);
    s.close();
    return TextFile.fileToString(destt.getAbsolutePath());
}
Also used : XmlParser(org.hl7.fhir.r4.formats.XmlParser) FileOutputStream(java.io.FileOutputStream) Resource(org.hl7.fhir.r4.model.Resource) CSFile(org.hl7.fhir.utilities.CSFile) RdfParserBase(org.hl7.fhir.r4.formats.RdfParserBase) CSFile(org.hl7.fhir.utilities.CSFile) File(java.io.File) TextFile(org.hl7.fhir.utilities.TextFile) FHIRException(org.hl7.fhir.exceptions.FHIRException) FileInputStream(java.io.FileInputStream) CSFileInputStream(org.hl7.fhir.utilities.CSFileInputStream) CSFileInputStream(org.hl7.fhir.utilities.CSFileInputStream) JsonParser(org.hl7.fhir.r4.formats.JsonParser) RdfParser(org.hl7.fhir.r4.formats.RdfParser)

Example 15 with RdfParser

use of org.hl7.fhir.r5.formats.RdfParser in project org.hl7.fhir.core by hapifhir.

the class ToolsHelper method processExamples.

public void processExamples(String rootDir, Collection<String> list) throws FHIRException {
    for (String n : list) {
        try {
            String filename = rootDir + n + ".xml";
            // 1. produce canonical XML
            CSFileInputStream source = new CSFileInputStream(filename);
            FileOutputStream dest = new FileOutputStream(Utilities.changeFileExt(filename, ".canonical.xml"));
            XmlParser p = new XmlParser();
            Resource r = p.parse(source);
            XmlParser cxml = new XmlParser();
            cxml.setOutputStyle(OutputStyle.CANONICAL);
            cxml.compose(dest, r);
            // 2. produce JSON
            source = new CSFileInputStream(filename);
            dest = new FileOutputStream(Utilities.changeFileExt(filename, ".json"));
            r = p.parse(source);
            JsonParser json = new JsonParser();
            json.setOutputStyle(OutputStyle.PRETTY);
            json.compose(dest, r);
            json = new JsonParser();
            json.setOutputStyle(OutputStyle.CANONICAL);
            dest = new FileOutputStream(Utilities.changeFileExt(filename, ".canonical.json"));
            json.compose(dest, r);
            // 2. produce JSON
            dest = new FileOutputStream(Utilities.changeFileExt(filename, ".ttl"));
            RdfParserBase rdf = new RdfParser();
            rdf.compose(dest, r);
        } catch (Exception e) {
            e.printStackTrace();
            throw new FHIRException("Error Processing " + n + ".xml: " + e.getMessage(), e);
        }
    }
}
Also used : XmlParser(org.hl7.fhir.dstu3.formats.XmlParser) FileOutputStream(java.io.FileOutputStream) Resource(org.hl7.fhir.dstu3.model.Resource) RdfParserBase(org.hl7.fhir.dstu3.formats.RdfParserBase) FHIRException(org.hl7.fhir.exceptions.FHIRException) CSFileInputStream(org.hl7.fhir.utilities.CSFileInputStream) NotImplementedException(org.apache.commons.lang3.NotImplementedException) IOException(java.io.IOException) XmlPullParserException(org.xmlpull.v1.XmlPullParserException) FHIRException(org.hl7.fhir.exceptions.FHIRException) JsonParser(org.hl7.fhir.dstu3.formats.JsonParser) RdfParser(org.hl7.fhir.dstu3.formats.RdfParser)

Aggregations

FileOutputStream (java.io.FileOutputStream)16 CSFileInputStream (org.hl7.fhir.utilities.CSFileInputStream)11 FHIRException (org.hl7.fhir.exceptions.FHIRException)10 CSFile (org.hl7.fhir.utilities.CSFile)9 RdfParser (org.hl7.fhir.r5.formats.RdfParser)8 JsonParser (org.hl7.fhir.r5.formats.JsonParser)7 XmlParser (org.hl7.fhir.r5.formats.XmlParser)7 File (java.io.File)6 TextFile (org.hl7.fhir.utilities.TextFile)6 FileInputStream (java.io.FileInputStream)5 IOException (java.io.IOException)5 NotImplementedException (org.apache.commons.lang3.NotImplementedException)5 XmlPullParserException (org.xmlpull.v1.XmlPullParserException)5 ProfileGenerator (org.hl7.fhir.definitions.generators.specification.ProfileGenerator)2 ResourceDefn (org.hl7.fhir.definitions.model.ResourceDefn)2 JsonParser (org.hl7.fhir.dstu2016may.formats.JsonParser)2 RdfParser (org.hl7.fhir.dstu2016may.formats.RdfParser)2 RdfParserBase (org.hl7.fhir.dstu2016may.formats.RdfParserBase)2 XmlParser (org.hl7.fhir.dstu2016may.formats.XmlParser)2 Resource (org.hl7.fhir.dstu2016may.model.Resource)2