use of org.hl7.fhir.r4.model.StructureMap.StructureMapGroupRuleComponent in project org.hl7.fhir.core by hapifhir.
the class StructureMapUtilities method parseTarget.
private void parseTarget(StructureMapGroupRuleComponent rule, FHIRLexer lexer) throws FHIRException {
StructureMapGroupRuleTargetComponent target = rule.addTarget();
target.setContext(lexer.take());
if (lexer.hasToken(".")) {
lexer.token(".");
target.setElement(lexer.take());
}
if (lexer.hasToken("=")) {
lexer.token("=");
boolean isConstant = lexer.isConstant(true);
String name = lexer.take();
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 {
while (!lexer.hasToken(")")) {
parseParameter(target, lexer);
if (!lexer.hasToken(")"))
lexer.token(",");
}
}
lexer.token(")");
} else {
target.setTransform(StructureMapTransform.COPY);
if (!isConstant) {
String id = name;
while (lexer.hasToken(".")) {
id = id + lexer.take() + lexer.take();
}
target.addParameter().setValue(new IdType(id));
} else
target.addParameter().setValue(readConstant(name, lexer));
}
}
if (lexer.hasToken("as")) {
lexer.take();
target.setVariable(lexer.take());
}
while (Utilities.existsInList(lexer.getCurrent(), "first", "last", "share", "only_one")) {
if (lexer.getCurrent().equals("share")) {
target.addListMode(StructureMapListMode.SHARE);
lexer.next();
target.setListRuleId(lexer.take());
} else if (lexer.getCurrent().equals("first"))
target.addListMode(StructureMapListMode.FIRST);
else
target.addListMode(StructureMapListMode.LAST);
lexer.next();
}
}
use of org.hl7.fhir.r4.model.StructureMap.StructureMapGroupRuleComponent in project org.hl7.fhir.core by hapifhir.
the class StructureMapUtilities method parseSource.
private void parseSource(StructureMapGroupRuleComponent rule, FHIRLexer lexer) throws FHIRException {
StructureMapGroupRuleSourceComponent source = rule.addSource();
if (lexer.hasToken("optional"))
lexer.next();
else
source.setRequired(true);
source.setContext(lexer.take());
if (lexer.hasToken(".")) {
lexer.token(".");
source.setElement(lexer.take());
}
if (Utilities.existsInList(lexer.getCurrent(), "first", "last", "only_one"))
if (lexer.getCurrent().equals("only_one")) {
source.setListMode(StructureMapListMode.SHARE);
lexer.take();
} else
source.setListMode(StructureMapListMode.fromCode(lexer.take()));
if (lexer.hasToken("as")) {
lexer.take();
source.setVariable(lexer.take());
}
if (lexer.hasToken("where")) {
lexer.take();
ExpressionNode node = fpe.parse(lexer);
source.setUserData(MAP_WHERE_EXPRESSION, node);
source.setCondition(node.toString());
}
if (lexer.hasToken("check")) {
lexer.take();
ExpressionNode node = fpe.parse(lexer);
source.setUserData(MAP_WHERE_CHECK, node);
source.setCheck(node.toString());
}
}
use of org.hl7.fhir.r4.model.StructureMap.StructureMapGroupRuleComponent in project org.hl7.fhir.core by hapifhir.
the class StructureMapUtilities method renderGroup.
private void renderGroup(StringBuilder b, StructureMapGroupComponent g) throws FHIRException {
b.append("group ");
b.append(g.getName());
if (g.hasExtends()) {
b.append(" extends ");
b.append(g.getExtends());
}
if (g.hasDocumentation())
renderDoco(b, g.getDocumentation());
b.append("\r\n");
for (StructureMapGroupInputComponent gi : g.getInput()) {
b.append(" input ");
b.append(gi.getName());
if (gi.hasType()) {
b.append(" : ");
b.append(gi.getType());
}
b.append(" as ");
b.append(gi.getMode().toCode());
b.append(";\r\n");
}
if (g.hasInput())
b.append("\r\n");
for (StructureMapGroupRuleComponent r : g.getRule()) {
renderRule(b, r, 2);
}
b.append("\r\nendgroup\r\n");
}
use of org.hl7.fhir.r4.model.StructureMap.StructureMapGroupRuleComponent in project org.hl7.fhir.core by hapifhir.
the class StructureMapUtilities method parseRule.
private void parseRule(List<StructureMapGroupRuleComponent> list, FHIRLexer lexer) throws FHIRException {
StructureMapGroupRuleComponent rule = new StructureMapGroupRuleComponent();
list.add(rule);
rule.setName(lexer.takeDottedToken());
lexer.token(":");
lexer.token("for");
boolean done = false;
while (!done) {
parseSource(rule, lexer);
done = !lexer.hasToken(",");
if (!done)
lexer.next();
}
if (lexer.hasToken("make")) {
lexer.token("make");
done = false;
while (!done) {
parseTarget(rule, lexer);
done = !lexer.hasToken(",");
if (!done)
lexer.next();
}
}
if (lexer.hasToken("then")) {
lexer.token("then");
if (lexer.hasToken("{")) {
lexer.token("{");
if (lexer.hasComment()) {
rule.setDocumentation(lexer.take().substring(2).trim());
}
lexer.skipComments();
while (!lexer.hasToken("}")) {
if (lexer.done())
throw lexer.error("premature termination expecting '}' in nested group");
parseRule(rule.getRule(), lexer);
}
lexer.token("}");
} else {
done = false;
while (!done) {
parseRuleReference(rule, lexer);
done = !lexer.hasToken(",");
if (!done)
lexer.next();
}
}
} else if (lexer.hasComment()) {
rule.setDocumentation(lexer.take().substring(2).trim());
}
lexer.skipComments();
}
Aggregations