Search in sources :

Example 26 with StructureMapGroupComponent

use of org.hl7.fhir.r4b.model.StructureMap.StructureMapGroupComponent in project org.hl7.fhir.core by hapifhir.

the class StructureMapUtilities method render.

public static String render(StructureMap map) {
    StringBuilder b = new StringBuilder();
    b.append("map \"");
    b.append(map.getUrl());
    b.append("\" = \"");
    b.append(Utilities.escapeJson(map.getName()));
    b.append("\"\r\n\r\n");
    renderConceptMaps(b, map);
    renderUses(b, map);
    renderImports(b, map);
    for (StructureMapGroupComponent g : map.getGroup()) renderGroup(b, g);
    return b.toString();
}
Also used : StructureMapGroupComponent(org.hl7.fhir.r4.model.StructureMap.StructureMapGroupComponent) CommaSeparatedStringBuilder(org.hl7.fhir.utilities.CommaSeparatedStringBuilder)

Example 27 with StructureMapGroupComponent

use of org.hl7.fhir.r4b.model.StructureMap.StructureMapGroupComponent in project org.hl7.fhir.core by hapifhir.

the class StructureMapUtilities method parseInput.

private void parseInput(StructureMapGroupComponent group, FHIRLexer lexer, boolean newFmt) throws FHIRException {
    StructureMapGroupInputComponent input = group.addInput();
    if (newFmt) {
        input.setMode(StructureMapInputMode.fromCode(lexer.take()));
    } else
        lexer.token("input");
    input.setName(lexer.take());
    if (lexer.hasToken(":")) {
        lexer.token(":");
        input.setType(lexer.take());
    }
    if (!newFmt) {
        lexer.token("as");
        input.setMode(StructureMapInputMode.fromCode(lexer.take()));
        if (lexer.hasComment()) {
            input.setDocumentation(lexer.take().substring(2).trim());
        }
        lexer.skipToken(";");
        lexer.skipComments();
    }
}
Also used : StructureMapGroupInputComponent(org.hl7.fhir.r4.model.StructureMap.StructureMapGroupInputComponent)

Example 28 with StructureMapGroupComponent

use of org.hl7.fhir.r4b.model.StructureMap.StructureMapGroupComponent in project org.hl7.fhir.core by hapifhir.

the class StructureMapUtilities method resolveGroupReference.

private ResolvedGroup resolveGroupReference(StructureMap map, StructureMapGroupComponent source, String name) throws FHIRException {
    String kn = "ref^" + name;
    if (source.hasUserData(kn))
        return (ResolvedGroup) source.getUserData(kn);
    ResolvedGroup res = new ResolvedGroup();
    res.targetMap = null;
    res.target = null;
    for (StructureMapGroupComponent grp : map.getGroup()) {
        if (grp.getName().equals(name)) {
            if (res.targetMap == null) {
                res.targetMap = map;
                res.target = grp;
            } else
                throw new FHIRException("Multiple possible matches for rule '" + name + "'");
        }
    }
    if (res.targetMap != null) {
        source.setUserData(kn, res);
        return res;
    }
    for (UriType imp : map.getImport()) {
        List<StructureMap> impMapList = findMatchingMaps(imp.getValue());
        if (impMapList.size() == 0)
            throw new FHIRException("Unable to find map(s) for " + imp.getValue());
        for (StructureMap impMap : impMapList) {
            if (!impMap.getUrl().equals(map.getUrl())) {
                for (StructureMapGroupComponent grp : impMap.getGroup()) {
                    if (grp.getName().equals(name)) {
                        if (res.targetMap == null) {
                            res.targetMap = impMap;
                            res.target = grp;
                        } else
                            throw new FHIRException("Multiple possible matches for rule group '" + name + "' in " + res.targetMap.getUrl() + "#" + res.target.getName() + " and " + impMap.getUrl() + "#" + grp.getName());
                    }
                }
            }
        }
    }
    if (res.target == null)
        throw new FHIRException("No matches found for rule '" + name + "'. Reference found in " + map.getUrl());
    source.setUserData(kn, res);
    return res;
}
Also used : StructureMapGroupComponent(org.hl7.fhir.r4.model.StructureMap.StructureMapGroupComponent) StructureMap(org.hl7.fhir.r4.model.StructureMap) FHIRException(org.hl7.fhir.exceptions.FHIRException) UriType(org.hl7.fhir.r4.model.UriType)

Example 29 with StructureMapGroupComponent

use of org.hl7.fhir.r4b.model.StructureMap.StructureMapGroupComponent in project org.hl7.fhir.core by hapifhir.

the class StructureMapUtilities method processTarget.

private void processTarget(String ruleId, TransformContext context, Variables vars, StructureMap map, StructureMapGroupComponent group, StructureMapGroupRuleTargetComponent tgt, String srcVar, boolean atRoot, Variables sharedVars) throws FHIRException {
    Base dest = null;
    if (tgt.hasContext()) {
        dest = vars.get(VariableMode.OUTPUT, tgt.getContext());
        if (dest == null)
            throw new FHIRException("Rule \"" + ruleId + "\": target context not known: " + tgt.getContext());
        if (!tgt.hasElement())
            throw new FHIRException("Rule \"" + ruleId + "\": Not supported yet");
    }
    Base v = null;
    if (tgt.hasTransform()) {
        v = runTransform(ruleId, context, map, group, tgt, vars, dest, tgt.getElement(), srcVar, atRoot);
        if (v != null && dest != null)
            // reset v because some implementations may have to rewrite v when setting the value
            v = dest.setProperty(tgt.getElement().hashCode(), tgt.getElement(), v);
    } else if (dest != null) {
        if (tgt.hasListMode(StructureMapTargetListMode.SHARE)) {
            v = sharedVars.get(VariableMode.SHARED, tgt.getListRuleId());
            if (v == null) {
                v = dest.makeProperty(tgt.getElement().hashCode(), tgt.getElement());
                sharedVars.add(VariableMode.SHARED, tgt.getListRuleId(), v);
            }
        } else {
            v = dest.makeProperty(tgt.getElement().hashCode(), tgt.getElement());
        }
    }
    if (tgt.hasVariable() && v != null)
        vars.add(VariableMode.OUTPUT, tgt.getVariable(), v);
}
Also used : FHIRException(org.hl7.fhir.exceptions.FHIRException) Base(org.hl7.fhir.r4.model.Base)

Example 30 with StructureMapGroupComponent

use of org.hl7.fhir.r4b.model.StructureMap.StructureMapGroupComponent in project org.hl7.fhir.core by hapifhir.

the class StructureMapUtilities method analyseGroup.

private void analyseGroup(String indent, TransformContext context, StructureMap map, VariablesForProfiling vars, StructureMapGroupComponent group, StructureMapAnalysis result) throws FHIRException {
    log(indent + "Analyse Group : " + group.getName());
    // todo: extends
    // todo: check inputs
    XhtmlNode tr = result.summary.addTag("tr").setAttribute("class", "diff-title");
    XhtmlNode xs = tr.addTag("td");
    XhtmlNode xt = tr.addTag("td");
    for (StructureMapGroupInputComponent inp : group.getInput()) {
        if (inp.getMode() == StructureMapInputMode.SOURCE)
            noteInput(vars, inp, VariableMode.INPUT, xs);
        if (inp.getMode() == StructureMapInputMode.TARGET)
            noteInput(vars, inp, VariableMode.OUTPUT, xt);
    }
    for (StructureMapGroupRuleComponent r : group.getRule()) {
        analyseRule(indent + "  ", context, map, vars, group, r, result);
    }
}
Also used : StructureMapGroupInputComponent(org.hl7.fhir.r4.model.StructureMap.StructureMapGroupInputComponent) StructureMapGroupRuleComponent(org.hl7.fhir.r4.model.StructureMap.StructureMapGroupRuleComponent) XhtmlNode(org.hl7.fhir.utilities.xhtml.XhtmlNode)

Aggregations

FHIRException (org.hl7.fhir.exceptions.FHIRException)34 XhtmlNode (org.hl7.fhir.utilities.xhtml.XhtmlNode)12 CommaSeparatedStringBuilder (org.hl7.fhir.utilities.CommaSeparatedStringBuilder)11 StructureMapGroupComponent (org.hl7.fhir.dstu3.model.StructureMap.StructureMapGroupComponent)7 StructureMapGroupComponent (org.hl7.fhir.r4.model.StructureMap.StructureMapGroupComponent)7 IOException (java.io.IOException)5 StructureMapGroupInputComponent (org.hl7.fhir.dstu3.model.StructureMap.StructureMapGroupInputComponent)5 StructureMapGroupRuleComponent (org.hl7.fhir.dstu3.model.StructureMap.StructureMapGroupRuleComponent)5 DefinitionException (org.hl7.fhir.exceptions.DefinitionException)5 FHIRFormatError (org.hl7.fhir.exceptions.FHIRFormatError)5 StructureMapGroupInputComponent (org.hl7.fhir.r4.model.StructureMap.StructureMapGroupInputComponent)5 StructureMapGroupRuleComponent (org.hl7.fhir.r4.model.StructureMap.StructureMapGroupRuleComponent)5 Base (org.hl7.fhir.dstu3.model.Base)4 UriType (org.hl7.fhir.dstu3.model.UriType)4 PathEngineException (org.hl7.fhir.exceptions.PathEngineException)4 Base (org.hl7.fhir.r4.model.Base)4 UriType (org.hl7.fhir.r4.model.UriType)4 StructureMap (org.hl7.fhir.r4b.model.StructureMap)4 StructureMap (org.hl7.fhir.r5.model.StructureMap)4 StructureMapGroupComponent (org.hl7.fhir.dstu2016may.model.StructureMap.StructureMapGroupComponent)3