use of org.ehrbase.webtemplate.model.WebTemplateInput in project openEHR_SDK by ehrbase.
the class ClassGenerator method addSimpleField.
private void addSimpleField(ClassGeneratorContext context, TypeSpec.Builder classBuilder, String path, WebTemplateNode endNode) {
Class<?> clazz = extractClass(endNode);
if (clazz == null) {
logger.warn("No class for path {} ", path);
return;
}
ValueSet valueSet = buildValueSet(endNode);
RmClassGeneratorConfig classGeneratorConfig = configMap.get(clazz);
if (classGeneratorConfig == null && !clazz.getName().contains("java.lang")) {
logger.debug("No ClassGenerator for {}", clazz);
}
boolean expand = classGeneratorConfig != null && classGeneratorConfig.isExpandField();
if (endNode.getRmType().equals("DV_CODED_TEXT") && !List.of("transition", "language", "setting", "category", "territory", "math_function", "null_flavour").contains(endNode.getId(false))) {
expand = expand && endNode.getInputs().stream().filter(i -> i.getType().equals("CODED_TEXT")).map(WebTemplateInput::getList).flatMap(List::stream).findAny().isPresent();
}
if (!expand) {
TypeName className = Optional.ofNullable(clazz).map(ClassName::get).orElse(ClassName.get(Object.class));
if (endNode.isMulti() && !context.nodeDeque.peek().getRmType().equals("ELEMENT")) {
className = ParameterizedTypeName.get(ClassName.get(List.class), className);
}
addField(context, classBuilder, path, endNode, className, valueSet, false);
} else {
Map<String, Field> fieldMap = Arrays.stream(FieldUtils.getAllFields(clazz)).filter(f -> !f.isSynthetic()).collect(Collectors.toMap(Field::getName, f -> f));
Set<String> expandFields = classGeneratorConfig.getExpandFields();
expandFields.forEach(fieldName -> addField(context, classBuilder, path + "|" + new SnakeCase(fieldName).camelToSnake(), endNode, ClassName.get(fieldMap.get(fieldName).getType()), valueSet, false));
}
}
use of org.ehrbase.webtemplate.model.WebTemplateInput in project openEHR_SDK by ehrbase.
the class DvCodedTextRMUnmarshaller method handle.
/**
* {@inheritDoc}
*/
@Override
public void handle(String currentTerm, DvCodedText rmObject, Map<FlatPathDto, String> currentValues, Context<Map<FlatPathDto, String>> context, Set<String> consumedPaths) {
setValue(currentTerm, "value", currentValues, rmObject::setValue, String.class, consumedPaths);
rmObject.setDefiningCode(new CodePhrase());
setValue(currentTerm, "code", currentValues, c -> rmObject.getDefiningCode().setCodeString(c), String.class, consumedPaths);
rmObject.getDefiningCode().setTerminologyId(new TerminologyId());
setValue(currentTerm, "terminology", currentValues, t -> rmObject.getDefiningCode().getTerminologyId().setValue(t), String.class, consumedPaths);
if (rmObject.getDefiningCode().getCodeString() == null && rmObject.getValue() == null) {
setValue(currentTerm, null, currentValues, c -> {
if (c != null) {
// try to interpret as code
setFromNode(rmObject, context, v -> Objects.equals(v.getValue(), c));
if (rmObject.getValue() == null) {
// try to interpret as value
setFromNode(rmObject, context, v -> Objects.equals(v.getLabel(), c));
}
}
}, String.class, consumedPaths);
} else if (rmObject.getDefiningCode().getCodeString() == null) {
setValue(currentTerm, null, currentValues, // It is the code
c -> rmObject.getDefiningCode().setCodeString(c), String.class, consumedPaths);
}
// Set terminology from Node
Optional.of(context.getNodeDeque().peek().getInputs()).stream().flatMap(List::stream).filter(i -> "code".equals(i.getSuffix())).findAny().map(WebTemplateInput::getTerminology).ifPresent(t -> rmObject.getDefiningCode().getTerminologyId().setValue(t));
// Set value from Node
setFromNode(rmObject, context, v -> Objects.equals(v.getValue(), rmObject.getDefiningCode().getCodeString()));
// set code from value if not set
if (rmObject.getDefiningCode().getCodeString() == null && rmObject.getValue() != null) {
setFromNode(rmObject, context, v -> Objects.equals(v.getLabel(), rmObject.getValue()));
}
setFromNode(rmObject, context, v -> Objects.equals(v.getValue(), rmObject.getDefiningCode().getCodeString()));
// consume strange legacy paths
if (rmObject.getDefiningCode() != null && rmObject.getDefiningCode().getCodeString() != null) {
currentValues.keySet().stream().map(FlatPathDto::format).filter(k -> StringUtils.substringAfter(k, "|").equals(rmObject.getDefiningCode().getCodeString())).forEach(consumedPaths::add);
}
setValue(currentTerm, "formatting", currentValues, rmObject::setFormatting, String.class, consumedPaths);
}
use of org.ehrbase.webtemplate.model.WebTemplateInput in project openEHR_SDK by ehrbase.
the class OPTParserTest method parseAllTypes.
@Test
public void parseAllTypes() throws IOException, XmlException {
OPERATIONALTEMPLATE template = TemplateDocument.Factory.parse(OperationalTemplateTestData.ALL_TYPES.getStream()).getTemplate();
OPTParser cut = new OPTParser(template);
WebTemplate actual = cut.parse();
actual = new Filter().filter(actual);
assertThat(actual).isNotNull();
ObjectMapper objectMapper = new ObjectMapper();
WebTemplate expected = objectMapper.readValue(IOUtils.toString(WebTemplateTestData.ALL_TYPES.getStream(), StandardCharsets.UTF_8), WebTemplate.class);
List<WebTemplateNode> dvOrdinalList = actual.getTree().findMatching(n -> n.getRmType().equals("DV_ORDINAL"));
assertThat(dvOrdinalList).size().isEqualTo(1);
assertThat(dvOrdinalList.get(0).getInputs()).flatExtracting(WebTemplateInput::getList).extracting(WebTemplateInputValue::getLabel, WebTemplateInputValue::getValue, WebTemplateInputValue::getOrdinal).containsExactlyInAnyOrder(new Tuple("ord1", "at0014", 0), new Tuple("ord1", "at0015", 1), new Tuple("ord3", "at0016", 2));
List<WebTemplateNode> dvQuantityList = actual.getTree().findMatching(n -> n.getRmType().equals("DV_QUANTITY"));
assertThat(dvQuantityList).flatExtracting(WebTemplateNode::getInputs).flatExtracting(WebTemplateInput::getList).extracting(WebTemplateInputValue::getLabel, WebTemplateInputValue::getValue).containsExactlyInAnyOrder(new Tuple("mg", "mg"), new Tuple("kg", "kg"), new Tuple("mm[H20]", "mm[H20]"), new Tuple("mm[Hg]", "mm[Hg]"));
List<WebTemplateNode> dvCodedTextList = actual.getTree().findMatching(n -> n.getRmType().equals("DV_CODED_TEXT"));
assertThat(dvCodedTextList).flatExtracting(WebTemplateNode::getInputs).extracting(WebTemplateInput::getTerminology, i -> i.getList().stream().map(v -> v.getValue() + ":" + v.getLabel()).collect(Collectors.joining(";"))).containsExactlyInAnyOrder(new Tuple("openehr", "433:event"), new Tuple("local", "at0006:value1;at0007:value2;at0008:value3"), new Tuple("local", ""), new Tuple("local", ""), new Tuple("SNOMED-CT", ""), new Tuple("SNOMED-CT", ""), new Tuple("local", "at0003:Planned;at0004:Active;at0005:Completed"), new Tuple("openehr", "526:planned;245:active;532:completed"), new Tuple(null, ""), new Tuple(null, ""), new Tuple(null, ""), new Tuple(null, ""));
List<String> errors = compareWebTemplate(actual, expected);
checkErrors(errors, new String[] { "LocalizedNames not equal [en=active] != [] in inputValue.code:245 id=current_state aql=/content[openEHR-EHR-SECTION.test_all_types.v1]/items[at0001]/items[at0002]/items[openEHR-EHR-ACTION.test_all_types.v1]/ism_transition/current_state", "LocalizedNames not equal [en=completed] != [] in inputValue.code:532 id=current_state aql=/content[openEHR-EHR-SECTION.test_all_types.v1]/items[at0001]/items[at0002]/items[openEHR-EHR-ACTION.test_all_types.v1]/ism_transition/current_state", "LocalizedNames not equal [en=planned] != [] in inputValue.code:526 id=current_state aql=/content[openEHR-EHR-SECTION.test_all_types.v1]/items[at0001]/items[at0002]/items[openEHR-EHR-ACTION.test_all_types.v1]/ism_transition/current_state", "LocalizedDescriptions not equal {en=*} != {} in inputValue.code:at0005 id=careflow_step aql=/content[openEHR-EHR-SECTION.test_all_types.v1]/items[at0001]/items[at0002]/items[openEHR-EHR-ACTION.test_all_types.v1]/ism_transition/careflow_step", "LocalizedDescriptions not equal {en=*} != {} in inputValue.code:at0004 id=careflow_step aql=/content[openEHR-EHR-SECTION.test_all_types.v1]/items[at0001]/items[at0002]/items[openEHR-EHR-ACTION.test_all_types.v1]/ism_transition/careflow_step", "LocalizedDescriptions not equal {en=*} != {} in inputValue.code:at0003 id=careflow_step aql=/content[openEHR-EHR-SECTION.test_all_types.v1]/items[at0001]/items[at0002]/items[openEHR-EHR-ACTION.test_all_types.v1]/ism_transition/careflow_step", "InContext not equal true != null in id=action_archetype_id aql=/content[openEHR-EHR-SECTION.test_all_types.v1]/items[at0001]/items[at0002]/items[openEHR-EHR-INSTRUCTION.test_all_types.v1]/activities[at0001]/action_archetype_id" });
}
use of org.ehrbase.webtemplate.model.WebTemplateInput in project openEHR_SDK by ehrbase.
the class Filter method mergeDVText.
public static WebTemplateNode mergeDVText(WebTemplateNode node) {
WebTemplateNode merged = new WebTemplateNode();
merged.setId("value");
merged.setName(node.getName());
merged.setMax(node.getMax());
merged.setMin(node.getMin());
merged.setRmType(DV_CODED_TEXT);
WebTemplateNode codedTextValue = node.findChildById("coded_text_value").orElseThrow();
merged.getInputs().addAll(codedTextValue.getInputs());
merged.setAqlPath(codedTextValue.getAqlPath());
merged.getLocalizedDescriptions().putAll(node.getLocalizedDescriptions());
merged.getLocalizedNames().putAll(node.getLocalizedNames());
merged.setLocalizedName(node.getLocalizedName());
merged.setAnnotations(node.getAnnotations());
WebTemplateInput other = InputHandler.buildWebTemplateInput("other", "TEXT");
merged.getInputs().add(other);
merged.getInputs().stream().filter(i -> Objects.equals(i.getSuffix(), "code")).findAny().ifPresent(i -> i.setListOpen(true));
return merged;
}
use of org.ehrbase.webtemplate.model.WebTemplateInput in project openEHR_SDK by ehrbase.
the class StdToCompositionWalker method postHandle.
@Override
protected void postHandle(Context<Map<FlatPathDto, String>> context) {
super.postHandle(context);
if (isRaw(context)) {
handleRaw(context);
}
WebTemplateNode currentNode = context.getNodeDeque().peek();
currentNode.getChildren().forEach(childNode -> {
// Check for Raw in optional (skipped Nodes)
if (context.getFlatHelper().skip(childNode, currentNode)) {
context.getNodeDeque().push(childNode);
context.getRmObjectDeque().push(new RMObject() {
});
String path = context.getFlatHelper().buildNamePath(context, true);
Map<FlatPathDto, String> subValues = context.getObjectDeque().peek().entrySet().stream().filter(e -> e.getKey().startsWith(path + "/_" + childNode.getId())).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
context.getObjectDeque().push(subValues);
if (isRaw(context)) {
handleRaw(context);
}
context.getNodeDeque().poll();
context.getRmObjectDeque().poll();
context.getObjectDeque().poll();
}
});
List<? extends UnmarshalPostprocessor<? extends RMObject>> postprocessor = findUnmarshalPostprocessors(context.getRmObjectDeque().peek().getClass());
String namePath = buildNamePathWithElementHandling(context);
if (Entry.class.isAssignableFrom(context.getRmObjectDeque().peek().getClass())) {
if (((Entry) context.getRmObjectDeque().peek()).getSubject() instanceof PartyRelated) {
Optional.ofNullable(context.getNodeDeque().peek()).flatMap(c -> c.findChildById("subject")).flatMap(c -> c.findChildById("relationship")).stream().map(WebTemplateNode::getInputs).flatMap(List::stream).filter(i -> "code".equals(i.getSuffix())).map(WebTemplateInput::getList).map(l -> l.size() == 1 ? l.get(0) : null).filter(Objects::nonNull).findAny().ifPresent(v -> ((PartyRelated) ((Entry) context.getRmObjectDeque().peek()).getSubject()).setRelationship(new DvCodedText(v.getLabel(), new CodePhrase(new TerminologyId("openehr"), v.getValue()))));
}
}
postprocessor.forEach(p -> ((UnmarshalPostprocessor) p).process(namePath, context.getRmObjectDeque().peek(), context.getObjectDeque().peek(), consumedPaths, context));
}
Aggregations