Search in sources :

Example 26 with Section

use of org.hl7.fhir.utilities.turtle.Turtle.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 : NamedElement(org.hl7.fhir.r4b.elementmodel.ParserBase.NamedElement) SpecialElement(org.hl7.fhir.r4b.elementmodel.Element.SpecialElement) TTLComplex(org.hl7.fhir.utilities.turtle.Turtle.TTLComplex) Complex(org.hl7.fhir.utilities.turtle.Turtle.Complex)

Example 27 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.utilities.turtle.Turtle) IOException(java.io.IOException) Section(org.hl7.fhir.utilities.turtle.Turtle.Section) Subject(org.hl7.fhir.utilities.turtle.Turtle.Subject) IOException(java.io.IOException)

Example 28 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.utilities.turtle.Turtle) IOException(java.io.IOException) Section(org.hl7.fhir.utilities.turtle.Turtle.Section) Subject(org.hl7.fhir.utilities.turtle.Turtle.Subject) IOException(java.io.IOException)

Example 29 with Section

use of org.hl7.fhir.utilities.turtle.Turtle.Section in project pathling by aehrc.

the class ValueSetMapping method toIntersection.

/**
 * Constructs a {@link ValueSet} representing the intersection of a set of codings and a server
 *
 * @param valueSetUri the server defined value set.
 * @param codings the set of codings to intersect.
 * @return the intersection value set.
 */
@Nonnull
public static ValueSet toIntersection(@Nonnull final String valueSetUri, @Nonnull final Collection<SimpleCoding> codings) {
    final Set<CodeSystemReference> validCodeSystems = codings.stream().filter(SimpleCoding::isDefined).map(coding -> new CodeSystemReference(Optional.ofNullable(coding.getSystem()), Optional.ofNullable(coding.getVersion()))).collect(Collectors.toUnmodifiableSet());
    // Create a ValueSet to represent the intersection of the input codings and the ValueSet
    // described by the URI in the argument.
    final ValueSet intersection = new ValueSet();
    final ValueSetComposeComponent compose = new ValueSetComposeComponent();
    final List<ConceptSetComponent> includes = new ArrayList<>();
    // Create an include section for each unique code system present within the input codings.
    for (final CodeSystemReference codeSystem : validCodeSystems) {
        final ConceptSetComponent include = new ConceptSetComponent();
        include.setValueSet(Collections.singletonList(new CanonicalType(valueSetUri)));
        // noinspection OptionalGetWithoutIsPresent
        include.setSystem(codeSystem.getSystem().get());
        codeSystem.getVersion().ifPresent(include::setVersion);
        // Add the codings that match the current code system.
        final List<ConceptReferenceComponent> concepts = codings.stream().filter(codeSystem::matchesCoding).map(SimpleCoding::getCode).filter(Objects::nonNull).distinct().map(code -> {
            final ConceptReferenceComponent concept = new ConceptReferenceComponent();
            concept.setCode(code);
            return concept;
        }).collect(Collectors.toList());
        if (!concepts.isEmpty()) {
            include.setConcept(concepts);
            includes.add(include);
        }
    }
    compose.setInclude(includes);
    intersection.setCompose(compose);
    return intersection;
}
Also used : ConceptReferenceComponent(org.hl7.fhir.r4.model.ValueSet.ConceptReferenceComponent) java.util(java.util) Slf4j(lombok.extern.slf4j.Slf4j) ConceptSetComponent(org.hl7.fhir.r4.model.ValueSet.ConceptSetComponent) SimpleCoding(au.csiro.pathling.fhirpath.encoding.SimpleCoding) CanonicalType(org.hl7.fhir.r4.model.CanonicalType) ValueSet(org.hl7.fhir.r4.model.ValueSet) Collectors(java.util.stream.Collectors) Nonnull(javax.annotation.Nonnull) Nullable(javax.annotation.Nullable) Value(lombok.Value) ValueSetComposeComponent(org.hl7.fhir.r4.model.ValueSet.ValueSetComposeComponent) ValueSetComposeComponent(org.hl7.fhir.r4.model.ValueSet.ValueSetComposeComponent) CanonicalType(org.hl7.fhir.r4.model.CanonicalType) ConceptReferenceComponent(org.hl7.fhir.r4.model.ValueSet.ConceptReferenceComponent) ConceptSetComponent(org.hl7.fhir.r4.model.ValueSet.ConceptSetComponent) SimpleCoding(au.csiro.pathling.fhirpath.encoding.SimpleCoding) ValueSet(org.hl7.fhir.r4.model.ValueSet) Nonnull(javax.annotation.Nonnull)

Example 30 with Section

use of org.hl7.fhir.utilities.turtle.Turtle.Section in project eCRNow by drajer-health.

the class CdaHistoryOfPresentIllnessGenerator method generateHistoryOfPresentIllnessSection.

public static String generateHistoryOfPresentIllnessSection(R4FhirData data) {
    StringBuilder sb = new StringBuilder(2000);
    // Will have to wait to discuss with vendors on History of Present Illness and how to obtain
    // that information reliably..
    // Then we can generate better text.
    sb.append(CdaGeneratorUtils.getXmlForStartElement(CdaGeneratorConstants.COMP_EL_NAME));
    sb.append(CdaGeneratorUtils.getXmlForStartElement(CdaGeneratorConstants.SECTION_EL_NAME));
    sb.append(CdaGeneratorUtils.getXmlForTemplateId(CdaGeneratorConstants.HISTORY_OF_PRESENT_ILLNESS_SEC_TEMPLATE_ID));
    sb.append(CdaGeneratorUtils.getXmlForCD(CdaGeneratorConstants.CODE_EL_NAME, CdaGeneratorConstants.HISTORY_OF_PRESENT_ILLNESS_SEC_CODE, CdaGeneratorConstants.LOINC_CODESYSTEM_OID, CdaGeneratorConstants.LOINC_CODESYSTEM_NAME, CdaGeneratorConstants.HISTORY_OF_PRESENT_ILLNESS_SEC_CODE_NAME));
    // Add Title
    sb.append(CdaGeneratorUtils.getXmlForText(CdaGeneratorConstants.TITLE_EL_NAME, CdaGeneratorConstants.HISTORY_OF_PRESENT_ILLNESS_SEC_TITLE));
    // Add Narrative Text
    sb.append(CdaGeneratorUtils.getXmlForStartElement(CdaGeneratorConstants.TEXT_EL_NAME));
    List<Condition> conds = data.getEncounterDiagnosisConditions();
    // Create Table Header.
    List<String> list = new ArrayList<>();
    list.add(CdaGeneratorConstants.NARRATIVE_TEXT_EL_NAME);
    sb.append(CdaGeneratorUtils.getXmlForTableHeader(list, CdaGeneratorConstants.TABLE_BORDER, CdaGeneratorConstants.TABLE_WIDTH));
    // Add Table Body
    sb.append(CdaGeneratorUtils.getXmlForStartElement(CdaGeneratorConstants.TABLE_BODY_EL_NAME));
    String text = CdaGeneratorConstants.UNKNOWN_HISTORY_OF_PRESENT_ILLNESS;
    int rowNum = 1;
    if (conds != null && !conds.isEmpty()) {
        // Add Body Rows
        for (Condition prob : conds) {
            String probDisplayName = CdaGeneratorConstants.UNKNOWN_VALUE;
            if (prob.getCode() != null && !StringUtils.isEmpty(prob.getCode().getText())) {
                probDisplayName = prob.getCode().getText();
            } else if (prob.getCode().getCodingFirstRep() != null && !StringUtils.isEmpty(prob.getCode().getCodingFirstRep().getDisplay())) {
                probDisplayName = prob.getCode().getCodingFirstRep().getDisplay();
            }
            Map<String, String> bodyvals = new LinkedHashMap<>();
            bodyvals.put(CdaGeneratorConstants.HISTORY_OF_PRESENT_ILLNESS_BODY_CONTENT, probDisplayName);
            sb.append(CdaGeneratorUtils.addTableRow(bodyvals, rowNum));
            ++rowNum;
        }
    } else {
        Map<String, String> bodyvals = new HashMap<>();
        bodyvals.put(CdaGeneratorConstants.HISTORY_OF_PRESENT_ILLNESS_BODY_CONTENT, text);
        sb.append(CdaGeneratorUtils.addTableRow(bodyvals, rowNum));
    }
    sb.append(CdaGeneratorUtils.getXmlForEndElement(CdaGeneratorConstants.TABLE_BODY_EL_NAME));
    // End Table.
    sb.append(CdaGeneratorUtils.getXmlForEndElement(CdaGeneratorConstants.TABLE_EL_NAME));
    sb.append(CdaGeneratorUtils.getXmlForEndElement(CdaGeneratorConstants.TEXT_EL_NAME));
    // Complete the section end tags.
    sb.append(CdaGeneratorUtils.getXmlForEndElement(CdaGeneratorConstants.SECTION_EL_NAME));
    sb.append(CdaGeneratorUtils.getXmlForEndElement(CdaGeneratorConstants.COMP_EL_NAME));
    return sb.toString();
}
Also used : Condition(org.hl7.fhir.r4.model.Condition) LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap)

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