Search in sources :

Example 1 with ConceptMapGroupComponent

use of org.hl7.fhir.r5.model.ConceptMap.ConceptMapGroupComponent in project bunsen by cerner.

the class ConceptMaps method expandMappingsIterator.

private static Iterator<Mapping> expandMappingsIterator(ConceptMap map) {
    List<Mapping> mappings = new ArrayList<>();
    for (ConceptMapGroupComponent group : map.getGroup()) {
        for (SourceElementComponent element : group.getElement()) {
            for (TargetElementComponent target : element.getTarget()) {
                Mapping mapping = new Mapping();
                mapping.setConceptMapUri(map.getUrl());
                mapping.setConceptMapVersion(map.getVersion());
                try {
                    String sourceValue = map.getSource() instanceof UriType ? map.getSourceUriType().getValue() : map.getSourceReference().getReference();
                    mapping.setSourceValueSet(sourceValue);
                    String targetValue = map.getTarget() instanceof UriType ? map.getTargetUriType().getValue() : map.getTargetReference().getReference();
                    mapping.setTargetValueSet(targetValue);
                } catch (FHIRException fhirException) {
                    // an exception.
                    throw new RuntimeException(fhirException);
                }
                mapping.setSourceSystem(group.getSource());
                mapping.setSourceValue(element.getCode());
                mapping.setTargetSystem(group.getTarget());
                mapping.setTargetValue(target.getCode());
                if (target.getEquivalence() != null) {
                    mapping.setEquivalence(target.getEquivalence().toCode());
                }
                mappings.add(mapping);
            }
        }
    }
    return mappings.iterator();
}
Also used : ArrayList(java.util.ArrayList) TargetElementComponent(org.hl7.fhir.dstu3.model.ConceptMap.TargetElementComponent) FHIRException(org.hl7.fhir.exceptions.FHIRException) ConceptMapGroupComponent(org.hl7.fhir.dstu3.model.ConceptMap.ConceptMapGroupComponent) SourceElementComponent(org.hl7.fhir.dstu3.model.ConceptMap.SourceElementComponent) UriType(org.hl7.fhir.dstu3.model.UriType)

Example 2 with ConceptMapGroupComponent

use of org.hl7.fhir.r5.model.ConceptMap.ConceptMapGroupComponent in project bunsen by cerner.

the class BroadcastableMappingsTest method setUp.

/**
 * Sets up Spark and concept maps for testing.
 */
@BeforeClass
public static void setUp() {
    spark = SparkSession.builder().master("local[2]").appName("BroadcastableMappingsTest").getOrCreate();
    ConceptMap conceptMap = new ConceptMap();
    conceptMap.setUrl("uri:test:concept:map").setVersion("0").setSource(new UriType("uri:test:source:valueset")).setTarget(new UriType("uri:test:target:valueset"));
    ConceptMapGroupComponent group = conceptMap.addGroup().setSource("uri:test:source:system").setTarget("uri:test:target:system");
    group.addElement().setCode("abc").addTarget().setCode("123");
    group.addElement().setCode("def").addTarget().setCode("456");
    ConceptMap delegatingMap = new ConceptMap();
    delegatingMap.setUrl("uri:test:concept:delegating").setVersion("0").setSource(new UriType("uri:test:source:valueset")).setTarget(new UriType("uri:test:target:valueset"));
    delegatingMap.addGroup().setSource("uri:test:source:system").setTarget("uri:test:target:system").setUnmapped(new ConceptMapGroupUnmappedComponent().setMode(ConceptMapGroupUnmappedMode.OTHERMAP).setUrl("uri:test:concept:map"));
    broadcast = BroadcastableMappings.broadcast(spark, ImmutableList.of(conceptMap, delegatingMap));
}
Also used : ConceptMapGroupUnmappedComponent(org.hl7.fhir.dstu3.model.ConceptMap.ConceptMapGroupUnmappedComponent) ConceptMap(org.hl7.fhir.dstu3.model.ConceptMap) ConceptMapGroupComponent(org.hl7.fhir.dstu3.model.ConceptMap.ConceptMapGroupComponent) UriType(org.hl7.fhir.dstu3.model.UriType) BeforeClass(org.junit.BeforeClass)

Example 3 with ConceptMapGroupComponent

use of org.hl7.fhir.r5.model.ConceptMap.ConceptMapGroupComponent in project kindling by HL7.

the class PageProcessor method parseConceptMapMapping.

private ConceptMap parseConceptMapMapping(ElementDefn logical, ElementDefinition resource, String src) throws FHIRException {
    if (!src.startsWith("{map:"))
        return null;
    ConceptMap map = new ConceptMap();
    map.setId(logical.getPath() + "2" + resource.getPath());
    map.setUrl("http://hl7.org/fhir/ConceptMap/" + map.getId());
    map.setVersion(version.toCode());
    ConceptMapGroupComponent grp = map.addGroup();
    String[] statements = src.substring(0, src.length() - 1).substring(5).split("\\;");
    if (statements.length == 0)
        throw new FHIRException("Unable to parse map details '" + src + "'");
    for (String s : statements) {
        String[] p = s.split("\\=");
        if (p.length < 2)
            throw new FHIRException("Unable to parse map details '" + src + "'");
        if (":default".equals(p[0].trim())) {
            grp.getUnmapped().setMode(ConceptMapGroupUnmappedMode.FIXED);
            grp.getUnmapped().setCode(p[1].trim());
        } else {
            grp.addElement().setCode(p[0].trim()).addTarget().setRelationship(ConceptMapRelationship.EQUIVALENT).setCode(p[1].trim());
        }
    }
    return map;
}
Also used : ConceptMap(org.hl7.fhir.r5.model.ConceptMap) FHIRException(org.hl7.fhir.exceptions.FHIRException) ConceptMapGroupComponent(org.hl7.fhir.r5.model.ConceptMap.ConceptMapGroupComponent)

Example 4 with ConceptMapGroupComponent

use of org.hl7.fhir.r5.model.ConceptMap.ConceptMapGroupComponent in project kindling by HL7.

the class ResourceNameConceptMapGenerator method elementForCode.

private static SourceElementComponent elementForCode(ConceptMapGroupComponent grp, String s) {
    for (SourceElementComponent t : grp.getElement()) if (t.getCode().equals(s))
        return t;
    SourceElementComponent t = grp.addElement();
    t.setCode(s);
    return t;
}
Also used : SourceElementComponent(org.hl7.fhir.r5.model.ConceptMap.SourceElementComponent)

Example 5 with ConceptMapGroupComponent

use of org.hl7.fhir.r5.model.ConceptMap.ConceptMapGroupComponent in project bunsen by cerner.

the class ConceptMaps method addToConceptMap.

@Override
protected void addToConceptMap(ConceptMap map, Dataset<Mapping> mappings) {
    // Sort the items so they are grouped together optimally, and so
    // we consistently produce the same ordering, therefore making
    // inspection and comparison of the concept maps easier.
    List<Mapping> sortedMappings = mappings.sort("sourceSystem", "targetSystem", "sourceValue", "targetValue").collectAsList();
    ConceptMapGroupComponent currentGroup = null;
    SourceElementComponent element = null;
    // Workaround for the decoder producing an immutable array by
    // replacing it with a mutable one.
    map.setGroup(new ArrayList<>(map.getGroup()));
    for (Mapping mapping : sortedMappings) {
        // Add a new group if we don't match the previous one.
        if (currentGroup == null || !mapping.getSourceSystem().equals(currentGroup.getSource()) || !mapping.getTargetSystem().equals(currentGroup.getTarget())) {
            currentGroup = null;
            // Find a matching group.
            for (ConceptMapGroupComponent candidate : map.getGroup()) {
                if (mapping.getSourceSystem().equals(candidate.getSource()) && mapping.getTargetSystem().equals(candidate.getTarget())) {
                    currentGroup = candidate;
                    // Workaround for the decoder producing an immutable array by
                    // replacing it with a mutable one.
                    currentGroup.setElement(new ArrayList<>(currentGroup.getElement()));
                    break;
                }
            }
            // No matching group found, so add it.
            if (currentGroup == null) {
                currentGroup = map.addGroup();
                currentGroup.setSource(mapping.getSourceSystem());
                currentGroup.setTarget(mapping.getTargetSystem());
                // Ensure a new element is created for the newly created group.
                element = null;
            }
        }
        // so add one if it does not match the previous.
        if (element == null || !mapping.getSourceValue().equals(element.getCode())) {
            element = currentGroup.addElement();
            element.setCode(mapping.getSourceValue());
        }
        element.addTarget().setCode(mapping.getTargetValue());
    }
}
Also used : Mapping(com.cerner.bunsen.spark.codes.Mapping) ConceptMapGroupComponent(org.hl7.fhir.dstu3.model.ConceptMap.ConceptMapGroupComponent) SourceElementComponent(org.hl7.fhir.dstu3.model.ConceptMap.SourceElementComponent)

Aggregations

ConceptMapGroupComponent (org.hl7.fhir.r5.model.ConceptMap.ConceptMapGroupComponent)17 ConceptMapGroupComponent (org.hl7.fhir.dstu3.model.ConceptMap.ConceptMapGroupComponent)14 SourceElementComponent (org.hl7.fhir.r5.model.ConceptMap.SourceElementComponent)13 ConceptMapGroupComponent (org.hl7.fhir.r4.model.ConceptMap.ConceptMapGroupComponent)12 FHIRException (org.hl7.fhir.exceptions.FHIRException)11 SourceElementComponent (org.hl7.fhir.dstu3.model.ConceptMap.SourceElementComponent)9 TargetElementComponent (org.hl7.fhir.r5.model.ConceptMap.TargetElementComponent)9 SourceElementComponent (org.hl7.fhir.r4.model.ConceptMap.SourceElementComponent)8 ConceptMapGroupComponent (org.hl7.fhir.r4b.model.ConceptMap.ConceptMapGroupComponent)8 HashMap (java.util.HashMap)7 SourceElementComponent (org.hl7.fhir.r4b.model.ConceptMap.SourceElementComponent)7 ArrayList (java.util.ArrayList)6 TargetElementComponent (org.hl7.fhir.dstu3.model.ConceptMap.TargetElementComponent)6 TargetElementComponent (org.hl7.fhir.r4.model.ConceptMap.TargetElementComponent)6 TargetElementComponent (org.hl7.fhir.r4b.model.ConceptMap.TargetElementComponent)6 UriType (org.hl7.fhir.dstu3.model.UriType)5 ConceptMap (org.hl7.fhir.dstu3.model.ConceptMap)4 ConceptMap (org.hl7.fhir.r4.model.ConceptMap)4 FileOutputStream (java.io.FileOutputStream)3 HashSet (java.util.HashSet)3