Search in sources :

Example 26 with RMObject

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;
}
Also used : CanonicalJson(org.ehrbase.serialisation.jsonencoding.CanonicalJson) RMObject(com.nedap.archie.rm.RMObject) Locatable(com.nedap.archie.rm.archetyped.Locatable) RMObject(com.nedap.archie.rm.RMObject)

Example 27 with 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();
}
Also used : RMObject(com.nedap.archie.rm.RMObject) Test(org.junit.Test)

Example 28 with RMObject

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();
}
Also used : RMObject(com.nedap.archie.rm.RMObject) Test(org.junit.Test)

Example 29 with RMObject

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();
}
Also used : RMObject(com.nedap.archie.rm.RMObject) Test(org.junit.Test)

Example 30 with RMObject

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();
}
Also used : RMObject(com.nedap.archie.rm.RMObject) Test(org.junit.Test)

Aggregations

RMObject (com.nedap.archie.rm.RMObject)57 Test (org.junit.Test)19 Composition (com.nedap.archie.rm.composition.Composition)10 CanonicalJson (org.ehrbase.serialisation.jsonencoding.CanonicalJson)9 QueryResponseData (org.ehrbase.response.openehr.QueryResponseData)8 Locatable (com.nedap.archie.rm.archetyped.Locatable)7 List (java.util.List)7 WebTemplateNode (org.ehrbase.webtemplate.model.WebTemplateNode)6 Collectors (java.util.stream.Collectors)5 TemplateId (com.nedap.archie.rm.archetyped.TemplateId)4 IOException (java.io.IOException)4 InvocationTargetException (java.lang.reflect.InvocationTargetException)4 Map (java.util.Map)4 ImmutablePair (org.apache.commons.lang3.tuple.ImmutablePair)4 TestDataTemplateProvider (org.ehrbase.client.templateprovider.TestDataTemplateProvider)4 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)3 Archetyped (com.nedap.archie.rm.archetyped.Archetyped)3 Version (com.nedap.archie.rm.changecontrol.Version)3 CodePhrase (com.nedap.archie.rm.datatypes.CodePhrase)3