From 952a16064560a2304688418107406345dd279f71 Mon Sep 17 00:00:00 2001 From: Vivek Singh Date: Fri, 20 Sep 2024 17:29:40 +0530 Subject: [PATCH 1/3] #1382 - fixed intersection logic --- .../src/service/CustomFilterService.js | 9 +++++++- .../openchs-android/test/DateSpikeTest.js | 21 +++++++++++++++++++ .../TestStandardReportCardTypeFactory.js | 1 + 3 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 packages/openchs-android/test/DateSpikeTest.js diff --git a/packages/openchs-android/src/service/CustomFilterService.js b/packages/openchs-android/src/service/CustomFilterService.js index 2f3010128..bfb46a111 100644 --- a/packages/openchs-android/src/service/CustomFilterService.js +++ b/packages/openchs-android/src/service/CustomFilterService.js @@ -363,12 +363,19 @@ class CustomFilterService extends BaseService { } applyCustomFilters(customFilters, filterName, includeVoided = false) { + General.logDebugTemp("CustomFilterService", "Applying custom filters"); let uniqueSubjectUUIDs = []; _.forEach(this.getSettings()[filterName], filter => { const selectedOptions = customFilters[filter.titleKey]; const {scopeParameters, scope, conceptUUID, type, widget} = filter; const selectedAnswerFilterQueryFunction = this.getFilterQueryByTypeFunction(filter, selectedOptions); - uniqueSubjectUUIDs = _.intersection(uniqueSubjectUUIDs, this.getSubjects(conceptUUID, selectedOptions, type, scope, scopeParameters, widget, selectedAnswerFilterQueryFunction, includeVoided)); + const subjects = this.getSubjects(conceptUUID, selectedOptions, type, scope, scopeParameters, widget, selectedAnswerFilterQueryFunction, includeVoided); + const filterHasValue = !_.isEmpty(selectedOptions) && !_.isNil(selectedOptions) + if (!filterHasValue || _.isEmpty(uniqueSubjectUUIDs)) { + uniqueSubjectUUIDs = subjects; + } else { + uniqueSubjectUUIDs = _.intersection(uniqueSubjectUUIDs, subjects); + } }); return uniqueSubjectUUIDs; } diff --git a/packages/openchs-android/test/DateSpikeTest.js b/packages/openchs-android/test/DateSpikeTest.js new file mode 100644 index 000000000..2858a88bc --- /dev/null +++ b/packages/openchs-android/test/DateSpikeTest.js @@ -0,0 +1,21 @@ +import moment from 'moment'; + +const scheduledOrCompletedEncountersOfType = function (nextVisitDate) { + const nextDateMonth = moment(nextVisitDate).month(); + const nextDateYear = moment(nextVisitDate).year(); + + const data = [{earliestVisitDateTime: new Date("2024-06-30T18:30:00.000Z")}].filter((enc) => + moment(enc.earliestVisitDateTime).year() === nextDateYear && + moment(enc.earliestVisitDateTime).month() === nextDateMonth + ); + return data; +}; + +it('should ', function () { + const date = new Date("2024-06-30T18:30:00.000Z"); + // console.log(moment(date).month()); + // console.log(scheduledOrCompletedEncountersOfType(date)); + let date2 = moment(date).add(1, 'M').startOf('month').toDate(); + console.log(date2); + // console.log("to server", JSON.stringify(date2)); +}); diff --git a/packages/openchs-android/test/model/reportNDashboard/TestStandardReportCardTypeFactory.js b/packages/openchs-android/test/model/reportNDashboard/TestStandardReportCardTypeFactory.js index b49b19e30..b9f212a7c 100644 --- a/packages/openchs-android/test/model/reportNDashboard/TestStandardReportCardTypeFactory.js +++ b/packages/openchs-android/test/model/reportNDashboard/TestStandardReportCardTypeFactory.js @@ -6,6 +6,7 @@ class TestStandardReportCardTypeFactory { const standardReportCardType = new StandardReportCardType(); standardReportCardType.uuid = uuid; standardReportCardType.name = name; + standardReportCardType.type = name; return standardReportCardType; } } From 97932a15065e40330f4c6af746b5e3707a960641 Mon Sep 17 00:00:00 2001 From: Joy A Date: Mon, 23 Sep 2024 10:32:26 +0530 Subject: [PATCH 2/3] #1512 | Fix crash on enabling/disabling dashboard auto-refresh --- .../src/action/customDashboard/CustomDashboardActions.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/openchs-android/src/action/customDashboard/CustomDashboardActions.js b/packages/openchs-android/src/action/customDashboard/CustomDashboardActions.js index 6329a4e68..56fd103d3 100644 --- a/packages/openchs-android/src/action/customDashboard/CustomDashboardActions.js +++ b/packages/openchs-android/src/action/customDashboard/CustomDashboardActions.js @@ -1,8 +1,8 @@ import _ from 'lodash'; -import CustomDashboardService, {CustomDashboardType} from "../../service/customDashboard/CustomDashboardService"; +import CustomDashboardService from "../../service/customDashboard/CustomDashboardService"; import DashboardSectionCardMappingService from "../../service/customDashboard/DashboardSectionCardMappingService"; import EntityService from "../../service/EntityService"; -import {ReportCard, NestedReportCardResult} from "openchs-models"; +import {ReportCard} from "openchs-models"; import ReportCardService from "../../service/customDashboard/ReportCardService"; import General from "../../utility/General"; import DashboardFilterService from "../../service/reports/DashboardFilterService"; @@ -133,7 +133,7 @@ class CustomDashboardActions { const newState = {...state}; - if (newState.dashboards.length === 0) { + if (_.isNil(newState.dashboards) || newState.dashboards.length === 0) { return newState; } From 58b4e8d7b08c88f74601b62771f9c35ef3e2d0df Mon Sep 17 00:00:00 2001 From: Vivek Singh Date: Mon, 23 Sep 2024 18:55:45 +0530 Subject: [PATCH 3/3] avniproject/avni-models#53 - used for timezone verification code --- .../openchs-android/test/DateSpikeTest.js | 37 ++++++++++++++----- 1 file changed, 28 insertions(+), 9 deletions(-) diff --git a/packages/openchs-android/test/DateSpikeTest.js b/packages/openchs-android/test/DateSpikeTest.js index 2858a88bc..28437c494 100644 --- a/packages/openchs-android/test/DateSpikeTest.js +++ b/packages/openchs-android/test/DateSpikeTest.js @@ -4,18 +4,37 @@ const scheduledOrCompletedEncountersOfType = function (nextVisitDate) { const nextDateMonth = moment(nextVisitDate).month(); const nextDateYear = moment(nextVisitDate).year(); - const data = [{earliestVisitDateTime: new Date("2024-06-30T18:30:00.000Z")}].filter((enc) => + return [ + {earliestVisitDateTime: new Date("2024-06-30T18:30:00.000Z")}, + {earliestVisitDateTime: new Date("2024-07-31T18:30:00.000Z")}, + {earliestVisitDateTime: new Date("2024-08-31T18:30:00.000Z")}, + ].filter((enc) => moment(enc.earliestVisitDateTime).year() === nextDateYear && moment(enc.earliestVisitDateTime).month() === nextDateMonth ); - return data; }; -it('should ', function () { - const date = new Date("2024-06-30T18:30:00.000Z"); - // console.log(moment(date).month()); - // console.log(scheduledOrCompletedEncountersOfType(date)); - let date2 = moment(date).add(1, 'M').startOf('month').toDate(); - console.log(date2); - // console.log("to server", JSON.stringify(date2)); +xit('should ', function () { + // console.log("nextDate", moment(new Date("2024-08-31T18:30:00.000Z")).add(1, 'M').startOf('month').toDate()); + // console.log("nextDate", moment(new Date("2024-08-21T18:30:00.000Z")).add(1, 'M').startOf('month').toDate()); + + // perform, should schedule next visit + let currentEncountersEarliestDate = new Date("2024-08-31T18:30:00.000Z"); + let nextDate = moment(currentEncountersEarliestDate).add(1, 'M').startOf('month').toDate(); + console.log("found visits", scheduledOrCompletedEncountersOfType(nextDate).length, "Next date", nextDate); + + currentEncountersEarliestDate = new Date("2024-08-31T18:30:00.000Z") || new Date("2024-09-05T10:30:00.000Z"); + nextDate = moment(currentEncountersEarliestDate).add(1, 'M').startOf('month').toDate(); + console.log("found visits", scheduledOrCompletedEncountersOfType(nextDate).length, "Next date", nextDate); + + currentEncountersEarliestDate = new Date("2024-07-31T18:30:00.000Z"); + nextDate = moment(currentEncountersEarliestDate).add(1, 'M').startOf('month').toDate(); + console.log("found visits", scheduledOrCompletedEncountersOfType(nextDate).length, "Next date", nextDate); + + console.log("Month", moment(new Date("2024-08-31T18:30:00.000Z")).format("MMMM")); + console.log("Month", moment(new Date()).month()); + + console.log("Month", moment(new Date("2024-01-20T18:30:00.000Z")).format("MMMM")); + + console.log("timezone", new Date().getTimezoneOffset()); });