use of org.hl7.fhir.r4.model.StructureMap.StructureMapGroupRuleTargetParameterComponent in project org.hl7.fhir.core by hapifhir.
the class StructureMapUtilities method translate.
private Base translate(TransformContext context, StructureMap map, Variables vars, List<StructureMapGroupRuleTargetParameterComponent> parameter) throws FHIRException {
Base src = getParam(vars, parameter.get(0));
String id = getParamString(vars, parameter.get(1));
String fld = parameter.size() > 2 ? getParamString(vars, parameter.get(2)) : null;
return translate(context, map, src, id, fld);
}
use of org.hl7.fhir.r4.model.StructureMap.StructureMapGroupRuleTargetParameterComponent in project org.hl7.fhir.core by hapifhir.
the class StructureMapUtilities method paramToString.
public static String paramToString(StructureMapGroupRuleTargetParameterComponent rtp) {
StringBuilder b = new StringBuilder();
renderTransformParam(b, rtp);
return b.toString();
}
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 {
DataType 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 analyseTarget.
private void analyseTarget(String ruleId, TransformContext context, VariablesForProfiling vars, StructureMap map, StructureMapGroupRuleTargetComponent tgt, String tv, TargetWriter tw, List<StructureDefinition> profiles, String sliceName) throws FHIRException {
VariableForProfiling var = null;
if (tgt.hasContext()) {
var = vars.get(VariableMode.OUTPUT, tgt.getContext());
if (var == null)
throw new FHIRException("Rule \"" + ruleId + "\": target context not known: " + tgt.getContext());
if (!tgt.hasElement())
throw new FHIRException("Rule \"" + ruleId + "\": Not supported yet");
}
TypeDetails type = null;
if (tgt.hasTransform()) {
type = analyseTransform(context, map, tgt, var, vars);
} else {
Property vp = var.getProperty().getBaseProperty().getChild(tgt.getElement(), tgt.getElement());
if (vp == null)
throw new FHIRException("Unknown Property " + tgt.getElement() + " on " + var.getProperty().getPath());
type = new TypeDetails(CollectionStatus.SINGLETON, vp.getType(tgt.getElement()));
}
if (tgt.getTransform() == StructureMapTransform.CREATE) {
String s = getParamString(vars, tgt.getParameter().get(0));
if (worker.getResourceNames().contains(s))
tw.newResource(tgt.getVariable(), s);
} else {
boolean mapsSrc = false;
for (StructureMapGroupRuleTargetParameterComponent p : tgt.getParameter()) {
DataType pr = p.getValue();
if (pr instanceof IdType && ((IdType) pr).asStringValue().equals(tv))
mapsSrc = true;
}
if (mapsSrc) {
if (var == null)
throw new Error("Rule \"" + ruleId + "\": Attempt to assign with no context");
tw.valueAssignment(tgt.getContext(), var.getProperty().getPath() + "." + tgt.getElement() + getTransformSuffix(tgt.getTransform()));
} else if (tgt.hasContext()) {
if (isSignificantElement(var.getProperty(), tgt.getElement())) {
String td = describeTransform(tgt);
if (td != null)
tw.keyAssignment(tgt.getContext(), var.getProperty().getPath() + "." + tgt.getElement() + " = " + td);
}
}
}
DataType fixed = generateFixedValue(tgt);
PropertyWithType prop = updateProfile(var, tgt.getElement(), type, map, profiles, sliceName, fixed, tgt);
if (tgt.hasVariable())
if (tgt.hasElement())
vars.add(VariableMode.OUTPUT, tgt.getVariable(), prop);
else
vars.add(VariableMode.OUTPUT, tgt.getVariable(), prop);
}
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();
}
}
Aggregations