David A Stumpf
David A Stumpf

Reputation: 793

Neo4j Cypher ToInt function not working

I am using Neo4j v 2.3.0. This cypher query returns zeros for LOS. DaysOfCare is a string.

MATCH x-[rr]-(a:Discharge)-[r]-(b:Dx)
WHERE b.ICD9='25000'
RETURN
  x.ICD9,
  x.DIAG_DESC,
  type(r),
  count(x.DIAG_DESC) as Ct,    
  sum(TOINT(x.DaysOfCare)) as LOS
ORDER BY Ct DESC LIMIT 250  

What's wrong here?

Has ToInt not yet been added as planned? Is this a bug or am I using the combination of Sum and ToInt incorrectly?

Upvotes: 1

Views: 539

Answers (2)

David A Stumpf
David A Stumpf

Reputation: 793

The query in the original question was not summing the correct data. This query produces the anticipated results:

MATCH x-[rr]-(a:Discharge)-[r]-(b:Dx) where b.ICD9='25000'  RETURN x.ICD9,x.DIAG_DESC,type(r),count(x.DIAG_DESC) as Ct,sum(ToInt(a.DaysOfCare)) as LOS order by Ct desc LIMIT 250

The a-node set is hospital discharges, which contains metadata, including the days of care. The query seeks a target diagnosis (25000 = diabetes mellitus) and then in the x nodes, other discharge diagnoses. The associated diagnoses are not random; certain conditions are clustered. First few lines of output are:

enter image description here

Clearly, ToInt is working correctly ... it's the user who was messed up.

Upvotes: 0

Brian Underwood
Brian Underwood

Reputation: 10856

The TOINT function has been part of Cypher for a while. What if you tried to change this line:

sum(TOINT(x.DaysOfCare)) as LOS

To this:

collect(x.DaysOfCare) as LOS

That might give you some insight as to why it's not working.

Upvotes: 1

Related Questions