Search in sources :

Example 46 with ConceptMapGroupComponent

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

the class ConceptMapSpreadsheetGenerator method renderConceptMap.

public ConceptMapSpreadsheetGenerator renderConceptMap(ConceptMap cm) {
    addConceptMapMetadata(renderCanonicalResource(cm), cm);
    int i = 0;
    for (ConceptMapGroupComponent grp : cm.getGroup()) {
        renderGroup(grp, i);
        i++;
    }
    return this;
}
Also used : ConceptMapGroupComponent(org.hl7.fhir.r4b.model.ConceptMap.ConceptMapGroupComponent)

Example 47 with ConceptMapGroupComponent

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

the class ConceptMapEngine method translateByJustCode.

private Coding translateByJustCode(ConceptMap cm, String code) throws FHIRException {
    SourceElementComponent ct = null;
    ConceptMapGroupComponent cg = null;
    for (ConceptMapGroupComponent g : cm.getGroup()) {
        for (SourceElementComponent e : g.getElement()) {
            if (code.equals(e.getCode())) {
                if (e != null)
                    throw new FHIRException("Unable to process translate " + code + " because multiple candidate matches were found in concept map " + cm.getUrl());
                ct = e;
                cg = g;
            }
        }
    }
    if (ct == null)
        return null;
    TargetElementComponent tt = null;
    for (TargetElementComponent t : ct.getTarget()) {
        if (!t.hasDependsOn() && !t.hasProduct() && isOkEquivalence(t.getEquivalence())) {
            if (tt != null)
                throw new FHIRException("Unable to process translate " + code + " because multiple targets were found in concept map " + cm.getUrl());
            tt = t;
        }
    }
    if (tt == null)
        return null;
    CanonicalPair cp = new CanonicalPair(cg.getTarget());
    return new Coding().setSystem(cp.getUrl()).setVersion(cp.getVersion()).setCode(tt.getCode()).setDisplay(tt.getDisplay());
}
Also used : Coding(org.hl7.fhir.r4b.model.Coding) TargetElementComponent(org.hl7.fhir.r4b.model.ConceptMap.TargetElementComponent) FHIRException(org.hl7.fhir.exceptions.FHIRException) SourceElementComponent(org.hl7.fhir.r4b.model.ConceptMap.SourceElementComponent) ConceptMapGroupComponent(org.hl7.fhir.r4b.model.ConceptMap.ConceptMapGroupComponent) CanonicalPair(org.hl7.fhir.utilities.CanonicalPair)

Example 48 with ConceptMapGroupComponent

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

the class ConceptMap14_30 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.dstu3.model.ConceptMap.ConceptMapGroupComponent)

Example 49 with ConceptMapGroupComponent

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

the class ConceptMap14_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)

Example 50 with ConceptMapGroupComponent

use of org.hl7.fhir.r4b.model.ConceptMap.ConceptMapGroupComponent 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

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