Search in sources :

Example 6 with StructureMapGroupRuleTargetParameterComponent

use of org.hl7.fhir.r5.model.StructureMap.StructureMapGroupRuleTargetParameterComponent in project org.hl7.fhir.core by hapifhir.

the class StructureMapUtilities method getParam.

private Base getParam(Variables vars, StructureMapGroupRuleTargetParameterComponent parameter) throws DefinitionException {
    Type p = parameter.getValue();
    if (!(p instanceof IdType))
        return p;
    else {
        String n = ((IdType) p).asStringValue();
        Base b = vars.get(VariableMode.INPUT, n);
        if (b == null)
            b = vars.get(VariableMode.OUTPUT, n);
        if (b == null)
            throw new DefinitionException("Variable " + n + " not found (" + vars.summary() + ")");
        return b;
    }
}
Also used : NodeType(org.hl7.fhir.utilities.xhtml.NodeType) PrimitiveType(org.hl7.fhir.r4.model.PrimitiveType) ProfiledType(org.hl7.fhir.r4.model.TypeDetails.ProfiledType) StringType(org.hl7.fhir.r4.model.StringType) IntegerType(org.hl7.fhir.r4.model.IntegerType) StructureMapContextType(org.hl7.fhir.r4.model.StructureMap.StructureMapContextType) BooleanType(org.hl7.fhir.r4.model.BooleanType) UriType(org.hl7.fhir.r4.model.UriType) Type(org.hl7.fhir.r4.model.Type) DecimalType(org.hl7.fhir.r4.model.DecimalType) CanonicalType(org.hl7.fhir.r4.model.CanonicalType) IdType(org.hl7.fhir.r4.model.IdType) CodeType(org.hl7.fhir.r4.model.CodeType) DefinitionException(org.hl7.fhir.exceptions.DefinitionException) Base(org.hl7.fhir.r4.model.Base) IdType(org.hl7.fhir.r4.model.IdType)

Example 7 with StructureMapGroupRuleTargetParameterComponent

use of org.hl7.fhir.r5.model.StructureMap.StructureMapGroupRuleTargetParameterComponent in project org.hl7.fhir.core by hapifhir.

the class StructureMapUtilities method renderTarget.

private static void renderTarget(StringBuilder b, StructureMapGroupRuleTargetComponent rt, boolean abbreviate) {
    if (rt.hasContext()) {
        if (rt.getContextType() == StructureMapContextType.TYPE)
            b.append("@");
        b.append(rt.getContext());
        if (rt.hasElement()) {
            b.append('.');
            b.append(rt.getElement());
        }
    }
    if (!abbreviate && rt.hasTransform()) {
        if (rt.hasContext())
            b.append(" = ");
        if (rt.getTransform() == StructureMapTransform.COPY && rt.getParameter().size() == 1) {
            renderTransformParam(b, rt.getParameter().get(0));
        } else if (rt.getTransform() == StructureMapTransform.EVALUATE && rt.getParameter().size() == 1) {
            b.append("(");
            b.append("\"" + ((StringType) rt.getParameter().get(0).getValue()).asStringValue() + "\"");
            b.append(")");
        } else if (rt.getTransform() == StructureMapTransform.EVALUATE && rt.getParameter().size() == 2) {
            b.append(rt.getTransform().toCode());
            b.append("(");
            b.append(((IdType) rt.getParameter().get(0).getValue()).asStringValue());
            b.append("\"" + ((StringType) rt.getParameter().get(1).getValue()).asStringValue() + "\"");
            b.append(")");
        } else {
            b.append(rt.getTransform().toCode());
            b.append("(");
            boolean first = true;
            for (StructureMapGroupRuleTargetParameterComponent rtp : rt.getParameter()) {
                if (first)
                    first = false;
                else
                    b.append(", ");
                renderTransformParam(b, rtp);
            }
            b.append(")");
        }
    }
    if (!abbreviate && rt.hasVariable()) {
        b.append(" as ");
        b.append(rt.getVariable());
    }
    for (Enumeration<StructureMapTargetListMode> lm : rt.getListMode()) {
        b.append(" ");
        b.append(lm.getValue().toCode());
        if (lm.getValue() == StructureMapTargetListMode.SHARE) {
            b.append(" ");
            b.append(rt.getListRuleId());
        }
    }
}
Also used : StructureMapTargetListMode(org.hl7.fhir.r4.model.StructureMap.StructureMapTargetListMode) StringType(org.hl7.fhir.r4.model.StringType) StructureMapGroupRuleTargetParameterComponent(org.hl7.fhir.r4.model.StructureMap.StructureMapGroupRuleTargetParameterComponent)

Example 8 with StructureMapGroupRuleTargetParameterComponent

use of org.hl7.fhir.r5.model.StructureMap.StructureMapGroupRuleTargetParameterComponent in project org.hl7.fhir.core by hapifhir.

the class StructureMapUtilities method getParam.

private TypeDetails getParam(VariablesForProfiling vars, StructureMapGroupRuleTargetParameterComponent parameter) throws DefinitionException {
    DataType p = parameter.getValue();
    if (!(p instanceof IdType))
        return new TypeDetails(CollectionStatus.SINGLETON, ProfileUtilities.sdNs(p.fhirType(), worker.getOverrideVersionNs()));
    else {
        String n = ((IdType) p).asStringValue();
        VariableForProfiling b = vars.get(VariableMode.INPUT, n);
        if (b == null)
            b = vars.get(VariableMode.OUTPUT, n);
        if (b == null)
            throw new DefinitionException("Variable " + n + " not found (" + vars.summary() + ")");
        return b.getProperty().getTypes();
    }
}
Also used : DefinitionException(org.hl7.fhir.exceptions.DefinitionException)

Example 9 with StructureMapGroupRuleTargetParameterComponent

use of org.hl7.fhir.r5.model.StructureMap.StructureMapGroupRuleTargetParameterComponent 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.getParameter().size()) {
        throw new FHIRException("Rule '" + dependent.getName() + "' has " + rg.target.getInput().size() + " but the invocation has " + dependent.getParameter().size() + " variables");
    }
    Variables v = new Variables();
    for (int i = 0; i < rg.target.getInput().size(); i++) {
        StructureMapGroupInputComponent input = rg.target.getInput().get(i);
        StructureMapGroupRuleTargetParameterComponent rdp = dependent.getParameter().get(i);
        String var = rdp.getValue().primitiveValue();
        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 10 with StructureMapGroupRuleTargetParameterComponent

use of org.hl7.fhir.r5.model.StructureMap.StructureMapGroupRuleTargetParameterComponent in project org.hl7.fhir.core by hapifhir.

the class StructureMap14_50 method convertStructureMapGroupRuleDependentComponent.

public static org.hl7.fhir.dstu2016may.model.StructureMap.StructureMapGroupRuleDependentComponent convertStructureMapGroupRuleDependentComponent(org.hl7.fhir.r5.model.StructureMap.StructureMapGroupRuleDependentComponent src) throws FHIRException {
    if (src == null || src.isEmpty())
        return null;
    org.hl7.fhir.dstu2016may.model.StructureMap.StructureMapGroupRuleDependentComponent tgt = new org.hl7.fhir.dstu2016may.model.StructureMap.StructureMapGroupRuleDependentComponent();
    ConversionContext14_50.INSTANCE.getVersionConvertor_14_50().copyElement(src, tgt);
    if (src.hasNameElement())
        tgt.setNameElement(Id14_50.convertId(src.getNameElement()));
    for (StructureMapGroupRuleTargetParameterComponent t : src.getParameter()) tgt.addVariable(t.getValue().primitiveValue());
    return tgt;
}
Also used : StructureMap(org.hl7.fhir.dstu2016may.model.StructureMap) StructureMapGroupRuleTargetParameterComponent(org.hl7.fhir.r5.model.StructureMap.StructureMapGroupRuleTargetParameterComponent)

Aggregations

DefinitionException (org.hl7.fhir.exceptions.DefinitionException)9 NodeType (org.hl7.fhir.utilities.xhtml.NodeType)6 FHIRException (org.hl7.fhir.exceptions.FHIRException)5 StringType (org.hl7.fhir.dstu3.model.StringType)4 FHIRFormatError (org.hl7.fhir.exceptions.FHIRFormatError)4 StringType (org.hl7.fhir.r4.model.StringType)4 CommaSeparatedStringBuilder (org.hl7.fhir.utilities.CommaSeparatedStringBuilder)4 BooleanType (org.hl7.fhir.dstu3.model.BooleanType)3 CodeType (org.hl7.fhir.dstu3.model.CodeType)3 DecimalType (org.hl7.fhir.dstu3.model.DecimalType)3 IdType (org.hl7.fhir.dstu3.model.IdType)3 IntegerType (org.hl7.fhir.dstu3.model.IntegerType)3 PrimitiveType (org.hl7.fhir.dstu3.model.PrimitiveType)3 StructureMapContextType (org.hl7.fhir.dstu3.model.StructureMap.StructureMapContextType)3 Type (org.hl7.fhir.dstu3.model.Type)3 ProfiledType (org.hl7.fhir.dstu3.model.TypeDetails.ProfiledType)3 UriType (org.hl7.fhir.dstu3.model.UriType)3 BooleanType (org.hl7.fhir.r4.model.BooleanType)3 CanonicalType (org.hl7.fhir.r4.model.CanonicalType)3 CodeType (org.hl7.fhir.r4.model.CodeType)3