From 972060865b198579317b42eb0c83c530d03c1522 Mon Sep 17 00:00:00 2001 From: Vivek Singh Date: Tue, 19 Dec 2023 17:55:38 +0530 Subject: [PATCH] #1216 - get count based on location for task type card --- .../ReportCardServiceIntegrationTest.js | 20 +++++++++++++++++-- .../customDashboard/ReportCardService.js | 11 +++++----- .../src/service/query/RealmQueryService.js | 3 ++- .../src/service/task/TaskService.js | 9 ++++++--- .../test/model/TestTaskFactory.js | 8 +++++++- .../test/model/TestTaskStatusFactory.js | 6 ++++-- .../test/model/TestTaskTypeFactory.js | 7 +++++-- 7 files changed, 47 insertions(+), 17 deletions(-) diff --git a/packages/openchs-android/integrationTest/ReportCardServiceIntegrationTest.js b/packages/openchs-android/integrationTest/ReportCardServiceIntegrationTest.js index eb282d8a1..234c37653 100644 --- a/packages/openchs-android/integrationTest/ReportCardServiceIntegrationTest.js +++ b/packages/openchs-android/integrationTest/ReportCardServiceIntegrationTest.js @@ -10,7 +10,7 @@ import { ProgramEnrolment, ReportCard, StandardReportCardType, - Comment + Comment, TaskType, Task, TaskStatus } from "openchs-models"; import TestSubjectFactory from "../test/model/txn/TestSubjectFactory"; import TestObsFactory from "../test/model/TestObsFactory"; @@ -31,6 +31,9 @@ import TestConceptFactory from "../test/model/TestConceptFactory"; import TestMetadataService from "./service/TestMetadataService"; import TestCommentFactory from "../test/model/comment/TestCommentFactory"; import TestCommentThreadFactory from "../test/model/comment/TestCommentThreadFactory"; +import TestTaskTypeFactory from "../test/model/TestTaskTypeFactory"; +import TestTaskFactory from "../test/model/TestTaskFactory"; +import TestTaskStatusFactory from "../test/model/TestTaskStatusFactory"; function getCount(test, card, reportFilters) { let reportCardCount = test.reportCardService.getReportCardCount(card, reportFilters); @@ -220,10 +223,23 @@ class ReportCardServiceIntegrationTest extends BaseIntegrationTest { }); assert.equal(1, getCount(this, commentCard, [])); assert.equal(1, getCount(this, commentCard, [this.addressSelected])); - this.logQueries(); assert.equal(0, getCount(this, commentCard, [this.address2Selected])); } + getCountForTaskCardType() { + let taskTypeCard; + this.executeInWrite((db) => { + const taskTypeCardType = db.create(StandardReportCardType, TestStandardReportCardTypeFactory.create({name: StandardReportCardType.type.CallTasks})); + taskTypeCard = db.create(ReportCard, TestReportCardFactory.create({name: "callTaskTypeCard", standardReportCardType: taskTypeCardType})); + const taskType = db.create(TaskType, TestTaskTypeFactory.create()); + const taskStatus = db.create(TaskStatus, TestTaskStatusFactory.create({taskType: taskType})); + db.create(Task, TestTaskFactory.create({taskType: taskType, taskStatus: taskStatus, subject: this.subject1})); + }); + assert.equal(1, getCount(this, taskTypeCard, [])); + assert.equal(1, getCount(this, taskTypeCard, [this.addressSelected])); + assert.equal(0, getCount(this, taskTypeCard, [this.address2Selected])); + } + getResultForApprovalCardsType() { assert.equal(2, getCount(this, this.approvedCard, [])); assert.equal(1, getCount(this, this.approvedCard, [this.addressSelected])); diff --git a/packages/openchs-android/src/service/customDashboard/ReportCardService.js b/packages/openchs-android/src/service/customDashboard/ReportCardService.js index 75fc74452..a48b91958 100644 --- a/packages/openchs-android/src/service/customDashboard/ReportCardService.js +++ b/packages/openchs-android/src/service/customDashboard/ReportCardService.js @@ -46,16 +46,16 @@ class ReportCardService extends BaseService { return this.getService(CommentService).getAllOpenCommentThreads(reportFilters); } - getCountForTaskCardType(taskTypeType) { + getCountForTaskCardType(taskTypeType, reportFilters) { return { - primaryValue: this.getResultForTaskCardType(taskTypeType).length, + primaryValue: this.getResultForTaskCardType(taskTypeType, reportFilters).length, secondaryValue: null, clickable: true }; } - getResultForTaskCardType(taskTypeType) { - return this.getService(TaskService).getIncompleteTasks(taskTypeType); + getResultForTaskCardType(taskTypeType, filters) { + return this.getService(TaskService).getIncompleteTasks(taskTypeType, filters); } getResultForDefaultCardsType(type, reportFilters) { @@ -127,9 +127,8 @@ class ReportCardService extends BaseService { return {status: null, result: this.getResultForApprovalCardsType(standardReportCardType, reportFilters)}; case standardReportCardType.isDefaultType() : return this.getResultForDefaultCardsType(standardReportCardType.name, reportFilters); - case standardReportCardType.isCommentType() : { + case standardReportCardType.isCommentType() : return {status: null, result: this.getResultForCommentCardType(reportFilters)}; - } case standardReportCardType.isChecklistType() : return this.getResultForChecklistCardType(standardReportCardType.name, reportFilters); } diff --git a/packages/openchs-android/src/service/query/RealmQueryService.js b/packages/openchs-android/src/service/query/RealmQueryService.js index b86777241..8e105a260 100644 --- a/packages/openchs-android/src/service/query/RealmQueryService.js +++ b/packages/openchs-android/src/service/query/RealmQueryService.js @@ -1,4 +1,4 @@ -import {ChecklistItem, Encounter, Individual, ProgramEncounter, ProgramEnrolment, Comment} from "openchs-models"; +import {ChecklistItem, Encounter, Individual, ProgramEncounter, ProgramEnrolment, Comment, Task} from "openchs-models"; import _ from "lodash"; import AddressLevel from "../../views/common/AddressLevel"; @@ -9,6 +9,7 @@ locationBasedQueries.set(ProgramEncounter.schema.name, "programEnrolment.individ locationBasedQueries.set(Encounter.schema.name, "individual.lowestAddressLevel.uuid = "); locationBasedQueries.set(ChecklistItem.schema.name, "checklist.programEnrolment.individual.lowestAddressLevel.uuid = "); locationBasedQueries.set(Comment.schema.name, "subject.lowestAddressLevel.uuid = "); +locationBasedQueries.set(Task.schema.name, "subject.lowestAddressLevel.uuid = "); class RealmQueryService { static orQuery(array) { diff --git a/packages/openchs-android/src/service/task/TaskService.js b/packages/openchs-android/src/service/task/TaskService.js index bfcc7efdf..1bc77f7c1 100644 --- a/packages/openchs-android/src/service/task/TaskService.js +++ b/packages/openchs-android/src/service/task/TaskService.js @@ -1,10 +1,11 @@ import BaseService from "../BaseService"; import Service from "../../framework/bean/Service"; import {EntityQueue, ObservationsHolder, Task} from 'openchs-models'; -import General from "../../utility/General"; import _ from 'lodash'; import TaskFilter from "../../model/TaskFilter"; import moment from 'moment'; +import {DashboardReportFilter} from "../../model/DashboardReportFilters"; +import RealmQueryService from "../query/RealmQueryService"; const getIncompleteTasks = function(taskService, taskTypeName) { return taskService.getAllNonVoided() @@ -21,8 +22,10 @@ class TaskService extends BaseService { return Task.schema.name; } - getIncompleteTasks(taskTypeName) { - return getIncompleteTasks(this, taskTypeName).sorted('scheduledOn', true); + getIncompleteTasks(taskTypeName, filters) { + const addressFilter = DashboardReportFilter.getAddressFilter(filters); + let entities = RealmQueryService.filterBasedOnAddress(Task.schema.name, getIncompleteTasks(this, taskTypeName), addressFilter); + return entities.sorted('scheduledOn', true); } getFilteredTasks(taskFilter: TaskFilter) { diff --git a/packages/openchs-android/test/model/TestTaskFactory.js b/packages/openchs-android/test/model/TestTaskFactory.js index ee3c2dad9..b88359836 100644 --- a/packages/openchs-android/test/model/TestTaskFactory.js +++ b/packages/openchs-android/test/model/TestTaskFactory.js @@ -1,10 +1,16 @@ import {Task} from 'openchs-models'; +import General from "../../src/utility/General"; class TestTaskFactory { - static create({uuid, metadata}) { + static create({uuid = General.randomUUID(), metadata = [], name = General.randomUUID(), taskType, taskStatus, scheduledOn = new Date(), subject} = {}) { let task = new Task(); task.uuid = uuid; + task.name = name; task.metadata = metadata; + task.taskType = taskType; + task.taskStatus = taskStatus; + task.scheduledOn = scheduledOn; + task.subject = subject; return task; } } diff --git a/packages/openchs-android/test/model/TestTaskStatusFactory.js b/packages/openchs-android/test/model/TestTaskStatusFactory.js index d4c1bfcc0..1f4f54bf3 100644 --- a/packages/openchs-android/test/model/TestTaskStatusFactory.js +++ b/packages/openchs-android/test/model/TestTaskStatusFactory.js @@ -1,10 +1,12 @@ -import _ from "lodash"; import {TaskStatus} from 'openchs-models'; +import General from "../../src/utility/General"; class TestTaskStatusFactory { - static create({uuid} = {}) { + static create({uuid = General.randomUUID(), name = General.randomUUID(), taskType} = {}) { const taskStatus = new TaskStatus(); taskStatus.uuid = uuid; + taskStatus.name = name; + taskStatus.taskType = taskType; return taskStatus; } } diff --git a/packages/openchs-android/test/model/TestTaskTypeFactory.js b/packages/openchs-android/test/model/TestTaskTypeFactory.js index 78a17a2bb..c1d0ec934 100644 --- a/packages/openchs-android/test/model/TestTaskTypeFactory.js +++ b/packages/openchs-android/test/model/TestTaskTypeFactory.js @@ -1,9 +1,12 @@ -import _ from "lodash"; import {TaskType} from 'openchs-models'; +import General from "../../src/utility/General"; class TestTaskTypeFactory { - static create({metadataSearchFields} = {metadataSearchFields: []}) { + static create({metadataSearchFields = [], name = General.randomUUID(), uuid = General.randomUUID(), type = TaskType.TaskTypeName.Call} = {}) { const taskType = new TaskType(); + taskType.uuid = uuid; + taskType.name = name; + taskType.type = type; taskType.metadataSearchFields = metadataSearchFields; return taskType; }