Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Updated with Raihan's input - specifically adding the Household relationship & the explanation for the relationships.

Another important component of Dristhi OpenSRP forms is entity_relationship.json. There is one entity_relationship.json per application (in this case DristhiOpenSRP). As the name suggests, it defines the relationship between the various entities of Dristhi the app. The entities that are part of the app as of now are are household, eligible_couple, mother and child. Dristhi’s The entity_relationship.json is below:

Code Block
languagejs
firstline1
titleentity_relationship.json
firstline1
linenumberstrue
[    {
        "parent": "household",
        "child": "eligible_couple",
        "field": "children",
        "kind": "one_to_many",
        "from": "household.id",
        "to": "eligible_couple.relationalid"
    },
    {
        "parent": "eligible_couple",
        "child": "mother",
        "field": "wife",
        "kind": "one_to_one",
        "from": "eligible_couple.id",
        "to": "mother.ecCaseId"
    },
    {
        "parent": "mother",
        "child": "child",
        "field": "children",
        "kind": "one_to_many",
        "from": "mother.id",
        "to": "child.motherCaseId"
    }
]

Each entry in list defines a relation. We have two three relationships in Dristhi, oneOpenSRP, one_to_many between household & eligible_couple, one_to_one between eligible_couple and mother and one_to_many between mother and child. Explanation for the fields below:

parent: This specifies the parent entity in the given relation.
child: This specifies the child entity in the given relation.
field: This specifies the field on parent entity which allows us to load child entity for that parent. This was added to support the cases where entities are stored on Document based Databases like CouchDB. This is currently not used or implemented in the app.
kind: This specifies the type of relationship. Currently supported valyes are one_to_one and one_to_many.
from and to: Together these two values specify how to load parent and child entities from a relational database.

 

BRIEF Explanation: We have Household as an entity which is the parent of an eligible couple. This is a one to many relationship; which is specified by “kind” field in the object. The most interesting part here is “from” and “to”. The client would have a unique code as “id”  for each household and every other entity (not to be confused with an household id in questionnaire).

According to the sample entity_relationship.json posted above , the household.id (auto generated entity id not to be confused with an household id in a questionnaire) would automatically be the eligible_couple.relationalid as it is mentioned in the lines:

"from": "household.id",

"to": "eligible_couple.relationalid"

This is how OpenSRP keeps track of parent and children relationships of entities.