Search in sources :

Example 1 with ConceptMapGroupComponent

use of org.hl7.fhir.r4b.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.r4b.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.r4b.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.r4b.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.r4b.model.ConceptMap.ConceptMapGroupComponent in project org.hl7.fhir.core by hapifhir.

the class ConceptMap10_50 method getGroup.

public static ConceptMapGroupComponent getGroup(ConceptMap map, String srcs, String tgts) {
    for (ConceptMapGroupComponent grp : map.getGroup()) {
        if (grp.getSource().equals(srcs) && grp.getTarget().equals(tgts))
            return grp;
    }
    ConceptMapGroupComponent grp = map.addGroup();
    grp.setSource(srcs);
    grp.setTarget(tgts);
    return grp;
}
Also used : ConceptMapGroupComponent(org.hl7.fhir.r5.model.ConceptMap.ConceptMapGroupComponent)

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