public StructureMapGroupRuleComponent copy() { StructureMapGroupRuleComponent dst = new StructureMapGroupRuleComponent(); copyValues(dst); dst.name = name == null ? null : name.copy(); if (source != null) { dst.source = new ArrayList<StructureMapGroupRuleSourceComponent>(); for (StructureMapGroupRuleSourceComponent i : source) dst.source.add(i.copy()); }; if (target != null) { dst.target = new ArrayList<StructureMapGroupRuleTargetComponent>(); for (StructureMapGroupRuleTargetComponent i : target) dst.target.add(i.copy()); }; if (rule != null) { dst.rule = new ArrayList<StructureMapGroupRuleComponent>(); for (StructureMapGroupRuleComponent i : rule) dst.rule.add(i.copy()); }; if (dependent != null) { dst.dependent = new ArrayList<StructureMapGroupRuleDependentComponent>(); for (StructureMapGroupRuleDependentComponent i : dependent) dst.dependent.add(i.copy()); }; dst.documentation = documentation == null ? null : documentation.copy(); return dst; }
@Override public Base addChild(String name) throws FHIRException { if (name.equals("name")) { throw new FHIRException("Cannot call addChild on a primitive type StructureMap.name"); } else if (name.equals("source")) { return addSource(); } else if (name.equals("target")) { return addTarget(); } else if (name.equals("rule")) { return addRule(); } else if (name.equals("dependent")) { return addDependent(); } else if (name.equals("documentation")) { throw new FHIRException("Cannot call addChild on a primitive type StructureMap.documentation"); } else return super.addChild(name); }
for (StructureMapGroupRuleSourceComponent rs : r.getSource()) { if (first) first = false; if (r.getTarget().size() > 1) { b.append(" -> "); first = true; for (StructureMapGroupRuleTargetComponent rt : r.getTarget()) { if (first) first = false; } else if (r.hasTarget()) { b.append(" -> "); renderTarget(b, r.getTarget().get(0), canBeAbbreviated); if (r.hasRule()) { b.append(" then {\r\n"); renderDoco(b, r.getDocumentation()); for (StructureMapGroupRuleComponent ir : r.getRule()) { renderRule(b, ir, indent+2); b.append("}"); } else { if (r.hasDependent()) { b.append(" then "); first = true; for (StructureMapGroupRuleDependentComponent rd : r.getDependent()) { if (first) first = false;
private void parseTarget(StructureMapGroupRuleComponent rule, FHIRLexer lexer) throws FHIRException { StructureMapGroupRuleTargetComponent target = rule.addTarget(); String start = lexer.take(); if (lexer.hasToken(".")) {
private void parseRule(StructureMap map, List<StructureMapGroupRuleComponent> list, FHIRLexer lexer, boolean newFmt) throws FHIRException { StructureMapGroupRuleComponent rule = new StructureMapGroupRuleComponent(); list.add(rule); if (!newFmt) { rule.setName(lexer.takeDottedToken()); lexer.token(":"); lexer.token("for"); lexer.token("{"); if (lexer.hasComment()) { rule.setDocumentation(lexer.take().substring(2).trim()); if (lexer.done()) throw lexer.error("premature termination expecting '}' in nested group"); parseRule(map, rule.getRule(), lexer, newFmt); rule.setDocumentation(lexer.take().substring(2).trim()); rule.getSourceFirstRep().setVariable(AUTO_VAR_NAME); rule.getTargetFirstRep().setVariable(AUTO_VAR_NAME); rule.getTargetFirstRep().setTransform(StructureMapTransform.CREATE); // with no parameter - e.g. imply what is to be created 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());
for (StructureMapGroupRuleSourceComponent rs : r.getSource()) { if (first) first = false; if (r.getTarget().size() > 1) { b.append(" -> "); first = true; for (StructureMapGroupRuleTargetComponent rt : r.getTarget()) { if (first) first = false; } else if (r.hasTarget()) { b.append(" -> "); renderTarget(b, r.getTarget().get(0), canBeAbbreviated); if (r.hasRule()) { b.append(" then {\r\n"); renderDoco(b, r.getDocumentation()); for (StructureMapGroupRuleComponent ir : r.getRule()) { renderRule(b, ir, indent+2); b.append("}"); } else { if (r.hasDependent()) { b.append(" then "); first = true; for (StructureMapGroupRuleDependentComponent rd : r.getDependent()) { if (first) first = false;
private void parseSource(StructureMapGroupRuleComponent rule, FHIRLexer lexer) throws FHIRException { StructureMapGroupRuleSourceComponent source = rule.addSource(); source.setContext(lexer.take()); if (source.getContext().equals("search") && lexer.hasToken("(")) {
private void executeRule(String indent, TransformContext context, StructureMap map, Variables vars, StructureMapGroupComponent group, StructureMapGroupRuleComponent rule, boolean atRoot) throws FHIRException { log(indent+"rule : "+rule.getName()+"; vars = "+vars.summary()); Variables srcVars = vars.copy(); if (rule.getSource().size() != 1) throw new FHIRException("Rule \""+rule.getName()+"\": not handled yet"); List<Variables> source = processSource(rule.getName(), context, srcVars, rule.getSource().get(0), map.getUrl(), indent); if (source != null) { 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); if (rule.hasRule()) { for (StructureMapGroupRuleComponent childrule : rule.getRule()) { executeRule(indent +" ", context, map, v, group, childrule, false); } else if (rule.hasDependent()) { for (StructureMapGroupRuleDependentComponent dependent : rule.getDependent()) { 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(); String tgtType = tgt.fhirType(); ResolvedGroup defGroup = resolveGroupByTypes(map, rule.getName(), group, srcType, tgtType); Variables vdef = new Variables(); vdef.add(VariableMode.INPUT, defGroup.target.getInput().get(0).getName(), src);
public StructureMapGroupRuleComponent copy() { StructureMapGroupRuleComponent dst = new StructureMapGroupRuleComponent(); copyValues(dst); dst.name = name == null ? null : name.copy(); if (source != null) { dst.source = new ArrayList<StructureMapGroupRuleSourceComponent>(); for (StructureMapGroupRuleSourceComponent i : source) dst.source.add(i.copy()); }; if (target != null) { dst.target = new ArrayList<StructureMapGroupRuleTargetComponent>(); for (StructureMapGroupRuleTargetComponent i : target) dst.target.add(i.copy()); }; if (rule != null) { dst.rule = new ArrayList<StructureMapGroupRuleComponent>(); for (StructureMapGroupRuleComponent i : rule) dst.rule.add(i.copy()); }; if (dependent != null) { dst.dependent = new ArrayList<StructureMapGroupRuleDependentComponent>(); for (StructureMapGroupRuleDependentComponent i : dependent) dst.dependent.add(i.copy()); }; dst.documentation = documentation == null ? null : documentation.copy(); return dst; }
@Override public Base setProperty(int hash, String name, Base value) throws FHIRException { switch (hash) { case 3373707: // name this.name = castToId(value); // IdType return value; case -896505829: // source this.getSource().add((StructureMapGroupRuleSourceComponent) value); // StructureMapGroupRuleSourceComponent return value; case -880905839: // target this.getTarget().add((StructureMapGroupRuleTargetComponent) value); // StructureMapGroupRuleTargetComponent return value; case 3512060: // rule this.getRule().add((StructureMapGroupRuleComponent) value); // StructureMapGroupRuleComponent return value; case -1109226753: // dependent this.getDependent().add((StructureMapGroupRuleDependentComponent) value); // StructureMapGroupRuleDependentComponent return value; case 1587405498: // documentation this.documentation = castToString(value); // StringType return value; default: return super.setProperty(hash, name, value); } }
@Override public Base addChild(String name) throws FHIRException { if (name.equals("name")) { throw new FHIRException("Cannot call addChild on a primitive type StructureMap.name"); } else if (name.equals("source")) { return addSource(); } else if (name.equals("target")) { return addTarget(); } else if (name.equals("rule")) { return addRule(); } else if (name.equals("dependent")) { return addDependent(); } else if (name.equals("documentation")) { throw new FHIRException("Cannot call addChild on a primitive type StructureMap.documentation"); } else return super.addChild(name); }
public static org.hl7.fhir.dstu2016may.model.StructureMap.StructureMapGroupRuleComponent convertStructureMapGroupRuleComponent(org.hl7.fhir.r4.model.StructureMap.StructureMapGroupRuleComponent src) throws FHIRException { if (src == null || src.isEmpty()) return null; org.hl7.fhir.dstu2016may.model.StructureMap.StructureMapGroupRuleComponent tgt = new org.hl7.fhir.dstu2016may.model.StructureMap.StructureMapGroupRuleComponent(); copyElement(src, tgt); tgt.setName(src.getName()); for (org.hl7.fhir.r4.model.StructureMap.StructureMapGroupRuleSourceComponent t : src.getSource()) tgt.addSource(convertStructureMapGroupRuleSourceComponent(t)); for (org.hl7.fhir.r4.model.StructureMap.StructureMapGroupRuleTargetComponent t : src.getTarget()) tgt.addTarget(convertStructureMapGroupRuleTargetComponent(t)); for (org.hl7.fhir.r4.model.StructureMap.StructureMapGroupRuleComponent t : src.getRule()) tgt.addRule(convertStructureMapGroupRuleComponent(t)); for (org.hl7.fhir.r4.model.StructureMap.StructureMapGroupRuleDependentComponent t : src.getDependent()) tgt.addDependent(convertStructureMapGroupRuleDependentComponent(t)); if (src.hasDocumentation()) tgt.setDocumentation(src.getDocumentation()); return tgt; }
@Override public Base setProperty(String name, Base value) throws FHIRException { if (name.equals("name")) { this.name = castToId(value); // IdType } else if (name.equals("source")) { this.getSource().add((StructureMapGroupRuleSourceComponent) value); } else if (name.equals("target")) { this.getTarget().add((StructureMapGroupRuleTargetComponent) value); } else if (name.equals("rule")) { this.getRule().add((StructureMapGroupRuleComponent) value); } else if (name.equals("dependent")) { this.getDependent().add((StructureMapGroupRuleDependentComponent) value); } else if (name.equals("documentation")) { this.documentation = castToString(value); // StringType } else return super.setProperty(name, value); return value; }
public static org.hl7.fhir.r4.model.StructureMap.StructureMapGroupRuleComponent convertStructureMapGroupRuleComponent(org.hl7.fhir.dstu2016may.model.StructureMap.StructureMapGroupRuleComponent src) throws FHIRException { if (src == null || src.isEmpty()) return null; org.hl7.fhir.r4.model.StructureMap.StructureMapGroupRuleComponent tgt = new org.hl7.fhir.r4.model.StructureMap.StructureMapGroupRuleComponent(); copyElement(src, tgt); tgt.setName(src.getName()); for (org.hl7.fhir.dstu2016may.model.StructureMap.StructureMapGroupRuleSourceComponent t : src.getSource()) tgt.addSource(convertStructureMapGroupRuleSourceComponent(t)); for (org.hl7.fhir.dstu2016may.model.StructureMap.StructureMapGroupRuleTargetComponent t : src.getTarget()) tgt.addTarget(convertStructureMapGroupRuleTargetComponent(t)); for (org.hl7.fhir.dstu2016may.model.StructureMap.StructureMapGroupRuleComponent t : src.getRule()) tgt.addRule(convertStructureMapGroupRuleComponent(t)); for (org.hl7.fhir.dstu2016may.model.StructureMap.StructureMapGroupRuleDependentComponent t : src.getDependent()) tgt.addDependent(convertStructureMapGroupRuleDependentComponent(t)); if (src.hasDocumentation()) tgt.setDocumentation(src.getDocumentation()); return tgt; }
private void parseRuleReference(StructureMapGroupRuleComponent rule, FHIRLexer lexer) throws FHIRLexerException { StructureMapGroupRuleDependentComponent ref = rule.addDependent(); ref.setName(lexer.take()); lexer.token("("); boolean done = false; while (!done) { ref.addVariable(lexer.take()); done = !lexer.hasToken(","); if (!done) lexer.next(); } lexer.token(")"); }
public StructureMapGroupRuleComponent addRule() { //3 StructureMapGroupRuleComponent t = new StructureMapGroupRuleComponent(); if (this.rule == null) this.rule = new ArrayList<StructureMapGroupRuleComponent>(); this.rule.add(t); return t; }
public StructureMapGroupRuleComponent addRule() { //3 StructureMapGroupRuleComponent t = new StructureMapGroupRuleComponent(); if (this.rule == null) this.rule = new ArrayList<StructureMapGroupRuleComponent>(); this.rule.add(t); return t; }
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); }