Search in sources :

Example 51 with Section

use of org.hl7.fhir.utilities.xml.SchematronWriter.Section in project kindling by HL7.

the class Publisher method insertSectionNumbers.

private String insertSectionNumbers(String src, SectionTracker st, String link, int level, DocumentHolder doch) throws Exception {
    try {
        // TextFile.stringToFile(src, "c:\\temp\\text.html");
        XhtmlDocument doc = new XhtmlParser().parse(src, "html");
        insertSectionNumbersInNode(doc, st, link, level, new BooleanHolder(), null);
        if (doch != null)
            doch.doc = doc;
        return new XhtmlComposer(XhtmlComposer.HTML).compose(doc);
    } catch (Exception e) {
        System.out.println(e.getMessage());
        // TextFile.stringToFile(src, "c:\\temp\\dump.html");
        TextFile.stringToFile(src, Utilities.appendSlash(System.getProperty("user.dir")) + "fhir-error-dump.html");
        throw new Exception("Exception inserting section numbers in " + link + ": " + e.getMessage(), e);
    }
}
Also used : XhtmlParser(org.hl7.fhir.utilities.xhtml.XhtmlParser) XhtmlComposer(org.hl7.fhir.utilities.xhtml.XhtmlComposer) TransformerException(javax.xml.transform.TransformerException) IOException(java.io.IOException) FHIRException(org.hl7.fhir.exceptions.FHIRException) FileNotFoundException(java.io.FileNotFoundException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) XhtmlDocument(org.hl7.fhir.utilities.xhtml.XhtmlDocument)

Example 52 with Section

use of org.hl7.fhir.utilities.xml.SchematronWriter.Section in project org.hl7.fhir.core by hapifhir.

the class RdfParser method composeCompositionSectionComponent.

protected void composeCompositionSectionComponent(Complex parent, String parentType, String name, Composition.SectionComponent element, int index) {
    if (element == null)
        return;
    Complex t;
    if (Utilities.noString(parentType))
        t = parent;
    else {
        t = parent.predicate("fhir:" + parentType + '.' + name);
    }
    composeBackboneElement(t, "section", name, element, index);
    if (element.hasTitleElement())
        composeString(t, "Composition", "title", element.getTitleElement(), -1);
    if (element.hasCode())
        composeCodeableConcept(t, "Composition", "code", element.getCode(), -1);
    if (element.hasText())
        composeNarrative(t, "Composition", "text", element.getText(), -1);
    if (element.hasModeElement())
        composeCode(t, "Composition", "mode", element.getModeElement(), -1);
    if (element.hasOrderedBy())
        composeCodeableConcept(t, "Composition", "orderedBy", element.getOrderedBy(), -1);
    for (int i = 0; i < element.getEntry().size(); i++) composeReference(t, "Composition", "entry", element.getEntry().get(i), i);
    if (element.hasEmptyReason())
        composeCodeableConcept(t, "Composition", "emptyReason", element.getEmptyReason(), -1);
    for (int i = 0; i < element.getSection().size(); i++) composeCompositionSectionComponent(t, "Composition", "section", element.getSection().get(i), i);
}
Also used : Complex(org.hl7.fhir.dstu2016may.formats.RdfGenerator.Complex)

Example 53 with Section

use of org.hl7.fhir.utilities.xml.SchematronWriter.Section in project org.hl7.fhir.core by hapifhir.

the class TurtleParser method composeElement.

private void composeElement(Section section, Complex ctxt, Element element, Element parent) throws FHIRException {
    // "Extension".equals(element.getType())?
    // (element.getProperty().getDefinition().getIsModifier()? "modifierExtension" : "extension") ;
    String en = getFormalName(element);
    Complex t;
    if (element.getSpecial() == SpecialElement.BUNDLE_ENTRY && parent != null && parent.getNamedChildValue("fullUrl") != null) {
        String url = "<" + parent.getNamedChildValue("fullUrl") + ">";
        ctxt.linkedPredicate("fhir:" + en, url, linkResolver == null ? null : linkResolver.resolveProperty(element.getProperty()));
        t = section.subject(url);
    } else {
        t = ctxt.linkedPredicate("fhir:" + en, linkResolver == null ? null : linkResolver.resolveProperty(element.getProperty()));
    }
    if (element.getSpecial() != null)
        t.linkedPredicate("a", "fhir:" + element.fhirType(), linkResolver == null ? null : linkResolver.resolveType(element.fhirType()));
    if (element.hasValue())
        t.linkedPredicate("fhir:value", ttlLiteral(element.getValue(), element.getType()), linkResolver == null ? null : linkResolver.resolveType(element.getType()));
    if (element.getProperty().isList() && (!element.isResource() || element.getSpecial() == SpecialElement.CONTAINED))
        t.linkedPredicate("fhir:index", Integer.toString(element.getIndex()), linkResolver == null ? null : linkResolver.resolvePage("rdf.html#index"));
    if ("Coding".equals(element.getType()))
        decorateCoding(t, element, section);
    if (Utilities.existsInList(element.getType(), "Reference"))
        decorateReference(t, element);
    else if (Utilities.existsInList(element.getType(), "canonical"))
        decorateCanonical(t, element);
    if ("canonical".equals(element.getType())) {
        String refURI = element.primitiveValue();
        if (refURI != null) {
            String uriType = getURIType(refURI);
            if (uriType != null && !section.hasSubject(refURI))
                section.triple(refURI, "a", "fhir:" + uriType);
        }
    }
    if ("Reference".equals(element.getType())) {
        String refURI = getReferenceURI(element.getChildValue("reference"));
        if (refURI != null) {
            String uriType = getURIType(refURI);
            if (uriType != null && !section.hasSubject(refURI))
                section.triple(refURI, "a", "fhir:" + uriType);
        }
    }
    for (Element child : element.getChildren()) {
        if ("xhtml".equals(child.getType())) {
            String childfn = getFormalName(child);
            t.predicate("fhir:" + childfn, ttlLiteral(child.getValue(), child.getType()));
        } else
            composeElement(section, t, child, element);
    }
}
Also used : SpecialElement(org.hl7.fhir.r4.elementmodel.Element.SpecialElement) Complex(org.hl7.fhir.r4.utils.formats.Turtle.Complex) TTLComplex(org.hl7.fhir.r4.utils.formats.Turtle.TTLComplex)

Example 54 with Section

use of org.hl7.fhir.utilities.xml.SchematronWriter.Section in project org.hl7.fhir.core by hapifhir.

the class TurtleParser method compose.

public void compose(Element e, Turtle ttl, String base) throws FHIRException {
    ttl.prefix("fhir", FHIR_URI_BASE);
    ttl.prefix("rdfs", "http://www.w3.org/2000/01/rdf-schema#");
    ttl.prefix("owl", "http://www.w3.org/2002/07/owl#");
    ttl.prefix("xsd", "http://www.w3.org/2001/XMLSchema#");
    Section section = ttl.section("resource");
    String subjId = genSubjectId(e);
    String ontologyId = subjId.replace(">", ".ttl>");
    Section ontology = ttl.section("ontology header");
    ontology.triple(ontologyId, "a", "owl:Ontology");
    ontology.triple(ontologyId, "owl:imports", "fhir:fhir.ttl");
    if (ontologyId.startsWith("<" + FHIR_URI_BASE))
        ontology.triple(ontologyId, "owl:versionIRI", ontologyId.replace(FHIR_URI_BASE, FHIR_VERSION_BASE));
    Subject subject = section.triple(subjId, "a", "fhir:" + e.getType());
    subject.linkedPredicate("fhir:nodeRole", "fhir:treeRoot", linkResolver == null ? null : linkResolver.resolvePage("rdf.html#tree-root"));
    for (Element child : e.getChildren()) {
        composeElement(section, subject, child, null);
    }
}
Also used : SpecialElement(org.hl7.fhir.r4.elementmodel.Element.SpecialElement) Section(org.hl7.fhir.r4.utils.formats.Turtle.Section) Subject(org.hl7.fhir.r4.utils.formats.Turtle.Subject)

Example 55 with Section

use of org.hl7.fhir.utilities.xml.SchematronWriter.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.r4b.renderers.utils.BaseWrappers.ResourceWrapper) BaseWrapper(org.hl7.fhir.r4b.renderers.utils.BaseWrappers.BaseWrapper)

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