use of org.ehrbase.response.openehr.QueryResponseData in project ehrbase by ehrbase.
the class OpenehrQueryController method executeQuery.
private QueryResponseData executeQuery(String aql, Map<String, Object> parameters, HttpServletRequest request) {
QueryResponseData queryResponseData;
// get the query and pass it to the service
if (parameters != null && !parameters.isEmpty()) {
queryResponseData = new QueryResponseData(queryService.query(aql, parameters, QueryMode.AQL, false));
} else {
queryResponseData = new QueryResponseData(queryService.query(aql, QueryMode.AQL, false));
}
// Enriches request attributes with EhrId(s) for later audit processing
Map<String, Set<Object>> auditResultMap = queryService.getAuditResultMap();
request.setAttribute(OpenEhrAuditInterceptor.EHR_ID_ATTRIBUTE, auditResultMap.get(EHR_ID_VALUE));
return queryResponseData;
}
use of org.ehrbase.response.openehr.QueryResponseData in project ehrbase by ehrbase.
the class OpenehrQueryController method executeStoredQuery.
/**
* {@inheritDoc}
*/
@Override
@PostMapping(path = { "/{qualified_query_name}", "/{qualified_query_name}/{version}" })
@PostAuthorize("checkAbacPostQuery(@queryServiceImp.getAuditResultMap())")
@SuppressWarnings("unchecked")
public ResponseEntity<QueryResponseData> executeStoredQuery(@PathVariable(name = "qualified_query_name") String qualifiedQueryName, @PathVariable(name = "version", required = false) String version, @RequestHeader(name = ACCEPT, required = false) String accept, @RequestHeader(name = CONTENT_TYPE) String contentType, @RequestBody(required = false) Map<String, Object> queryRequest, HttpServletRequest request) {
logger.trace("postStoredQuery with the following input: {}, {}, {}", qualifiedQueryName, version, queryRequest);
// retrieve the stored query for execution
request.setAttribute(QueryAuditInterceptor.QUERY_ID_ATTRIBUTE, qualifiedQueryName);
QueryDefinitionResultDto queryDefinitionResultDto = queryService.retrieveStoredQuery(qualifiedQueryName, version != null ? version : LATEST);
String query = queryDefinitionResultDto.getQueryText();
if (query == null) {
var message = MessageFormat.format("Could not retrieve AQL {0}/{1}", qualifiedQueryName, version != null ? version : LATEST);
throw new ObjectNotFoundException("AQL", message);
}
// Enriches request attributes with aql for later audit processing
request.setAttribute(QueryAuditInterceptor.QUERY_ATTRIBUTE, query);
// retrieve the parameter from body
// get the query and parameters if any
Map<String, Object> queryParameter = null;
if (queryRequest != null && !queryRequest.isEmpty()) {
queryParameter = (Map<String, Object>) queryRequest.get(QUERY_PARAMETERS);
query = withOffsetLimit(query, queryRequest);
}
QueryResponseData queryResponseData = invoke(query, queryParameter, request);
queryResponseData.setName(queryDefinitionResultDto.getQualifiedName() + "/" + queryDefinitionResultDto.getVersion());
return ResponseEntity.ok(queryResponseData);
}
use of org.ehrbase.response.openehr.QueryResponseData in project ehrbase by ehrbase.
the class OpenehrQueryController method invoke.
private QueryResponseData invoke(String query, Map<String, Object> queryParameter, HttpServletRequest request) {
QueryResponseData queryResponseData;
if (queryParameter != null && !queryParameter.isEmpty()) {
Map<String, Object> parameters = new HashMap<>(queryParameter);
queryResponseData = new QueryResponseData(queryService.query(query, parameters, QueryMode.AQL, false));
} else {
queryResponseData = new QueryResponseData(queryService.query(query, QueryMode.AQL, false));
}
// Enriches request attributes with EhrId(s) for later audit processing
Map<String, Set<Object>> auditResultMap = queryService.getAuditResultMap();
request.setAttribute(OpenEhrAuditInterceptor.EHR_ID_ATTRIBUTE, auditResultMap.get(EHR_ID_VALUE));
return queryResponseData;
}
use of org.ehrbase.response.openehr.QueryResponseData in project ehrbase by ehrbase.
the class OpenehrQueryController method executeStoredQuery.
/**
* {@inheritDoc}
*/
@Override
@GetMapping(path = { "/{qualified_query_name}", "/{qualified_query_name}/{version}" })
@PostAuthorize("checkAbacPostQuery(@queryServiceImp.getAuditResultMap())")
public ResponseEntity<QueryResponseData> executeStoredQuery(@PathVariable(name = "qualified_query_name") String qualifiedQueryName, @PathVariable(name = "version", required = false) String version, @RequestParam(name = "offset", required = false) Integer offset, @RequestParam(name = "fetch", required = false) Integer fetch, @RequestParam(name = "query_parameters", required = false) Map<String, Object> queryParameter, @RequestHeader(name = ACCEPT, required = false) String accept, HttpServletRequest request) {
logger.trace("getStoredQuery not implemented but got following input: {} - {} - {} - {} - {}", qualifiedQueryName, version, offset, fetch, queryParameter);
// Enriches request attributes with query name for later audit processing
request.setAttribute(QueryAuditInterceptor.QUERY_ID_ATTRIBUTE, qualifiedQueryName);
// retrieve the stored query for execution
QueryDefinitionResultDto queryDefinitionResultDto = queryService.retrieveStoredQuery(qualifiedQueryName, version != null ? version : LATEST);
String query = queryDefinitionResultDto.getQueryText();
// Enriches request attributes with aql for later audit processing
request.setAttribute(QueryAuditInterceptor.QUERY_ATTRIBUTE, query);
if (fetch != null) {
// append LIMIT clause to aql
query = withFetch(query, fetch);
}
if (offset != null) {
// append OFFSET clause to aql
query = withOffset(query, offset);
}
QueryResponseData queryResponseData = invoke(query, queryParameter, request);
queryResponseData.setName(queryDefinitionResultDto.getQualifiedName() + "/" + queryDefinitionResultDto.getVersion());
return ResponseEntity.ok(queryResponseData);
}
use of org.ehrbase.response.openehr.QueryResponseData in project openEHR_SDK by ehrbase.
the class AqlTestIT method testExecute13.
@Test
public void testExecute13() throws IOException {
ehr = openEhrClient.ehrEndpoint().createEhr();
Composition composition = new CanonicalJson().unmarshal(IOUtils.toString(CompositionTestDataCanonicalJson.CORONA.getStream(), StandardCharsets.UTF_8), Composition.class);
Flattener flattener = new Flattener(new TestDataTemplateProvider());
CoronaAnamneseComposition coronaAnamneseComposition = flattener.flatten(composition, CoronaAnamneseComposition.class);
coronaAnamneseComposition.setVersionUid(null);
openEhrClient.compositionEndpoint(ehr).mergeCompositionEntity(coronaAnamneseComposition);
Query query = Query.buildNativeQuery("Select DISTINCT " + " o/data[at0001]/events[at0002]/data[at0003]/items[at0022]/items[at0005]/value/value as var1, o/data[at0001]/events[at0002]/data[at0003]/items[at0022]/items[at0004]/value/value as var2 " + " from EHR e[ehr_id/value = $ehr_id] " + " contains COMPOSITION c3[openEHR-EHR-COMPOSITION.report.v1]" + " contains SECTION s4[openEHR-EHR-SECTION.adhoc.v1]" + " contains OBSERVATION o[openEHR-EHR-OBSERVATION.symptom_sign_screening.v0]" + " WHERE" + " o/data[at0001]/events[at0002]/data[at0003]/items[at0022]/items[at0005]/value/value is not null " + " AND" + " o/data[at0001]/events[at0002]/data[at0003]/items[at0022]/items[at0004]/value/value is not null");
QueryResponseData result = openEhrClient.aqlEndpoint().executeRaw(query, new ParameterValue("ehr_id", ehr));
assertNotNull(result);
assertNotNull(result.getQuery());
assertNotNull(result.getRows());
assertNotNull(result.getColumns());
assertEquals(14, result.getRows().size());
assertEquals(2, result.getColumns().size());
List expectedResults = Arrays.asList(List.of("Nicht vorhanden", "Durchfall"), List.of("Nicht vorhanden", "Fieber oder erhöhte Körpertemperatur"), List.of("Nicht vorhanden", "gestörter Geruchssinn"), List.of("Nicht vorhanden", "gestörter Geschmackssinn"), List.of("Nicht vorhanden", "Heiserkeit"), List.of("Nicht vorhanden", "Husten"), List.of("Nicht vorhanden", "Schnupfen"), List.of("Vorhanden", "Durchfall"), List.of("Vorhanden", "Fieber oder erhöhte Körpertemperatur"), List.of("Vorhanden", "gestörter Geruchssinn"), List.of("Vorhanden", "gestörter Geschmackssinn"), List.of("Vorhanden", "Heiserkeit"), List.of("Vorhanden", "Husten"), List.of("Vorhanden", "Schnupfen"));
assertTrue(CollectionUtils.isEqualCollection(result.getRows(), expectedResults));
}
Aggregations