use of org.hl7.fhir.r4.model.StructureMap.StructureMapGroupRuleTargetComponent in project org.hl7.fhir.core by hapifhir.
the class StructureMapUtilities method runTransform.
private Base runTransform(TransformContext context, StructureMap map, StructureMapGroupRuleTargetComponent tgt, Variables vars) throws FHIRException {
switch(tgt.getTransform()) {
case CREATE:
return ResourceFactory.createResourceOrType(getParamString(vars, tgt.getParameter().get(0)));
case COPY:
return getParam(vars, tgt.getParameter().get(0));
case EVALUATE:
ExpressionNode expr = (ExpressionNode) tgt.getUserData(MAP_EXPRESSION);
if (expr == null) {
expr = fpe.parse(getParamString(vars, tgt.getParameter().get(1)));
tgt.setUserData(MAP_WHERE_EXPRESSION, expr);
}
List<Base> v = fpe.evaluate(null, null, getParam(vars, tgt.getParameter().get(0)), expr);
if (v.size() != 1)
throw new FHIRException("evaluation of " + expr.toString() + " returned " + Integer.toString(v.size()) + " objects");
return v.get(0);
case TRUNCATE:
String src = getParamString(vars, tgt.getParameter().get(0));
String len = getParamString(vars, tgt.getParameter().get(1));
if (Utilities.isInteger(len)) {
int l = Integer.parseInt(len);
if (src.length() > l)
src = src.substring(0, l);
}
return new StringType(src);
case ESCAPE:
throw new Error("Transform " + tgt.getTransform().toCode() + " not supported yet");
case CAST:
throw new Error("Transform " + tgt.getTransform().toCode() + " not supported yet");
case APPEND:
throw new Error("Transform " + tgt.getTransform().toCode() + " not supported yet");
case TRANSLATE:
return translate(context, map, vars, tgt.getParameter());
case REFERENCE:
throw new Error("Transform " + tgt.getTransform().toCode() + " not supported yet");
case DATEOP:
throw new Error("Transform " + tgt.getTransform().toCode() + " not supported yet");
case UUID:
return new IdType(UUID.randomUUID().toString());
case POINTER:
Base b = getParam(vars, tgt.getParameter().get(0));
if (b instanceof Resource)
return new UriType("urn:uuid:" + ((Resource) b).getId());
else
throw new FHIRException("Transform engine cannot point at an element of type " + b.fhirType());
default:
throw new Error("Transform Unknown: " + tgt.getTransform().toCode());
}
}
use of org.hl7.fhir.r4.model.StructureMap.StructureMapGroupRuleTargetComponent 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.StructureMapGroupRuleTargetComponent in project org.hl7.fhir.core by hapifhir.
the class StructureMapUtilities method targetToString.
public static String targetToString(StructureMapGroupRuleTargetComponent rt) {
StringBuilder b = new StringBuilder();
renderTarget(b, rt, false);
return b.toString();
}
use of org.hl7.fhir.r4.model.StructureMap.StructureMapGroupRuleTargetComponent in project org.hl7.fhir.core by hapifhir.
the class StructureMapUtilities method generateFixedValue.
private Type generateFixedValue(StructureMapGroupRuleTargetComponent tgt) {
if (!allParametersFixed(tgt))
return null;
if (!tgt.hasTransform())
return null;
switch(tgt.getTransform()) {
case COPY:
return tgt.getParameter().get(0).getValue();
case TRUNCATE:
return null;
// case APPEND:
case TRANSLATE:
return null;
// case EVALUATE,
case CC:
CodeableConcept cc = new CodeableConcept();
cc.addCoding(buildCoding(tgt.getParameter().get(0).getValue(), tgt.getParameter().get(1).getValue()));
return cc;
case C:
return buildCoding(tgt.getParameter().get(0).getValue(), tgt.getParameter().get(1).getValue());
case QTY:
return null;
// case CP,
default:
return null;
}
}
use of org.hl7.fhir.r4.model.StructureMap.StructureMapGroupRuleTargetComponent in project org.hl7.fhir.core by hapifhir.
the class StructureMapUtilities method analyseTransform.
private TypeDetails analyseTransform(TransformContext context, StructureMap map, StructureMapGroupRuleTargetComponent tgt, VariableForProfiling var, VariablesForProfiling vars) throws FHIRException {
switch(tgt.getTransform()) {
case CREATE:
String p = getParamString(vars, tgt.getParameter().get(0));
return new TypeDetails(CollectionStatus.SINGLETON, p);
case COPY:
return getParam(vars, tgt.getParameter().get(0));
case EVALUATE:
ExpressionNode expr = (ExpressionNode) tgt.getUserData(MAP_EXPRESSION);
if (expr == null) {
expr = fpe.parse(getParamString(vars, tgt.getParameter().get(tgt.getParameter().size() - 1)));
tgt.setUserData(MAP_WHERE_EXPRESSION, expr);
}
return fpe.check(vars, null, expr);
// // throw new Error("Transform "+tgt.getTransform().toCode()+" not supported yet");
case TRANSLATE:
return new TypeDetails(CollectionStatus.SINGLETON, "CodeableConcept");
case CC:
ProfiledType res = new ProfiledType("CodeableConcept");
if (tgt.getParameter().size() >= 2 && isParamId(vars, tgt.getParameter().get(1))) {
TypeDetails td = vars.get(null, getParamId(vars, tgt.getParameter().get(1))).property.types;
if (td != null && td.hasBinding())
// todo: do we need to check that there's no implicit translation her? I don't think we do...
res.addBinding(td.getBinding());
}
return new TypeDetails(CollectionStatus.SINGLETON, res);
case C:
return new TypeDetails(CollectionStatus.SINGLETON, "Coding");
case QTY:
return new TypeDetails(CollectionStatus.SINGLETON, "Quantity");
case REFERENCE:
VariableForProfiling vrs = vars.get(VariableMode.OUTPUT, getParamId(vars, tgt.getParameterFirstRep()));
if (vrs == null)
throw new FHIRException("Unable to resolve variable \"" + getParamId(vars, tgt.getParameterFirstRep()) + "\"");
String profile = vrs.property.getProfileProperty().getStructure().getUrl();
TypeDetails td = new TypeDetails(CollectionStatus.SINGLETON);
td.addType("Reference", profile);
return td;
// // throw new FHIRException("Transform engine cannot point at an element of type "+b.fhirType());
default:
throw new Error("Transform Unknown or not handled yet: " + tgt.getTransform().toCode());
}
}
Aggregations