Search in sources :

Example 91 with DomainResource

use of org.hl7.fhir.r4.model.DomainResource in project org.hl7.fhir.core by hapifhir.

the class BundleRenderer method renderDocument.

private boolean renderDocument(XhtmlNode x, Bundle b) throws UnsupportedEncodingException, FHIRException, IOException, EOperationOutcome {
    // from the spec:
    // 
    // When the document is presented for human consumption, applications SHOULD present the collated narrative portions in order:
    // * The subject resource Narrative
    // * The Composition resource Narrative
    // * The section.text Narratives
    Composition comp = (Composition) b.getEntry().get(0).getResource();
    Resource subject = resolveReference(b, comp.getSubject());
    if (subject != null) {
        XhtmlNode nx = (subject instanceof DomainResource) ? ((DomainResource) subject).getText().getDiv() : null;
        if (nx != null) {
            x.addChildren(nx);
        } else {
            RendererFactory.factory(subject, context).render(x, subject);
        }
    }
    x.hr();
    if (comp.getText().hasDiv()) {
        x.addChildren(comp.getText().getDiv());
        x.hr();
    }
    for (SectionComponent section : comp.getSection()) {
        addSection(x, section, 2, false);
    }
    return false;
}
Also used : Composition(org.hl7.fhir.r4b.model.Composition) DomainResource(org.hl7.fhir.r4b.model.DomainResource) Resource(org.hl7.fhir.r4b.model.Resource) DomainResource(org.hl7.fhir.r4b.model.DomainResource) SectionComponent(org.hl7.fhir.r4b.model.Composition.SectionComponent) XhtmlNode(org.hl7.fhir.utilities.xhtml.XhtmlNode)

Example 92 with DomainResource

use of org.hl7.fhir.r4.model.DomainResource in project org.hl7.fhir.core by hapifhir.

the class NarrativeGeneratorTests method process.

private void process(InputStream stream) throws FileNotFoundException, IOException, XmlPullParserException, EOperationOutcome, FHIRException {
    XmlParser p = new XmlParser();
    DomainResource r = (DomainResource) p.parse(stream);
    RendererFactory.factory(r, rc).render(r);
    FileOutputStream s = new FileOutputStream(TestingUtilities.tempFile("gen", "gen.xml"));
    new XmlParser().compose(s, r, true);
    s.close();
}
Also used : XmlParser(org.hl7.fhir.r4b.formats.XmlParser) DomainResource(org.hl7.fhir.r4b.model.DomainResource) FileOutputStream(java.io.FileOutputStream)

Example 93 with DomainResource

use of org.hl7.fhir.r4.model.DomainResource in project org.hl7.fhir.core by hapifhir.

the class NarrativeGenerator method generateByProfile.

private void generateByProfile(DomainResource r, StructureDefinition profile, boolean showCodeDetails) {
    XhtmlNode x = new XhtmlNode(NodeType.Element, "div");
    x.addTag("p").addTag("b").addText("Generated Narrative" + (showCodeDetails ? " with Details" : ""));
    try {
        generateByProfile(r, profile, r, profile.getSnapshot().getElement(), profile.getSnapshot().getElement().get(0), getChildrenForPath(profile.getSnapshot().getElement(), r.getResourceType().toString()), x, r.getResourceType().toString(), showCodeDetails);
    } catch (Exception e) {
        e.printStackTrace();
        x.addTag("p").addTag("b").setAttribute("style", "color: maroon").addText("Exception generating Narrative: " + e.getMessage());
    }
    inject(r, x, NarrativeStatus.GENERATED);
}
Also used : DefinitionException(org.hl7.fhir.exceptions.DefinitionException) IOException(java.io.IOException) FHIRException(org.hl7.fhir.exceptions.FHIRException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) NotImplementedException(org.apache.commons.lang3.NotImplementedException) XhtmlNode(org.hl7.fhir.utilities.xhtml.XhtmlNode)

Example 94 with DomainResource

use of org.hl7.fhir.r4.model.DomainResource in project org.hl7.fhir.core by hapifhir.

the class NarrativeGenerator method inject.

private void inject(DomainResource r, XhtmlNode x, NarrativeStatus status) {
    if (!r.hasText() || !r.getText().hasDiv() || r.getText().getDiv().getChildNodes().isEmpty()) {
        r.setText(new Narrative());
        r.getText().setDiv(x);
        r.getText().setStatus(status);
    } else {
        XhtmlNode n = r.getText().getDiv();
        n.addTag("hr");
        n.getChildNodes().addAll(x.getChildNodes());
    }
}
Also used : Narrative(org.hl7.fhir.dstu2.model.Narrative) XhtmlNode(org.hl7.fhir.utilities.xhtml.XhtmlNode)

Example 95 with DomainResource

use of org.hl7.fhir.r4.model.DomainResource in project org.hl7.fhir.core by hapifhir.

the class ProfileUtilities method checkTypeDerivation.

public void checkTypeDerivation(String purl, StructureDefinition srcSD, ElementDefinition base, ElementDefinition derived, TypeRefComponent ts) {
    boolean ok = false;
    CommaSeparatedStringBuilder b = new CommaSeparatedStringBuilder();
    String t = ts.getWorkingCode();
    for (TypeRefComponent td : base.getType()) {
        ;
        String tt = td.getWorkingCode();
        b.append(tt);
        if (td.hasCode() && (tt.equals(t))) {
            ok = true;
        }
        if (!ok) {
            StructureDefinition sdt = context.fetchTypeDefinition(tt);
            if (sdt != null && (sdt.getAbstract() || sdt.getKind() == StructureDefinitionKind.LOGICAL)) {
                StructureDefinition sdb = context.fetchTypeDefinition(t);
                while (sdb != null && !ok) {
                    ok = sdb.getType().equals(sdt.getType());
                    sdb = context.fetchResource(StructureDefinition.class, sdb.getBaseDefinition());
                }
            }
        }
        // work around for old badly generated SDs
        if (DONT_DO_THIS && Utilities.existsInList(tt, "Extension", "uri", "string", "Element")) {
            ok = true;
        }
        if (DONT_DO_THIS && Utilities.existsInList(tt, "Resource", "DomainResource") && pkp.isResource(t)) {
            ok = true;
        }
        if (ok && ts.hasTargetProfile()) {
            // check that any derived target has a reference chain back to one of the base target profiles
            for (UriType u : ts.getTargetProfile()) {
                String url = u.getValue();
                boolean tgtOk = !td.hasTargetProfile() || td.hasTargetProfile(url);
                while (url != null && !tgtOk) {
                    StructureDefinition sd = context.fetchRawProfile(url);
                    if (sd == null) {
                        if (messages != null) {
                            messages.add(new ValidationMessage(Source.InstanceValidator, IssueType.BUSINESSRULE, purl + "#" + derived.getPath(), "Cannot check whether the target profile " + url + " is valid constraint on the base because it is not known", IssueSeverity.WARNING));
                        }
                        url = null;
                        // suppress error message
                        tgtOk = true;
                    } else {
                        url = sd.getBaseDefinition();
                        tgtOk = td.hasTargetProfile(url);
                    }
                }
                if (!tgtOk) {
                    if (messages == null) {
                        throw new FHIRException(context.formatMessage(I18nConstants.ERROR_AT__THE_TARGET_PROFILE__IS_NOT__VALID_CONSTRAINT_ON_THE_BASE_, purl, derived.getPath(), url, td.getTargetProfile()));
                    } else {
                        messages.add(new ValidationMessage(Source.InstanceValidator, IssueType.BUSINESSRULE, derived.getPath(), "The target profile " + u.getValue() + " is not a valid constraint on the base (" + td.getTargetProfile() + ") at " + derived.getPath(), IssueSeverity.ERROR));
                    }
                }
            }
        }
    }
    if (!ok) {
        throw new DefinitionException(context.formatMessage(I18nConstants.STRUCTUREDEFINITION__AT__ILLEGAL_CONSTRAINED_TYPE__FROM__IN_, purl, derived.getPath(), t, b.toString(), srcSD.getUrl()));
    }
}
Also used : StructureDefinition(org.hl7.fhir.r4b.model.StructureDefinition) ValidationMessage(org.hl7.fhir.utilities.validation.ValidationMessage) TypeRefComponent(org.hl7.fhir.r4b.model.ElementDefinition.TypeRefComponent) CommaSeparatedStringBuilder(org.hl7.fhir.utilities.CommaSeparatedStringBuilder) DefinitionException(org.hl7.fhir.exceptions.DefinitionException) FHIRException(org.hl7.fhir.exceptions.FHIRException) UriType(org.hl7.fhir.r4b.model.UriType)

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