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));
}
}
}
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());
}
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;
}
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();
}
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));
}
}
Aggregations