Search in sources :

Example 91 with Resource

use of org.hl7.fhir.r4.model.Resource in project kindling by HL7.

the class Publisher method getIgProfile.

public StructureDefinition getIgProfile(String base) throws Exception {
    String[] parts = base.split("#");
    StructureDefinition p = getIGProfileByURL(parts[0]);
    if (p == null)
        return null;
    // this is recursive, but will terminate at the root
    processProfile(p);
    if (parts.length == 1) {
        if (p.getSnapshot() == null)
            // or else we could fill it in?
            throw new Exception("StructureDefinition " + base + " has no snapshot");
        return p;
    }
    for (Resource r : p.getContained()) {
        if (r instanceof StructureDefinition && r.getId().equals(parts[1])) {
            StructureDefinition pc = (StructureDefinition) r;
            if (pc.getSnapshot() == null) {
                StructureDefinition ps = getSnapShotForProfile(pc.getBaseDefinition());
                processProfile(pc);
            }
            return pc;
        }
    }
    throw new Exception("Unable to find snapshot for " + base);
}
Also used : StructureDefinition(org.hl7.fhir.r5.model.StructureDefinition) Resource(org.hl7.fhir.r5.model.Resource) DomainResource(org.hl7.fhir.r5.model.DomainResource) CanonicalResource(org.hl7.fhir.r5.model.CanonicalResource) TransformerException(javax.xml.transform.TransformerException) IOException(java.io.IOException) FHIRException(org.hl7.fhir.exceptions.FHIRException) FileNotFoundException(java.io.FileNotFoundException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 92 with Resource

use of org.hl7.fhir.r4.model.Resource in project kindling by HL7.

the class Publisher method resource2Ttl.

private String resource2Ttl(Resource r) throws Exception {
    ByteArrayOutputStream bytes = new ByteArrayOutputStream();
    IParser rdf = new RdfParser().setOutputStyle(OutputStyle.PRETTY);
    rdf.setSuppressXhtml("Snipped for Brevity");
    rdf.compose(bytes, r);
    bytes.close();
    return new String(bytes.toByteArray());
}
Also used : ByteArrayOutputStream(java.io.ByteArrayOutputStream) IParser(org.hl7.fhir.r5.formats.IParser) RdfParser(org.hl7.fhir.r5.formats.RdfParser)

Example 93 with Resource

use of org.hl7.fhir.r4.model.Resource in project kindling by HL7.

the class Publisher method stripJson.

private InputStream stripJson(InputStream source) throws Exception {
    JsonParser p = new JsonParser();
    Resource r = p.parse(source);
    minify(r);
    ByteArrayOutputStream bo = new ByteArrayOutputStream();
    p.compose(bo, r);
    bo.close();
    return new ByteArrayInputStream(bo.toByteArray());
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) Resource(org.hl7.fhir.r5.model.Resource) DomainResource(org.hl7.fhir.r5.model.DomainResource) CanonicalResource(org.hl7.fhir.r5.model.CanonicalResource) ByteArrayOutputStream(java.io.ByteArrayOutputStream) JsonParser(org.hl7.fhir.r5.formats.JsonParser)

Example 94 with Resource

use of org.hl7.fhir.r4.model.Resource in project kindling by HL7.

the class PageProcessor method resourcesHeader.

private String resourcesHeader(String mode) {
    StringBuilder b = new StringBuilder();
    b.append("<ul class=\"nav nav-tabs\">");
    b.append(makeHeaderTab("Resource Definitions", "resource.html", mode == null || "base".equals(mode)));
    b.append(makeHeaderTab("Examples", "resources-examples.html", mode == null || "examples".equals(mode)));
    b.append(makeHeaderTab("Detailed Descriptions", "resources-definitions.html", mode == null || "definitions".equals(mode)));
    b.append("</ul>\r\n");
    return b.toString();
}
Also used : CommaSeparatedStringBuilder(org.hl7.fhir.utilities.CommaSeparatedStringBuilder)

Example 95 with Resource

use of org.hl7.fhir.r4.model.Resource in project kindling by HL7.

the class PageProcessor method buildIgRegistry.

private String buildIgRegistry(ImplementationGuideDefn ig, String types) throws Exception {
    StringBuilder b = new StringBuilder();
    b.append("<table class=\"codes\">\r\n");
    b.append("<tr><td><b>Id</b></td><td><b>Name</b></td><td><b>Description</b></td></tr>\r\n");
    // examples second:
    boolean example = false;
    while (true) {
        boolean usedPurpose = false;
        for (String type : types.split("\\,")) {
            List<String> ids = new ArrayList<String>();
            Map<String, ImplementationGuideDefinitionResourceComponent> map = new HashMap<String, ImplementationGuideDefinitionResourceComponent>();
            for (ImplementationGuideDefinitionResourceComponent r : ig.getIg().getDefinition().getResource()) {
                Resource ar = (Resource) r.getUserData(ToolResourceUtilities.RES_ACTUAL_RESOURCE);
                if (ar != null && ar.getResourceType().toString().equals(type) && r.hasExample() == example) {
                    String id = ar.getId();
                    ids.add(id);
                    map.put(id, r);
                }
                Example ex = (Example) r.getUserData(ToolResourceUtilities.NAME_RES_EXAMPLE);
                if (ex != null && ex.getResourceName().equals(type) && r.hasExample() == example) {
                    String id = ex.getId();
                    ids.add(id);
                    map.put(id, r);
                }
            }
            if (ids.size() > 0) {
                if (!usedPurpose) {
                    b.append("<tr><td colspan=\"3\" style=\"background: #DFDFDF\"><b>" + (example ? "Specification" : "Example") + "</b> </td></tr>\r\n");
                    usedPurpose = true;
                }
                Collections.sort(ids);
                b.append("<tr><td colspan=\"3\" style=\"background: #EFEFEF\">" + getTypePluralDesc(type) + "</td></tr>\r\n");
                for (String id : ids) {
                    ImplementationGuideDefinitionResourceComponent r = map.get(id);
                    b.append("<tr><td><a href=\"" + Utilities.changeFileExt(r.getReference().getReference(), ".html") + "\">" + id + "</a></td><td>" + Utilities.escapeXml(r.getName()) + "</td><td>" + Utilities.escapeXml(r.getDescription()) + "</td></tr>\r\n");
                }
            }
        }
        if (example)
            break;
        else
            example = true;
    }
    b.append("</table>\r\n");
    return b.toString();
}
Also used : CommaSeparatedStringBuilder(org.hl7.fhir.utilities.CommaSeparatedStringBuilder) HashMap(java.util.HashMap) Example(org.hl7.fhir.definitions.model.Example) OperationExample(org.hl7.fhir.definitions.model.Operation.OperationExample) ArrayList(java.util.ArrayList) Resource(org.hl7.fhir.r5.model.Resource) DomainResource(org.hl7.fhir.r5.model.DomainResource) CanonicalResource(org.hl7.fhir.r5.model.CanonicalResource) ImplementationGuideDefinitionResourceComponent(org.hl7.fhir.r5.model.ImplementationGuide.ImplementationGuideDefinitionResourceComponent)

Aggregations

ArrayList (java.util.ArrayList)319 Resource (org.hl7.fhir.r4.model.Resource)312 Test (org.junit.jupiter.api.Test)297 IBaseResource (org.hl7.fhir.instance.model.api.IBaseResource)270 BundleEntryComponent (org.hl7.fhir.r4.model.Bundle.BundleEntryComponent)230 FHIRException (org.hl7.fhir.exceptions.FHIRException)201 Test (org.junit.Test)190 IOException (java.io.IOException)181 Bundle (org.hl7.fhir.r4.model.Bundle)169 Date (java.util.Date)147 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)139 List (java.util.List)133 HashMap (java.util.HashMap)131 Patient (org.hl7.fhir.r4.model.Patient)118 FileOutputStream (java.io.FileOutputStream)110 Reference (org.hl7.fhir.r4.model.Reference)109 IGenericClient (ca.uhn.fhir.rest.client.api.IGenericClient)102 File (java.io.File)100 Collectors (java.util.stream.Collectors)95 XhtmlNode (org.hl7.fhir.utilities.xhtml.XhtmlNode)92