How to Model a Schema for Best Retrieve Information

Hello friends.

I have two questions for you.

1st.) Currently, I am modeling a new application and I need to relate a Patient node with several Measures (there are 13 types of those) nodes, as per the attached image

If my model defines the measurementDate is located in the HAS relationship, is it feasible to transverse the graph to retrieve all measures from a group of patients ordered by patientId and measurementDate? Or extract all nodes from a range of dates?

This is a classic example of a MxN relationship in a relational database and, in this case, I would model the measurementDate field in the MxN table.

Is this approach correct?

2nd.) Person and Patient nodes share lots of information and Patient node is a derivation from Person node - you must be a Person before being a Patient. In the image, I have a Person (node) who is responsible for a Patient (node) like a mother is responsible for her child, the Patient is also Person

Should I replicate all shared attributes for both nodes or the attributes are automatically inherited from Person to Patient somehow? Does it make sense?

Thanks for your attention.

I'm fairly new to neo4j but I think I can offer some help.

The relationships between nodes are first class citizens, meaning they are just as important as the nodes. So you could think of your MxN join table as the HAS relationship and add the measurementDate attribute to the relationship HAS.

(:Patient)-[:HAS {measurementDate: date()]->(:Measure)

Traversing the graph to retrieve all measure from a group of patients and ordered by patientId and measurementDate is certainly feasible in this way. You would need to decide what format to save the measurementDate in however.

MATCH (p:Patient)-[rel:HAS]->(m:Measure) WHERE p.patientId IN [12,14,16] RETURN (p)-[rel]->(m) ORDER BY p.patientId, rel.measurementDate

Attributes are not inherited between nodes. I would say however, to treat them as separate entities and keep only Patient related attributes, in the Patient node, and any Person attributes only in the Person node.
Optionally you could actually treat them as a single node with two labels. So if a Person was also a Patient, you would just use one node with two labels. (p:Person:Patient)

1 Like

Hello @PeteM

You confirmed my supposition. I really appreciate your support in these questions, you saved me time on research, which I´ll use to better model my graph.

Thank you very much.

No problem. One thing that I have found is you can easily adjust your graph model depending on your needs. You could also deploy a test graph you can chop and change until it fits your needs (i.e. queries you want to run against it).

1 Like

(post withdrawn by author, will be automatically deleted in 24 hours unless flagged)