cht-core icon indicating copy to clipboard operation
cht-core copied to clipboard

Expose child count to contact summary

Open ChinHairSaintClair opened this issue 5 months ago • 0 comments

What feature do you want to improve? In the contact-summary there's no way to check the number of items that have been captured under a parent. For example, the amount of household members captured for a household.

Describe the improvement you'd like I would like to expose the children of a contact and use it to verify the enumerated items against the expected amount. Should there be a mismatch, I want to notify the CHW that further action is required via a contact flag.

Describe alternatives you've considered NA

Additional context After some pointers from @jkuester we managed to achieve the desired functionality: image Just as a note the config/<your_project>/.eslintrc will need to have children added to its globals block.

The count can be used as follows:

const getChildCount = (items, key) => {
  for (let i = 0; i < items.length; i++) {
    const element = items[i];
    if (element.type.id === key) {
      return element.contacts.length;
    }
  }
  return 0; // No children exist
};
const contactChildren = children;
getChildCount(contactChildren ? contactChildren : [],'hhm')

https://forum.communityhealthtoolkit.org/t/expose-child-count-to-contact-summary/3493

ChinHairSaintClair avatar Aug 29 '24 12:08 ChinHairSaintClair