Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
08-28-2020 09:58 AM
Hello guys.
I'm modeling a health graph and got an unexpected behavior in my model.
There are three nodes - Test, TestResult and EMR. If you execute the following commands, you will see this schema;
// EMR
MERGE (e:EMR {id:toInteger(6700001)}) ON CREATE SET e.id=toInteger(6700001), e.observation='PEP';
// Test
MERGE (t:Test {id:toInteger(16000001)}) ON CREATE SET t.id=toInteger(16000001), t.description='Glucose';
// TestResult
MERGE (t:TestResult {id:toInteger(85000001)}) ON CREATE SET t.id=toInteger(85000001), t.description='Glucose', t.value=toFloat(96), t.measurementUnit='mg/dL', t.collectDate=date('2015-08-27'), t.source='serum';
// Test x TestResult - BELONGS_TO
MATCH (e:Test), (t:TestResult) WHERE t.id=85000001 AND e.id=16000001 MERGE (t)-[r:BELONGS_TO]->(e);
So far, so good.
Now I want that all Test nodes to belong to the EMR node, which is my wallet for medical tests. For that you may execute the following command:
// EMR x Test - BELONGS_TO
MATCH (e:EMR), (t:Test) WHERE t.id=16000001 AND e.id=6700001 MERGE (t)-[r:BELONGS_TO]->(e) SET r.releaseDate=date('2015-08-27');
I expected something like this as result of the command:
But what I've got is this:
However, if I just query for Test nodes, I get this (which is exactly what I want to.):
What I missed? What I did wrong? I really don't get why (in the schema visualization) there is a self-relation in Test Node and why there is a relation between TestResult and EMR if I didn't explicitly ask for it. In fact, I'm not sure if the graph would behave like the query or like the schema in the future when there will be millions of nodes and hundreds of millions of relations.
Solved! Go to Solution.
08-28-2020 10:45 AM
Could you send the table results for the query that has that extra relationship? Looks like there's more data, and probably some other merge/create statements that are causing the trouble here.
There's some cleanup to do...
MERGE (e:EMR {id:toInteger(6700001)})
ON CREATE SET e.observation='PEP';
MERGE (emr:EMR {id:toInteger(6700001)}) ON CREATE SET emr.observation='PEP'
MERGE (test:Test {id:toInteger(16000001)}) ON CREATE SET test.description='Glucose'
MERGE (result:TestResult {id:toInteger(85000001)}) ON CREATE SET result.description='Glucose', result.value=toFloat(96), result.measurementUnit='mg/dL', result.collectDate=date('2015-08-27'), result.source='serum'
MERGE (result)-[:BELONGS_TO]->(test)
MERGE (test)-[rel:BELONGS_TO]->(emr) ON CREATE SET rel.releaseDate=date('2015-08-27')
There's likely some other data and merge/create commands somewhere that are creating that extra relationship.
http://console.neo4j.org/?id=9z0wvl
08-28-2020 10:43 AM
Interesting, my first guess, there might be a bug in db.schema.visualization?
I usually use
call apoc.meta.graph()
and here we see the expected model
08-28-2020 02:11 PM
Joel.
Thanks for this apoc function. I really don't know much about Neo4j. And the best part is that the schema seems to display correctly now, take a look:
About db.schema.visualization
, I cannot say if there is a bug in there. I guess not, but only a guess.
Thanks for your support.
08-31-2020 10:53 AM
I did a little more poking around at it, and YES, there is a bug in there.
After changing the relationship labels from :BELONGS_TO
to :RES_TEST
and :TEST_EMR
, the result was as expected.
09-02-2020 03:39 PM
Now I just use the procedure apoc.meta.graph
, it is working fine. But it is very strange the schema.visualization()
not working in that scenario.
I appreciate the effort on helping me to solve this.
10-31-2020 09:29 AM
Well, it is good news. But, for me, it continues not working.
08-28-2020 10:45 AM
Could you send the table results for the query that has that extra relationship? Looks like there's more data, and probably some other merge/create statements that are causing the trouble here.
There's some cleanup to do...
MERGE (e:EMR {id:toInteger(6700001)})
ON CREATE SET e.observation='PEP';
MERGE (emr:EMR {id:toInteger(6700001)}) ON CREATE SET emr.observation='PEP'
MERGE (test:Test {id:toInteger(16000001)}) ON CREATE SET test.description='Glucose'
MERGE (result:TestResult {id:toInteger(85000001)}) ON CREATE SET result.description='Glucose', result.value=toFloat(96), result.measurementUnit='mg/dL', result.collectDate=date('2015-08-27'), result.source='serum'
MERGE (result)-[:BELONGS_TO]->(test)
MERGE (test)-[rel:BELONGS_TO]->(emr) ON CREATE SET rel.releaseDate=date('2015-08-27')
There's likely some other data and merge/create commands somewhere that are creating that extra relationship.
http://console.neo4j.org/?id=9z0wvl
08-28-2020 03:39 PM
@tony, thanks for these suggestions, I rewrote my queries based on that.
Regarding the table results, there were just those 3 nodes in the entire database, so what you see is what you get. But, when I executed apoc.meta.graph
, the schema was displayed correctly. Who figured...
All the sessions of the conference are now available online