Search in sources :

Example 46 with StructureMapGroupComponent

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

the class StructureMapUtilities method transform.

public void transform(Object appInfo, Base source, StructureMap map, Base target) throws FHIRException {
    TransformContext context = new TransformContext(appInfo);
    log("Start Transform " + map.getUrl());
    StructureMapGroupComponent g = map.getGroup().get(0);
    Variables vars = new Variables();
    vars.add(VariableMode.INPUT, getInputName(g, StructureMapInputMode.SOURCE, "source"), source);
    if (target != null)
        vars.add(VariableMode.OUTPUT, getInputName(g, StructureMapInputMode.TARGET, "target"), target);
    else if (getInputName(g, StructureMapInputMode.TARGET, null) != null) {
        String type = getInputType(g, StructureMapInputMode.TARGET);
        throw new Error("not handled yet: creating a type of " + type);
    }
    executeGroup("", context, map, vars, g, true);
    if (target instanceof Element)
        ((Element) target).sort();
}
Also used : Element(org.hl7.fhir.r5.elementmodel.Element) FHIRFormatError(org.hl7.fhir.exceptions.FHIRFormatError)

Example 47 with StructureMapGroupComponent

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

the class StructureMapUtilities method analyse.

/**
 * Given a structure map, return a set of analyses on it.
 * <p>
 * Returned:
 * - a list or profiles for what it will create. First profile is the target
 * - a table with a summary (in xhtml) for easy human undertanding of the mapping
 *
 * @param appInfo
 * @param map
 * @return
 * @throws Exception
 */
public StructureMapAnalysis analyse(Object appInfo, StructureMap map) throws FHIRException {
    ids.clear();
    StructureMapAnalysis result = new StructureMapAnalysis();
    TransformContext context = new TransformContext(appInfo);
    VariablesForProfiling vars = new VariablesForProfiling(this, false, false);
    StructureMapGroupComponent start = map.getGroup().get(0);
    for (StructureMapGroupInputComponent t : start.getInput()) {
        PropertyWithType ti = resolveType(map, t.getType(), t.getMode());
        if (t.getMode() == StructureMapInputMode.SOURCE)
            vars.add(VariableMode.INPUT, t.getName(), ti);
        else
            vars.add(VariableMode.OUTPUT, t.getName(), createProfile(map, result.profiles, ti, start.getName(), start));
    }
    result.summary = new XhtmlNode(NodeType.Element, "table").setAttribute("class", "grid");
    XhtmlNode tr = result.summary.addTag("tr");
    tr.addTag("td").addTag("b").addText("Source");
    tr.addTag("td").addTag("b").addText("Target");
    log("Start Profiling Transform " + map.getUrl());
    analyseGroup("", context, map, vars, start, result);
    ProfileUtilities pu = new ProfileUtilities(worker, null, pkp);
    for (StructureDefinition sd : result.getProfiles()) pu.cleanUpDifferential(sd);
    return result;
}
Also used : ProfileUtilities(org.hl7.fhir.r5.conformance.ProfileUtilities) XhtmlNode(org.hl7.fhir.utilities.xhtml.XhtmlNode)

Example 48 with StructureMapGroupComponent

use of org.hl7.fhir.r4.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 '" + name + "' in " + res.targetMap.getUrl() + " and " + impMap.getUrl());
                    }
                }
            }
        }
    }
    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.dstu3.model.StructureMap.StructureMapGroupComponent) StructureMap(org.hl7.fhir.dstu3.model.StructureMap) FHIRException(org.hl7.fhir.exceptions.FHIRException) UriType(org.hl7.fhir.dstu3.model.UriType)

Example 49 with StructureMapGroupComponent

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

the class StructureMapUtilities method parseInput.

private void parseInput(StructureMapGroupComponent group, FHIRLexer lexer) throws FHIRException {
    lexer.token("input");
    StructureMapGroupInputComponent input = group.addInput();
    input.setName(lexer.take());
    if (lexer.hasToken(":")) {
        lexer.token(":");
        input.setType(lexer.take());
    }
    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.dstu3.model.StructureMap.StructureMapGroupInputComponent)

Example 50 with StructureMapGroupComponent

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

the class StructureMapUtilities method parseGroup.

private void parseGroup(StructureMap result, FHIRLexer lexer) throws FHIRException {
    lexer.token("group");
    StructureMapGroupComponent group = result.addGroup();
    if (lexer.hasToken("for")) {
        lexer.token("for");
        if ("type".equals(lexer.getCurrent())) {
            lexer.token("type");
            lexer.token("+");
            lexer.token("types");
            group.setTypeMode(StructureMapGroupTypeMode.TYPEANDTYPES);
        } else {
            lexer.token("types");
            group.setTypeMode(StructureMapGroupTypeMode.TYPES);
        }
    } else
        group.setTypeMode(StructureMapGroupTypeMode.NONE);
    group.setName(lexer.take());
    if (lexer.hasToken("extends")) {
        lexer.next();
        group.setExtends(lexer.take());
    }
    lexer.skipComments();
    while (lexer.hasToken("input")) parseInput(group, lexer);
    while (!lexer.hasToken("endgroup")) {
        if (lexer.done())
            throw lexer.error("premature termination expecting 'endgroup'");
        parseRule(result, group.getRule(), lexer);
    }
    lexer.next();
    lexer.skipComments();
}
Also used : StructureMapGroupComponent(org.hl7.fhir.dstu3.model.StructureMap.StructureMapGroupComponent)

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