def get_rows(self, datespan): def get_awc_filter(awcs): return get_nested_terms_filter("awc_name.#value", awcs) def get_gp_filter(gp): owner_ids = [user._id for user in self.users if getattr(user, 'user_data', {}).get('gp') in self.gp] return es_filters.term("owner_id", owner_ids) def get_block_filter(block): return es_filters.term("block_name.#value", block.lower()) query = case_es.CaseES().domain(self.domain)\ .fields([])\ .opened_range(lte=self.datespan.enddate_utc)\ .term("type.exact", self.default_case_type) query.index = 'report_cases' if self.display_open_cases_only: query = query.filter(es_filters.OR( case_es.is_closed(False), case_es.closed_range(gte=self.datespan.enddate_utc) )) elif self.display_closed_cases_only: query = query.filter(case_es.closed_range(lte=self.datespan.enddate_utc)) if self.awcs: query = query.filter(get_awc_filter(self.awcs)) elif self.gp: query = query.filter(get_gp_filter(self.gp)) elif self.block: query = query.filter(get_block_filter(self.block)) result = query.run() return map(CommCareCase, iter_docs(CommCareCase.get_db(), result.ids))
def cases(self): if 'debug_case' in self.request.GET: case = CommCareCase.get(self.request.GET['debug_case']) if case.domain != DOMAIN: raise Http404() return [case] query = case_es.CaseES().domain(self.domain)\ .fields([])\ .opened_range(lte=self.datespan.enddate_utc)\ .case_type(self.default_case_type) query.index = 'report_cases' if self.case_status == 'open': query = query.filter(es_filters.OR( case_es.is_closed(False), case_es.closed_range(gte=self.datespan.enddate_utc) )) elif self.case_status == 'closed': query = query.filter(case_es.closed_range(lte=self.datespan.enddate_utc)) query = query.owner([user['doc_id'] for user in self.users_matching_filter]) result = query.run() return [ CommCareCase.wrap(doc) for doc in iter_docs(CommCareCase.get_db(), result.ids) ]
def get_rows(self): query = case_es.CaseES().domain(self.domain)\ .fields([])\ .opened_range(lte=self.datespan.enddate_utc)\ .case_type(self.default_case_type) query.index = 'report_cases' if self.case_status == 'open': query = query.filter(es_filters.OR( case_es.is_closed(False), case_es.closed_range(gte=self.datespan.enddate_utc) )) elif self.case_status == 'closed': query = query.filter(case_es.closed_range(lte=self.datespan.enddate_utc)) query = query.owner([user['doc_id'] for user in self.users_matching_filter]) result = query.run() return [ CommCareCase.wrap(doc) for doc in iter_docs(CommCareCase.get_db(), result.ids) ]
def get_rows(self, datespan): def get_awc_filter(awcs): return get_nested_terms_filter("awc_name.#value", awcs) def get_gp_filter(gp): owner_ids = [ user._id for user in self.users if getattr(user, 'user_data', {}).get('gp') in self.gp ] return es_filters.term("owner_id", owner_ids) def get_block_filter(block): return es_filters.term("block_name.#value", block.lower()) query = case_es.CaseES().domain(self.domain)\ .fields([])\ .opened_range(lte=self.datespan.enddate_utc)\ .term("type.exact", self.default_case_type) query.index = 'report_cases' if self.display_open_cases_only: query = query.filter( es_filters.OR( case_es.is_closed(False), case_es.closed_range(gte=self.datespan.enddate_utc))) elif self.display_closed_cases_only: query = query.filter( case_es.closed_range(lte=self.datespan.enddate_utc)) if self.awcs: query = query.filter(get_awc_filter(self.awcs)) elif self.gp: query = query.filter(get_gp_filter(self.gp)) elif self.block: query = query.filter(get_block_filter(self.block)) result = query.run() return map(CommCareCase, iter_docs(CommCareCase.get_db(), result.ids))