use of org.hl7.fhir.r5.model.StructureMap in project org.hl7.fhir.core by hapifhir.
the class StructureMapUtilities method render.
public static String render(StructureMap map) {
StringBuilder b = new StringBuilder();
b.append("map \"");
b.append(map.getUrl());
b.append("\" = \"");
b.append(Utilities.escapeJava(map.getName()));
b.append("\"\r\n\r\n");
renderConceptMaps(b, map);
renderUses(b, map);
renderImports(b, map);
for (StructureMapGroupComponent g : map.getGroup()) renderGroup(b, g);
return b.toString();
}
use of org.hl7.fhir.r5.model.StructureMap in project org.hl7.fhir.core by hapifhir.
the class StructureMapUtilities method renderUses.
private static void renderUses(StringBuilder b, StructureMap map) {
for (StructureMapStructureComponent s : map.getStructure()) {
b.append("uses \"");
b.append(s.getUrl());
b.append("\" ");
if (s.hasAlias()) {
b.append("alias ");
b.append(s.getAlias());
b.append(" ");
}
b.append("as ");
b.append(s.getMode().toCode());
b.append("\r\n");
renderDoco(b, s.getDocumentation());
}
if (map.hasStructure())
b.append("\r\n");
}
use of org.hl7.fhir.r5.model.StructureMap in project org.hl7.fhir.core by hapifhir.
the class StructureMapUtilities method generateMapFromMappings.
public StructureMap generateMapFromMappings(StructureDefinition sd) throws IOException, FHIRException {
String id = getLogicalMappingId(sd);
if (id == null)
return null;
String prefix = ToolingExtensions.readStringExtension(sd, ToolingExtensions.EXT_MAPPING_PREFIX);
String suffix = ToolingExtensions.readStringExtension(sd, ToolingExtensions.EXT_MAPPING_SUFFIX);
if (prefix == null || suffix == null)
return null;
// we build this by text. Any element that has a mapping, we put it's mappings inside it....
StringBuilder b = new StringBuilder();
b.append(prefix);
ElementDefinition root = sd.getSnapshot().getElementFirstRep();
String m = getMapping(root, id);
if (m != null)
b.append(m + "\r\n");
addChildMappings(b, id, "", sd, root, false);
b.append("\r\n");
b.append(suffix);
b.append("\r\n");
StructureMap map = parse(b.toString());
map.setId(tail(map.getUrl()));
if (!map.hasStatus())
map.setStatus(PublicationStatus.DRAFT);
map.getText().setStatus(NarrativeStatus.GENERATED);
map.getText().setDiv(new XhtmlNode(NodeType.Element, "div"));
map.getText().getDiv().addTag("pre").addText(render(map));
return map;
}
use of org.hl7.fhir.r5.model.StructureMap in project org.hl7.fhir.core by hapifhir.
the class StructureMapUtilities method processTarget.
private void processTarget(String ruleId, TransformContext context, Variables vars, StructureMap map, StructureMapGroupComponent group, StructureMapGroupRuleTargetComponent tgt, String srcVar) throws FHIRException {
Base dest = null;
if (tgt.hasContext()) {
dest = vars.get(VariableMode.OUTPUT, tgt.getContext());
if (dest == null)
throw new FHIRException("Rule \"" + ruleId + "\": target context not known: " + tgt.getContext());
if (!tgt.hasElement())
throw new FHIRException("Rule \"" + ruleId + "\": Not supported yet");
}
Base v = null;
if (tgt.hasTransform()) {
v = runTransform(ruleId, context, map, group, tgt, vars, dest, tgt.getElement(), srcVar);
if (v != null && dest != null)
// reset v because some implementations may have to rewrite v when setting the value
v = dest.setProperty(tgt.getElement().hashCode(), tgt.getElement(), v);
} else if (dest != null)
v = dest.makeProperty(tgt.getElement().hashCode(), tgt.getElement());
if (tgt.hasVariable() && v != null)
vars.add(VariableMode.OUTPUT, tgt.getVariable(), v);
}
use of org.hl7.fhir.r5.model.StructureMap in project org.hl7.fhir.core by hapifhir.
the class StructureMapUtilities method analyseRule.
private void analyseRule(String indent, TransformContext context, StructureMap map, VariablesForProfiling vars, StructureMapGroupComponent group, StructureMapGroupRuleComponent rule, StructureMapAnalysis result) throws Exception {
log(indent + "Analyse rule : " + rule.getName());
XhtmlNode tr = result.summary.addTag("tr");
XhtmlNode xs = tr.addTag("td");
XhtmlNode xt = tr.addTag("td");
VariablesForProfiling srcVars = vars.copy();
if (rule.getSource().size() != 1)
throw new Exception("Rule \"" + rule.getName() + "\": not handled yet");
VariablesForProfiling source = analyseSource(rule.getName(), context, srcVars, rule.getSourceFirstRep(), xs);
TargetWriter tw = new TargetWriter();
for (StructureMapGroupRuleTargetComponent t : rule.getTarget()) {
analyseTarget(rule.getName(), context, source, map, t, rule.getSourceFirstRep().getVariable(), tw, result.profiles, rule.getName());
}
tw.commit(xt);
for (StructureMapGroupRuleComponent childrule : rule.getRule()) {
analyseRule(indent + " ", context, map, source, group, childrule, result);
}
// for (StructureMapGroupRuleDependentComponent dependent : rule.getDependent()) {
// executeDependency(indent+" ", context, map, v, group, dependent); // do we need group here?
// }
}
Aggregations