We are facing an issue while implementing a form in CHT and would like to get some guidance on the recommended approach.
Requirement
We need to populate a select_one field with the parent hierarchy / ancestor places of the current contact as selectable options.
Example Hierarchy
State → District → District Hospital → Community Health Center → Primary Health Center → Health & Wellness Center → Village
Use Case
If a contact belongs to a lower-level place (for example, Village or HWC), we need the form to dynamically display its ancestor hierarchy places (such as PHC, CHC, District Hospital, etc.) as options in a select_one field.
Clarification Required
Is there any recommended way in CHT/XLSForm to fetch and populate ancestor places dynamically?
Can this be achieved using contact.parent, lineage, or any existing helper functions?
Are there any sample implementations or best practices available for this use case?
Any guidance or reference implementation would be helpful.
You can get the parent name and grandparent names of the hierarchy for offline users like this:
type
name
label
calculate
calculate
parent_name
Parent Name
../inputs/contact/parent/name
calculate
grandparent_name
Grandparent Name
../inputs/contact/parent/parent/name
Place names from the user’s own hierarchy (facility, ward, municipality, district, etc.) can be prepopulated dynamically via inputs/contact, inputs/user, or contact-summary context. However, places outside the user’s replicated hierarchy can’t be fetched offline. The only way I can see to make those available would be to add them in the xlsx as choices.
Curious why this requirement came up though. The reports already contain hierarchical information that can be extracted, or passed through via contact-summary. Is there a case where a user registered under a lower-level HWC or village might actually belong to a different place than the hierarchy they were created under?
The parent name is being populated correctly, and we’re able to display it in the form. However, the grandparent value is coming empty.
We also tested it using notes:
Household: ${patient_parent_name}
Village/Ward: ${patient_grandparent_name}
But Only the parent value is resolving successfully.
Could you please let us know if we are missing anything in the implementation, or if there are any limitations/requirements for accessing deeper hierarchy levels like grandparent?
@Ramu
This behavior you’re describing is the expected and by-design behavior of the CHT hierarchy system. A logged-in user will only see the parent hierarchy levels at or below their own placement in the hierarchy. We can connect tomorrow to talk about this. Feel free to setup a meeting.