# Target update based on Latest form filled

**URL:** <https://forum.communityhealthtoolkit.org/t/target-update-based-on-latest-form-filled/3206>\
**Category:** Development\
**Tags:** date, target\
**Created:** [December 5, 2023, 10:18am UTC](https://forum.communityhealthtoolkit.org/t/target-update-based-on-latest-form-filled/3206 "2023-12-05T10:18:00Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sanjit7](https://communityhealthtoolkit.b-cdn.net/user_avatar/forum.communityhealthtoolkit.org/sanjit7/32/2003_2.png) [@Sanjit7](https://forum.communityhealthtoolkit.org/u/Sanjit7)\
**Post date:** [December 5, 2023, 10:18am UTC](https://forum.communityhealthtoolkit.org/t/target-update-based-on-latest-form-filled/3206/1 "2023-12-05T10:18:00Z")

</div>

We have a followup\_form.  
When patient comes for follow up CHWs fill the followup form.  
Patients is determined Hypertension controlled and Hypertension uncontrolled on the basis of Bp recorded during follow up.  
In Target, Hypertension Controlled and Uncontrolled count is done based on the latest follow up of the patients, but according to our code it counts total follow up of the patients.

Patients can have multiple follow up,but we only need to count latest followup form filled and its data for controlled and uncontrolled Bp.

Note : We are using the same follow form for multiple visits of patients ( e.g.2nd ,3rd, 4th and so on …)

The result due to the code below is 14 patients followed up, but 33 patients were uncontrolled and 10 patients were controlled so it does not tally with real data.

```auto
{
  id: 'controlled',
  type: 'count',
  goal: -1,
  translation_key: 'targets.controlled',
  subtitle_translation_key: 'targets.all_time.subtitle',
    context: ' user.role === "flhw"',
  appliesTo: 'reports',
  appliesToType: ['follow_up'], 
  appliesIf: function(contact, report) {
    const hypertensionDiagnosed = Utils.getField(report, 'g2.q13_1_control_uncontrol_checker'); 
    return hypertensionDiagnosed === '0';
  },
  idType: 'report',
  date: 'now',
  aggregate: true
},

  
  {
  id: 'uncontrolled',
  type: 'count',
  goal: -1,
  translation_key: 'targets.uncontrolled',
  subtitle_translation_key: 'targets.all_time.subtitle',
    context: 'user.role === "flhw" ',
  appliesTo: 'reports',
  appliesToType: ['follow_up'], 
  appliesIf: function(contact, report) {
    const hypertensionDiagnosed = Utils.getField(report, 'g2.q13_1_control_uncontrol_checker'); 
    return hypertensionDiagnosed === '1';
  },
  
  idType: 'report',
  date: 'now',
  aggregate: true
}

```

---

<div class="post-metadata">

**Author:** ![Sanjit7](https://communityhealthtoolkit.b-cdn.net/user_avatar/forum.communityhealthtoolkit.org/sanjit7/32/2003_2.png) [@Sanjit7](https://forum.communityhealthtoolkit.org/u/Sanjit7)\
**Post date:** [December 5, 2023, 10:37am UTC](https://forum.communityhealthtoolkit.org/t/target-update-based-on-latest-form-filled/3206/2 "2023-12-05T10:37:03Z")

</div>

![target](https://communityhealthtoolkit.b-cdn.net/uploads/default/original/2X/c/caf01b137cb3f79b0b07c2f8c3dd2cc732685e43.png)

---

<div class="post-metadata">

**Author:** ![mrjones](https://communityhealthtoolkit.b-cdn.net/user_avatar/forum.communityhealthtoolkit.org/mrjones/32/681_2.png) [@mrjones](https://forum.communityhealthtoolkit.org/u/mrjones)\
**Post date:** [December 5, 2023, 3:21pm UTC](https://forum.communityhealthtoolkit.org/t/target-update-based-on-latest-form-filled/3206/3 "2023-12-05T15:21:32Z")

</div>

@Sanjit7 - thanks for posting your issue!

Is it possible for you to post a link to your XLXS form and the source of the `g2.q13_1_control_uncontrol_checker()` function? This will help us try and debug why there’s a count discrepancy.

---

<div class="post-metadata">

**Author:** ![Sanjit7](https://communityhealthtoolkit.b-cdn.net/user_avatar/forum.communityhealthtoolkit.org/sanjit7/32/2003_2.png) [@Sanjit7](https://forum.communityhealthtoolkit.org/u/Sanjit7)\
**Post date:** [December 6, 2023, 4:54am UTC](https://forum.communityhealthtoolkit.org/t/target-update-based-on-latest-form-filled/3206/4 "2023-12-06T04:54:10Z")

</div>

I have shared the xls form and the target.js file

Please find the file from following link below :  
[https://drive.google.com/drive/folders/1fbV8k2nLL7llM9HiVlt7M7ECkkfQ3laP?usp=sharing](https://drive.google.com/drive/folders/1fbV8k2nLL7llM9HiVlt7M7ECkkfQ3laP?usp=sharing)

---

<div class="post-metadata">

**Author:** ![Sanjit7](https://communityhealthtoolkit.b-cdn.net/user_avatar/forum.communityhealthtoolkit.org/sanjit7/32/2003_2.png) [@Sanjit7](https://forum.communityhealthtoolkit.org/u/Sanjit7)\
**Post date:** [December 7, 2023, 6:30am UTC](https://forum.communityhealthtoolkit.org/t/target-update-based-on-latest-form-filled/3206/5 "2023-12-07T06:30:26Z")

</div>

If anything required from my side , please feel free to ask.
