Hi Everyone.
I was following the tutorial steps to Building a Simple Task when all of a sudden the list of contacts I had disappeared.
To confirm what happened and recreated it this is what I did
- I changed the location of my database in
cht-couchdb.yml
to a newtask-database
for testing - With the new location I could create a brand new contact
- After confirming all was okay, I added this task in
tasks.js
module.exports = [{
name: 'assessment-after-registration',
title: 'First Assessment',
icon: 'icon-healthcare-assessment',
appliesTo: 'contacts',
appliesToType: ['patient'],
appliesIf: c => user.parent && user.parent.contact_type === 'chw_area' && !c.contact.date_of_death && !c.contact.muted,
actions: [{ form: 'assessment' }],
events: [{
start: 7,
days: 7,
end: 0,
}],
}];
-
I uploaded my settings successfully…
-
After the upload, my contacts is now broken, on reloading the application I cannot see the contact from above.
I think the problem is related to this other forum post.
Based on the form post this is what I have tried to resolve the issue.
- This is my
tasks.js
const {
isFormArraySubmittedInWindow,
} = require('./nools-extras');
module.exports = [
{
name: 'assessment-after-registration',
title: 'First Assessment',
icon: 'icon-healthcare-assessment',
appliesTo: 'contacts',
appliesToType: ['patient'],
appliesIf: (c) =>
user.parent &&
user.parent.contact_type === 'chw_area' &&
!c.contact.date_of_death &&
!c.contact.muted,
actions: [{ form: 'assessment' }],
events: [
{
id: 'assessment 1',
start: 7,
days: 7,
end: 0,
},
],
resolvedIf: function (c, r, event, dueDate) {
return isFormArraySubmittedInWindow(
c.reports,
['assessment'],
dueDate,
event,
null,
r._id
);
},
},
];
- This is my
nools-extra.js
// @ts-nocheck
const getField = (report, fieldPath) =>
['fields', ...(fieldPath || '').split('.')].reduce((prev, fieldName) => {
if (prev === undefined) {
return undefined;
}
return prev[fieldName];
}, report);
const isFormArraySubmittedInWindow = (
reports,
formArray,
dueDate,
event,
count,
sourceID
) => {
let found = false;
let reportCount = 0;
const start = Utils.addDate(dueDate, -event.start).getTime();
const end = Utils.addDate(dueDate, event.end + 1).getTime();
reports.forEach(function (report) {
if (formArray.includes(report.form)) {
if (report.reported_date >= start && report.reported_date <= end) {
if (sourceID) {
if (getField(report, 'inputs.source_id') === sourceID) {
found = true;
if (count) {
reportCount++;
}
}
} else {
found = true;
if (count) {
reportCount++;
}
}
}
}
});
if (count) {
return reportCount >= count;
}
return found;
};
module.exports = {
isFormArraySubmittedInWindow,
};
At this point,
- I still can’t add a person using the
medic
admin - When I create a new person a new task is not created.