use of org.hl7.fhir.r4.model.StructureMap.StructureMapGroupRuleTargetComponent 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();
String start = lexer.take();
if (lexer.hasToken(".")) {
target.setContext(start);
target.setContextType(StructureMapContextType.VARIABLE);
start = null;
lexer.token(".");
target.setElement(lexer.take());
}
String name;
boolean isConstant = false;
if (lexer.hasToken("=")) {
if (start != null)
target.setContext(start);
lexer.token("=");
isConstant = lexer.isConstant(true);
name = lexer.take();
} else
name = start;
if ("(".equals(name)) {
// inline fluentpath expression
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 {
while (!lexer.hasToken(")")) {
parseParameter(target, lexer);
if (!lexer.hasToken(")"))
lexer.token(",");
}
}
lexer.token(")");
} else if (name != null) {
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", "collate")) {
if (lexer.getCurrent().equals("share")) {
target.addListMode(StructureMapTargetListMode.SHARE);
lexer.next();
target.setListRuleId(lexer.take());
} else if (lexer.getCurrent().equals("first"))
target.addListMode(StructureMapTargetListMode.FIRST);
else
target.addListMode(StructureMapTargetListMode.LAST);
lexer.next();
}
}
use of org.hl7.fhir.r4.model.StructureMap.StructureMapGroupRuleTargetComponent in project org.hl7.fhir.core by hapifhir.
the class StructureMapUtilities method renderRule.
private static void renderRule(StringBuilder b, StructureMapGroupRuleComponent r, int indent) {
for (int i = 0; i < indent; i++) b.append(' ');
b.append(r.getName());
b.append(" : for ");
boolean canBeAbbreviated = checkisSimple(r);
boolean first = true;
for (StructureMapGroupRuleSourceComponent rs : r.getSource()) {
if (first)
first = false;
else
b.append(", ");
renderSource(b, rs, canBeAbbreviated);
}
if (r.getTarget().size() > 1) {
b.append(" make ");
first = true;
for (StructureMapGroupRuleTargetComponent rt : r.getTarget()) {
if (first)
first = false;
else
b.append(", ");
if (RENDER_MULTIPLE_TARGETS_ONELINE)
b.append(' ');
else {
b.append("\r\n");
for (int i = 0; i < indent + 4; i++) b.append(' ');
}
renderTarget(b, rt, false);
}
} else if (r.hasTarget()) {
b.append(" make ");
renderTarget(b, r.getTarget().get(0), canBeAbbreviated);
}
if (!canBeAbbreviated) {
if (r.hasRule()) {
b.append(" then {\r\n");
renderDoco(b, r.getDocumentation());
for (StructureMapGroupRuleComponent ir : r.getRule()) {
renderRule(b, ir, indent + 2);
}
for (int i = 0; i < indent; i++) b.append(' ');
b.append("}\r\n");
} else {
if (r.hasDependent()) {
b.append(" then ");
first = true;
for (StructureMapGroupRuleDependentComponent rd : r.getDependent()) {
if (first)
first = false;
else
b.append(", ");
b.append(rd.getName());
b.append("(");
boolean ifirst = true;
for (StringType rdp : rd.getVariable()) {
if (ifirst)
ifirst = false;
else
b.append(", ");
b.append(rdp.asStringValue());
}
b.append(")");
}
}
}
}
renderDoco(b, r.getDocumentation());
b.append("\r\n");
}
use of org.hl7.fhir.r4.model.StructureMap.StructureMapGroupRuleTargetComponent in project org.hl7.fhir.core by hapifhir.
the class StructureMapUtilities method updateProfile.
private PropertyWithType updateProfile(VariableForProfiling var, String element, TypeDetails type, StructureMap map, List<StructureDefinition> profiles, String sliceName, Type fixed, StructureMapGroupRuleTargetComponent tgt) throws FHIRException {
if (var == null) {
assert (Utilities.noString(element));
// 1. start the new structure definition
StructureDefinition sdn = worker.fetchResource(StructureDefinition.class, type.getType());
if (sdn == null)
throw new FHIRException("Unable to find definition for " + type.getType());
ElementDefinition edn = sdn.getSnapshot().getElementFirstRep();
PropertyWithType pn = createProfile(map, profiles, new PropertyWithType(sdn.getId(), new Property(worker, edn, sdn), null, type), sliceName, tgt);
// }
return pn;
} else {
assert (!Utilities.noString(element));
Property pvb = var.getProperty().getBaseProperty();
Property pvd = var.getProperty().getProfileProperty();
Property pc = pvb.getChild(element, var.property.types);
if (pc == null)
throw new DefinitionException("Unable to find a definition for " + pvb.getDefinition().getPath() + "." + element);
// the profile structure definition (derived)
StructureDefinition sd = var.getProperty().profileProperty.getStructure();
ElementDefinition ednew = sd.getDifferential().addElement();
ednew.setPath(var.getProperty().profileProperty.getDefinition().getPath() + "." + pc.getName());
ednew.setUserData("slice-name", sliceName);
ednew.setFixed(fixed);
for (ProfiledType pt : type.getProfiledTypes()) {
if (pt.hasBindings())
ednew.setBinding(pt.getBindings().get(0));
if (pt.getUri().startsWith("http://hl7.org/fhir/StructureDefinition/")) {
String t = pt.getUri().substring(40);
t = checkType(t, pc, pt.getProfiles());
if (t != null) {
if (pt.hasProfiles()) {
for (String p : pt.getProfiles()) if (t.equals("Reference"))
ednew.addType().setCode(t).setTargetProfile(p);
else
ednew.addType().setCode(t).setProfile(p);
} else
ednew.addType().setCode(t);
}
}
}
return new PropertyWithType(var.property.path + "." + element, pc, new Property(worker, ednew, sd), type);
}
}
use of org.hl7.fhir.r4.model.StructureMap.StructureMapGroupRuleTargetComponent in project org.hl7.fhir.core by hapifhir.
the class StructureMapUtilities method describeTransformCCorC.
@SuppressWarnings("rawtypes")
private String describeTransformCCorC(StructureMapGroupRuleTargetComponent tgt) throws FHIRException {
if (tgt.getParameter().size() < 2)
return null;
Type p1 = tgt.getParameter().get(0).getValue();
Type p2 = tgt.getParameter().get(1).getValue();
if (p1 instanceof IdType || p2 instanceof IdType)
return null;
if (!(p1 instanceof PrimitiveType) || !(p2 instanceof PrimitiveType))
return null;
String uri = ((PrimitiveType) p1).asStringValue();
String code = ((PrimitiveType) p2).asStringValue();
if (Utilities.noString(uri))
throw new FHIRException("Describe Transform, but the uri is blank");
if (Utilities.noString(code))
throw new FHIRException("Describe Transform, but the code is blank");
Coding c = buildCoding(uri, code);
return NarrativeGenerator.describeSystem(c.getSystem()) + "#" + c.getCode() + (c.hasDisplay() ? "(" + c.getDisplay() + ")" : "");
}
use of org.hl7.fhir.r4.model.StructureMap.StructureMapGroupRuleTargetComponent in project org.hl7.fhir.core by hapifhir.
the class StructureMapUtilities method generateFixedValue.
private Type generateFixedValue(StructureMapGroupRuleTargetComponent tgt) {
if (!allParametersFixed(tgt))
return null;
if (!tgt.hasTransform())
return null;
switch(tgt.getTransform()) {
case COPY:
return tgt.getParameter().get(0).getValue();
case TRUNCATE:
return null;
// case APPEND:
case TRANSLATE:
return null;
// case EVALUATE,
case CC:
CodeableConcept cc = new CodeableConcept();
cc.addCoding(buildCoding(tgt.getParameter().get(0).getValue(), tgt.getParameter().get(1).getValue()));
return cc;
case C:
return buildCoding(tgt.getParameter().get(0).getValue(), tgt.getParameter().get(1).getValue());
case QTY:
return null;
// case CP,
default:
return null;
}
}
Aggregations