Search in sources :

Example 1 with Record1

use of org.ehrbase.client.aql.record.Record1 in project openEHR_SDK by ehrbase.

the class CanonicalEhrQuery3IT method testEhrAttributesDrillDown.

@Test
public void testEhrAttributesDrillDown() {
    String rootPath = "e/ehr_status";
    RMObject referenceNode = referenceEhrStatus;
    String[] attributePaths = { "archetype_node_id", "archetype_details", "archetype_details/archetype_id", "archetype_details/archetype_id/value", "archetype_details/template_id", "archetype_details/template_id/value", "subject", "subject/external_ref", "subject/external_ref/id", "subject/external_ref/id/value", "subject/external_ref/id/scheme", "subject/external_ref/namespace", "subject/external_ref/type", "other_details", "other_details/name", "other_details/name/value", "other_details/items[at0001]", "other_details/items[at0001]/archetype_node_id", "other_details/items[at0001]/name", "other_details/items[at0001]/name/value", "other_details/items[at0001]/value", "other_details/items[at0001]/value/id", "other_details/items[at0001]/value/type", "other_details/items[at0001]/value/issuer", "other_details/items[at0001]/value/assigner", "is_queryable", "is_modifiable" };
    for (String attributePath : attributePaths) {
        String aqlSelect = rootPath + "/" + attributePath;
        StringBuilder stringBuilder = new StringBuilder();
        stringBuilder.append("select ");
        stringBuilder.append(aqlSelect);
        stringBuilder.append(" from EHR e[ehr_id/value = $ehr_id]");
        Query<Record1<Map>> query = Query.buildNativeQuery(stringBuilder.toString(), Map.class);
        QueryResponseData result = openEhrClient.aqlEndpoint().executeRaw(query, new ParameterValue("ehr_id", ehrUUID));
        List<Object> objectList = result.getRows().get(0);
        // Mapped object(s) from JSON
        Object actual = valueObject(objectList.get(0));
        if (actual instanceof List) {
            // RMObject(s)
            Object expected = attributeArrayValueAt(referenceNode, attributePath);
            assertThat(toRmObjectList((List<Object>) actual).toArray()).as(aqlSelect).containsExactlyInAnyOrder(((List<?>) expected).toArray());
        } else {
            assertThat(valueObject(objectList.get(0))).as(aqlSelect).isEqualTo(attributeValueAt(referenceNode, attributePath));
        }
    }
}
Also used : ParameterValue(org.ehrbase.client.aql.parameter.ParameterValue) QueryResponseData(org.ehrbase.response.openehr.QueryResponseData) RMObject(com.nedap.archie.rm.RMObject) List(java.util.List) RMObject(com.nedap.archie.rm.RMObject) Record1(org.ehrbase.client.aql.record.Record1)

Example 2 with Record1

use of org.ehrbase.client.aql.record.Record1 in project openEHR_SDK by ehrbase.

the class DefaultRestFolderDAO method find.

@Override
public <T> List<T> find(Class<T> clazz) {
    Containment compositionContainment = new Containment("COMPOSITION");
    EntityQuery<Record1<T>> query = Query.buildEntityQuery(compositionContainment, new NativeSelectAqlField<>(compositionContainment, "", clazz));
    query.where(Condition.equal(EhrFields.EHR_ID(), directoryEndpoint.getEhrId()).and(Condition.equal(new NativeSelectAqlField<>(compositionContainment, "/template_id", String.class), extractTemplateId(clazz))).and(Condition.matches(new NativeSelectAqlField<>(compositionContainment, "/uid/value", String.class), getFolder().getItems().stream().map(ObjectRef::getId).map(Object::toString).toArray(String[]::new))));
    List<Record1<T>> execute = directoryEndpoint.getDefaultRestClient().aqlEndpoint().execute(query);
    return execute.stream().map(Record1::value1).collect(Collectors.toList());
}
Also used : NativeSelectAqlField(org.ehrbase.client.aql.field.NativeSelectAqlField) Containment(org.ehrbase.client.aql.containment.Containment) Record1(org.ehrbase.client.aql.record.Record1)

Example 3 with Record1

use of org.ehrbase.client.aql.record.Record1 in project openEHR_SDK by ehrbase.

the class TestQueryEngine method performEhrStatusQueryWithAutoWhere.

private QueryResponseData performEhrStatusQueryWithAutoWhere(String rootPath, String attributePath, RMObject referenceNode) {
    String whereCondition = new AutoWhereCondition(rootPath, attributePath, referenceNode).condition();
    Query<Record1<Map>> query = Query.buildNativeQuery(new AqlExpressionBuilder(rootPath, attributePath).ehrStatus(whereCondition), Map.class);
    try {
        return openEhrClient.aqlEndpoint().executeRaw(query, new ParameterValue("ehr_id", ehrUUID));
    } catch (WrongStatusCodeException e) {
        fail("path:" + rootPath + "/" + attributePath + ", error" + e.getMessage());
    }
    return null;
}
Also used : ParameterValue(org.ehrbase.client.aql.parameter.ParameterValue) AutoWhereCondition(org.ehrbase.client.openehrclient.defaultrestclient.systematic.compositionquery.queries.auto.AutoWhereCondition) WrongStatusCodeException(org.ehrbase.client.exception.WrongStatusCodeException) Record1(org.ehrbase.client.aql.record.Record1)

Example 4 with Record1

use of org.ehrbase.client.aql.record.Record1 in project openEHR_SDK by ehrbase.

the class CanonicalEhrQuery1IT method testEhrAttributes.

/**
 * create a basic ehr and check attributes
 */
@Test
public void testEhrAttributes() {
    // see issue CR #478 (cannot retrieve time_created via a get using the SDK)
    // for the time being just compare date and time zone
    Query<Record1<Map>> query = Query.buildNativeQuery("select e " + "from EHR e[ehr_id/value = $ehr_id]", Map.class);
    List<Record1<Map>> result = openEhrClient.aqlEndpoint().execute(query, new ParameterValue("ehr_id", ehrUUID));
    Map<String, Object> valueMap = result.get(0).value1();
    assertThat(new EhrComparator(referenceEhrStatus, ehrUUID, actualDvDateTime).compare(valueMap)).isNull();
}
Also used : ParameterValue(org.ehrbase.client.aql.parameter.ParameterValue) EhrComparator(org.ehrbase.client.openehrclient.defaultrestclient.systematic.comparator.EhrComparator) RMObject(com.nedap.archie.rm.RMObject) Record1(org.ehrbase.client.aql.record.Record1)

Example 5 with Record1

use of org.ehrbase.client.aql.record.Record1 in project openEHR_SDK by ehrbase.

the class CanonicalEhrQuery1IT method testEhrAttributesDrillDown3.

@Test
public void testEhrAttributesDrillDown3() {
    String rootPath = "e/ehr_status";
    RMObject referenceNode = referenceEhrStatus;
    String[] attributePaths = { "archetype_node_id", "archetype_details", "archetype_details/archetype_id", "archetype_details/archetype_id/value", "archetype_details/template_id", "archetype_details/template_id/value", "archetype_details/rm_version", "subject", "is_queryable", "is_modifiable" };
    for (String attributePath : attributePaths) {
        String aqlSelect = rootPath + "/" + attributePath;
        StringBuilder stringBuilder = new StringBuilder();
        stringBuilder.append("select ");
        stringBuilder.append(aqlSelect);
        stringBuilder.append(" from EHR e[ehr_id/value = $ehr_id]");
        Query<Record1<Map>> query = Query.buildNativeQuery(stringBuilder.toString(), Map.class);
        QueryResponseData result = openEhrClient.aqlEndpoint().executeRaw(query, new ParameterValue("ehr_id", ehrUUID));
        List<Object> objectList = result.getRows().get(0);
        assertThat(valueObject(objectList.get(0))).as(aqlSelect).isEqualTo(attributeValueAt(referenceNode, attributePath));
    }
}
Also used : ParameterValue(org.ehrbase.client.aql.parameter.ParameterValue) QueryResponseData(org.ehrbase.response.openehr.QueryResponseData) RMObject(com.nedap.archie.rm.RMObject) RMObject(com.nedap.archie.rm.RMObject) Record1(org.ehrbase.client.aql.record.Record1)

Aggregations

Record1 (org.ehrbase.client.aql.record.Record1)12 ParameterValue (org.ehrbase.client.aql.parameter.ParameterValue)8 RMObject (com.nedap.archie.rm.RMObject)6 QueryResponseData (org.ehrbase.response.openehr.QueryResponseData)4 ArrayList (java.util.ArrayList)3 UUID (java.util.UUID)3 Condition (org.ehrbase.client.aql.condition.Condition)3 EhrbaseBloodPressureSimpleDeV0Composition (org.ehrbase.client.classgenerator.examples.ehrbasebloodpressuresimpledev0composition.EhrbaseBloodPressureSimpleDeV0Composition)3 EhrbaseBloodPressureSimpleDeV0CompositionContainment (org.ehrbase.client.classgenerator.examples.ehrbasebloodpressuresimpledev0composition.EhrbaseBloodPressureSimpleDeV0CompositionContainment)3 BloodPressureTrainingSampleObservationContainment (org.ehrbase.client.classgenerator.examples.ehrbasebloodpressuresimpledev0composition.definition.BloodPressureTrainingSampleObservationContainment)3 VersionUid (org.ehrbase.client.openehrclient.VersionUid)3 Test (org.junit.Test)3 List (java.util.List)1 Containment (org.ehrbase.client.aql.containment.Containment)1 NativeSelectAqlField (org.ehrbase.client.aql.field.NativeSelectAqlField)1 OrderByExpression (org.ehrbase.client.aql.orderby.OrderByExpression)1 TopExpresion (org.ehrbase.client.aql.top.TopExpresion)1 WrongStatusCodeException (org.ehrbase.client.exception.WrongStatusCodeException)1 EhrComparator (org.ehrbase.client.openehrclient.defaultrestclient.systematic.comparator.EhrComparator)1 AutoWhereCondition (org.ehrbase.client.openehrclient.defaultrestclient.systematic.compositionquery.queries.auto.AutoWhereCondition)1