
var config  = require('../config/config.js');
var neo4j = require('neo4j');
var _ = require("lodash");

var db = new neo4j.GraphDatabase({
    url: 'http://localhost:7474',
    auth: config.neo4j
***REMOVED***);


module.exports = function *() {
***REMOVED*** var query = 'MATCH (t1:Concept { name:{A***REMOVED*** ***REMOVED***), (t2:Concept { name:{B***REMOVED*** ***REMOVED***), p = allShortestPaths((t1)-[:is_part_of*..2]-(t2)) return p, ID(p)';
    var query = 'MATCH (t1:Concept { name:{A***REMOVED*** ***REMOVED***), (t2:Concept { name:{B***REMOVED*** ***REMOVED***), (g:Group), (t1)-[:is_part_of]->(g)<-[:is_part_of]-(t2), g<-[:is_part_of]-(r) return t1, t2, g, ID(g) as ID, COLLECT(r) as terms'
    var params = this.request.body.query;

    var cypherObj = {
        "query"  : query,
        "params" : {
            "A": params[0],
            "B": params[1]
    ***REMOVED***,

        "lean": true
***REMOVED***;

    var result = yield function(callback) {
        db.cypher(cypherObj, function(err, paths) {
            if (err) {
              console.log(err);
              callback(false, [])
        ***REMOVED***

            var found = [];

            for (var i=0; i < paths.length; i++) {
                var finding = paths[i];

            ***REMOVED*** If no group found, skip
                if (! finding.hasOwnProperty("g")) {
                    continue;
            ***REMOVED***

                var rel = {
                    "groupId": finding["ID"],
                    "groupName": finding["g"]["name"],
                    "abbreviation": finding["g"]["abbr"] || "",
                    "description" : finding["g"]["description"] || "",
                    "groupTerms"  : finding["terms"]
            ***REMOVED***

                found.push(rel);
        ***REMOVED***

            callback(null, found)
    ***REMOVED***);
***REMOVED***

    this.body = result;
***REMOVED***;

@@ -244,211 +244,796 @@
 ) %7B%0A
-***REMOVED*** var query = 'MATCH (t1:Concept %7B name:%7BA***REMOVED*** ***REMOVED***), (t2:Concept %7B name:%7BB***REMOVED*** ***REMOVED***), p = allShortestPaths((t1)-%5B:is_part_of*..2%5D-(t2)) return p, ID(p)';%0A
+    var params = this.request.body.query;%0A    var cypherObj = false;%0A%0A***REMOVED*** Query can be a list of terms or list of object with cui + string%0A    if (typeof params%5B0%5D === %22string%22) %7B%0A        var query = 'MATCH (t1:Concept %7B name:%7BA***REMOVED*** ***REMOVED***), (t2:Concept %7B name:%7BB***REMOVED*** ***REMOVED***), (g:Group), (t1)-%5B:is_part_of%5D-%3E(g)%3C-%5B:is_part_of%5D-(t2), g%3C-%5B:is_part_of%5D-(r) return t1, t2, g, ID(g) as ID, COLLECT(r) as terms'%0A%0A        var cypherObj = %7B%0A            %22query%22  : query,%0A            %22params%22 : %7B%0A                %22A%22: params%5B0%5D.toLowerCase(),%0A                %22B%22: params%5B1%5D.toLowerCase()%0A        ***REMOVED***,%0A%0A            %22lean%22: true%0A    ***REMOVED***;%0A***REMOVED***%0A    else if (typeof params%5B0%5D === %22object%22 && params%5B0%5D.hasOwnProperty(%22cui%22)) %7B%0A    
     
@@ -1057,36 +1057,35 @@
 H (t1:Concept %7B 
-name
+cui
 :%7BA***REMOVED***
@@ -1107,36 +1107,35 @@
 , (t2:Concept %7B 
-name
+cui
 :%7BB***REMOVED***
@@ -1284,51 +1284,13 @@
 ms'%0A
+%0A
     
-var params = this.request.body.query;%0A%0A
     
@@ -1307,32 +1307,36 @@
 Obj = %7B%0A        
+    
 %22query%22  : query
@@ -1337,32 +1337,36 @@
  query,%0A        
+    
 %22params%22 : %7B%0A   
@@ -1354,32 +1354,36 @@
    %22params%22 : %7B%0A
+    
             %22A%22:
@@ -1392,18 +1392,31 @@
 arams%5B0%5D
-,%0A
+.cui %7C%7C %22%22,%0A   
         
@@ -1411,32 +1411,33 @@
 %0A               
+ 
 %22B%22: params%5B1%5D%0A 
@@ -1434,21 +1434,35 @@
 arams%5B1%5D
-%0A
+.cui %7C%7C %22%22%0A  
     
+  
 ***REMOV
@@ -1469,32 +1469,36 @@
 ED***,%0A%0A        
+    
 %22lean%22: true%0A***
@@ -1494,16 +1494,20 @@
 %22: true%0A
+    
 ***REMOV
@@ -1513,16 +1513,94 @@
 VED***;%0A
+***REMOVED***%0A    ***REMOVED***%0A        return this.body = %5B%5D;%0A***REMOVED***%0A%0A
 %0A    var

make suggestion work with CUI