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.

Add weights to a relation, and fetch the path with highest weight using neo4j-ogm

I'm new to using neo4j. I'm trying to build a frequency graph which holds a patient record in a path like shown below.

Ex: Diagnosis--> Gender--> Age--> Medcine

Consider a situation like this where db is used to record a medical record of a patient.
1.Patient A is Male aged in 20's has disease A and is precribed DrugA
2.Patient B is Male aged in 20's has disease A and is precribed DrugA
3.Patient C is Male aged in 20's has disease A and is precribed DrugA
4.Patient D is Male aged in 20's has disease A and is precribed DrugB

Final Graph after inserting each record should look like this.

Disase A---(4)--->MALE---(4)--->20's---(3)-->Drug A
Disase A---(4)--->MALE---(4)--->20's--- (1)-->Drug B

When a same record is inserted weights should get incremented.

How do I design my NodeEntity,RelationEntity such i can get resultant path with highest weight?

Thanks in advance.

1 REPLY 1

Benoit_d
Graph Buddy

Hi Nirmalmahen,

Before inserting new data in the graph, you will have to query the graph to get the data. I only worked on the querying.

It might be my own preference on design, but I see age and sex as a property of the patient. Sex and age are quantification/qualification which doesn't have own properties. So they can be defined as nodes but then they have only a relation to patient not to drugs or disease.

With age and sex as Patients properties, it is about querying all the path between Disease and drugs, clustering/grouping the patients with same age and sex and grouping the whole while counting the path of each cluster. Then return ordered decreasing on path count and limit to 1 to have only the cluster with the biggest amount of path.

match p=(di:Disease)<--(pa:Patient)-->(dr:Drug)
with di, pa.age as p_age, pa.sex as p_sex, count(p) as cp, dr
return di, p_age, p_sex, dr, cp order by cp desc limit 1

It returns the Disease+Drug combination with the biggest group of patients of the same age and sex.

I'm not sure this solution could work with your design. You will have to combine sex-nodes and age-nodes together.

Kind regards
Benoit