Search in sources :

Example 1 with ConceptMapRelationship

use of org.hl7.fhir.r5.model.Enumerations.ConceptMapRelationship 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.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();
        ConceptMapRelationship rel = readRelationship(lexer);
        String tgts = 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.setRelationship(rel);
        lexer.token(":");
        tgt.setCode(lexer.take());
        if (tgt.getCode().startsWith("\""))
            tgt.setCode(lexer.processConstant(tgt.getCode()));
        tgt.setComment(lexer.getFirstComment());
    }
    lexer.token("}");
}
Also used : TargetElementComponent(org.hl7.fhir.r5.model.ConceptMap.TargetElementComponent) ConceptMapGroupComponent(org.hl7.fhir.r5.model.ConceptMap.ConceptMapGroupComponent) SourceElementComponent(org.hl7.fhir.r5.model.ConceptMap.SourceElementComponent) ConceptMapRelationship(org.hl7.fhir.r5.model.Enumerations.ConceptMapRelationship)

Aggregations

ConceptMapGroupComponent (org.hl7.fhir.r5.model.ConceptMap.ConceptMapGroupComponent)1 SourceElementComponent (org.hl7.fhir.r5.model.ConceptMap.SourceElementComponent)1 TargetElementComponent (org.hl7.fhir.r5.model.ConceptMap.TargetElementComponent)1 ConceptMapRelationship (org.hl7.fhir.r5.model.Enumerations.ConceptMapRelationship)1