use of org.hl7.fhir.r4.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;
}
}
use of org.hl7.fhir.r4.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());
}
}
}
use of org.hl7.fhir.r4.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();
}
}
use of org.hl7.fhir.r4.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);
}
use of org.hl7.fhir.r4.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;
}
Aggregations