Search in sources :

Example 21 with Section

use of org.hl7.fhir.utilities.turtle.Turtle.Section in project org.hl7.fhir.core by hapifhir.

the class ProfileUtilities method generateForChildren.

private void generateForChildren(SchematronWriter sch, String xpath, ElementDefinition ed, StructureDefinition structure, StructureDefinition base) throws IOException {
    // generateForChild(txt, structure, child);
    List<ElementDefinition> children = getChildList(structure, ed);
    String sliceName = null;
    ElementDefinitionSlicingComponent slicing = null;
    for (ElementDefinition child : children) {
        String name = tail(child.getPath());
        if (child.hasSlicing()) {
            sliceName = name;
            slicing = child.getSlicing();
        } else if (!name.equals(sliceName))
            slicing = null;
        ElementDefinition based = getByPath(base, child.getPath());
        boolean doMin = (child.getMin() > 0) && (based == null || (child.getMin() != based.getMin()));
        boolean doMax = child.hasMax() && !child.getMax().equals("*") && (based == null || (!child.getMax().equals(based.getMax())));
        Slicer slicer = slicing == null ? new Slicer(true) : generateSlicer(child, slicing, structure);
        if (slicer.check) {
            if (doMin || doMax) {
                Section s = sch.section(xpath);
                Rule r = s.rule(xpath);
                if (doMin)
                    r.assrt("count(f:" + name + slicer.criteria + ") >= " + Integer.toString(child.getMin()), name + slicer.name + ": minimum cardinality of '" + name + "' is " + Integer.toString(child.getMin()));
                if (doMax)
                    r.assrt("count(f:" + name + slicer.criteria + ") <= " + child.getMax(), name + slicer.name + ": maximum cardinality of '" + name + "' is " + child.getMax());
            }
        }
    }
    for (ElementDefinitionConstraintComponent inv : ed.getConstraint()) {
        if (inv.hasXpath()) {
            Section s = sch.section(ed.getPath());
            Rule r = s.rule(xpath);
            r.assrt(inv.getXpath(), (inv.hasId() ? inv.getId() + ": " : "") + inv.getHuman() + (inv.hasUserData(IS_DERIVED) ? " (inherited)" : ""));
        }
    }
    if (!ed.hasContentReference()) {
        for (ElementDefinition child : children) {
            String name = tail(child.getPath());
            generateForChildren(sch, xpath + "/f:" + name, child, structure, base);
        }
    }
}
Also used : ElementDefinitionSlicingComponent(org.hl7.fhir.r5.model.ElementDefinition.ElementDefinitionSlicingComponent) ElementDefinition(org.hl7.fhir.r5.model.ElementDefinition) Rule(org.hl7.fhir.utilities.xml.SchematronWriter.Rule) TypeDerivationRule(org.hl7.fhir.r5.model.StructureDefinition.TypeDerivationRule) Section(org.hl7.fhir.utilities.xml.SchematronWriter.Section) ElementDefinitionConstraintComponent(org.hl7.fhir.r5.model.ElementDefinition.ElementDefinitionConstraintComponent)

Example 22 with Section

use of org.hl7.fhir.utilities.turtle.Turtle.Section in project org.hl7.fhir.core by hapifhir.

the class RdfParserBase method compose.

@Override
public void compose(OutputStream stream, Resource resource) throws IOException {
    Turtle ttl = new Turtle();
    // ttl.setFormat(FFormat);
    ttl.prefix("fhir", "http://hl7.org/fhir/");
    ttl.prefix("rdfs", "http://www.w3.org/2000/01/rdf-schema#");
    Section section = ttl.section("resource");
    Subject subject;
    if (url != null)
        subject = section.triple("<" + url + ">", "a", "fhir:" + resource.getResourceType().toString());
    else
        subject = section.triple("[]", "a", "fhir:" + resource.getResourceType().toString());
    composeResource(subject, resource);
    try {
        ttl.commit(stream, false);
    } catch (Exception e) {
        throw new IOException(e);
    }
}
Also used : Turtle(org.hl7.fhir.r4.utils.formats.Turtle) IOException(java.io.IOException) Section(org.hl7.fhir.r4.utils.formats.Turtle.Section) Subject(org.hl7.fhir.r4.utils.formats.Turtle.Subject) IOException(java.io.IOException)

Example 23 with Section

use of org.hl7.fhir.utilities.turtle.Turtle.Section in project org.hl7.fhir.core by hapifhir.

the class BundleRenderer method addSection.

private void addSection(XhtmlNode x, BaseWrapper section, int level, boolean nested) throws UnsupportedEncodingException, FHIRException, IOException {
    if (section.has("title") || section.has("code") || section.has("text") || section.has("section")) {
        XhtmlNode div = x.div();
        if (section.has("title")) {
            div.h(level).tx(section.get("title").primitiveValue());
        } else if (section.has("code")) {
            renderBase(div.h(level), section.get("code"));
        }
        if (section.has("text")) {
            Base narrative = section.get("text");
            x.addChildren(narrative.getXhtml());
        }
        if (section.has("section")) {
            List<BaseWrapper> sections = section.children("section");
            for (BaseWrapper child : sections) {
                if (nested) {
                    addSection(x.blockquote(), child, level + 1, true);
                } else {
                    addSection(x, child, level + 1, true);
                }
            }
        }
    }
// children
}
Also used : BaseWrapper(org.hl7.fhir.r4b.renderers.utils.BaseWrappers.BaseWrapper) Base(org.hl7.fhir.r4b.model.Base) XhtmlNode(org.hl7.fhir.utilities.xhtml.XhtmlNode)

Example 24 with Section

use of org.hl7.fhir.utilities.turtle.Turtle.Section in project org.hl7.fhir.core by hapifhir.

the class BundleRenderer method renderDocument.

private boolean renderDocument(XhtmlNode x, ResourceWrapper b, List<BaseWrapper> entries) 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
    ResourceWrapper comp = (ResourceWrapper) entries.get(0).getChildByName("resource").getAsResource();
    ResourceWrapper subject = resolveReference(entries, comp.get("subject"));
    if (subject != null) {
        if (subject.hasNarrative()) {
            x.addChildren(subject.getNarrative());
        } else {
            RendererFactory.factory(subject, context).render(x, subject);
        }
    }
    x.hr();
    if (comp.hasNarrative()) {
        x.addChildren(comp.getNarrative());
        x.hr();
    }
    List<BaseWrapper> sections = comp.children("section");
    for (BaseWrapper section : sections) {
        addSection(x, section, 2, false);
    }
    return false;
}
Also used : ResourceWrapper(org.hl7.fhir.r5.renderers.utils.BaseWrappers.ResourceWrapper) BaseWrapper(org.hl7.fhir.r5.renderers.utils.BaseWrappers.BaseWrapper)

Example 25 with Section

use of org.hl7.fhir.utilities.turtle.Turtle.Section in project org.hl7.fhir.core by hapifhir.

the class ProfileUtilities method generateForChildren.

private void generateForChildren(SchematronWriter sch, String xpath, ElementDefinition ed, StructureDefinition structure, StructureDefinition base) throws IOException {
    // generateForChild(txt, structure, child);
    List<ElementDefinition> children = getChildList(structure, ed);
    String sliceName = null;
    ElementDefinitionSlicingComponent slicing = null;
    for (ElementDefinition child : children) {
        String name = tail(child.getPath());
        if (child.hasSlicing()) {
            sliceName = name;
            slicing = child.getSlicing();
        } else if (!name.equals(sliceName))
            slicing = null;
        ElementDefinition based = getByPath(base, child.getPath());
        boolean doMin = (child.getMin() > 0) && (based == null || (child.getMin() != based.getMin()));
        boolean doMax = child.hasMax() && !child.getMax().equals("*") && (based == null || (!child.getMax().equals(based.getMax())));
        Slicer slicer = slicing == null ? new Slicer(true) : generateSlicer(child, slicing, structure);
        if (slicer.check) {
            if (doMin || doMax) {
                Section s = sch.section(xpath);
                Rule r = s.rule(xpath);
                if (doMin)
                    r.assrt("count(f:" + name + slicer.criteria + ") >= " + Integer.toString(child.getMin()), name + slicer.name + ": minimum cardinality of '" + name + "' is " + Integer.toString(child.getMin()));
                if (doMax)
                    r.assrt("count(f:" + name + slicer.criteria + ") <= " + child.getMax(), name + slicer.name + ": maximum cardinality of '" + name + "' is " + child.getMax());
            }
        }
    }
    for (ElementDefinitionConstraintComponent inv : ed.getConstraint()) {
        if (inv.hasXpath()) {
            Section s = sch.section(ed.getPath());
            Rule r = s.rule(xpath);
            r.assrt(inv.getXpath(), (inv.hasId() ? inv.getId() + ": " : "") + inv.getHuman() + (inv.hasUserData(IS_DERIVED) ? " (inherited)" : ""));
        }
    }
    for (ElementDefinition child : children) {
        String name = tail(child.getPath());
        generateForChildren(sch, xpath + "/f:" + name, child, structure, base);
    }
}
Also used : ElementDefinitionSlicingComponent(org.hl7.fhir.r4.model.ElementDefinition.ElementDefinitionSlicingComponent) ElementDefinition(org.hl7.fhir.r4.model.ElementDefinition) TypeDerivationRule(org.hl7.fhir.r4.model.StructureDefinition.TypeDerivationRule) Rule(org.hl7.fhir.utilities.xml.SchematronWriter.Rule) Section(org.hl7.fhir.utilities.xml.SchematronWriter.Section) ElementDefinitionConstraintComponent(org.hl7.fhir.r4.model.ElementDefinition.ElementDefinitionConstraintComponent)

Aggregations

ArrayList (java.util.ArrayList)21 Element (org.w3c.dom.Element)11 IOException (java.io.IOException)10 LinkedHashMap (java.util.LinkedHashMap)9 Section (org.hl7.fhir.utilities.xml.SchematronWriter.Section)9 POCDMT000002UK01Section (uk.nhs.connect.iucds.cda.ucr.POCDMT000002UK01Section)8 Rule (org.hl7.fhir.utilities.xml.SchematronWriter.Rule)7 POCDMT000002UK01Component3 (uk.nhs.connect.iucds.cda.ucr.POCDMT000002UK01Component3)7 Reference (org.hl7.fhir.dstu3.model.Reference)6 XhtmlNode (org.hl7.fhir.utilities.xhtml.XhtmlNode)6 SectionComponent (org.hl7.fhir.dstu3.model.Composition.SectionComponent)5 CodeableConcept (org.hl7.fhir.r4.model.CodeableConcept)5 BeforeEach (org.junit.jupiter.api.BeforeEach)5 HashMap (java.util.HashMap)4 NotImplementedException (org.apache.commons.lang3.NotImplementedException)4 IdType (org.hl7.fhir.dstu3.model.IdType)4 Section (org.hl7.fhir.utilities.turtle.Turtle.Section)4 Subject (org.hl7.fhir.utilities.turtle.Turtle.Subject)4 POCDMT000002UK01Component5 (uk.nhs.connect.iucds.cda.ucr.POCDMT000002UK01Component5)4 FileNotFoundException (java.io.FileNotFoundException)3