Search in sources :

Example 71 with ConceptMap

use of org.hl7.fhir.r4b.model.ConceptMap in project org.hl7.fhir.core by hapifhir.

the class DataRenderer method isCanonical.

private boolean isCanonical(String path) {
    if (!path.endsWith(".url"))
        return false;
    String t = path.substring(0, path.length() - 4);
    StructureDefinition sd = getContext().getWorker().fetchTypeDefinition(t);
    if (sd == null)
        return false;
    if (Utilities.existsInList(t, VersionUtilities.getCanonicalResourceNames(getContext().getWorker().getVersion()))) {
        return true;
    }
    if (Utilities.existsInList(t, "ActivityDefinition", "CapabilityStatement", "CapabilityStatement2", "ChargeItemDefinition", "Citation", "CodeSystem", "CompartmentDefinition", "ConceptMap", "ConditionDefinition", "EventDefinition", "Evidence", "EvidenceReport", "EvidenceVariable", "ExampleScenario", "GraphDefinition", "ImplementationGuide", "Library", "Measure", "MessageDefinition", "NamingSystem", "PlanDefinition"))
        return true;
    return sd.getBaseDefinitionElement().hasExtension("http://hl7.org/fhir/StructureDefinition/structuredefinition-codegen-super");
}
Also used : StructureDefinition(org.hl7.fhir.r5.model.StructureDefinition)

Example 72 with ConceptMap

use of org.hl7.fhir.r4b.model.ConceptMap in project org.hl7.fhir.core by hapifhir.

the class StructureMapUtilities method getGroup.

private ConceptMapGroupComponent getGroup(ConceptMap map, String srcs, String tgts) {
    for (ConceptMapGroupComponent grp : map.getGroup()) {
        if (grp.getSource().equals(srcs))
            if (!grp.hasTarget() || tgts == null || tgts.equals(grp.getTarget())) {
                if (!grp.hasTarget() && tgts != null)
                    grp.setTarget(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)

Example 73 with ConceptMap

use of org.hl7.fhir.r4b.model.ConceptMap in project org.hl7.fhir.core by hapifhir.

the class StructureMapUtilities method translate.

public Base translate(TransformContext context, StructureMap map, Base source, String conceptMapUrl, String fieldToReturn) throws FHIRException {
    Coding src = new Coding();
    if (source.isPrimitive()) {
        src.setCode(source.primitiveValue());
    } else if ("Coding".equals(source.fhirType())) {
        Base[] b = source.getProperty("system".hashCode(), "system", true);
        if (b.length == 1)
            src.setSystem(b[0].primitiveValue());
        b = source.getProperty("code".hashCode(), "code", true);
        if (b.length == 1)
            src.setCode(b[0].primitiveValue());
    } else if ("CE".equals(source.fhirType())) {
        Base[] b = source.getProperty("codeSystem".hashCode(), "codeSystem", true);
        if (b.length == 1)
            src.setSystem(b[0].primitiveValue());
        b = source.getProperty("code".hashCode(), "code", true);
        if (b.length == 1)
            src.setCode(b[0].primitiveValue());
    } else
        throw new FHIRException("Unable to translate source " + source.fhirType());
    String su = conceptMapUrl;
    if (conceptMapUrl.equals("http://hl7.org/fhir/ConceptMap/special-oid2uri")) {
        String uri = worker.oid2Uri(src.getCode());
        if (uri == null)
            uri = "urn:oid:" + src.getCode();
        if ("uri".equals(fieldToReturn))
            return new UriType(uri);
        else
            throw new FHIRException("Error in return code");
    } else {
        ConceptMap cmap = null;
        if (conceptMapUrl.startsWith("#")) {
            for (Resource r : map.getContained()) {
                if (r instanceof ConceptMap && r.getId().equals(conceptMapUrl.substring(1))) {
                    cmap = (ConceptMap) r;
                    su = map.getUrl() + "#" + conceptMapUrl;
                }
            }
            if (cmap == null)
                throw new FHIRException("Unable to translate - cannot find map " + conceptMapUrl);
        } else {
            if (conceptMapUrl.contains("#")) {
                String[] p = conceptMapUrl.split("\\#");
                StructureMap mapU = worker.fetchResource(StructureMap.class, p[0]);
                for (Resource r : mapU.getContained()) {
                    if (r instanceof ConceptMap && r.getId().equals(p[1])) {
                        cmap = (ConceptMap) r;
                        su = conceptMapUrl;
                    }
                }
            }
            if (cmap == null)
                cmap = worker.fetchResource(ConceptMap.class, conceptMapUrl);
        }
        Coding outcome = null;
        boolean done = false;
        String message = null;
        if (cmap == null) {
            if (services == null)
                message = "No map found for " + conceptMapUrl;
            else {
                outcome = services.translate(context.getAppInfo(), src, conceptMapUrl);
                done = true;
            }
        } else {
            List<SourceElementComponentWrapper> list = new ArrayList<SourceElementComponentWrapper>();
            for (ConceptMapGroupComponent g : cmap.getGroup()) {
                for (SourceElementComponent e : g.getElement()) {
                    if (!src.hasSystem() && src.getCode().equals(e.getCode()))
                        list.add(new SourceElementComponentWrapper(g, e));
                    else if (src.hasSystem() && src.getSystem().equals(g.getSource()) && src.getCode().equals(e.getCode()))
                        list.add(new SourceElementComponentWrapper(g, e));
                }
            }
            if (list.size() == 0)
                done = true;
            else if (list.get(0).getComp().getTarget().size() == 0)
                message = "Concept map " + su + " found no translation for " + src.getCode();
            else {
                for (TargetElementComponent tgt : list.get(0).getComp().getTarget()) {
                    if (tgt.getRelationship() == null || EnumSet.of(ConceptMapRelationship.RELATEDTO, ConceptMapRelationship.EQUIVALENT, ConceptMapRelationship.SOURCEISNARROWERTHANTARGET).contains(tgt.getRelationship())) {
                        if (done) {
                            message = "Concept map " + su + " found multiple matches for " + src.getCode();
                            done = false;
                        } else {
                            done = true;
                            outcome = new Coding().setCode(tgt.getCode()).setSystem(list.get(0).getGroup().getTarget());
                        }
                    }
                }
                if (!done)
                    message = "Concept map " + su + " found no usable translation for " + src.getCode();
            }
        }
        if (!done)
            throw new FHIRException(message);
        if (outcome == null)
            return null;
        if ("code".equals(fieldToReturn))
            return new CodeType(outcome.getCode());
        else
            return outcome;
    }
}
Also used : FHIRException(org.hl7.fhir.exceptions.FHIRException) StructureMap(org.hl7.fhir.r5.model.StructureMap) TargetElementComponent(org.hl7.fhir.r5.model.ConceptMap.TargetElementComponent) ConceptMapGroupComponent(org.hl7.fhir.r5.model.ConceptMap.ConceptMapGroupComponent) SourceElementComponent(org.hl7.fhir.r5.model.ConceptMap.SourceElementComponent)

Example 74 with ConceptMap

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

the class DefaultTerminologyServiceTest method testSubsumesFiltersIllegalAndUnknownCodings.

@Test
@SuppressWarnings("ConstantConditions")
void testSubsumesFiltersIllegalAndUnknownCodings() {
    // CODING1 subsumes CODING2
    final ConceptMap responseMap = ConceptMapBuilder.empty().withSubsumes(CODING2_VERSION1.toCoding(), CODING1_VERSION1.toCoding()).build();
    when(terminologyClient.closure(any(), any())).thenReturn(responseMap);
    // setup SYSTEM1 as known system
    when(terminologyClient.searchCodeSystems(refEq(new UriParam(SYSTEM1)), any())).thenReturn(Collections.singletonList(new CodeSystem()));
    final Relation actualRelation = terminologyService.getSubsumesRelation(Arrays.asList(CODING1_VERSION1, CODING1_UNVERSIONED, CODING2_VERSION1, CODING3_VERSION1, new SimpleCoding(SYSTEM1, null), new SimpleCoding(null, "code1"), new SimpleCoding(null, null), null));
    final Relation expectedRelation = RelationBuilder.empty().add(CODING1_VERSION1.toCoding(), CODING2_VERSION1.toCoding()).build();
    assertEquals(expectedRelation, actualRelation);
    // verify behaviour
    verify(terminologyClient).searchCodeSystems(refEq(new UriParam(SYSTEM1)), any());
    verify(terminologyClient).searchCodeSystems(refEq(new UriParam(SYSTEM2)), any());
    verify(terminologyClient).initialiseClosure(deepEq(new StringType(TEST_UUID_AS_STRING)));
    verify(terminologyClient).closure(deepEq(new StringType(TEST_UUID_AS_STRING)), argThat(new CodingSetMatcher(Arrays.asList(CODING1_VERSION1, CODING1_UNVERSIONED, CODING2_VERSION1))));
    verifyNoMoreInteractions(terminologyClient);
}
Also used : SimpleCoding(au.csiro.pathling.fhirpath.encoding.SimpleCoding) StringType(org.hl7.fhir.r4.model.StringType) ConceptMap(org.hl7.fhir.r4.model.ConceptMap) UriParam(ca.uhn.fhir.rest.param.UriParam) CodeSystem(org.hl7.fhir.r4.model.CodeSystem) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 75 with ConceptMap

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

the class TranslateMappingTest method throwsErrorIfAnyEntryHasError.

@Test
void throwsErrorIfAnyEntryHasError() {
    final Bundle responseBundle = (Bundle) jsonParser.parseResource(getResourceAsStream("txResponses/TranslateMappingTest/responseWith404.Bundle.json"));
    // Response bundle has 2 entries
    final ResourceNotFoundException error = assertThrows(ResourceNotFoundException.class, () -> TranslateMapping.fromResponseBundle(responseBundle, Arrays.asList(SIMPLE_CODING_1, SIMPLE_CODING_2), Collections.emptyList(), fhirContext));
    assertEquals("Error in response entry : HTTP 404 : [ed835929-8734-4a4a-b4ed-8614f2d46321]: Unable to find ConceptMap with URI http://snomed.info/sct?fhir_cm=xxxx", error.getMessage());
}
Also used : Bundle(org.hl7.fhir.r4.model.Bundle) ResourceNotFoundException(ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException) Test(org.junit.jupiter.api.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