use of org.hl7.fhir.r4.model.StructureMap in project org.hl7.fhir.core by hapifhir.
the class StructureMapUtilities method render.
public String render(StructureMap map) throws FHIRException {
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");
renderUses(b, map);
renderImports(b, map);
for (StructureMapGroupComponent g : map.getGroup()) renderGroup(b, g);
return b.toString();
}
use of org.hl7.fhir.r4.model.StructureMap in project org.hl7.fhir.core by hapifhir.
the class StructureMapUtilities method translate.
private Base translate(TransformContext context, StructureMap map, Variables vars, List<StructureMapGroupRuleTargetParameterComponent> parameter) throws FHIRException {
Base src = getParam(vars, parameter.get(0));
String id = getParamString(vars, parameter.get(1));
String fld = getParamString(vars, parameter.get(2));
return translate(context, map, src, id, fld);
}
use of org.hl7.fhir.r4.model.StructureMap in project org.hl7.fhir.core by hapifhir.
the class StructureMapUtilities method parseUses.
private void parseUses(StructureMap result, FHIRLexer lexer) throws FHIRException {
lexer.token("uses");
StructureMapStructureComponent st = result.addStructure();
st.setUrl(lexer.readConstant("url"));
if (lexer.hasToken("alias")) {
lexer.token("alias");
st.setAlias(lexer.take());
}
lexer.token("as");
st.setMode(StructureMapModelMode.fromCode(lexer.take()));
lexer.skipToken(";");
if (lexer.hasComment()) {
st.setDocumentation(lexer.take().substring(2).trim());
}
lexer.skipComments();
}
use of org.hl7.fhir.r4.model.StructureMap in project org.hl7.fhir.core by hapifhir.
the class StructureMapUtilities method analyseTransform.
private TypeDetails analyseTransform(TransformContext context, StructureMap map, StructureMapGroupRuleTargetComponent tgt, VariableForProfiling var, VariablesForProfiling vars) throws FHIRException {
switch(tgt.getTransform()) {
case CREATE:
String p = getParamString(vars, tgt.getParameter().get(0));
return new TypeDetails(CollectionStatus.SINGLETON, p);
case COPY:
return getParam(vars, tgt.getParameter().get(0));
case EVALUATE:
ExpressionNode expr = (ExpressionNode) tgt.getUserData(MAP_EXPRESSION);
if (expr == null) {
expr = fpe.parse(getParamString(vars, tgt.getParameter().get(tgt.getParameter().size() - 1)));
tgt.setUserData(MAP_WHERE_EXPRESSION, expr);
}
return fpe.check(vars, null, expr);
// // throw new Error("Transform "+tgt.getTransform().toCode()+" not supported yet");
case TRANSLATE:
return new TypeDetails(CollectionStatus.SINGLETON, "CodeableConcept");
case CC:
ProfiledType res = new ProfiledType("CodeableConcept");
if (tgt.getParameter().size() >= 2 && isParamId(vars, tgt.getParameter().get(1))) {
TypeDetails td = vars.get(null, getParamId(vars, tgt.getParameter().get(1))).property.types;
if (td != null && td.hasBinding())
// todo: do we need to check that there's no implicit translation her? I don't think we do...
res.addBinding(td.getBinding());
}
return new TypeDetails(CollectionStatus.SINGLETON, res);
case C:
return new TypeDetails(CollectionStatus.SINGLETON, "Coding");
case QTY:
return new TypeDetails(CollectionStatus.SINGLETON, "Quantity");
case REFERENCE:
VariableForProfiling vrs = vars.get(VariableMode.OUTPUT, getParamId(vars, tgt.getParameterFirstRep()));
if (vrs == null)
throw new FHIRException("Unable to resolve variable \"" + getParamId(vars, tgt.getParameterFirstRep()) + "\"");
String profile = vrs.property.getProfileProperty().getStructure().getUrl();
TypeDetails td = new TypeDetails(CollectionStatus.SINGLETON);
td.addType("Reference", profile);
return td;
// // throw new FHIRException("Transform engine cannot point at an element of type "+b.fhirType());
default:
throw new Error("Transform Unknown or not handled yet: " + tgt.getTransform().toCode());
}
}
use of org.hl7.fhir.r4.model.StructureMap in project org.hl7.fhir.core by hapifhir.
the class StructureMapUtilities method findMatchingMaps.
private List<StructureMap> findMatchingMaps(String value) {
List<StructureMap> res = new ArrayList<StructureMap>();
if (value.contains("*")) {
for (StructureMap sm : library.values()) {
if (urlMatches(value, sm.getUrl())) {
res.add(sm);
}
}
} else {
StructureMap sm = library.get(value);
if (sm != null)
res.add(sm);
}
Set<String> check = new HashSet<String>();
for (StructureMap sm : res) {
if (check.contains(sm.getUrl()))
throw new Error("duplicate");
else
check.add(sm.getUrl());
}
return res;
}
Aggregations