Search in sources :

Example 1 with ConceptReferenceComponent

use of org.hl7.fhir.dstu2.model.ValueSet.ConceptReferenceComponent in project bunsen by cerner.

the class ValueSets method expandValuesIterator.

private static Iterator<Value> expandValuesIterator(ValueSet valueSet) {
    List<Value> values = new ArrayList<>();
    ValueSetComposeComponent compose = valueSet.getCompose();
    for (ConceptSetComponent inclusion : compose.getInclude()) {
        for (ConceptReferenceComponent concept : inclusion.getConcept()) {
            Value value = new Value();
            value.setValueSetUri(valueSet.getUrl());
            value.setValueSetVersion(valueSet.getVersion());
            value.setSystem(inclusion.getSystem());
            value.setVersion(inclusion.getVersion());
            value.setValue(concept.getCode());
            values.add(value);
        }
    }
    return values.iterator();
}
Also used : ConceptSetComponent(org.hl7.fhir.dstu3.model.ValueSet.ConceptSetComponent) ArrayList(java.util.ArrayList) ValueSetComposeComponent(org.hl7.fhir.dstu3.model.ValueSet.ValueSetComposeComponent) ConceptReferenceComponent(org.hl7.fhir.dstu3.model.ValueSet.ConceptReferenceComponent)

Example 2 with ConceptReferenceComponent

use of org.hl7.fhir.dstu2.model.ValueSet.ConceptReferenceComponent in project bunsen by cerner.

the class ValueSets method addToValueSet.

/**
 * Adds the given values to the given value set instance.
 */
private void addToValueSet(ValueSet valueSet, Dataset<Value> values) {
    ValueSetComposeComponent composeComponent = valueSet.getCompose();
    ConceptSetComponent currentInclusion = null;
    ConceptReferenceComponent concept = null;
    List<Value> sortedValues = values.sort("system", "version", "value").collectAsList();
    // Workaround for the decoder producing an immutable array by replacing it with a mutable one
    composeComponent.setInclude(new ArrayList<>(composeComponent.getInclude()));
    for (Value value : sortedValues) {
        if (currentInclusion == null || !value.getSystem().equals(currentInclusion.getSystem()) || !value.getVersion().equals(currentInclusion.getVersion())) {
            // Find a matching inclusion
            for (ConceptSetComponent candidate : composeComponent.getInclude()) {
                if (value.getSystem().equals(candidate.getSystem()) && value.getVersion().equals(candidate.getVersion())) {
                    currentInclusion = candidate;
                    // Workaround for the decoder producing an immutable array by replacing it with a
                    // mutable one
                    currentInclusion.setConcept(new ArrayList<>(currentInclusion.getConcept()));
                }
            }
            // No matching inclusion found, so add one
            if (currentInclusion == null) {
                currentInclusion = composeComponent.addInclude();
                currentInclusion.setSystem(value.getSystem());
                currentInclusion.setVersion(value.getVersion());
                concept = null;
            }
        }
        // Create concept if not exists
        if (concept == null || !value.getValue().equals(concept.getCode())) {
            concept = currentInclusion.addConcept();
            concept.setCode(value.getValue());
        }
    }
}
Also used : ConceptSetComponent(org.hl7.fhir.dstu3.model.ValueSet.ConceptSetComponent) ValueSetComposeComponent(org.hl7.fhir.dstu3.model.ValueSet.ValueSetComposeComponent) ConceptReferenceComponent(org.hl7.fhir.dstu3.model.ValueSet.ConceptReferenceComponent)

Example 3 with ConceptReferenceComponent

use of org.hl7.fhir.dstu2.model.ValueSet.ConceptReferenceComponent in project kindling by HL7.

the class PageProcessor method getSnomedCTConceptList.

private String getSnomedCTConceptList() throws Exception {
    Map<String, SnomedConceptUsage> concepts = new HashMap<String, SnomedConceptUsage>();
    for (ValueSet vs : definitions.getValuesets().getList()) {
        if (!vs.hasUrl() || !vs.getUrl().startsWith("http://terminology.hl7.org")) {
            for (ConceptSetComponent cc : vs.getCompose().getInclude()) if (cc.hasSystem() && cc.getSystem().equals("http://snomed.info/sct")) {
                for (ConceptReferenceComponent c : cc.getConcept()) {
                    String d = c.hasDisplay() ? c.getDisplay() : workerContext.getCodeDefinition("http://snomed.info/sct", c.getCode()).getDisplay();
                    if (concepts.containsKey(c.getCode()))
                        concepts.get(c.getCode()).update(d, vs);
                    else
                        concepts.put(c.getCode(), new SnomedConceptUsage(c.getCode(), d, vs));
                }
                for (ConceptSetFilterComponent c : cc.getFilter()) {
                    if ("concept".equals(c.getProperty())) {
                        getSnomedCTConcept(concepts, vs, c);
                    }
                }
            }
        }
    }
    List<String> sorts = new ArrayList<String>();
    for (String s : concepts.keySet()) sorts.add(s);
    Collections.sort(sorts);
    StringBuilder b = new StringBuilder();
    b.append("<table class=\"codes\">\r\n");
    b.append(" <tr><td><b>Code</b></td><td><b>Display</b></td><td>ValueSets</td></tr>\r\n");
    for (String s : sorts) {
        SnomedConceptUsage usage = concepts.get(s);
        b.append(" <tr>\r\n   <td>" + s + "</td>\r\n    <td>" + Utilities.escapeXml(usage.getDisplay()) + "</td>\r\n    <td>");
        boolean first = true;
        for (ValueSet vs : usage.getValueSets()) {
            if (first)
                first = false;
            else
                b.append("<br/>");
            String path = (String) vs.getUserData("path");
            b.append(" <a href=\"" + pathTail(Utilities.changeFileExt(path, ".html")) + "\">" + Utilities.escapeXml(vs.present()) + "</a>");
        }
        b.append("</td>\r\n  </tr>\r\n");
    }
    b.append("</table>\r\n");
    return b.toString();
}
Also used : ConceptSetComponent(org.hl7.fhir.r5.model.ValueSet.ConceptSetComponent) ConceptSetFilterComponent(org.hl7.fhir.r5.model.ValueSet.ConceptSetFilterComponent) CommaSeparatedStringBuilder(org.hl7.fhir.utilities.CommaSeparatedStringBuilder) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ValueSet(org.hl7.fhir.r5.model.ValueSet) ConceptReferenceComponent(org.hl7.fhir.r5.model.ValueSet.ConceptReferenceComponent)

Example 4 with ConceptReferenceComponent

use of org.hl7.fhir.dstu2.model.ValueSet.ConceptReferenceComponent in project kindling by HL7.

the class CodeListToValueSetParser method generateConceptMapV2.

private void generateConceptMapV2(String v2map, ValueSet vs, CodeSystem cs) throws Exception {
    ConceptMap cm = new ConceptMap();
    cm.setId("cm-" + vs.getId() + "-v2");
    cm.setVersion(version);
    cm.setUserData("path", cm.getId() + ".html");
    cm.setUserData("generate", true);
    cm.setUrl("http://hl7.org/fhir/ConceptMap/" + cm.getId());
    cm.setName("v2." + vs.getName());
    cm.setTitle("v2 map for " + vs.present());
    cm.setPublisher("HL7 (FHIR Project)");
    for (ContactDetail cc : vs.getContact()) {
        ContactDetail cd = cm.addContact();
        cd.setName(cc.getName());
        for (ContactPoint ccs : cc.getTelecom()) cd.addTelecom(ccs.copy());
    }
    cm.setCopyright(vs.getCopyright());
    // until we publish DSTU, then .review
    cm.setStatus(vs.getStatus());
    cm.setDate(vs.getDate());
    cm.setSource(Factory.newCanonical(vs.getUrl()));
    cm.setTarget(Factory.newCanonical(v2map));
    if (cs != null)
        processV2ConceptDefs(cm, cs.getUrl(), cs.getConcept());
    for (ConceptSetComponent cc : vs.getCompose().getInclude()) for (ConceptReferenceComponent c : cc.getConcept()) {
        processV2Map(cm, cc.getSystem(), c.getCode(), c.getUserString("v2"));
    }
    maps.see(cm, packageInfo);
}
Also used : ContactDetail(org.hl7.fhir.r5.model.ContactDetail) ContactPoint(org.hl7.fhir.r5.model.ContactPoint) ConceptSetComponent(org.hl7.fhir.r5.model.ValueSet.ConceptSetComponent) ConceptMap(org.hl7.fhir.r5.model.ConceptMap) ConceptReferenceComponent(org.hl7.fhir.r5.model.ValueSet.ConceptReferenceComponent)

Example 5 with ConceptReferenceComponent

use of org.hl7.fhir.dstu2.model.ValueSet.ConceptReferenceComponent in project quality-measure-and-cohort-service by Alvearie.

the class ValueSetUtil method createArtifact.

public static ValueSetArtifact createArtifact(InputStream is, Map<String, String> customCodeSystem) throws IOException {
    XSSFSheet informationSheet;
    try (XSSFWorkbook wb = new XSSFWorkbook(is)) {
        informationSheet = wb.getSheetAt(wb.getSheetIndex("Expansion List"));
    } catch (IllegalArgumentException e) {
        throw new RuntimeException("Spreadsheet is missing required sheet \"Expansion List\"", e);
    }
    ValueSet valueSet = new ValueSet();
    boolean inCodesSection = false;
    valueSet.setStatus(Enumerations.PublicationStatus.ACTIVE);
    HashMap<CodeSystemKey, List<ValueSet.ConceptReferenceComponent>> codeSystemToCodes = new HashMap<>();
    String url = "http://cts.nlm.nih.gov/fhir/ValueSet/";
    String identifier = null;
    for (Row currentRow : informationSheet) {
        String code = currentRow.getCell(0) == null ? "" : currentRow.getCell(0).getStringCellValue();
        if (!code.equals("") && currentRow.getCell(1) != null && !inCodesSection) {
            String value;
            switch(currentRow.getCell(1).getCellType()) {
                case NUMERIC:
                    value = Double.toString(currentRow.getCell(1).getNumericCellValue());
                    break;
                case STRING:
                    value = currentRow.getCell(1).getStringCellValue();
                    break;
                default:
                    throw new RuntimeException("Cell type does not match either String or Numeric for key " + code);
            }
            switch(currentRow.getCell(0).getStringCellValue().toLowerCase()) {
                case "value set name":
                    valueSet.setName(value);
                    valueSet.setTitle(value);
                    break;
                case "id":
                    valueSet.setId(value);
                    identifier = value;
                    break;
                case "oid":
                    if (valueSet.getId() == null) {
                        valueSet.setId(value);
                        identifier = value;
                    }
                    break;
                case "url":
                    // fallthrough
                    url = value.endsWith("/") ? value : value + "/";
                case "definition version":
                    valueSet.setVersion(value);
                    break;
                case "code":
                    inCodesSection = true;
                    break;
                default:
                    break;
            }
        } else if (inCodesSection) {
            String display = currentRow.getCell(1).getStringCellValue();
            String codeSystemEntry = currentRow.getCell(2).getStringCellValue();
            String codeSystemVersion = currentRow.getCell(3).getStringCellValue();
            String codeSystem;
            if (codeSystemEntry.startsWith("http://") || codeSystemEntry.startsWith("https://")) {
                codeSystem = codeSystemEntry;
            } else if (customCodeSystem != null && customCodeSystem.get(codeSystemEntry) != null) {
                codeSystem = customCodeSystem.get(codeSystemEntry);
            } else {
                codeSystem = CodeSystemLookup.getUrlFromName(codeSystemEntry);
            }
            if (codeSystem == null) {
                throw new IllegalArgumentException("Unmatched Code System! " + codeSystemEntry + " not found!");
            }
            ValueSet.ConceptReferenceComponent concept = new ValueSet.ConceptReferenceComponent();
            concept.setCode(code);
            concept.setDisplay(display);
            List<ValueSet.ConceptReferenceComponent> conceptsSoFar = codeSystemToCodes.computeIfAbsent(new CodeSystemKey(codeSystem, codeSystemVersion), x -> new ArrayList<>());
            conceptsSoFar.add(concept);
        }
    }
    if (identifier == null || identifier.equals("")) {
        throw new RuntimeException("There must be an Identifier specified! Please populate the ID field");
    }
    valueSet.setUrl(url + identifier);
    valueSet.setId(identifier);
    ValueSet.ValueSetComposeComponent compose = new ValueSet.ValueSetComposeComponent();
    for (Entry<CodeSystemKey, List<ConceptReferenceComponent>> singleInclude : codeSystemToCodes.entrySet()) {
        ValueSet.ConceptSetComponent component = new ValueSet.ConceptSetComponent();
        component.setSystem(singleInclude.getKey().getCodeSystem());
        component.setVersion(singleInclude.getKey().getCodeSystemVersion());
        component.setConcept(singleInclude.getValue());
        compose.addInclude(component);
    }
    valueSet.setCompose(compose);
    ValueSetArtifact artifact = new ValueSetArtifact();
    artifact.setName(valueSet.getName());
    artifact.setFhirResource(valueSet);
    artifact.setUrl(valueSet.getUrl());
    return artifact;
}
Also used : ConceptReferenceComponent(org.hl7.fhir.r4.model.ValueSet.ConceptReferenceComponent) Enumerations(org.hl7.fhir.r4.model.Enumerations) IOException(java.io.IOException) HashMap(java.util.HashMap) ValueSet(org.hl7.fhir.r4.model.ValueSet) MethodOutcome(ca.uhn.fhir.rest.api.MethodOutcome) InputStreamReader(java.io.InputStreamReader) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) XSSFWorkbook(org.apache.poi.xssf.usermodel.XSSFWorkbook) List(java.util.List) Map(java.util.Map) Entry(java.util.Map.Entry) XSSFSheet(org.apache.poi.xssf.usermodel.XSSFSheet) Row(org.apache.poi.ss.usermodel.Row) Bundle(org.hl7.fhir.r4.model.Bundle) BufferedReader(java.io.BufferedReader) IGenericClient(ca.uhn.fhir.rest.client.api.IGenericClient) InputStream(java.io.InputStream) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ConceptReferenceComponent(org.hl7.fhir.r4.model.ValueSet.ConceptReferenceComponent) XSSFSheet(org.apache.poi.xssf.usermodel.XSSFSheet) XSSFWorkbook(org.apache.poi.xssf.usermodel.XSSFWorkbook) ArrayList(java.util.ArrayList) List(java.util.List) ConceptReferenceComponent(org.hl7.fhir.r4.model.ValueSet.ConceptReferenceComponent) Row(org.apache.poi.ss.usermodel.Row) ValueSet(org.hl7.fhir.r4.model.ValueSet)

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)9 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 ConceptDefinitionComponent (org.hl7.fhir.r5.model.CodeSystem.ConceptDefinitionComponent)6 NotImplementedException (org.apache.commons.lang3.NotImplementedException)5 NoTerminologyServiceException (org.hl7.fhir.exceptions.NoTerminologyServiceException)5 ValueSet (org.hl7.fhir.r4.model.ValueSet)5 ConceptSetComponent (org.hl7.fhir.r4.model.ValueSet.ConceptSetComponent)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