All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.opencds.cqf.quick.HtmlBuilder Maven / Gradle / Ivy

There is a newer version: 3.1.0
Show newest version
package org.opencds.cqf.quick;

import java.net.URI;
import java.net.URISyntaxException;

public class HtmlBuilder {

    private QuickAtlas atlas;

    private final String header = "\n" +
            "\n" +
            "    \n" +
            "\n" +
            "    \n" +
            "\n" +
            "     \n" +
            "\n" +
            "    \n" +
            "     \n" +
            "     \n" +
            "     \n" +
            "\n" +
            "    \n" +
            "     \n" +
            "     \n" +
            "     \n" +
            "\n" +
            "    \n" +
            "    \n" +
            "\n" +
            "    \n" +
            "     \n" +
            "     \n" +
            "     \n" +
            "     \n" +
            "     \n" +
            "\n" +
            "\n" +
            "";

    private final String footer = "\n" +
            "";

    private final String mustSupportIcon = " ";
    private final String modifierIcon = " ";
    private final String extensionIcon = " ";

    private StringBuilder html = new StringBuilder();
    private String profileName;

    private String fileName;
    public String getFileName() {
        return fileName;
    }

    public HtmlBuilder(String profileName, QuickAtlas atlas) {
        this.profileName = profileName;
        this.atlas = atlas;
        this.fileName = "QUICK-" + profileName + ".html";
        html.append(header);
    }

    public String build() {
        html.append("
\n"); html.append(footer); return html.toString(); } public HtmlBuilder buildLegend() { html.append(String.format("

%s = Must Support, %s = Is Modifier, %s = QiCore defined extension

\n", mustSupportIcon, modifierIcon, extensionIcon)); return this; } public HtmlBuilder buildHeader(String name) { String header = String.format( "
\n

%s

\n", name, name, name ); html.append(header); return this; } public HtmlBuilder buildOverviewHeader(String name) { String header = String.format( "
\n

%s

\n", name ); html.append(header); return this; } public HtmlBuilder buildParagraph(String content) { html.append("

").append(content).append("

\n"); return this; } public HtmlBuilder buildTableStart() { html.append("\n").append("\n"); return this; } public HtmlBuilder buildTableEnd() { html.append("
FieldCard.TypeDescription
\n"); return this; } public HtmlBuilder buildOverviewTableStart() { html.append("\n").append("\n"); return this; } public HtmlBuilder buildOverviewTableEnd() { html.append("
FHIR TypeCQL Type
\n"); return this; } public HtmlBuilder buildRow(boolean mustSupport, boolean isModifier, boolean qicoreExt, String field, String card, String type, String description) { String row = String.format( "%s%s%s%s%s%s%s\n", mustSupport ? mustSupportIcon : "", isModifier ? modifierIcon : "", qicoreExt ? extensionIcon : "", field, card, type, description ); html.append(row); return this; } public HtmlBuilder buildOverviewRow(String fhirType, String cqlType, String href) { String row = String.format( "%s%s\n", fhirType, href, cqlType ); html.append(row); return this; } public HtmlBuilder buildOverviewRowWithInterval(String fhirType, String cqlType, String href) { String intervalUrl = atlas.getCqlIntervalUrl(); String row = String.format( "%sInterval<%s>\n", intervalUrl, fhirType, href, cqlType ); html.append(row); return this; } public HtmlBuilder appendHtml(String content) { html.append(content); return this; } public static String buildLink(String href, String label) { if (href == null) { return String.format("%s", "", label); } try { URI uri = new URI(href); if (uri.isAbsolute()) { return String.format("%s", href, label); } } catch (URISyntaxException use) { // ignore } return String.format("%s", href, label); } public static String buildNewTabLink(String href, String label) { return String.format("%s", href, label); } public static String buildBinding(String href, String label, String strength) { if (href.contains("us/core/ValueSet/")) { href = href.replace("ValueSet/", "ValueSet-") + ".html"; } else if (href.contains("http://hl7.org/fhir/us/qicore/ValueSet/")) { href = href.replace("http://hl7.org/fhir/us/qicore/ValueSet/", "../ValueSet-") + ".html"; } String binding = "
Binding: "; binding += String.format("%s ", href, label); switch (strength) { case "required": binding += "(required)"; break; case "extensible": binding += "(extensible)"; break; case "preferred": binding += "(preferred)"; break; case "example": binding += "(example)"; break; } return binding; } // public HtmlBuilder buildRowWithBinding(boolean mustSupport, boolean isModifier, boolean qicoreExt, // String field, String title, String card, String type, // String description, String binding) // { // String row = String.format( // "%s%s%s%s\nBinding: %s\n", title, field, card, type, description, binding // ); // html.append(row); // return this; // } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy