Search in sources :

Example 86 with DomainResource

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

the class Publisher method addToResourceFeed.

private void addToResourceFeed(DomainResource resource, Bundle dest, String filename) throws Exception {
    maybeFixResourceId(resource, filename);
    if (resource.getId() == null)
        throw new Exception("Resource has no id");
    BundleEntryComponent byId = ResourceUtilities.getEntryById(dest, resource.getResourceType(), resource.getId());
    if (byId != null)
        dest.getEntry().remove(byId);
    deletefromFeed(resource.getResourceType(), resource.getId(), dest);
    ResourceUtilities.meta(resource).setLastUpdated(page.getGenDate().getTime());
    if (!resource.hasText() || !resource.getText().hasDiv()) {
        RendererFactory.factory(resource, page.getRc().copy()).render(resource);
    }
    if (resource.getText() == null || resource.getText().getDiv() == null)
        throw new Exception("Example Resource " + resource.getId() + " does not have any narrative");
    dest.getEntry().add(new BundleEntryComponent().setResource(resource).setFullUrl("http://hl7.org/fhir/" + resource.getResourceType().toString() + "/" + resource.getId()));
}
Also used : BundleEntryComponent(org.hl7.fhir.r5.model.Bundle.BundleEntryComponent) TransformerException(javax.xml.transform.TransformerException) IOException(java.io.IOException) FHIRException(org.hl7.fhir.exceptions.FHIRException) FileNotFoundException(java.io.FileNotFoundException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 87 with DomainResource

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

the class Publisher method validate.

private void validate() throws Exception {
    page.log("Validating", LogMessageType.Process);
    ResourceValidator val = new ResourceValidator(page.getDefinitions(), page.getTranslations(), page.getCodeSystems(), page.getFolders().srcDir, fpUsages, page.getSuppressedMessages(), page.getWorkerContext());
    val.resolvePatterns();
    ProfileValidator valp = new ProfileValidator(page.getWorkerContext(), null);
    for (String n : page.getDefinitions().getTypes().keySet()) page.getValidationErrors().addAll(val.checkStucture(n, page.getDefinitions().getTypes().get(n)));
    val.checkSearchParams(page.getValidationErrors(), page.getDefinitions().getResourceByName("Resource"));
    val.checkSearchParams(page.getValidationErrors(), page.getDefinitions().getResourceByName("DomainResource"));
    for (String n : page.getDefinitions().sortedResourceNames()) if (hasBuildFlag("page-" + n.toLowerCase()))
        page.getValidationErrors().addAll(val.check(n, page.getDefinitions().getResources().get(n)));
    page.getValidationErrors().addAll(val.check("Parameters", page.getDefinitions().getResourceByName("Parameters")));
    for (String rname : page.getDefinitions().sortedResourceNames()) {
        ResourceDefn r = page.getDefinitions().getResources().get(rname);
        checkExampleLinks(page.getValidationErrors(), r);
    }
    for (Compartment cmp : page.getDefinitions().getCompartments()) page.getValidationErrors().addAll(val.check(cmp));
    page.setPatternFinder(val.getPatternFinder());
    val.report();
    val.summariseSearchTypes(page.getSearchTypeUsage());
    val.dumpParams();
    val.close();
    checkAllOk();
}
Also used : ResourceValidator(org.hl7.fhir.definitions.validation.ResourceValidator) Compartment(org.hl7.fhir.definitions.model.Compartment) ResourceDefn(org.hl7.fhir.definitions.model.ResourceDefn) ProfileValidator(org.hl7.fhir.validation.profile.ProfileValidator)

Example 88 with DomainResource

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

the class Publisher method saveAsPureHtml.

private void saveAsPureHtml(DomainResource resource, FileOutputStream stream, boolean isPretty) throws Exception {
    XhtmlDocument html = new XhtmlDocument();
    html.setNodeType(NodeType.Document);
    html.addComment("Generated by automatically by FHIR Tooling");
    XhtmlNode doc = html.addTag("html");
    XhtmlNode head = doc.addTag("head");
    XhtmlNode work = head.addTag("title");
    work.addText("test title");
    work = head.addTag("link");
    work.setAttribute("rel", "Stylesheet");
    work.setAttribute("href", "/css/fhir.css");
    work.setAttribute("type", "text/css");
    work.setAttribute("media", "screen");
    work = doc.addTag("body");
    if ((resource.hasText()) && (resource.getText().hasDiv())) {
        work.getAttributes().putAll(resource.getText().getDiv().getAttributes());
        work.getChildNodes().addAll(resource.getText().getDiv().getChildNodes());
    }
    XhtmlComposer xml = new XhtmlComposer(XhtmlComposer.HTML, isPretty);
    xml.compose(stream, html);
    stream.close();
}
Also used : XhtmlComposer(org.hl7.fhir.utilities.xhtml.XhtmlComposer) XhtmlDocument(org.hl7.fhir.utilities.xhtml.XhtmlDocument) XhtmlNode(org.hl7.fhir.utilities.xhtml.XhtmlNode)

Example 89 with DomainResource

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

the class PageProcessor method processPageIncludesForPrinting.

String processPageIncludesForPrinting(String file, String src, Resource resource, ImplementationGuideDefn ig) throws Exception {
    boolean even = false;
    List<String> tabs = new ArrayList<String>();
    while (src.contains("<%") || src.contains("[%")) {
        int i1 = src.indexOf("<%");
        int i2 = src.indexOf("%>");
        if (i1 == -1) {
            i1 = src.indexOf("[%");
            i2 = src.indexOf("%]");
        }
        String s1 = src.substring(0, i1);
        String s2 = src.substring(i1 + 2, i2).trim();
        String s3 = src.substring(i2 + 2);
        String name = file.substring(0, file.indexOf("."));
        String[] com = s2.split(" ");
        if (com.length == 3 && com[0].equals("edt")) {
            if (tabs != null)
                tabs.add("tabs-" + com[1]);
            src = s1 + orgDT(com[1], xmlForDt(com[1], com[2]), treeForDt(com[1]), umlForDt(com[1], com[2]), umlForDt(com[1], com[2] + "b"), profileRef(com[1]), tsForDt(com[1]), jsonForDt(com[1], com[2]), ttlForDt(com[1], com[2]), diffForDt(com[1], com[2])) + s3;
        } else if (com.length == 2 && com[0].equals("dt")) {
            if (tabs != null)
                tabs.add("tabs-" + com[1]);
            src = s1 + xmlForDt(com[1], null) + tsForDt(com[1]) + s3;
        } else if (com.length == 2 && com[0].equals("adt")) {
            if (tabs != null)
                tabs.add("tabs-" + com[1]);
            src = s1 + xmlForDt(com[1], null) + tsForDt(com[1]) + s3;
        } else if (com.length == 2 && com[0].equals("dt.constraints"))
            src = s1 + genConstraints(com[1], "") + s3;
        else if (com.length == 2 && com[0].equals("dt.restrictions"))
            src = s1 + genRestrictions(com[1]) + s3;
        else if (com.length == 2 && com[0].equals("dictionary"))
            src = s1 + dictForDt(com[1]) + s3;
        else if (Utilities.existsInList(com[0], "pageheader", "dtheader", "atheader", "mdtheader", "edheader", "mmheader", "drheader", "elheader", "belheader", "extheader", "resourcesheader", "formatsheader", "narrheader", "refheader", "extrasheader", "profilesheader", "txheader", "txheader0", "fmtheader", "igheader", "cmpheader", "atomheader", "dictheader", "ctheader", "adheader", "pdheader", "tdheader", "cdheader", "diheader", "statheader", "ordistheader", "ucheader", "rrheader"))
            src = s1 + s3;
        else if (com[0].equals("resheader"))
            src = s1 + resHeader(name, "Document", com.length > 1 ? com[1] : null) + s3;
        else if (com[0].equals("aresheader"))
            src = s1 + abstractResHeader(name, "Document", com.length > 1 ? com[1] : null) + s3;
        else if (com[0].equals("codelist"))
            src = s1 + codelist((CodeSystem) resource, com.length > 1 ? com[1] : null, false, true, file) + s3;
        else if (com[0].equals("codelist-nh"))
            src = s1 + codelist((CodeSystem) resource, com.length > 1 ? com[1] : null, false, false, file) + s3;
        else if (com[0].equals("linkcodelist"))
            src = s1 + codelist((CodeSystem) resource, com.length > 1 ? com[1] : null, true, false, file) + s3;
        else if (com[0].equals("sct-vs-list"))
            src = s1 + getSnomedCTVsList() + s3;
        else if (com[0].equals("sct-concept-list"))
            src = s1 + getSnomedCTConceptList() + s3;
        else if (com[0].equals("codetoc"))
            src = s1 + codetoc(com.length > 1 ? com[1] : null) + s3;
        else if (com[0].equals("res-category")) {
            src = s1 + resCategory(s2.substring(com[0].length() + 1)) + s3;
            even = false;
        } else if (com[0].equals("res-item")) {
            even = !even;
            src = s1 + resItem(com[1], even) + s3;
        } else if (com[0].equals("resdesc")) {
            src = s1 + resDesc(com[1]) + s3;
        } else if (com[0].equals("rescat")) {
            src = s1 + resCat(com.length == 1 ? null : s2.substring(7)) + s3;
        } else if (com[0].equals("w5"))
            src = s1 + genW5("true".equals(com[1])) + s3;
        else if (com[0].equals("vs-warning"))
            src = s1 + vsWarning((ValueSet) resource) + s3;
        else if (com[0].equals("res-status-special"))
            src = s1 + vsSpecialStatus((DomainResource) resource) + s3;
        else if (com[0].equals("file")) {
            if (new File(folders.templateDir + com[1] + ".html").exists()) {
                src = s1 + TextFile.fileToString(folders.templateDir + com[1] + ".html") + s3;
            } else {
                src = s1 + TextFile.fileToString(folders.srcDir + com[1] + ".html") + s3;
            }
        } else if (com[0].equals("conceptmaplistvs")) {
            throw new Error("Fix this");
        // BindingSpecification bs = definitions.getBindingByName(Utilities.fileTitle(file));
        // String ref;
        // if (bs == null) {
        // ref = "http://hl7.org/fhir/ValueSet/"+Utilities.fileTitle(file);
        // } else {
        // ref = bs.getReference();
        // if (ref.startsWith("valueset-"))
        // ref = ref.substring(9);
        // ref = "http://hl7.org/fhir/ValueSet/"+ref;
        // }
        // src = s1 + conceptmaplist(ref, com[1]) + s3;
        } else if (com[0].equals("dtmappings"))
            src = s1 + genDataTypeMappings(com[1]) + s3;
        else if (com[0].equals("dtusage"))
            src = s1 + genDataTypeUsage(com[1]) + s3;
        else if (com[0].equals("othertabs"))
            src = s1 + genOtherTabs(com[1], tabs) + s3;
        else if (com[0].equals("toc"))
            src = s1 + generateToc() + s3;
        else if (com.length != 1)
            throw new Exception("Instruction <%" + s2 + "%> not understood parsing page " + file);
        else if (com[0].equals("newheader"))
            src = s1 + TextFile.fileToString(folders.srcDir + "newheader.html") + s3;
        else if (com[0].equals("newheader1"))
            src = s1 + TextFile.fileToString(folders.srcDir + "newheader1.html") + s3;
        else if (com[0].equals("footer"))
            src = s1 + TextFile.fileToString(folders.srcDir + "footer.html") + s3;
        else if (com[0].equals("newfooter"))
            src = s1 + TextFile.fileToString(folders.srcDir + "newfooter.html") + s3;
        else if (com[0].equals("footer1"))
            src = s1 + TextFile.fileToString(folders.srcDir + "footer1.html") + s3;
        else if (com[0].equals("footer2"))
            src = s1 + TextFile.fileToString(folders.srcDir + "footer2.html") + s3;
        else if (com[0].equals("footer3"))
            src = s1 + TextFile.fileToString(folders.srcDir + "footer3.html") + s3;
        else if (com[0].equals("title"))
            src = s1 + Utilities.escapeXml(name.toUpperCase().substring(0, 1) + name.substring(1)) + s3;
        else if (com[0].equals("xtitle"))
            src = s1 + Utilities.escapeXml(name.toUpperCase().substring(0, 1) + name.substring(1)) + s3;
        else if (com[0].equals("name"))
            src = s1 + name + s3;
        else if (com[0].equals("version"))
            src = s1 + ini.getStringProperty("FHIR", "version") + s3;
        else if (com[0].equals("gendate"))
            src = s1 + Config.DATE_FORMAT().format(new Date()) + s3;
        else if (com[0].equals("maindiv"))
            src = s1 + s3;
        else if (com[0].equals("/maindiv"))
            src = s1 + s3;
        else if (com[0].equals("enteredInErrorTable"))
            src = s1 + enteredInErrorTable() + s3;
        else if (com[0].equals("events"))
            src = s1 + getEventsTable(file) + s3;
        else if (com[0].equals("resourcecodes"))
            src = s1 + genResCodes() + s3;
        else if (com[0].equals("datatypecodes"))
            src = s1 + genDTCodes() + s3;
        else // src = s1 + genBindingTable(false) + s3;
        if (com[0].equals("codeslist"))
            src = s1 + genCodeSystemsTable() + s3;
        else if (com[0].equals("valuesetslist"))
            src = s1 + genValueSetsTable(ig) + s3;
        else if (com[0].equals("igvaluesetslist"))
            src = s1 + genIGValueSetsTable() + s3;
        else if (com[0].equals("namespacelist"))
            src = s1 + genNSList() + s3;
        else if (com[0].equals("resimplall"))
            src = s1 + genResImplList() + s3;
        else if (com[0].equals("txurl"))
            src = s1 + "http://hl7.org/fhir/" + Utilities.fileTitle(file) + s3;
        else if (com[0].equals("vstxurl"))
            src = s1 + "http://hl7.org/fhir/ValueSet/" + Utilities.fileTitle(file) + s3;
        else if (com[0].equals("csurl")) {
            if (resource instanceof CodeSystem)
                src = s1 + ((CodeSystem) resource).getUrl() + s3;
            else
                src = s1 + ((ValueSet) resource).getUrl() + s3;
        } else if (com[0].equals("vsurl")) {
            if (resource instanceof CodeSystem)
                src = s1 + ((CodeSystem) resource).getUrl() + s3;
            else
                src = s1 + ((ValueSet) resource).getUrl() + s3;
        } else if (com[0].equals("txdef"))
            src = s1 + generateCodeDefinition(Utilities.fileTitle(file)) + s3;
        else if (com[0].equals("vsxref"))
            src = s1 + xreferencesForFhir(name) + s3;
        else if (com[0].equals("vsdef"))
            if (resource instanceof CodeSystem)
                src = s1 + Utilities.escapeXml(((CodeSystem) resource).getDescription()) + s3;
            else
                src = s1 + Utilities.escapeXml(((ValueSet) resource).getDescription()) + s3;
        else if (com[0].equals("txusage"))
            src = s1 + generateValueSetUsage((ValueSet) resource, genlevel(0), true) + s3;
        else if (com[0].equals("vsusage"))
            src = s1 + generateValueSetUsage((ValueSet) resource, genlevel(0), true) + s3;
        else if (com[0].equals("csusage"))
            src = s1 + generateCSUsage((CodeSystem) resource, genlevel(0)) + s3;
        else if (com[0].equals("vssummary"))
            src = s1 + "todo" + s3;
        else if (com[0].equals("piperesources"))
            src = s1 + pipeResources() + s3;
        else if (com[0].equals("pub-type"))
            src = s1 + publicationType + s3;
        else // src = s1 + expandValueSet(Utilities.fileTitle(file), resource == null ? null : (ValueSet) resource) + s3;
        if (com[0].equals("vsexpansionig"))
            src = s1 + expandValueSetIG((ValueSet) resource, true) + s3;
        else if (com[0].equals("pub-notice"))
            src = s1 + publicationNotice + s3;
        else if (com[0].startsWith("!"))
            src = s1 + s3;
        else if (macros.containsKey(com[0])) {
            src = s1 + macros.get(com[0]) + s3;
        } else
            throw new Exception("Instruction <%" + s2 + "%> not understood parsing page " + file);
    }
    return src;
}
Also used : DomainResource(org.hl7.fhir.r5.model.DomainResource) ArrayList(java.util.ArrayList) FHIRFormatError(org.hl7.fhir.exceptions.FHIRFormatError) TransformerFactoryConfigurationError(javax.xml.transform.TransformerFactoryConfigurationError) CodeSystem(org.hl7.fhir.r5.model.CodeSystem) ContactPoint(org.hl7.fhir.r5.model.ContactPoint) 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) Date(java.util.Date) IniFile(org.hl7.fhir.utilities.IniFile) File(java.io.File) CSFile(org.hl7.fhir.utilities.CSFile) TextFile(org.hl7.fhir.utilities.TextFile) ValueSet(org.hl7.fhir.r5.model.ValueSet)

Example 90 with DomainResource

use of org.hl7.fhir.r4b.model.DomainResource in project redmatch by aehrc.

the class RedmatchApi method export.

/**
 * Exports the generated FHIR resources that result from running a Redmatch rules document.
 *
 * @param redmatchRulesFile The Redmatch rules document.
 * @param progressReporter An object used to report progress. Can be null.
 * @param cancelToken Used to check if the user has cancelled the operation.
 * @return List of diagnostic messages.
 */
public List<Diagnostic> export(@NotNull File redmatchRulesFile, ProgressReporter progressReporter, CancelChecker cancelToken) {
    try {
        Pair<Map<String, DomainResource>, List<Diagnostic>> data = transform(redmatchRulesFile, progressReporter, cancelToken);
        // If the resource map is empty then something went wrong or the operation was cancelled by the user
        if (data.getValue0().isEmpty()) {
            return data.getValue1();
        }
        Map<String, DomainResource> resourceMap = data.getValue0();
        // Group resources by type
        final Map<String, List<DomainResource>> grouped = new HashMap<>();
        for (String key : resourceMap.keySet()) {
            DomainResource dr = resourceMap.get(key);
            String resourceType = dr.getResourceType().toString();
            List<DomainResource> list = grouped.computeIfAbsent(resourceType, k -> new ArrayList<>());
            list.add(dr);
        }
        File baseFolder = redmatchRulesFile.toPath().getParent().toFile();
        Path outputFolder = createOutputFolder(baseFolder).toPath();
        save(grouped, outputFolder, progressReporter, cancelToken);
        return data.getValue1();
    } catch (Exception e) {
        log.error(e);
        return List.of(new Diagnostic(zeroZero, "Could not complete transformation:" + e.getLocalizedMessage(), DiagnosticSeverity.Error, "API"));
    }
}
Also used : Path(java.nio.file.Path) DomainResource(org.hl7.fhir.r4.model.DomainResource) Diagnostic(org.eclipse.lsp4j.Diagnostic)

Aggregations

XhtmlNode (org.hl7.fhir.utilities.xhtml.XhtmlNode)24 FHIRException (org.hl7.fhir.exceptions.FHIRException)22 DomainResource (org.hl7.fhir.r4.model.DomainResource)21 DefinitionException (org.hl7.fhir.exceptions.DefinitionException)16 IOException (java.io.IOException)15 DomainResource (org.hl7.fhir.dstu3.model.DomainResource)15 FileOutputStream (java.io.FileOutputStream)12 ArrayList (java.util.ArrayList)11 CommaSeparatedStringBuilder (org.hl7.fhir.utilities.CommaSeparatedStringBuilder)11 Test (org.junit.jupiter.api.Test)11 Resource (org.hl7.fhir.r4.model.Resource)10 IBaseResource (org.hl7.fhir.instance.model.api.IBaseResource)9 FileNotFoundException (java.io.FileNotFoundException)8 List (java.util.List)8 NotImplementedException (org.apache.commons.lang3.NotImplementedException)8 StructureDefinition (org.hl7.fhir.r5.model.StructureDefinition)8 SystemRequestDetails (ca.uhn.fhir.jpa.partition.SystemRequestDetails)7 File (java.io.File)7 ElementDefn (org.hl7.fhir.definitions.model.ElementDefn)7 RestIntegrationTest (org.opencds.cqf.ruler.test.RestIntegrationTest)7