Search in sources :

Example 1 with ConceptMap

use of org.hl7.fhir.r4b.model.ConceptMap in project kindling by HL7.

the class Publisher method produceSpecMap.

private void produceSpecMap() throws IOException {
    SpecMapManager spm = new SpecMapManager("hl7.fhir.core", page.getVersion().toCode(), page.getVersion().toCode(), page.getBuildId(), page.getGenDate(), CANONICAL_BASE);
    for (StructureDefinition sd : page.getWorkerContext().allStructures()) {
        if (sd.hasUserData("path")) {
            spm.path(sd.getUrl(), sd.getUserString("path").replace("\\", "/"));
            spm.target(sd.getUserString("path").replace("\\", "/"));
        }
    }
    for (StructureDefinition sd : page.getWorkerContext().getExtensionDefinitions()) {
        if (sd.hasUserData("path")) {
            spm.path(sd.getUrl(), sd.getUserString("path").replace("\\", "/"));
            spm.target(sd.getUserString("path").replace("\\", "/"));
        }
    }
    for (String s : page.getCodeSystems().keys()) {
        CodeSystem cs = page.getCodeSystems().get(s);
        if (cs == null && !Utilities.existsInList(s, "http://unitsofmeasure.org", "http://loinc.org", "http://fdasis.nlm.nih.gov", "http://www.nlm.nih.gov/research/umls/rxnorm", "urn:oid:1.2.36.1.2001.1005.17") && !SIDUtilities.isknownCodeSystem(s))
            System.out.println("No code system resource found for " + s);
    }
    for (CodeSystem cs : page.getCodeSystems().getList()) {
        if (cs != null && cs.hasUserData("path")) {
            spm.path(cs.getUrl(), cs.getUserString("path").replace("\\", "/"));
            spm.target(cs.getUserString("path").replace("\\", "/"));
        }
    }
    for (ValueSet vs : page.getValueSets().getList()) {
        if (vs.hasUserData("path")) {
            spm.path(vs.getUrl(), vs.getUserString("path").replace("\\", "/"));
            spm.target(vs.getUserString("path").replace("\\", "/"));
        }
    }
    for (ConceptMap cm : page.getConceptMaps().getList()) {
        if (cm.hasUserData("path")) {
            spm.path(cm.getUrl(), cm.getUserString("path").replace("\\", "/"));
            spm.target(cm.getUserString("path").replace("\\", "/"));
        }
    }
    for (String s : page.getDefinitions().getPageTitles().keySet()) {
        spm.page(s, page.getDefinitions().getPageTitles().get(s));
    }
    for (String n : page.getIni().getPropertyNames("pages")) {
        spm.target(n);
    }
    for (ResourceDefn rd : page.getDefinitions().getResources().values()) {
        spm.target(rd.getName().toLowerCase() + ".html");
        spm.target(rd.getName().toLowerCase() + "-definitions.html");
        spm.target(rd.getName().toLowerCase() + "-mappings.html");
        spm.target(rd.getName().toLowerCase() + "-examples.html");
        spm.target(rd.getName().toLowerCase() + "-profiles.html");
        if (!rd.getOperations().isEmpty())
            spm.target(rd.getName().toLowerCase() + "-operations.html");
        for (Example ex : rd.getExamples()) {
            ImplementationGuideDefn ig = ex.getIg() == null ? null : page.getDefinitions().getIgs().get(ex.getIg());
            String prefix = (ig == null || ig.isCore()) ? "" : ig.getCode() + "/";
            spm.target(prefix + ex.getTitle() + ".html");
        }
    }
    for (Profile p : page.getDefinitions().getPackList()) {
        spm.target(p.getId() + ".html");
    }
    // for (String url : page.getDefinitions().getMapTypes().keySet()) {
    // spm.map(url, page.getDefinitions().getMapTypes().get(url).getPreamble());
    // }
    scanForImages(spm, page.getFolders().dstDir, page.getFolders().dstDir);
    scanForPages(spm, page.getFolders().dstDir, page.getFolders().dstDir);
    for (String url : page.getDefinitions().getRedirectList().keySet()) {
        // http://hl7.org/fhir/ = 20 chars
        spm.target(url.substring(20));
    }
    spm.save(page.getFolders().dstDir + "spec.internals");
}
Also used : StructureDefinition(org.hl7.fhir.r5.model.StructureDefinition) Example(org.hl7.fhir.definitions.model.Example) ConceptMap(org.hl7.fhir.r5.model.ConceptMap) ImplementationGuideDefn(org.hl7.fhir.definitions.model.ImplementationGuideDefn) CodeSystem(org.hl7.fhir.r5.model.CodeSystem) ValueSet(org.hl7.fhir.r5.model.ValueSet) ResourceDefn(org.hl7.fhir.definitions.model.ResourceDefn) Profile(org.hl7.fhir.definitions.model.Profile)

Example 2 with ConceptMap

use of org.hl7.fhir.r4b.model.ConceptMap in project kindling by HL7.

the class Publisher method generateConceptMaps.

private void generateConceptMaps() throws Exception {
    List<ConceptMap> list = new ArrayList<>();
    page.getConceptMaps().listAll(list);
    for (ConceptMap cm : list) {
        if (cm.hasUserData("generate")) {
            generateConceptMap(cm);
        }
    }
}
Also used : ArrayList(java.util.ArrayList) ConceptMap(org.hl7.fhir.r5.model.ConceptMap)

Example 3 with ConceptMap

use of org.hl7.fhir.r4b.model.ConceptMap in project kindling by HL7.

the class Publisher method generateConceptMap.

private void generateConceptMap(ConceptMap cm) throws Exception {
    String filename = cm.getUserString("path");
    RenderingContext lrc = page.getRc().copy().setLocalPrefix("").setTooCostlyNoteEmpty(PageProcessor.TOO_MANY_CODES_TEXT_EMPTY).setTooCostlyNoteNotEmpty(PageProcessor.TOO_MANY_CODES_TEXT_NOT_EMPTY);
    RendererFactory.factory(cm, lrc).render(cm);
    IParser json = new JsonParser().setOutputStyle(OutputStyle.PRETTY);
    FileOutputStream s = new FileOutputStream(page.getFolders().dstDir + Utilities.changeFileExt(filename, ".json"));
    json.compose(s, cm);
    s.close();
    json = new JsonParser().setOutputStyle(OutputStyle.CANONICAL);
    s = new FileOutputStream(page.getFolders().dstDir + Utilities.changeFileExt(filename, ".canonical.json"));
    json.compose(s, cm);
    s.close();
    String n = Utilities.changeFileExt(filename, "");
    jsonToXhtml(n, cm.getName(), resource2Json(cm), "conceptmap-instance", "Concept Map", null, wg("vocab"));
    ttlToXhtml(n, cm.getName(), resource2Ttl(cm), "conceptmap-instance", "Concept Map", null, wg("vocab"));
    IParser xml = new XmlParser().setOutputStyle(OutputStyle.PRETTY);
    s = new FileOutputStream(page.getFolders().dstDir + Utilities.changeFileExt(filename, ".xml"));
    xml.compose(s, cm);
    s.close();
    xml = new XmlParser().setOutputStyle(OutputStyle.CANONICAL);
    s = new FileOutputStream(page.getFolders().dstDir + Utilities.changeFileExt(filename, ".canonical.xml"));
    xml.compose(s, cm);
    s.close();
    cloneToXhtml(n, cm.getName(), false, "conceptmap-instance", "Concept Map", null, wg("vocab"));
    // now, we create an html page from the narrative
    String narrative = new XhtmlComposer(XhtmlComposer.HTML).compose(cm.getText().getDiv());
    String html = TextFile.fileToString(page.getFolders().templateDir + "template-example.html").replace("<%example%>", narrative);
    html = page.processPageIncludes(Utilities.changeFileExt(filename, ".html"), html, "conceptmap-instance", null, null, null, "Concept Map", null, null, wg("vocab"));
    TextFile.stringToFile(html, page.getFolders().dstDir + Utilities.changeFileExt(filename, ".html"));
    conceptMapsFeed.getEntry().add(new BundleEntryComponent().setResource(cm).setFullUrl("http://hl7.org/fhir/" + cm.fhirType() + "/" + cm.getId()));
    page.getConceptMaps().see(cm, page.packageInfo());
    page.getHTMLChecker().registerFile(n + ".html", cm.getName(), HTMLLinkChecker.XHTML_TYPE, false);
}
Also used : RenderingContext(org.hl7.fhir.r5.renderers.utils.RenderingContext) XmlParser(org.hl7.fhir.r5.formats.XmlParser) BundleEntryComponent(org.hl7.fhir.r5.model.Bundle.BundleEntryComponent) FileOutputStream(java.io.FileOutputStream) XhtmlComposer(org.hl7.fhir.utilities.xhtml.XhtmlComposer) IParser(org.hl7.fhir.r5.formats.IParser) JsonParser(org.hl7.fhir.r5.formats.JsonParser)

Example 4 with ConceptMap

use of org.hl7.fhir.r4b.model.ConceptMap in project kindling by HL7.

the class Publisher method produceConceptMap.

private void produceConceptMap(ConceptMap cm, ResourceDefn rd, SectionTracker st) throws Exception {
    RenderingContext lrc = page.getRc().copy().setLocalPrefix("");
    RendererFactory.factory(cm, lrc).render(cm);
    String n = cm.getUserString("path");
    FileOutputStream s = new FileOutputStream(page.getFolders().dstDir + Utilities.changeFileExt(n, ".xml"));
    new XmlParser().setOutputStyle(OutputStyle.PRETTY).compose(s, cm);
    s.close();
    s = new FileOutputStream(page.getFolders().dstDir + Utilities.changeFileExt(n, ".canonical.xml"));
    new XmlParser().setOutputStyle(OutputStyle.CANONICAL).compose(s, cm);
    s.close();
    s = new FileOutputStream(page.getFolders().dstDir + Utilities.changeFileExt(n, ".json"));
    new JsonParser().setOutputStyle(OutputStyle.PRETTY).compose(s, cm);
    s.close();
    s = new FileOutputStream(page.getFolders().dstDir + Utilities.changeFileExt(n, ".canonical.json"));
    new JsonParser().setOutputStyle(OutputStyle.CANONICAL).compose(s, cm);
    s.close();
    Utilities.copyFile(new CSFile(page.getFolders().dstDir + Utilities.changeFileExt(n, ".xml")), new CSFile(page.getFolders().dstDir + "examples" + File.separator + Utilities.changeFileExt(n, ".xml")));
    // saveAsPureHtml(cm, new FileOutputStream(Utilities.path(page.getFolders().dstDir, "html", n)), true);
    String src = TextFile.fileToString(page.getFolders().templateDir + "template-status-map.html");
    Map<String, String> others = new HashMap<String, String>();
    others.put("status-map", new XhtmlComposer(XhtmlComposer.HTML).compose(cm.getText().getDiv()));
    TextFile.stringToFile(insertSectionNumbers(page.processPageIncludes(n, src, "conceptmap-instance", others, null, null, "Profile", null, rd, rd.getWg()), st, n, 0, null), page.getFolders().dstDir + n);
    page.getHTMLChecker().registerFile(n, cm.getTitle(), HTMLLinkChecker.XHTML_TYPE, true);
    cloneToXhtml(Utilities.changeFileExt(n, ""), cm.getTitle(), true, "conceptmap-instance", "Profile", null, ((ResourceDefn) cm.getUserData("resource-definition")).getWg());
    jsonToXhtml(Utilities.changeFileExt(n, ""), cm.getTitle(), resource2Json(cm), "conceptmap-instance", "Profile", null, ((ResourceDefn) cm.getUserData("resource-definition")).getWg());
    ttlToXhtml(Utilities.changeFileExt(n, ""), cm.getTitle(), resource2Ttl(cm), "conceptmap-instance", "Profile", null, ((ResourceDefn) cm.getUserData("resource-definition")).getWg());
}
Also used : RenderingContext(org.hl7.fhir.r5.renderers.utils.RenderingContext) XmlParser(org.hl7.fhir.r5.formats.XmlParser) LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap) FileOutputStream(java.io.FileOutputStream) XhtmlComposer(org.hl7.fhir.utilities.xhtml.XhtmlComposer) CSFile(org.hl7.fhir.utilities.CSFile) JsonParser(org.hl7.fhir.r5.formats.JsonParser)

Example 5 with ConceptMap

use of org.hl7.fhir.r4b.model.ConceptMap in project kindling by HL7.

the class PageProcessor method parseConceptMapMapping.

private ConceptMap parseConceptMapMapping(ElementDefn logical, ElementDefinition resource, String src) throws FHIRException {
    if (!src.startsWith("{map:"))
        return null;
    ConceptMap map = new ConceptMap();
    map.setId(logical.getPath() + "2" + resource.getPath());
    map.setUrl("http://hl7.org/fhir/ConceptMap/" + map.getId());
    map.setVersion(version.toCode());
    ConceptMapGroupComponent grp = map.addGroup();
    String[] statements = src.substring(0, src.length() - 1).substring(5).split("\\;");
    if (statements.length == 0)
        throw new FHIRException("Unable to parse map details '" + src + "'");
    for (String s : statements) {
        String[] p = s.split("\\=");
        if (p.length < 2)
            throw new FHIRException("Unable to parse map details '" + src + "'");
        if (":default".equals(p[0].trim())) {
            grp.getUnmapped().setMode(ConceptMapGroupUnmappedMode.FIXED);
            grp.getUnmapped().setCode(p[1].trim());
        } else {
            grp.addElement().setCode(p[0].trim()).addTarget().setRelationship(ConceptMapRelationship.EQUIVALENT).setCode(p[1].trim());
        }
    }
    return map;
}
Also used : ConceptMap(org.hl7.fhir.r5.model.ConceptMap) FHIRException(org.hl7.fhir.exceptions.FHIRException) ConceptMapGroupComponent(org.hl7.fhir.r5.model.ConceptMap.ConceptMapGroupComponent)

Aggregations

ConceptMap (org.hl7.fhir.dstu3.model.ConceptMap)34 Test (org.junit.Test)31 ArrayList (java.util.ArrayList)29 HashMap (java.util.HashMap)27 FHIRException (org.hl7.fhir.exceptions.FHIRException)26 ConceptMap (org.hl7.fhir.r4.model.ConceptMap)23 XhtmlNode (org.hl7.fhir.utilities.xhtml.XhtmlNode)23 ConceptMap (org.hl7.fhir.r5.model.ConceptMap)22 ConceptMapGroupComponent (org.hl7.fhir.r5.model.ConceptMap.ConceptMapGroupComponent)17 ConceptMapGroupComponent (org.hl7.fhir.dstu3.model.ConceptMap.ConceptMapGroupComponent)15 HashSet (java.util.HashSet)13 ConceptMapGroupComponent (org.hl7.fhir.r4.model.ConceptMap.ConceptMapGroupComponent)13 StructureDefinition (org.hl7.fhir.r5.model.StructureDefinition)12 FileOutputStream (java.io.FileOutputStream)11 ValueSet (org.hl7.fhir.r5.model.ValueSet)11 SourceElementComponent (org.hl7.fhir.dstu3.model.ConceptMap.SourceElementComponent)10 Test (org.junit.jupiter.api.Test)10 ConceptMap (org.hl7.fhir.dstu2016may.model.ConceptMap)9 Coding (org.hl7.fhir.r4.model.Coding)9 SourceElementComponent (org.hl7.fhir.r4.model.ConceptMap.SourceElementComponent)9