Search in sources :

Example 6 with ConceptMapEquivalence

use of org.hl7.fhir.r4.model.Enumerations.ConceptMapEquivalence in project pathling by aehrc.

the class ClosureMappingTest method toRelationIgnoresUnknownEquivalenceTypes.

@Test
void toRelationIgnoresUnknownEquivalenceTypes() {
    final Collection<ConceptMapEquivalence> validRelations = new HashSet<>(Arrays.asList(ConceptMapEquivalence.SPECIALIZES, ConceptMapEquivalence.SUBSUMES, ConceptMapEquivalence.EQUAL, ConceptMapEquivalence.UNMATCHED));
    Stream.of(ConceptMapEquivalence.values()).filter(e -> !validRelations.contains(e)).forEach(e -> {
        final ConceptMap invalidMap = ConceptMapBuilder.empty().with(CODING_1_1_1, CODING_1_1_1, e).build();
        assertEquals(EMPTY_RELATION, ClosureMapping.relationFromConceptMap(invalidMap));
    });
}
Also used : ConceptMapEquivalence(org.hl7.fhir.r4.model.Enumerations.ConceptMapEquivalence) Arrays(java.util.Arrays) ConceptMap(org.hl7.fhir.r4.model.ConceptMap) Collection(java.util.Collection) ConceptMapBuilder(au.csiro.pathling.test.fixtures.ConceptMapBuilder) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test) Stream(java.util.stream.Stream) TerminologyHelpers.newVersionedCoding(au.csiro.pathling.test.helpers.TerminologyHelpers.newVersionedCoding) RelationBuilder(au.csiro.pathling.test.fixtures.RelationBuilder) Coding(org.hl7.fhir.r4.model.Coding) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) Tag(org.junit.jupiter.api.Tag) ConceptMapEquivalence(org.hl7.fhir.r4.model.Enumerations.ConceptMapEquivalence) ConceptMap(org.hl7.fhir.r4.model.ConceptMap) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test)

Example 7 with ConceptMapEquivalence

use of org.hl7.fhir.r4.model.Enumerations.ConceptMapEquivalence in project org.hl7.fhir.core by hapifhir.

the class StructureMapUtilities method parseConceptMap.

private void parseConceptMap(StructureMap result, FHIRLexer lexer) throws FHIRLexerException {
    lexer.token("conceptmap");
    ConceptMap map = new ConceptMap();
    String id = lexer.readConstant("map id");
    if (id.startsWith("#"))
        throw lexer.error("Concept Map identifier must start with #");
    map.setId(id);
    // todo: how to add this to the text format
    map.setStatus(PublicationStatus.DRAFT);
    result.getContained().add(map);
    lexer.token("{");
    lexer.skipComments();
    // lexer.token("source");
    // map.setSource(new UriType(lexer.readConstant("source")));
    // lexer.token("target");
    // map.setSource(new UriType(lexer.readConstant("target")));
    Map<String, String> prefixes = new HashMap<String, String>();
    while (lexer.hasToken("prefix")) {
        lexer.token("prefix");
        String n = lexer.take();
        lexer.token("=");
        String v = lexer.readConstant("prefix url");
        prefixes.put(n, v);
    }
    while (lexer.hasToken("unmapped")) {
        lexer.token("unmapped");
        lexer.token("for");
        String n = readPrefix(prefixes, lexer);
        ConceptMapGroupComponent g = getGroup(map, n, null);
        lexer.token("=");
        String v = lexer.take();
        if (v.equals("provided")) {
            g.getUnmapped().setMode(ConceptMapGroupUnmappedMode.PROVIDED);
        } else
            throw lexer.error("Only unmapped mode PROVIDED is supported at this time");
    }
    while (!lexer.hasToken("}")) {
        String srcs = readPrefix(prefixes, lexer);
        lexer.token(":");
        String sc = lexer.getCurrent().startsWith("\"") ? lexer.readConstant("code") : lexer.take();
        ConceptMapEquivalence eq = readEquivalence(lexer);
        String tgts = (eq != ConceptMapEquivalence.UNMATCHED) ? readPrefix(prefixes, lexer) : "";
        ConceptMapGroupComponent g = getGroup(map, srcs, tgts);
        SourceElementComponent e = g.addElement();
        e.setCode(sc);
        if (e.getCode().startsWith("\""))
            e.setCode(lexer.processConstant(e.getCode()));
        TargetElementComponent tgt = e.addTarget();
        tgt.setEquivalence(eq);
        if (tgt.getEquivalence() != ConceptMapEquivalence.UNMATCHED) {
            lexer.token(":");
            tgt.setCode(lexer.take());
            if (tgt.getCode().startsWith("\""))
                tgt.setCode(lexer.processConstant(tgt.getCode()));
        }
        if (lexer.hasComment())
            tgt.setComment(lexer.take().substring(2).trim());
    }
    lexer.token("}");
}
Also used : HashMap(java.util.HashMap) TargetElementComponent(org.hl7.fhir.r4.model.ConceptMap.TargetElementComponent) ConceptMapEquivalence(org.hl7.fhir.r4.model.Enumerations.ConceptMapEquivalence) ConceptMap(org.hl7.fhir.r4.model.ConceptMap) ConceptMapGroupComponent(org.hl7.fhir.r4.model.ConceptMap.ConceptMapGroupComponent) SourceElementComponent(org.hl7.fhir.r4.model.ConceptMap.SourceElementComponent)

Aggregations

ConceptMapEquivalence (org.hl7.fhir.r4.model.Enumerations.ConceptMapEquivalence)5 ElementDefinition (au.csiro.pathling.fhirpath.element.ElementDefinition)3 ParserContext (au.csiro.pathling.fhirpath.parser.ParserContext)3 ConceptTranslator (au.csiro.pathling.terminology.ConceptTranslator)3 Row (org.apache.spark.sql.Row)3 Test (org.junit.jupiter.api.Test)3 FhirPath (au.csiro.pathling.fhirpath.FhirPath)2 ElementPath (au.csiro.pathling.fhirpath.element.ElementPath)2 SimpleCoding (au.csiro.pathling.fhirpath.encoding.SimpleCoding)2 NamedFunctionInput (au.csiro.pathling.fhirpath.function.NamedFunctionInput)2 StringLiteralPath (au.csiro.pathling.fhirpath.literal.StringLiteralPath)2 DatasetBuilder (au.csiro.pathling.test.builders.DatasetBuilder)2 ElementPathBuilder (au.csiro.pathling.test.builders.ElementPathBuilder)2 ParserContextBuilder (au.csiro.pathling.test.builders.ParserContextBuilder)2 HashMap (java.util.HashMap)2 ConceptMap (org.hl7.fhir.r4.model.ConceptMap)2 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)2 TerminologyServiceFactory (au.csiro.pathling.fhir.TerminologyServiceFactory)1 CodingPath (au.csiro.pathling.fhirpath.element.CodingPath)1 SimpleCodingsDecoders (au.csiro.pathling.fhirpath.encoding.SimpleCodingsDecoders)1