Skip to content

Commit

Permalink
#1216 - get count based on location for task type card
Browse files Browse the repository at this point in the history
  • Loading branch information
petmongrels committed Dec 20, 2023
1 parent 1ab9422 commit 9720608
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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);
Expand Down Expand Up @@ -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]));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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";

Expand All @@ -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) {
Expand Down
9 changes: 6 additions & 3 deletions packages/openchs-android/src/service/task/TaskService.js
Original file line number Diff line number Diff line change
@@ -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()
Expand All @@ -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) {
Expand Down
8 changes: 7 additions & 1 deletion packages/openchs-android/test/model/TestTaskFactory.js
Original file line number Diff line number Diff line change
@@ -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;
}
}
Expand Down
6 changes: 4 additions & 2 deletions packages/openchs-android/test/model/TestTaskStatusFactory.js
Original file line number Diff line number Diff line change
@@ -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;
}
}
Expand Down
7 changes: 5 additions & 2 deletions packages/openchs-android/test/model/TestTaskTypeFactory.js
Original file line number Diff line number Diff line change
@@ -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;
}
Expand Down

0 comments on commit 9720608

Please sign in to comment.