Skip to content

Commit

Permalink
#1216 - filter tasks based on locations
Browse files Browse the repository at this point in the history
  • Loading branch information
petmongrels committed Dec 20, 2023
1 parent 9720608 commit 7558574
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 18 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import BaseIntegrationTest from "./BaseIntegrationTest";
import {
Comment,
CommentThread,
Concept,
CustomFilter,
Expand All @@ -10,7 +11,9 @@ import {
ProgramEnrolment,
ReportCard,
StandardReportCardType,
Comment, TaskType, Task, TaskStatus
Task,
TaskStatus,
TaskType
} from "openchs-models";
import TestSubjectFactory from "../test/model/txn/TestSubjectFactory";
import TestObsFactory from "../test/model/TestObsFactory";
Expand All @@ -34,6 +37,8 @@ import TestCommentThreadFactory from "../test/model/comment/TestCommentThreadFac
import TestTaskTypeFactory from "../test/model/TestTaskTypeFactory";
import TestTaskFactory from "../test/model/TestTaskFactory";
import TestTaskStatusFactory from "../test/model/TestTaskStatusFactory";
import TaskService from "../src/service/task/TaskService";
import TaskFilter from "../src/model/TaskFilter";

function getCount(test, card, reportFilters) {
let reportCardCount = test.reportCardService.getReportCardCount(card, reportFilters);
Expand Down Expand Up @@ -227,17 +232,31 @@ class ReportCardServiceIntegrationTest extends BaseIntegrationTest {
}

getCountForTaskCardType() {
let taskTypeCard;
let callTaskTypeCard, openSubjectTaskTypeCard;
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}));
const callTaskCardType = db.create(StandardReportCardType, TestStandardReportCardTypeFactory.create({name: StandardReportCardType.type.CallTasks}));
const openSubjectTaskCardType = db.create(StandardReportCardType, TestStandardReportCardTypeFactory.create({name: StandardReportCardType.type.OpenSubjectTasks}));
callTaskTypeCard = db.create(ReportCard, TestReportCardFactory.create({name: "callTaskTypeCard", standardReportCardType: callTaskCardType}));
openSubjectTaskTypeCard = db.create(ReportCard, TestReportCardFactory.create({name: "callTaskTypeCard", standardReportCardType: openSubjectTaskCardType}));
const callTaskType = db.create(TaskType, TestTaskTypeFactory.create({type: TaskType.TaskTypeName.Call}));
const openSubjectTaskType = db.create(TaskType, TestTaskTypeFactory.create({type: TaskType.TaskTypeName.OpenSubject}));
const callTaskStatus = db.create(TaskStatus, TestTaskStatusFactory.create({taskType: callTaskType}));
const openSubjectTaskStatus = db.create(TaskStatus, TestTaskStatusFactory.create({taskType: openSubjectTaskType}));
db.create(Task, TestTaskFactory.create({taskType: callTaskType, taskStatus: callTaskStatus, subject: this.subject1}));
db.create(Task, TestTaskFactory.create({taskType: openSubjectTaskType, taskStatus: openSubjectTaskStatus, 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]));
assert.equal(1, getCount(this, callTaskTypeCard, []));
assert.equal(1, getCount(this, callTaskTypeCard, [this.addressSelected]));
assert.equal(0, getCount(this, callTaskTypeCard, [this.address2Selected]));
assert.equal(1, getCount(this, openSubjectTaskTypeCard, []));
assert.equal(1, getCount(this, openSubjectTaskTypeCard, [this.addressSelected]));
assert.equal(0, getCount(this, openSubjectTaskTypeCard, [this.address2Selected]));

const taskService = this.getService(TaskService);
const taskFilter = TaskFilter.createNoCriteriaFilter(TaskType.TaskTypeName.Call);
assert.equal(1, taskService.getFilteredTasks(taskFilter, []).length);
assert.equal(1, taskService.getFilteredTasks(taskFilter, [this.addressSelected]).length);
assert.equal(0, taskService.getFilteredTasks(taskFilter, [this.address2Selected]).length);
}

getResultForApprovalCardsType() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class CustomDashboardActions {
const newState = {...state};
const reportCard = context.get(EntityService).findByUUID(action.reportCardUUID, ReportCard.schema.name);
if (reportCard.isStandardTaskType()) {
action.goToTaskLists(reportCard.standardReportCardType.getTaskTypeType());
action.goToTaskLists(reportCard.standardReportCardType.getTaskTypeType(), state.ruleInput.ruleInputArray);
} else {
const {result, status} = context.get(ReportCardService).getReportCardResult(reportCard, state.ruleInput.ruleInputArray);
const standardReportCardType = reportCard.standardReportCardType;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class TaskListActions {
const taskTypes = taskTypeService.findAllByTaskType(action.filter.taskType.type);
newState.filter.taskType = taskTypes[0];

newState.results = taskService.getFilteredTasks(newState.filter);
newState.results = taskService.getFilteredTasks(newState.filter, action.reportFilters);
return newState;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export class DashboardReportFilter {
filterValue;

static getAddressFilter(reportFilters) {
if (_.isNil(reportFilters)) return null;
return _.find(reportFilters, (x: DashboardReportFilter) => x.type === CustomFilter.type.Address);
}
}
Expand Down
5 changes: 3 additions & 2 deletions packages/openchs-android/src/service/task/TaskService.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@ class TaskService extends BaseService {
return entities.sorted('scheduledOn', true);
}

getFilteredTasks(taskFilter: TaskFilter) {
let tasks = getIncompleteTasks(this, taskFilter.taskType.type);
getFilteredTasks(taskFilter: TaskFilter, reportFilters) {
const addressFilter = DashboardReportFilter.getAddressFilter(reportFilters);
let tasks = RealmQueryService.filterBasedOnAddress(Task.schema.name, getIncompleteTasks(this, taskFilter.taskType.type), addressFilter);
if (taskFilter.taskStatuses.length > 0)
tasks = tasks.filtered(BaseService.orFilterCriteria(taskFilter.taskStatuses, "taskStatus.uuid"));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,11 +169,12 @@ class CustomDashboardView extends AbstractComponent {
this.dispatchAction(Actions.LOAD_INDICATOR, {loading: true});
return setTimeout(() => this.dispatchAction(Actions.ON_CARD_PRESS, {
reportCardUUID,
goToTaskLists: (taskTypeType) => {
goToTaskLists: (taskTypeType, reportFilters) => {
TypedTransition.from(this).with({
taskTypeType: taskTypeType,
backFunction: this.onBackPress.bind(this),
indicatorActionName: Actions.LOAD_INDICATOR
indicatorActionName: Actions.LOAD_INDICATOR,
reportFilters: reportFilters
}).to(TaskListView);
},
onApprovalItemsResults: (results, status, viewName, approvalStatus_status, reportFilters) => TypedTransition.from(this).with({
Expand Down
5 changes: 3 additions & 2 deletions packages/openchs-android/src/views/task/TaskListView.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ class TaskListView extends AbstractComponent {
static paramTypes = {
backFunction: PropTypes.func,
taskTypeType: PropTypes.string.isRequired,
indicatorActionName: PropTypes.string
indicatorActionName: PropTypes.string,
reportFilters: PropTypes.object
};

constructor(props, context) {
Expand All @@ -79,7 +80,7 @@ class TaskListView extends AbstractComponent {
UNSAFE_componentWillMount() {
setTimeout(() => {
super.UNSAFE_componentWillMount();
this.dispatchAction(Actions.ON_LOAD, {filter: TaskFilter.createNoCriteriaFilter(this.props.params.taskTypeType)});
this.dispatchAction(Actions.ON_LOAD, {filter: TaskFilter.createNoCriteriaFilter(this.props.params.taskTypeType), reportFilters: this.props.params.reportFilters});
this.dispatchAction(this.props.params.indicatorActionName, {loading: false});
}, 0);
}
Expand Down

0 comments on commit 7558574

Please sign in to comment.