Skip to content

Commit

Permalink
#1531 - do not run create query function when filter doesn't have value
Browse files Browse the repository at this point in the history
  • Loading branch information
petmongrels committed Oct 7, 2024
1 parent 02cdac6 commit 3b85469
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions packages/openchs-android/src/service/CustomFilterService.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import _ from "lodash";
import ConceptService from "./ConceptService";
import moment from "moment";
import RealmQueryService from "./query/RealmQueryService";
import {JSONStringify} from "../utility/JsonStringify";

function getDateFilterFunction(filterValue, widget, queryColumn) {
if (widget === CustomFilter.widget.Range) {
Expand Down Expand Up @@ -372,13 +373,14 @@ class CustomFilterService extends BaseService {
_.forEach(this.getSettings()[filterName], filter => {
const selectedOptions = customFilters[filter.titleKey];
const {scopeParameters, scope, conceptUUID, type, widget} = filter;
const selectedAnswerFilterQueryFunction = this.getFilterQueryByTypeFunction(filter, selectedOptions);
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);
if (filterHasValue) {
const selectedAnswerFilterQueryFunction = this.getFilterQueryByTypeFunction(filter, selectedOptions);
const subjects = this.getSubjects(conceptUUID, selectedOptions, type, scope, scopeParameters, widget, selectedAnswerFilterQueryFunction, includeVoided);
if (_.isEmpty(uniqueSubjectUUIDs))
uniqueSubjectUUIDs = subjects
else
uniqueSubjectUUIDs = _.intersection(uniqueSubjectUUIDs, subjects);
}
});
return uniqueSubjectUUIDs;
Expand Down

0 comments on commit 3b85469

Please sign in to comment.