I wish to create 2 programs - Household and Beneficiary using 2 different tracked entity types: Household and Beneficiary respectively. I have the following questions regarding relationships and analytics:
To establish a relationship between Household and Beneficiary, do I have to create two relationship types as shown in demo between mother and child: Mother-Child_a-to-b_(Person-Person) and Mother-Child_b-to-a_(Person-Person)?
a) Why two relationship types and not one. I am bit confused.
b) To link data between Household and beneficiary, I would like to have Household ID as a foreign key in beneficiary. In other words, I would like to be able to first select the Household ID and register all the contacts. How can I configure this?
When it comes to analytics, will it be possible in the above DHIS 2 version to view all the Beneficiaries in a particular household in a single report?
You only need a single relationshipType for your case. You choose Household as one side, and Beneficiary as the other side. You can furthermore define the relationshipType as either bidirectional or not. Bidirectional relationships means the relationship is seen from both sides, which also means users need write access to both sides of the relationship.
The relationships you see in the demo, is a result of a version upgrade where we introduced a new form of relationship, where we had to break up single relationships into multiple relationships. You can disregard those.
We do not work with foreign keys in tracker\relationships, so if you are asking in the context of a relationship, you just need to pick the two tracked entities in questions, namely the Household and the Beneficiary you want to relate. If you are asking in the context outside of relationships, you would need to add a tracked entity attribute to the Beneficiary that represents Household ID. In the latter case, users would have to manually add the value - There is no support for creating dropdowns or searching for existing data in forms.
For your second question regarding analytics, there is currently no support for relationships in analytics, so I don’t think what you are asking is supported. However, you can through the API get that information, and export it. I’m not sure that will solve your problem, but that is a current workaround for getting this data in the manner you are asking.
Option 1 will return trackedEntityInstance(s) and related data, while option 2 will return all relationships for a given trackedEntity.
Have a look at the documentation and play around with the API to see if you find a good representation for you; If not, I would suggest writing a jira issue with your use-case so we can look into if or how we can support it
In theory, a relationship has 2 distinct sides. This way we can say that one side is a Household and one is a Beneficiary. This is how we store them in the database. However, if you choose a bidirectional relationship, the sides doesnt matter, as long as either side is a Household and the other a Beneficiary