Search in sources :

Example 6 with StructureMapGroupRuleDependentComponent

use of org.hl7.fhir.r4.model.StructureMap.StructureMapGroupRuleDependentComponent in project org.hl7.fhir.core by hapifhir.

the class MappingSheetParser method getStructureMap.

public StructureMap getStructureMap() throws FHIRException {
    StructureMap map = new StructureMap();
    loadMetadata(map);
    if (metadata.containsKey("copyright"))
        map.setCopyright(metadata.get("copyright"));
    StructureMapGroupComponent grp = map.addGroup();
    for (MappingRow row : rows) {
        StructureMapGroupRuleComponent rule = grp.addRule();
        rule.setName(row.getSequence());
        StructureMapGroupRuleSourceComponent src = rule.getSourceFirstRep();
        src.setContext("src");
        src.setElement(row.getIdentifier());
        src.setMin(row.getCardinalityMin());
        src.setMax(row.getCardinalityMax());
        src.setType(row.getDataType());
        src.addExtension(ToolingExtensions.EXT_MAPPING_NAME, new StringType(row.getName()));
        if (row.getCondition() != null) {
            src.setCheck(processCondition(row.getCondition()));
        }
        StructureMapGroupRuleTargetComponent tgt = rule.getTargetFirstRep();
        tgt.setContext("tgt");
        tgt.setElement(row.getAttribute());
        tgt.addExtension(ToolingExtensions.EXT_MAPPING_TGTTYPE, new StringType(row.getType()));
        tgt.addExtension(ToolingExtensions.EXT_MAPPING_TGTCARD, new StringType(row.getMinMax()));
        if (row.getDtMapping() != null) {
            src.setVariable("s");
            tgt.setVariable("t");
            tgt.setTransform(StructureMapTransform.CREATE);
            StructureMapGroupRuleDependentComponent dep = rule.addDependent();
            dep.setName(row.getDtMapping());
            dep.addVariable("s");
            dep.addVariable("t");
        } else if (row.getVocabMapping() != null) {
            tgt.setTransform(StructureMapTransform.TRANSLATE);
            tgt.addParameter().setValue(new StringType(row.getVocabMapping()));
            tgt.addParameter().setValue(new IdType("src"));
        } else {
            tgt.setTransform(StructureMapTransform.COPY);
        }
        rule.setDocumentation(row.getComments());
        if (row.getDerived() != null) {
            tgt = rule.addTarget();
            tgt.setContext("tgt");
            tgt.setElement(row.getDerived());
            tgt.setTransform(StructureMapTransform.COPY);
            tgt.addParameter().setValue(new StringType(row.getDerivedMapping()));
        }
    }
    return map;
}
Also used : StructureMap(org.hl7.fhir.r4b.model.StructureMap) StructureMapGroupComponent(org.hl7.fhir.r4b.model.StructureMap.StructureMapGroupComponent) StringType(org.hl7.fhir.r4b.model.StringType) StructureMapGroupRuleDependentComponent(org.hl7.fhir.r4b.model.StructureMap.StructureMapGroupRuleDependentComponent) StructureMapGroupRuleComponent(org.hl7.fhir.r4b.model.StructureMap.StructureMapGroupRuleComponent) StructureMapGroupRuleSourceComponent(org.hl7.fhir.r4b.model.StructureMap.StructureMapGroupRuleSourceComponent) StructureMapGroupRuleTargetComponent(org.hl7.fhir.r4b.model.StructureMap.StructureMapGroupRuleTargetComponent) IdType(org.hl7.fhir.r4b.model.IdType)

Example 7 with StructureMapGroupRuleDependentComponent

use of org.hl7.fhir.r4.model.StructureMap.StructureMapGroupRuleDependentComponent in project org.hl7.fhir.core by hapifhir.

the class StructureMapUtilities method executeRule.

private void executeRule(String indent, TransformContext context, StructureMap map, Variables vars, StructureMapGroupComponent group, StructureMapGroupRuleComponent rule) throws FHIRException {
    log(indent + "rule : " + rule.getName());
    if (rule.getName().contains("CarePlan.participant-unlink"))
        System.out.println("debug");
    Variables srcVars = vars.copy();
    if (rule.getSource().size() != 1)
        throw new FHIRException("Rule \"" + rule.getName() + "\": not handled yet");
    List<Variables> source = processSource(rule.getName(), context, srcVars, rule.getSource().get(0));
    if (source != null) {
        for (Variables v : source) {
            for (StructureMapGroupRuleTargetComponent t : rule.getTarget()) {
                processTarget(rule.getName(), context, v, map, group, t, rule.getSource().size() == 1 ? rule.getSourceFirstRep().getVariable() : null);
            }
            if (rule.hasRule()) {
                for (StructureMapGroupRuleComponent childrule : rule.getRule()) {
                    executeRule(indent + "  ", context, map, v, group, childrule);
                }
            } else if (rule.hasDependent()) {
                for (StructureMapGroupRuleDependentComponent dependent : rule.getDependent()) {
                    executeDependency(indent + "  ", context, map, v, group, dependent);
                }
            } else if (rule.getSource().size() == 1 && rule.getSourceFirstRep().hasVariable() && rule.getTarget().size() == 1 && rule.getTargetFirstRep().hasVariable() && rule.getTargetFirstRep().getTransform() == StructureMapTransform.CREATE && !rule.getTargetFirstRep().hasParameter()) {
                // simple inferred, map by type
                Base src = v.get(VariableMode.INPUT, rule.getSourceFirstRep().getVariable());
                Base tgt = v.get(VariableMode.OUTPUT, rule.getTargetFirstRep().getVariable());
                String srcType = src.fhirType();
                String tgtType = tgt.fhirType();
                ResolvedGroup defGroup = resolveGroupByTypes(map, rule.getName(), group, srcType, tgtType);
                Variables vdef = new Variables();
                vdef.add(VariableMode.INPUT, defGroup.target.getInput().get(0).getName(), src);
                vdef.add(VariableMode.OUTPUT, defGroup.target.getInput().get(1).getName(), tgt);
                executeGroup(indent + "  ", context, defGroup.targetMap, vdef, defGroup.target);
            }
        }
    }
}
Also used : StructureMapGroupRuleDependentComponent(org.hl7.fhir.dstu3.model.StructureMap.StructureMapGroupRuleDependentComponent) FHIRException(org.hl7.fhir.exceptions.FHIRException) StructureMapGroupRuleTargetComponent(org.hl7.fhir.dstu3.model.StructureMap.StructureMapGroupRuleTargetComponent) StructureMapGroupRuleComponent(org.hl7.fhir.dstu3.model.StructureMap.StructureMapGroupRuleComponent) Base(org.hl7.fhir.dstu3.model.Base)

Example 8 with StructureMapGroupRuleDependentComponent

use of org.hl7.fhir.r4.model.StructureMap.StructureMapGroupRuleDependentComponent in project org.hl7.fhir.core by hapifhir.

the class StructureMapUtilities method analyseRule.

private void analyseRule(String indent, TransformContext context, StructureMap map, VariablesForProfiling vars, StructureMapGroupComponent group, StructureMapGroupRuleComponent rule, StructureMapAnalysis result) throws Exception {
    log(indent + "Analyse rule : " + rule.getName());
    XhtmlNode tr = result.summary.addTag("tr");
    XhtmlNode xs = tr.addTag("td");
    XhtmlNode xt = tr.addTag("td");
    VariablesForProfiling srcVars = vars.copy();
    if (rule.getSource().size() != 1)
        throw new Exception("Rule \"" + rule.getName() + "\": not handled yet");
    VariablesForProfiling source = analyseSource(rule.getName(), context, srcVars, rule.getSourceFirstRep(), xs);
    TargetWriter tw = new TargetWriter();
    for (StructureMapGroupRuleTargetComponent t : rule.getTarget()) {
        analyseTarget(rule.getName(), context, source, map, t, rule.getSourceFirstRep().getVariable(), tw, result.profiles, rule.getName());
    }
    tw.commit(xt);
    for (StructureMapGroupRuleComponent childrule : rule.getRule()) {
        analyseRule(indent + "  ", context, map, source, group, childrule, result);
    }
// for (StructureMapGroupRuleDependentComponent dependent : rule.getDependent()) {
// executeDependency(indent+"  ", context, map, v, group, dependent); // do we need group here?
// }
}
Also used : FHIRLexerException(org.hl7.fhir.dstu3.utils.FHIRLexer.FHIRLexerException) DefinitionException(org.hl7.fhir.exceptions.DefinitionException) PathEngineException(org.hl7.fhir.exceptions.PathEngineException) IOException(java.io.IOException) FHIRException(org.hl7.fhir.exceptions.FHIRException) StructureMapGroupRuleTargetComponent(org.hl7.fhir.dstu3.model.StructureMap.StructureMapGroupRuleTargetComponent) StructureMapGroupRuleComponent(org.hl7.fhir.dstu3.model.StructureMap.StructureMapGroupRuleComponent) XhtmlNode(org.hl7.fhir.utilities.xhtml.XhtmlNode)

Example 9 with StructureMapGroupRuleDependentComponent

use of org.hl7.fhir.r4.model.StructureMap.StructureMapGroupRuleDependentComponent in project org.hl7.fhir.core by hapifhir.

the class MappingSheetParser method getStructureMap.

public StructureMap getStructureMap() throws FHIRException {
    StructureMap map = new StructureMap();
    loadMetadata(map);
    if (metadata.containsKey("copyright"))
        map.setCopyright(metadata.get("copyright"));
    StructureMapGroupComponent grp = map.addGroup();
    for (MappingRow row : rows) {
        StructureMapGroupRuleComponent rule = grp.addRule();
        rule.setName(row.getSequence());
        StructureMapGroupRuleSourceComponent src = rule.getSourceFirstRep();
        src.setContext("src");
        src.setElement(row.getIdentifier());
        src.setMin(row.getCardinalityMin());
        src.setMax(row.getCardinalityMax());
        src.setType(row.getDataType());
        src.addExtension(ToolingExtensions.EXT_MAPPING_NAME, new StringType(row.getName()));
        if (row.getCondition() != null) {
            src.setCheck(processCondition(row.getCondition()));
        }
        StructureMapGroupRuleTargetComponent tgt = rule.getTargetFirstRep();
        tgt.setContext("tgt");
        tgt.setElement(row.getAttribute());
        tgt.addExtension(ToolingExtensions.EXT_MAPPING_TGTTYPE, new StringType(row.getType()));
        tgt.addExtension(ToolingExtensions.EXT_MAPPING_TGTCARD, new StringType(row.getMinMax()));
        if (row.getDtMapping() != null) {
            src.setVariable("s");
            tgt.setVariable("t");
            tgt.setTransform(StructureMapTransform.CREATE);
            StructureMapGroupRuleDependentComponent dep = rule.addDependent();
            dep.setName(row.getDtMapping());
            dep.addParameter().setValue(new IdType("s"));
            dep.addParameter().setValue(new IdType("t"));
        } else if (row.getVocabMapping() != null) {
            tgt.setTransform(StructureMapTransform.TRANSLATE);
            tgt.addParameter().setValue(new StringType(row.getVocabMapping()));
            tgt.addParameter().setValue(new IdType("src"));
        } else {
            tgt.setTransform(StructureMapTransform.COPY);
        }
        rule.setDocumentation(row.getComments());
        if (row.getDerived() != null) {
            tgt = rule.addTarget();
            tgt.setContext("tgt");
            tgt.setElement(row.getDerived());
            tgt.setTransform(StructureMapTransform.COPY);
            tgt.addParameter().setValue(new StringType(row.getDerivedMapping()));
        }
    }
    return map;
}
Also used : StructureMap(org.hl7.fhir.r5.model.StructureMap) StructureMapGroupComponent(org.hl7.fhir.r5.model.StructureMap.StructureMapGroupComponent) StringType(org.hl7.fhir.r5.model.StringType) StructureMapGroupRuleDependentComponent(org.hl7.fhir.r5.model.StructureMap.StructureMapGroupRuleDependentComponent) StructureMapGroupRuleComponent(org.hl7.fhir.r5.model.StructureMap.StructureMapGroupRuleComponent) StructureMapGroupRuleSourceComponent(org.hl7.fhir.r5.model.StructureMap.StructureMapGroupRuleSourceComponent) StructureMapGroupRuleTargetComponent(org.hl7.fhir.r5.model.StructureMap.StructureMapGroupRuleTargetComponent) IdType(org.hl7.fhir.r5.model.IdType)

Example 10 with StructureMapGroupRuleDependentComponent

use of org.hl7.fhir.r4.model.StructureMap.StructureMapGroupRuleDependentComponent in project org.hl7.fhir.core by hapifhir.

the class StructureMapUtilities method analyseRule.

private void analyseRule(String indent, TransformContext context, StructureMap map, VariablesForProfiling vars, StructureMapGroupComponent group, StructureMapGroupRuleComponent rule, StructureMapAnalysis result) throws FHIRException {
    log(indent + "Analyse rule : " + rule.getName());
    XhtmlNode tr = result.summary.addTag("tr");
    XhtmlNode xs = tr.addTag("td");
    XhtmlNode xt = tr.addTag("td");
    VariablesForProfiling srcVars = vars.copy();
    if (rule.getSource().size() != 1)
        throw new FHIRException("Rule \"" + rule.getName() + "\": not handled yet");
    VariablesForProfiling source = analyseSource(rule.getName(), context, srcVars, rule.getSourceFirstRep(), xs);
    TargetWriter tw = new TargetWriter();
    for (StructureMapGroupRuleTargetComponent t : rule.getTarget()) {
        analyseTarget(rule.getName(), context, source, map, t, rule.getSourceFirstRep().getVariable(), tw, result.profiles, rule.getName());
    }
    tw.commit(xt);
    for (StructureMapGroupRuleComponent childrule : rule.getRule()) {
        analyseRule(indent + "  ", context, map, source, group, childrule, result);
    }
// for (StructureMapGroupRuleDependentComponent dependent : rule.getDependent()) {
// executeDependency(indent+"  ", context, map, v, group, dependent); // do we need group here?
// }
}
Also used : FHIRException(org.hl7.fhir.exceptions.FHIRException) StructureMapGroupRuleTargetComponent(org.hl7.fhir.r4.model.StructureMap.StructureMapGroupRuleTargetComponent) StructureMapGroupRuleComponent(org.hl7.fhir.r4.model.StructureMap.StructureMapGroupRuleComponent) XhtmlNode(org.hl7.fhir.utilities.xhtml.XhtmlNode)

Aggregations

FHIRException (org.hl7.fhir.exceptions.FHIRException)14 XhtmlNode (org.hl7.fhir.utilities.xhtml.XhtmlNode)4 StructureMapGroupRuleDependentComponent (org.hl7.fhir.dstu2016may.model.StructureMap.StructureMapGroupRuleDependentComponent)3 StructureMapGroupRuleComponent (org.hl7.fhir.dstu3.model.StructureMap.StructureMapGroupRuleComponent)3 StructureMapGroupRuleDependentComponent (org.hl7.fhir.dstu3.model.StructureMap.StructureMapGroupRuleDependentComponent)3 StructureMapGroupRuleTargetComponent (org.hl7.fhir.dstu3.model.StructureMap.StructureMapGroupRuleTargetComponent)3 StructureMapGroupRuleComponent (org.hl7.fhir.r4.model.StructureMap.StructureMapGroupRuleComponent)3 StructureMapGroupRuleDependentComponent (org.hl7.fhir.r4.model.StructureMap.StructureMapGroupRuleDependentComponent)3 StructureMapGroupRuleTargetComponent (org.hl7.fhir.r4.model.StructureMap.StructureMapGroupRuleTargetComponent)3 StringType (org.hl7.fhir.dstu2016may.model.StringType)2 StructureMapGroupRuleTargetComponent (org.hl7.fhir.dstu2016may.model.StructureMap.StructureMapGroupRuleTargetComponent)2 Base (org.hl7.fhir.dstu3.model.Base)2 ContactPoint (org.hl7.fhir.dstu3.model.ContactPoint)2 StringType (org.hl7.fhir.dstu3.model.StringType)2 Base (org.hl7.fhir.r4.model.Base)2 ContactPoint (org.hl7.fhir.r4.model.ContactPoint)2 StringType (org.hl7.fhir.r4.model.StringType)2 IOException (java.io.IOException)1 Base (org.hl7.fhir.dstu2016may.model.Base)1 StructureMap (org.hl7.fhir.dstu2016may.model.StructureMap)1