public StructureMapGroupRuleTargetComponent copy() { StructureMapGroupRuleTargetComponent dst = new StructureMapGroupRuleTargetComponent(); copyValues(dst); dst.context = context == null ? null : context.copy(); dst.contextType = contextType == null ? null : contextType.copy(); dst.element = element == null ? null : element.copy(); dst.variable = variable == null ? null : variable.copy(); if (listMode != null) { dst.listMode = new ArrayList<Enumeration<StructureMapTargetListMode>>(); for (Enumeration<StructureMapTargetListMode> i : listMode) dst.listMode.add(i.copy()); }; dst.listRuleId = listRuleId == null ? null : listRuleId.copy(); dst.transform = transform == null ? null : transform.copy(); if (parameter != null) { dst.parameter = new ArrayList<StructureMapGroupRuleTargetParameterComponent>(); for (StructureMapGroupRuleTargetParameterComponent i : parameter) dst.parameter.add(i.copy()); }; return dst; }
@Override public Base addChild(String name) throws FHIRException { if (name.equals("context")) { throw new FHIRException("Cannot call addChild on a primitive type StructureMap.context"); } else if (name.equals("contextType")) { throw new FHIRException("Cannot call addChild on a primitive type StructureMap.contextType"); } else if (name.equals("element")) { throw new FHIRException("Cannot call addChild on a primitive type StructureMap.element"); } else if (name.equals("variable")) { throw new FHIRException("Cannot call addChild on a primitive type StructureMap.variable"); } else if (name.equals("listMode")) { throw new FHIRException("Cannot call addChild on a primitive type StructureMap.listMode"); } else if (name.equals("listRuleId")) { throw new FHIRException("Cannot call addChild on a primitive type StructureMap.listRuleId"); } else if (name.equals("transform")) { throw new FHIRException("Cannot call addChild on a primitive type StructureMap.transform"); } else if (name.equals("parameter")) { return addParameter(); } else return super.addChild(name); }
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)
private Base runTransform(String ruleId, TransformContext context, StructureMap map, StructureMapGroupComponent group, StructureMapGroupRuleTargetComponent tgt, Variables vars, Base dest, String element, String srcVar, boolean root) throws FHIRException { try { switch (tgt.getTransform()) { case CREATE : String tn; if (tgt.getParameter().isEmpty()) { throw new Error("Cannot determine type implicitly because there is no single input variable"); } else { tn = getParamStringNoNull(vars, tgt.getParameter().get(0), tgt.toString()); if (tgt.hasUserData("profile")) res.setUserData("profile", tgt.getUserData("profile")); return res; case COPY : return getParam(vars, tgt.getParameter().get(0)); case EVALUATE : ExpressionNode expr = (ExpressionNode) tgt.getUserData(MAP_EXPRESSION); if (expr == null) { expr = fpe.parse(getParamStringNoNull(vars, tgt.getParameter().get(1), tgt.toString())); tgt.setUserData(MAP_WHERE_EXPRESSION, expr); List<Base> v = fpe.evaluate(vars, null, tgt.getParameter().size() == 2 ? getParam(vars, tgt.getParameter().get(0)) : new BooleanType(false), expr); if (v.size() == 0) return null; String src = getParamString(vars, tgt.getParameter().get(0)); String len = getParamStringNoNull(vars, tgt.getParameter().get(1), tgt.toString()); if (Utilities.isInteger(len)) { int l = Integer.parseInt(len);
String start = lexer.take(); if (lexer.hasToken(".")) { target.setContext(start); target.setContextType(StructureMapContextType.VARIABLE); start = null; lexer.token("."); target.setElement(lexer.take()); if (lexer.hasToken("=")) { if (start != null) target.setContext(start); lexer.token("="); isConstant = lexer.isConstant(true); target.setTransform(StructureMapTransform.EVALUATE); ExpressionNode node = fpe.parse(lexer); target.setUserData(MAP_EXPRESSION, node); target.addParameter().setValue(new StringType(node.toString())); lexer.token(")"); } else if (lexer.hasToken("(")) { target.setTransform(StructureMapTransform.fromCode(name)); lexer.token("("); if (target.getTransform() == StructureMapTransform.EVALUATE) { parseParameter(target, lexer); lexer.token(","); ExpressionNode node = fpe.parse(lexer); target.setUserData(MAP_EXPRESSION, node); target.addParameter().setValue(new StringType(node.toString())); } else {
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)
executeDependency(indent+" ", context, map, v, group, dependent); } else if (rule.getSource().size() == 1 && rule.getSourceFirstRep().hasVariable() && rule.getTarget().size() == 1 && rule.getTargetFirstRep().hasVariable() && rule.getTargetFirstRep().getTransform() == StructureMapTransform.CREATE && !rule.getTargetFirstRep().hasParameter()) { Base tgt = v.get(VariableMode.OUTPUT, rule.getTargetFirstRep().getVariable()); String srcType = src.fhirType(); String tgtType = tgt.fhirType();
switch (hash) { case 951530927: // context this.context = castToId(value); // IdType return value; case -102839927: // contextType value = new StructureMapContextTypeEnumFactory().fromType(castToCode(value)); this.contextType = (Enumeration) value; // Enumeration<StructureMapContextType> return value; case -1662836996: // element this.element = castToString(value); // StringType return value; case -1249586564: // variable this.variable = castToId(value); // IdType return value; case 1345445729: // listMode value = new StructureMapTargetListModeEnumFactory().fromType(castToCode(value)); this.getListMode().add((Enumeration) value); // Enumeration<StructureMapTargetListMode> return value; case 337117045: // listRuleId this.listRuleId = castToId(value); // IdType return value; case 1052666732: // transform value = new StructureMapTransformEnumFactory().fromType(castToCode(value)); this.transform = (Enumeration) value; // Enumeration<StructureMapTransform> return value; case 1954460585: // parameter this.getParameter().add((StructureMapGroupRuleTargetParameterComponent) value); // StructureMapGroupRuleTargetParameterComponent return value; default: return super.setProperty(hash, name, value);
@Override public Base addChild(String name) throws FHIRException { if (name.equals("context")) { throw new FHIRException("Cannot call addChild on a primitive type StructureMap.context"); } else if (name.equals("contextType")) { throw new FHIRException("Cannot call addChild on a primitive type StructureMap.contextType"); } else if (name.equals("element")) { throw new FHIRException("Cannot call addChild on a primitive type StructureMap.element"); } else if (name.equals("variable")) { throw new FHIRException("Cannot call addChild on a primitive type StructureMap.variable"); } else if (name.equals("listMode")) { throw new FHIRException("Cannot call addChild on a primitive type StructureMap.listMode"); } else if (name.equals("listRuleId")) { throw new FHIRException("Cannot call addChild on a primitive type StructureMap.listRuleId"); } else if (name.equals("transform")) { throw new FHIRException("Cannot call addChild on a primitive type StructureMap.transform"); } else if (name.equals("parameter")) { return addParameter(); } else return super.addChild(name); }
public static org.hl7.fhir.r4.model.StructureMap.StructureMapGroupRuleTargetComponent convertStructureMapGroupRuleTargetComponent(org.hl7.fhir.dstu2016may.model.StructureMap.StructureMapGroupRuleTargetComponent src) throws FHIRException { if (src == null || src.isEmpty()) return null; org.hl7.fhir.r4.model.StructureMap.StructureMapGroupRuleTargetComponent tgt = new org.hl7.fhir.r4.model.StructureMap.StructureMapGroupRuleTargetComponent(); copyElement(src, tgt); if (src.hasContext()) tgt.setContext(src.getContext()); if (src.hasContextType()) tgt.setContextType(convertStructureMapContextType(src.getContextType())); if (src.hasElement()) tgt.setElement(src.getElement()); if (src.hasVariable()) tgt.setVariable(src.getVariable()); for (org.hl7.fhir.dstu2016may.model.Enumeration<org.hl7.fhir.dstu2016may.model.StructureMap.StructureMapListMode> t : src.getListMode()) tgt.addListMode(convertStructureMapTargetListMode(t.getValue())); if (src.hasListRuleId()) tgt.setListRuleId(src.getListRuleId()); if (src.hasTransform()) tgt.setTransform(convertStructureMapTransform(src.getTransform())); for (org.hl7.fhir.dstu2016may.model.StructureMap.StructureMapGroupRuleTargetParameterComponent t : src.getParameter()) tgt.addParameter(convertStructureMapGroupRuleTargetParameterComponent(t)); return tgt; }
public StructureMapGroupRuleTargetComponent copy() { StructureMapGroupRuleTargetComponent dst = new StructureMapGroupRuleTargetComponent(); copyValues(dst); dst.context = context == null ? null : context.copy(); dst.contextType = contextType == null ? null : contextType.copy(); dst.element = element == null ? null : element.copy(); dst.variable = variable == null ? null : variable.copy(); if (listMode != null) { dst.listMode = new ArrayList<Enumeration<StructureMapTargetListMode>>(); for (Enumeration<StructureMapTargetListMode> i : listMode) dst.listMode.add(i.copy()); }; dst.listRuleId = listRuleId == null ? null : listRuleId.copy(); dst.transform = transform == null ? null : transform.copy(); if (parameter != null) { dst.parameter = new ArrayList<StructureMapGroupRuleTargetParameterComponent>(); for (StructureMapGroupRuleTargetParameterComponent i : parameter) dst.parameter.add(i.copy()); }; return dst; }
@Override public Base setProperty(String name, Base value) throws FHIRException { if (name.equals("context")) { this.context = castToId(value); // IdType } else if (name.equals("contextType")) { value = new StructureMapContextTypeEnumFactory().fromType(castToCode(value)); this.contextType = (Enumeration) value; // Enumeration<StructureMapContextType> } else if (name.equals("element")) { this.element = castToString(value); // StringType } else if (name.equals("variable")) { this.variable = castToId(value); // IdType } else if (name.equals("listMode")) { value = new StructureMapTargetListModeEnumFactory().fromType(castToCode(value)); this.getListMode().add((Enumeration) value); } else if (name.equals("listRuleId")) { this.listRuleId = castToId(value); // IdType } else if (name.equals("transform")) { value = new StructureMapTransformEnumFactory().fromType(castToCode(value)); this.transform = (Enumeration) value; // Enumeration<StructureMapTransform> } else if (name.equals("parameter")) { this.getParameter().add((StructureMapGroupRuleTargetParameterComponent) value); } else return super.setProperty(name, value); return value; }
public static org.hl7.fhir.dstu2016may.model.StructureMap.StructureMapGroupRuleTargetComponent convertStructureMapGroupRuleTargetComponent(org.hl7.fhir.r4.model.StructureMap.StructureMapGroupRuleTargetComponent src) throws FHIRException { if (src == null || src.isEmpty()) return null; org.hl7.fhir.dstu2016may.model.StructureMap.StructureMapGroupRuleTargetComponent tgt = new org.hl7.fhir.dstu2016may.model.StructureMap.StructureMapGroupRuleTargetComponent(); copyElement(src, tgt); if (src.hasContext()) tgt.setContext(src.getContext()); if (src.hasContextType()) tgt.setContextType(convertStructureMapContextType(src.getContextType())); if (src.hasElement()) tgt.setElement(src.getElement()); if (src.hasVariable()) tgt.setVariable(src.getVariable()); for (Enumeration<org.hl7.fhir.r4.model.StructureMap.StructureMapTargetListMode> t : src.getListMode()) tgt.addListMode(convertStructureMapTargetListMode(t.getValue())); if (src.hasListRuleId()) tgt.setListRuleId(src.getListRuleId()); if (src.hasTransform()) tgt.setTransform(convertStructureMapTransform(src.getTransform())); for (org.hl7.fhir.r4.model.StructureMap.StructureMapGroupRuleTargetParameterComponent t : src.getParameter()) tgt.addParameter(convertStructureMapGroupRuleTargetParameterComponent(t)); return tgt; }
private void processTarget(String ruleId, TransformContext context, Variables vars, StructureMap map, StructureMapGroupComponent group, StructureMapGroupRuleTargetComponent tgt, String srcVar, boolean atRoot) throws FHIRException { Base dest = null; if (tgt.hasContext()) { dest = vars.get(VariableMode.OUTPUT, tgt.getContext()); if (dest == null) throw new FHIRException("Rule \""+ruleId+"\": target context not known: "+tgt.getContext()); if (!tgt.hasElement()) throw new FHIRException("Rule \""+ruleId+"\": Not supported yet"); } Base v = null; if (tgt.hasTransform()) { v = runTransform(ruleId, context, map, group, tgt, vars, dest, tgt.getElement(), srcVar, atRoot); if (v != null && dest != null) v = dest.setProperty(tgt.getElement().hashCode(), tgt.getElement(), v); // reset v because some implementations may have to rewrite v when setting the value } else if (dest != null) v = dest.makeProperty(tgt.getElement().hashCode(), tgt.getElement()); if (tgt.hasVariable() && v != null) vars.add(VariableMode.OUTPUT, tgt.getVariable(), v); }
@Override public Base makeProperty(int hash, String name) throws FHIRException { switch (hash) { case 951530927: return getContextElement(); case -102839927: return getContextTypeElement(); case -1662836996: return getElementElement(); case -1249586564: return getVariableElement(); case 1345445729: return addListModeElement(); case 337117045: return getListRuleIdElement(); case 1052666732: return getTransformElement(); case 1954460585: return addParameter(); default: return super.makeProperty(hash, name); } }
private void parseParameter(StructureMapGroupRuleTargetComponent target, FHIRLexer lexer) throws FHIRLexerException, FHIRFormatError { if (!lexer.isConstant(true)) { target.addParameter().setValue(new IdType(lexer.take())); } else if (lexer.isStringConstant()) target.addParameter().setValue(new StringType(lexer.readConstant("??"))); else { target.addParameter().setValue(readConstant(lexer.take(), lexer)); } }
private static boolean checkisSimple(StructureMapGroupRuleComponent r) { return (r.getSource().size() == 1 && r.getSourceFirstRep().hasElement() && r.getSourceFirstRep().hasVariable()) && (r.getTarget().size() == 1 && r.getTargetFirstRep().hasVariable() && (r.getTargetFirstRep().getTransform() == null || r.getTargetFirstRep().getTransform() == StructureMapTransform.CREATE) && r.getTargetFirstRep().getParameter().size() == 0) && (r.getDependent().size() == 0) && (r.getRule().size() == 0) ; }
/** * @return The first repetition of repeating field {@link #parameter}, creating it if it does not already exist */ public StructureMapGroupRuleTargetParameterComponent getParameterFirstRep() { if (getParameter().isEmpty()) { addParameter(); } return getParameter().get(0); }
public StructureMapGroupRuleTargetComponent addTarget() { //3 StructureMapGroupRuleTargetComponent t = new StructureMapGroupRuleTargetComponent(); if (this.target == null) this.target = new ArrayList<StructureMapGroupRuleTargetComponent>(); this.target.add(t); return t; }
private Base runTransform(String ruleId, TransformContext context, StructureMap map, StructureMapGroupComponent group, StructureMapGroupRuleTargetComponent tgt, Variables vars, Base dest, String element, String srcVar, boolean root) throws FHIRException { try { switch (tgt.getTransform()) { case CREATE : String tn; if (tgt.getParameter().isEmpty()) { throw new Error("Cannot determine type implicitly because there is no single input variable"); } else { tn = getParamStringNoNull(vars, tgt.getParameter().get(0), tgt.toString()); if (tgt.hasUserData("profile")) res.setUserData("profile", tgt.getUserData("profile")); return res; case COPY : return getParam(vars, tgt.getParameter().get(0)); case EVALUATE : ExpressionNode expr = (ExpressionNode) tgt.getUserData(MAP_EXPRESSION); if (expr == null) { expr = fpe.parse(getParamStringNoNull(vars, tgt.getParameter().get(1), tgt.toString())); tgt.setUserData(MAP_WHERE_EXPRESSION, expr); List<Base> v = fpe.evaluate(vars, null, tgt.getParameter().size() == 2 ? getParam(vars, tgt.getParameter().get(0)) : new BooleanType(false), expr); if (v.size() == 0) return null; String src = getParamString(vars, tgt.getParameter().get(0)); String len = getParamStringNoNull(vars, tgt.getParameter().get(1), tgt.toString()); if (Utilities.isInteger(len)) { int l = Integer.parseInt(len);