use of com.nedap.archie.rm.datavalues.quantity.DvInterval 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.datavalues.quantity.DvInterval in project openEHR_SDK by ehrbase.
the class DvOrderedPostprocessor method handleNormalRange.
private void handleNormalRange(Map<FlatPathDto, String> values, Set<String> consumedPaths, Context<Map<FlatPathDto, String>> context, String term, Consumer<DvInterval> rangeConsumer) {
Map<FlatPathDto, String> rangeValues = FlatHelper.filter(values, term, false);
if (!rangeValues.isEmpty()) {
DvInterval range = new DvInterval();
rangeConsumer.accept(range);
handleBorder(values, consumedPaths, context, "upper", range::setUpper, term);
handleBorder(values, consumedPaths, context, "lower", range::setLower, term);
callPostProcess(term, null, range, rangeValues, consumedPaths, context, context.getNodeDeque().peek().findChildById("range").orElse(FlatHelper.buildDummyChild("range", context.getNodeDeque().peek())));
}
}
use of com.nedap.archie.rm.datavalues.quantity.DvInterval in project openEHR_SDK by ehrbase.
the class DBEncodeTest method testDBDecodeDvIntervalCompositeClass.
@Test
public void testDBDecodeDvIntervalCompositeClass() throws Exception {
String db_encoded = IOUtils.resourceToString("/composition/canonical_json/composition_with_dvinterval_composite.json", UTF_8);
assertNotNull(db_encoded);
JsonElement converted = new LightRawJsonEncoder(db_encoded).encodeContentAsJson(null);
// see if this can be interpreted by Archie
Composition composition = new CanonicalJson().unmarshal(converted.toString(), Composition.class);
// hack the composition to figure out what is the format of DvInterval...
((DvInterval) ((Element) ((AdminEntry) composition.getContent().get(0)).getData().getItems().get(0)).getValue()).setLower(new DvDateTime("2019-11-22T00:00+01:00"));
((DvInterval) ((Element) ((AdminEntry) composition.getContent().get(0)).getData().getItems().get(0)).getValue()).setUpper(new DvDateTime("2019-12-22T00:00+01:00"));
assertNotNull(composition);
String toJson = new CanonicalJson().marshal(composition);
String interpreted = new CanonicalXML().marshal(composition);
assertNotNull(interpreted);
}
use of com.nedap.archie.rm.datavalues.quantity.DvInterval in project openEHR_SDK by ehrbase.
the class WebTemplateSkeletonBuilder method build.
@SuppressWarnings("unchecked")
public static <T> T build(WebTemplateNode node, boolean withChildren, Class<T> clazz) {
String rmclass = node.getRmType();
CComplexObject elementConstraint = new CComplexObject();
elementConstraint.setRmTypeName(rmclass);
Object skeleton;
switch(rmclass) {
case "UID_BASED_ID":
skeleton = new HierObjectId();
break;
case "PARTY_PROXY":
skeleton = new PartyIdentified();
break;
case "STRING":
case "LONG":
skeleton = null;
break;
case "BOOLEAN":
skeleton = false;
break;
default:
skeleton = RM_OBJECT_CREATOR.create(elementConstraint);
break;
}
if (withChildren) {
node.getChildren().stream().filter(n -> !List.of("name", "archetype_node_id", "offset").contains(n.getId())).forEach(c -> {
Object childObject = build(c, true, Object.class);
insert(node, (RMObject) skeleton, c, childObject);
});
}
if (skeleton instanceof Locatable) {
Optional<WebTemplateNode> name = node.findChildById("name");
if (name.isPresent()) {
if (name.get().getRmType().equals(RmConstants.DV_CODED_TEXT)) {
((Locatable) skeleton).setName(extractDefault(name.get(), DvCodedText.class).orElseThrow());
} else {
((Locatable) skeleton).setName(extractDefault(name.get(), DvText.class).orElse(new DvText(node.getName())));
}
} else {
((Locatable) skeleton).setName(new DvText(node.getName()));
}
((Locatable) skeleton).setArchetypeNodeId(node.getNodeId());
}
if (skeleton instanceof Entry) {
((Entry) skeleton).setEncoding(new CodePhrase(new TerminologyId("IANA_character-sets"), "UTF-8"));
node.findChildById("subject").map(n -> build(n, false, PartyProxy.class)).ifPresent(((Entry) skeleton)::setSubject);
}
if (skeleton instanceof Composition) {
node.findChildById("category").flatMap(n -> extractDefault(n, DvCodedText.class)).ifPresent(((Composition) skeleton)::setCategory);
}
if (skeleton instanceof DvInterval) {
((DvInterval<?>) skeleton).setLowerIncluded(true);
((DvInterval<?>) skeleton).setUpperIncluded(true);
}
if (skeleton instanceof PartyRelated) {
node.findChildById("relationship").flatMap(n -> extractDefault(n, DvCodedText.class)).ifPresent(((PartyRelated) skeleton)::setRelationship);
}
if (skeleton == null || clazz.isAssignableFrom(skeleton.getClass())) {
return (T) skeleton;
} else {
throw new SdkException(String.format("%s not assignable from %s", skeleton.getClass(), clazz));
}
}
Aggregations