Search in sources :

Example 56 with EOperationOutcome

use of org.hl7.fhir.r5.utils.EOperationOutcome 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 57 with EOperationOutcome

use of org.hl7.fhir.r5.utils.EOperationOutcome in project org.hl7.fhir.core by hapifhir.

the class BundleRenderer method render.

@Override
public boolean render(XhtmlNode x, Resource r) throws FHIRFormatError, DefinitionException, IOException, FHIRException, EOperationOutcome {
    XhtmlNode n = render((Bundle) r);
    x.addChildren(n.getChildNodes());
    return false;
}
Also used : XhtmlNode(org.hl7.fhir.utilities.xhtml.XhtmlNode)

Example 58 with EOperationOutcome

use of org.hl7.fhir.r5.utils.EOperationOutcome 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 59 with EOperationOutcome

use of org.hl7.fhir.r5.utils.EOperationOutcome in project org.hl7.fhir.core by hapifhir.

the class ProfileUtilitiesTests method testSimple2.

// 
// /**
// * This is simple: we just create an empty differential, generate the snapshot, and then insist it must match the base. for a different resource with recursion
// *
// * @param context2
// * @
// * @throws EOperationOutcome
// */
@Test
public void testSimple2() {
    StructureDefinition base = TestingUtilities.context().fetchResource(StructureDefinition.class, "http://hl7.org/fhir/StructureDefinition/ValueSet").copy();
    StructureDefinition focus = base.copy();
    focus.setUrl(Utilities.makeUuidUrn());
    focus.setSnapshot(null);
    focus.setDifferential(null);
    List<ValidationMessage> messages = new ArrayList<>();
    new ProfileUtilities(TestingUtilities.context(), messages, null).generateSnapshot(base, focus, focus.getUrl(), "http://test.org", "Simple Test");
    boolean ok = base.getSnapshot().getElement().size() == focus.getSnapshot().getElement().size();
    for (int i = 0; i < base.getSnapshot().getElement().size(); i++) {
        if (ok) {
            ElementDefinition b = base.getSnapshot().getElement().get(i);
            ElementDefinition f = focus.getSnapshot().getElement().get(i);
            for (ElementDefinitionConstraintComponent c : b.getConstraint()) {
                c.setSource(null);
            }
            for (ElementDefinitionConstraintComponent c : f.getConstraint()) {
                c.setSource(null);
            }
            if (!f.hasBase() || !b.getPath().equals(f.getPath()))
                ok = false;
            else {
                f.setBase(null);
                b.setBase(null);
                b.setRequirements(null);
                f.setRequirements(null);
                b.setComment(null);
                f.setComment(null);
                b.setDefinition(null);
                f.setDefinition(null);
                b.setContentReference(null);
                f.setContentReference(null);
                ok = Base.compareDeep(b, f, true);
            }
        }
    }
    Assertions.assertTrue(ok);
}
Also used : StructureDefinition(org.hl7.fhir.r4b.model.StructureDefinition) ValidationMessage(org.hl7.fhir.utilities.validation.ValidationMessage) ProfileUtilities(org.hl7.fhir.r4b.conformance.ProfileUtilities) ArrayList(java.util.ArrayList) ElementDefinition(org.hl7.fhir.r4b.model.ElementDefinition) ElementDefinitionConstraintComponent(org.hl7.fhir.r4b.model.ElementDefinition.ElementDefinitionConstraintComponent) Test(org.junit.jupiter.api.Test)

Example 60 with EOperationOutcome

use of org.hl7.fhir.r5.utils.EOperationOutcome in project org.hl7.fhir.core by hapifhir.

the class ProfileUtilitiesTests method testSimple.

// /**
// * This is simple: we just create an empty differential, generate the snapshot, and then insist it must match the base
// *
// * @param context2
// * @
// * @throws EOperationOutcome
// */
@Test
public void testSimple() throws FHIRException {
    StructureDefinition focus = new StructureDefinition();
    StructureDefinition base = TestingUtilities.context().fetchResource(StructureDefinition.class, "http://hl7.org/fhir/StructureDefinition/Patient").copy();
    focus.setUrl(Utilities.makeUuidUrn());
    focus.setBaseDefinition(base.getUrl());
    focus.setType("Patient");
    focus.setDerivation(TypeDerivationRule.CONSTRAINT);
    List<ValidationMessage> messages = new ArrayList<>();
    new ProfileUtilities(TestingUtilities.context(), messages, null).generateSnapshot(base, focus, focus.getUrl(), "http://test.org/test", "Simple Test");
    boolean ok = base.getSnapshot().getElement().size() == focus.getSnapshot().getElement().size();
    for (int i = 0; i < base.getSnapshot().getElement().size(); i++) {
        ElementDefinition b = base.getSnapshot().getElement().get(i);
        ElementDefinition f = focus.getSnapshot().getElement().get(i);
        if (ok) {
            if (!f.hasBase())
                ok = false;
            else if (!b.getPath().equals(f.getPath()))
                ok = false;
            else {
                b.setBase(null);
                f.setBase(null);
                b.setRequirements(null);
                f.setRequirements(null);
                for (ElementDefinitionConstraintComponent c : b.getConstraint()) {
                    c.setSource(null);
                }
                for (ElementDefinitionConstraintComponent c : f.getConstraint()) {
                    c.setSource(null);
                }
                ok = Base.compareDeep(b, f, true);
            }
        }
    }
    Assertions.assertTrue(ok);
}
Also used : StructureDefinition(org.hl7.fhir.r4b.model.StructureDefinition) ValidationMessage(org.hl7.fhir.utilities.validation.ValidationMessage) ProfileUtilities(org.hl7.fhir.r4b.conformance.ProfileUtilities) ArrayList(java.util.ArrayList) ElementDefinition(org.hl7.fhir.r4b.model.ElementDefinition) ElementDefinitionConstraintComponent(org.hl7.fhir.r4b.model.ElementDefinition.ElementDefinitionConstraintComponent) Test(org.junit.jupiter.api.Test)

Aggregations

XhtmlNode (org.hl7.fhir.utilities.xhtml.XhtmlNode)52 FHIRException (org.hl7.fhir.exceptions.FHIRException)38 ValidationMessage (org.hl7.fhir.utilities.validation.ValidationMessage)37 ArrayList (java.util.ArrayList)35 ProfileUtilities (org.hl7.fhir.dstu3.conformance.ProfileUtilities)14 ElementDefinition (org.hl7.fhir.dstu2.model.ElementDefinition)13 StructureDefinition (org.hl7.fhir.dstu2.model.StructureDefinition)13 ProfileUtilities (org.hl7.fhir.dstu2.utils.ProfileUtilities)13 ElementDefinition (org.hl7.fhir.dstu3.model.ElementDefinition)13 StructureDefinition (org.hl7.fhir.dstu3.model.StructureDefinition)13 FileOutputStream (java.io.FileOutputStream)10 Test (org.junit.jupiter.api.Test)10 IOException (java.io.IOException)9 StructureDefinition (org.hl7.fhir.r5.model.StructureDefinition)9 DomainResource (org.hl7.fhir.r5.model.DomainResource)7 DomainResource (org.hl7.fhir.r4b.model.DomainResource)6 StructureDefinition (org.hl7.fhir.r4b.model.StructureDefinition)6 BaseWrapper (org.hl7.fhir.r4b.renderers.utils.BaseWrappers.BaseWrapper)6 BaseWrapper (org.hl7.fhir.r5.renderers.utils.BaseWrappers.BaseWrapper)6 ElementDefinition (org.hl7.fhir.r4b.model.ElementDefinition)5