Search in sources :

Example 26 with ValueSetComposeComponent

use of org.hl7.fhir.r4.model.ValueSet.ValueSetComposeComponent in project snowstorm by IHTSDO.

the class FHIRValueSetProvider method doExplicitExpansion.

/**
 * An explicit ValueSet has been saved on the server with a name and id, and
 * is defined by use of the "compose" element within the valueset resource.
 * @param branchPathForced
 */
private Page<ConceptMini> doExplicitExpansion(ValueSet vs, Boolean active, String filter, BranchPath branchPath, List<LanguageDialect> designations, PageRequest pageRequest, boolean branchPathForced) throws FHIROperationException {
    Page<ConceptMini> conceptMiniPage = new PageImpl<>(new ArrayList<>());
    if (vs != null && vs.getCompose() != null && !vs.getCompose().isEmpty()) {
        if (!branchPathForced) {
            branchPath.set(obtainConsistentCodeSystemVersionFromCompose(vs.getCompose(), branchPath));
        }
        ValueSetComposeComponent compose = vs.getCompose();
        Set<String> conceptIds = new HashSet<>();
        StringBuilder filterECL = new StringBuilder();
        boolean firstItem = true;
        for (ConceptSetComponent include : compose.getInclude()) {
            conceptIds.addAll(include.getConcept().stream().map(ValueSet.ConceptReferenceComponent::getCode).collect(Collectors.toSet()));
            filterECL.append(fhirHelper.convertFilterToECL(include, firstItem));
            if (firstItem) {
                firstItem = false;
            }
        }
        firstItem = true;
        for (ConceptSetComponent exclude : compose.getExclude()) {
            conceptIds.addAll(exclude.getConcept().stream().map(ValueSet.ConceptReferenceComponent::getCode).collect(Collectors.toSet()));
            filterECL.append(fhirHelper.convertFilterToECL(exclude, firstItem));
            if (firstItem) {
                firstItem = false;
            }
        }
        String branch = branchPath.toString();
        Collection<ConceptMini> fromService = conceptService.findConceptMinis(branch, conceptIds, designations).getResultsMap().values();
        logger.info("Recovered {} Concepts from branch {} with Compose.", fromService.size(), branch);
        String ecl = filterECL.toString();
        Page<ConceptMini> page = fhirHelper.eclSearch(ecl, active, filter, designations, branchPath, pageRequest);
        Collection<ConceptMini> fromECL = page.getContent();
        logger.info("Recovered {} Concepts from branch {} with ECL {}.", page.getTotalElements(), branch, filterECL);
        List<ConceptMini> conceptMinis = new ArrayList<>();
        conceptMinis.addAll(fromService);
        conceptMinis.addAll(fromECL);
        long totalCount = fromService.size() + page.getTotalElements();
        conceptMiniPage = new PageImpl<ConceptMini>(conceptMinis, page.getPageable(), totalCount);
        logger.info("Collectively recovered {} Concepts from branch {}.", conceptMiniPage.getTotalElements(), branch);
    } else {
        String msg = "Compose element(s) or 'url' parameter is expected to be present for an expansion, containing eg http://snomed.info/sct?fhir_vs=ecl/ or http://snomed.info/sct/45991000052106?fhir_vs=ecl/ ";
        // We don't need ECL if we're expanding a named valueset
        if (vs != null) {
            logger.warn(msg + " when expanding " + vs.getId());
        } else {
            throw new FHIROperationException(IssueType.VALUE, msg);
        }
    }
    return conceptMiniPage;
}
Also used : PageImpl(org.springframework.data.domain.PageImpl) ValueSetComposeComponent(org.hl7.fhir.r4.model.ValueSet.ValueSetComposeComponent) ConceptSetComponent(org.hl7.fhir.r4.model.ValueSet.ConceptSetComponent) ConceptMini(org.snomed.snowstorm.core.data.domain.ConceptMini)

Example 27 with ValueSetComposeComponent

use of org.hl7.fhir.r4.model.ValueSet.ValueSetComposeComponent in project kindling by HL7.

the class CodeListToValueSetParser method execute.

public void execute(String v2map, String v3map, boolean utg) throws Exception {
    boolean hasDefine = false;
    for (int row = 0; row < sheet.rows.size(); row++) {
        hasDefine = hasDefine || Utilities.noString(sheet.getColumn(row, "System"));
    }
    Map<String, ConceptDefinitionComponent> codes = new HashMap<String, ConceptDefinitionComponent>();
    Map<String, ConceptDefinitionComponent> codesById = new HashMap<String, ConceptDefinitionComponent>();
    Map<String, ConceptSetComponent> includes = new HashMap<String, ConceptSetComponent>();
    CodeSystem cs = null;
    if (hasDefine) {
        cs = new CodeSystem();
        if (utg)
            cs.setUrl("http://terminology.hl7.org/CodeSystem/" + sheetName);
        else
            cs.setUrl("http://hl7.org/fhir/" + sheetName);
        if (!valueSet.hasCompose())
            valueSet.setCompose(new ValueSetComposeComponent());
        valueSet.getCompose().addInclude().setSystem(cs.getUrl());
        cs.setVersion(version);
        cs.setCaseSensitive(true);
        cs.setContent(CodeSystemContentMode.COMPLETE);
        codeSystems.see(cs, packageInfo);
        for (int row = 0; row < sheet.rows.size(); row++) {
            if (Utilities.noString(sheet.getColumn(row, "System"))) {
                ConceptDefinitionComponent cc = new ConceptDefinitionComponent();
                cc.setUserData("id", sheet.getColumn(row, "Id"));
                cc.setCode(sheet.getColumn(row, "Code"));
                if (codes.containsKey(cc.getCode()))
                    throw new Exception("Duplicate Code " + cc.getCode());
                codes.put(cc.getCode(), cc);
                codesById.put(cc.getUserString("id"), cc);
                cc.setDisplay(sheet.getColumn(row, "Display"));
                if (sheet.getColumn(row, "Abstract").toUpperCase().equals("Y"))
                    CodeSystemUtilities.setNotSelectable(cs, cc);
                if (cc.hasCode() && !cc.hasDisplay())
                    cc.setDisplay(Utilities.humanize(cc.getCode()));
                cc.setDefinition(Utilities.appendPeriod(sheet.getColumn(row, "Definition")));
                if (!Utilities.noString(sheet.getColumn(row, "Comment")))
                    ToolingExtensions.addCSComment(cc, sheet.getColumn(row, "Comment"));
                cc.setUserData("v2", sheet.getColumn(row, "v2"));
                cc.setUserData("v3", sheet.getColumn(row, "v3"));
                for (String ct : sheet.columns) if (ct.startsWith("Display:") && !Utilities.noString(sheet.getColumn(row, ct)))
                    cc.addDesignation().setLanguage(ct.substring(8)).setValue(sheet.getColumn(row, ct));
                String parent = sheet.getColumn(row, "Parent");
                if (Utilities.noString(parent))
                    cs.addConcept(cc);
                else if (parent.startsWith("#") && codesById.containsKey(parent.substring(1)))
                    codesById.get(parent.substring(1)).addConcept(cc);
                else if (codes.containsKey(parent))
                    codes.get(parent).addConcept(cc);
                else
                    throw new Exception("Parent " + parent + " not resolved in " + sheetName);
            }
        }
    }
    for (int row = 0; row < sheet.rows.size(); row++) {
        if (!Utilities.noString(sheet.getColumn(row, "System"))) {
            String system = sheet.getColumn(row, "System");
            ConceptSetComponent t = includes.get(system);
            if (t == null) {
                if (!valueSet.hasCompose())
                    valueSet.setCompose(new ValueSetComposeComponent());
                t = valueSet.getCompose().addInclude();
                t.setSystem(system);
                includes.put(system, t);
            }
            ConceptReferenceComponent cc = t.addConcept();
            cc.setCode(sheet.getColumn(row, "Code"));
            if (codes.containsKey(cc.getCode()))
                throw new Exception("Duplicate Code " + cc.getCode());
            codes.put(cc.getCode(), null);
            cc.setDisplay(sheet.getColumn(row, "Display"));
            if (!Utilities.noString(sheet.getColumn(row, "Definition")))
                ToolingExtensions.addDefinition(cc, sheet.getColumn(row, "Definition"));
            if (!Utilities.noString(sheet.getColumn(row, "Comment")))
                ToolingExtensions.addVSComment(cc, sheet.getColumn(row, "Comment"));
            cc.setUserDataINN("v2", sheet.getColumn(row, "v2"));
            cc.setUserDataINN("v3", sheet.getColumn(row, "v3"));
            for (String ct : sheet.columns) if (ct.startsWith("Display:") && !Utilities.noString(sheet.getColumn(row, ct)))
                cc.addDesignation().setLanguage(ct.substring(8)).setValue(sheet.getColumn(row, ct));
        }
    }
    if (!Utilities.noString(v2map)) {
        generateConceptMapV2(v2map, valueSet, cs);
    }
    if (!Utilities.noString(v3map)) {
        generateConceptMapV3(v3map, valueSet, cs);
    }
    if (cs != null)
        CodeSystemConvertor.populate(cs, valueSet);
}
Also used : ConceptSetComponent(org.hl7.fhir.r5.model.ValueSet.ConceptSetComponent) ConceptDefinitionComponent(org.hl7.fhir.r5.model.CodeSystem.ConceptDefinitionComponent) HashMap(java.util.HashMap) CodeSystem(org.hl7.fhir.r5.model.CodeSystem) ValueSetComposeComponent(org.hl7.fhir.r5.model.ValueSet.ValueSetComposeComponent) ConceptReferenceComponent(org.hl7.fhir.r5.model.ValueSet.ConceptReferenceComponent) ContactPoint(org.hl7.fhir.r5.model.ContactPoint)

Example 28 with ValueSetComposeComponent

use of org.hl7.fhir.r4.model.ValueSet.ValueSetComposeComponent in project kindling by HL7.

the class ValueSetGenerator method genDefinedTypes.

private void genDefinedTypes(ValueSet vs, boolean doAbstract) throws Exception {
    ValueSetComposeComponent compose = new ValueSetComposeComponent();
    vs.setCompose(compose);
    compose.addInclude().setSystem("http://hl7.org/fhir/data-types");
    compose.addInclude().setSystem("http://hl7.org/fhir/resource-types");
    if (doAbstract)
        compose.addInclude().setSystem("http://hl7.org/fhir/abstract-types");
    vs.setUserData("filename", "valueset-" + vs.getId());
    if (!vs.hasExtension(ToolingExtensions.EXT_WORKGROUP)) {
        vs.addExtension().setUrl(ToolingExtensions.EXT_WORKGROUP).setValue(new CodeType("fhir"));
    } else {
        String ec = ToolingExtensions.readStringExtension(vs, ToolingExtensions.EXT_WORKGROUP);
        if (!ec.equals("fhir"))
            System.out.println("ValueSet " + vs.getUrl() + " WG mismatch 9: is " + ec + ", want to set to " + "fhir");
    }
    vs.setUserData("path", "valueset-" + vs.getId() + ".html");
    markSpecialStatus(vs, null, true);
}
Also used : CodeType(org.hl7.fhir.r5.model.CodeType) ValueSetComposeComponent(org.hl7.fhir.r5.model.ValueSet.ValueSetComposeComponent)

Example 29 with ValueSetComposeComponent

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

the class ValueSetExpanderSimple method handleCompose.

private void handleCompose(ValueSetComposeComponent compose, List<ValueSetExpansionParameterComponent> params, Parameters expParams, String ctxt) throws ETooCostly, FileNotFoundException, IOException, FHIRException {
    compose.checkNoModifiers("ValueSet.compose", "expanding");
    // Exclude comes first because we build up a map of things to exclude
    for (ConceptSetComponent inc : compose.getExclude()) excludeCodes(inc, params, ctxt);
    canBeHeirarchy = !expParams.getParameterBool("excludeNested") && excludeKeys.isEmpty() && excludeSystems.isEmpty();
    boolean first = true;
    for (ConceptSetComponent inc : compose.getInclude()) {
        if (first == true)
            first = false;
        else
            canBeHeirarchy = false;
        includeCodes(inc, params, expParams, canBeHeirarchy);
    }
}
Also used : ConceptSetComponent(org.hl7.fhir.r4.model.ValueSet.ConceptSetComponent)

Example 30 with ValueSetComposeComponent

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

the class BaseWorkerContext method expandVS.

@Override
public ValueSetExpansionComponent expandVS(ConceptSetComponent inc) {
    ValueSet vs = new ValueSet();
    vs.setCompose(new ValueSetComposeComponent());
    vs.getCompose().getInclude().add(inc);
    ValueSetExpansionOutcome vse = expandVS(vs, true);
    return vse.getValueset().getExpansion();
}
Also used : ValueSetExpansionOutcome(org.hl7.fhir.dstu2016may.terminologies.ValueSetExpander.ValueSetExpansionOutcome) ValueSet(org.hl7.fhir.dstu2016may.model.ValueSet) ValueSetComposeComponent(org.hl7.fhir.dstu2016may.model.ValueSet.ValueSetComposeComponent)

Aggregations

ConceptSetComponent (org.hl7.fhir.r4.model.ValueSet.ConceptSetComponent)9 ArrayList (java.util.ArrayList)8 ValueSetComposeComponent (org.hl7.fhir.r5.model.ValueSet.ValueSetComposeComponent)8 ValueSetComposeComponent (org.hl7.fhir.r4.model.ValueSet.ValueSetComposeComponent)7 ValueSetComposeComponent (org.hl7.fhir.dstu3.model.ValueSet.ValueSetComposeComponent)6 CodeSystem (org.hl7.fhir.r5.model.CodeSystem)6 CodeType (org.hl7.fhir.r5.model.CodeType)6 ConceptDefinitionComponent (org.hl7.fhir.r5.model.CodeSystem.ConceptDefinitionComponent)5 HashMap (java.util.HashMap)4 ConceptReferenceComponent (org.hl7.fhir.dstu3.model.ValueSet.ConceptReferenceComponent)4 ConceptSetComponent (org.hl7.fhir.dstu3.model.ValueSet.ConceptSetComponent)4 TerminologyServiceException (org.hl7.fhir.exceptions.TerminologyServiceException)4 ConceptReferenceComponent (org.hl7.fhir.r4.model.ValueSet.ConceptReferenceComponent)4 ConceptSetComponent (org.hl7.fhir.r5.model.ValueSet.ConceptSetComponent)4 FileNotFoundException (java.io.FileNotFoundException)3 IOException (java.io.IOException)3 DefinitionException (org.hl7.fhir.exceptions.DefinitionException)3 FHIRException (org.hl7.fhir.exceptions.FHIRException)3 NoTerminologyServiceException (org.hl7.fhir.exceptions.NoTerminologyServiceException)3 ConceptSetComponent (org.hl7.fhir.r4b.model.ValueSet.ConceptSetComponent)3