use of org.hl7.fhir.r4b.model.StructureMap.StructureMapGroupRuleSourceComponent in project org.hl7.fhir.core by hapifhir.
the class StructureMapUtilities method analyseSource.
private List<Variables> analyseSource(TransformContext context, Variables vars, StructureMapGroupRuleSourceComponent src) throws Exception {
Base b = vars.get(VariableMode.INPUT, src.getContext());
if (b == null)
throw new FHIRException("Unknown input variable " + src.getContext());
if (src.hasCondition()) {
ExpressionNode expr = (ExpressionNode) src.getUserData(MAP_WHERE_EXPRESSION);
if (expr == null) {
expr = fpe.parse(src.getCondition());
// fpe.check(context.appInfo, ??, ??, expr)
src.setUserData(MAP_WHERE_EXPRESSION, expr);
}
if (!fpe.evaluateToBoolean(null, b, expr))
return null;
}
if (src.hasCheck()) {
ExpressionNode expr = (ExpressionNode) src.getUserData(MAP_WHERE_CHECK);
if (expr == null) {
expr = fpe.parse(src.getCondition());
// fpe.check(context.appInfo, ??, ??, expr)
src.setUserData(MAP_WHERE_CHECK, expr);
}
if (!fpe.evaluateToBoolean(null, b, expr))
throw new Exception("Check condition failed");
}
List<Base> items = new ArrayList<Base>();
if (!src.hasElement())
items.add(b);
else
getChildrenByName(b, src.getElement(), items);
List<Variables> result = new ArrayList<Variables>();
for (Base r : items) {
Variables v = vars.copy();
if (src.hasVariable())
v.add(VariableMode.INPUT, src.getVariable(), r);
result.add(v);
}
return result;
}
use of org.hl7.fhir.r4b.model.StructureMap.StructureMapGroupRuleSourceComponent in project org.hl7.fhir.core by hapifhir.
the class StructureMapUtilities method analyseSource.
private VariablesForProfiling analyseSource(String ruleId, TransformContext context, VariablesForProfiling vars, StructureMapGroupRuleSourceComponent src, XhtmlNode td) throws Exception {
VariableForProfiling var = vars.get(VariableMode.INPUT, src.getContext());
if (var == null)
throw new FHIRException("Rule \"" + ruleId + "\": Unknown input variable " + src.getContext());
PropertyWithType prop = var.getProperty();
boolean optional = false;
boolean repeating = false;
if (src.hasCondition()) {
optional = true;
}
if (src.hasElement()) {
Property element = prop.getBaseProperty().getChild(prop.types.getType(), src.getElement());
if (element == null)
throw new Exception("Rule \"" + ruleId + "\": Unknown element name " + src.getElement());
if (element.getDefinition().getMin() == 0)
optional = true;
if (element.getDefinition().getMax().equals("*"))
repeating = true;
VariablesForProfiling result = vars.copy(optional, repeating);
TypeDetails type = new TypeDetails(CollectionStatus.SINGLETON);
for (TypeRefComponent tr : element.getDefinition().getType()) {
if (!tr.hasCode())
throw new Error("Rule \"" + ruleId + "\": Element has no type");
ProfiledType pt = new ProfiledType(tr.getCode());
if (tr.hasProfile())
pt.addProfile(tr.getProfile());
if (element.getDefinition().hasBinding())
pt.addBinding(element.getDefinition().getBinding());
type.addType(pt);
}
td.addText(prop.getPath() + "." + src.getElement());
if (src.hasVariable())
result.add(VariableMode.INPUT, src.getVariable(), new PropertyWithType(prop.getPath() + "." + src.getElement(), element, null, type));
return result;
} else {
// ditto!
td.addText(prop.getPath());
return vars.copy(optional, repeating);
}
}
use of org.hl7.fhir.r4b.model.StructureMap.StructureMapGroupRuleSourceComponent in project org.hl7.fhir.core by hapifhir.
the class StructureMapUtilities method sourceToString.
public static String sourceToString(StructureMapGroupRuleSourceComponent r) {
StringBuilder b = new StringBuilder();
renderSource(b, r, false);
return b.toString();
}
use of org.hl7.fhir.r4b.model.StructureMap.StructureMapGroupRuleSourceComponent in project org.hl7.fhir.core by hapifhir.
the class MappingSheetParser method getStructureMap.
public StructureMap getStructureMap() throws FHIRException {
StructureMap map = new StructureMap();
loadMetadata(map);
if (metadata.containsKey("copyright"))
map.setCopyright(metadata.get("copyright"));
StructureMapGroupComponent grp = map.addGroup();
for (MappingRow row : rows) {
StructureMapGroupRuleComponent rule = grp.addRule();
rule.setName(row.getSequence());
StructureMapGroupRuleSourceComponent src = rule.getSourceFirstRep();
src.setContext("src");
src.setElement(row.getIdentifier());
src.setMin(row.getCardinalityMin());
src.setMax(row.getCardinalityMax());
src.setType(row.getDataType());
src.addExtension(ToolingExtensions.EXT_MAPPING_NAME, new StringType(row.getName()));
if (row.getCondition() != null) {
src.setCheck(processCondition(row.getCondition()));
}
StructureMapGroupRuleTargetComponent tgt = rule.getTargetFirstRep();
tgt.setContext("tgt");
tgt.setElement(row.getAttribute());
tgt.addExtension(ToolingExtensions.EXT_MAPPING_TGTTYPE, new StringType(row.getType()));
tgt.addExtension(ToolingExtensions.EXT_MAPPING_TGTCARD, new StringType(row.getMinMax()));
if (row.getDtMapping() != null) {
src.setVariable("s");
tgt.setVariable("t");
tgt.setTransform(StructureMapTransform.CREATE);
StructureMapGroupRuleDependentComponent dep = rule.addDependent();
dep.setName(row.getDtMapping());
dep.addVariable("s");
dep.addVariable("t");
} else if (row.getVocabMapping() != null) {
tgt.setTransform(StructureMapTransform.TRANSLATE);
tgt.addParameter().setValue(new StringType(row.getVocabMapping()));
tgt.addParameter().setValue(new IdType("src"));
} else {
tgt.setTransform(StructureMapTransform.COPY);
}
rule.setDocumentation(row.getComments());
if (row.getDerived() != null) {
tgt = rule.addTarget();
tgt.setContext("tgt");
tgt.setElement(row.getDerived());
tgt.setTransform(StructureMapTransform.COPY);
tgt.addParameter().setValue(new StringType(row.getDerivedMapping()));
}
}
return map;
}
use of org.hl7.fhir.r4b.model.StructureMap.StructureMapGroupRuleSourceComponent in project org.hl7.fhir.core by hapifhir.
the class StructureMapUtilities method analyseSource.
private VariablesForProfiling analyseSource(String ruleId, TransformContext context, VariablesForProfiling vars, StructureMapGroupRuleSourceComponent src, XhtmlNode td) throws FHIRException {
VariableForProfiling var = vars.get(VariableMode.INPUT, src.getContext());
if (var == null)
throw new FHIRException("Rule \"" + ruleId + "\": Unknown input variable " + src.getContext());
PropertyWithType prop = var.getProperty();
boolean optional = false;
boolean repeating = false;
if (src.hasCondition()) {
optional = true;
}
if (src.hasElement()) {
Property element = prop.getBaseProperty().getChild(prop.getTypes().getType(), src.getElement());
if (element == null)
throw new FHIRException("Rule \"" + ruleId + "\": Unknown element name " + src.getElement());
if (element.getDefinition().getMin() == 0)
optional = true;
if (element.getDefinition().getMax().equals("*"))
repeating = true;
VariablesForProfiling result = vars.copy(optional, repeating);
TypeDetails type = new TypeDetails(CollectionStatus.SINGLETON);
for (TypeRefComponent tr : element.getDefinition().getType()) {
if (!tr.hasCode())
throw new Error("Rule \"" + ruleId + "\": Element has no type");
ProfiledType pt = new ProfiledType(tr.getWorkingCode());
if (tr.hasProfile())
pt.addProfiles(tr.getProfile());
if (element.getDefinition().hasBinding())
pt.addBinding(element.getDefinition().getBinding());
type.addType(pt);
}
td.addText(prop.getPath() + "." + src.getElement());
if (src.hasVariable())
result.add(VariableMode.INPUT, src.getVariable(), new PropertyWithType(prop.getPath() + "." + src.getElement(), element, null, type));
return result;
} else {
// ditto!
td.addText(prop.getPath());
return vars.copy(optional, repeating);
}
}
Aggregations