Linking Parent and Child Case Data
This page will guide you through linking different levels of cases when looking at data exports.
How Cases are Linked
Child cases are linked to their parents via a special case property called parent_id.Â
Every child case has a property parent_id that matches the case_id of its parent case.
Setting up an Export to include the Parent Case ID
In order to include the parent id in an export, you will need to ensure it is selected when you create a case export. More detail on case exports can be found at https://dimagi.atlassian.net/wiki/x/vCzKfw.
Overall Settings
Make sure to set your file type to Excel.
Parent Case Section
Choose Parent Cases:
You must then include at least row.number and case_id:
Matching the Parent Case in an Export
The document you download will have two tabs - the first one has case data, and the second has the parent ID for each case that has one.
The two tabs (and two cases) are linked together by the variable row.number. If you want to add the parent id to the first tab (the one with the case data), see how to use the VLOOKUP feature in Excel at https://dimagi.atlassian.net/wiki/x/PSXKfw.
If you want to include more detail from the parent case, you will need to separately export the parent case and use the case_id to link the data together.
Multiple Levels
If you have a "grandparent" case you will need to link the levels one at a time. For example, imagine a case structure where you have household - mother - child. In order to link the child to the household you need to first link the child to the mother, and then the mother to the household.
Application Design
You can make this type of analysis much easier by thinking about where to save key variables in your application design. For example, if your parent case type has some sort of unique ID or name, you can save that name to the child case. You can also save other parent properties to the child case.