Search in sources :

Example 36 with SourceElementComponent

use of org.hl7.fhir.r5.model.ConceptMap.SourceElementComponent 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() && isOkRelationship(t.getRelationship())) {
            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.r5.model.Coding) TargetElementComponent(org.hl7.fhir.r5.model.ConceptMap.TargetElementComponent) FHIRException(org.hl7.fhir.exceptions.FHIRException) SourceElementComponent(org.hl7.fhir.r5.model.ConceptMap.SourceElementComponent) ConceptMapGroupComponent(org.hl7.fhir.r5.model.ConceptMap.ConceptMapGroupComponent) CanonicalPair(org.hl7.fhir.utilities.CanonicalPair)

Example 37 with SourceElementComponent

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

the class MappingSheetParser method getConceptMap.

public ConceptMap getConceptMap() throws FHIRException {
    ConceptMap map = new ConceptMap();
    loadMetadata(map);
    if (metadata.containsKey("copyright"))
        map.setCopyright(metadata.get("copyright"));
    for (MappingRow row : rows) {
        SourceElementComponent element = map.getGroupFirstRep().addElement();
        element.setCode(row.getIdentifier());
        element.setId(row.getSequence());
        element.setDisplay(row.getName() + " : " + row.getDataType() + " [" + row.getCardinality() + "]");
        element.addExtension(ToolingExtensions.EXT_MAPPING_NAME, new StringType(row.getName()));
        element.addExtension(ToolingExtensions.EXT_MAPPING_TYPE, new StringType(row.getDataType()));
        element.addExtension(ToolingExtensions.EXT_MAPPING_CARD, new StringType(row.getCardinality()));
        if ("N/A".equals(row.getAttribute()))
            element.addTarget().setEquivalence(ConceptMapEquivalence.UNMATCHED);
        else {
            element.getTargetFirstRep().setEquivalence(ConceptMapEquivalence.RELATEDTO);
            if (row.getCondition() != null)
                element.getTargetFirstRep().addDependsOn().setProperty("http://hl7.org/fhirpath").setValue(processCondition(row.getCondition()));
            element.getTargetFirstRep().setCode(row.getAttribute());
            element.getTargetFirstRep().setDisplay(row.getType() + " : [" + row.getMinMax() + "]");
            element.getTargetFirstRep().addExtension(ToolingExtensions.EXT_MAPPING_TGTTYPE, new StringType(row.getType()));
            element.getTargetFirstRep().addExtension(ToolingExtensions.EXT_MAPPING_TGTCARD, new StringType(row.getMinMax()));
            if (row.getDerived() != null)
                element.getTargetFirstRep().getProductFirstRep().setProperty(row.getDerived()).setValue(row.getDerivedMapping());
            if (row.getComments() != null)
                element.getTargetFirstRep().setComment(row.getComments());
            if (row.getDtMapping() != null)
                element.getTargetFirstRep().addExtension("http://hl7.org/fhir/StructureDefinition/ConceptMap-type-mapping", new UrlType("todo#" + row.getDtMapping()));
            if (row.getVocabMapping() != null)
                element.getTargetFirstRep().addExtension("http://hl7.org/fhir/StructureDefinition/ConceptMap-vocab-mapping", new UrlType("todo#" + row.getVocabMapping()));
        }
    }
    return map;
}
Also used : StringType(org.hl7.fhir.r4b.model.StringType) ConceptMap(org.hl7.fhir.r4b.model.ConceptMap) UrlType(org.hl7.fhir.r4b.model.UrlType) SourceElementComponent(org.hl7.fhir.r4b.model.ConceptMap.SourceElementComponent)

Example 38 with SourceElementComponent

use of org.hl7.fhir.r5.model.ConceptMap.SourceElementComponent 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)

Example 39 with SourceElementComponent

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

the class MappingSheetParser method getConceptMap.

public ConceptMap getConceptMap() throws FHIRException {
    ConceptMap map = new ConceptMap();
    loadMetadata(map);
    if (metadata.containsKey("copyright"))
        map.setCopyright(metadata.get("copyright"));
    for (MappingRow row : rows) {
        SourceElementComponent element = map.getGroupFirstRep().addElement();
        element.setCode(row.getIdentifier());
        element.setId(row.getSequence());
        element.setDisplay(row.getName() + " : " + row.getDataType() + " [" + row.getCardinality() + "]");
        element.addExtension(ToolingExtensions.EXT_MAPPING_NAME, new StringType(row.getName()));
        element.addExtension(ToolingExtensions.EXT_MAPPING_TYPE, new StringType(row.getDataType()));
        element.addExtension(ToolingExtensions.EXT_MAPPING_CARD, new StringType(row.getCardinality()));
        if ("N/A".equals(row.getAttribute()))
            element.setNoMap(true);
        else {
            element.getTargetFirstRep().setRelationship(ConceptMapRelationship.RELATEDTO);
            if (row.getCondition() != null)
                element.getTargetFirstRep().addDependsOn().setProperty("http://hl7.org/fhirpath").setValue(processCondition(row.getCondition()));
            element.getTargetFirstRep().setCode(row.getAttribute());
            element.getTargetFirstRep().setDisplay(row.getType() + " : [" + row.getMinMax() + "]");
            element.getTargetFirstRep().addExtension(ToolingExtensions.EXT_MAPPING_TGTTYPE, new StringType(row.getType()));
            element.getTargetFirstRep().addExtension(ToolingExtensions.EXT_MAPPING_TGTCARD, new StringType(row.getMinMax()));
            if (row.getDerived() != null)
                element.getTargetFirstRep().getProductFirstRep().setProperty(row.getDerived()).setValue(row.getDerivedMapping());
            if (row.getComments() != null)
                element.getTargetFirstRep().setComment(row.getComments());
            if (row.getDtMapping() != null)
                element.getTargetFirstRep().addExtension("http://hl7.org/fhir/StructureDefinition/ConceptMap-type-mapping", new UrlType("todo#" + row.getDtMapping()));
            if (row.getVocabMapping() != null)
                element.getTargetFirstRep().addExtension("http://hl7.org/fhir/StructureDefinition/ConceptMap-vocab-mapping", new UrlType("todo#" + row.getVocabMapping()));
        }
    }
    return map;
}
Also used : StringType(org.hl7.fhir.r5.model.StringType) ConceptMap(org.hl7.fhir.r5.model.ConceptMap) UrlType(org.hl7.fhir.r5.model.UrlType) SourceElementComponent(org.hl7.fhir.r5.model.ConceptMap.SourceElementComponent)

Example 40 with SourceElementComponent

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

the class MappingSheetParser method readConceptMap.

private void readConceptMap(ConceptMap cm) throws FHIRException {
    for (ConceptMapGroupComponent g : cm.getGroup()) {
        for (SourceElementComponent e : g.getElement()) {
            if (e.hasId() && e.getTarget().size() == 1 && e.hasExtension(ToolingExtensions.EXT_MAPPING_TYPE)) {
                TargetElementComponent t = e.getTargetFirstRep();
                MappingRow row = new MappingRow();
                row.sequence = e.getId();
                row.identifier = e.getCode();
                row.name = e.getExtensionString(ToolingExtensions.EXT_MAPPING_NAME);
                row.dataType = e.getExtensionString(ToolingExtensions.EXT_MAPPING_TYPE);
                row.cardinality = e.getExtensionString(ToolingExtensions.EXT_MAPPING_CARD);
                if (e.getNoMap() == true) {
                    row.attribute = "N/A";
                } else {
                    OtherElementComponent dep = getDependency(t, "http://hl7.org/fhirpath");
                    if (dep != null)
                        row.condition = dep.getValue();
                    row.attribute = t.getCode();
                    row.type = t.getExtensionString(ToolingExtensions.EXT_MAPPING_TGTTYPE);
                    row.minMax = t.getExtensionString(ToolingExtensions.EXT_MAPPING_TGTCARD);
                    row.dtMapping = t.getExtensionString("http://hl7.org/fhir/StructureDefinition/ConceptMap-type-mapping");
                    row.vocabMapping = t.getExtensionString("http://hl7.org/fhir/StructureDefinition/ConceptMap-vocab-mapping");
                    if (t.getProduct().size() > 0) {
                        row.derived = t.getProductFirstRep().getProperty();
                        row.derivedMapping = t.getProductFirstRep().getValue();
                    }
                }
                row.comments = t.getComment();
                rows.add(row);
            }
        }
    }
}
Also used : OtherElementComponent(org.hl7.fhir.r5.model.ConceptMap.OtherElementComponent) TargetElementComponent(org.hl7.fhir.r5.model.ConceptMap.TargetElementComponent) ConceptMapGroupComponent(org.hl7.fhir.r5.model.ConceptMap.ConceptMapGroupComponent) SourceElementComponent(org.hl7.fhir.r5.model.ConceptMap.SourceElementComponent)

Aggregations

SourceElementComponent (org.hl7.fhir.r5.model.ConceptMap.SourceElementComponent)14 FHIRException (org.hl7.fhir.exceptions.FHIRException)11 ConceptMapGroupComponent (org.hl7.fhir.r5.model.ConceptMap.ConceptMapGroupComponent)11 HashMap (java.util.HashMap)10 ConceptMapGroupComponent (org.hl7.fhir.dstu3.model.ConceptMap.ConceptMapGroupComponent)9 SourceElementComponent (org.hl7.fhir.dstu3.model.ConceptMap.SourceElementComponent)9 TargetElementComponent (org.hl7.fhir.r5.model.ConceptMap.TargetElementComponent)9 ConceptMapGroupComponent (org.hl7.fhir.r4.model.ConceptMap.ConceptMapGroupComponent)8 SourceElementComponent (org.hl7.fhir.r4.model.ConceptMap.SourceElementComponent)8 SourceElementComponent (org.hl7.fhir.r4b.model.ConceptMap.SourceElementComponent)8 ArrayList (java.util.ArrayList)7 TargetElementComponent (org.hl7.fhir.dstu3.model.ConceptMap.TargetElementComponent)6 TargetElementComponent (org.hl7.fhir.r4.model.ConceptMap.TargetElementComponent)6 XhtmlNode (org.hl7.fhir.utilities.xhtml.XhtmlNode)6 HashSet (java.util.HashSet)5 ConceptMap (org.hl7.fhir.r4.model.ConceptMap)5 ConceptMapGroupComponent (org.hl7.fhir.r4b.model.ConceptMap.ConceptMapGroupComponent)5 TargetElementComponent (org.hl7.fhir.r4b.model.ConceptMap.TargetElementComponent)5 Coding (org.hl7.fhir.r4.model.Coding)4 ConceptMap (org.hl7.fhir.r5.model.ConceptMap)4