Describe the bug
Targets which should be counted "always" (not part of the monthly interval reporting) emit with date: Date.now(). We cache that emission for 7 days. If that emission is cached near the end of a reporting window, and then a new reporting interval begins -- we fail to count it since the cached date is outside the current interval. The result is taht targets with date: 'now' can show incorrect counts for the first seven days of a reporting window.
To Reproduce
Steps to reproduce:
default configuration, register a pregnancyExpected: View "active pregnancies = 1"
Observed: View "active pregnancies = 0"
If you move your clock forward six more days (eg. Mar 7), and refresh the target tab -- the proper values are displayed again.
Environment
Additional context
We recognized clearly that the use of Date.now() was going to be a problem with our approach. But we thought this was rare - only mattering for calculations like "age of contact", etc. We could have used date: undefined instead of date: now to communicate that the emission should always be counted, but that's very awkward to do now in 3.9.0.
@kennsippell / @garethbowen backport to 3.8.1?
Scheduled for 3.8.1
In my mind, I've coupled the fix with a fix for https://github.com/medic/cht-core/issues/6209 (where no emissions from last day of the reporting interval are counted towards that month's targets doc) . The solution we're choosing here could maybe pave the way we're going to fix this secondary issue.
I've gone over a bunch of solutions for this problem, all with pros and cons and no perfect one:
A. Change cht-core to expire all task/targets calculations at the end of the reporting interval
pros:
time-to-live to a best-before, where the expiration date is min(reporting interval turnover, a week from now).cons:
targets based on last saved (stale) state, disregarding "external" changes, instead of the current state (if we recalculate, all targets with date: now won't be counted for last month's targets)Already have a PR with this fix.
B. Change medic-conf so docs that pass for targets with date: now would actually emit multiple times/doc, with multiple dates - maybe covering today, today - 1 month and today + 1 month, so it'd hit all "adjacent" reporting intervals.
pros:
date: now are always calculated correctly, and we don't need to expire all calculations at the end of an intervalcons:
nools.rules.js) need manual updates to emit correctly. if not updated, they'll still experience this bug.Already have a branch with this fix.
I'm concerned with option B and think we should go with option A in 3.8.1 and come up with an option C to solve 6209 in 3.9.0. @dianabarsan I'll endeavour to catch you online soon to discuss what that might be...
Ready for AT on 6267-unstale-targets.
There is an issue on New Pregnancies card. If during registration, No Information is selected on the Gestational Age page, that registration does not show on New Pregnancies card.


Did you want to have a look at this @dianabarsan ?
@ngaruko this is highly dependent on configuration.
Can you please share your config?
@dianabarsan This was tested on a fresh install with default config
Thanks @ngaruko .
Looking at how such a report looks like:
...
"fields": {
"patient_age_in_years": "33",
"patient_uuid": "3fb7172a-74d8-4b00-9e29-6b0d6e55a3ce",
"patient_id": "",
"patient_name": "person3",
"patient_short_name": "the woman",
"patient_short_name_start": "The woman",
"lmp_date_8601": "",
"edd_8601": "",
"lmp_method_approx": "no",
}
....
Notice that lmp_date_8601 field is empty.
Now looking at the target configuration: https://github.com/medic/cht-core/blob/master/config/default/targets.js#L40
In order to qualify a report as new pregnancy, it must have a way to determine LMP, which such report does not.
So it's expected not to be counted.
Also, this target has set date: "reported", while this issue covers targets that have date: "now" like active-pregnancies.
Does your report count as a active pregnancy?
Thanks @dianabarsan .Let us close this issue and continue to look at the new pregnancy issue separately. Feel free to merge!
Merged into master and backported to 3.8.x.