use of org.hl7.fhir.r4.model.StructureMap.StructureMapGroupComponent in project org.hl7.fhir.core by hapifhir.
the class StructureMapUtilities method transform.
public void transform(Object appInfo, Base source, StructureMap map, Base target) throws FHIRException {
TransformContext context = new TransformContext(appInfo);
log("Start Transform " + map.getUrl());
StructureMapGroupComponent g = map.getGroup().get(0);
Variables vars = new Variables();
vars.add(VariableMode.INPUT, getInputName(g, StructureMapInputMode.SOURCE, "source"), source);
vars.add(VariableMode.OUTPUT, getInputName(g, StructureMapInputMode.TARGET, "target"), target);
executeGroup("", context, map, vars, g);
if (target instanceof Element)
((Element) target).sort();
}
use of org.hl7.fhir.r4.model.StructureMap.StructureMapGroupComponent 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.r4.model.StructureMap.StructureMapGroupComponent in project org.hl7.fhir.core by hapifhir.
the class StructureMapUtilities method transform.
public void transform(Object appInfo, Base source, StructureMap map, Base target) throws FHIRException {
TransformContext context = new TransformContext(appInfo);
log("Start Transform " + map.getUrl());
StructureMapGroupComponent g = map.getGroup().get(0);
Variables vars = new Variables();
vars.add(VariableMode.INPUT, getInputName(g, StructureMapInputMode.SOURCE, "source"), source);
if (target != null)
vars.add(VariableMode.OUTPUT, getInputName(g, StructureMapInputMode.TARGET, "target"), target);
executeGroup("", context, map, vars, g, true);
if (target instanceof Element)
((Element) target).sort();
}
use of org.hl7.fhir.r4.model.StructureMap.StructureMapGroupComponent in project org.hl7.fhir.core by hapifhir.
the class StructureMapUtilities method determineTypeFromSourceType.
private String determineTypeFromSourceType(StructureMap map, StructureMapGroupComponent source, Base base, String[] types) throws FHIRException {
String type = base.fhirType();
String kn = "type^" + type;
if (source.hasUserData(kn))
return source.getUserString(kn);
ResolvedGroup res = new ResolvedGroup();
res.targetMap = null;
res.target = null;
for (StructureMapGroupComponent grp : map.getGroup()) {
if (matchesByType(map, grp, type)) {
if (res.targetMap == null) {
res.targetMap = map;
res.target = grp;
} else
throw new FHIRException("Multiple possible matches looking for default rule for '" + type + "'");
}
}
if (res.targetMap != null) {
String result = getActualType(res.targetMap, res.target.getInput().get(1).getType());
source.setUserData(kn, result);
return result;
}
for (UriType imp : map.getImport()) {
List<StructureMap> impMapList = findMatchingMaps(imp.getValue());
if (impMapList.size() == 0)
throw new FHIRException("Unable to find map(s) for " + imp.getValue());
for (StructureMap impMap : impMapList) {
if (!impMap.getUrl().equals(map.getUrl())) {
for (StructureMapGroupComponent grp : impMap.getGroup()) {
if (matchesByType(impMap, grp, type)) {
if (res.targetMap == null) {
res.targetMap = impMap;
res.target = grp;
} else
throw new FHIRException("Multiple possible matches for default rule for '" + type + "' in " + res.targetMap.getUrl() + " (" + res.target.getName() + ") and " + impMap.getUrl() + " (" + grp.getName() + ")");
}
}
}
}
}
if (res.target == null)
throw new FHIRException("No matches found for default rule for '" + type + "' from " + map.getUrl());
// should be .getType, but R2...
String result = getActualType(res.targetMap, res.target.getInput().get(1).getType());
source.setUserData(kn, result);
return result;
}
use of org.hl7.fhir.r4.model.StructureMap.StructureMapGroupComponent in project org.hl7.fhir.core by hapifhir.
the class StructureMapUtilities method groupToString.
public static String groupToString(StructureMapGroupComponent g) {
StringBuilder b = new StringBuilder();
renderGroup(b, g);
return b.toString();
}
Aggregations