Search in sources :

Example 26 with ConceptSetComponent

use of org.hl7.fhir.r4.model.ValueSet.ConceptSetComponent in project org.hl7.fhir.core by hapifhir.

the class ValueSetExpanderSimple method excludeCodes.

private void excludeCodes(ConceptSetComponent exc, List<ValueSetExpansionParameterComponent> params, String ctxt) throws FHIRException {
    exc.checkNoModifiers("Compose.exclude", "expanding");
    if (exc.hasSystem() && exc.getConcept().size() == 0 && exc.getFilter().size() == 0) {
        excludeSystems.add(exc.getSystem());
    }
    if (exc.hasValueSet())
        throw new Error("Processing Value set references in exclude is not yet done in " + ctxt);
    // importValueSet(imp.getValue(), params, expParams);
    CodeSystem cs = context.fetchCodeSystem(exc.getSystem());
    if ((cs == null || cs.getContent() != CodeSystemContentMode.COMPLETE) && context.supportsSystem(exc.getSystem())) {
        ValueSetExpansionOutcome vse = context.expandVS(exc, false);
        ValueSet valueset = vse.getValueset();
        if (valueset == null)
            throw new TerminologyServiceException("Error Expanding ValueSet: " + vse.getError());
        excludeCodes(valueset.getExpansion(), params);
        return;
    }
    for (ConceptReferenceComponent c : exc.getConcept()) {
        excludeCode(exc.getSystem(), c.getCode());
    }
    if (exc.getFilter().size() > 0)
        throw new NotImplementedException("not done yet");
}
Also used : NotImplementedException(org.apache.commons.lang3.NotImplementedException) FHIRFormatError(org.hl7.fhir.exceptions.FHIRFormatError) NoTerminologyServiceException(org.hl7.fhir.exceptions.NoTerminologyServiceException) TerminologyServiceException(org.hl7.fhir.exceptions.TerminologyServiceException) CodeSystem(org.hl7.fhir.r4.model.CodeSystem) ValueSet(org.hl7.fhir.r4.model.ValueSet) ConceptReferenceComponent(org.hl7.fhir.r4.model.ValueSet.ConceptReferenceComponent)

Example 27 with ConceptSetComponent

use of org.hl7.fhir.r4.model.ValueSet.ConceptSetComponent in project org.hl7.fhir.core by hapifhir.

the class ValueSetCheckerSimple method inComponent.

private boolean inComponent(ConceptSetComponent vsi, String system, String code, boolean only) throws FHIRException {
    for (UriType uri : vsi.getValueSet()) {
        if (inImport(uri.getValue(), system, code))
            return true;
    }
    if (!vsi.hasSystem())
        return false;
    if (only && system == null) {
        // whether we know the system or not, we'll accept the stated codes at face value
        for (ConceptReferenceComponent cc : vsi.getConcept()) if (cc.getCode().equals(code))
            return true;
    }
    if (!system.equals(vsi.getSystem()))
        return false;
    if (vsi.hasFilter()) {
        boolean ok = true;
        for (ConceptSetFilterComponent f : vsi.getFilter()) if (!codeInFilter(system, f, code)) {
            ok = false;
            break;
        }
        if (ok)
            return true;
    }
    CodeSystem def = context.fetchCodeSystem(system);
    if (def.getContent() != CodeSystemContentMode.COMPLETE)
        throw new FHIRException("Unable to resolve system " + vsi.getSystem() + " - system is not complete");
    List<ConceptDefinitionComponent> list = def.getConcept();
    boolean ok = validateCodeInConceptList(code, def, list);
    if (ok && vsi.hasConcept()) {
        for (ConceptReferenceComponent cc : vsi.getConcept()) if (cc.getCode().equals(code))
            return true;
        return false;
    } else
        return ok;
}
Also used : ConceptDefinitionComponent(org.hl7.fhir.r4.model.CodeSystem.ConceptDefinitionComponent) FHIRException(org.hl7.fhir.exceptions.FHIRException)

Example 28 with ConceptSetComponent

use of org.hl7.fhir.r4.model.ValueSet.ConceptSetComponent in project org.hl7.fhir.core by hapifhir.

the class TerminologyCache method generateExpandToken.

public CacheToken generateExpandToken(ValueSet vs, boolean heirarchical) {
    CacheToken ct = new CacheToken();
    ValueSet vsc = getVSEssense(vs);
    for (ConceptSetComponent inc : vs.getCompose().getInclude()) if (inc.hasSystem())
        ct.setName(getNameForSystem(inc.getSystem()));
    for (ConceptSetComponent inc : vs.getCompose().getExclude()) if (inc.hasSystem())
        ct.setName(getNameForSystem(inc.getSystem()));
    for (ValueSetExpansionContainsComponent inc : vs.getExpansion().getContains()) if (inc.hasSystem())
        ct.setName(getNameForSystem(inc.getSystem()));
    JsonParser json = new JsonParser();
    json.setOutputStyle(OutputStyle.PRETTY);
    try {
        ct.request = "{\"hierarchical\" : " + (heirarchical ? "true" : "false") + ", \"valueSet\" :" + extracted(json, vsc) + "}\r\n";
    } catch (IOException e) {
        throw new Error(e);
    }
    ct.key = String.valueOf(hashNWS(ct.request));
    return ct;
}
Also used : ConceptSetComponent(org.hl7.fhir.r4b.model.ValueSet.ConceptSetComponent) ValueSetExpansionContainsComponent(org.hl7.fhir.r4b.model.ValueSet.ValueSetExpansionContainsComponent) IOException(java.io.IOException) ValueSet(org.hl7.fhir.r4b.model.ValueSet) JsonParser(org.hl7.fhir.r4b.formats.JsonParser)

Example 29 with ConceptSetComponent

use of org.hl7.fhir.r4.model.ValueSet.ConceptSetComponent in project org.hl7.fhir.core by hapifhir.

the class TerminologyCache method getIncSummary.

private String getIncSummary(ConceptSetComponent cc) {
    CommaSeparatedStringBuilder b = new CommaSeparatedStringBuilder();
    for (UriType vs : cc.getValueSet()) b.append(vs.asStringValue());
    String vsd = b.length() > 0 ? " where the codes are in the value sets (" + b.toString() + ")" : "";
    String system = cc.getSystem();
    if (cc.hasConcept())
        return Integer.toString(cc.getConcept().size()) + " codes from " + system + vsd;
    if (cc.hasFilter()) {
        String s = "";
        for (ConceptSetFilterComponent f : cc.getFilter()) {
            if (!Utilities.noString(s))
                s = s + " & ";
            s = s + f.getProperty() + " " + (f.hasOp() ? f.getOp().toCode() : "?") + " " + f.getValue();
        }
        return "from " + system + " where " + s + vsd;
    }
    return "All codes from " + system + vsd;
}
Also used : ConceptSetFilterComponent(org.hl7.fhir.r4b.model.ValueSet.ConceptSetFilterComponent) CommaSeparatedStringBuilder(org.hl7.fhir.utilities.CommaSeparatedStringBuilder) UriType(org.hl7.fhir.r4b.model.UriType)

Example 30 with ConceptSetComponent

use of org.hl7.fhir.r4.model.ValueSet.ConceptSetComponent 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.r4b.model.ValueSet.ConceptSetComponent) Element(org.hl7.fhir.r4b.model.Element) Row(org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator.Row) ConceptReferenceComponent(org.hl7.fhir.r4b.model.ValueSet.ConceptReferenceComponent)

Aggregations

ConceptSetComponent (org.hl7.fhir.r5.model.ValueSet.ConceptSetComponent)25 ArrayList (java.util.ArrayList)22 ConceptSetComponent (org.hl7.fhir.r4.model.ValueSet.ConceptSetComponent)21 IOException (java.io.IOException)20 TerminologyServiceException (org.hl7.fhir.exceptions.TerminologyServiceException)20 XhtmlNode (org.hl7.fhir.utilities.xhtml.XhtmlNode)19 FHIRException (org.hl7.fhir.exceptions.FHIRException)17 HashMap (java.util.HashMap)15 ConceptSetComponent (org.hl7.fhir.dstu3.model.ValueSet.ConceptSetComponent)14 ConceptReferenceComponent (org.hl7.fhir.r5.model.ValueSet.ConceptReferenceComponent)14 ValueSet (org.hl7.fhir.r4.model.ValueSet)13 ValueSet (org.hl7.fhir.r5.model.ValueSet)13 DefinitionException (org.hl7.fhir.exceptions.DefinitionException)12 NoTerminologyServiceException (org.hl7.fhir.exceptions.NoTerminologyServiceException)12 ConceptSetComponent (org.hl7.fhir.r4b.model.ValueSet.ConceptSetComponent)12 FileNotFoundException (java.io.FileNotFoundException)10 NotImplementedException (org.apache.commons.lang3.NotImplementedException)10 CodeSystem (org.hl7.fhir.r5.model.CodeSystem)10 CommaSeparatedStringBuilder (org.hl7.fhir.utilities.CommaSeparatedStringBuilder)10 ValueSet (org.hl7.fhir.dstu3.model.ValueSet)9