Commit 95b55ef4 authored by Georg Fette's avatar Georg Fette
Browse files

- fixed cypher object tree return mechanism

- added another aql2cypher test with multiplereturnobjects
parent e3bc521d
......@@ -135,16 +135,7 @@ public class Graph_2_Cypher_Mapper extends Graph_2_System_Mapper {
QueryOperator resolveAlias = aConc.resolveAlias();
result = writeExpression(resolveAlias);
if (resolveAlias.isConcept() && resolveAlias.hasToBeReturned() && retrieveAllChildNodesInResult) {
String alias = aliases.get(resolveAlias);
String output;
if (aConc.outputName == null) {
output = alias;
} else {
output = aConc.outputName;
}
output = StringUtilsUniWue.cleanStringFromSpecialCharacters(output);
result = "last(nodes(" + result + "_paths)) as " + output + "_rm_object, extract(r in relationships(" + alias
+ "_paths) | type(r)) as " + output + "_relationships";
result = aliases.get(resolveAlias);
}
} else if (aConc.type == OperatorType.INDEXED_FIELD) {
// the INDEXED_FIELDS are already handled in the Match via aliases
......@@ -471,8 +462,18 @@ public class Graph_2_Cypher_Mapper extends Graph_2_System_Mapper {
List<String> returnExpStrings = new ArrayList<String>();
QueryOperator returnOp = query.getParameters().get(1).asOperator();
for (Expression anExp : returnOp.getParameters()) {
String expString = writeExpression(anExp);
returnExpStrings.add(expString);
String returnString;
if (anExp.asOperator().type == OperatorType.ALIAS_REF) {
QueryOperator aliasedOperator = anExp.asOperator().resolveAlias();
String cypherAlias = aliases.get(aliasedOperator);
returnString = "tree_" + cypherAlias;
if (aliasedOperator.asOperator().alias != null) {
returnString += " AS " + aliasedOperator.asOperator().alias;
}
} else {
returnString = writeExpression(anExp);
}
returnExpStrings.add(returnString);
}
result += StringUtilsUniWue.concat(returnExpStrings, ", ");
return result.trim();
......@@ -542,11 +543,32 @@ public class Graph_2_Cypher_Mapper extends Graph_2_System_Mapper {
private String writeCalls() {
List<String> resultStrings = new ArrayList<String>();
List<QueryOperator> concepts = query.getConcepts();
for (QueryOperator aConc : concepts) {
if (aConc.hasToBeReturned() && retrieveAllChildNodesInResult) {
if (retrieveAllChildNodesInResult) {
List<QueryOperator> conceptToReturn = new ArrayList<QueryOperator>();
for (QueryOperator aConc : concepts) {
if (aConc.hasToBeReturned()) {
conceptToReturn.add(aConc);
}
}
List<QueryOperator> processedConcepts = new ArrayList<QueryOperator>();
for (QueryOperator aConc : conceptToReturn) {
String alias = aliases.get(aConc);
resultStrings.add("MATCH path_" + alias + " = (" + alias + ") -[*]-> (leaf)");
String withString = "WITH collect(path_" + alias + ") as paths_" + alias;
for (QueryOperator aConc2 : conceptToReturn) {
String alias2 = aliases.get(aConc2);
withString += ", " + alias2;
if (processedConcepts.contains(aConc2)) {
withString += ", paths_" + alias2;
}
}
resultStrings.add(withString);
processedConcepts.add(aConc);
}
for (QueryOperator aConc : conceptToReturn) {
String alias = aliases.get(aConc);
resultStrings.add("CALL apoc.path.spanningTree(" + alias + ", {relationshipFilter:'>'}) yield path as " + alias
+ "_paths");
resultStrings.add("CALL apoc.convert.toTree(paths_" + alias + ") yield value as tree_" + alias);
}
}
String result = StringUtilsUniWue.concat(resultStrings, "\n").trim();
......
......@@ -37,8 +37,8 @@ WHERE
C.value = 'Natrium_g_dl' AND
C.archetype_node_id = 'at0024' AND
B.archetype_node_id = 'openEHR-EHR-CLUSTER.laboratory_test_analyte_dvquantity.v1'
MATCH
path = (A) -[*] -> (leaf) WITH collect(path) as paths
CALL apoc.convert.toTree(paths) YIELD value
MATCH path_A = (A) -[*]-> (leaf)
WITH collect(path_A) as paths_A, A
CALL apoc.convert.toTree(paths_A) yield value as tree_A
RETURN
value as tree
\ No newline at end of file
tree_A AS e
\ No newline at end of file
......@@ -30,8 +30,8 @@ MATCH
WHERE
B.archetype_node_id = 'openEHR-EHR-OBSERVATION.laboratory_test_result.v1' AND
C.archetype_node_id = 'openEHR-EHR-OBSERVATION.laboratory_test_result.v1'
MATCH
path = (A) -[*] -> (leaf) WITH collect(path) as paths
CALL apoc.convert.toTree(paths) YIELD value
MATCH path_A = (A) -[*]-> (leaf)
WITH collect(path_A) as paths_A, A
CALL apoc.convert.toTree(paths_A) yield value as tree_A
RETURN
value as tree
\ No newline at end of file
tree_A AS e
\ No newline at end of file
......@@ -60,8 +60,8 @@ WHERE
F.archetype_node_id = 'at0001' AND
B.archetype_node_id = 'openEHR-EHR-CLUSTER.laboratory_test_analyte_dvquantity.v1' AND
C.archetype_node_id = 'openEHR-EHR-CLUSTER.laboratory_test_analyte_dvquantity.v1'
MATCH
path = (A) -[*] -> (leaf) WITH collect(path) as paths
CALL apoc.convert.toTree(paths) YIELD value
MATCH path_A = (A) -[*]-> (leaf)
WITH collect(path_A) as paths_A, A
CALL apoc.convert.toTree(paths_A) yield value as tree_A
RETURN
value as tree
\ No newline at end of file
tree_A AS e
\ No newline at end of file
......@@ -61,8 +61,8 @@ WHERE
E.archetype_node_id = 'at0024' AND
B.archetype_node_id = 'openEHR-EHR-CLUSTER.laboratory_test_analyte_dvquantity.v1' AND
C.archetype_node_id = 'openEHR-EHR-CLUSTER.laboratory_test_analyte_dvquantity.v1'
MATCH
path = (A) -[*] -> (leaf) WITH collect(path) as paths
CALL apoc.convert.toTree(paths) YIELD value
MATCH path_A = (A) -[*]-> (leaf)
WITH collect(path_A) as paths_A, A
CALL apoc.convert.toTree(paths_A) yield value as tree_A
RETURN
value as tree
\ No newline at end of file
tree_A AS e
\ No newline at end of file
......@@ -30,8 +30,8 @@ MATCH
WHERE
B.archetype_node_id = 'openEHR-EHR-OBSERVATION.laboratory_test_result.v1' AND
C.archetype_node_id = 'openEHR-EHR-CLUSTER.laboratory_test_analyte.v1'
MATCH
path = (A) -[*] -> (leaf) WITH collect(path) as paths
CALL apoc.convert.toTree(paths) YIELD value
MATCH path_A = (A) -[*]-> (leaf)
WITH collect(path_A) as paths_A, A
CALL apoc.convert.toTree(paths_A) yield value as tree_A
RETURN
value as tree
\ No newline at end of file
tree_A AS e
\ No newline at end of file
......@@ -48,8 +48,8 @@ WHERE
C.archetype_node_id = 'openEHR-EHR-OBSERVATION.laboratory_test_result.v1' AND
E.archetype_node_id = 'openEHR-EHR-CLUSTER.laboratory_test_analyte_dvquantity.v1' AND
D.archetype_node_id = 'openEHR-EHR-OBSERVATION.blood_pressure.v2'
MATCH
path = (A) -[*] -> (leaf) WITH collect(path) as paths
CALL apoc.convert.toTree(paths) YIELD value
MATCH path_A = (A) -[*]-> (leaf)
WITH collect(path_A) as paths_A, A
CALL apoc.convert.toTree(paths_A) yield value as tree_A
RETURN
value as tree
\ No newline at end of file
tree_A AS e
\ No newline at end of file
*AQL
SELECT e, a, e/ehr_id
FROM EHR e
CONTAINS COMPOSITION a[openEHR-EHR-COMPOSITION.report.v1]
*Graph
QUERY(
FILTER(
ITERATE('EHR') as e,
EXISTS(CONTAINS_TYPE(
ALIAS_REF('e'),
'COMPOSITION',
'openEHR-EHR-COMPOSITION.report.v1'
) as a)
),
RETURN(
ALIAS_REF('e') out 'e',
ALIAS_REF('a') out 'a',
FIELD(
ALIAS_REF('e'),
'ehr_id'
) out 'e/ehr_id'
)
)
*Cypher
MATCH
(A:EHR), (A)-[*]->(B:COMPOSITION)
WHERE
B.archetype_node_id = 'openEHR-EHR-COMPOSITION.report.v1'
MATCH path_A = (A) -[*]-> (leaf)
WITH collect(path_A) as paths_A, A, B
MATCH path_B = (B) -[*]-> (leaf)
WITH collect(path_B) as paths_B, A, paths_A, B
CALL apoc.convert.toTree(paths_A) yield value as tree_A
CALL apoc.convert.toTree(paths_B) yield value as tree_B
RETURN
tree_A AS e, tree_B AS a, A.ehr_id as e_ehr_id
\ No newline at end of file
......@@ -60,8 +60,8 @@ WHERE
E.archetype_node_id = 'at0002' AND
C.archetype_node_id = 'openEHR-EHR-EVALUATION.gender.v1' AND
B.archetype_node_id = 'openEHR-EHR-COMPOSITION.report.v1'
MATCH
path = (B) -[*] -> (leaf) WITH collect(path) as paths
CALL apoc.convert.toTree(paths) YIELD value
MATCH path_B = (B) -[*]-> (leaf)
WITH collect(path_B) as paths_B, B
CALL apoc.convert.toTree(paths_B) yield value as tree_B
RETURN
value as tree
\ No newline at end of file
tree_B AS a
\ No newline at end of file
......@@ -18,8 +18,8 @@ QUERY(
*Cypher
MATCH
(A:EHR), (A)-[*]->(B:Banana)
MATCH
path = (A) -[*] -> (leaf) WITH collect(path) as paths
CALL apoc.convert.toTree(paths) YIELD value
MATCH path_A = (A) -[*]-> (leaf)
WITH collect(path_A) as paths_A, A
CALL apoc.convert.toTree(paths_A) yield value as tree_A
RETURN
value as tree
\ No newline at end of file
tree_A AS e
\ No newline at end of file
......@@ -40,8 +40,8 @@ WHERE
120 < D.magnitude AND
C.archetype_node_id = 'at0001' AND
B.archetype_node_id = 'openEHR-EHR-CLUSTER.laboratory_test_analyte_dvquantity.v1'
MATCH
path = (A) -[*] -> (leaf) WITH collect(path) as paths
CALL apoc.convert.toTree(paths) YIELD value
MATCH path_A = (A) -[*]-> (leaf)
WITH collect(path_A) as paths_A, A
CALL apoc.convert.toTree(paths_A) yield value as tree_A
RETURN
value as tree
\ No newline at end of file
tree_A AS e
\ No newline at end of file
......@@ -39,8 +39,8 @@ WHERE
D.archetype_node_id = 'openEHR-EHR-ADMIN_ENTRY.discharge_summary.v0' AND
B.archetype_node_id = 'openEHR-EHR-COMPOSITION.encounter.v1' AND
C.archetype_node_id = 'openEHR-EHR-ADMIN_ENTRY.admission.v0'
MATCH
path = (A) -[*] -> (leaf) WITH collect(path) as paths
CALL apoc.convert.toTree(paths) YIELD value
MATCH path_A = (A) -[*]-> (leaf)
WITH collect(path_A) as paths_A, A
CALL apoc.convert.toTree(paths_A) yield value as tree_A
RETURN
value as tree
\ No newline at end of file
tree_A AS e
\ No newline at end of file
......@@ -39,8 +39,8 @@ WHERE
NOT EXISTS ((B)-[:content]->(:ADMIN_ENTRY{archetype_node_id:'openEHR-EHR-ADMIN_ENTRY.discharge_summary.v0'})) AND
B.archetype_node_id = 'openEHR-EHR-COMPOSITION.encounter.v1' AND
C.archetype_node_id = 'openEHR-EHR-ADMIN_ENTRY.admission.v0'
MATCH
path = (A) -[*] -> (leaf) WITH collect(path) as paths
CALL apoc.convert.toTree(paths) YIELD value
MATCH path_A = (A) -[*]-> (leaf)
WITH collect(path_A) as paths_A, A
CALL apoc.convert.toTree(paths_A) yield value as tree_A
RETURN
value as tree
\ No newline at end of file
tree_A AS e
\ No newline at end of file
......@@ -30,8 +30,8 @@ MATCH
WHERE
NOT EXISTS ((B)-[:content]->(:ADMIN_ENTRY{archetype_node_id:'openEHR-EHR-ADMIN_ENTRY.discharge_summary.v0'})) AND
B.archetype_node_id = 'openEHR-EHR-COMPOSITION.encounter.v1'
MATCH
path = (A) -[*] -> (leaf) WITH collect(path) as paths
CALL apoc.convert.toTree(paths) YIELD value
MATCH path_A = (A) -[*]-> (leaf)
WITH collect(path_A) as paths_A, A
CALL apoc.convert.toTree(paths_A) yield value as tree_A
RETURN
value as tree
\ No newline at end of file
tree_A AS e
\ No newline at end of file
......@@ -84,8 +84,8 @@ WHERE
E.archetype_node_id = 'at0024' AND
F.archetype_node_id = 'at0024' AND
B.archetype_node_id = 'openEHR-EHR-CLUSTER.laboratory_test_analyte.v1'
MATCH
path = (A) -[*] -> (leaf) WITH collect(path) as paths
CALL apoc.convert.toTree(paths) YIELD value
MATCH path_A = (A) -[*]-> (leaf)
WITH collect(path_A) as paths_A, A
CALL apoc.convert.toTree(paths_A) yield value as tree_A
RETURN
value as tree
\ No newline at end of file
tree_A AS e
\ No newline at end of file
......@@ -40,8 +40,8 @@ WHERE
D.magnitude = 10 AND
C.archetype_node_id = 'at0001' AND
B.archetype_node_id = 'openEHR-EHR-CLUSTER.laboratory_test_analyte_dvquantity.v1'
MATCH
path = (A) -[*] -> (leaf) WITH collect(path) as paths
CALL apoc.convert.toTree(paths) YIELD value
MATCH path_A = (A) -[*]-> (leaf)
WITH collect(path_A) as paths_A, A
CALL apoc.convert.toTree(paths_A) yield value as tree_A
RETURN
value as tree
\ No newline at end of file
tree_A AS e
\ No newline at end of file
......@@ -21,8 +21,8 @@ MATCH
(A:EHR), (A)-[*]->(B:COMPOSITION)
WHERE
B.archetype_node_id = 'openEHR-EHR-COMPOSITION.encounter.v1'
MATCH
path = (A) -[*] -> (leaf) WITH collect(path) as paths
CALL apoc.convert.toTree(paths) YIELD value
MATCH path_A = (A) -[*]-> (leaf)
WITH collect(path_A) as paths_A, A
CALL apoc.convert.toTree(paths_A) yield value as tree_A
RETURN
value as tree
\ No newline at end of file
tree_A AS e
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment