As always, @jkuester, you’re a legend.
We ended up getting it working after also updating the enkito.service.ts
file and adding a linting exclusion rule to our newly exposed children
property.
contact-summary.service.ts:
...
private getGeneratorFunction() {
if (!this.generatorFunction) {
const script = this.settings[this.SETTING_NAME];
if (!script) {
this.generatorFunction = function() {};
} else {
this.generatorFunction = new Function(
'contact',
'reports',
'lineage',
'children',
...
get(contact, reports, lineage, children, targetDoc?) {
return this.ngZone.runOutsideAngular(() => this._get(contact, reports, lineage, children, targetDoc));
}
private async _get(contact, reports, lineage, children, targetDoc?) {
if (!this.settings) {
this.settings = await this.settingsService.get();
}
if (!this.visitCountSettings) {
this.visitCountSettings = this.uhcSettingsService.getVisitCountSettings(this.settings);
}
const generatorFunction = this.getGeneratorFunction();
const uhcStats = {
homeVisits: await this.uhcStatsService.getHomeVisitStats(contact, this.visitCountSettings),
uhcInterval: this.uhcStatsService.getUHCInterval(this.visitCountSettings)
};
const chtScriptApi = await this.chtScriptApiService.getApi();
try {
const summary = generatorFunction(contact, reports || [], lineage || [], children, uhcStats, chtScriptApi, targetDoc);
...
enkito.service.ts:
...
private getContactSummary(doc, instanceData) {
const contact = instanceData?.contact;
if (!doc.hasContactSummary || !contact) {
return Promise.resolve();
}
return Promise
.all([
this.getContactReports(contact),
this.getLineage(contact),
])
.then(([reports, lineage]) => this.contactSummaryService.get(contact, reports, lineage, contact.children));
...
contacts.effects.ts:
...
private loadContactSummary(contactId) {
const selected = this.selectedContact;
return this.contactSummaryService
.get(selected.doc, selected.reports, selected.lineage, selected.children, selected.targetDoc)
.then(summary => {
return this
.verifySelectedContactNotChanged(contactId)
.then(() => {
this.contactsActions.setContactsLoadingSummary(false);
return this.contactsActions.updateSelectedContactSummary(summary);
});
});
}
...
contact-summary-templated.js:
...
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 -1;
};
// eslint-disable-next-line no-undef
const contactChildren = children;
// The above property is being custom supplied by us.
// We're required to check the enumerated household member count against the expected count.
...
const hhmCount = getChildCount(contactChildren,'hhm');
const cards = [
{
appliesToType: ['household'],
appliesIf: () => hhmCount !== parseInt(thisContact.expected_member_count || 0), // Although captured as an integer, the `expected_member_count` value comes through as a string.
label: 'Attention!',
fields: [
{ label: `Please ensure all household members have been captured.\nExpected count: ${thisContact.expected_member_count}\nActual count: ${hhmCount}`, icon: 'icon-risk' },
...
Visual result:
Unfortunately I’m unable to deploy the code without that linting rule exclusion. Do you perhaps know if there’s some sort of polyfill or something that needs updating for that to work?