cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

Create path from distinct nodes

Hello,
I'm new with neo4j and need to generate a grah with the COVID-19 Patients in my hospital in the form:
(p:Patient)-[:Is_covid19_patient]->(d:Diagnosis).
Because a patient has many cases, I wrote this code in cypher to select the different patients and different covid variants:
match p=(pat:Patient)-[:Is_case]->(:Case)-[:Has_second_diagnosis]->(di:Diagnosis) where di.diagnosisName contains 'COVID' return distinct pat, di.

Thank.

Abel

1 ACCEPTED SOLUTION

So you just want to do this?

MATCH p=(pat:Patient)-[:Is_case]->(ca:Case)-[:Has_second_diagnosis]->(di:Diagnosis:Secondary)
WHERE di.diagnosisName =~ '(?i).*COVID-19.*'
WITH DISTINCT pat, di
MERGE (pat)-[:Is_covid19_patient]->(di)

View solution in original post

4 REPLIES 4

Hello @abel.hodelin.hernand and welcome to the Neo4j community

Can you tell us what you are trying to accomplish?
Can you give us a small example that you would expect?

Regards,
Cobra

Hello Cobra,
I habe selected the different patients with covid and the different covid variants with this code:
match p=(pat:Patient)-[:Is_case]->(ca:Case)-[:Has_second_diagnosis]->(di:Diagnosis:Secondary) where di.diagnosisName contains 'COVID-19' return distinct pat, di;

I habe created this code because I don't habe a direct edge from patients (pat:Patient) to diagnosis (di:Diagnosis). The only way to know if a patient has a diagnosis is via cases (ca:Case). A patient can have more than one case and a case can have more than one primary diagnosis (di:Diagnosis:Primary {diagnosisPId: ...}), wich determine the secondary diagnosis (di:Diagnosis:Secondary {diagnosisSId: ...}) in the form (ca:Case)-[:Has_secondary_diagnosis {diagnosisPId: ...} ]->(dis:Diagnosis:Secondary)

From the node with the different patients and covid variants I need to create a graph only with the nodes of patients and diagnosis in the form (p:Patient {patientId: ... })-[icp:Is_covid19_patient]->(d:Diagnosis:Secondary {diagnosisSId: ... })

Thank

So you just want to do this?

MATCH p=(pat:Patient)-[:Is_case]->(ca:Case)-[:Has_second_diagnosis]->(di:Diagnosis:Secondary)
WHERE di.diagnosisName =~ '(?i).*COVID-19.*'
WITH DISTINCT pat, di
MERGE (pat)-[:Is_covid19_patient]->(di)

Thank so much!!
Muchas Gracias!!
Vielen Danke!!