Search in sources :

Example 76 with ConceptMap

use of org.hl7.fhir.r4b.model.ConceptMap in project pathling by aehrc.

the class ConceptMapBuilder method build.

@Nonnull
public ConceptMap build() {
    final Map<Pair<VersionedSystem, VersionedSystem>, List<ConceptMapEntry>> mappingsBySystem = entries.stream().collect(Collectors.groupingBy(ConceptMapBuilder::getVersionedSystems));
    final ConceptMap result = new ConceptMap();
    result.setStatus(PublicationStatus.ACTIVE);
    mappingsBySystem.forEach((srcAndTarget, systemMappings) -> {
        final ConceptMapGroupComponent group = result.addGroup();
        group.setSource(srcAndTarget.getLeft().getSystem());
        group.setSourceVersion(srcAndTarget.getLeft().getVersion());
        group.setTarget(srcAndTarget.getRight().getSystem());
        group.setTargetVersion(srcAndTarget.getRight().getVersion());
        systemMappings.forEach(m -> {
            final SourceElementComponent sourceElement = group.addElement();
            sourceElement.setCode(m.getSource().getCode());
            final TargetElementComponent targetElement = sourceElement.addTarget();
            targetElement.setCode(m.getTarget().getCode());
            targetElement.setEquivalence(m.getEquivalence());
        });
    });
    return result;
}
Also used : TargetElementComponent(org.hl7.fhir.r4.model.ConceptMap.TargetElementComponent) ArrayList(java.util.ArrayList) List(java.util.List) ConceptMap(org.hl7.fhir.r4.model.ConceptMap) ConceptMapGroupComponent(org.hl7.fhir.r4.model.ConceptMap.ConceptMapGroupComponent) SourceElementComponent(org.hl7.fhir.r4.model.ConceptMap.SourceElementComponent) Pair(org.apache.commons.lang3.tuple.Pair) Nonnull(javax.annotation.Nonnull)

Example 77 with ConceptMap

use of org.hl7.fhir.r4b.model.ConceptMap in project MtbImporter by nr23730.

the class FhirResolver method resolveOncoTree.

/**
 * Converts an ICD-O-3 classification into an OncoTree coding.
 * @param topography ICD-O-3 topography code (first part)
 * @param morphology ICD-O-3 morpholoy code (second part)
 * @return FHIR coding for the corresponding OncoTree-Code.
 */
public static Coding resolveOncoTree(String topography, String morphology) {
    Parameters params = new Parameters();
    params.addParameter("system", new UriType(Settings.getFhir().getTerminology().getIcdO3Url()));
    params.addParameter("target", new UriType(Settings.getFhir().getTerminology().getOncoTreeUrl()));
    params.addParameter("conceptMap", new UriType(Settings.getFhir().getTerminology().getIcdO3ToOncoTreeConceptMapUrl()));
    params.addParameter("code", topography.split(" ")[0] + " " + morphology.split(" ")[0]);
    try {
        Parameters result = terminologyClient.operation().onInstance("ConceptMap/" + Settings.getFhir().getTerminology().getIcdO3ToOncoTreeConceptMapId()).named("translate").withParameters(params).execute();
        for (ParametersParameterComponent p : result.getParameter()) {
            if (!p.getName().equals("match")) {
                continue;
            }
            Coding coding = null;
            String str = null;
            for (ParametersParameterComponent c : p.getPart()) {
                if (c.getValue() instanceof Coding) {
                    coding = (Coding) c.getValue();
                }
                if (c.getValue() instanceof StringType && c.getName().equals("source")) {
                    str = ((StringType) c.getValue()).getValue();
                }
            }
            if (str != null && str.equals(Settings.getFhir().getTerminology().getIcdO3ToOncoTreeConceptMapUrl())) {
                return coding;
            }
        }
    } catch (FhirClientConnectionException e) {
        Logger.error("Could not connect to FHIR Terminology Server", e);
    }
    return new Coding();
}
Also used : Parameters(org.hl7.fhir.r4.model.Parameters) Coding(org.hl7.fhir.r4.model.Coding) StringType(org.hl7.fhir.r4.model.StringType) FhirClientConnectionException(ca.uhn.fhir.rest.client.exceptions.FhirClientConnectionException) UriType(org.hl7.fhir.r4.model.UriType) ParametersParameterComponent(org.hl7.fhir.r4.model.Parameters.ParametersParameterComponent)

Example 78 with ConceptMap

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

the class ConceptMapsTest method testWithMapsFromDirectoryJson.

@Test
public void testWithMapsFromDirectoryJson() {
    ConceptMaps maps = ConceptMaps.getEmpty(spark).withMapsFromDirectory("src/test/resources/json/conceptmaps");
    ConceptMap genderMap = maps.getConceptMap("urn:cerner:poprec:fhir:conceptmap:demographics:gender", "0.0.1");
    Assert.assertNotNull(genderMap);
    Assert.assertEquals("urn:cerner:poprec:fhir:conceptmap:demographics:gender", genderMap.getUrl());
    Assert.assertEquals("0.0.1", genderMap.getVersion());
}
Also used : ConceptMap(org.hl7.fhir.dstu3.model.ConceptMap) Test(org.junit.Test)

Example 79 with ConceptMap

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

the class ConceptMapsTest method testWithDisjointMapsFromDirectory.

@Test
public void testWithDisjointMapsFromDirectory() {
    String database = "test_conceptmaps_disjoint";
    spark.sql("CREATE DATABASE " + database);
    ConceptMaps.getEmpty(spark).withMapsFromDirectory("src/test/resources/xml/conceptmaps").writeToDatabase(database);
    ConceptMaps maps = ConceptMaps.getFromDatabase(spark, database).withDisjointMapsFromDirectory("src/test/resources/xml/conceptmaps", database);
    ConceptMap genderMap = maps.getConceptMap("urn:cerner:poprec:fhir:conceptmap:demographics:gender", "0.0.1");
    Assert.assertEquals(1, maps.getMaps().count());
    Assert.assertNotNull(genderMap);
    Assert.assertEquals("urn:cerner:poprec:fhir:conceptmap:demographics:gender", genderMap.getUrl());
    Assert.assertEquals("0.0.1", genderMap.getVersion());
}
Also used : ConceptMap(org.hl7.fhir.dstu3.model.ConceptMap) Test(org.junit.Test)

Example 80 with ConceptMap

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

the class ConceptMapsTest method testExpandMappings.

@Test
public void testExpandMappings() {
    ConceptMap conceptMap = ConceptMaps.getEmpty(spark).withConceptMaps(conceptMap("urn:cerner:conceptmap:map", "1")).getConceptMap("urn:cerner:conceptmap:map", "1");
    List<Mapping> mappings = ConceptMaps.expandMappings(conceptMap);
    Mapping expectedValue = new Mapping("urn:cerner:conceptmap:map", "1", "urn:source:valueset", "urn:target:valueset", "urn:source:system", "urn:source:code:a", "urn:target:system", "urn:target:code:1", Mapping.EQUIVALENT);
    Assert.assertEquals(1, mappings.size());
    Assert.assertEquals(expectedValue, mappings.get(0));
}
Also used : ConceptMap(org.hl7.fhir.dstu3.model.ConceptMap) Test(org.junit.Test)

Aggregations

ConceptMap (org.hl7.fhir.dstu3.model.ConceptMap)34 Test (org.junit.Test)31 ArrayList (java.util.ArrayList)29 HashMap (java.util.HashMap)27 FHIRException (org.hl7.fhir.exceptions.FHIRException)26 ConceptMap (org.hl7.fhir.r4.model.ConceptMap)23 XhtmlNode (org.hl7.fhir.utilities.xhtml.XhtmlNode)23 ConceptMap (org.hl7.fhir.r5.model.ConceptMap)22 ConceptMapGroupComponent (org.hl7.fhir.r5.model.ConceptMap.ConceptMapGroupComponent)17 ConceptMapGroupComponent (org.hl7.fhir.dstu3.model.ConceptMap.ConceptMapGroupComponent)15 HashSet (java.util.HashSet)13 ConceptMapGroupComponent (org.hl7.fhir.r4.model.ConceptMap.ConceptMapGroupComponent)13 StructureDefinition (org.hl7.fhir.r5.model.StructureDefinition)12 FileOutputStream (java.io.FileOutputStream)11 ValueSet (org.hl7.fhir.r5.model.ValueSet)11 SourceElementComponent (org.hl7.fhir.dstu3.model.ConceptMap.SourceElementComponent)10 Test (org.junit.jupiter.api.Test)10 ConceptMap (org.hl7.fhir.dstu2016may.model.ConceptMap)9 Coding (org.hl7.fhir.r4.model.Coding)9 SourceElementComponent (org.hl7.fhir.r4.model.ConceptMap.SourceElementComponent)9