use of com.nedap.archie.rm.archetyped.Locatable in project openEHR_SDK by ehrbase.
the class LocatableMarshalPostprocessor method process.
/**
* {@inheritDoc}
*/
@Override
public void process(String term, Locatable rmObject, Map<String, Object> values, Context<Map<String, Object>> context) {
if (RmConstants.ELEMENT.equals(context.getNodeDeque().peek().getRmType()) || !context.getFlatHelper().skip(context)) {
addValue(values, term + PATH_DIVIDER + "_uid", null, Optional.of(rmObject).map(Locatable::getUid).map(ObjectId::getValue).orElse(null));
if (rmObject.getLinks() != null) {
IntStream.range(0, rmObject.getLinks().size()).forEach(i -> {
Link link = rmObject.getLinks().get(i);
String termLoop = term + PATH_DIVIDER + "_link:" + i;
addValue(values, termLoop, "meaning", Optional.of(link).map(Link::getMeaning).map(DvText::getValue).orElse(null));
addValue(values, termLoop, "type", Optional.of(link).map(Link::getType).map(DvText::getValue).orElse(null));
addValue(values, termLoop, "target", Optional.of(link).map(Link::getTarget).map(DvEHRURI::getValue).orElse(null));
});
}
if (rmObject.getFeederAudit() != null) {
callMarshal(term, "_feeder_audit", rmObject.getFeederAudit(), values, context, context.getNodeDeque().peek().findChildById("feeder_audit").orElse(FlatHelper.buildDummyChild("feeder_audit", context.getNodeDeque().peek())));
}
if (Optional.ofNullable(rmObject.getName()).map(DvText::getValue).filter(n -> !Objects.equals(context.getNodeDeque().peek().getName(), n)).isPresent()) {
handleRmAttribute(term, rmObject.getName(), values, context, "name");
}
}
}
use of com.nedap.archie.rm.archetyped.Locatable in project openEHR_SDK by ehrbase.
the class OptSkeletonBuilderTest method testGenerateCorona.
@Test
public void testGenerateCorona() throws Exception {
org.openehr.schemas.v1.TemplateDocument document = org.openehr.schemas.v1.TemplateDocument.Factory.parse(OperationalTemplateTestData.CORONA_ANAMNESE.getStream());
OPERATIONALTEMPLATE operationaltemplate = document.getTemplate();
OptSkeletonBuilder cut = new OptSkeletonBuilder();
Composition generate = (Composition) cut.generate(operationaltemplate);
assertThat(generate.getContent()).extracting(Locatable::getName).extracting(DvText::getValue).containsExactlyInAnyOrder("Geschichte/Historie", "Symptome", "Kontakt", "Risikogebiet", "Allgemeine Angaben");
}
use of com.nedap.archie.rm.archetyped.Locatable in project openEHR_SDK by ehrbase.
the class DefaultValidator method validate.
private List<ConstraintViolation> validate(Locatable locatable, WebTemplateNode node) {
List<ConstraintViolation> result = new ArrayList<>();
node.getChildren().forEach(childNode -> {
var count = 0;
for (var item : locatable.itemsAtPath(node.buildRelativePath(childNode))) {
if (item instanceof Locatable) {
if (!node.isRelativePathNameDependent(childNode) || Objects.equals(((Locatable) item).getNameAsString(), childNode.getName())) {
count++;
}
} else {
count++;
}
}
var interval = getMultiplicityInterval(childNode, node);
if (!interval.has(count)) {
String message = RMObjectValidationMessageIds.rm_OCCURRENCE_MISMATCH.getMessage(count, interval.toString());
result.add(new ConstraintViolation(childNode.getAqlPath(), message));
}
});
return result;
}
use of com.nedap.archie.rm.archetyped.Locatable in project openEHR_SDK by ehrbase.
the class ItemExtractor method invoke.
public ItemExtractor invoke() {
relativeAql = StringUtils.removeEnd(StringUtils.removeStart(childNode.getAqlPath(), currentNode.getAqlPath()), "/");
FlatPath childPath = new FlatPath(relativeAql);
parentAql = StringUtils.removeEnd(childPath.format(false), childPath.format(false).substring(childPath.format(false).lastIndexOf("/")));
if (StringUtils.isBlank(parentAql)) {
parentAql = "/";
}
if (currentRM instanceof Pathable) {
try {
child = ((Pathable) currentRM).itemsAtPath(childPath.format(false));
if (child == null || ((List) child).isEmpty()) {
child = ((Pathable) currentRM).itemAtPath(childPath.format(false));
}
} catch (RuntimeException e) {
child = null;
}
parent = ((Pathable) currentRM).itemAtPath(parentAql);
} else if (currentRM instanceof DvInterval) {
if (relativeAql.contains("upper_included")) {
child = new RmBoolean(((DvInterval<?>) currentRM).isUpperIncluded());
} else if (relativeAql.contains("lower_included")) {
child = new RmBoolean(((DvInterval<?>) currentRM).isLowerIncluded());
} else if (relativeAql.contains("lower")) {
child = ((DvInterval<?>) currentRM).getLower();
} else if (relativeAql.contains("upper")) {
child = ((DvInterval<?>) currentRM).getUpper();
}
parent = currentRM;
} else {
throw new SdkException(String.format("Can not extract from class %s", currentRM.getClass().getSimpleName()));
}
if (StringUtils.isNotBlank(childPath.findOtherPredicate("name/value")) && child instanceof List && Locatable.class.isAssignableFrom(Walker.ARCHIE_RM_INFO_LOOKUP.getClass(childNode.getRmType()))) {
child = ((List) child).stream().filter(c -> childPath.findOtherPredicate("name/value").equals(((Locatable) c).getNameAsString())).collect(Collectors.toList());
// if name not found return null
if (((List<?>) child).isEmpty()) {
child = null;
}
}
if (isChoice && child instanceof List) {
child = ((List) child).stream().filter(c -> Walker.ARCHIE_RM_INFO_LOOKUP.getTypeInfo(c.getClass()).getRmName().equals(childNode.getRmType())).collect(Collectors.toList());
// if rmType not found return null
if (((List<?>) child).isEmpty()) {
child = null;
}
}
if ((childNode.getMax() == 1 || currentNode.getRmType().equals(RmConstants.ELEMENT)) && child instanceof List) {
if (((List<?>) child).isEmpty()) {
child = null;
} else {
child = ((List) child).get(0);
}
}
if (child instanceof Element && !childNode.getRmType().equals(RmConstants.ELEMENT)) {
child = ((Element) child).getValue();
}
return this;
}
use of com.nedap.archie.rm.archetyped.Locatable in project openEHR_SDK by ehrbase.
the class ToCompositionWalker method postHandle.
@Override
protected void postHandle(Context<T> context) {
RMObject currentRM = context.getRmObjectDeque().peek();
WebTemplateNode currentNode = context.getNodeDeque().peek();
if (currentRM instanceof Locatable) {
org.ehrbase.webtemplate.parser.NodeId nodeId = new NodeId(currentNode.getNodeId());
if (nodeId.isArchetypeId()) {
Archetyped archetyped = new Archetyped();
archetyped.setArchetypeId(new ArchetypeID(nodeId.getNodeId()));
archetyped.setRmVersion(RM_VERSION_1_4_0);
TemplateId templateId = new TemplateId();
templateId.setValue(context.getTemplateId());
archetyped.setTemplateId(templateId);
((Locatable) currentRM).setArchetypeDetails(archetyped);
((Locatable) currentRM).setArchetypeNodeId(nodeId.getNodeId());
}
}
normalise(currentRM);
}
Aggregations