Search in sources :

Example 56 with RMObject

use of com.nedap.archie.rm.RMObject in project openEHR_SDK by ehrbase.

the class TestQueryEngine method checkSimpleQuery.

protected void checkSimpleQuery(String csvPath, String rootPath, String contains, RMObject referenceNode) throws FileNotFoundException {
    SimplePathExpressionSettings simplePathExpressionSettings = new SimplePathExpressionSettings();
    CsvParser csvParser = new CsvParser(simplePathExpressionSettings.settings());
    csvParser.parse(new FileReader(csvPath));
    List<PathExpression> attributeDefinitions = simplePathExpressionSettings.getPathExpressionRow().getBeans();
    for (PathExpression pathExpression : attributeDefinitions) {
        if (pathExpression.getComment() == null) {
            String attributePath = pathExpression.getPath();
            QueryResponseData result = performQuery(rootPath, attributePath, contains);
            try {
                List<Object> objectList = result.getRows().get(0);
                Object actual = valueObject(objectList.get(0));
                if (actual instanceof List) {
                    // RMObject(s)
                    Object expected = attributeArrayValueAt(referenceNode, attributePath);
                    assertThat(toRmObjectList((List<Object>) actual).toArray()).as(rootPath + "/" + attributePath).containsExactlyInAnyOrder(((List<?>) expected).toArray());
                } else {
                    assertThat(valueObject(objectList.get(0))).as(rootPath + "/" + attributePath).isEqualTo(attributeValueAt(referenceNode, attributePath));
                }
            } catch (Exception e) {
                fail(e.getMessage());
            }
        }
    }
}
Also used : SimplePathExpressionSettings(org.ehrbase.client.openehrclient.defaultrestclient.systematic.compositionquery.queries.simple.SimplePathExpressionSettings) PathExpression(org.ehrbase.client.openehrclient.defaultrestclient.systematic.compositionquery.queries.simple.PathExpression) CsvParser(org.junit.jupiter.params.shadow.com.univocity.parsers.csv.CsvParser) FileReader(java.io.FileReader) QueryResponseData(org.ehrbase.response.openehr.QueryResponseData) RMObject(com.nedap.archie.rm.RMObject) List(java.util.List) WrongStatusCodeException(org.ehrbase.client.exception.WrongStatusCodeException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException)

Example 57 with RMObject

use of com.nedap.archie.rm.RMObject in project ehrbase by ehrbase.

the class ContributionServiceImp method getListOfTemplates.

@Override
public Set<String> getListOfTemplates(String contribution, CompositionFormat format) {
    List<Version> versions = ContributionServiceHelper.parseVersions(contribution, format);
    Set<String> templates = new HashSet<>();
    for (Version version : versions) {
        Object versionData = version.getData();
        // the version contains the optional "data" attribute (i.e. payload), therefore has specific object type (composition, folder,...)
        if (versionData != null) {
            RMObject versionRmObject;
            if (versionData instanceof LinkedHashMap) {
                versionRmObject = ContributionServiceHelper.unmarshalMapContentToRmObject((LinkedHashMap) versionData, format);
            } else {
                throw new IllegalArgumentException("Contribution input can't be processed");
            }
            // switch to allow acting depending on exact type
            SupportedClasses versionClass;
            try {
                versionClass = SupportedClasses.valueOf(versionRmObject.getClass().getSimpleName().toUpperCase());
            } catch (Exception e) {
                throw new InvalidApiParameterException("Invalid version object in contribution. " + versionRmObject.getClass().getSimpleName().toUpperCase() + " not supported.");
            }
            switch(versionClass) {
                case COMPOSITION:
                    TemplateId templateId = ((Composition) versionRmObject).getArchetypeDetails().getTemplateId();
                    if (templateId != null) {
                        templates.add(templateId.getValue());
                    }
                    break;
                // TODO: might add later, if other_details support templated content
                case EHRSTATUS:
                case FOLDER:
                default:
                    throw new IllegalArgumentException("Contribution input contains invalid version class");
            }
        }
    }
    return templates;
}
Also used : Version(com.nedap.archie.rm.changecontrol.Version) RMObject(com.nedap.archie.rm.RMObject) TemplateId(com.nedap.archie.rm.archetyped.TemplateId) RMObject(com.nedap.archie.rm.RMObject)

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