use of com.nedap.archie.rm.RMObject in project openEHR_SDK by ehrbase.
the class CanonicalUtil method getAttributePathValue.
/**
* Retrieve the value of an attribute identified by a path.
* NB. This is not supposed to replace Locatable.itemsAtPath(), but instead it should be used
* to resolve values in non locatable RMObject
*
* @param root
* @param attributePath
* @return
* @see com.nedap.archie.rm.archetyped.Locatable
*/
private static Object getAttributePathValue(Object root, String attributePath, boolean keepArray) {
Object rmObject = root;
if (rmObject instanceof Locatable) {
try {
List<Object> items = ((Locatable) root).itemsAtPath(attributePath);
if (!items.isEmpty())
rmObject = keepArray ? items : items.get(0);
else
rmObject = null;
} catch (Exception e) {
throw new IllegalArgumentException("Invalid path:" + attributePath);
}
} else {
if (!attributePath.contains("/"))
rmObject = getAttributeValue(root, attributePath);
else {
String[] pathItems = attributePath.split("/");
int iteration = 0;
for (String item : pathItems) {
rmObject = getAttributeValue(rmObject, item);
iteration++;
if (rmObject instanceof Locatable) {
// f.e. items in other_details
rmObject = locatableValueItem((RMObject) rmObject, iteration, Arrays.asList(pathItems).subList(iteration, pathItems.length));
break;
}
}
}
}
if (rmObject instanceof RMObject)
return new CanonicalJson().marshal((RMObject) rmObject);
else
return rmObject;
}
use of com.nedap.archie.rm.RMObject in project openEHR_SDK by ehrbase.
the class AutoWhereIT method testObservationAutoWhere.
@Test
public void testObservationAutoWhere() 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 + "/testObservationWhere.csv";
assertThat(autoWhereQuery.testItemPaths(csvTestSet, rootPath, contains, referenceNode)).isTrue();
}
use of com.nedap.archie.rm.RMObject in project openEHR_SDK by ehrbase.
the class AutoWhereIT method testSectionAutoWhere.
@Test
public void testSectionAutoWhere() throws IOException {
String rootPath = "s";
RMObject referenceNode = (RMObject) aComposition.itemsAtPath("/content[openEHR-EHR-SECTION.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]";
String csvTestSet = dirPath + "/testSectionWhere.csv";
assertThat(autoWhereQuery.testItemPaths(csvTestSet, rootPath, contains, referenceNode)).isTrue();
}
use of com.nedap.archie.rm.RMObject in project openEHR_SDK by ehrbase.
the class AutoWhereIT method testActionAutoWhere.
@Test
public void testActionAutoWhere() 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 + "/testActionWhere.csv";
assertThat(autoWhereQuery.testItemPaths(csvTestSet, rootPath, contains, referenceNode)).isTrue();
}
use of com.nedap.archie.rm.RMObject in project openEHR_SDK by ehrbase.
the class AutoWhereIT method testCompositionAutoWhere.
@Test
public void testCompositionAutoWhere() throws IOException {
String rootPath = "c";
RMObject referenceNode = aComposition;
String contains = "composition c[openEHR-EHR-COMPOSITION.test_all_types.v1]";
String csvTestSet = dirPath + "/testCompositionWhere.csv";
assertThat(autoWhereQuery.testItemPaths(csvTestSet, rootPath, contains, referenceNode)).isTrue();
}
Aggregations