Search in sources :

Example 1 with MappingSpace

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

the class PageProcessor method genMappingsTable.

private String genMappingsTable() throws IOException {
    StringBuilder b = new StringBuilder();
    b.append("<table class=\"rows\">\r\n");
    b.append(" <tr>\r\n");
    b.append("  <th width=\"250\">Name</th>\r\n");
    b.append("  <th>Details</th>\r\n");
    b.append(" </tr>\r\n");
    for (String s : definitions.getMapTypes().keySet()) {
        MappingSpace m = definitions.getMapTypes().get(s);
        if (m.isPublish()) {
            b.append(" <tr>\r\n");
            b.append("  <td><a name=\"" + m.getId() + "\"></a>");
            if (m.hasLink())
                b.append("<a href=\"" + m.getLink() + "\">" + Utilities.escapeXml(m.getTitle()) + "</a></td>\r\n");
            else
                b.append(Utilities.escapeXml(m.getTitle()) + "</td>\r\n");
            b.append("  <td>Formal URL: <code>" + s + "</code>" + (m.getPreamble() != null ? "<br/>" + new XhtmlComposer(false, true).compose(m.getPreamble()) : "") + "</td>\r\n");
            b.append(" </tr>\r\n");
        }
    }
    b.append("</table>\r\n");
    return b.toString();
}
Also used : MappingSpace(org.hl7.fhir.definitions.model.MappingSpace) CommaSeparatedStringBuilder(org.hl7.fhir.utilities.CommaSeparatedStringBuilder) XhtmlComposer(org.hl7.fhir.utilities.xhtml.XhtmlComposer)

Example 2 with MappingSpace

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

the class OldSpreadsheetParser method checkMappings.

private void checkMappings(Profile pack) throws Exception {
    pack.getMappingSpaces().clear();
    Sheet sheet = loadSheet("Mappings");
    if (sheet != null) {
        for (int row = 0; row < sheet.rows.size(); row++) {
            String uri = sheet.getNonEmptyColumn(row, "Uri");
            MappingSpace ms = new MappingSpace(sheet.getNonEmptyColumn(row, "Column"), sheet.getNonEmptyColumn(row, "Title"), sheet.getNonEmptyColumn(row, "Id"), sheet.getIntColumn(row, "Sort Order"), true, false, false, sheet.hasColumn(row, "Link") ? sheet.getColumn(row, "Link") : uri);
            pack.getMappingSpaces().put(uri, ms);
        }
    }
}
Also used : MappingSpace(org.hl7.fhir.definitions.model.MappingSpace) Sheet(org.hl7.fhir.utilities.xls.XLSXmlParser.Sheet)

Example 3 with MappingSpace

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

the class MappingsGenerator method generate.

public void generate(ResourceDefn resource) throws IOException {
    StringBuilder s = new StringBuilder();
    List<String> maps = new ArrayList<String>();
    listKnownMappings(resource.getRoot(), maps);
    Collections.sort(maps, new Sorter());
    StringBuilder list = new StringBuilder();
    for (String m : maps) {
        MappingSpace ms = definitions.getMapTypes().get(m);
        list.append("|" + ms.getTitle() + "#" + ms.getId());
        s.append("<a name=\"" + m + "\"> </a><a name=\"" + ms.getId() + "\"> </a>");
        if (!Utilities.noString(ms.getLink()))
            s.append("<h3>" + ms.getTitle() + " (<a href=\"" + ms.getLink() + "\">" + m + "</a>)</h3>");
        else
            s.append("<h3>" + ms.getTitle() + " (" + m + ")</h3>");
        XhtmlNode pre = ms.getPreamble();
        if (pre != null)
            s.append(new XhtmlComposer(XhtmlComposer.HTML).compose(pre));
        s.append("<table class=\"grid\">\r\n");
        genElement(s, 0, resource.getRoot(), m, ROOT_ONLY, true, ms.isSparse());
        genInherited(s, resource, m);
        genElement(s, 0, resource.getRoot(), m, CHILDREN_ONLY, true, ms.isSparse());
        s.append("</table>\r\n");
    }
    mappings = s.toString();
    mappingsList = list.length() == 0 ? "" : list.toString().substring(1);
}
Also used : MappingSpace(org.hl7.fhir.definitions.model.MappingSpace) ArrayList(java.util.ArrayList) XhtmlComposer(org.hl7.fhir.utilities.xhtml.XhtmlComposer) XhtmlNode(org.hl7.fhir.utilities.xhtml.XhtmlNode)

Example 4 with MappingSpace

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

the class ProfileGenerator method addElementConstraint.

/*
   *     // resource
    // domain resource
    for (ElementDefn child : definitions.getBaseResources().get("DomainResource").getRoot().getElements()) 
      defineElement(null, p, p.getSnapshot(), child, r.getRoot().getName()+"."+child.getName(), containedSlices, new ArrayList<ProfileGenerator.SliceHandle>(), SnapShotMode.Resource);

   */
/*
  private String registerMapping(ConformancePackage ap, StructureDefinition p, String m) {
    for (StructureDefinitionMappingComponent map : p.getMapping()) {
      if (map.getUri().equals(m))
        return map.getIdentity();
    }
    StructureDefinitionMappingComponent map = new StructureDefinitionMappingComponent();
    MappingSpace space = definitions.getMapTypes().get(m);
    if (space != null)
      map.setIdentity(space.getId());
    else
      map.setIdentity("m" + Integer.toString(p.getMapping().size()+1));
    map.setUri(m);
    String name = ap.metadata(m+"-name");
    if (Utilities.noString(name) && space != null)
      name = space.getTitle();
    if (!Utilities.noString(name))
      map.setName(name);
    String comments = ap.metadata(m+"-comments");
    if (Utilities.noString(comments) && space != null)
        comments = space.getPreamble();
    if (!Utilities.noString(comments))
      map.setComments(comments);
    return map.getIdentity();
  }
   */
private ElementDefinition addElementConstraint(StructureDefinition sd, ElementDefinition ed) {
    if (!ed.getPath().contains(".") && sd.getKind() == StructureDefinitionKind.RESOURCE)
        return ed;
    if (hasSystemType(ed))
        return ed;
    if (isResource(ed))
        return ed;
    if (hasConstraint(ed, "ele-1"))
        return ed;
    ElementDefinitionConstraintComponent inv = ed.addConstraint();
    inv.setKey("ele-1");
    inv.setSeverity(ConstraintSeverity.ERROR);
    inv.setHuman("All FHIR elements must have a @value or children");
    inv.setExpression("hasValue() or (children().count() > id.count())");
    inv.setXpath("@value|f:*|h:div");
    inv.setSource("http://hl7.org/fhir/StructureDefinition/Element");
    return ed;
}
Also used : ElementDefinitionConstraintComponent(org.hl7.fhir.r5.model.ElementDefinition.ElementDefinitionConstraintComponent)

Example 5 with MappingSpace

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

the class SourceParser method loadMappingSpaces.

private void loadMappingSpaces() throws Exception {
    FileInputStream is = null;
    try {
        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
        factory.setNamespaceAware(true);
        DocumentBuilder builder = factory.newDocumentBuilder();
        is = new FileInputStream(Utilities.path(srcDir, "mappingSpaces.xml"));
        Document doc = builder.parse(is);
        Element e = XMLUtil.getFirstChild(doc.getDocumentElement());
        while (e != null) {
            MappingSpace m = new MappingSpace(XMLUtil.getNamedChild(e, "columnName").getTextContent(), XMLUtil.getNamedChild(e, "title").getTextContent(), XMLUtil.getNamedChild(e, "id").getTextContent(), Integer.parseInt(XMLUtil.getNamedChild(e, "sort").getTextContent()), isTrue(XMLUtil.getNamedChild(e, "publish")), isTrue(XMLUtil.getNamedChild(e, "sparse")), isTrue(XMLUtil.getNamedChild(e, "pattern")), XMLUtil.getNamedChild(e, "link") != null ? XMLUtil.getNamedChild(e, "link").getTextContent() : XMLUtil.getNamedChild(e, "url").getTextContent());
            definitions.getMapTypes().put(XMLUtil.getNamedChild(e, "url").getTextContent(), m);
            Element p = XMLUtil.getNamedChild(e, "preamble");
            if (p != null)
                m.setPreamble(new XhtmlParser().parseHtmlNode(p).setName("div"));
            e = XMLUtil.getNextSibling(e);
        }
    } catch (Exception e) {
        throw new Exception("Error processing mappingSpaces.xml: " + e.getMessage(), e);
    } finally {
        IOUtils.closeQuietly(is);
    }
}
Also used : MappingSpace(org.hl7.fhir.definitions.model.MappingSpace) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) XhtmlParser(org.hl7.fhir.utilities.xhtml.XhtmlParser) DocumentBuilder(javax.xml.parsers.DocumentBuilder) Element(org.w3c.dom.Element) Document(org.w3c.dom.Document) CSFileInputStream(org.hl7.fhir.utilities.CSFileInputStream) FileInputStream(java.io.FileInputStream) IOException(java.io.IOException) FHIRException(org.hl7.fhir.exceptions.FHIRException) FileNotFoundException(java.io.FileNotFoundException) SAXException(org.xml.sax.SAXException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException)

Aggregations

MappingSpace (org.hl7.fhir.definitions.model.MappingSpace)4 XhtmlComposer (org.hl7.fhir.utilities.xhtml.XhtmlComposer)2 FileInputStream (java.io.FileInputStream)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 DocumentBuilder (javax.xml.parsers.DocumentBuilder)1 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)1 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)1 FHIRException (org.hl7.fhir.exceptions.FHIRException)1 ElementDefinitionConstraintComponent (org.hl7.fhir.r5.model.ElementDefinition.ElementDefinitionConstraintComponent)1 CSFileInputStream (org.hl7.fhir.utilities.CSFileInputStream)1 CommaSeparatedStringBuilder (org.hl7.fhir.utilities.CommaSeparatedStringBuilder)1 XhtmlNode (org.hl7.fhir.utilities.xhtml.XhtmlNode)1 XhtmlParser (org.hl7.fhir.utilities.xhtml.XhtmlParser)1 Sheet (org.hl7.fhir.utilities.xls.XLSXmlParser.Sheet)1 Document (org.w3c.dom.Document)1 Element (org.w3c.dom.Element)1 SAXException (org.xml.sax.SAXException)1