Search in sources :

Example 36 with DomainResource

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

the class NarrativeGenerator method renderBundle.

public XhtmlNode renderBundle(Bundle b) throws FHIRException {
    if (b.getType() == BundleType.DOCUMENT) {
        if (!b.hasEntry() || !(b.getEntryFirstRep().hasResource() && b.getEntryFirstRep().getResource() instanceof Composition))
            throw new FHIRException("Invalid document - first entry is not a Composition");
        Composition dr = (Composition) b.getEntryFirstRep().getResource();
        return dr.getText().getDiv();
    } else {
        XhtmlNode root = new XhtmlNode(NodeType.Element, "div");
        root.para().addText("Bundle " + b.getId() + " of type " + b.getType().toCode());
        int i = 0;
        for (BundleEntryComponent be : b.getEntry()) {
            root.hr();
            root.para().addText("Entry " + Integer.toString(i) + (be.hasFullUrl() ? "Full URL = " + be.getFullUrl() : ""));
            if (be.hasRequest())
                renderRequest(root, be.getRequest());
            if (be.hasSearch())
                renderSearch(root, be.getSearch());
            if (be.hasResponse())
                renderResponse(root, be.getResponse());
            if (be.hasResource()) {
                root.para().addText("Resource " + be.getResource().fhirType() + ":");
                if (be.hasResource() && be.getResource() instanceof DomainResource) {
                    DomainResource dr = (DomainResource) be.getResource();
                    if (dr.getText().hasDiv())
                        root.blockquote().getChildNodes().addAll(dr.getText().getDiv().getChildNodes());
                }
            }
        }
        return root;
    }
}
Also used : Composition(org.hl7.fhir.dstu3.model.Composition) BundleEntryComponent(org.hl7.fhir.dstu3.model.Bundle.BundleEntryComponent) DomainResource(org.hl7.fhir.dstu3.model.DomainResource) FHIRException(org.hl7.fhir.exceptions.FHIRException) ContactPoint(org.hl7.fhir.dstu3.model.ContactPoint) XhtmlNode(org.hl7.fhir.utilities.xhtml.XhtmlNode)

Example 37 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(String path) throws FileNotFoundException, IOException, XmlPullParserException, EOperationOutcome, FHIRException {
    XmlParser p = new XmlParser();
    DomainResource r = (DomainResource) p.parse(new FileInputStream(path));
    gen.generate(r);
    FileOutputStream s = new FileOutputStream(Utilities.path("[tmp]", "gen.xml"));
    new XmlParser().compose(s, r, true);
    s.close();
}
Also used : XmlParser(org.hl7.fhir.dstu3.formats.XmlParser) DomainResource(org.hl7.fhir.dstu3.model.DomainResource) FileOutputStream(java.io.FileOutputStream) FileInputStream(java.io.FileInputStream)

Example 38 with DomainResource

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

the class NarrativeGenerator method generateDocumentNarrative.

public XhtmlNode generateDocumentNarrative(Bundle feed) {
    /*
     When the document is presented for human consumption, applications must present the collated narrative portions of the following resources in order:
     * The Composition resource
     * The Subject resource
     * Resources referenced in the section.content
     */
    XhtmlNode root = new XhtmlNode(NodeType.Element, "div");
    Composition comp = (Composition) feed.getEntry().get(0).getResource();
    root.getChildNodes().add(comp.getText().getDiv());
    Resource subject = ResourceUtilities.getById(feed, null, comp.getSubject().getReference());
    if (subject != null && subject instanceof DomainResource) {
        root.hr();
        root.getChildNodes().add(((DomainResource) subject).getText().getDiv());
    }
    List<SectionComponent> sections = comp.getSection();
    renderSections(feed, root, sections, 1);
    return root;
}
Also used : SectionComponent(org.hl7.fhir.r4.model.Composition.SectionComponent) XhtmlNode(org.hl7.fhir.utilities.xhtml.XhtmlNode)

Example 39 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.r5.model.StructureDefinition) ValidationMessage(org.hl7.fhir.utilities.validation.ValidationMessage) TypeRefComponent(org.hl7.fhir.r5.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.r5.model.UriType)

Example 40 with DomainResource

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

the class NarrativeGenerator method generateByProfile.

private boolean generateByProfile(DomainResource r, StructureDefinition profile, boolean showCodeDetails) {
    XhtmlNode x = new XhtmlNode(NodeType.Element, "div");
    x.para().b().tx("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.para().b().setAttribute("style", "color: maroon").tx("Exception generating Narrative: " + e.getMessage());
    }
    inject(r, x, NarrativeStatus.GENERATED);
    return true;
}
Also used : TerminologyServiceException(org.hl7.fhir.exceptions.TerminologyServiceException) DefinitionException(org.hl7.fhir.exceptions.DefinitionException) IOException(java.io.IOException) FHIRException(org.hl7.fhir.exceptions.FHIRException) ParseException(java.text.ParseException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) NotImplementedException(org.apache.commons.lang3.NotImplementedException) XhtmlNode(org.hl7.fhir.utilities.xhtml.XhtmlNode)

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