Creating Parent-Child Relationship in the Form(Without using parent/child case management configuration)

Dear CommCare Users,
I am creating two case types in two different modules. The first one is the Parent Case and the second one is the Child Case and the requirement is that I register them separately and that I should be able to select the Parent Case, when registering a Child Case, from the list of registered Parent Case. I am able to display a list of Parent Cases using instance(‘casedb’)/casedb/case[@case_type=‘test_parent’] and I am also able to extract the Case ID of Parent Case without any challenges. The real challenge is I am not sure of which Case Property to save the selected Parent Case ID value that can link the Child Case to the Parent Case in order for CommCare to “recognize” it as a “Child Case”!

I know how to create Parent-Child relationships via excel import but doing it in the App as described above is proving to be a challenge to me. Can someone highlight this?

Thanks and kind regards,
Chaiwa.

Hi Chaiwa,

Out of curiosity, why do you want to avoid the standard Case Management configuration? Is this related to your requirement that you register them separately? If so, there are ways to accomplish this while still using the built-in Case Management options.

If you simply need to register the parent and the child from separate forms, I’d recommend adding a Child Registration form to your Parent Case list. In Case Management for this form, don’t update any parent properties, but simply create the child case following the instructions on the Child Cases confluence page.

If you need to register the child from a separate case list, this can be done too, though it requires a couple more add ons:

  1. Create a Child Registration form as above.
  2. Activate the display conditions add-on, and update the Child Registration form’s display condition to false() (this will prevent you from being able to register a Child case from the Parent case list)
  3. Activate the Register from case list add-on. In your Child case list settings, set Registration Form Accessible from Case List to the Child Registration form you just created.

This will allow you to register a new Child case directly from the Child case list, even though you’re referencing a form in the Parent case list. It will also prompt you to select a parent before registering the case, and the Child case will be automatically linked to that parent!

Thanks Cody, that sounds like a better option! Appreciated.
Chaiwa.

Hi @cstahl,
I just came back to thank you for helping out! Following your recommended 3 steps, I managed to setup the workflow and it works! :slight_smile:

One quick tweak I made, though, was on the settings for the "Child Registration Form" which was put in the Parent Case List or Module: In the Cases Section of the form settings, I changed from the default setting of Registration: This form opens a new case to Followup: This form loads a case and may then update or close it.

The other thing I tweaked was in the Save Questions to Properties section: I removed all properties. That is, no changes should be saved to the currently loaded case(which in this case is the Parent case)!

Lastly, I turned-on Open Child Case and configured the properties to match those of the Child Case I intended to create.

Sincerely grateful :blush:
Thanks and kind regards,
Chaiwa.

1 Like