Search in sources :

Example 96 with Resource

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

the class PageProcessor method produceExtensions.

private String produceExtensions(ResourceDefn resource) {
    int count = 0;
    Map<String, StructureDefinition> map = new HashMap<String, StructureDefinition>();
    for (StructureDefinition sd : workerContext.getExtensionDefinitions()) {
        boolean inc = false;
        for (StructureDefinitionContextComponent ec : sd.getContext()) {
            if (ec.getType() == ExtensionContextType.ELEMENT) {
                inc = inc || (ec.getExpression().equals(resource.getName()) || ec.getExpression().startsWith(resource.getName() + "."));
            }
            if (inc)
                map.put(sd.getId(), sd);
        }
    }
    StringBuilder b = new StringBuilder();
    for (String s : sorted(map.keySet())) {
        StructureDefinition cs = map.get(s);
        count++;
        b.append("  <tr>\r\n");
        String ref = cs.getUserString("path");
        b.append("    <td><a href=\"").append(ref).append("\">").append(Utilities.escapeXml(cs.getId())).append("</a></td>\r\n");
        b.append("    <td>").append(presentContext(cs, resource.getName())).append("</td>\r\n");
        b.append("    <td>").append(Utilities.escapeXml(cs.getName())).append("</td>\r\n");
        Profile ap = (Profile) cs.getUserData("profile");
        if (ap == null)
            b.append("    <td></td>\r\n");
        else {
            ImplementationGuideDefn ig = definitions.getIgs().get(ap.getCategory());
            b.append("    <td>for <a href=\"" + ig.getPrefix() + ap.getId().toLowerCase() + ".html\">" + Utilities.escapeXml(ap.getTitle()) + "</a></td>\r\n");
        }
        b.append(" </tr>\r\n");
    }
    if (count == 0)
        b.append("<tr><td>No Extensions defined for this resource</td></tr>");
    map.clear();
    for (StructureDefinition sd : workerContext.getExtensionDefinitions()) {
        boolean inc = false;
        for (StructureDefinitionContextComponent ec : sd.getContext()) inc = inc || (ec.getExpression().equals("Resource") || ec.getExpression().equals("DomainResource") || ec.getExpression().equals("Any"));
        if (inc)
            map.put(sd.getId(), sd);
    }
    b.append("<tr><td colspan=\"4\">Extensions for all resources or elements</td></tr>");
    for (String s : sorted(map.keySet())) {
        StructureDefinition cs = map.get(s);
        count++;
        b.append("  <tr>\r\n");
        String ref = cs.getUserString("path");
        b.append("    <td colspan=\"2\"><a href=\"").append(ref).append("\">").append(Utilities.escapeXml(cs.getId())).append("</a></td>\r\n");
        b.append("    <td>").append(Utilities.escapeXml(cs.getName())).append("</td>\r\n");
        Profile ap = (Profile) cs.getUserData("profile");
        if (ap == null)
            b.append("    <td></td>\r\n");
        else {
            ImplementationGuideDefn ig = definitions.getIgs().get(ap.getCategory());
            b.append("    <td>for <a href=\"" + ig.getPrefix() + ap.getId() + ".html\">" + Utilities.escapeXml(ap.getTitle()) + "</a></td>\r\n");
        }
        b.append(" </tr>\r\n");
    }
    return b.toString();
}
Also used : StructureDefinition(org.hl7.fhir.r5.model.StructureDefinition) StructureDefinitionContextComponent(org.hl7.fhir.r5.model.StructureDefinition.StructureDefinitionContextComponent) CommaSeparatedStringBuilder(org.hl7.fhir.utilities.CommaSeparatedStringBuilder) HashMap(java.util.HashMap) ImplementationGuideDefn(org.hl7.fhir.definitions.model.ImplementationGuideDefn) ContactPoint(org.hl7.fhir.r5.model.ContactPoint) Profile(org.hl7.fhir.definitions.model.Profile)

Example 97 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 98 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 99 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 100 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)

Aggregations

Resource (org.hl7.fhir.r4.model.Resource)263 Test (org.junit.jupiter.api.Test)226 IBaseResource (org.hl7.fhir.instance.model.api.IBaseResource)213 BundleEntryComponent (org.hl7.fhir.r4.model.Bundle.BundleEntryComponent)197 Test (org.junit.Test)184 ArrayList (java.util.ArrayList)180 Bundle (org.hl7.fhir.r4.model.Bundle)154 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)121 List (java.util.List)107 Patient (org.hl7.fhir.r4.model.Patient)98 Reference (org.hl7.fhir.r4.model.Reference)98 Date (java.util.Date)97 IOException (java.io.IOException)87 Coding (org.hl7.fhir.r4.model.Coding)83 IGenericClient (ca.uhn.fhir.rest.client.api.IGenericClient)79 Collectors (java.util.stream.Collectors)78 CodeableConcept (org.hl7.fhir.r4.model.CodeableConcept)77 FHIRException (org.hl7.fhir.exceptions.FHIRException)74 IdType (org.hl7.fhir.r4.model.IdType)74 Observation (org.hl7.fhir.r4.model.Observation)74