Search in sources :

Example 1 with StructureMapGroupInputComponent

use of org.hl7.fhir.dstu3.model.StructureMap.StructureMapGroupInputComponent in project org.hl7.fhir.core by hapifhir.

the class StructureMapUtilities method renderGroup.

private static void renderGroup(StringBuilder b, StructureMapGroupComponent g) {
    b.append("group ");
    switch(g.getTypeMode()) {
        case TYPES:
            b.append("for types");
        case TYPEANDTYPES:
            b.append("for type+types ");
        // NONE, NULL
        default:
    }
    b.append("for types ");
    b.append(g.getName());
    if (g.hasExtends()) {
        b.append(" extends ");
        b.append(g.getExtends());
    }
    if (g.hasDocumentation())
        renderDoco(b, g.getDocumentation());
    b.append("\r\n");
    for (StructureMapGroupInputComponent gi : g.getInput()) {
        b.append("  input ");
        b.append(gi.getName());
        if (gi.hasType()) {
            b.append(" : ");
            b.append(gi.getType());
        }
        b.append(" as ");
        b.append(gi.getMode().toCode());
        b.append("\r\n");
    }
    if (g.hasInput())
        b.append("\r\n");
    for (StructureMapGroupRuleComponent r : g.getRule()) {
        renderRule(b, r, 2);
    }
    b.append("\r\nendgroup\r\n");
}
Also used : StructureMapGroupInputComponent(org.hl7.fhir.dstu3.model.StructureMap.StructureMapGroupInputComponent) StructureMapGroupRuleComponent(org.hl7.fhir.dstu3.model.StructureMap.StructureMapGroupRuleComponent)

Example 2 with StructureMapGroupInputComponent

use of org.hl7.fhir.dstu3.model.StructureMap.StructureMapGroupInputComponent in project org.hl7.fhir.core by hapifhir.

the class StructureMapUtilities method executeDependency.

private void executeDependency(String indent, TransformContext context, StructureMap map, Variables vin, StructureMapGroupComponent group, StructureMapGroupRuleDependentComponent dependent) throws FHIRException {
    ResolvedGroup rg = resolveGroupReference(map, group, dependent.getName());
    if (rg.target.getInput().size() != dependent.getVariable().size()) {
        throw new FHIRException("Rule '" + dependent.getName() + "' has " + Integer.toString(rg.target.getInput().size()) + " but the invocation has " + Integer.toString(dependent.getVariable().size()) + " variables");
    }
    Variables v = new Variables();
    for (int i = 0; i < rg.target.getInput().size(); i++) {
        StructureMapGroupInputComponent input = rg.target.getInput().get(i);
        StringType rdp = dependent.getVariable().get(i);
        String var = rdp.asStringValue();
        VariableMode mode = input.getMode() == StructureMapInputMode.SOURCE ? VariableMode.INPUT : VariableMode.OUTPUT;
        Base vv = vin.get(mode, var);
        if (// * once source, always source. but target can be treated as source at user convenient
        vv == null && mode == VariableMode.INPUT)
            vv = vin.get(VariableMode.OUTPUT, var);
        if (vv == null)
            throw new FHIRException("Rule '" + dependent.getName() + "' " + mode.toString() + " variable '" + input.getName() + "' named as '" + var + "' has no value");
        v.add(mode, input.getName(), vv);
    }
    executeGroup(indent + "  ", context, rg.targetMap, v, rg.target);
}
Also used : StringType(org.hl7.fhir.dstu3.model.StringType) StructureMapGroupInputComponent(org.hl7.fhir.dstu3.model.StructureMap.StructureMapGroupInputComponent) FHIRException(org.hl7.fhir.exceptions.FHIRException) ContactPoint(org.hl7.fhir.dstu3.model.ContactPoint) Base(org.hl7.fhir.dstu3.model.Base)

Example 3 with StructureMapGroupInputComponent

use of org.hl7.fhir.dstu3.model.StructureMap.StructureMapGroupInputComponent in project org.hl7.fhir.core by hapifhir.

the class StructureMapUtilities method executeDependency.

private void executeDependency(String indent, TransformContext context, StructureMap map, Variables vin, StructureMapGroupComponent group, StructureMapGroupRuleDependentComponent dependent) throws FHIRException {
    ResolvedGroup rg = resolveGroupReference(map, group, dependent.getName());
    if (rg.target.getInput().size() != dependent.getVariable().size()) {
        throw new FHIRException("Rule '" + dependent.getName() + "' has " + Integer.toString(rg.target.getInput().size()) + " but the invocation has " + Integer.toString(dependent.getVariable().size()) + " variables");
    }
    Variables v = new Variables();
    for (int i = 0; i < rg.target.getInput().size(); i++) {
        StructureMapGroupInputComponent input = rg.target.getInput().get(i);
        StringType rdp = dependent.getVariable().get(i);
        String var = rdp.asStringValue();
        VariableMode mode = input.getMode() == StructureMapInputMode.SOURCE ? VariableMode.INPUT : VariableMode.OUTPUT;
        Base vv = vin.get(mode, var);
        if (// * once source, always source. but target can be treated as source at user convenient
        vv == null && mode == VariableMode.INPUT)
            vv = vin.get(VariableMode.OUTPUT, var);
        if (vv == null)
            throw new FHIRException("Rule '" + dependent.getName() + "' " + mode.toString() + " variable '" + input.getName() + "' named as '" + var + "' has no value (vars = " + vin.summary() + ")");
        v.add(mode, input.getName(), vv);
    }
    executeGroup(indent + "  ", context, rg.targetMap, v, rg.target, false);
}
Also used : FHIRException(org.hl7.fhir.exceptions.FHIRException)

Example 4 with StructureMapGroupInputComponent

use of org.hl7.fhir.dstu3.model.StructureMap.StructureMapGroupInputComponent 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 : XhtmlNode(org.hl7.fhir.utilities.xhtml.XhtmlNode)

Example 5 with StructureMapGroupInputComponent

use of org.hl7.fhir.dstu3.model.StructureMap.StructureMapGroupInputComponent in project org.hl7.fhir.core by hapifhir.

the class StructureMapUtilities method analyse.

/**
 * Given a structure map, return a set of analyses on it.
 *
 * 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 Exception {
    ids.clear();
    StructureMapAnalysis result = new StructureMapAnalysis();
    TransformContext context = new TransformContext(appInfo);
    VariablesForProfiling vars = new VariablesForProfiling(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 : StructureMapGroupComponent(org.hl7.fhir.dstu3.model.StructureMap.StructureMapGroupComponent) StructureDefinition(org.hl7.fhir.dstu3.model.StructureDefinition) ProfileUtilities(org.hl7.fhir.dstu3.conformance.ProfileUtilities) StructureMapGroupInputComponent(org.hl7.fhir.dstu3.model.StructureMap.StructureMapGroupInputComponent) XhtmlNode(org.hl7.fhir.utilities.xhtml.XhtmlNode)

Aggregations

XhtmlNode (org.hl7.fhir.utilities.xhtml.XhtmlNode)8 StructureMapGroupInputComponent (org.hl7.fhir.dstu3.model.StructureMap.StructureMapGroupInputComponent)5 FHIRException (org.hl7.fhir.exceptions.FHIRException)5 StructureMapGroupInputComponent (org.hl7.fhir.r4.model.StructureMap.StructureMapGroupInputComponent)5 StructureMapGroupInputComponent (org.hl7.fhir.dstu2016may.model.StructureMap.StructureMapGroupInputComponent)3 StructureMapGroupRuleComponent (org.hl7.fhir.dstu3.model.StructureMap.StructureMapGroupRuleComponent)2 StructureMapGroupRuleComponent (org.hl7.fhir.r4.model.StructureMap.StructureMapGroupRuleComponent)2 Base (org.hl7.fhir.dstu2016may.model.Base)1 StringType (org.hl7.fhir.dstu2016may.model.StringType)1 StructureMap (org.hl7.fhir.dstu2016may.model.StructureMap)1 StructureMapGroupComponent (org.hl7.fhir.dstu2016may.model.StructureMap.StructureMapGroupComponent)1 StructureMapGroupRuleComponent (org.hl7.fhir.dstu2016may.model.StructureMap.StructureMapGroupRuleComponent)1 UriType (org.hl7.fhir.dstu2016may.model.UriType)1 ProfileUtilities (org.hl7.fhir.dstu3.conformance.ProfileUtilities)1 Base (org.hl7.fhir.dstu3.model.Base)1 ContactPoint (org.hl7.fhir.dstu3.model.ContactPoint)1 StringType (org.hl7.fhir.dstu3.model.StringType)1 StructureDefinition (org.hl7.fhir.dstu3.model.StructureDefinition)1 StructureMapGroupComponent (org.hl7.fhir.dstu3.model.StructureMap.StructureMapGroupComponent)1 ProfileUtilities (org.hl7.fhir.r4.conformance.ProfileUtilities)1