use of com.nedap.archie.rm.RMObject in project openEHR_SDK by ehrbase.
the class Flattener method flatten.
public <T> T flatten(RMObject locatable, Class<T> clazz) {
try {
T dto = createInstance(clazz);
Class<?> rootC = ReflectionHelper.findRootClass(clazz);
String packageNames = StringUtils.removeEnd(rootC.getPackageName(), ".definition");
classGraph = new ClassGraph().enableClassInfo().enableAnnotationInfo().acceptPackages(packageNames).scan();
String templateId = classGraph.getClassesWithAnnotation(Template.class.getName()).loadClasses().get(0).getAnnotation(Template.class).value();
String archetypeValue = clazz.getAnnotation(Archetype.class).value();
WebTemplateNode root = templateProvider.buildIntrospect(templateId).orElseThrow(() -> new SdkException(String.format("Can not find Template: %s", templateId))).getTree().findMatching(n -> Objects.equals(n.getNodeId(), archetypeValue)).get(0);
new DtoFromCompositionWalker().walk(locatable, new DtoWithMatchingFields(dto, DtoFromCompositionWalker.buildFieldByPathMap(dto.getClass())), root, templateId);
if (locatable instanceof Composition && ((Composition) locatable).getUid() != null) {
addVersion(dto, new VersionUid(((Composition) locatable).getUid().toString()));
}
return dto;
} finally {
if (classGraph != null) {
classGraph.close();
}
}
}
use of com.nedap.archie.rm.RMObject in project openEHR_SDK by ehrbase.
the class WebTemplateSkeletonBuilder method remove.
public static void remove(WebTemplateNode parentNode, RMObject parentObject, WebTemplateNode childNode, Object removeChildObject) {
String attributeName = FlatPath.removeStart(new FlatPath(childNode.getAqlPath(true)), new FlatPath(parentNode.getAqlPath(true))).getLast().getName();
RMAttributeInfo attributeInfo = ARCHIE_RM_INFO_LOOKUP.getAttributeInfo(parentObject.getClass(), attributeName);
try {
Object actualChild = attributeInfo.getGetMethod().invoke(parentObject);
if (actualChild instanceof Collection) {
((Collection<?>) actualChild).remove(removeChildObject);
} else if (Objects.equals(actualChild, removeChildObject)) {
attributeInfo.getSetMethod().invoke(parentObject, (Object) null);
}
} catch (IllegalAccessException | InvocationTargetException e) {
throw new SdkException(e.getMessage());
}
}
use of com.nedap.archie.rm.RMObject 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));
}
}
use of com.nedap.archie.rm.RMObject in project openEHR_SDK by ehrbase.
the class SelectRMIT method testObservationDrillDown.
@Test
public void testObservationDrillDown() throws IOException {
String rootPath = "o";
RMObject referenceNode = (RMObject) aComposition.itemsAtPath("/content[openEHR-EHR-OBSERVATION.test_all_types.v1]").get(0);
String contains = "composition c[openEHR-EHR-COMPOSITION.test_all_types.v1]" + " contains observation o[openEHR-EHR-OBSERVATION.test_all_types.v1]";
String csvTestSet = dirPath + "/testObservationDrillDown.csv";
assertThat(simpleSelectQueryEngine.testItemPaths(csvTestSet, rootPath, contains, referenceNode)).isTrue();
}
use of com.nedap.archie.rm.RMObject in project openEHR_SDK by ehrbase.
the class SelectRMIT method testActionDrillDown.
@Test
public void testActionDrillDown() throws IOException {
String rootPath = "a";
RMObject referenceNode = (RMObject) aComposition.itemsAtPath("/content[openEHR-EHR-SECTION.test_all_types.v1]/items[at0001]/items[at0002]/items[openEHR-EHR-ACTION.test_all_types.v1]").get(0);
String contains = "composition c[openEHR-EHR-COMPOSITION.test_all_types.v1]" + " contains section s[openEHR-EHR-SECTION.test_all_types.v1]" + " contains action a[openEHR-EHR-ACTION.test_all_types.v1]";
String csvTestSet = dirPath + "/testActionDrillDown.csv";
assertThat(simpleSelectQueryEngine.testItemPaths(csvTestSet, rootPath, contains, referenceNode)).isTrue();
}
Aggregations