hi community,
here the target’s schema is documented, however, I do not find the emitCustom property documentation.
where could I find documentation about the emitCustion target property ?
hi community,
here the target’s schema is documented, however, I do not find the emitCustom property documentation.
where could I find documentation about the emitCustion target property ?
Hi @bamatic
You’re right, there is no specific documentation about emitCustom
.
I found some references and examples of how to use it: Building Target Widgets | Community Health Toolkit . Please let me know if this helps you figure out how to work with it.
It appears that we already have an issue to track adding documentation for emitCustom
: Declarative configuration target schema is missing explanation of emitCustom · Issue #87 · medic/cht-docs · GitHub
Thank you @diana , from your references I’ve been figuring out how targets work, if you have a little time and you can review this explanation, I’d appreciate it
the explanation is slightly simpler for me with count widgets, for each report/contact that the count widget should count, a target instance, an object is emitted. The CHT emits this target instance on our behalf based on widget configuration.
If with the configuration schema properties we are not able to achieve our “counting logic”, we can provide a custom function with the emitCustom property,
This function takes three parameters, the first is the emit function,the second is the original target instance and the third is the current contact in the contacts loop if the widget applies to contacts or the contact associated to the current report in the report loop, if the widget appies to reports.
So in the emitCustom function we can emit the target instance when our “custom conditions” are fit.
If the widget is a percent widget, we need to emit target instances with pass : true property to increment the numerator and with pass: false to increment the denominator.
We can give and expression to calculate dates of each target instance but all emitted instances will be counted/aggregated during each natural month, it is not possible to change this and have quarter or custom periode metrics
If two or more target instances are emitted with the same instance id, only one will be counted.
@bamatic This is all correct.
Some history: Before the declarative configuration system (targets.js
) in ~2018, CHT App Devs worked directly with target emissions. This is the documentation from way back then and it explains target instances in more detail. Some partners still use this old system and so the CHT must continue to support it for now. Therefore, the declarative config system is “sugar” but the system is using “target instances” behind the scenes.
This is the only thing I’d comment on. Everything is spot on.
If a target has attribute date: 'reported'
, then emissions are aggregated monthly. Only monthly aggregation are supported. This is in cht-core so you’d need a core upgrade to support different intervals. Note you can define the first day of the month (eg. 15th of January to 15th of February) - so not only the “natural month”.
But many projects use other reporting intervals for targets. They achieve this with using date: 'now'
which includes all emissions. In target.js
you would need to conditionally emit the instance based on the current datetime (eg. appliesIf
returns true only if report was created in the current quarter). This isn’t 100% supported by CHT and you might see some inaccuracies in the first 7 days of the reporting period but it is “pretty good” and a lot of people rely on it. You wouldn’t necessarily need emitCustom
to achieve this.