public StructureMapGroupRuleSourceComponent addSource() { //3 StructureMapGroupRuleSourceComponent t = new StructureMapGroupRuleSourceComponent(); if (this.source == null) this.source = new ArrayList<StructureMapGroupRuleSourceComponent>(); this.source.add(t); return t; }
private List<Variables> processSource(String ruleId, TransformContext context, Variables vars, StructureMapGroupRuleSourceComponent src, String pathForErrors, String indent) throws FHIRException { List<Base> items; if (src.getContext().equals("@search")) { ExpressionNode expr = (ExpressionNode) src.getUserData(MAP_SEARCH_EXPRESSION); if (expr == null) { expr = fpe.parse(src.getElement()); src.setUserData(MAP_SEARCH_EXPRESSION, expr); } else { items = new ArrayList<Base>(); Base b = vars.get(VariableMode.INPUT, src.getContext()); if (b == null) throw new FHIRException("Unknown input variable "+src.getContext()+" in "+pathForErrors+" rule "+ruleId+" (vars = "+vars.summary()+")"); if (!src.hasElement()) items.add(b); else { getChildrenByName(b, src.getElement(), items); if (items.size() == 0 && src.hasDefaultValue()) items.add(src.getDefaultValue()); if (src.hasType()) { List<Base> remove = new ArrayList<Base>(); for (Base item : items) { if (item != null && !isType(item, src.getType())) { remove.add(item); if (src.hasCondition()) { ExpressionNode expr = (ExpressionNode) src.getUserData(MAP_WHERE_EXPRESSION); if (expr == null) {
rule.getSourceFirstRep().setVariable(AUTO_VAR_NAME); rule.getTargetFirstRep().setVariable(AUTO_VAR_NAME); rule.setName(lexer.take()); } else { if (rule.getSource().size() != 1 || !rule.getSourceFirstRep().hasElement()) throw lexer.error("Complex rules must have an explicit name"); if (rule.getSourceFirstRep().hasType()) rule.setName(rule.getSourceFirstRep().getElement()+"-"+rule.getSourceFirstRep().getType()); else rule.setName(rule.getSourceFirstRep().getElement());
private List<Variables> processSource(String ruleId, TransformContext context, Variables vars, StructureMapGroupRuleSourceComponent src, String pathForErrors, String indent) throws FHIRException { List<Base> items; if (src.getContext().equals("@search")) { ExpressionNode expr = (ExpressionNode) src.getUserData(MAP_SEARCH_EXPRESSION); if (expr == null) { expr = fpe.parse(src.getElement()); src.setUserData(MAP_SEARCH_EXPRESSION, expr); } else { items = new ArrayList<Base>(); Base b = vars.get(VariableMode.INPUT, src.getContext()); if (b == null) throw new FHIRException("Unknown input variable "+src.getContext()+" in "+pathForErrors+" rule "+ruleId+" (vars = "+vars.summary()+")"); if (!src.hasElement()) items.add(b); else { getChildrenByName(b, src.getElement(), items); if (items.size() == 0 && src.hasDefaultValue()) items.add(src.getDefaultValue()); if (src.hasType()) { List<Base> remove = new ArrayList<Base>(); for (Base item : items) { if (item != null && !isType(item, src.getType())) { remove.add(item); if (src.hasCondition()) { ExpressionNode expr = (ExpressionNode) src.getUserData(MAP_WHERE_EXPRESSION); if (expr == null) {
private void parseSource(StructureMapGroupRuleComponent rule, FHIRLexer lexer) throws FHIRException { StructureMapGroupRuleSourceComponent source = rule.addSource(); source.setContext(lexer.take()); if (source.getContext().equals("search") && lexer.hasToken("(")) { source.setContext("@search"); lexer.take(); ExpressionNode node = fpe.parse(lexer); source.setUserData(MAP_SEARCH_EXPRESSION, node); source.setElement(node.toString()); lexer.token(")"); } else if (lexer.hasToken(".")) { lexer.token("."); source.setElement(lexer.take()); source.setType(lexer.takeDottedToken()); if (!lexer.hasToken("as", "first", "last", "not_first", "not_last", "only_one", "default")) { source.setMin(lexer.takeInt()); lexer.token(".."); source.setMax(lexer.take()); source.setDefaultValue(new StringType(lexer.readConstant("default value"))); source.setListMode(StructureMapSourceListMode.fromCode(lexer.take())); source.setVariable(lexer.take()); source.setUserData(MAP_WHERE_EXPRESSION, node); source.setCondition(node.toString()); source.setUserData(MAP_WHERE_CHECK, node);
for (Variables v : source) { for (StructureMapGroupRuleTargetComponent t : rule.getTarget()) { processTarget(rule.getName(), context, v, map, group, t, rule.getSource().size() == 1 ? rule.getSourceFirstRep().getVariable() : null, atRoot); 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 src = v.get(VariableMode.INPUT, rule.getSourceFirstRep().getVariable()); Base tgt = v.get(VariableMode.OUTPUT, rule.getTargetFirstRep().getVariable()); String srcType = src.fhirType();
private static void renderSource(StringBuilder b, StructureMapGroupRuleSourceComponent rs, boolean abbreviate) { b.append(rs.getContext()); if (rs.getContext().equals("@search")) { b.append('('); b.append(rs.getElement()); b.append(')'); } else if (rs.hasElement()) { b.append('.'); b.append(rs.getElement()); if (rs.hasType()) { b.append(" : "); b.append(rs.getType()); if (rs.hasMin()) { b.append(" "); b.append(rs.getMin()); b.append(".."); b.append(rs.getMax()); if (rs.hasListMode()) { b.append(" "); b.append(rs.getListMode().toCode()); if (rs.hasDefaultValue()) { b.append(" default "); assert rs.getDefaultValue() instanceof StringType; b.append("\""+Utilities.escapeJson(((StringType) rs.getDefaultValue()).asStringValue())+"\""); if (!abbreviate && rs.hasVariable()) { b.append(" as ");
private VariablesForProfiling analyseSource(String ruleId, TransformContext context, VariablesForProfiling vars, StructureMapGroupRuleSourceComponent src, XhtmlNode td) throws Exception { VariableForProfiling var = vars.get(VariableMode.INPUT, src.getContext()); if (var == null) throw new FHIRException("Rule \""+ruleId+"\": Unknown input variable "+src.getContext()); PropertyWithType prop = var.getProperty(); boolean repeating = false; if (src.hasCondition()) { optional = true; if (src.hasElement()) { Property element = prop.getBaseProperty().getChild(prop.types.getType(), src.getElement()); if (element == null) throw new Exception("Rule \""+ruleId+"\": Unknown element name "+src.getElement()); if (element.getDefinition().getMin() == 0) optional = true; type.addType(pt); td.addText(prop.getPath()+"."+src.getElement()); if (src.hasVariable()) result.add(VariableMode.INPUT, src.getVariable(), new PropertyWithType(prop.getPath()+"."+src.getElement(), element, null, type)); return result; } else {
public static org.hl7.fhir.r4.model.StructureMap.StructureMapGroupRuleSourceComponent convertStructureMapGroupRuleSourceComponent(org.hl7.fhir.dstu2016may.model.StructureMap.StructureMapGroupRuleSourceComponent src) throws FHIRException { if (src == null || src.isEmpty()) return null; org.hl7.fhir.r4.model.StructureMap.StructureMapGroupRuleSourceComponent tgt = new org.hl7.fhir.r4.model.StructureMap.StructureMapGroupRuleSourceComponent(); copyElement(src, tgt); tgt.setMin(src.getRequired()? 1 : 0); if (src.getContextType().equals(StructureMap.StructureMapContextType.TYPE)) tgt.setType(src.getContext()); if (src.hasElement()) tgt.setElement(src.getElement()); if (src.hasListMode()) tgt.setListMode(convertStructureMapSourceListMode(src.getListMode())); if (src.hasVariable()) tgt.setVariable(src.getVariable()); if (src.hasCondition()) tgt.setCondition(src.getCondition()); if (src.hasCheck()) tgt.setCheck(src.getCheck()); return tgt; }
public StructureMapGroupRuleSourceComponent copy() { StructureMapGroupRuleSourceComponent dst = new StructureMapGroupRuleSourceComponent(); copyValues(dst); dst.context = context == null ? null : context.copy(); dst.min = min == null ? null : min.copy(); dst.max = max == null ? null : max.copy(); dst.type = type == null ? null : type.copy(); dst.defaultValue = defaultValue == null ? null : defaultValue.copy(); dst.element = element == null ? null : element.copy(); dst.listMode = listMode == null ? null : listMode.copy(); dst.variable = variable == null ? null : variable.copy(); dst.condition = condition == null ? null : condition.copy(); dst.check = check == null ? null : check.copy(); dst.logMessage = logMessage == null ? null : logMessage.copy(); return dst; }
public static org.hl7.fhir.dstu2016may.model.StructureMap.StructureMapGroupRuleSourceComponent convertStructureMapGroupRuleSourceComponent(org.hl7.fhir.r4.model.StructureMap.StructureMapGroupRuleSourceComponent src) throws FHIRException { if (src == null || src.isEmpty()) return null; org.hl7.fhir.dstu2016may.model.StructureMap.StructureMapGroupRuleSourceComponent tgt = new org.hl7.fhir.dstu2016may.model.StructureMap.StructureMapGroupRuleSourceComponent(); copyElement(src, tgt); tgt.setContextType(StructureMapContextType.TYPE); tgt.setContext(src.getContext()); if (src.hasElement()) tgt.setElement(src.getElement()); if (src.hasListMode()) tgt.setListMode(convertStructureMapSourceListMode(src.getListMode())); if (src.hasVariable()) tgt.setVariable(src.getVariable()); if (src.hasCondition()) tgt.setCondition(src.getCondition()); if (src.hasCheck()) tgt.setCheck(src.getCheck()); return tgt; }
private static boolean matchesName(String n, List<StructureMapGroupRuleSourceComponent> source) { if (source.size() != 1) return false; if (!source.get(0).hasElement()) return false; String s = source.get(0).getElement(); if (n.equals(s) || n.equals("\""+s+"\"")) return true; if (source.get(0).hasType()) { s = source.get(0).getElement()+"-"+source.get(0).getType(); if (n.equals(s) || n.equals("\""+s+"\"")) return true; } return false; }
private boolean isSimpleSyntax(StructureMapGroupRuleComponent rule) { return (rule.getSource().size() == 1 && rule.getSourceFirstRep().hasContext() && rule.getSourceFirstRep().hasElement() && !rule.getSourceFirstRep().hasVariable()) && (rule.getTarget().size() == 1 && rule.getTargetFirstRep().hasContext() && rule.getTargetFirstRep().hasElement() && !rule.getTargetFirstRep().hasVariable() && !rule.getTargetFirstRep().hasParameter()) && (rule.getDependent().size() == 0 && rule.getRule().size() == 0); }
public StructureMapGroupRuleSourceComponent addSource() { //3 StructureMapGroupRuleSourceComponent t = new StructureMapGroupRuleSourceComponent(); if (this.source == null) this.source = new ArrayList<StructureMapGroupRuleSourceComponent>(); this.source.add(t); return t; }
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) ; }
rule.getSourceFirstRep().setVariable(AUTO_VAR_NAME); rule.getTargetFirstRep().setVariable(AUTO_VAR_NAME); rule.setName(lexer.take()); } else { if (rule.getSource().size() != 1 || !rule.getSourceFirstRep().hasElement()) throw lexer.error("Complex rules must have an explicit name"); if (rule.getSourceFirstRep().hasType()) rule.setName(rule.getSourceFirstRep().getElement()+"-"+rule.getSourceFirstRep().getType()); else rule.setName(rule.getSourceFirstRep().getElement());
private void parseSource(StructureMapGroupRuleComponent rule, FHIRLexer lexer) throws FHIRException { StructureMapGroupRuleSourceComponent source = rule.addSource(); source.setContext(lexer.take()); if (source.getContext().equals("search") && lexer.hasToken("(")) { source.setContext("@search"); lexer.take(); ExpressionNode node = fpe.parse(lexer); source.setUserData(MAP_SEARCH_EXPRESSION, node); source.setElement(node.toString()); lexer.token(")"); } else if (lexer.hasToken(".")) { lexer.token("."); source.setElement(lexer.take()); source.setType(lexer.takeDottedToken()); if (!lexer.hasToken("as", "first", "last", "not_first", "not_last", "only_one", "default")) { source.setMin(lexer.takeInt()); lexer.token(".."); source.setMax(lexer.take()); source.setDefaultValue(new StringType(lexer.readConstant("default value"))); source.setListMode(StructureMapSourceListMode.fromCode(lexer.take())); source.setVariable(lexer.take()); source.setUserData(MAP_WHERE_EXPRESSION, node); source.setCondition(node.toString()); source.setUserData(MAP_WHERE_CHECK, node);
private static void renderSource(StringBuilder b, StructureMapGroupRuleSourceComponent rs, boolean abbreviate) { b.append(rs.getContext()); if (rs.getContext().equals("@search")) { b.append('('); b.append(rs.getElement()); b.append(')'); } else if (rs.hasElement()) { b.append('.'); b.append(rs.getElement()); if (rs.hasType()) { b.append(" : "); b.append(rs.getType()); if (rs.hasMin()) { b.append(" "); b.append(rs.getMin()); b.append(".."); b.append(rs.getMax()); if (rs.hasListMode()) { b.append(" "); b.append(rs.getListMode().toCode()); if (rs.hasDefaultValue()) { b.append(" default "); assert rs.getDefaultValue() instanceof StringType; b.append("\""+Utilities.escapeJson(((StringType) rs.getDefaultValue()).asStringValue())+"\""); if (!abbreviate && rs.hasVariable()) { b.append(" as ");
private VariablesForProfiling analyseSource(String ruleId, TransformContext context, VariablesForProfiling vars, StructureMapGroupRuleSourceComponent src, XhtmlNode td) throws Exception { VariableForProfiling var = vars.get(VariableMode.INPUT, src.getContext()); if (var == null) throw new FHIRException("Rule \""+ruleId+"\": Unknown input variable "+src.getContext()); PropertyWithType prop = var.getProperty(); boolean repeating = false; if (src.hasCondition()) { optional = true; if (src.hasElement()) { Property element = prop.getBaseProperty().getChild(prop.types.getType(), src.getElement()); if (element == null) throw new Exception("Rule \""+ruleId+"\": Unknown element name "+src.getElement()); if (element.getDefinition().getMin() == 0) optional = true; type.addType(pt); td.addText(prop.getPath()+"."+src.getElement()); if (src.hasVariable()) result.add(VariableMode.INPUT, src.getVariable(), new PropertyWithType(prop.getPath()+"."+src.getElement(), element, null, type)); return result; } else {
for (Variables v : source) { for (StructureMapGroupRuleTargetComponent t : rule.getTarget()) { processTarget(rule.getName(), context, v, map, group, t, rule.getSource().size() == 1 ? rule.getSourceFirstRep().getVariable() : null, atRoot); 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 src = v.get(VariableMode.INPUT, rule.getSourceFirstRep().getVariable()); Base tgt = v.get(VariableMode.OUTPUT, rule.getTargetFirstRep().getVariable()); String srcType = src.fhirType();