Search in sources :

Example 11 with ValueSetExpansionParameterComponent

use of org.hl7.fhir.dstu2016may.model.ValueSet.ValueSetExpansionParameterComponent in project org.hl7.fhir.core by hapifhir.

the class CodeSystemSpreadsheetGenerator method genExpansionParams.

private void genExpansionParams(List<ValueSetExpansionParameterComponent> params) {
    Sheet sheet = makeSheet("Expansion Parameters");
    addHeaders(sheet, "Parameter", "Value");
    for (ValueSetExpansionParameterComponent p : params) {
        addRow(sheet, p.getName(), dr.display(p.getValue()));
    }
}
Also used : ValueSetExpansionParameterComponent(org.hl7.fhir.r5.model.ValueSet.ValueSetExpansionParameterComponent) Sheet(org.apache.poi.ss.usermodel.Sheet)

Example 12 with ValueSetExpansionParameterComponent

use of org.hl7.fhir.dstu2016may.model.ValueSet.ValueSetExpansionParameterComponent 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 13 with ValueSetExpansionParameterComponent

use of org.hl7.fhir.dstu2016may.model.ValueSet.ValueSetExpansionParameterComponent in project org.hl7.fhir.core by hapifhir.

the class ValueSetSpreadsheetGenerator method genExpansionParams.

private void genExpansionParams(List<ValueSetExpansionParameterComponent> params) {
    Sheet sheet = makeSheet("Expansion Parameters");
    addHeaders(sheet, "Parameter", "Value");
    for (ValueSetExpansionParameterComponent p : params) {
        addRow(sheet, p.getName(), dr.display(p.getValue()));
    }
}
Also used : ValueSetExpansionParameterComponent(org.hl7.fhir.r4b.model.ValueSet.ValueSetExpansionParameterComponent) Sheet(org.apache.poi.ss.usermodel.Sheet)

Example 14 with ValueSetExpansionParameterComponent

use of org.hl7.fhir.dstu2016may.model.ValueSet.ValueSetExpansionParameterComponent in project org.hl7.fhir.core by hapifhir.

the class NarrativeGenerator method generateVersionNotice.

@SuppressWarnings("rawtypes")
private void generateVersionNotice(XhtmlNode x, ValueSetExpansionComponent expansion) {
    Map<String, String> versions = new HashMap<String, String>();
    boolean firstVersion = true;
    for (ValueSetExpansionParameterComponent p : expansion.getParameter()) {
        if (p.getName().equals("version")) {
            String[] parts = ((PrimitiveType) p.getValue()).asStringValue().split("\\|");
            if (parts.length == 2)
                versions.put(parts[0], parts[1]);
            if (!versions.isEmpty()) {
                StringBuilder b = new StringBuilder();
                if (firstVersion) {
                    // the first version
                    // set the <p> tag and style attribute
                    x.para().setAttribute("style", "border: black 1px dotted; background-color: #EEEEEE; padding: 8px");
                    firstVersion = false;
                } else {
                    // the second (or greater) version
                    // add line break before the version text
                    x.br();
                }
                b.append("Expansion based on ");
                boolean firstPart = true;
                for (String s : versions.keySet()) {
                    if (firstPart)
                        firstPart = false;
                    else
                        b.append(", ");
                    if (!s.equals("http://snomed.info/sct"))
                        b.append(describeSystem(s) + " version " + versions.get(s));
                    else {
                        parts = versions.get(s).split("\\/");
                        if (parts.length >= 5) {
                            String m = describeModule(parts[4]);
                            if (parts.length == 7)
                                b.append("SNOMED CT " + m + " edition " + formatSCTDate(parts[6]));
                            else
                                b.append("SNOMED CT " + m + " edition");
                        } else
                            b.append(describeSystem(s) + " version " + versions.get(s));
                    }
                }
                // add the version text
                x.addText(b.toString());
            }
        }
    }
}
Also used : CommaSeparatedStringBuilder(org.hl7.fhir.utilities.CommaSeparatedStringBuilder) HashMap(java.util.HashMap) ValueSetExpansionParameterComponent(org.hl7.fhir.dstu3.model.ValueSet.ValueSetExpansionParameterComponent)

Example 15 with ValueSetExpansionParameterComponent

use of org.hl7.fhir.dstu2016may.model.ValueSet.ValueSetExpansionParameterComponent in project org.hl7.fhir.core by hapifhir.

the class NarrativeGenerator method generateVersionNotice.

@SuppressWarnings("rawtypes")
private void generateVersionNotice(XhtmlNode x, ValueSetExpansionComponent expansion) {
    Map<String, String> versions = new HashMap<String, String>();
    boolean firstVersion = true;
    for (ValueSetExpansionParameterComponent p : expansion.getParameter()) {
        if (p.getName().equals("version")) {
            String[] parts = ((PrimitiveType) p.getValue()).asStringValue().split("\\|");
            if (parts.length == 2)
                versions.put(parts[0], parts[1]);
            if (!versions.isEmpty()) {
                StringBuilder b = new StringBuilder();
                if (firstVersion) {
                    // the first version
                    // set the <p> tag and style attribute
                    x.para().setAttribute("style", "border: black 1px dotted; background-color: #EEEEEE; padding: 8px");
                    firstVersion = false;
                } else {
                    // the second (or greater) version
                    // add line break before the version text
                    x.br();
                }
                b.append("Expansion based on ");
                boolean firstPart = true;
                for (String s : versions.keySet()) {
                    if (firstPart)
                        firstPart = false;
                    else
                        b.append(", ");
                    if (!s.equals("http://snomed.info/sct"))
                        b.append(describeSystem(s) + " version " + versions.get(s));
                    else {
                        parts = versions.get(s).split("\\/");
                        if (parts.length >= 5) {
                            String m = describeModule(parts[4]);
                            if (parts.length == 7)
                                b.append("SNOMED CT " + m + " edition " + formatSCTDate(parts[6]));
                            else
                                b.append("SNOMED CT " + m + " edition");
                        } else
                            b.append(describeSystem(s) + " version " + versions.get(s));
                    }
                }
                // add the version text
                x.addText(b.toString());
            }
        }
    }
}
Also used : CommaSeparatedStringBuilder(org.hl7.fhir.utilities.CommaSeparatedStringBuilder)

Aggregations

TerminologyServiceException (org.hl7.fhir.exceptions.TerminologyServiceException)10 ValueSetExpansionParameterComponent (org.hl7.fhir.r4b.model.ValueSet.ValueSetExpansionParameterComponent)9 ValueSetExpansionParameterComponent (org.hl7.fhir.r5.model.ValueSet.ValueSetExpansionParameterComponent)9 NoTerminologyServiceException (org.hl7.fhir.exceptions.NoTerminologyServiceException)6 NotImplementedException (org.apache.commons.lang3.NotImplementedException)5 UriType (org.hl7.fhir.r4b.model.UriType)5 UriType (org.hl7.fhir.r5.model.UriType)5 Sheet (org.apache.poi.ss.usermodel.Sheet)4 UriType (org.hl7.fhir.r4.model.UriType)4 ValueSet (org.hl7.fhir.r4.model.ValueSet)4 XhtmlNode (org.hl7.fhir.utilities.xhtml.XhtmlNode)4 ArrayList (java.util.ArrayList)3 ValueSetExpansionParameterComponent (org.hl7.fhir.r4.model.ValueSet.ValueSetExpansionParameterComponent)3 ValueSet (org.hl7.fhir.r4b.model.ValueSet)3 ValueSet (org.hl7.fhir.r5.model.ValueSet)3 List (java.util.List)2 UriType (org.hl7.fhir.dstu2.model.UriType)2 ValueSet (org.hl7.fhir.dstu2.model.ValueSet)2 ValueSetExpansionParameterComponent (org.hl7.fhir.dstu2.model.ValueSet.ValueSetExpansionParameterComponent)2 UriType (org.hl7.fhir.dstu2016may.model.UriType)2