Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const { DateTime } = require('luxon');
- const extras = require('./nools-extras');
- const {
- isCHC,
- wasPregnantAtScreening,
- getLMPDateFromScreening,
- isPregnancyTerminated,
- hasDelivered,
- hadIssuesWithFamilyPlanningAtScreening,
- hadIssuesWithFamilyPlanningAtFollowup,
- familyPlanningWithIssuesFollowupIsRescheduled,
- hasDangerSignsFollowup,
- isMuted,
- hasDeliveredSinceLessThan42Weeks,
- hadBreastfeedingIssues,
- doneCMAMIScreening,
- cmamiDangerSignsReferralGiven,
- cmamiWithIssuesFollowupIsRescheduled,
- childDangerSignsReferralGiven,
- //malnutritionReferralGiven,
- //malnutritionReferralGivenBefore,
- malnutritionReferralGivenNew,
- malnutritionReferralGivenBeforeNew,
- imciDangerSignsReferralGiven,
- malnutritionWithIssuesReported,
- tbTreatmentStopped,
- getMostRecentCompletedTBMonthlyFollowup,
- getDOBISO,
- getAgeInWeeks,
- getAgeInYears
- } = extras;
- const generateEventsForPostnatalScreening = (start, end, day) => ({
- id: `postnatal-${day}`,
- start,
- end,
- dueDate: function (event, contact, report) {
- return DateTime.fromISO(Utils.getField(report, 'delivery_details.date_of_delivery')).plus({ days: day }).toJSDate();
- }
- });
- const generateEventsBasedOnDOB = (eventId, start, end, day) => ({
- id: eventId,
- start,
- end,
- dueDate: function (event, contact) {
- return DateTime.fromISO(getDOBISO(contact.contact)).plus({ days: day }).toJSDate();
- }
- });
- const syncReminderEvent = () => {
- const dayOfMonth = DateTime.local().get('day');
- if (dayOfMonth > 18 || dayOfMonth < 4) {
- const addMonth = dayOfMonth > 18 ? 1 : 0;
- const dueDate = DateTime.local().plus({ month: addMonth }).set({ day: 1 });//1st of next month or 1st of this month.
- return { id: `sync-${dueDate.toISODate()}`, start: 1, end: 2, dueDate: () => dueDate.toJSDate() };
- }
- else {
- const dueDate = DateTime.local().set({ day: 15 });//15th of this month
- return { id: `sync-${dueDate.toISODate()}`, start: 0, end: 3, dueDate: () => dueDate.toJSDate() };
- }
- };
- module.exports = [
- //Sync reminder, every 1st and 15th of the month
- {
- name: 'sync-reminder',
- icon: 'icon-sync',
- title: 'task.sync.title',
- appliesTo: 'contacts',
- appliesToType: ['person'],
- appliesIf: function (contact) {
- return isCHC() && contact.contact._id === user._id;//Self
- },
- resolvedIf: (contact, report, event, dueDate) => {
- return Utils.isFormSubmittedInWindow(
- contact.reports,
- 'sync',
- Utils.addDate(dueDate, -event.start).getTime(),
- Utils.addDate(dueDate, event.end + 1).getTime()
- );
- },
- actions: [
- {
- type: 'report',
- form: 'sync',
- label: 'Sync'
- }
- ],
- events: [syncReminderEvent()]
- },
- //Screening based on contact
- {
- name: 'screening',
- icon: 'icon-family',
- title: 'task.screening.title',
- appliesTo: 'contacts',
- appliesToType: ['person'],
- appliesIf: function (contact) {
- return !isMuted(contact) && isCHC() &&
- contact.contact.role === 'household_member';
- },
- resolvedIf: (contact, report, event, dueDate) => {
- return Utils.isFormSubmittedInWindow(
- contact.reports,
- 'screening',
- Utils.addDate(dueDate, -event.start).getTime(),
- Utils.addDate(dueDate, event.end + 1).getTime()
- );
- },
- actions: [
- {
- type: 'report',
- form: 'screening',
- label: 'Screening'
- }
- ],
- events: [{
- id: 'screening',
- start: 60,
- end: 180,
- days: 60
- }
- ]
- },
- //Screening based on the last screening
- {
- name: 'screening.next',
- icon: 'icon-family',
- title: 'task.screening.title',
- appliesTo: 'reports',
- appliesToType: ['screening'],
- appliesIf: function (contact) {
- return !isMuted(contact) && isCHC() &&
- contact.contact.role === 'household_member';
- },
- resolvedIf: (contact, report, event, dueDate) => {
- return Utils.isFormSubmittedInWindow(
- contact.reports,
- 'screening',
- report.reported_date + 1,
- Utils.addDate(dueDate, event.end + 1).getTime()
- );
- },
- actions: [
- {
- type: 'report',
- form: 'screening',
- label: 'Screening'
- }
- ],
- events: [{
- id: 'screening',
- start: 15,
- end: 180,
- days: 60
- }
- ]
- },
- //Pregnancy followup from screening
- {
- name: 'anc.pregnancy_followup.screening',
- icon: 'icon-pregnancy',
- title: 'task.anc.pregnancy_followup.title',
- appliesTo: 'reports',
- appliesToType: ['screening'],
- appliesIf: function (contact, report) {
- // If pregnant
- return !isMuted(contact) && isCHC() && !!wasPregnantAtScreening(report) &&
- !isPregnancyTerminated(contact, report) && !hasDelivered(contact, report);
- },
- resolvedIf: (contact, report, event, dueDate) => {
- return Utils.isFormSubmittedInWindow(
- contact.reports,
- 'pregnancy_followup',
- Utils.addDate(dueDate, -event.start).getTime(),
- Utils.addDate(dueDate, event.end + 1).getTime()
- ) ||
- Utils.isFormSubmittedInWindow(
- contact.reports,
- 'delivery_report',
- Utils.addDate(dueDate, -event.start).getTime(),
- Utils.addDate(dueDate, event.end + 1).getTime()
- );
- },
- actions: [
- {
- type: 'report',
- form: 'pregnancy_followup',
- label: 'Pregnancy followup'
- }
- ],
- events: [{
- id: 'pregnancy-followup',
- start: 5,
- end: 180,
- days: 30
- }
- ]
- },
- //Pregnancy followup rescheduled
- {
- name: 'anc.pregnancy_followup.rescheduled',
- icon: 'icon-pregnancy',
- title: 'task.anc.pregnancy_followup.title',
- appliesTo: 'reports',
- appliesToType: ['pregnancy_followup'],
- appliesIf: function (contact, report) {
- // If rescheduled
- return !isMuted(contact) && isCHC() && Utils.getField(report, 'followup_details.continue') === 'no' &&
- !isPregnancyTerminated(contact, report) && !hasDelivered(contact, report);
- },
- resolvedIf: (contact, report, event, dueDate) => {
- return Utils.isFormSubmittedInWindow(
- contact.reports,
- 'pregnancy_followup',
- report.reported_date + 1,
- Utils.addDate(dueDate, event.end + 1).getTime()
- );
- },
- actions: [
- {
- type: 'report',
- form: 'pregnancy_followup',
- label: 'Pregnancy followup'
- }
- ],
- events: [
- {
- id: 'pregnancy-followup',
- start: 5,
- end: 180,
- dueDate: function (event, contact, report) {
- return DateTime.fromISO(Utils.getField(report, 'pregnancy_followup_date')).toJSDate();
- }
- }
- ]
- },
- //Pregnancy followup from pregnancy followup
- {
- name: 'anc.pregnancy_followup.next',
- icon: 'icon-pregnancy',
- title: 'task.anc.pregnancy_followup.title',
- appliesTo: 'reports',
- appliesToType: ['pregnancy_followup'],
- appliesIf: function (contact, report) {
- // If rescheduled
- return !isMuted(contact) && isCHC() && Utils.getField(report, 'followup_details.continue') === 'yes' &&
- !isPregnancyTerminated(contact, report) && !hasDelivered(contact, report);
- },
- resolvedIf: (contact, report, event, dueDate) => {
- return Utils.isFormSubmittedInWindow(
- contact.reports,
- 'pregnancy_followup',
- report.reported_date + 1,
- Utils.addDate(dueDate, event.end + 1).getTime()
- );
- },
- actions: [
- {
- type: 'report',
- form: 'pregnancy_followup',
- label: 'Pregnancy followup'
- }
- ],
- events: [
- {
- id: 'pregnancy-followup',
- start: 5,
- end: 180,
- days: 30
- }
- ]
- },
- //Pregnancy danger signs followup
- {
- name: 'anc.pregnancy_danger_signs_followup',
- icon: 'icon-pregnancy-danger',
- title: 'task.anc.pregnancy_danger_signs_followup.title',
- appliesTo: 'reports',
- appliesToType: ['screening', 'pregnancy_followup'],
- appliesIf: function (contact, report) {
- return !isMuted(contact) && isCHC() && hasDangerSignsFollowup(report) &&
- !isPregnancyTerminated(contact, report) && !hasDelivered(contact, report);
- },
- resolvedIf: (contact, report, event, dueDate) => {
- return Utils.isFormSubmittedInWindow(
- contact.reports,
- 'pregnancy_danger_signs_followup',
- Utils.addDate(dueDate, -event.start).getTime(),
- Utils.addDate(dueDate, event.end + 1).getTime()
- );
- },
- actions: [
- {
- type: 'report',
- form: 'pregnancy_danger_signs_followup',
- label: 'Pregnancy danger signs followup',
- modifyContent: function (content, contact, report) {
- content.lmp_date = getLMPDateFromScreening(report);
- }
- }
- ],
- events: [{
- id: 'pregnancy-danger-signs-followup',
- start: 2,
- end: 180,
- days: 2
- }
- ]
- },
- //FP with issues followup
- {
- name: 'fp.with_issues_followup',
- icon: 'icon-follow-up',
- title: 'task.fp.with_issues_followup.title',
- appliesTo: 'reports',
- appliesToType: ['screening', 'fp_followup', 'fp_with_issues_followup'],
- appliesIf: (contact, report) => {
- return !isMuted(contact) && isCHC() &&
- (report.form === 'screening' && hadIssuesWithFamilyPlanningAtScreening(report) ||
- report.form === 'fp_followup' && hadIssuesWithFamilyPlanningAtFollowup(report) ||
- report.form === 'fp_with_issues_followup' && familyPlanningWithIssuesFollowupIsRescheduled(report));//If had first FP with issues followup or a reschedule.
- },
- resolvedIf: (contact, report, event, dueDate) => {
- return Utils.isFormSubmittedInWindow(
- contact.reports,
- 'fp_with_issues_followup',
- report.reported_date + 1,
- Utils.addDate(dueDate, event.end + 1).getTime()
- );
- },
- actions: [{
- type: 'report',
- form: 'fp_with_issues_followup',
- label: 'FP with issues followup',
- }],
- events: [
- {
- id: 'fp-with-issues-followup',
- start: 2,
- end: 180,
- dueDate: (event, contact, report) => {
- return DateTime.fromISO(Utils.getField(report, 'fp_referral_followup_date')).toJSDate();
- }
- }
- ]
- },
- //FP Screening follow up
- {
- name: 'fp.screening_followup',
- icon: 'icon-follow-up',
- title: 'task.fp.screening_followup.title',
- appliesTo: 'reports',
- appliesToType: ['screening'],
- appliesIf: (contact, report) => {
- return !isMuted(contact) && isCHC() &&
- Utils.getField(report, 'g_fp.fp_screening_4.fp_screening_4_1.fp_interest') === 'other';
- },
- resolvedIf: (contact, report, event, dueDate) => {
- return Utils.isFormSubmittedInWindow(
- contact.reports,
- 'fp_screening_followup',
- Utils.addDate(dueDate, -event.start).getTime(),
- Utils.addDate(dueDate, event.end + 1).getTime()
- );
- },
- actions: [{
- type: 'report',
- form: 'fp_screening_followup',
- label: 'FP screening followup',
- }],
- events: [
- {
- id: 'fp-screening-followup',
- start: 2,
- end: 180,
- days: 2
- }
- ]
- },
- //FP follow up from screening or FP screening follow up
- {
- name: 'fp.followup',
- icon: 'icon-follow-up',
- title: 'task.fp.followup.title',
- appliesTo: 'reports',
- appliesToType: ['screening', 'fp_screening_followup'],
- appliesIf: (contact, report) => {
- return !isMuted(contact) && isCHC() &&
- (
- report.form === 'screening' &&
- Utils.getField(report, 'g_fp.fp_screening_4.fp_screening_4_1.fp_interest') === 'yes' &&
- Utils.getField(report, 'g_fp.fp_screening_4.referral_card.fp_rhu_given_again') === 'yes' ||
- report.form === 'fp_screening_followup' &&
- Utils.getField(report, 'fp_screening.fp_interest') === 'yes' &&
- Utils.getField(report, 'fp_screening_3.referral') === 'yes'
- );
- },
- resolvedIf: (contact, report, event, dueDate) => {
- return Utils.isFormSubmittedInWindow(
- contact.reports,
- 'fp_followup',
- Utils.addDate(dueDate, -event.start).getTime(),
- Utils.addDate(dueDate, event.end + 1).getTime()
- );
- },
- actions: [{
- type: 'report',
- form: 'fp_followup',
- label: 'FP followup',
- }],
- events: [
- {
- id: 'fp-followup',
- start: 2,
- end: 180,
- days: 2
- }
- ]
- },
- //FP follow up from FP followup
- {
- name: 'fp.followup.followup',
- icon: 'icon-follow-up',
- title: 'task.fp.followup.title',
- appliesTo: 'reports',
- appliesToType: ['fp_followup'],
- appliesIf: (contact, report) => {
- return !isMuted(contact) && isCHC() &&
- Utils.getField(report, 'followup_details_1.continue') === 'no';
- },
- resolvedIf: (contact, report, event, dueDate) => {
- return Utils.isFormSubmittedInWindow(
- contact.reports,
- 'fp_followup',
- report.reported_date + 1,
- Utils.addDate(dueDate, event.end + 1).getTime()
- );
- },
- actions: [{
- type: 'report',
- form: 'fp_followup',
- label: 'FP followup',
- }],
- events: [
- {
- id: 'fp-followup',
- start: 2,
- end: 180,
- dueDate: (event, contact, report) => {
- return DateTime.fromISO(Utils.getField(report, 'followup_details_1.reschedule')).toJSDate();
- }
- }
- ]
- },
- //FP procedure followup
- {
- name: 'fp.procedure.followup',
- icon: 'icon-follow-up',
- title: 'task.fp.procedure.title',
- appliesTo: 'reports',
- appliesToType: ['fp_followup'],
- appliesIf: (contact, report) => {
- return !isMuted(contact) && isCHC() &&
- Utils.getField(report, 'visit_details_3.fp_appointment') === 'yes';
- },
- resolvedIf: (contact, report, event, dueDate) => {
- return Utils.isFormSubmittedInWindow(
- contact.reports,
- 'fp_procedure_followup',
- Utils.addDate(dueDate, -event.start).getTime(),
- Utils.addDate(dueDate, event.end + 1).getTime()
- );
- },
- actions: [{
- type: 'report',
- form: 'fp_procedure_followup',
- label: 'FP procedure followup',
- }],
- events: [
- {
- id: 'fp-procedure-followup',
- start: 2,
- end: 180,
- dueDate: (event, contact, report) => {
- return DateTime.fromISO(Utils.getField(report, 'visit_details_3.next_appointment')).plus({ days: 2 }).toJSDate();
- }
- }
- ]
- },
- //CMAMI TASKS
- //CMAMI screening
- {
- name: 'cmami.screening',
- icon: 'icon-infant',
- title: 'task.cmami.screening.title',
- appliesTo: 'contacts',
- appliesToType: ['person'],
- appliesIf: function (contact) {
- return !isMuted(contact) && isCHC() && contact.contact.role === 'household_member' && getAgeInWeeks(contact.contact) < 6;
- },
- resolvedIf: (contact, report, event, dueDate) => {
- return Utils.isFormSubmittedInWindow(
- contact.reports,
- 'cmami_screening',
- Utils.addDate(dueDate, -event.start).getTime(),
- Utils.addDate(dueDate, event.end + 1).getTime()
- );
- },
- actions: [
- {
- type: 'report',
- form: 'cmami_screening',
- label: 'CMAMI Screening'
- }
- ],
- events: [
- generateEventsBasedOnDOB('cmami-screening-d1', 1, 1, 1),//Due on day 1, shows from 0-2 days
- generateEventsBasedOnDOB('cmami-screening-d3', 0, 2, 3),//Due on day 3, shows from 3-5 days
- generateEventsBasedOnDOB('cmami-screening-d7', 1, 3, 7),//Due on day 7, shows from 6-10 days
- generateEventsBasedOnDOB('cmami-screening-d14', 3, 19, 14),//Due on day 14, shows from 11-33 days
- generateEventsBasedOnDOB('cmami-screening-d41', 7, 0, 41)//Due on day 41, shows from 34-41 days (1 day before child turns 42 days i.e. 6 weeks)
- ]
- },
- //CMAMI Screening from age 6 weeks to less than 24 weeks, if not already done
- {
- name: 'cmami.screening.immediate',
- icon: 'icon-infant',
- title: 'task.cmami.screening.title',
- appliesTo: 'contacts',
- appliesToType: ['person'],
- appliesIf: function (contact) {
- return !isMuted(contact) && isCHC() && contact.contact.role === 'household_member' &&
- getAgeInWeeks(contact.contact) >= 6 && getAgeInWeeks(contact.contact) < 24 &&
- !doneCMAMIScreening(contact);
- },
- resolvedIf: (contact, report, event, dueDate) => {
- return Utils.isFormSubmittedInWindow(
- contact.reports,
- 'cmami_screening',
- Utils.addDate(dueDate, -event.start).getTime(),
- Utils.addDate(dueDate, event.end + 1).getTime()
- );
- },
- actions: [
- {
- type: 'report',
- form: 'cmami_screening',
- label: 'CMAMI Screening'
- }
- ],
- events: [
- { id: 'cmami-screening-0', start: 7, end: 60, days: 7 }
- ]
- },
- //CMAMI followup from contacts
- {
- name: 'cmami.followup',
- icon: 'icon-infant',
- title: 'task.cmami.followup.title',
- appliesTo: 'contacts',
- appliesToType: ['person'],
- appliesIf: function (contact) {
- return !isMuted(contact) && isCHC() &&
- contact.contact.role === 'household_member' &&
- getAgeInWeeks(contact.contact) >= 6 &&
- getAgeInWeeks(contact.contact) <= 22 &&
- doneCMAMIScreening(contact);
- },
- resolvedIf: (contact, report, event, dueDate) => {
- return Utils.isFormSubmittedInWindow(
- contact.reports,
- 'cmami_followup',
- Utils.addDate(dueDate, -event.start).getTime(),
- Utils.addDate(dueDate, event.end + 1).getTime()
- );
- },
- actions: [
- {
- type: 'report',
- form: 'cmami_followup',
- label: 'CMAMI follow up'
- }
- ],
- events: [
- generateEventsBasedOnDOB('cmami-followup-w6', 0, 4 * 7 - 4, 6 * 7),//Due on day 42, shows from 42-66 days
- generateEventsBasedOnDOB('cmami-followup-w10', 3, 4 * 7 - 4, 10 * 7),//Due on day 70, shows from 67-94 days
- generateEventsBasedOnDOB('cmami-followup-w14', 3, 4 * 7 - 4, 14 * 7),//Due on day 98, shows from 95-122 days
- generateEventsBasedOnDOB('cmami-followup-w18', 3, 4 * 7 - 4, 18 * 7),//Due on day 126, shows from 123-150 days
- generateEventsBasedOnDOB('cmami-followup-w22', 3, 6, 22 * 7)//Due on day 154, shows from 151-160 days (1 day before child turns 161 days i.e. 23 weeks)
- ]
- },
- //CMAMI follow up from CMAMI follow up (rescheduled)
- {
- name: 'cmami.screening.followup.followup',
- icon: 'icon-infant',
- title: 'task.cmami.screening.followup.title',
- appliesTo: 'reports',
- appliesToType: ['cmami_followup'],
- appliesIf: function (contact, report) {
- return !isMuted(contact) && isCHC() &&
- !!Utils.getField(report, 'resheduled_date') &&
- getAgeInWeeks(contact.contact) <= 22;
- },
- resolvedIf: (contact, report, event, dueDate) => {
- return Utils.isFormSubmittedInWindow(
- contact.reports,
- 'cmami_screening_followup',
- report.reported_date + 1,
- Utils.addDate(dueDate, event.end + 1).getTime()
- );
- },
- actions: [
- {
- type: 'report',
- form: 'cmami_screening',
- label: 'CMAMI Screening'
- }
- ],
- events: [
- {
- id: 'cmami-followup',
- start: 3,
- end: 160,
- dueDate: (event, contact, report) => {
- return DateTime.fromISO(Utils.getField(report, 'rescheduled_date')).toJSDate();
- }
- }
- ]
- },
- //Postnatal screening
- {
- name: 'pnc.postnatal.screening',
- icon: 'icon-mother-child',
- title: 'task.pnc.postnatal.screening.title',
- appliesTo: 'reports',
- appliesToType: ['delivery_report'],
- appliesIf: function (contact, report) {
- return !isMuted(contact) && isCHC() && hasDeliveredSinceLessThan42Weeks(report) === true; // Mother is no more eligible after 42 weeks of delivery
- },
- resolvedIf: (contact, report, event, dueDate) => {
- return Utils.isFormSubmittedInWindow(
- contact.reports,
- 'postnatal_screening',
- Utils.addDate(dueDate, -event.start).getTime(),
- Utils.addDate(dueDate, event.end + 1).getTime()
- );
- },
- actions: [{
- type: 'report',
- form: 'postnatal_screening',
- label: 'Postnatal screening',
- modifyContent: function (content, contact, report) {
- content.date_of_delivery = Utils.getField(report, 'delivery_details.date_of_delivery');
- }
- }],
- events: [
- generateEventsForPostnatalScreening(1, 1, 1),//Due on day 1, shows from day 0-2
- generateEventsForPostnatalScreening(0, 1, 3),//Due on day 3, shows from day 3-4
- generateEventsForPostnatalScreening(2, 3, 7),//Due on day 7, shows from day 5-10
- generateEventsForPostnatalScreening(3, 4 * 7 - 6, 2 * 7),//Due on day 14, shows from day 11-36
- generateEventsForPostnatalScreening(5, 4 * 7 - 6, 6 * 7),//Due on day 42, shows from day 37-64
- generateEventsForPostnatalScreening(5, 4 * 7 - 6, 10 * 7),//Due on day 70, shows from day 67-92
- generateEventsForPostnatalScreening(5, 4 * 7 - 6, 14 * 7),//Due on day 98, shows from day 93-120
- generateEventsForPostnatalScreening(5, 4 * 7 - 6, 18 * 7),//Due on day 126. shows from day 121-148
- generateEventsForPostnatalScreening(5, 90, 22 * 7)////Due on day 154, shows from day 149-244
- ]
- },
- //CMAMI with issues followup
- {
- name: 'cmami.with_issues_followup',
- icon: 'icon-infant',
- title: 'task.cmami.with_issues_followup.title',
- appliesTo: 'reports',
- appliesToType: ['cmami_screening', 'cmami_followup', 'cmami_with_issues_followup'],
- appliesIf: (contact, report) => {
- return !isMuted(contact) && isCHC() &&
- getAgeInWeeks(contact.contact) <= 22 &&
- (
- (report.form === 'cmami_screening' && hadBreastfeedingIssues(report)) ||
- (report.form === 'cmami_followup' && hadBreastfeedingIssues(report)) ||
- (report.form === 'cmami_with_issues_followup' && cmamiWithIssuesFollowupIsRescheduled(report))
- );
- },
- resolvedIf: (contact, report, event, dueDate) => {
- return Utils.isFormSubmittedInWindow(
- contact.reports,
- 'cmami_with_issues_followup',
- report.reported_date + 1,
- Utils.addDate(dueDate, event.end + 1).getTime()
- );
- },
- actions: [{
- type: 'report',
- form: 'cmami_with_issues_followup',
- label: 'CMAMI with issues followup',
- }],
- events: [
- {
- id: 'cmami-with-issues-followup',
- start: 2,
- end: 180,
- dueDate: (event, contact, report) => {
- return DateTime.fromISO(Utils.getField(report, 'issues_followup_date')).toJSDate();
- }
- }
- ]
- },
- //CMAMI danger signs followup
- {
- name: 'cmami.danger_signs_followup',
- icon: 'icon-infant-danger',
- title: 'task.cmami.danger_signs.title',
- appliesTo: 'reports',
- appliesToType: ['cmami_screening', 'cmami_followup'],
- appliesIf: (contact, report) => {
- return !isMuted(contact) && isCHC() &&
- getAgeInWeeks(contact.contact) <= 22 &&
- cmamiDangerSignsReferralGiven(report);
- },
- resolvedIf: (contact, report, event, dueDate) => {
- return Utils.isFormSubmittedInWindow(
- contact.reports,
- 'cmami_danger_signs_followup',
- Utils.addDate(dueDate, -event.start).getTime(),
- Utils.addDate(dueDate, event.end + 1).getTime()
- );
- },
- actions: [{
- type: 'report',
- form: 'cmami_danger_signs_followup',
- label: 'CMAMI danger signs followup',
- }],
- events: [
- {
- id: 'cmami-danger-signs-followup',
- start: 2,
- end: 180,
- dueDate: (event, contact, report) => {
- return DateTime.fromISO(Utils.getField(report, 'danger_signs_followup_date')).toJSDate();
- }
- }
- ]
- },
- //CHILD HEALTH WORKFLOW
- //Child health danger signs followup
- {
- name: 'child_health.danger_signs_followup',
- icon: 'icon-child-danger',
- title: 'task.child_health.danger_signs.title',
- appliesTo: 'reports',
- appliesToType: ['screening'],
- appliesIf: (contact, report) => {
- return !isMuted(contact) && isCHC() &&
- getAgeInYears(contact.contact) < 5 &&
- childDangerSignsReferralGiven(report);
- },
- resolvedIf: (contact, report, event, dueDate) => {
- return Utils.isFormSubmittedInWindow(
- contact.reports,
- 'child_health_danger_signs_followup',
- Utils.addDate(dueDate, -event.start).getTime(),
- Utils.addDate(dueDate, event.end + 1).getTime()
- );
- },
- actions: [{
- type: 'report',
- form: 'child_health_danger_signs_followup',
- label: 'Child health danger signs followup',
- }],
- events: [
- {
- id: 'child-health-danger-signs-followup',
- start: 2,
- end: 180,
- days: 2
- }
- ]
- },
- //Malnutrition 48 hrs follow up from screening - try to remove this tasks if possible
- /* {
- name: 'malnutrition.48_hrs_followup',
- icon: 'icon-child-nutrition',
- title: 'task.malnutrition_48_hrs.title',
- appliesTo: 'reports',
- appliesToType: ['screening'],
- appliesIf: (contact, report) => {
- return !isMuted(contact) && isCHC() && getAgeInYears(contact.contact) < 5 &&
- malnutritionReferralGiven(report);
- },
- resolvedIf: (contact, report, event, dueDate) => {
- return Utils.isFormSubmittedInWindow(
- contact.reports,
- 'malnutrition_followup_48h',
- Utils.addDate(dueDate, -event.start).getTime(),
- Utils.addDate(dueDate, event.end + 1).getTime()
- ) ||
- Utils.isFormSubmittedInWindow(
- contact.reports,
- 'malnutrition_discharge',
- Utils.addDate(dueDate, -event.start).getTime(),
- Utils.addDate(dueDate, event.end + 1).getTime()
- );
- },
- actions: [{
- type: 'report',
- form: 'malnutrition_followup_48h',
- label: 'Malnutrition 48 hrs followup',
- }],
- events: [
- {
- id: 'malnutrition-48hrs-followup',
- start: 2,
- end: 180,
- days: 2
- }
- ]
- },
- */
- //Malnutrition 48 hrs follow up rescheduled - try to remove this tasks if possible
- /* {
- name: 'malnutrition.48_hrs_followup.rescheduled',
- icon: 'icon-child-nutrition',
- title: 'task.malnutrition_48_hrs.title',
- appliesTo: 'reports',
- appliesToType: ['malnutrition_followup_48h'],
- appliesIf: (contact, report) => {
- return !isMuted(contact) && isCHC() &&
- getAgeInYears(contact.contact) < 5 &&
- Utils.getField(report, 'g_continue.continue') === 'no';
- },
- resolvedIf: (contact, report, event, dueDate) => {
- return Utils.isFormSubmittedInWindow(
- contact.reports,
- 'malnutrition_followup_48h',
- report.reported_date + 1,
- Utils.addDate(dueDate, event.end + 1).getTime()
- ) ||
- Utils.isFormSubmittedInWindow(
- contact.reports,
- 'malnutrition_discharge',
- report.reported_date + 1,
- Utils.addDate(dueDate, event.end + 1).getTime()
- );
- },
- actions: [{
- type: 'report',
- form: 'malnutrition_followup_48h',
- label: 'Malnutrition 48 hrs followup',
- }],
- events: [
- {
- id: 'malnutrition-48hrs-followup',
- start: 2,
- end: 180,
- dueDate: (event, contact, report) => {
- return DateTime.fromISO(Utils.getField(report, 'g_continue.reschedule')).toJSDate();
- }
- }
- ]
- },
- */
- //Malnutrition every 2 weeks follow up from screening - try to change the from of malnutrition_followup_every_2w to health_facility_followup_every_2w
- {
- name: 'malnutrition.every_2_weeks_followup',
- icon: 'icon-child-nutrition',
- title: 'task.malnutrition_every_2_weeks.title',
- appliesTo: 'reports',
- appliesToType: ['screening'],
- appliesIf: (contact, report) => {
- return !isMuted(contact) && isCHC() && getAgeInYears(contact.contact) < 5 &&
- (malnutritionReferralGivenNew(report) || malnutritionReferralGivenBeforeNew(report));
- },
- resolvedIf: (contact, report, event, dueDate) => {
- return Utils.isFormSubmittedInWindow(
- contact.reports,
- 'health_facility_followup_every_2w',
- report.reported_date + 1,
- Utils.addDate(dueDate, event.end + 1).getTime()
- ) ||
- Utils.isFormSubmittedInWindow(
- contact.reports,
- 'malnutrition_followup_every_2w',
- report.reported_date + 1,
- Utils.addDate(dueDate, event.end + 1).getTime()
- ) ||
- Utils.isFormSubmittedInWindow(
- contact.reports,
- 'malnutrition_discharge',
- report.reported_date + 1,
- Utils.addDate(dueDate, event.end + 1).getTime()
- );
- },
- actions: [{
- type: 'report',
- form: 'health_facility_followup_every_2w',
- label: 'Malnutrition every 2 weeks followup',
- }],
- events: [
- {
- id: 'malnutrition-every2w-followup',
- start: 5, //for testing, change 2 from 5.
- end: 180,
- days: 14
- }
- ]
- },
- //Malnutrition every 2 weeks follow up from pervious Malnutrition every 2 weeks follow up - try to change the from of malnutrition_followup_every_2w to health_facility_followup_every_2w
- {
- name: 'malnutrition.every_2_weeks_followup.next',
- icon: 'icon-child-nutrition',
- title: 'task.malnutrition_every_2_weeks.title',
- appliesTo: 'reports',
- appliesToType: ['health_facility_followup_every_2w'],
- appliesIf: (contact) => {
- //Applies automatically
- return !isMuted(contact) && isCHC() && getAgeInYears(contact.contact) < 5;
- },
- resolvedIf: (contact, report, event, dueDate) => {
- return Utils.isFormSubmittedInWindow(
- contact.reports,
- 'health_facility_followup_every_2w',
- report.reported_date + 1,
- Utils.addDate(dueDate, event.end + 1).getTime()
- ) || Utils.isFormSubmittedInWindow(
- contact.reports,
- 'malnutrition_followup_every_2w',
- report.reported_date + 1,
- Utils.addDate(dueDate, event.end + 1).getTime()
- ) ||
- Utils.isFormSubmittedInWindow(
- contact.reports,
- 'malnutrition_discharge',
- report.reported_date + 1,
- Utils.addDate(dueDate, event.end + 1).getTime()
- );
- },
- actions: [{
- type: 'report',
- form: 'health_facility_followup_every_2w',
- label: 'Malnutrition every 2 weeks followup',
- }],
- events: [
- {
- id: 'malnutrition-every2w-followup',
- start: 5,
- end: 180,
- days: 14
- }
- ]
- },
- //Malnutrition with issues followup from Malnutrition every 2 weeks follow up
- {
- name: 'malnutrition.with_issues_followup',
- icon: 'icon-follow-up',
- title: 'task.malnutrition.with_issues_followup.title',
- appliesTo: 'reports',
- appliesToType: ['health_facility_followup_every_2w'], //malnutrition_followup_every_2w
- appliesIf: (contact, report) => {
- return !isMuted(contact) && isCHC() && getAgeInYears(contact.contact) < 5 && malnutritionWithIssuesReported(report);
- },
- resolvedIf: (contact, report, event, dueDate) => {
- return Utils.isFormSubmittedInWindow(
- contact.reports,
- 'malnutrition_with_issues_followup',
- Utils.addDate(dueDate, -event.start).getTime(),
- Utils.addDate(dueDate, event.end + 1).getTime()
- ) ||
- Utils.isFormSubmittedInWindow(
- contact.reports,
- 'malnutrition_discharge',
- Utils.addDate(dueDate, -event.start).getTime(),
- Utils.addDate(dueDate, event.end + 1).getTime()
- );
- },
- actions: [{
- type: 'report',
- form: 'malnutrition_with_issues_followup',
- label: 'Malnutrition with issues followup',
- }],
- events: [
- {
- id: 'malnutrition-with-issues-followup',
- start: 2,
- end: 180,
- days: 2
- }
- ]
- },
- //Malnutrition with issues follow up rescheduled
- {
- name: 'malnutrition.with_issues_followup.rescheduled',
- icon: 'icon-follow-up',
- title: 'task.malnutrition.with_issues_followup.title',
- appliesTo: 'reports',
- appliesToType: ['malnutrition_with_issues_followup'],
- appliesIf: (contact, report) => {
- return !isMuted(contact) && isCHC() && getAgeInYears(contact.contact) < 5 &&
- Utils.getField(report, 'followup_details_1.continue') === 'no';
- },
- resolvedIf: (contact, report, event, dueDate) => {
- return Utils.isFormSubmittedInWindow(
- contact.reports,
- 'malnutrition_with_issues_followup',
- Utils.addDate(dueDate, -event.start).getTime(),
- Utils.addDate(dueDate, event.end + 1).getTime()
- ) ||
- Utils.isFormSubmittedInWindow(
- contact.reports,
- 'malnutrition_discharge',
- Utils.addDate(dueDate, -event.start).getTime(),
- Utils.addDate(dueDate, event.end + 1).getTime()
- );
- },
- actions: [{
- type: 'report',
- form: 'malnutrition_with_issues_followup',
- label: 'Malnutrition with issues followup',
- }],
- events: [
- {
- id: 'malnutrition-48hrs-followup',
- start: 2,
- end: 180,
- dueDate: (event, contact, report) => {
- return DateTime.fromISO(Utils.getField(report, 'malnutrition_with_issues_followup_date')).toJSDate();
- }
- }
- ]
- },
- //IMCI
- //IMCI appointment followup
- {
- name: 'imci.appointment.followup',
- icon: 'icon-follow-up',
- title: 'task.imci_appointment_followup.title',
- appliesTo: 'reports',
- appliesToType: ['imci_followup_48h'],
- appliesIf: (contact, report) => {
- return !isMuted(contact) && isCHC() && getAgeInYears(contact.contact) < 5 &&
- Utils.getField(report, 'appointment_date_iso');
- },
- resolvedIf: (contact, report, event, dueDate) => {
- return Utils.isFormSubmittedInWindow(
- contact.reports,
- 'imci_appointment_followup',
- report.reported_date + 1,
- Utils.addDate(dueDate, event.end + 1).getTime()
- ) ||
- Utils.isFormSubmittedInWindow(
- contact.reports,
- 'imci_recovery',
- report.reported_date + 1,
- Utils.addDate(dueDate, event.end + 1).getTime()
- );
- },
- actions: [{
- type: 'report',
- form: 'imci_appointment_followup',
- label: 'IMCI follow up',
- }],
- events: [
- {
- id: 'imci-appointment-followup',
- start: 2,
- end: 60,
- dueDate: (event, contact, report) => {
- return DateTime.fromISO(Utils.getField(report, 'appointment_date_iso')).plus({ days: 2 }).toJSDate();
- }
- }
- ]
- },
- //IMCI 48 hrs follow up (danger signs)
- {
- name: 'imci.48_hrs_followup',
- icon: 'icon-follow-up',
- title: 'task.imci_48_hrs.title',
- appliesTo: 'reports',
- appliesToType: ['screening', 'imci_followup_48h', 'imci_followup_weekly'],
- appliesIf: (contact, report) => {
- return !isMuted(contact) && isCHC() && imciDangerSignsReferralGiven(report);
- },
- resolvedIf: (contact, report, event, dueDate) => {
- return Utils.isFormSubmittedInWindow(
- contact.reports,
- 'imci_followup_48h',
- report.reported_date + 1,
- Utils.addDate(dueDate, event.end + 1).getTime()
- ) ||
- Utils.isFormSubmittedInWindow(
- contact.reports,
- 'imci_recovery',
- Utils.addDate(dueDate, -event.start).getTime(),
- Utils.addDate(dueDate, event.end + 1).getTime()
- ) ||
- getAgeInYears(contact.contact) >= 5; // make the task disappear if baby age gets to >= 5 years
- },
- actions: [{
- type: 'report',
- form: 'imci_followup_48h',
- label: 'IMCI 48 hrs followup',
- }],
- events: [
- {
- id: 'imci-48hrs-followup',
- start: 2,
- end: 60,
- days: 2
- }
- ]
- },
- //IMCI weekly follow up
- {
- name: 'imci.weekly_followup',
- icon: 'icon-follow-up',
- title: 'task.imci_weekly.title',
- appliesTo: 'reports',
- appliesToType: ['screening', 'imci_followup_48h', 'imci_followup_weekly'],
- appliesIf: (contact, report) => {
- return !isMuted(contact) && isCHC() && getAgeInYears(contact.contact) < 5 && imciDangerSignsReferralGiven(report);
- },
- resolvedIf: (contact, report, event, dueDate) => {
- return Utils.isFormSubmittedInWindow(
- contact.reports,
- 'imci_followup_weekly',
- report.reported_date + 1,
- Utils.addDate(dueDate, event.end + 1).getTime()
- ) ||
- Utils.isFormSubmittedInWindow(
- contact.reports,
- 'imci_recovery',
- Utils.addDate(dueDate, -event.start).getTime(),
- Utils.addDate(dueDate, event.end + 1).getTime()
- );
- },
- actions: [{
- type: 'report',
- form: 'imci_followup_weekly',
- label: 'IMCI weekly followup',
- }],
- events: [
- {
- id: 'imci-weekly-followup',
- start: 3,
- end: 60,
- days: 7
- }
- ]
- },
- //IMCI weekly follow up from previous IMCI weekly followup
- {
- name: 'imci.weekly_followup.next',
- icon: 'icon-follow-up',
- title: 'task.imci_weekly.title',
- appliesTo: 'reports',
- appliesToType: ['imci_followup_weekly'],
- appliesIf: (contact) => {
- return !isMuted(contact) && isCHC() && getAgeInYears(contact.contact) < 5;
- },
- resolvedIf: (contact, report, event, dueDate) => {
- return Utils.isFormSubmittedInWindow(
- contact.reports,
- 'imci_followup_weekly',
- report.reported_date + 1,
- Utils.addDate(dueDate, event.end + 1).getTime()
- ) ||
- Utils.isFormSubmittedInWindow(
- contact.reports,
- 'imci_recovery',
- Utils.addDate(dueDate, -event.start).getTime(),
- Utils.addDate(dueDate, event.end + 1).getTime()
- );
- },
- actions: [{
- type: 'report',
- form: 'imci_followup_weekly',
- label: 'IMCI weekly followup',
- }],
- events: [
- {
- id: 'imci-weekly-followup',
- start: 3,
- end: 60,
- days: 7
- }
- ]
- },
- //IMCI weekly follow up rescheduled
- {
- name: 'imci.weekly_followup.rescheduled',
- icon: 'icon-follow-up',
- title: 'task.imci_weekly.title',
- appliesTo: 'reports',
- appliesToType: ['imci_followup_weekly'],
- appliesIf: (contact, report) => {
- return !isMuted(contact) && isCHC() && getAgeInYears(contact.contact) < 5 &&
- Utils.getField(report, 'g_continue.continue') === 'no';
- },
- resolvedIf: (contact, report, event, dueDate) => {
- return Utils.isFormSubmittedInWindow(
- contact.reports,
- 'imci_followup_weekly',
- report.reported_date + 1,
- Utils.addDate(dueDate, event.end + 1).getTime()
- ) ||
- Utils.isFormSubmittedInWindow(
- contact.reports,
- 'imci_recovery',
- report.reported_date + 1,
- Utils.addDate(dueDate, event.end + 1).getTime()
- );
- },
- actions: [{
- type: 'report',
- form: 'imci_followup_weekly',
- label: 'IMCI weekly followup',
- }],
- events: [
- {
- id: 'imci-weekly-followup',
- start: 3,
- end: 60,
- dueDate: (event, contact, report) => {
- return DateTime.fromISO(Utils.getField(report, 'g_continue.reschedule')).toJSDate();
- }
- }
- ]
- },
- //TB Follow up
- {
- name: 'tb.follow_up',
- icon: 'icon-tb',
- title: 'tb.follow_up.title',
- appliesTo: 'reports',
- appliesToType: ['screening', 'tb_followup'],
- appliesIf: (contact, report) => {
- return !isMuted(contact) && isCHC() &&
- !tbTreatmentStopped(contact, report) && (
- report.form === 'screening' && !!Utils.getField(report, 'tb_followup_date')
- ||
- report.form === 'tb_followup' && Utils.getField(report, 'g_continue.continue') === 'no'//Rescheduled
- );
- },
- resolvedIf: (contact, report, event, dueDate) => {
- return Utils.isFormSubmittedInWindow(
- contact.reports,
- 'tb_followup',
- report.reported_date + 1,
- Utils.addDate(dueDate, event.end + 1).getTime()
- );
- },
- actions: [{
- type: 'report',
- form: 'tb_followup',
- label: 'TB Follow up',
- }],
- events: [
- {
- id: 'tb_followup',
- start: 2,
- end: 180,
- dueDate: (event, contact, report) => {
- return (
- report.form === 'screening' && DateTime.fromISO(Utils.getField(report, 'tb_followup_date')).toJSDate()
- ||
- report.form === 'tb_followup' && DateTime.fromISO(Utils.getField(report, 'g_continue.reschedule')).toJSDate()//Rescheduled
- );
- }
- }
- ]
- },
- //TB Testing Follow up
- {
- name: 'tb.followup.testing',
- icon: 'icon-tb',
- title: 'tb.followup.testing.title',
- appliesTo: 'reports',
- appliesToType: ['tb_followup'],
- appliesIf: (contact, report) => {
- return !isMuted(contact) && isCHC() &&
- !tbTreatmentStopped(contact, report) &&
- !!Utils.getField(report, 'test_followup_date');
- },
- resolvedIf: (contact, report, event, dueDate) => {
- return Utils.isFormSubmittedInWindow(
- contact.reports,
- 'tb_test_followup',
- report.reported_date + 1,
- Utils.addDate(dueDate, event.end + 1).getTime()
- );
- },
- actions: [{
- type: 'report',
- form: 'tb_test_followup',
- label: 'TB Testing Follow up',
- }],
- events: [
- {
- id: 'tb_test_followup',
- start: 2,
- end: 180,
- dueDate: (event, contact, report) => {
- return DateTime.fromISO(Utils.getField(report, 'test_followup_date')).toJSDate();
- }
- }
- ]
- },
- //TB Diagnosis Follow up
- {
- name: 'tb.followup.diagnosis',
- icon: 'icon-tb',
- title: 'tb.followup.diagnosis.title',
- appliesTo: 'reports',
- appliesToType: ['tb_followup', 'tb_test_followup'],
- appliesIf: (contact, report) => {
- return !isMuted(contact) && isCHC() &&
- !tbTreatmentStopped(contact, report) &&
- !!Utils.getField(report, 'diagnosis_followup_date');
- },
- resolvedIf: (contact, report, event, dueDate) => {
- return Utils.isFormSubmittedInWindow(
- contact.reports,
- 'tb_diagnosis_followup',
- report.reported_date + 1,
- Utils.addDate(dueDate, event.end + 1).getTime()
- );
- },
- actions: [{
- type: 'report',
- form: 'tb_diagnosis_followup',
- label: 'TB Diagnosis Follow up',
- }],
- events: [
- {
- id: 'tb_diagnosis_followup',
- start: 2,
- end: 180,
- dueDate: (event, contact, report) => {
- return DateTime.fromISO(Utils.getField(report, 'diagnosis_followup_date')).toJSDate();
- }
- }
- ]
- },
- //TB Monthly Follow up
- {
- name: 'tb.followup.monthly',
- icon: 'icon-tb',
- title: 'tb.follow_up.monthly.title',
- appliesTo: 'reports',
- appliesToType: ['screening', 'tb_followup', 'tb_diagnosis_followup', 'tb_monthly_followup', 'tb_six_months_followup'],
- appliesIf: (contact, report) => {
- return !isMuted(contact) && isCHC() &&
- !tbTreatmentStopped(contact, report) && (
- report.form === 'tb_monthly_followup' ||
- !!Utils.getField(report, 'tb_monthly_followup_date')//From screening/tb_followup/tb_diagnosis_followup/tb_six_months_followup
- );
- },
- resolvedIf: (contact, report, event, dueDate) => {
- return Utils.isFormSubmittedInWindow(
- contact.reports,
- 'tb_monthly_followup',
- report.reported_date + 1,
- Utils.addDate(dueDate, event.end + 1).getTime()
- );
- },
- actions: [{
- type: 'report',
- form: 'tb_monthly_followup',
- label: 'TB Follow up',
- }],
- events: [
- {
- id: 'tb_monthly_followup',
- start: 5,
- end: 180,
- dueDate: (event, contact, report) => {
- return (
- (report.form === 'tb_monthly_followup' && (
- Utils.getField(report, 'followup_details_01.continue') === 'yes' && DateTime.fromMillis(report.reported_date).plus({ days: 30 }).toJSDate()//Completed
- ||
- DateTime.fromISO(Utils.getField(report, 'followup_details_01.reschedule')).toJSDate()//Rescheduled
- )) ||
- DateTime.fromISO(Utils.getField(report, 'tb_monthly_followup_date')).toJSDate()
- //From screening/tb_followup/tb_diagnosis_followup/tb_six_months_followup
- );
- }
- }
- ]
- },
- //TB 6 Months Follow up
- {
- name: 'tb.followup.6months',
- icon: 'icon-tb',
- title: 'tb.followup.6months.title',
- appliesTo: 'reports',
- appliesToType: ['tb_monthly_followup'],
- appliesIf: (contact, report) => {
- return !isMuted(contact) && isCHC() &&
- !tbTreatmentStopped(contact, report) &&
- Utils.getField(report, 'followup_details_01.continue') === 'yes' &&
- getMostRecentCompletedTBMonthlyFollowup(contact.reports)._id === report._id;//Only apply for the most recent completed monthly followup
- },
- resolvedIf: (contact, report, event, dueDate) => {
- return Utils.isFormSubmittedInWindow(
- contact.reports,
- 'tb_six_months_followup',
- report.reported_date + 1,
- Utils.addDate(dueDate, event.end + 1).getTime()
- );
- },
- actions: [{
- type: 'report',
- form: 'tb_six_months_followup',
- label: 'TB Six Months Follow up',
- }],
- events: [
- {
- id: 'tb_six_months_followup',
- start: 30,
- end: 180,
- dueDate: (event, contact, report) => {
- const monthsTreatment = Utils.getField(report, 'followup_details_02.months');
- return DateTime.fromMillis(report.reported_date).minus({ months: monthsTreatment }).plus({ months: 6 }).toJSDate();//6 months since the Treatment started
- }
- }
- ]
- }
- ];
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement