use of org.hl7.fhir.r4b.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();
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());
}
if (lexer.hasToken(":")) {
// type and cardinality
lexer.token(":");
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());
}
}
if (lexer.hasToken("default")) {
lexer.token("default");
source.setDefaultValue(new StringType(lexer.readConstant("default value")));
}
if (Utilities.existsInList(lexer.getCurrent(), "first", "last", "not_first", "not_last", "only_one"))
source.setListMode(StructureMapSourceListMode.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.r4b.model.StructureMap.StructureMapGroupRuleComponent in project org.hl7.fhir.core by hapifhir.
the class StructureMapUtilities method renderGroup.
private static void renderGroup(StringBuilder b, StructureMapGroupComponent g) {
b.append("group ");
b.append(g.getName());
b.append("(");
boolean first = true;
for (StructureMapGroupInputComponent gi : g.getInput()) {
if (first)
first = false;
else
b.append(", ");
b.append(gi.getMode().toCode());
b.append(" ");
b.append(gi.getName());
if (gi.hasType()) {
b.append(" : ");
b.append(gi.getType());
}
}
b.append(")");
if (g.hasExtends()) {
b.append(" extends ");
b.append(g.getExtends());
}
if (g.hasTypeMode()) {
switch(g.getTypeMode()) {
case TYPES:
b.append(" <<types>>");
break;
case TYPEANDTYPES:
b.append(" <<type+>>");
break;
// NONE, NULL
default:
}
}
b.append(" {\r\n");
for (StructureMapGroupRuleComponent r : g.getRule()) {
renderRule(b, r, 2);
}
b.append("}\r\n\r\n");
}
use of org.hl7.fhir.r4b.model.StructureMap.StructureMapGroupRuleComponent in project org.hl7.fhir.core by hapifhir.
the class StructureMapUtilities method ruleToString.
public static String ruleToString(StructureMapGroupRuleComponent r) {
StringBuilder b = new StringBuilder();
renderRule(b, r, 0);
return b.toString();
}
use of org.hl7.fhir.r4b.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();
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());
}
if (lexer.hasToken(":")) {
// type and cardinality
lexer.token(":");
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());
}
}
if (lexer.hasToken("default")) {
lexer.token("default");
source.setDefaultValue(new StringType(lexer.readConstant("default value")));
}
if (Utilities.existsInList(lexer.getCurrent(), "first", "last", "not_first", "not_last", "only_one"))
source.setListMode(StructureMapSourceListMode.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());
}
if (lexer.hasToken("log")) {
lexer.take();
ExpressionNode node = fpe.parse(lexer);
source.setUserData(MAP_WHERE_CHECK, node);
source.setLogMessage(node.toString());
}
}
use of org.hl7.fhir.r4b.model.StructureMap.StructureMapGroupRuleComponent in project org.hl7.fhir.core by hapifhir.
the class StructureMapUtilities method parseRuleReference.
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(")");
}
Aggregations