Search in sources :

Example 16 with ConceptReferenceComponent

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

the class NarrativeGenerator method addLanguageRow.

private void addLanguageRow(ConceptReferenceComponent c, XhtmlNode t, List<String> langs) {
    XhtmlNode tr = t.tr();
    tr.td().addText(c.getCode());
    for (String lang : langs) {
        String d = null;
        for (ConceptReferenceDesignationComponent cd : c.getDesignation()) {
            String l = cd.getLanguage();
            if (lang.equals(l))
                d = cd.getValue();
        }
        tr.td().addText(d == null ? "" : d);
    }
}
Also used : ConceptReferenceDesignationComponent(org.hl7.fhir.dstu3.model.ValueSet.ConceptReferenceDesignationComponent) XhtmlNode(org.hl7.fhir.utilities.xhtml.XhtmlNode)

Example 17 with ConceptReferenceComponent

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

the class ValueSetExpanderSimple method includeCodes.

private void includeCodes(ConceptSetComponent inc, List<ValueSetExpansionParameterComponent> params, ExpansionProfile profile) throws ETooCostly, FileNotFoundException, IOException, FHIRException {
    List<ValueSet> imports = new ArrayList<ValueSet>();
    for (UriType imp : inc.getValueSet()) imports.add(importValueSet(imp.getValue(), params, profile));
    if (!inc.hasSystem()) {
        if (// though this is not supposed to be the case
        imports.isEmpty())
            return;
        ValueSet base = imports.get(0);
        imports.remove(0);
        copyImportContains(base.getExpansion().getContains(), null, profile, imports);
    } else {
        CodeSystem cs = context.fetchCodeSystem(inc.getSystem());
        if ((cs == null || cs.getContent() != CodeSystemContentMode.COMPLETE) && context.supportsSystem(inc.getSystem())) {
            addCodes(context.expandVS(inc, canBeHeirarchy), params, profile, imports);
            return;
        }
        if (cs == null) {
            if (context.isNoTerminologyServer())
                throw new NoTerminologyServiceException("unable to find code system " + inc.getSystem().toString());
            else
                throw new TerminologyServiceException("unable to find code system " + inc.getSystem().toString());
        }
        if (cs.getContent() != CodeSystemContentMode.COMPLETE)
            throw new TerminologyServiceException("Code system " + inc.getSystem().toString() + " is incomplete");
        if (cs.hasVersion())
            if (!existsInParams(params, "version", new UriType(cs.getUrl() + "|" + cs.getVersion())))
                params.add(new ValueSetExpansionParameterComponent().setName("version").setValue(new UriType(cs.getUrl() + "|" + cs.getVersion())));
        if (inc.getConcept().size() == 0 && inc.getFilter().size() == 0) {
            // special case - add all the code system
            for (ConceptDefinitionComponent def : cs.getConcept()) {
                addCodeAndDescendents(cs, inc.getSystem(), def, null, profile, imports);
            }
        }
        if (!inc.getConcept().isEmpty()) {
            canBeHeirarchy = false;
            for (ConceptReferenceComponent c : inc.getConcept()) {
                addCode(inc.getSystem(), c.getCode(), Utilities.noString(c.getDisplay()) ? getCodeDisplay(cs, c.getCode()) : c.getDisplay(), null, convertDesignations(c.getDesignation()), profile, false, CodeSystemUtilities.isInactive(cs, c.getCode()), imports);
            }
        }
        if (inc.getFilter().size() > 1) {
            // which will bt the case if we get around to supporting this
            canBeHeirarchy = false;
            // need to and them, and this isn't done yet. But this shouldn't arise in non loinc and snomed value sets
            throw new TerminologyServiceException("Multiple filters not handled yet");
        }
        if (inc.getFilter().size() == 1) {
            ConceptSetFilterComponent fc = inc.getFilter().get(0);
            if ("concept".equals(fc.getProperty()) && fc.getOp() == FilterOperator.ISA) {
                // special: all codes in the target code system under the value
                ConceptDefinitionComponent def = getConceptForCode(cs.getConcept(), fc.getValue());
                if (def == null)
                    throw new TerminologyServiceException("Code '" + fc.getValue() + "' not found in system '" + inc.getSystem() + "'");
                addCodeAndDescendents(cs, inc.getSystem(), def, null, profile, imports);
            } else if ("concept".equals(fc.getProperty()) && fc.getOp() == FilterOperator.DESCENDENTOF) {
                // special: all codes in the target code system under the value
                ConceptDefinitionComponent def = getConceptForCode(cs.getConcept(), fc.getValue());
                if (def == null)
                    throw new TerminologyServiceException("Code '" + fc.getValue() + "' not found in system '" + inc.getSystem() + "'");
                for (ConceptDefinitionComponent c : def.getConcept()) addCodeAndDescendents(cs, inc.getSystem(), c, null, profile, imports);
            } else if ("display".equals(fc.getProperty()) && fc.getOp() == FilterOperator.EQUAL) {
                // gg; note: wtf is this: if the filter is display=v, look up the code 'v', and see if it's diplsay is 'v'?
                canBeHeirarchy = false;
                ConceptDefinitionComponent def = getConceptForCode(cs.getConcept(), fc.getValue());
                if (def != null) {
                    if (isNotBlank(def.getDisplay()) && isNotBlank(fc.getValue())) {
                        if (def.getDisplay().contains(fc.getValue())) {
                            addCode(inc.getSystem(), def.getCode(), def.getDisplay(), null, def.getDesignation(), profile, CodeSystemUtilities.isNotSelectable(cs, def), CodeSystemUtilities.isInactive(cs, def), imports);
                        }
                    }
                }
            } else
                throw new NotImplementedException("Search by property[" + fc.getProperty() + "] and op[" + fc.getOp() + "] is not supported yet");
        }
    }
}
Also used : NoTerminologyServiceException(org.hl7.fhir.exceptions.NoTerminologyServiceException) ConceptDefinitionComponent(org.hl7.fhir.dstu3.model.CodeSystem.ConceptDefinitionComponent) NotImplementedException(org.apache.commons.lang3.NotImplementedException) NoTerminologyServiceException(org.hl7.fhir.exceptions.NoTerminologyServiceException) TerminologyServiceException(org.hl7.fhir.exceptions.TerminologyServiceException) ValueSet(org.hl7.fhir.dstu3.model.ValueSet)

Example 18 with ConceptReferenceComponent

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

the class ValueSetRenderer method addLangaugesToRow.

public void addLangaugesToRow(ConceptReferenceComponent c, List<String> langs, XhtmlNode tr) {
    for (String lang : langs) {
        String d = null;
        for (Extension ext : c.getExtension()) {
            if (ToolingExtensions.EXT_TRANSLATION.equals(ext.getUrl())) {
                String l = ToolingExtensions.readStringExtension(ext, "lang");
                if (lang.equals(l)) {
                    d = ToolingExtensions.readStringExtension(ext, "content");
                }
            }
        }
        if (d == null) {
            for (ConceptReferenceDesignationComponent dd : c.getDesignation()) {
                String l = dd.getLanguage();
                if (lang.equals(l)) {
                    d = dd.getValue();
                }
            }
        }
        tr.td().addText(d == null ? "" : d);
    }
}
Also used : Extension(org.hl7.fhir.r4b.model.Extension) ConceptReferenceDesignationComponent(org.hl7.fhir.r4b.model.ValueSet.ConceptReferenceDesignationComponent)

Example 19 with ConceptReferenceComponent

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

the class ValueSetComparer method addSetConceptRow.

private void addSetConceptRow(HierarchicalTableGenerator gen, List<Row> rows, StructuralMatch<Element> t) {
    Row r = gen.new Row();
    rows.add(r);
    r.getCells().add(gen.new Cell(null, null, "Concept", null, null));
    if (t.hasLeft() && t.hasRight()) {
        ConceptReferenceComponent csL = (ConceptReferenceComponent) t.getLeft();
        ConceptReferenceComponent csR = (ConceptReferenceComponent) t.getRight();
        // we assume both have codes
        if (csL.getCode().equals(csR.getCode())) {
            r.getCells().add(gen.new Cell(null, null, csL.getCode(), null, null).span(2).center());
        } else {
            r.getCells().add(gen.new Cell(null, null, csL.getCode(), null, null).setStyle("background-color: " + COLOR_DIFFERENT));
            r.getCells().add(gen.new Cell(null, null, csR.getCode(), null, null).setStyle("background-color: " + COLOR_DIFFERENT));
        }
        if (csL.hasDisplay() && csR.hasDisplay()) {
            if (csL.getDisplay().equals(csR.getDisplay())) {
                r.getCells().add(gen.new Cell(null, null, csL.getDisplay(), null, null).span(2).center());
            } else {
                r.getCells().add(gen.new Cell(null, null, csL.getDisplay(), null, null).setStyle("background-color: " + COLOR_DIFFERENT));
                r.getCells().add(gen.new Cell(null, null, csR.getDisplay(), null, null).setStyle("background-color: " + COLOR_DIFFERENT));
            }
        } else if (csL.hasDisplay()) {
            r.getCells().add(gen.new Cell(null, null, csL.getDisplay(), null, null));
            r.getCells().add(missingCell(gen, COLOR_NO_CELL_RIGHT));
        } else if (csR.hasDisplay()) {
            r.getCells().add(missingCell(gen, COLOR_NO_CELL_LEFT));
            r.getCells().add(gen.new Cell(null, null, csR.getDisplay(), null, null));
        } else {
            r.getCells().add(missingCell(gen).span(2).center());
        }
    } else if (t.hasLeft()) {
        r.setColor(COLOR_NO_ROW_RIGHT);
        ConceptReferenceComponent cs = (ConceptReferenceComponent) t.getLeft();
        r.getCells().add(gen.new Cell(null, null, cs.getCode(), null, null));
        r.getCells().add(missingCell(gen));
        r.getCells().add(gen.new Cell(null, null, cs.hasDisplay() ? "Version: " + cs.getDisplay() : "", null, null));
        r.getCells().add(missingCell(gen));
    } else {
        r.setColor(COLOR_NO_ROW_LEFT);
        ConceptReferenceComponent cs = (ConceptReferenceComponent) t.getRight();
        r.getCells().add(missingCell(gen));
        r.getCells().add(gen.new Cell(null, null, cs.getCode(), null, null));
        r.getCells().add(missingCell(gen));
        r.getCells().add(gen.new Cell(null, null, cs.hasDisplay() ? "Version: " + cs.getDisplay() : "", null, null));
    }
    r.getCells().add(cellForMessages(gen, t.getMessages()));
}
Also used : Row(org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator.Row) ConceptReferenceComponent(org.hl7.fhir.r5.model.ValueSet.ConceptReferenceComponent)

Example 20 with ConceptReferenceComponent

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

the class ValueSetComparer method addComposeRow.

private void addComposeRow(HierarchicalTableGenerator gen, List<Row> rows, StructuralMatch<Element> t, String name) {
    Row r = gen.new Row();
    rows.add(r);
    r.getCells().add(gen.new Cell(null, null, name, null, null));
    if (t.hasLeft() && t.hasRight()) {
        ConceptSetComponent csL = (ConceptSetComponent) t.getLeft();
        ConceptSetComponent csR = (ConceptSetComponent) t.getRight();
        if (csL.hasSystem() && csL.getSystem().equals(csR.getSystem())) {
            r.getCells().add(gen.new Cell(null, null, csL.getSystem(), null, null).span(2).center());
        } else {
            r.getCells().add(gen.new Cell(null, null, csL.getSystem(), null, null).setStyle("background-color: " + COLOR_DIFFERENT));
            r.getCells().add(gen.new Cell(null, null, csR.getSystem(), null, null).setStyle("background-color: " + COLOR_DIFFERENT));
        }
        if (csL.hasVersion() && csR.hasVersion()) {
            if (csL.getVersion().equals(csR.getVersion())) {
                r.getCells().add(gen.new Cell(null, null, csL.getVersion(), null, null).span(2).center());
            } else {
                r.getCells().add(gen.new Cell(null, null, csL.getVersion(), null, null).setStyle("background-color: " + COLOR_DIFFERENT));
                r.getCells().add(gen.new Cell(null, null, csR.getVersion(), null, null).setStyle("background-color: " + COLOR_DIFFERENT));
            }
        } else if (csL.hasVersion()) {
            r.getCells().add(gen.new Cell(null, null, csL.getVersion(), null, null));
            r.getCells().add(missingCell(gen, COLOR_NO_CELL_RIGHT));
        } else if (csR.hasVersion()) {
            r.getCells().add(missingCell(gen, COLOR_NO_CELL_LEFT));
            r.getCells().add(gen.new Cell(null, null, csR.getVersion(), null, null));
        } else {
            r.getCells().add(missingCell(gen).span(2).center());
        }
    } else if (t.hasLeft()) {
        r.setColor(COLOR_NO_ROW_RIGHT);
        ConceptSetComponent cs = (ConceptSetComponent) t.getLeft();
        r.getCells().add(gen.new Cell(null, null, cs.getSystem(), null, null));
        r.getCells().add(missingCell(gen));
        r.getCells().add(gen.new Cell(null, null, cs.hasVersion() ? "Version: " + cs.getVersion() : "", null, null));
        r.getCells().add(missingCell(gen));
    } else {
        r.setColor(COLOR_NO_ROW_LEFT);
        ConceptSetComponent cs = (ConceptSetComponent) t.getRight();
        r.getCells().add(missingCell(gen));
        r.getCells().add(gen.new Cell(null, null, cs.getSystem(), null, null));
        r.getCells().add(missingCell(gen));
        r.getCells().add(gen.new Cell(null, null, cs.hasVersion() ? "Version: " + cs.getVersion() : "", null, null));
    }
    r.getCells().add(cellForMessages(gen, t.getMessages()));
    for (StructuralMatch<Element> c : t.getChildren()) {
        if (c.either() instanceof ConceptReferenceComponent) {
            addSetConceptRow(gen, r.getSubRows(), c);
        } else {
            addSetFilterRow(gen, r.getSubRows(), c);
        }
    }
}
Also used : ConceptSetComponent(org.hl7.fhir.r5.model.ValueSet.ConceptSetComponent) Element(org.hl7.fhir.r5.model.Element) Row(org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator.Row) ConceptReferenceComponent(org.hl7.fhir.r5.model.ValueSet.ConceptReferenceComponent)

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