Search in sources :

Example 26 with ConceptReferenceComponent

use of org.hl7.fhir.dstu2.model.ValueSet.ConceptReferenceComponent in project org.hl7.fhir.core by hapifhir.

the class ValueSetRenderer method scanDesignations.

private void scanDesignations(ConceptSetComponent inc, List<String> langs, Map<String, String> designations) {
    for (ConceptReferenceComponent cc : inc.getConcept()) {
        for (Extension ext : cc.getExtension()) {
            if (ToolingExtensions.EXT_TRANSLATION.equals(ext.getUrl())) {
                String lang = ToolingExtensions.readStringExtension(ext, "lang");
                if (!Utilities.noString(lang) && !langs.contains(lang)) {
                    langs.add(lang);
                }
            }
        }
        for (ConceptReferenceDesignationComponent d : cc.getDesignation()) {
            String lang = d.getLanguage();
            if (!Utilities.noString(lang) && !langs.contains(lang)) {
                langs.add(lang);
            } else {
                // can we present this as a designation that we know?
                String disp = getDisplayForDesignation(d);
                String url = getUrlForDesignation(d);
                if (disp == null) {
                    disp = getDisplayForUrl(url);
                }
                if (disp != null && !designations.containsKey(url)) {
                    designations.put(url, disp);
                }
            }
        }
    }
}
Also used : Extension(org.hl7.fhir.r5.model.Extension) ConceptReferenceDesignationComponent(org.hl7.fhir.r5.model.ValueSet.ConceptReferenceDesignationComponent) ConceptReferenceComponent(org.hl7.fhir.r5.model.ValueSet.ConceptReferenceComponent)

Example 27 with ConceptReferenceComponent

use of org.hl7.fhir.dstu2.model.ValueSet.ConceptReferenceComponent in project org.hl7.fhir.core by hapifhir.

the class ValueSetRenderer method genInclude.

private boolean genInclude(XhtmlNode ul, ConceptSetComponent inc, String type, List<String> langs, boolean doDesignations, List<UsedConceptMap> maps, Map<String, String> designations, int index) throws FHIRException, IOException {
    boolean hasExtensions = false;
    XhtmlNode li;
    li = ul.li();
    CodeSystem e = getContext().getWorker().fetchCodeSystem(inc.getSystem());
    Map<String, ConceptDefinitionComponent> definitions = new HashMap<>();
    if (inc.hasSystem()) {
        if (inc.getConcept().size() == 0 && inc.getFilter().size() == 0) {
            li.addText(type + " all codes defined in ");
            addCsRef(inc, li, e);
        } else {
            if (inc.getConcept().size() > 0) {
                li.addText(type + " these codes as defined in ");
                addCsRef(inc, li, e);
                if (inc.hasVersion()) {
                    li.addText(" version ");
                    li.code(inc.getVersion());
                }
                // for performance reasons, we do all the fetching in one batch
                definitions = getConceptsForCodes(e, inc);
                XhtmlNode t = li.table("none");
                boolean hasComments = false;
                boolean hasDefinition = false;
                for (ConceptReferenceComponent c : inc.getConcept()) {
                    hasComments = hasComments || ExtensionHelper.hasExtension(c, ToolingExtensions.EXT_VS_COMMENT);
                    ConceptDefinitionComponent cc = definitions.get(c.getCode());
                    hasDefinition = hasDefinition || ((cc != null && cc.hasDefinition()) || ExtensionHelper.hasExtension(c, ToolingExtensions.EXT_DEFINITION));
                }
                if (hasComments || hasDefinition)
                    hasExtensions = true;
                addMapHeaders(addTableHeaderRowStandard(t, false, true, hasDefinition, hasComments, false, false, null, langs, designations, doDesignations), maps);
                for (ConceptReferenceComponent c : inc.getConcept()) {
                    XhtmlNode tr = t.tr();
                    XhtmlNode td = tr.td();
                    ConceptDefinitionComponent cc = definitions.get(c.getCode());
                    addCodeToTable(false, inc.getSystem(), c.getCode(), c.hasDisplay() ? c.getDisplay() : cc != null ? cc.getDisplay() : "", td);
                    td = tr.td();
                    if (!Utilities.noString(c.getDisplay()))
                        td.addText(c.getDisplay());
                    else if (cc != null && !Utilities.noString(cc.getDisplay()))
                        td.addText(cc.getDisplay());
                    if (hasDefinition) {
                        td = tr.td();
                        if (ExtensionHelper.hasExtension(c, ToolingExtensions.EXT_DEFINITION)) {
                            smartAddText(td, ToolingExtensions.readStringExtension(c, ToolingExtensions.EXT_DEFINITION));
                        } else if (cc != null && !Utilities.noString(cc.getDefinition())) {
                            smartAddText(td, cc.getDefinition());
                        }
                    }
                    if (hasComments) {
                        td = tr.td();
                        if (ExtensionHelper.hasExtension(c, ToolingExtensions.EXT_VS_COMMENT)) {
                            smartAddText(td, "Note: " + ToolingExtensions.readStringExtension(c, ToolingExtensions.EXT_VS_COMMENT));
                        }
                    }
                    if (doDesignations) {
                        addDesignationsToRow(c, designations, tr);
                        addLangaugesToRow(c, langs, tr);
                    }
                }
            }
            if (inc.getFilter().size() > 0) {
                li.addText(type + " codes from ");
                addCsRef(inc, li, e);
                li.tx(" where ");
                for (int i = 0; i < inc.getFilter().size(); i++) {
                    ConceptSetFilterComponent f = inc.getFilter().get(i);
                    if (i > 0) {
                        if (i == inc.getFilter().size() - 1) {
                            li.tx(" and ");
                        } else {
                            li.tx(", ");
                        }
                    }
                    if (f.getOp() == FilterOperator.EXISTS) {
                        if (f.getValue().equals("true")) {
                            li.tx(f.getProperty() + " exists");
                        } else {
                            li.tx(f.getProperty() + " doesn't exist");
                        }
                    } else {
                        li.tx(f.getProperty() + " " + describe(f.getOp()) + " ");
                        if (e != null && codeExistsInValueSet(e, f.getValue())) {
                            String href = getContext().fixReference(getCsRef(e));
                            if (href.contains("#"))
                                href = href + "-" + Utilities.nmtokenize(f.getValue());
                            else
                                href = href + "#" + e.getId() + "-" + Utilities.nmtokenize(f.getValue());
                            li.ah(href).addText(f.getValue());
                        } else if ("concept".equals(f.getProperty()) && inc.hasSystem()) {
                            li.addText(f.getValue());
                            ValidationResult vr = getContext().getWorker().validateCode(getContext().getTerminologyServiceOptions(), inc.getSystem(), inc.getVersion(), f.getValue(), null);
                            if (vr.isOk()) {
                                li.tx(" (" + vr.getDisplay() + ")");
                            }
                        } else
                            li.addText(f.getValue());
                        String disp = ToolingExtensions.getDisplayHint(f);
                        if (disp != null)
                            li.tx(" (" + disp + ")");
                    }
                }
            }
        }
        if (inc.hasValueSet()) {
            li.tx(", where the codes are contained in ");
            boolean first = true;
            for (UriType vs : inc.getValueSet()) {
                if (first)
                    first = false;
                else
                    li.tx(", ");
                AddVsRef(vs.asStringValue(), li);
            }
        }
        if (inc.hasExtension(ToolingExtensions.EXT_EXPAND_RULES) || inc.hasExtension(ToolingExtensions.EXT_EXPAND_GROUP)) {
            hasExtensions = true;
            renderExpansionRules(li, inc, index, definitions);
        }
    } else {
        li.tx("Import all the codes that are contained in ");
        if (inc.getValueSet().size() < 4) {
            boolean first = true;
            for (UriType vs : inc.getValueSet()) {
                if (first)
                    first = false;
                else
                    li.tx(", ");
                AddVsRef(vs.asStringValue(), li);
            }
        } else {
            XhtmlNode xul = li.ul();
            for (UriType vs : inc.getValueSet()) {
                AddVsRef(vs.asStringValue(), xul.li());
            }
        }
    }
    return hasExtensions;
}
Also used : ConceptSetFilterComponent(org.hl7.fhir.r5.model.ValueSet.ConceptSetFilterComponent) ConceptDefinitionComponent(org.hl7.fhir.r5.model.CodeSystem.ConceptDefinitionComponent) HashMap(java.util.HashMap) ValidationResult(org.hl7.fhir.r5.context.IWorkerContext.ValidationResult) CodeSystem(org.hl7.fhir.r5.model.CodeSystem) ConceptReferenceComponent(org.hl7.fhir.r5.model.ValueSet.ConceptReferenceComponent) XhtmlNode(org.hl7.fhir.utilities.xhtml.XhtmlNode) UriType(org.hl7.fhir.r5.model.UriType)

Example 28 with ConceptReferenceComponent

use of org.hl7.fhir.dstu2.model.ValueSet.ConceptReferenceComponent in project org.hl7.fhir.core by hapifhir.

the class ValueSetRenderer method addDesignationsToRow.

public void addDesignationsToRow(ConceptReferenceComponent c, Map<String, String> designations, XhtmlNode tr) {
    for (String url : designations.keySet()) {
        String d = null;
        if (d == null) {
            for (ConceptReferenceDesignationComponent dd : c.getDesignation()) {
                if (url.equals(getUrlForDesignation(dd))) {
                    d = dd.getValue();
                }
            }
        }
        tr.td().addText(d == null ? "" : d);
    }
}
Also used : ConceptReferenceDesignationComponent(org.hl7.fhir.r5.model.ValueSet.ConceptReferenceDesignationComponent)

Example 29 with ConceptReferenceComponent

use of org.hl7.fhir.dstu2.model.ValueSet.ConceptReferenceComponent 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 ConceptReferenceComponent

use of org.hl7.fhir.dstu2.model.ValueSet.ConceptReferenceComponent in project pathling by aehrc.

the class DefaultTerminologyServiceTest method testIntersectFiltersIllegalAndUnknownCodings.

@SuppressWarnings("ConstantConditions")
@Test
void testIntersectFiltersIllegalAndUnknownCodings() {
    final ValueSet responseExpansion = new ValueSet();
    responseExpansion.getExpansion().getContains().addAll(Arrays.asList(fromSimpleCoding(CODING1_VERSION1), fromSimpleCoding(CODING2_VERSION1)));
    when(terminologyClient.expand(any(), any())).thenReturn(responseExpansion);
    // setup SYSTEM1 as known system
    when(terminologyClient.searchCodeSystems(refEq(new UriParam(SYSTEM1)), any())).thenReturn(Collections.singletonList(new CodeSystem()));
    final Set<SimpleCoding> actualExpansion = terminologyService.intersect("uuid:value-set", Arrays.asList(CODING1_VERSION1, CODING2_VERSION1, CODING3_VERSION1, new SimpleCoding(SYSTEM1, null), new SimpleCoding(null, "code1"), new SimpleCoding(null, null), null));
    final Set<SimpleCoding> expectedExpansion = ImmutableSet.of(CODING1_VERSION1, CODING2_VERSION1);
    assertEquals(expectedExpansion, actualExpansion);
    // verify behaviour
    verify(terminologyClient).searchCodeSystems(refEq(new UriParam(SYSTEM1)), any());
    verify(terminologyClient).searchCodeSystems(refEq(new UriParam(SYSTEM2)), any());
    final ValueSet requestValueSet = new ValueSet();
    final List<ConceptSetComponent> includes = requestValueSet.getCompose().getInclude();
    includes.add(new ConceptSetComponent().addValueSet("uuid:value-set").setSystem(SYSTEM1).setVersion("version1").addConcept(new ConceptReferenceComponent().setCode("code1")).addConcept(new ConceptReferenceComponent().setCode("code2")));
    verify(terminologyClient).expand(deepEq(requestValueSet), deepEq(new IntegerType(2)));
    verifyNoMoreInteractions(terminologyClient);
}
Also used : IntegerType(org.hl7.fhir.r4.model.IntegerType) ConceptSetComponent(org.hl7.fhir.r4.model.ValueSet.ConceptSetComponent) SimpleCoding(au.csiro.pathling.fhirpath.encoding.SimpleCoding) ValueSet(org.hl7.fhir.r4.model.ValueSet) UriParam(ca.uhn.fhir.rest.param.UriParam) CodeSystem(org.hl7.fhir.r4.model.CodeSystem) ConceptReferenceComponent(org.hl7.fhir.r4.model.ValueSet.ConceptReferenceComponent) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

ConceptReferenceComponent (org.hl7.fhir.r5.model.ValueSet.ConceptReferenceComponent)17 ArrayList (java.util.ArrayList)14 XhtmlNode (org.hl7.fhir.utilities.xhtml.XhtmlNode)14 ConceptReferenceComponent (org.hl7.fhir.r4b.model.ValueSet.ConceptReferenceComponent)12 ConceptReferenceComponent (org.hl7.fhir.r4.model.ValueSet.ConceptReferenceComponent)10 HashMap (java.util.HashMap)7 ConceptReferenceComponent (org.hl7.fhir.dstu3.model.ValueSet.ConceptReferenceComponent)7 TerminologyServiceException (org.hl7.fhir.exceptions.TerminologyServiceException)7 ConceptSetComponent (org.hl7.fhir.r5.model.ValueSet.ConceptSetComponent)7 ValueSet (org.hl7.fhir.r4.model.ValueSet)6 ConceptSetComponent (org.hl7.fhir.r4.model.ValueSet.ConceptSetComponent)6 ConceptDefinitionComponent (org.hl7.fhir.r5.model.CodeSystem.ConceptDefinitionComponent)6 NotImplementedException (org.apache.commons.lang3.NotImplementedException)5 NoTerminologyServiceException (org.hl7.fhir.exceptions.NoTerminologyServiceException)5 ConceptReferenceDesignationComponent (org.hl7.fhir.r5.model.ValueSet.ConceptReferenceDesignationComponent)5 ConceptSetComponent (org.hl7.fhir.dstu3.model.ValueSet.ConceptSetComponent)4 ConceptDefinitionComponent (org.hl7.fhir.r4b.model.CodeSystem.ConceptDefinitionComponent)4 ConceptReferenceDesignationComponent (org.hl7.fhir.r4b.model.ValueSet.ConceptReferenceDesignationComponent)4 ValueSet (org.hl7.fhir.r5.model.ValueSet)4 ConceptSetFilterComponent (org.hl7.fhir.r5.model.ValueSet.ConceptSetFilterComponent)4