Search in sources :

Example 21 with DefinedCode

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

the class PageProcessor method generateCode.

private void generateCode(BindingSpecification cd, StringBuilder s, boolean hasSource, boolean hasId, boolean hasComment, boolean hasDefinition, boolean hasParent, int level, DefinedCode c) {
    String id = hasId ? "<td>" + fixNull(c.getId()) + "</td>" : "";
    String src = "";
    if (hasSource) {
        if (Utilities.noString(c.getSystem())) {
            src = "<td></td>";
        } else {
            String url = c.getSystem();
            url = fixUrlReference(url);
            src = "<td><a href=\"" + url + "\">" + codeSystemDescription(c.getSystem()) + "</a></td>";
        }
    }
    String lvl = hasParent ? "<td>" + Integer.toString(level) + "</td>" : "";
    String indent = "";
    for (int i = 1; i < level; i++) indent = indent + "&nbsp;&nbsp;";
    if (hasComment)
        s.append("    <tr>" + id + src + lvl + "<td>" + indent + Utilities.escapeXml(c.getCode()) + "</td><td>" + Utilities.escapeXml(c.getDefinition()) + "</td><td>" + Utilities.escapeXml(c.getComment()) + "</td></tr>\r\n");
    else if (hasDefinition)
        s.append("    <tr>" + id + src + lvl + "<td>" + indent + Utilities.escapeXml(c.getCode()) + "</td><td colspan=\"2\">" + Utilities.escapeXml(c.getDefinition()) + "</td></tr>\r\n");
    else
        s.append("    <tr>" + id + src + lvl + "<td colspan=\"3\">" + indent + Utilities.escapeXml(c.getCode()) + "</td></tr>\r\n");
    for (DefinedCode ch : c.getChildCodes()) {
        generateCode(cd, s, hasSource, hasId, hasComment, hasDefinition, hasParent, level + 1, ch);
    }
}
Also used : DefinedCode(org.hl7.fhir.definitions.model.DefinedCode) ContactPoint(org.hl7.fhir.r5.model.ContactPoint)

Example 22 with DefinedCode

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

the class PageProcessor method genResCodes.

private String genResCodes() {
    StringBuilder html = new StringBuilder();
    List<String> names = new ArrayList<String>();
    names.addAll(definitions.getKnownResources().keySet());
    Collections.sort(names);
    for (String n : names) {
        DefinedCode c = definitions.getKnownResources().get(n);
        String htmlFilename = c.getComment();
        html.append("  <tr><td><a href=\"" + htmlFilename + ".html\">" + c.getCode() + "</a></td><td>" + Utilities.escapeXml(c.getDefinition()) + "</td></tr>");
    }
    return html.toString();
}
Also used : CommaSeparatedStringBuilder(org.hl7.fhir.utilities.CommaSeparatedStringBuilder) DefinedCode(org.hl7.fhir.definitions.model.DefinedCode) ArrayList(java.util.ArrayList)

Example 23 with DefinedCode

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

the class PageProcessor method getDefinition.

private String getDefinition(String n, String c) {
    ElementDefn e = null;
    try {
        e = definitions.getElementByPath(n.split("\\."), "Status Codes", true);
    } catch (Exception ex) {
        throw new Error("Unable to find " + n, ex);
    }
    if (e == null) {
        throw new Error("Unable to find " + n);
    }
    if (e.getBinding() == null)
        return null;
    List<DefinedCode> t;
    try {
        t = e.getBinding().getAllCodes(definitions.getCodeSystems(), definitions.getValuesets(), true);
    } catch (Exception e1) {
        return null;
    }
    if (t == null)
        return null;
    for (DefinedCode d : t) {
        if (d.getCode().equals(c))
            return d.getDefinition();
    }
    return null;
}
Also used : DefinedCode(org.hl7.fhir.definitions.model.DefinedCode) ElementDefn(org.hl7.fhir.definitions.model.ElementDefn) FHIRFormatError(org.hl7.fhir.exceptions.FHIRFormatError) TransformerFactoryConfigurationError(javax.xml.transform.TransformerFactoryConfigurationError) UcumException(org.fhir.ucum.UcumException) TransformerException(javax.xml.transform.TransformerException) TransformerConfigurationException(javax.xml.transform.TransformerConfigurationException) IOException(java.io.IOException) FHIRException(org.hl7.fhir.exceptions.FHIRException) URISyntaxException(java.net.URISyntaxException) PathEngineException(org.hl7.fhir.exceptions.PathEngineException) DefinitionException(org.hl7.fhir.exceptions.DefinitionException) FileNotFoundException(java.io.FileNotFoundException) NotImplementedException(org.apache.commons.lang3.NotImplementedException)

Example 24 with DefinedCode

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

the class OldSpreadsheetParser method parseCodes.

private void parseCodes(List<DefinedCode> codes, Sheet sheet) throws Exception {
    for (int row = 0; row < sheet.rows.size(); row++) {
        DefinedCode c = new DefinedCode();
        c.setId(sheet.getColumn(row, "Id"));
        c.setAbstract(sheet.getColumn(row, "Abstract").toUpperCase().equals("Y"));
        c.setCode(sheet.getColumn(row, "Code"));
        c.setDisplay(sheet.getColumn(row, "Display"));
        if (c.hasCode() && !c.hasDisplay())
            c.setDisplay(Utilities.humanize(c.getCode()));
        c.setSystem(sheet.getColumn(row, "System"));
        c.setDefinition(Utilities.appendPeriod(processDefinition(sheet.getColumn(row, "Definition"))));
        c.setComment(Utilities.appendPeriod(sheet.getColumn(row, "Comment")));
        c.setParent(sheet.getColumn(row, "Parent"));
        c.setV2Map(sheet.getColumn(row, "v2"));
        c.setV3Map(sheet.getColumn(row, "v3"));
        for (String ct : sheet.columns) if (ct.startsWith("Display:") && !Utilities.noString(sheet.getColumn(row, ct)))
            c.getLangs().put(ct.substring(8), sheet.getColumn(row, ct));
        if (Utilities.noString(c.getId()) && Utilities.noString(c.getSystem()))
            throw new Exception("code has no id or system (" + sheet.title + ") " + getLocation(row));
        codes.add(c);
    }
}
Also used : DefinedCode(org.hl7.fhir.definitions.model.DefinedCode) FHIRException(org.hl7.fhir.exceptions.FHIRException)

Example 25 with DefinedCode

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

the class SourceParser method loadResource.

private ResourceDefn loadResource(String n, Map<String, ResourceDefn> map, boolean isAbstract, boolean isTemplate, String t, boolean isInterface) throws Exception {
    String folder = n;
    WorkGroup wg = definitions.getWorkgroups().get(ini.getStringProperty("workgroups", n));
    if (wg == null)
        throw new Exception("No Workgroup found for resource " + n + ": '" + ini.getStringProperty("workgroups", n) + "'");
    File f = new File(Utilities.path(srcDir, folder, n + ".svg"));
    if (isTemplate) {
        File spreadsheet = new CSFile((srcDir) + folder + File.separatorChar + n + "-spreadsheet.xml");
        OldSpreadsheetParser sparser = new OldSpreadsheetParser("core", new CSFileInputStream(spreadsheet), spreadsheet.getName(), spreadsheet.getAbsolutePath(), definitions, srcDir, logger, registry, version, context, genDate, isAbstract, page, false, ini, wg, definitions.getProfileIds(), fpUsages, page.getConceptMaps(), exceptionIfExcelNotNormalised, page.packageInfo(), page.getRc());
        ResourceDefn root;
        try {
            root = sparser.parseResource(isTemplate);
        } catch (Exception e) {
            throw new Exception("Error Parsing Resource " + n + ": " + e.getMessage(), e);
        }
        root.setAbstract(isAbstract);
        root.setInterface(isInterface);
        errors.addAll(sparser.getErrors());
        setResourceProps(n, wg, root);
        String sc = ini.getStringProperty("security-categorization", root.getName().toLowerCase());
        if (sc != null) {
            root.setSecurityCategorization(SecurityCategorization.fromCode(sc));
        } else if (!Utilities.existsInList(root.getName(), "Resource", "DomainResource", "CanonicalResource", "MetadataResource", "MetadataPattern"))
            throw new Exception("Must have an entry in the security-categorization section of fhir.ini for the resource " + root.getName());
        for (EventDefn e : sparser.getEvents()) {
            processEvent(e, root.getRoot());
        }
        if (map != null) {
            map.put(root.getName(), root);
        }
        if (!isTemplate) {
            definitions.getKnownResources().put(root.getName(), new DefinedCode(root.getName(), root.getRoot().getDefinition(), n));
            context.getResourceNames().add(root.getName());
        }
        if (root.getNormativeVersion() != null || root.getNormativePackage() != null) {
            root.setStatus(StandardsStatus.NORMATIVE);
        }
        if (f.exists()) {
            parseSvgFile(f, root.getLayout(), f.getName());
        }
        if (map != null) {
            map.put(root.getName(), root);
        }
        return root;
    } else {
        try {
            new SpreadSheetReloader(context, srcDir, t, version.toCode()).process();
        } catch (Exception e) {
            System.out.println("Error loading spreadsheet for resource " + t + ": " + e.getMessage());
        }
        new SpreadSheetCreator(context, srcDir, t).generateSpreadsheet();
        ResourceDefn rootNew = new ResourceParser(srcDir, definitions, context, wg, registry, version.toCode(), page.getConceptMaps()).parse(n, t);
        if (f.exists()) {
            parseSvgFile(f, rootNew.getLayout(), f.getName());
        }
        if (!isTemplate) {
            definitions.getKnownResources().put(rootNew.getName(), new DefinedCode(rootNew.getName(), rootNew.getRoot().getDefinition(), n));
            context.getResourceNames().add(rootNew.getName());
        }
        setResourceProps(n, wg, rootNew);
        if (map != null) {
            map.put(rootNew.getName(), rootNew);
        }
        return rootNew;
    }
}
Also used : SpreadSheetCreator(org.hl7.fhir.definitions.parsers.spreadsheets.SpreadSheetCreator) EventDefn(org.hl7.fhir.definitions.model.EventDefn) CSFile(org.hl7.fhir.utilities.CSFile) ResourceDefn(org.hl7.fhir.definitions.model.ResourceDefn) IOException(java.io.IOException) FHIRException(org.hl7.fhir.exceptions.FHIRException) FileNotFoundException(java.io.FileNotFoundException) SAXException(org.xml.sax.SAXException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) WorkGroup(org.hl7.fhir.definitions.model.WorkGroup) DefinedCode(org.hl7.fhir.definitions.model.DefinedCode) OldSpreadsheetParser(org.hl7.fhir.definitions.parsers.spreadsheets.OldSpreadsheetParser) IniFile(org.hl7.fhir.utilities.IniFile) File(java.io.File) CSFile(org.hl7.fhir.utilities.CSFile) TextFile(org.hl7.fhir.utilities.TextFile) SpreadSheetReloader(org.hl7.fhir.definitions.parsers.spreadsheets.SpreadSheetReloader) CSFileInputStream(org.hl7.fhir.utilities.CSFileInputStream)

Aggregations

DefinedCode (org.hl7.fhir.definitions.model.DefinedCode)19 ArrayList (java.util.ArrayList)8 ElementDefn (org.hl7.fhir.definitions.model.ElementDefn)7 IOException (java.io.IOException)6 ResourceDefn (org.hl7.fhir.definitions.model.ResourceDefn)6 PrimitiveType (org.hl7.fhir.definitions.model.PrimitiveType)5 FHIRException (org.hl7.fhir.exceptions.FHIRException)5 JsonObject (com.google.gson.JsonObject)4 DefinedStringPattern (org.hl7.fhir.definitions.model.DefinedStringPattern)4 TypeDefn (org.hl7.fhir.definitions.model.TypeDefn)4 CommaSeparatedStringBuilder (org.hl7.fhir.utilities.CommaSeparatedStringBuilder)4 FileNotFoundException (java.io.FileNotFoundException)3 UnsupportedEncodingException (java.io.UnsupportedEncodingException)3 ProfiledType (org.hl7.fhir.definitions.model.ProfiledType)3 TypeRef (org.hl7.fhir.definitions.model.TypeRef)3 StructureDefinition (org.hl7.fhir.r5.model.StructureDefinition)3 CSFile (org.hl7.fhir.utilities.CSFile)3 File (java.io.File)2 TransformerException (javax.xml.transform.TransformerException)2 ConstraintStructure (org.hl7.fhir.definitions.model.ConstraintStructure)2