# How to Model a Schema for Best Retrieve Information

**URL:** <https://community.neo4j.com/t/how-to-model-a-schema-for-best-retrieve-information/22704>\
**Category:** Modeling\
**Created:** [August 1, 2020, 3:07am UTC](https://community.neo4j.com/t/how-to-model-a-schema-for-best-retrieve-information/22704 "2020-08-01T03:07:18Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![renatospaka](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/renatospaka/32/9445_2.png) [@renatospaka](https://community.neo4j.com/u/renatospaka)\
**Post date:** [August 1, 2020, 3:07am UTC](https://community.neo4j.com/t/how-to-model-a-schema-for-best-retrieve-information/22704/1 "2020-08-01T03:07:19Z")

</div>

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

 ![neo4j_modeling-question](https://us1.discourse-cdn.com/flex021/uploads/neo4jcommunity/original/2X/1/1a7b31135ac96b9237d90dec299a0d8178f4e72c.png)

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.  
Renato

---

<div class="post-metadata">

**Author:** ![PeteM](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/petem/32/13052_2.png) [@PeteM](https://community.neo4j.com/u/PeteM)\
**Post date:** [August 1, 2020, 3:32am UTC](https://community.neo4j.com/t/how-to-model-a-schema-for-best-retrieve-information/22704/2 "2020-08-01T03:32:45Z")

</div>

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.

```auto
(: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.

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

```

2nd)  
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)

> **[How do I report on nodes with multiple labels - Knowledge Base](https://neo4j.com/developer/kb/how-do-i-report-on-nodes-with-multiple-labels/)**
>
> If your data model has chosen to define multiple labels on a node, for example To find all nodes which are defined with both labels of Actor AND Director use…

---

<div class="post-metadata">

**Author:** ![renatospaka](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/renatospaka/32/9445_2.png) [@renatospaka](https://community.neo4j.com/u/renatospaka)\
**Post date:** [August 5, 2020, 8:39pm UTC](https://community.neo4j.com/t/how-to-model-a-schema-for-best-retrieve-information/22704/3 "2020-08-05T20:39:58Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![PeteM](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/petem/32/13052_2.png) [@PeteM](https://community.neo4j.com/u/PeteM)\
**Post date:** [August 7, 2020, 11:29am UTC](https://community.neo4j.com/t/how-to-model-a-schema-for-best-retrieve-information/22704/4 "2020-08-07T11:29:36Z")

</div>

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).

---

<div class="post-metadata">

**Author:** ![asperlinga](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/asperlinga/32/12320_2.png) [@asperlinga](https://community.neo4j.com/u/asperlinga)\
**Post date:** [August 20, 2020, 9:00am UTC](https://community.neo4j.com/t/how-to-model-a-schema-for-best-retrieve-information/22704/6 "2020-08-20T09:00:17Z")

</div>

Hi everyone,

I think there's a potential problem with time measurement.  
In principle a patient is always a person, or rather being a patient is the temporary state of a person. At least I would insert in the Patient node the start and end date of the state.

Alessio

---

<div class="post-metadata">

**Author:** ![ameyasoft](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/ameyasoft/32/32639_2.png) [@ameyasoft](https://community.neo4j.com/u/ameyasoft)\
**Post date:** [August 20, 2020, 3:12pm UTC](https://community.neo4j.com/t/how-to-model-a-schema-for-best-retrieve-information/22704/7 "2020-08-20T15:12:15Z")

</div>

Check this link for some more ideas:

> [@How to keep node relationship unique](https://community.neo4j.com/t/how-to-keep-node-relationship-unique/16412/8):
>
> great idea and what about the performance like for millions of record may be you can say i am over engineering it but actually i want to make system scale able . so two questions with reference. 1: what if date node dosen't exist it should create in that situation . 2: is this solution suitable for millions of record . ? i have tested some thing like this . query 1 : match parent node and option match date and time . then on the basis of this result i am creating missing nodes . so lets s…

---

<div class="post-metadata">

**Author:** ![renatospaka](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/renatospaka/32/9445_2.png) [@renatospaka](https://community.neo4j.com/u/renatospaka)\
**Post date:** [August 20, 2020, 3:59pm UTC](https://community.neo4j.com/t/how-to-model-a-schema-for-best-retrieve-information/22704/8 "2020-08-20T15:59:35Z")

</div>

Sure @asperlinga, a Patient is always a Person but a Person is not always a Patient, he/she could be a mom or dad taking his/her child to the hospital or attending a medical appointment.

Regarding time measurement, I am researching Date Modeling and found this [article](https://medium.com/neo4j/neo4j-data-modelling-2982bd90aa0c) which gave me a good idea about how to proceed with that.

Anyway, this is a matter I like to discuss with people. I would be glad to keep this conversation.

Regards,
