Advertisement
marcelo_deguzman

tasks.js

Sep 21st, 2022 (edited)
37
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 54.36 KB | None | 0 0
  1. const { DateTime } = require('luxon');
  2.  
  3. const extras = require('./nools-extras');
  4.  
  5. const {
  6. isCHC,
  7. wasPregnantAtScreening,
  8. getLMPDateFromScreening,
  9. isPregnancyTerminated,
  10. hasDelivered,
  11. hadIssuesWithFamilyPlanningAtScreening,
  12. hadIssuesWithFamilyPlanningAtFollowup,
  13. familyPlanningWithIssuesFollowupIsRescheduled,
  14. hasDangerSignsFollowup,
  15. isMuted,
  16. hasDeliveredSinceLessThan42Weeks,
  17. hadBreastfeedingIssues,
  18. doneCMAMIScreening,
  19. cmamiDangerSignsReferralGiven,
  20. cmamiWithIssuesFollowupIsRescheduled,
  21. childDangerSignsReferralGiven,
  22. //malnutritionReferralGiven,
  23. //malnutritionReferralGivenBefore,
  24. malnutritionReferralGivenNew,
  25. malnutritionReferralGivenBeforeNew,
  26. imciDangerSignsReferralGiven,
  27. malnutritionWithIssuesReported,
  28. tbTreatmentStopped,
  29. getMostRecentCompletedTBMonthlyFollowup,
  30. getDOBISO,
  31. getAgeInWeeks,
  32. getAgeInYears
  33. } = extras;
  34.  
  35. const generateEventsForPostnatalScreening = (start, end, day) => ({
  36. id: `postnatal-${day}`,
  37. start,
  38. end,
  39. dueDate: function (event, contact, report) {
  40. return DateTime.fromISO(Utils.getField(report, 'delivery_details.date_of_delivery')).plus({ days: day }).toJSDate();
  41. }
  42. });
  43.  
  44. const generateEventsBasedOnDOB = (eventId, start, end, day) => ({
  45. id: eventId,
  46. start,
  47. end,
  48. dueDate: function (event, contact) {
  49. return DateTime.fromISO(getDOBISO(contact.contact)).plus({ days: day }).toJSDate();
  50. }
  51. });
  52.  
  53. const syncReminderEvent = () => {
  54. const dayOfMonth = DateTime.local().get('day');
  55. if (dayOfMonth > 18 || dayOfMonth < 4) {
  56. const addMonth = dayOfMonth > 18 ? 1 : 0;
  57. const dueDate = DateTime.local().plus({ month: addMonth }).set({ day: 1 });//1st of next month or 1st of this month.
  58. return { id: `sync-${dueDate.toISODate()}`, start: 1, end: 2, dueDate: () => dueDate.toJSDate() };
  59. }
  60. else {
  61. const dueDate = DateTime.local().set({ day: 15 });//15th of this month
  62. return { id: `sync-${dueDate.toISODate()}`, start: 0, end: 3, dueDate: () => dueDate.toJSDate() };
  63. }
  64. };
  65.  
  66. module.exports = [
  67. //Sync reminder, every 1st and 15th of the month
  68. {
  69. name: 'sync-reminder',
  70. icon: 'icon-sync',
  71. title: 'task.sync.title',
  72. appliesTo: 'contacts',
  73. appliesToType: ['person'],
  74. appliesIf: function (contact) {
  75. return isCHC() && contact.contact._id === user._id;//Self
  76. },
  77.  
  78. resolvedIf: (contact, report, event, dueDate) => {
  79. return Utils.isFormSubmittedInWindow(
  80. contact.reports,
  81. 'sync',
  82. Utils.addDate(dueDate, -event.start).getTime(),
  83. Utils.addDate(dueDate, event.end + 1).getTime()
  84. );
  85. },
  86.  
  87. actions: [
  88. {
  89. type: 'report',
  90. form: 'sync',
  91. label: 'Sync'
  92. }
  93. ],
  94.  
  95. events: [syncReminderEvent()]
  96. },
  97.  
  98. //Screening based on contact
  99. {
  100. name: 'screening',
  101. icon: 'icon-family',
  102. title: 'task.screening.title',
  103. appliesTo: 'contacts',
  104. appliesToType: ['person'],
  105. appliesIf: function (contact) {
  106. return !isMuted(contact) && isCHC() &&
  107. contact.contact.role === 'household_member';
  108. },
  109.  
  110. resolvedIf: (contact, report, event, dueDate) => {
  111. return Utils.isFormSubmittedInWindow(
  112. contact.reports,
  113. 'screening',
  114. Utils.addDate(dueDate, -event.start).getTime(),
  115. Utils.addDate(dueDate, event.end + 1).getTime()
  116. );
  117. },
  118.  
  119. actions: [
  120. {
  121. type: 'report',
  122. form: 'screening',
  123. label: 'Screening'
  124. }
  125. ],
  126. events: [{
  127. id: 'screening',
  128. start: 60,
  129. end: 180,
  130. days: 60
  131. }
  132. ]
  133. },
  134.  
  135. //Screening based on the last screening
  136. {
  137. name: 'screening.next',
  138. icon: 'icon-family',
  139. title: 'task.screening.title',
  140. appliesTo: 'reports',
  141. appliesToType: ['screening'],
  142. appliesIf: function (contact) {
  143. return !isMuted(contact) && isCHC() &&
  144. contact.contact.role === 'household_member';
  145. },
  146.  
  147. resolvedIf: (contact, report, event, dueDate) => {
  148. return Utils.isFormSubmittedInWindow(
  149. contact.reports,
  150. 'screening',
  151. report.reported_date + 1,
  152. Utils.addDate(dueDate, event.end + 1).getTime()
  153. );
  154. },
  155.  
  156. actions: [
  157. {
  158. type: 'report',
  159. form: 'screening',
  160. label: 'Screening'
  161. }
  162. ],
  163. events: [{
  164. id: 'screening',
  165. start: 15,
  166. end: 180,
  167. days: 60
  168. }
  169. ]
  170. },
  171.  
  172. //Pregnancy followup from screening
  173. {
  174. name: 'anc.pregnancy_followup.screening',
  175. icon: 'icon-pregnancy',
  176. title: 'task.anc.pregnancy_followup.title',
  177. appliesTo: 'reports',
  178. appliesToType: ['screening'],
  179. appliesIf: function (contact, report) {
  180. // If pregnant
  181. return !isMuted(contact) && isCHC() && !!wasPregnantAtScreening(report) &&
  182. !isPregnancyTerminated(contact, report) && !hasDelivered(contact, report);
  183. },
  184.  
  185. resolvedIf: (contact, report, event, dueDate) => {
  186. return Utils.isFormSubmittedInWindow(
  187. contact.reports,
  188. 'pregnancy_followup',
  189. Utils.addDate(dueDate, -event.start).getTime(),
  190. Utils.addDate(dueDate, event.end + 1).getTime()
  191. ) ||
  192. Utils.isFormSubmittedInWindow(
  193. contact.reports,
  194. 'delivery_report',
  195. Utils.addDate(dueDate, -event.start).getTime(),
  196. Utils.addDate(dueDate, event.end + 1).getTime()
  197.  
  198. );
  199.  
  200. },
  201.  
  202. actions: [
  203. {
  204. type: 'report',
  205. form: 'pregnancy_followup',
  206. label: 'Pregnancy followup'
  207. }
  208. ],
  209. events: [{
  210. id: 'pregnancy-followup',
  211. start: 5,
  212. end: 180,
  213. days: 30
  214. }
  215. ]
  216. },
  217. //Pregnancy followup rescheduled
  218. {
  219. name: 'anc.pregnancy_followup.rescheduled',
  220. icon: 'icon-pregnancy',
  221. title: 'task.anc.pregnancy_followup.title',
  222. appliesTo: 'reports',
  223. appliesToType: ['pregnancy_followup'],
  224. appliesIf: function (contact, report) {
  225. // If rescheduled
  226. return !isMuted(contact) && isCHC() && Utils.getField(report, 'followup_details.continue') === 'no' &&
  227. !isPregnancyTerminated(contact, report) && !hasDelivered(contact, report);
  228. },
  229.  
  230. resolvedIf: (contact, report, event, dueDate) => {
  231. return Utils.isFormSubmittedInWindow(
  232. contact.reports,
  233. 'pregnancy_followup',
  234. report.reported_date + 1,
  235. Utils.addDate(dueDate, event.end + 1).getTime()
  236. );
  237. },
  238.  
  239. actions: [
  240. {
  241. type: 'report',
  242. form: 'pregnancy_followup',
  243. label: 'Pregnancy followup'
  244. }
  245. ],
  246. events: [
  247. {
  248. id: 'pregnancy-followup',
  249. start: 5,
  250. end: 180,
  251. dueDate: function (event, contact, report) {
  252. return DateTime.fromISO(Utils.getField(report, 'pregnancy_followup_date')).toJSDate();
  253. }
  254. }
  255. ]
  256. },
  257.  
  258. //Pregnancy followup from pregnancy followup
  259. {
  260. name: 'anc.pregnancy_followup.next',
  261. icon: 'icon-pregnancy',
  262. title: 'task.anc.pregnancy_followup.title',
  263. appliesTo: 'reports',
  264. appliesToType: ['pregnancy_followup'],
  265. appliesIf: function (contact, report) {
  266. // If rescheduled
  267. return !isMuted(contact) && isCHC() && Utils.getField(report, 'followup_details.continue') === 'yes' &&
  268. !isPregnancyTerminated(contact, report) && !hasDelivered(contact, report);
  269. },
  270.  
  271. resolvedIf: (contact, report, event, dueDate) => {
  272. return Utils.isFormSubmittedInWindow(
  273. contact.reports,
  274. 'pregnancy_followup',
  275. report.reported_date + 1,
  276. Utils.addDate(dueDate, event.end + 1).getTime()
  277. );
  278. },
  279.  
  280. actions: [
  281. {
  282. type: 'report',
  283. form: 'pregnancy_followup',
  284. label: 'Pregnancy followup'
  285. }
  286. ],
  287. events: [
  288. {
  289. id: 'pregnancy-followup',
  290. start: 5,
  291. end: 180,
  292. days: 30
  293. }
  294. ]
  295. },
  296.  
  297. //Pregnancy danger signs followup
  298. {
  299. name: 'anc.pregnancy_danger_signs_followup',
  300. icon: 'icon-pregnancy-danger',
  301. title: 'task.anc.pregnancy_danger_signs_followup.title',
  302. appliesTo: 'reports',
  303. appliesToType: ['screening', 'pregnancy_followup'],
  304. appliesIf: function (contact, report) {
  305. return !isMuted(contact) && isCHC() && hasDangerSignsFollowup(report) &&
  306. !isPregnancyTerminated(contact, report) && !hasDelivered(contact, report);
  307. },
  308.  
  309. resolvedIf: (contact, report, event, dueDate) => {
  310. return Utils.isFormSubmittedInWindow(
  311. contact.reports,
  312. 'pregnancy_danger_signs_followup',
  313. Utils.addDate(dueDate, -event.start).getTime(),
  314. Utils.addDate(dueDate, event.end + 1).getTime()
  315. );
  316. },
  317.  
  318. actions: [
  319. {
  320. type: 'report',
  321. form: 'pregnancy_danger_signs_followup',
  322. label: 'Pregnancy danger signs followup',
  323. modifyContent: function (content, contact, report) {
  324. content.lmp_date = getLMPDateFromScreening(report);
  325. }
  326. }
  327. ],
  328. events: [{
  329. id: 'pregnancy-danger-signs-followup',
  330. start: 2,
  331. end: 180,
  332. days: 2
  333. }
  334. ]
  335. },
  336.  
  337. //FP with issues followup
  338. {
  339. name: 'fp.with_issues_followup',
  340. icon: 'icon-follow-up',
  341. title: 'task.fp.with_issues_followup.title',
  342. appliesTo: 'reports',
  343. appliesToType: ['screening', 'fp_followup', 'fp_with_issues_followup'],
  344. appliesIf: (contact, report) => {
  345. return !isMuted(contact) && isCHC() &&
  346. (report.form === 'screening' && hadIssuesWithFamilyPlanningAtScreening(report) ||
  347. report.form === 'fp_followup' && hadIssuesWithFamilyPlanningAtFollowup(report) ||
  348. report.form === 'fp_with_issues_followup' && familyPlanningWithIssuesFollowupIsRescheduled(report));//If had first FP with issues followup or a reschedule.
  349.  
  350. },
  351. resolvedIf: (contact, report, event, dueDate) => {
  352. return Utils.isFormSubmittedInWindow(
  353. contact.reports,
  354. 'fp_with_issues_followup',
  355. report.reported_date + 1,
  356. Utils.addDate(dueDate, event.end + 1).getTime()
  357. );
  358. },
  359.  
  360. actions: [{
  361. type: 'report',
  362. form: 'fp_with_issues_followup',
  363. label: 'FP with issues followup',
  364.  
  365. }],
  366.  
  367. events: [
  368. {
  369. id: 'fp-with-issues-followup',
  370. start: 2,
  371. end: 180,
  372. dueDate: (event, contact, report) => {
  373. return DateTime.fromISO(Utils.getField(report, 'fp_referral_followup_date')).toJSDate();
  374. }
  375. }
  376. ]
  377. },
  378.  
  379.  
  380. //FP Screening follow up
  381. {
  382. name: 'fp.screening_followup',
  383. icon: 'icon-follow-up',
  384. title: 'task.fp.screening_followup.title',
  385. appliesTo: 'reports',
  386. appliesToType: ['screening'],
  387. appliesIf: (contact, report) => {
  388. return !isMuted(contact) && isCHC() &&
  389. Utils.getField(report, 'g_fp.fp_screening_4.fp_screening_4_1.fp_interest') === 'other';
  390. },
  391. resolvedIf: (contact, report, event, dueDate) => {
  392. return Utils.isFormSubmittedInWindow(
  393. contact.reports,
  394. 'fp_screening_followup',
  395. Utils.addDate(dueDate, -event.start).getTime(),
  396. Utils.addDate(dueDate, event.end + 1).getTime()
  397. );
  398. },
  399.  
  400. actions: [{
  401. type: 'report',
  402. form: 'fp_screening_followup',
  403. label: 'FP screening followup',
  404.  
  405. }],
  406.  
  407. events: [
  408. {
  409. id: 'fp-screening-followup',
  410. start: 2,
  411. end: 180,
  412. days: 2
  413. }
  414. ]
  415. },
  416.  
  417. //FP follow up from screening or FP screening follow up
  418. {
  419. name: 'fp.followup',
  420. icon: 'icon-follow-up',
  421. title: 'task.fp.followup.title',
  422. appliesTo: 'reports',
  423. appliesToType: ['screening', 'fp_screening_followup'],
  424. appliesIf: (contact, report) => {
  425. return !isMuted(contact) && isCHC() &&
  426. (
  427. report.form === 'screening' &&
  428. Utils.getField(report, 'g_fp.fp_screening_4.fp_screening_4_1.fp_interest') === 'yes' &&
  429. Utils.getField(report, 'g_fp.fp_screening_4.referral_card.fp_rhu_given_again') === 'yes' ||
  430.  
  431. report.form === 'fp_screening_followup' &&
  432. Utils.getField(report, 'fp_screening.fp_interest') === 'yes' &&
  433. Utils.getField(report, 'fp_screening_3.referral') === 'yes'
  434. );
  435. },
  436. resolvedIf: (contact, report, event, dueDate) => {
  437. return Utils.isFormSubmittedInWindow(
  438. contact.reports,
  439. 'fp_followup',
  440. Utils.addDate(dueDate, -event.start).getTime(),
  441. Utils.addDate(dueDate, event.end + 1).getTime()
  442. );
  443. },
  444.  
  445. actions: [{
  446. type: 'report',
  447. form: 'fp_followup',
  448. label: 'FP followup',
  449.  
  450. }],
  451.  
  452. events: [
  453. {
  454. id: 'fp-followup',
  455. start: 2,
  456. end: 180,
  457. days: 2
  458. }
  459. ]
  460. },
  461.  
  462. //FP follow up from FP followup
  463. {
  464. name: 'fp.followup.followup',
  465. icon: 'icon-follow-up',
  466. title: 'task.fp.followup.title',
  467. appliesTo: 'reports',
  468. appliesToType: ['fp_followup'],
  469. appliesIf: (contact, report) => {
  470. return !isMuted(contact) && isCHC() &&
  471. Utils.getField(report, 'followup_details_1.continue') === 'no';
  472. },
  473. resolvedIf: (contact, report, event, dueDate) => {
  474. return Utils.isFormSubmittedInWindow(
  475. contact.reports,
  476. 'fp_followup',
  477. report.reported_date + 1,
  478. Utils.addDate(dueDate, event.end + 1).getTime()
  479. );
  480. },
  481.  
  482. actions: [{
  483. type: 'report',
  484. form: 'fp_followup',
  485. label: 'FP followup',
  486.  
  487. }],
  488.  
  489. events: [
  490. {
  491. id: 'fp-followup',
  492. start: 2,
  493. end: 180,
  494. dueDate: (event, contact, report) => {
  495. return DateTime.fromISO(Utils.getField(report, 'followup_details_1.reschedule')).toJSDate();
  496. }
  497. }
  498. ]
  499. },
  500.  
  501. //FP procedure followup
  502. {
  503. name: 'fp.procedure.followup',
  504. icon: 'icon-follow-up',
  505. title: 'task.fp.procedure.title',
  506. appliesTo: 'reports',
  507. appliesToType: ['fp_followup'],
  508. appliesIf: (contact, report) => {
  509. return !isMuted(contact) && isCHC() &&
  510. Utils.getField(report, 'visit_details_3.fp_appointment') === 'yes';
  511. },
  512. resolvedIf: (contact, report, event, dueDate) => {
  513. return Utils.isFormSubmittedInWindow(
  514. contact.reports,
  515. 'fp_procedure_followup',
  516. Utils.addDate(dueDate, -event.start).getTime(),
  517. Utils.addDate(dueDate, event.end + 1).getTime()
  518. );
  519. },
  520.  
  521. actions: [{
  522. type: 'report',
  523. form: 'fp_procedure_followup',
  524. label: 'FP procedure followup',
  525.  
  526. }],
  527.  
  528. events: [
  529. {
  530. id: 'fp-procedure-followup',
  531. start: 2,
  532. end: 180,
  533. dueDate: (event, contact, report) => {
  534. return DateTime.fromISO(Utils.getField(report, 'visit_details_3.next_appointment')).plus({ days: 2 }).toJSDate();
  535. }
  536. }
  537. ]
  538. },
  539.  
  540. //CMAMI TASKS
  541. //CMAMI screening
  542. {
  543. name: 'cmami.screening',
  544. icon: 'icon-infant',
  545. title: 'task.cmami.screening.title',
  546. appliesTo: 'contacts',
  547. appliesToType: ['person'],
  548. appliesIf: function (contact) {
  549. return !isMuted(contact) && isCHC() && contact.contact.role === 'household_member' && getAgeInWeeks(contact.contact) < 6;
  550. },
  551.  
  552. resolvedIf: (contact, report, event, dueDate) => {
  553. return Utils.isFormSubmittedInWindow(
  554. contact.reports,
  555. 'cmami_screening',
  556. Utils.addDate(dueDate, -event.start).getTime(),
  557. Utils.addDate(dueDate, event.end + 1).getTime()
  558. );
  559. },
  560.  
  561. actions: [
  562. {
  563. type: 'report',
  564. form: 'cmami_screening',
  565. label: 'CMAMI Screening'
  566. }
  567. ],
  568.  
  569. events: [
  570. generateEventsBasedOnDOB('cmami-screening-d1', 1, 1, 1),//Due on day 1, shows from 0-2 days
  571. generateEventsBasedOnDOB('cmami-screening-d3', 0, 2, 3),//Due on day 3, shows from 3-5 days
  572. generateEventsBasedOnDOB('cmami-screening-d7', 1, 3, 7),//Due on day 7, shows from 6-10 days
  573. generateEventsBasedOnDOB('cmami-screening-d14', 3, 19, 14),//Due on day 14, shows from 11-33 days
  574. 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)
  575. ]
  576. },
  577.  
  578. //CMAMI Screening from age 6 weeks to less than 24 weeks, if not already done
  579. {
  580. name: 'cmami.screening.immediate',
  581. icon: 'icon-infant',
  582. title: 'task.cmami.screening.title',
  583. appliesTo: 'contacts',
  584. appliesToType: ['person'],
  585. appliesIf: function (contact) {
  586. return !isMuted(contact) && isCHC() && contact.contact.role === 'household_member' &&
  587. getAgeInWeeks(contact.contact) >= 6 && getAgeInWeeks(contact.contact) < 24 &&
  588. !doneCMAMIScreening(contact);
  589. },
  590.  
  591. resolvedIf: (contact, report, event, dueDate) => {
  592. return Utils.isFormSubmittedInWindow(
  593. contact.reports,
  594. 'cmami_screening',
  595. Utils.addDate(dueDate, -event.start).getTime(),
  596. Utils.addDate(dueDate, event.end + 1).getTime()
  597. );
  598. },
  599.  
  600. actions: [
  601. {
  602. type: 'report',
  603. form: 'cmami_screening',
  604. label: 'CMAMI Screening'
  605. }
  606. ],
  607.  
  608. events: [
  609. { id: 'cmami-screening-0', start: 7, end: 60, days: 7 }
  610. ]
  611. },
  612.  
  613. //CMAMI followup from contacts
  614. {
  615. name: 'cmami.followup',
  616. icon: 'icon-infant',
  617. title: 'task.cmami.followup.title',
  618. appliesTo: 'contacts',
  619. appliesToType: ['person'],
  620. appliesIf: function (contact) {
  621. return !isMuted(contact) && isCHC() &&
  622. contact.contact.role === 'household_member' &&
  623. getAgeInWeeks(contact.contact) >= 6 &&
  624. getAgeInWeeks(contact.contact) <= 22 &&
  625. doneCMAMIScreening(contact);
  626. },
  627.  
  628. resolvedIf: (contact, report, event, dueDate) => {
  629. return Utils.isFormSubmittedInWindow(
  630. contact.reports,
  631. 'cmami_followup',
  632. Utils.addDate(dueDate, -event.start).getTime(),
  633. Utils.addDate(dueDate, event.end + 1).getTime()
  634. );
  635. },
  636.  
  637. actions: [
  638. {
  639. type: 'report',
  640. form: 'cmami_followup',
  641. label: 'CMAMI follow up'
  642. }
  643. ],
  644. events: [
  645.  
  646. generateEventsBasedOnDOB('cmami-followup-w6', 0, 4 * 7 - 4, 6 * 7),//Due on day 42, shows from 42-66 days
  647. generateEventsBasedOnDOB('cmami-followup-w10', 3, 4 * 7 - 4, 10 * 7),//Due on day 70, shows from 67-94 days
  648. generateEventsBasedOnDOB('cmami-followup-w14', 3, 4 * 7 - 4, 14 * 7),//Due on day 98, shows from 95-122 days
  649. generateEventsBasedOnDOB('cmami-followup-w18', 3, 4 * 7 - 4, 18 * 7),//Due on day 126, shows from 123-150 days
  650. 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)
  651. ]
  652. },
  653.  
  654. //CMAMI follow up from CMAMI follow up (rescheduled)
  655. {
  656. name: 'cmami.screening.followup.followup',
  657. icon: 'icon-infant',
  658. title: 'task.cmami.screening.followup.title',
  659. appliesTo: 'reports',
  660. appliesToType: ['cmami_followup'],
  661. appliesIf: function (contact, report) {
  662. return !isMuted(contact) && isCHC() &&
  663. !!Utils.getField(report, 'resheduled_date') &&
  664. getAgeInWeeks(contact.contact) <= 22;
  665. },
  666.  
  667. resolvedIf: (contact, report, event, dueDate) => {
  668. return Utils.isFormSubmittedInWindow(
  669. contact.reports,
  670. 'cmami_screening_followup',
  671. report.reported_date + 1,
  672. Utils.addDate(dueDate, event.end + 1).getTime()
  673. );
  674. },
  675.  
  676. actions: [
  677. {
  678. type: 'report',
  679. form: 'cmami_screening',
  680. label: 'CMAMI Screening'
  681. }
  682. ],
  683. events: [
  684.  
  685. {
  686. id: 'cmami-followup',
  687. start: 3,
  688. end: 160,
  689. dueDate: (event, contact, report) => {
  690. return DateTime.fromISO(Utils.getField(report, 'rescheduled_date')).toJSDate();
  691. }
  692. }
  693. ]
  694. },
  695. //Postnatal screening
  696. {
  697. name: 'pnc.postnatal.screening',
  698. icon: 'icon-mother-child',
  699. title: 'task.pnc.postnatal.screening.title',
  700. appliesTo: 'reports',
  701. appliesToType: ['delivery_report'],
  702. appliesIf: function (contact, report) {
  703. return !isMuted(contact) && isCHC() && hasDeliveredSinceLessThan42Weeks(report) === true; // Mother is no more eligible after 42 weeks of delivery
  704. },
  705. resolvedIf: (contact, report, event, dueDate) => {
  706.  
  707. return Utils.isFormSubmittedInWindow(
  708. contact.reports,
  709. 'postnatal_screening',
  710. Utils.addDate(dueDate, -event.start).getTime(),
  711. Utils.addDate(dueDate, event.end + 1).getTime()
  712. );
  713. },
  714.  
  715. actions: [{
  716. type: 'report',
  717. form: 'postnatal_screening',
  718. label: 'Postnatal screening',
  719. modifyContent: function (content, contact, report) {
  720. content.date_of_delivery = Utils.getField(report, 'delivery_details.date_of_delivery');
  721. }
  722. }],
  723.  
  724.  
  725. events: [
  726. generateEventsForPostnatalScreening(1, 1, 1),//Due on day 1, shows from day 0-2
  727. generateEventsForPostnatalScreening(0, 1, 3),//Due on day 3, shows from day 3-4
  728. generateEventsForPostnatalScreening(2, 3, 7),//Due on day 7, shows from day 5-10
  729. generateEventsForPostnatalScreening(3, 4 * 7 - 6, 2 * 7),//Due on day 14, shows from day 11-36
  730. generateEventsForPostnatalScreening(5, 4 * 7 - 6, 6 * 7),//Due on day 42, shows from day 37-64
  731. generateEventsForPostnatalScreening(5, 4 * 7 - 6, 10 * 7),//Due on day 70, shows from day 67-92
  732. generateEventsForPostnatalScreening(5, 4 * 7 - 6, 14 * 7),//Due on day 98, shows from day 93-120
  733. generateEventsForPostnatalScreening(5, 4 * 7 - 6, 18 * 7),//Due on day 126. shows from day 121-148
  734. generateEventsForPostnatalScreening(5, 90, 22 * 7)////Due on day 154, shows from day 149-244
  735. ]
  736. },
  737. //CMAMI with issues followup
  738. {
  739. name: 'cmami.with_issues_followup',
  740. icon: 'icon-infant',
  741. title: 'task.cmami.with_issues_followup.title',
  742. appliesTo: 'reports',
  743. appliesToType: ['cmami_screening', 'cmami_followup', 'cmami_with_issues_followup'],
  744. appliesIf: (contact, report) => {
  745. return !isMuted(contact) && isCHC() &&
  746. getAgeInWeeks(contact.contact) <= 22 &&
  747. (
  748. (report.form === 'cmami_screening' && hadBreastfeedingIssues(report)) ||
  749. (report.form === 'cmami_followup' && hadBreastfeedingIssues(report)) ||
  750. (report.form === 'cmami_with_issues_followup' && cmamiWithIssuesFollowupIsRescheduled(report))
  751. );
  752. },
  753. resolvedIf: (contact, report, event, dueDate) => {
  754. return Utils.isFormSubmittedInWindow(
  755. contact.reports,
  756. 'cmami_with_issues_followup',
  757. report.reported_date + 1,
  758. Utils.addDate(dueDate, event.end + 1).getTime()
  759. );
  760. },
  761.  
  762. actions: [{
  763. type: 'report',
  764. form: 'cmami_with_issues_followup',
  765. label: 'CMAMI with issues followup',
  766.  
  767. }],
  768.  
  769. events: [
  770. {
  771. id: 'cmami-with-issues-followup',
  772. start: 2,
  773. end: 180,
  774. dueDate: (event, contact, report) => {
  775. return DateTime.fromISO(Utils.getField(report, 'issues_followup_date')).toJSDate();
  776. }
  777. }
  778. ]
  779. },
  780.  
  781. //CMAMI danger signs followup
  782. {
  783. name: 'cmami.danger_signs_followup',
  784. icon: 'icon-infant-danger',
  785. title: 'task.cmami.danger_signs.title',
  786. appliesTo: 'reports',
  787. appliesToType: ['cmami_screening', 'cmami_followup'],
  788. appliesIf: (contact, report) => {
  789. return !isMuted(contact) && isCHC() &&
  790. getAgeInWeeks(contact.contact) <= 22 &&
  791. cmamiDangerSignsReferralGiven(report);
  792. },
  793. resolvedIf: (contact, report, event, dueDate) => {
  794. return Utils.isFormSubmittedInWindow(
  795. contact.reports,
  796. 'cmami_danger_signs_followup',
  797. Utils.addDate(dueDate, -event.start).getTime(),
  798. Utils.addDate(dueDate, event.end + 1).getTime()
  799. );
  800. },
  801.  
  802. actions: [{
  803. type: 'report',
  804. form: 'cmami_danger_signs_followup',
  805. label: 'CMAMI danger signs followup',
  806.  
  807. }],
  808.  
  809. events: [
  810. {
  811. id: 'cmami-danger-signs-followup',
  812. start: 2,
  813. end: 180,
  814. dueDate: (event, contact, report) => {
  815. return DateTime.fromISO(Utils.getField(report, 'danger_signs_followup_date')).toJSDate();
  816. }
  817. }
  818. ]
  819. },
  820.  
  821. //CHILD HEALTH WORKFLOW
  822.  
  823.  
  824. //Child health danger signs followup
  825. {
  826. name: 'child_health.danger_signs_followup',
  827. icon: 'icon-child-danger',
  828. title: 'task.child_health.danger_signs.title',
  829. appliesTo: 'reports',
  830. appliesToType: ['screening'],
  831. appliesIf: (contact, report) => {
  832. return !isMuted(contact) && isCHC() &&
  833. getAgeInYears(contact.contact) < 5 &&
  834. childDangerSignsReferralGiven(report);
  835. },
  836. resolvedIf: (contact, report, event, dueDate) => {
  837. return Utils.isFormSubmittedInWindow(
  838. contact.reports,
  839. 'child_health_danger_signs_followup',
  840. Utils.addDate(dueDate, -event.start).getTime(),
  841. Utils.addDate(dueDate, event.end + 1).getTime()
  842. );
  843. },
  844.  
  845. actions: [{
  846. type: 'report',
  847. form: 'child_health_danger_signs_followup',
  848. label: 'Child health danger signs followup',
  849.  
  850. }],
  851.  
  852. events: [
  853. {
  854. id: 'child-health-danger-signs-followup',
  855. start: 2,
  856. end: 180,
  857. days: 2
  858. }
  859. ]
  860. },
  861.  
  862. //Malnutrition 48 hrs follow up from screening - try to remove this tasks if possible
  863. /* {
  864. name: 'malnutrition.48_hrs_followup',
  865. icon: 'icon-child-nutrition',
  866. title: 'task.malnutrition_48_hrs.title',
  867. appliesTo: 'reports',
  868. appliesToType: ['screening'],
  869. appliesIf: (contact, report) => {
  870. return !isMuted(contact) && isCHC() && getAgeInYears(contact.contact) < 5 &&
  871. malnutritionReferralGiven(report);
  872. },
  873. resolvedIf: (contact, report, event, dueDate) => {
  874. return Utils.isFormSubmittedInWindow(
  875. contact.reports,
  876. 'malnutrition_followup_48h',
  877. Utils.addDate(dueDate, -event.start).getTime(),
  878. Utils.addDate(dueDate, event.end + 1).getTime()
  879. ) ||
  880. Utils.isFormSubmittedInWindow(
  881. contact.reports,
  882. 'malnutrition_discharge',
  883. Utils.addDate(dueDate, -event.start).getTime(),
  884. Utils.addDate(dueDate, event.end + 1).getTime()
  885. );
  886. },
  887.  
  888. actions: [{
  889. type: 'report',
  890. form: 'malnutrition_followup_48h',
  891. label: 'Malnutrition 48 hrs followup',
  892.  
  893. }],
  894.  
  895. events: [
  896. {
  897. id: 'malnutrition-48hrs-followup',
  898. start: 2,
  899. end: 180,
  900. days: 2
  901. }
  902. ]
  903. },
  904. */
  905. //Malnutrition 48 hrs follow up rescheduled - try to remove this tasks if possible
  906. /* {
  907. name: 'malnutrition.48_hrs_followup.rescheduled',
  908. icon: 'icon-child-nutrition',
  909. title: 'task.malnutrition_48_hrs.title',
  910. appliesTo: 'reports',
  911. appliesToType: ['malnutrition_followup_48h'],
  912. appliesIf: (contact, report) => {
  913. return !isMuted(contact) && isCHC() &&
  914. getAgeInYears(contact.contact) < 5 &&
  915. Utils.getField(report, 'g_continue.continue') === 'no';
  916. },
  917. resolvedIf: (contact, report, event, dueDate) => {
  918. return Utils.isFormSubmittedInWindow(
  919. contact.reports,
  920. 'malnutrition_followup_48h',
  921. report.reported_date + 1,
  922. Utils.addDate(dueDate, event.end + 1).getTime()
  923. ) ||
  924. Utils.isFormSubmittedInWindow(
  925. contact.reports,
  926. 'malnutrition_discharge',
  927. report.reported_date + 1,
  928. Utils.addDate(dueDate, event.end + 1).getTime()
  929. );
  930. },
  931.  
  932. actions: [{
  933. type: 'report',
  934. form: 'malnutrition_followup_48h',
  935. label: 'Malnutrition 48 hrs followup',
  936.  
  937. }],
  938.  
  939. events: [
  940. {
  941. id: 'malnutrition-48hrs-followup',
  942. start: 2,
  943. end: 180,
  944. dueDate: (event, contact, report) => {
  945. return DateTime.fromISO(Utils.getField(report, 'g_continue.reschedule')).toJSDate();
  946. }
  947. }
  948. ]
  949. },
  950. */
  951. //Malnutrition every 2 weeks follow up from screening - try to change the from of malnutrition_followup_every_2w to health_facility_followup_every_2w
  952. {
  953. name: 'malnutrition.every_2_weeks_followup',
  954. icon: 'icon-child-nutrition',
  955. title: 'task.malnutrition_every_2_weeks.title',
  956. appliesTo: 'reports',
  957. appliesToType: ['screening'],
  958. appliesIf: (contact, report) => {
  959. return !isMuted(contact) && isCHC() && getAgeInYears(contact.contact) < 5 &&
  960. (malnutritionReferralGivenNew(report) || malnutritionReferralGivenBeforeNew(report));
  961. },
  962. resolvedIf: (contact, report, event, dueDate) => {
  963. return Utils.isFormSubmittedInWindow(
  964. contact.reports,
  965. 'health_facility_followup_every_2w',
  966. report.reported_date + 1,
  967. Utils.addDate(dueDate, event.end + 1).getTime()
  968. ) ||
  969. Utils.isFormSubmittedInWindow(
  970. contact.reports,
  971. 'malnutrition_followup_every_2w',
  972. report.reported_date + 1,
  973. Utils.addDate(dueDate, event.end + 1).getTime()
  974. ) ||
  975. Utils.isFormSubmittedInWindow(
  976. contact.reports,
  977. 'malnutrition_discharge',
  978. report.reported_date + 1,
  979. Utils.addDate(dueDate, event.end + 1).getTime()
  980. );
  981. },
  982.  
  983. actions: [{
  984. type: 'report',
  985. form: 'health_facility_followup_every_2w',
  986. label: 'Malnutrition every 2 weeks followup',
  987.  
  988. }],
  989.  
  990.  
  991. events: [
  992. {
  993. id: 'malnutrition-every2w-followup',
  994. start: 5, //for testing, change 2 from 5.
  995. end: 180,
  996. days: 14
  997. }
  998. ]
  999.  
  1000. },
  1001.  
  1002. //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
  1003. {
  1004. name: 'malnutrition.every_2_weeks_followup.next',
  1005. icon: 'icon-child-nutrition',
  1006. title: 'task.malnutrition_every_2_weeks.title',
  1007. appliesTo: 'reports',
  1008. appliesToType: ['health_facility_followup_every_2w'],
  1009. appliesIf: (contact) => {
  1010. //Applies automatically
  1011. return !isMuted(contact) && isCHC() && getAgeInYears(contact.contact) < 5;
  1012. },
  1013. resolvedIf: (contact, report, event, dueDate) => {
  1014. return Utils.isFormSubmittedInWindow(
  1015. contact.reports,
  1016. 'health_facility_followup_every_2w',
  1017. report.reported_date + 1,
  1018. Utils.addDate(dueDate, event.end + 1).getTime()
  1019. ) || Utils.isFormSubmittedInWindow(
  1020. contact.reports,
  1021. 'malnutrition_followup_every_2w',
  1022. report.reported_date + 1,
  1023. Utils.addDate(dueDate, event.end + 1).getTime()
  1024. ) ||
  1025. Utils.isFormSubmittedInWindow(
  1026. contact.reports,
  1027. 'malnutrition_discharge',
  1028. report.reported_date + 1,
  1029. Utils.addDate(dueDate, event.end + 1).getTime()
  1030. );
  1031. },
  1032.  
  1033. actions: [{
  1034. type: 'report',
  1035. form: 'health_facility_followup_every_2w',
  1036. label: 'Malnutrition every 2 weeks followup',
  1037.  
  1038. }],
  1039.  
  1040.  
  1041. events: [
  1042. {
  1043. id: 'malnutrition-every2w-followup',
  1044. start: 5,
  1045. end: 180,
  1046. days: 14
  1047. }
  1048. ]
  1049.  
  1050. },
  1051.  
  1052.  
  1053.  
  1054. //Malnutrition with issues followup from Malnutrition every 2 weeks follow up
  1055. {
  1056. name: 'malnutrition.with_issues_followup',
  1057. icon: 'icon-follow-up',
  1058. title: 'task.malnutrition.with_issues_followup.title',
  1059. appliesTo: 'reports',
  1060. appliesToType: ['health_facility_followup_every_2w'], //malnutrition_followup_every_2w
  1061. appliesIf: (contact, report) => {
  1062. return !isMuted(contact) && isCHC() && getAgeInYears(contact.contact) < 5 && malnutritionWithIssuesReported(report);
  1063. },
  1064. resolvedIf: (contact, report, event, dueDate) => {
  1065. return Utils.isFormSubmittedInWindow(
  1066. contact.reports,
  1067. 'malnutrition_with_issues_followup',
  1068. Utils.addDate(dueDate, -event.start).getTime(),
  1069. Utils.addDate(dueDate, event.end + 1).getTime()
  1070. ) ||
  1071. Utils.isFormSubmittedInWindow(
  1072. contact.reports,
  1073. 'malnutrition_discharge',
  1074. Utils.addDate(dueDate, -event.start).getTime(),
  1075. Utils.addDate(dueDate, event.end + 1).getTime()
  1076. );
  1077. },
  1078.  
  1079. actions: [{
  1080. type: 'report',
  1081. form: 'malnutrition_with_issues_followup',
  1082. label: 'Malnutrition with issues followup',
  1083.  
  1084. }],
  1085.  
  1086. events: [
  1087. {
  1088. id: 'malnutrition-with-issues-followup',
  1089. start: 2,
  1090. end: 180,
  1091. days: 2
  1092. }
  1093. ]
  1094. },
  1095.  
  1096. //Malnutrition with issues follow up rescheduled
  1097. {
  1098. name: 'malnutrition.with_issues_followup.rescheduled',
  1099. icon: 'icon-follow-up',
  1100. title: 'task.malnutrition.with_issues_followup.title',
  1101. appliesTo: 'reports',
  1102. appliesToType: ['malnutrition_with_issues_followup'],
  1103. appliesIf: (contact, report) => {
  1104. return !isMuted(contact) && isCHC() && getAgeInYears(contact.contact) < 5 &&
  1105. Utils.getField(report, 'followup_details_1.continue') === 'no';
  1106. },
  1107. resolvedIf: (contact, report, event, dueDate) => {
  1108. return Utils.isFormSubmittedInWindow(
  1109. contact.reports,
  1110. 'malnutrition_with_issues_followup',
  1111. Utils.addDate(dueDate, -event.start).getTime(),
  1112. Utils.addDate(dueDate, event.end + 1).getTime()
  1113. ) ||
  1114. Utils.isFormSubmittedInWindow(
  1115. contact.reports,
  1116. 'malnutrition_discharge',
  1117. Utils.addDate(dueDate, -event.start).getTime(),
  1118. Utils.addDate(dueDate, event.end + 1).getTime()
  1119. );
  1120. },
  1121.  
  1122. actions: [{
  1123. type: 'report',
  1124. form: 'malnutrition_with_issues_followup',
  1125. label: 'Malnutrition with issues followup',
  1126.  
  1127. }],
  1128.  
  1129. events: [
  1130. {
  1131. id: 'malnutrition-48hrs-followup',
  1132. start: 2,
  1133. end: 180,
  1134. dueDate: (event, contact, report) => {
  1135. return DateTime.fromISO(Utils.getField(report, 'malnutrition_with_issues_followup_date')).toJSDate();
  1136. }
  1137. }
  1138. ]
  1139. },
  1140.  
  1141. //IMCI
  1142.  
  1143. //IMCI appointment followup
  1144. {
  1145. name: 'imci.appointment.followup',
  1146. icon: 'icon-follow-up',
  1147. title: 'task.imci_appointment_followup.title',
  1148. appliesTo: 'reports',
  1149. appliesToType: ['imci_followup_48h'],
  1150. appliesIf: (contact, report) => {
  1151. return !isMuted(contact) && isCHC() && getAgeInYears(contact.contact) < 5 &&
  1152. Utils.getField(report, 'appointment_date_iso');
  1153. },
  1154. resolvedIf: (contact, report, event, dueDate) => {
  1155. return Utils.isFormSubmittedInWindow(
  1156. contact.reports,
  1157. 'imci_appointment_followup',
  1158. report.reported_date + 1,
  1159. Utils.addDate(dueDate, event.end + 1).getTime()
  1160. ) ||
  1161. Utils.isFormSubmittedInWindow(
  1162. contact.reports,
  1163. 'imci_recovery',
  1164. report.reported_date + 1,
  1165. Utils.addDate(dueDate, event.end + 1).getTime()
  1166. );
  1167. },
  1168.  
  1169. actions: [{
  1170. type: 'report',
  1171. form: 'imci_appointment_followup',
  1172. label: 'IMCI follow up',
  1173.  
  1174. }],
  1175.  
  1176. events: [
  1177. {
  1178. id: 'imci-appointment-followup',
  1179. start: 2,
  1180. end: 60,
  1181. dueDate: (event, contact, report) => {
  1182. return DateTime.fromISO(Utils.getField(report, 'appointment_date_iso')).plus({ days: 2 }).toJSDate();
  1183. }
  1184. }
  1185. ]
  1186. },
  1187. //IMCI 48 hrs follow up (danger signs)
  1188. {
  1189. name: 'imci.48_hrs_followup',
  1190. icon: 'icon-follow-up',
  1191. title: 'task.imci_48_hrs.title',
  1192. appliesTo: 'reports',
  1193. appliesToType: ['screening', 'imci_followup_48h', 'imci_followup_weekly'],
  1194. appliesIf: (contact, report) => {
  1195. return !isMuted(contact) && isCHC() && imciDangerSignsReferralGiven(report);
  1196. },
  1197. resolvedIf: (contact, report, event, dueDate) => {
  1198. return Utils.isFormSubmittedInWindow(
  1199. contact.reports,
  1200. 'imci_followup_48h',
  1201. report.reported_date + 1,
  1202. Utils.addDate(dueDate, event.end + 1).getTime()
  1203. ) ||
  1204. Utils.isFormSubmittedInWindow(
  1205. contact.reports,
  1206. 'imci_recovery',
  1207. Utils.addDate(dueDate, -event.start).getTime(),
  1208. Utils.addDate(dueDate, event.end + 1).getTime()
  1209. ) ||
  1210. getAgeInYears(contact.contact) >= 5; // make the task disappear if baby age gets to >= 5 years
  1211. },
  1212.  
  1213. actions: [{
  1214. type: 'report',
  1215. form: 'imci_followup_48h',
  1216. label: 'IMCI 48 hrs followup',
  1217.  
  1218. }],
  1219.  
  1220. events: [
  1221. {
  1222. id: 'imci-48hrs-followup',
  1223. start: 2,
  1224. end: 60,
  1225. days: 2
  1226. }
  1227. ]
  1228. },
  1229.  
  1230. //IMCI weekly follow up
  1231. {
  1232. name: 'imci.weekly_followup',
  1233. icon: 'icon-follow-up',
  1234. title: 'task.imci_weekly.title',
  1235. appliesTo: 'reports',
  1236. appliesToType: ['screening', 'imci_followup_48h', 'imci_followup_weekly'],
  1237. appliesIf: (contact, report) => {
  1238. return !isMuted(contact) && isCHC() && getAgeInYears(contact.contact) < 5 && imciDangerSignsReferralGiven(report);
  1239. },
  1240. resolvedIf: (contact, report, event, dueDate) => {
  1241. return Utils.isFormSubmittedInWindow(
  1242. contact.reports,
  1243. 'imci_followup_weekly',
  1244. report.reported_date + 1,
  1245. Utils.addDate(dueDate, event.end + 1).getTime()
  1246. ) ||
  1247. Utils.isFormSubmittedInWindow(
  1248. contact.reports,
  1249. 'imci_recovery',
  1250. Utils.addDate(dueDate, -event.start).getTime(),
  1251. Utils.addDate(dueDate, event.end + 1).getTime()
  1252. );
  1253. },
  1254.  
  1255. actions: [{
  1256. type: 'report',
  1257. form: 'imci_followup_weekly',
  1258. label: 'IMCI weekly followup',
  1259.  
  1260. }],
  1261.  
  1262. events: [
  1263. {
  1264. id: 'imci-weekly-followup',
  1265. start: 3,
  1266. end: 60,
  1267. days: 7
  1268. }
  1269. ]
  1270. },
  1271.  
  1272. //IMCI weekly follow up from previous IMCI weekly followup
  1273. {
  1274. name: 'imci.weekly_followup.next',
  1275. icon: 'icon-follow-up',
  1276. title: 'task.imci_weekly.title',
  1277. appliesTo: 'reports',
  1278. appliesToType: ['imci_followup_weekly'],
  1279. appliesIf: (contact) => {
  1280. return !isMuted(contact) && isCHC() && getAgeInYears(contact.contact) < 5;
  1281. },
  1282. resolvedIf: (contact, report, event, dueDate) => {
  1283. return Utils.isFormSubmittedInWindow(
  1284. contact.reports,
  1285. 'imci_followup_weekly',
  1286. report.reported_date + 1,
  1287. Utils.addDate(dueDate, event.end + 1).getTime()
  1288. ) ||
  1289. Utils.isFormSubmittedInWindow(
  1290. contact.reports,
  1291. 'imci_recovery',
  1292. Utils.addDate(dueDate, -event.start).getTime(),
  1293. Utils.addDate(dueDate, event.end + 1).getTime()
  1294. );
  1295. },
  1296.  
  1297. actions: [{
  1298. type: 'report',
  1299. form: 'imci_followup_weekly',
  1300. label: 'IMCI weekly followup',
  1301.  
  1302. }],
  1303.  
  1304. events: [
  1305. {
  1306. id: 'imci-weekly-followup',
  1307. start: 3,
  1308. end: 60,
  1309. days: 7
  1310. }
  1311. ]
  1312. },
  1313.  
  1314. //IMCI weekly follow up rescheduled
  1315. {
  1316. name: 'imci.weekly_followup.rescheduled',
  1317. icon: 'icon-follow-up',
  1318. title: 'task.imci_weekly.title',
  1319. appliesTo: 'reports',
  1320. appliesToType: ['imci_followup_weekly'],
  1321. appliesIf: (contact, report) => {
  1322. return !isMuted(contact) && isCHC() && getAgeInYears(contact.contact) < 5 &&
  1323. Utils.getField(report, 'g_continue.continue') === 'no';
  1324. },
  1325. resolvedIf: (contact, report, event, dueDate) => {
  1326. return Utils.isFormSubmittedInWindow(
  1327. contact.reports,
  1328. 'imci_followup_weekly',
  1329. report.reported_date + 1,
  1330. Utils.addDate(dueDate, event.end + 1).getTime()
  1331. ) ||
  1332. Utils.isFormSubmittedInWindow(
  1333. contact.reports,
  1334. 'imci_recovery',
  1335. report.reported_date + 1,
  1336. Utils.addDate(dueDate, event.end + 1).getTime()
  1337. );
  1338. },
  1339.  
  1340. actions: [{
  1341. type: 'report',
  1342. form: 'imci_followup_weekly',
  1343. label: 'IMCI weekly followup',
  1344.  
  1345. }],
  1346.  
  1347. events: [
  1348. {
  1349. id: 'imci-weekly-followup',
  1350. start: 3,
  1351. end: 60,
  1352. dueDate: (event, contact, report) => {
  1353. return DateTime.fromISO(Utils.getField(report, 'g_continue.reschedule')).toJSDate();
  1354. }
  1355. }
  1356. ]
  1357. },
  1358.  
  1359. //TB Follow up
  1360. {
  1361. name: 'tb.follow_up',
  1362. icon: 'icon-tb',
  1363. title: 'tb.follow_up.title',
  1364. appliesTo: 'reports',
  1365. appliesToType: ['screening', 'tb_followup'],
  1366. appliesIf: (contact, report) => {
  1367. return !isMuted(contact) && isCHC() &&
  1368. !tbTreatmentStopped(contact, report) && (
  1369. report.form === 'screening' && !!Utils.getField(report, 'tb_followup_date')
  1370. ||
  1371. report.form === 'tb_followup' && Utils.getField(report, 'g_continue.continue') === 'no'//Rescheduled
  1372. );
  1373. },
  1374. resolvedIf: (contact, report, event, dueDate) => {
  1375. return Utils.isFormSubmittedInWindow(
  1376. contact.reports,
  1377. 'tb_followup',
  1378. report.reported_date + 1,
  1379. Utils.addDate(dueDate, event.end + 1).getTime()
  1380. );
  1381. },
  1382. actions: [{
  1383. type: 'report',
  1384. form: 'tb_followup',
  1385. label: 'TB Follow up',
  1386.  
  1387. }],
  1388.  
  1389. events: [
  1390. {
  1391. id: 'tb_followup',
  1392. start: 2,
  1393. end: 180,
  1394. dueDate: (event, contact, report) => {
  1395. return (
  1396. report.form === 'screening' && DateTime.fromISO(Utils.getField(report, 'tb_followup_date')).toJSDate()
  1397. ||
  1398. report.form === 'tb_followup' && DateTime.fromISO(Utils.getField(report, 'g_continue.reschedule')).toJSDate()//Rescheduled
  1399. );
  1400. }
  1401. }
  1402. ]
  1403. },
  1404.  
  1405. //TB Testing Follow up
  1406. {
  1407. name: 'tb.followup.testing',
  1408. icon: 'icon-tb',
  1409. title: 'tb.followup.testing.title',
  1410. appliesTo: 'reports',
  1411. appliesToType: ['tb_followup'],
  1412. appliesIf: (contact, report) => {
  1413. return !isMuted(contact) && isCHC() &&
  1414. !tbTreatmentStopped(contact, report) &&
  1415. !!Utils.getField(report, 'test_followup_date');
  1416. },
  1417. resolvedIf: (contact, report, event, dueDate) => {
  1418. return Utils.isFormSubmittedInWindow(
  1419. contact.reports,
  1420. 'tb_test_followup',
  1421. report.reported_date + 1,
  1422. Utils.addDate(dueDate, event.end + 1).getTime()
  1423. );
  1424. },
  1425. actions: [{
  1426. type: 'report',
  1427. form: 'tb_test_followup',
  1428. label: 'TB Testing Follow up',
  1429.  
  1430. }],
  1431. events: [
  1432. {
  1433. id: 'tb_test_followup',
  1434. start: 2,
  1435. end: 180,
  1436. dueDate: (event, contact, report) => {
  1437. return DateTime.fromISO(Utils.getField(report, 'test_followup_date')).toJSDate();
  1438. }
  1439. }
  1440. ]
  1441. },
  1442.  
  1443. //TB Diagnosis Follow up
  1444. {
  1445. name: 'tb.followup.diagnosis',
  1446. icon: 'icon-tb',
  1447. title: 'tb.followup.diagnosis.title',
  1448. appliesTo: 'reports',
  1449. appliesToType: ['tb_followup', 'tb_test_followup'],
  1450. appliesIf: (contact, report) => {
  1451. return !isMuted(contact) && isCHC() &&
  1452. !tbTreatmentStopped(contact, report) &&
  1453. !!Utils.getField(report, 'diagnosis_followup_date');
  1454. },
  1455. resolvedIf: (contact, report, event, dueDate) => {
  1456. return Utils.isFormSubmittedInWindow(
  1457. contact.reports,
  1458. 'tb_diagnosis_followup',
  1459. report.reported_date + 1,
  1460. Utils.addDate(dueDate, event.end + 1).getTime()
  1461. );
  1462. },
  1463. actions: [{
  1464. type: 'report',
  1465. form: 'tb_diagnosis_followup',
  1466. label: 'TB Diagnosis Follow up',
  1467.  
  1468. }],
  1469. events: [
  1470. {
  1471. id: 'tb_diagnosis_followup',
  1472. start: 2,
  1473. end: 180,
  1474. dueDate: (event, contact, report) => {
  1475. return DateTime.fromISO(Utils.getField(report, 'diagnosis_followup_date')).toJSDate();
  1476. }
  1477. }
  1478. ]
  1479. },
  1480.  
  1481. //TB Monthly Follow up
  1482. {
  1483. name: 'tb.followup.monthly',
  1484. icon: 'icon-tb',
  1485. title: 'tb.follow_up.monthly.title',
  1486. appliesTo: 'reports',
  1487. appliesToType: ['screening', 'tb_followup', 'tb_diagnosis_followup', 'tb_monthly_followup', 'tb_six_months_followup'],
  1488. appliesIf: (contact, report) => {
  1489. return !isMuted(contact) && isCHC() &&
  1490. !tbTreatmentStopped(contact, report) && (
  1491. report.form === 'tb_monthly_followup' ||
  1492. !!Utils.getField(report, 'tb_monthly_followup_date')//From screening/tb_followup/tb_diagnosis_followup/tb_six_months_followup
  1493. );
  1494. },
  1495. resolvedIf: (contact, report, event, dueDate) => {
  1496. return Utils.isFormSubmittedInWindow(
  1497. contact.reports,
  1498. 'tb_monthly_followup',
  1499. report.reported_date + 1,
  1500. Utils.addDate(dueDate, event.end + 1).getTime()
  1501. );
  1502. },
  1503. actions: [{
  1504. type: 'report',
  1505. form: 'tb_monthly_followup',
  1506. label: 'TB Follow up',
  1507.  
  1508. }],
  1509.  
  1510. events: [
  1511. {
  1512. id: 'tb_monthly_followup',
  1513. start: 5,
  1514. end: 180,
  1515. dueDate: (event, contact, report) => {
  1516. return (
  1517. (report.form === 'tb_monthly_followup' && (
  1518. Utils.getField(report, 'followup_details_01.continue') === 'yes' && DateTime.fromMillis(report.reported_date).plus({ days: 30 }).toJSDate()//Completed
  1519. ||
  1520. DateTime.fromISO(Utils.getField(report, 'followup_details_01.reschedule')).toJSDate()//Rescheduled
  1521. )) ||
  1522. DateTime.fromISO(Utils.getField(report, 'tb_monthly_followup_date')).toJSDate()
  1523. //From screening/tb_followup/tb_diagnosis_followup/tb_six_months_followup
  1524. );
  1525. }
  1526. }
  1527. ]
  1528. },
  1529.  
  1530. //TB 6 Months Follow up
  1531. {
  1532. name: 'tb.followup.6months',
  1533. icon: 'icon-tb',
  1534. title: 'tb.followup.6months.title',
  1535. appliesTo: 'reports',
  1536. appliesToType: ['tb_monthly_followup'],
  1537. appliesIf: (contact, report) => {
  1538. return !isMuted(contact) && isCHC() &&
  1539. !tbTreatmentStopped(contact, report) &&
  1540. Utils.getField(report, 'followup_details_01.continue') === 'yes' &&
  1541. getMostRecentCompletedTBMonthlyFollowup(contact.reports)._id === report._id;//Only apply for the most recent completed monthly followup
  1542. },
  1543. resolvedIf: (contact, report, event, dueDate) => {
  1544. return Utils.isFormSubmittedInWindow(
  1545. contact.reports,
  1546. 'tb_six_months_followup',
  1547. report.reported_date + 1,
  1548. Utils.addDate(dueDate, event.end + 1).getTime()
  1549. );
  1550. },
  1551. actions: [{
  1552. type: 'report',
  1553. form: 'tb_six_months_followup',
  1554. label: 'TB Six Months Follow up',
  1555.  
  1556. }],
  1557. events: [
  1558. {
  1559. id: 'tb_six_months_followup',
  1560. start: 30,
  1561. end: 180,
  1562. dueDate: (event, contact, report) => {
  1563. const monthsTreatment = Utils.getField(report, 'followup_details_02.months');
  1564. return DateTime.fromMillis(report.reported_date).minus({ months: monthsTreatment }).plus({ months: 6 }).toJSDate();//6 months since the Treatment started
  1565. }
  1566. }
  1567. ]
  1568. }
  1569. ];
Tags: medic
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement