Search in sources :

Example 36 with ConceptReferenceComponent

use of org.hl7.fhir.r4.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) Value(com.cerner.bunsen.spark.codes.Value) ArrayList(java.util.ArrayList) ValueSetComposeComponent(org.hl7.fhir.dstu3.model.ValueSet.ValueSetComposeComponent) ConceptReferenceComponent(org.hl7.fhir.dstu3.model.ValueSet.ConceptReferenceComponent)

Example 37 with ConceptReferenceComponent

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

the class ValueSets method addToValueSet.

@Override
protected 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.r4.model.ValueSet.ConceptSetComponent) Value(com.cerner.bunsen.codes.Value) ValueSetComposeComponent(org.hl7.fhir.r4.model.ValueSet.ValueSetComposeComponent) ConceptReferenceComponent(org.hl7.fhir.r4.model.ValueSet.ConceptReferenceComponent)

Example 38 with ConceptReferenceComponent

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

the class FHIRHelper method convertToECL.

public String convertToECL(ConceptSetComponent setDefn) throws FHIROperationException {
    String ecl = "";
    boolean firstItem = true;
    for (ConceptReferenceComponent concept : setDefn.getConcept()) {
        if (firstItem) {
            firstItem = false;
        } else {
            ecl += " OR ";
        }
        ecl += concept.getCode() + "|" + concept.getDisplay() + "|";
    }
    ecl += convertFilterToECL(setDefn, firstItem);
    return ecl;
}
Also used : ConceptReferenceComponent(org.hl7.fhir.r4.model.ValueSet.ConceptReferenceComponent)

Example 39 with ConceptReferenceComponent

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

the class R4FileSystemFhirTerminologyProvider method loadFromFile.

/**
 * Loads ValueSet definitions from the filesystem or S3 compatible location
 * ValueSet definitions are expected to be stored in FHIR xml or JSON format
 * named using the valueSet id (ie 2.16.840.1.113762.1.4.1114.7.json)
 *
 * @param valueSetInfo contains information for teh VlaueSet we want to load
 */
protected void loadFromFile(ValueSetInfo valueSetInfo) throws RuntimeException {
    LOG.debug("Entry: loadFromFile() ValueSet.getId=[{}] version=[{}]", valueSetInfo.getId(), valueSetInfo.getVersion());
    VersionedIdentifier valueSetIdentifier = createVersionedIdentifierForValueSet(valueSetInfo);
    String valueSetId = valueSetIdentifier.getId();
    // get the valueSet codes from the cache if it is there
    Map<String, Set<String>> codesToCodeSystems = valueSetToCodesCache.get(valueSetIdentifier);
    List<Code> codeList = valueSetCodeCache.get(valueSetIdentifier);
    if (codesToCodeSystems == null || codeList == null) {
        LOG.debug("loadFromFile() valueSetId={} not found in cache, attempting to load from file", valueSetId);
        FileStatus[] valueSetFiles;
        FileSystem fileSystem;
        // List the files in the terminology directory that end in xml or json
        try {
            fileSystem = terminologyDirectory.getFileSystem(configuration);
            valueSetFiles = fileSystem.listStatus(terminologyDirectory, new PathFilter() {

                @Override
                public boolean accept(Path path) {
                    return path.getName().equalsIgnoreCase(valueSetId + ".json") || path.getName().equalsIgnoreCase(valueSetId + ".xml");
                }
            });
        } catch (ConfigurationException | DataFormatException | IOException e) {
            LOG.error("Error attempting to get ValueSet file for ValueSet [" + valueSetId + " from " + terminologyDirectory.toString(), e);
            throw new RuntimeException("Error attempting to get ValueSet file for ValueSet [" + valueSetId + " from " + terminologyDirectory.toString(), e);
        }
        if (valueSetFiles.length == 0) {
            LOG.error("No valueSet file " + valueSetId + ".json or " + valueSetId + ".xml found in terminology directory " + terminologyDirectory.toString());
            throw new RuntimeException("No valueSet file " + valueSetId + ".json or " + valueSetId + ".xml found in terminology directory " + terminologyDirectory.toString());
        } else {
            if (valueSetFiles.length > 1) {
                LOG.warn("Multiple ValueSet files found for ValueSet {} in terminology directory {}. File {} will be used.", valueSetId, terminologyDirectory.toString(), valueSetFiles[0].toString());
            }
            ValueSet valueSetFhirR4 = null;
            try {
                // Use the fhir parsers to convert file contents back into ValueSet fhir object
                if (valueSetFiles[0].getPath().getName().toLowerCase().endsWith(".xml")) {
                    valueSetFhirR4 = (ValueSet) fhirContext.newXmlParser().parseResource(new InputStreamReader(fileSystem.open(valueSetFiles[0].getPath())));
                    LOG.info("Unmarshalled xml {}", valueSetFhirR4.getId());
                } else if (valueSetFiles[0].getPath().getName().toLowerCase().endsWith(".json")) {
                    valueSetFhirR4 = (ValueSet) fhirContext.newJsonParser().parseResource(new InputStreamReader(fileSystem.open(valueSetFiles[0].getPath())));
                    LOG.info("Unmarshalled json {}", valueSetFhirR4.getId());
                }
                // This improves performance for the in() method for code lookup in large valuesets
                codesToCodeSystems = new HashMap<String, Set<String>>();
                // cache the list of code objects for the expand method
                codeList = new ArrayList<Code>();
                for (ConceptSetComponent csc : valueSetFhirR4.getCompose().getInclude()) {
                    for (ConceptReferenceComponent cfc : csc.getConcept()) {
                        codeList.add(new Code().withCode(cfc.getCode()).withDisplay(cfc.getDisplay()).withSystem(csc.getSystem()).withVersion(csc.getVersion()));
                        Set<String> codeSystems = codesToCodeSystems.get(cfc.getCode());
                        if (codeSystems == null) {
                            codeSystems = new HashSet<String>();
                            codesToCodeSystems.put(cfc.getCode(), codeSystems);
                        }
                        codeSystems.add(csc.getSystem());
                    }
                }
                valueSetToCodesCache.put(valueSetIdentifier, codesToCodeSystems);
                valueSetCodeCache.put(valueSetIdentifier, codeList);
            } catch (ConfigurationException | DataFormatException | IOException e) {
                LOG.error("Error attempting to deserialize ValueSet " + valueSetFiles[0].getPath().toString(), e);
                throw new RuntimeException("Error attempting to deserialize ValueSet " + valueSetFiles[0].getPath().toString(), e);
            }
        }
    }
    LOG.debug("Exit: loadFromFile() ValueSet.getId=[{}] version=[{}]", valueSetInfo.getId(), valueSetInfo.getVersion());
}
Also used : Path(org.apache.hadoop.fs.Path) PathFilter(org.apache.hadoop.fs.PathFilter) ValueSet(org.hl7.fhir.r4.model.ValueSet) HashSet(java.util.HashSet) Set(java.util.Set) FileStatus(org.apache.hadoop.fs.FileStatus) InputStreamReader(java.io.InputStreamReader) IOException(java.io.IOException) Code(org.opencds.cqf.cql.engine.runtime.Code) ConceptReferenceComponent(org.hl7.fhir.r4.model.ValueSet.ConceptReferenceComponent) ConceptSetComponent(org.hl7.fhir.r4.model.ValueSet.ConceptSetComponent) VersionedIdentifier(org.cqframework.cql.elm.execution.VersionedIdentifier) DataFormatException(ca.uhn.fhir.parser.DataFormatException) ConfigurationException(ca.uhn.fhir.context.ConfigurationException) FileSystem(org.apache.hadoop.fs.FileSystem) ValueSet(org.hl7.fhir.r4.model.ValueSet)

Example 40 with ConceptReferenceComponent

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

the class CodeListToValueSetParser method generateConceptMapV3.

private void generateConceptMapV3(String v3map, ValueSet vs, CodeSystem cs) throws Exception {
    if (!v3map.startsWith("http://terminology.hl7.org/ValueSet/v3-"))
        v3map = "http://terminology.hl7.org/ValueSet/v3-" + v3map;
    ConceptMap cm = new ConceptMap();
    cm.setVersion(version);
    cm.setId("cm-" + vs.getId() + "-v3");
    cm.setUserData("path", cm.getId() + ".html");
    cm.setUserData("generate", true);
    cm.setUrl("http://hl7.org/fhir/ConceptMap/" + cm.getId());
    cm.setName("v3." + vs.getName());
    cm.setTitle("v3 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(v3map));
    if (cs != null)
        processV3ConceptDefs(cm, cs.getUrl(), cs.getConcept());
    for (ConceptSetComponent cc : vs.getCompose().getInclude()) for (ConceptReferenceComponent c : cc.getConcept()) {
        processV3Map(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)

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