Search in sources :

Example 21 with IniFile

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

the class PageProcessor method populateLogicalMappingColumn.

private void populateLogicalMappingColumn(StringBuilder b, String n, String page, ElementDefn e, StructureDefinition sd, String rn, String code, String url, StringBuilder b2, IniFile ini, String iniPath) throws FHIRException {
    LogicalModelSupportInformation info = new LogicalModelSupportInformation();
    for (ElementDefinition ed : sd.getSnapshot().getElement()) {
        for (ElementDefinitionMappingComponent m : ed.getMapping()) {
            if (m.getIdentity().equals(code)) {
                String s = m.getMap();
                for (String p : s.split("\\,")) {
                    String f = p.contains("{") ? p.substring(0, p.indexOf("{")).trim() : p;
                    String cm = p.contains("{") ? p.substring(p.indexOf("{")) : null;
                    if (cm != null) {
                        cm = cm.trim();
                    }
                    if (f.equals(e.getPath())) {
                        checkMapping(info, e, ed, b2 == null, cm);
                    }
                }
            }
        }
    }
    for (StructureDefinition ext : workerContext.getExtensionDefinitions()) {
        boolean ok = false;
        for (StructureDefinitionContextComponent ec : ext.getContext()) {
            if (ec.getType() == ExtensionContextType.ELEMENT) {
                if (rn.equals(ec.getExpression()))
                    ok = true;
            }
            if (ok) {
                String map = getWorkflowMapping(ext, url);
                if (map != null) {
                    for (String p : map.split("\\,")) {
                        String f = p.contains("{") ? p.substring(0, p.indexOf("{")) : p;
                        if (f.equals(e.getPath())) {
                            checkExtMapping(info, e, ext);
                        }
                    }
                }
            }
        }
    }
    // color:
    // one color when supported and aligned
    // one color when not aligned
    // one coor when color extension
    // blank for no mapping
    String color;
    if (info.typeMismatch == TypeMappingStatus.ERROR || info.cardinalityProblem)
        color = LOGICAL_MAPPING_MISMATCH_COLOR;
    else if (info.nameChanged || info.typeMismatch == TypeMappingStatus.NEEDS_MAPPING)
        color = LOGICAL_MAPPING_NAMECHANGE_COLOR;
    else if (info.extension)
        color = LOGICAL_MAPPING_EXTENSION_COLOR;
    else if (info.elementcount > 0)
        color = LOGICAL_MAPPING_MAPPED_COLOR;
    else
        color = LOGICAL_MAPPING_NOTMAPPED_COLOR;
    if (b != null) {
        StringBuilder ns = new StringBuilder();
        for (String s : info.notes) {
            if (ns.length() > 0)
                ns.append("; ");
            ns.append(s);
        }
        b.append("  <td style=\"background-color: " + color + "\" title=\"" + ns.toString() + "\">");
        if (info.elementcount > 0)
            b.append(info.elementcount);
        else if (info.extension)
            b.append("E");
        b.append(" ");
        if (info.nameChanged)
            b.append("N");
        if (info.typeMismatch == TypeMappingStatus.ERROR)
            b.append("T");
        if (info.cardinalityProblem)
            b.append("C");
        b.append("</td>\r\n");
    }
    StringBuilder ns = new StringBuilder();
    for (String s : info.notes) {
        ns.append(s);
    }
    String tasks = ini == null ? null : ini.getStringProperty(iniPath, sd.getName() + ".tasks");
    String status = ini == null ? null : ini.getStringProperty(iniPath, sd.getName() + ".status");
    String notes = ini == null ? null : ini.getStringProperty(iniPath, sd.getName() + ".notes");
    if (b2 != null && !(Utilities.noString(ns.toString()) && Utilities.noString(tasks))) {
        b2.append("<tr style=\"background-color: " + color + "\"><td><b><a href=\"" + sd.getName().toLowerCase() + ".html\">" + sd.getName() + "</a></b></td><td><ul>" + ns.toString() + "</ul>");
        if (info.extension)
            b2.append(" (as an extension)");
        b2.append("</td><td>");
        if (info.nameChanged || info.typeMismatch != TypeMappingStatus.OK || info.cardinalityProblem) {
            boolean first = true;
            if (info.nameChanged) {
                b2.append("Names are different. ");
                first = false;
            }
            if (info.typeMismatch != TypeMappingStatus.OK) {
                if (!first)
                    b2.append("<br/>");
                b2.append("Type Mismatch. ");
                first = false;
            }
            if (info.cardinalityProblem) {
                if (!first)
                    b2.append("<br/>");
                b2.append("Cardinality Problem. ");
            }
        }
        b2.append("</td><td>");
        boolean first = true;
        if (!Utilities.noString(tasks)) {
            for (String id : tasks.split("\\;")) {
                if (!first)
                    b2.append(" | ");
                b2.append("<a href=\"https://gforge.hl7.org/gf/project/fhir/tracker/?action=TrackerItemEdit&amp;tracker_item_id=" + id.trim() + "\">GF#" + id.trim() + "</a>");
                first = false;
            }
            b2.append("</td><td>");
        }
        if (!Utilities.noString(status))
            b2.append(Utilities.escapeXml(status));
        b2.append("</td><td>");
        if (!Utilities.noString(notes))
            b2.append(Utilities.escapeXml(notes));
        b2.append("</td></tr>\r\n");
    }
}
Also used : StructureDefinition(org.hl7.fhir.r5.model.StructureDefinition) StructureDefinitionContextComponent(org.hl7.fhir.r5.model.StructureDefinition.StructureDefinitionContextComponent) CommaSeparatedStringBuilder(org.hl7.fhir.utilities.CommaSeparatedStringBuilder) ElementDefinition(org.hl7.fhir.r5.model.ElementDefinition) ElementDefinitionMappingComponent(org.hl7.fhir.r5.model.ElementDefinition.ElementDefinitionMappingComponent)

Example 22 with IniFile

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

the class PageProcessor method genLogicalAnalysis.

private String genLogicalAnalysis(ResourceDefn logical, String genlevel) throws FHIRException, IOException {
    IniFile ini = new IniFile(Utilities.path(getFolders().srcDir, logical.getName(), logical.getName() + "-tasks.ini"));
    String url = logical.getMappingUrl();
    Map<ElementDefn, StringBuilder> bm = new HashMap<>();
    List<ElementDefn> elements = new ArrayList<ElementDefn>();
    listAllElements(elements, logical.getRoot().getName(), logical.getRoot());
    for (ElementDefn e : elements) {
        StringBuilder b2 = new StringBuilder();
        bm.put(e, b2);
    }
    boolean any = false;
    for (String s : sorted(definitions.getResources().keySet())) {
        ResourceDefn rd = definitions.getResourceByName(s);
        StructureDefinition sd = rd.getProfile();
        String code = null;
        for (StructureDefinitionMappingComponent m : sd.getMapping()) {
            if (m.getUri().equals(url))
                code = m.getIdentity();
        }
        if (code != null) {
            if (hasLogicalMapping(sd, logical, code)) {
                any = true;
                for (ElementDefn e : elements) {
                    StringBuilder b2 = bm.get(e);
                    populateLogicalMappingColumn(null, logical.getRoot().getName(), rd.getName().toLowerCase() + "-definitions.html#", e, sd, rd.getName(), code, url, b2, ini, e.getPath());
                }
            }
        }
    }
    if (any) {
        StringBuilder bx = new StringBuilder();
        bx.append("<a name=\"mappings\"></a><h3>Mappings</h3>\r\n");
        bx.append("<table class=\"grid\">\r\n");
        for (ElementDefn e : elements) {
            if (logical.getRoot().getElements().contains(e)) {
                bx.append("<tr><td colspan=\"6\"><b><a href=\"" + logical.getName().toLowerCase() + "-definitions.html#" + e.getPath() + "\">" + e.getPath() + "</a></b></td></tr>\r\n");
            } else {
                bx.append("<tr><td colspan=\"6\"><b><a href=\"" + logical.getName().toLowerCase() + "-definitions.html#" + e.getPath() + "\">." + e.getPath() + "</a></b></td></tr>\r\n");
            }
            bx.append("<tr><td colspan=\"6\">" + e.getPath() + " : " + e.typeCode() + " [" + e.describeCardinality() + "]</td></tr>\r\n");
            bx.append("<tr><td>Resource</td><td>Matches</td><td>Issues</td><td>Tasks</td><td>Status</td><td>Notes</td></tr>\r\n");
            bx.append(bm.get(e).toString());
        }
        bx.append("</table>\r\n");
        return bx.toString();
    } else
        return "";
}
Also used : StructureDefinition(org.hl7.fhir.r5.model.StructureDefinition) StructureDefinitionMappingComponent(org.hl7.fhir.r5.model.StructureDefinition.StructureDefinitionMappingComponent) CommaSeparatedStringBuilder(org.hl7.fhir.utilities.CommaSeparatedStringBuilder) IniFile(org.hl7.fhir.utilities.IniFile) HashMap(java.util.HashMap) ElementDefn(org.hl7.fhir.definitions.model.ElementDefn) ArrayList(java.util.ArrayList) ResourceDefn(org.hl7.fhir.definitions.model.ResourceDefn)

Example 23 with IniFile

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

the class PageProcessor method resDesc.

private String resDesc(String name) throws Exception {
    if (definitions.hasResource(name)) {
        ResourceDefn r = definitions.getResourceByName(name);
        if (resourceCategory != null) {
            if (!ToolingExtensions.hasExtension(r.getProfile(), ToolingExtensions.EXT_RESOURCE_CATEGORY)) {
                ToolingExtensions.setStringExtension(r.getProfile(), ToolingExtensions.EXT_RESOURCE_CATEGORY, resourceCategory);
            }
            IniFile cini = new IniFile(Utilities.path(folders.rootDir, "temp", "categories.ini"));
            if (!resourceCategory.equals(cini.getStringProperty("category", r.getName()))) {
                cini.setStringProperty("category", r.getName(), resourceCategory, null);
                cini.save();
            }
        }
        return Utilities.escapeXml(r.getDefinition());
    } else {
        return " ";
    }
}
Also used : IniFile(org.hl7.fhir.utilities.IniFile) ResourceDefn(org.hl7.fhir.definitions.model.ResourceDefn)

Example 24 with IniFile

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

the class SourceParser method isOkLocally.

private boolean isOkLocally(String code) throws IOException {
    if (forPublication)
        return false;
    String inifile = Utilities.path(rootDir, "local.ini");
    if (!new File(inifile).exists())
        return false;
    IniFile ini = new IniFile(inifile);
    boolean ok = "true".equals(ini.getStringProperty("igs", code));
    return ok;
}
Also used : IniFile(org.hl7.fhir.utilities.IniFile) IniFile(org.hl7.fhir.utilities.IniFile) File(java.io.File) CSFile(org.hl7.fhir.utilities.CSFile) TextFile(org.hl7.fhir.utilities.TextFile)

Example 25 with IniFile

use of org.hl7.fhir.utilities.IniFile in project org.hl7.fhir.core by hapifhir.

the class BatchLoader method sendFile.

private static void sendFile(FHIRToolingClient client, File f, int size, IniFile ini) throws FHIRFormatError, FileNotFoundException, IOException {
    long ms = System.currentTimeMillis();
    System.out.print("Loading " + f.getName() + ".. ");
    IParser parser = f.getName().endsWith(".json") ? new JsonParser() : new XmlParser();
    Resource res = parser.parse(new FileInputStream(f));
    System.out.println("  done: (" + Long.toString(System.currentTimeMillis() - ms) + " ms)");
    if (res instanceof Bundle) {
        Bundle bnd = (Bundle) res;
        int cursor = ini.hasProperty("progress", f.getName()) ? ini.getIntegerProperty("progress", f.getName()) : 0;
        while (cursor < bnd.getEntry().size()) {
            Bundle bt = new Bundle();
            bt.setType(BundleType.BATCH);
            bt.setId(UUID.randomUUID().toString().toLowerCase());
            for (int i = cursor; i < Math.min(bnd.getEntry().size(), cursor + size); i++) {
                BundleEntryComponent be = bt.addEntry();
                be.setResource(bnd.getEntry().get(i).getResource());
                be.getRequest().setMethod(HTTPVerb.PUT);
                be.getRequest().setUrl(be.getResource().getResourceType().toString() + "/" + be.getResource().getId());
            }
            System.out.print(f.getName() + " (" + cursor + "/" + bnd.getEntry().size() + "): ");
            ms = System.currentTimeMillis();
            Bundle resp = client.transaction(bt);
            int ncursor = cursor + size;
            for (int i = 0; i < resp.getEntry().size(); i++) {
                BundleEntryComponent t = resp.getEntry().get(i);
                if (!t.getResponse().getStatus().startsWith("2")) {
                    System.out.println("failed status at " + Integer.toString(i) + ": " + t.getResponse().getStatus());
                    ncursor = cursor + i - 1;
                    break;
                }
            }
            cursor = ncursor;
            System.out.println("  .. done: (" + Long.toString(System.currentTimeMillis() - ms) + " ms) " + SimpleDateFormat.getInstance().format(new Date()));
            ini.setIntegerProperty("progress", f.getName(), cursor, null);
            ini.save();
        }
        ini.setBooleanProperty("finished", f.getName(), true, null);
        ini.save();
    } else {
        client.update(res);
        ini.setBooleanProperty("finished", f.getName(), true, null);
        ini.save();
    }
}
Also used : XmlParser(org.hl7.fhir.r4.formats.XmlParser) BundleEntryComponent(org.hl7.fhir.r4.model.Bundle.BundleEntryComponent) Bundle(org.hl7.fhir.r4.model.Bundle) Resource(org.hl7.fhir.r4.model.Resource) FileInputStream(java.io.FileInputStream) Date(java.util.Date) IParser(org.hl7.fhir.r4.formats.IParser) JsonParser(org.hl7.fhir.r4.formats.JsonParser)

Aggregations

IniFile (org.hl7.fhir.utilities.IniFile)27 File (java.io.File)16 TextFile (org.hl7.fhir.utilities.TextFile)12 ArrayList (java.util.ArrayList)7 CSFile (org.hl7.fhir.utilities.CSFile)6 FileNotFoundException (java.io.FileNotFoundException)5 IOException (java.io.IOException)5 Date (java.util.Date)5 ResourceDefn (org.hl7.fhir.definitions.model.ResourceDefn)5 FileInputStream (java.io.FileInputStream)4 FHIRException (org.hl7.fhir.exceptions.FHIRException)4 CommaSeparatedStringBuilder (org.hl7.fhir.utilities.CommaSeparatedStringBuilder)4 RandomAccessFile (java.io.RandomAccessFile)3 StructureDefinition (org.hl7.fhir.r5.model.StructureDefinition)3 JsonObject (com.google.gson.JsonObject)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 FileOutputStream (java.io.FileOutputStream)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 ParseException (java.text.ParseException)2