def es_query(self, paginated): reviewed_form_ids = get_form_ids_by_status(self.domain, getattr(self, 'display_status', None)) if len(reviewed_form_ids) > 0: if not getattr(self, 'es_response', None): date_tuple = _get_date_range(self.request_params.get('range', None)) filtered_case_ids = self._get_filtered_cases(date_tuple[0], date_tuple[1]) location_ids = get_location_hierarchy_by_id( self.request_params.get("location_id", None), self.domain, self.request.couch_user, CCT_only=True ) q = _get_report_query(date_tuple[0], date_tuple[1], filtered_case_ids, location_ids) if len(reviewed_form_ids) > 0: q["filter"]["and"].append({"ids": {"values": reviewed_form_ids}}) q["sort"] = self.get_sorting_block() if self.get_sorting_block() else [{"form.meta.timeEnd" : {"order": "desc"}}] if paginated: self.es_response = es_query(params={"domain.exact": self.domain}, q=q, es_index='forms', start_at=self.pagination.start, size=self.pagination.count) else: self.es_response = es_query(params={"domain.exact": self.domain}, q=q, es_index='forms') else: self.es_response = {'hits': {'total': 0}} return self.es_response
def get_report_data(cls, config): validate_report_parameters(["domain", "location_id", "datespan"], config) domain = config["domain"] location_id = config["location_id"] user = config["user"] sql_data = ProjectIndicatorsCaseSqlData( domain=domain, datespan=config["datespan"]).data locations = get_location_hierarchy_by_id(location_id, domain, user, CCT_only=True) row_data = ProjectIndicatorsReport.get_initial_row_data() for key in sql_data: if key[2] not in locations: continue data = sql_data.get(key, {}) for row_key in row_data: value = data.get(row_key, 0) if value is None: value = 0 if row_key == "women_delivering_within_6_weeks_attending_pnc_total" and value > 1: value = 1 row_data.get(row_key, {})["value"] += value return sorted([(key, row_data[key]) for key in row_data], key=lambda t: t[1].get("s/n"))
def get_report_data(cls, config): validate_report_parameters(["domain", "location_id", "datespan"], config) domain = config["domain"] location_id = config["location_id"] datespan = config["datespan"] sql_data = [ AncHmisCaseSqlData(domain=domain, datespan=datespan).data, LdHmisCaseSqlData(domain=domain, datespan=datespan).data, ImmunizationHmisCaseSqlData(domain=domain, datespan=datespan).data, AllHmisCaseSqlData(domain=domain, datespan=datespan).data ] locations = get_location_hierarchy_by_id(location_id, domain) row_data = AllHmisReport.get_initial_row_data() for data in sql_data: for location_id in locations: key = (domain, location_id) if key in data: report_rows = _get_rows(row_data, data, key) for key in report_rows: row_data.get(key)["value"] += report_rows.get(key) return sorted([(key, row_data[key]) for key in row_data], key=lambda t: t[1].get("hmis_code"))
def es_query(self, paginated): if not getattr(self, 'es_response', None): date_tuple = _get_date_range(self.request_params.get('range', None)) filtered_case_ids = self._get_filtered_cases(date_tuple[0], date_tuple[1]) location_ids = get_location_hierarchy_by_id( self.request_params.get("location_id", None), self.domain, self.request.couch_user, CCT_only=True ) q = _get_report_query(date_tuple[0], date_tuple[1], filtered_case_ids, location_ids) xmlnss = _get_relevant_xmlnss_for_service_type(self.request.GET.get("service_type_filter")) if xmlnss: q["filter"]["and"].append({"terms": {"xmlns.exact": xmlnss}}) modify_close = [_f for _f in [u'Modify/Close Client'] if _f] q["filter"]["and"].append({"not": {"terms": {"form.@name": modify_close}}}) q["sort"] = self.get_sorting_block() \ if self.get_sorting_block() else [{"form.meta.timeEnd": {"order": "desc"}}] if paginated: self.es_response = es_query(params={"domain.exact": self.domain}, q=q, es_index='forms', start_at=self.pagination.start, size=self.pagination.count) else: self.es_response = es_query(params={"domain.exact": self.domain}, q=q, es_index='forms') return self.es_response
def get_report_data(cls, config): validate_report_parameters(["domain", "location_id", "datespan"], config) domain = config["domain"] location_id = config["location_id"] datespan = config["datespan"] user = config["user"] sql_data = McctMonthlyAggregateFormSqlData(domain=domain, datespan=datespan).data locations = get_location_hierarchy_by_id(location_id, domain, user, CCT_only=True) row_data = McctMonthlyAggregateReport.get_initial_row_data() for location_id in locations: key = (domain, location_id) if key in sql_data: report_rows = _get_rows(row_data, sql_data, key) for key in report_rows: row_data.get(key)["value"] += report_rows.get(key) _add_eligible_9months(row_data, datespan.startdate_utc, datespan.enddate_utc, domain) return sorted([(key, row_data[key]) for key in row_data], key=lambda t: t[1].get("s/n"))
def es_query(self, paginated): if not getattr(self, 'es_response', None): date_tuple = _get_date_range(self.request_params.get('range', None)) filtered_case_ids = self._get_filtered_cases(date_tuple[0], date_tuple[1]) location_ids = get_location_hierarchy_by_id( self.request_params.get("location_id", None), self.domain, self.request.couch_user, CCT_only=True ) q = _get_report_query(date_tuple[0], date_tuple[1], filtered_case_ids, location_ids) xmlnss = _get_relevant_xmlnss_for_service_type(self.request.GET.get("service_type_filter")) if xmlnss: q["filter"]["and"].append({"terms": {"xmlns.exact": xmlnss}}) modify_close = [_f for _f in ['Modify/Close Client'] if _f] q["filter"]["and"].append({"not": {"terms": {"form.@name": modify_close}}}) q["sort"] = self.get_sorting_block() \ if self.get_sorting_block() else [{"form.meta.timeEnd": {"order": "desc"}}] if paginated: self.es_response = es_query(params={"domain.exact": self.domain}, q=q, es_index='forms', start_at=self.pagination.start, size=self.pagination.count) else: self.es_response = es_query(params={"domain.exact": self.domain}, q=q, es_index='forms') return self.es_response
def test_no_location_restricted(self): self.web_user.add_to_assigned_locations(self.domain, self.locations['Middlesex']) self.restrict_user_to_assigned_locations(self.web_user) self.assertEqual( len(get_location_hierarchy_by_id(None, self.domain, self.web_user)), 3)
def test_with_location_restricted(self): self.web_user.add_to_assigned_locations(self.domain, self.locations['Middlesex']) self.restrict_user_to_assigned_locations(self.web_user) self.assertEqual( len( get_location_hierarchy_by_id( self.locations['Massachusetts'].location_id, self.domain, self.web_user ) ), 3 )
def get_report_data(cls, config): validate_report_parameters(["domain", "location_id", "datespan"], config) domain = config["domain"] location_id = config["location_id"] sql_data = ImmunizationHmisCaseSqlData(domain=domain, datespan=config["datespan"]).data locations = get_location_hierarchy_by_id(location_id, domain) row_data = ImmunizationHmisReport.get_initial_row_data() for location_id in locations: key = (domain, location_id) if key in sql_data: report_rows = _get_row(row_data, sql_data, key) for key in report_rows: row_data.get(key)["value"] += report_rows.get(key) return sorted([(key, row_data[key]) for key in row_data], key=lambda t: t[1].get("hmis_code"))
def es_query(self, paginated): if not getattr(self, 'es_response', None): range = self.request_params.get('range', None) start_date = None end_date = None if range is not None: dates = str(range).split(_(" to ")) start_date = dates[0] end_date = dates[1] filtered_case_ids = self._get_filtered_cases(start_date, end_date) exclude_form_ids = [ mcct_status.form_id for mcct_status in McctStatus.objects.filter( domain=self.domain, received_on__range=(start_date, end_date) ) if (mcct_status.status != "eligible" or ( not mcct_status.immunized and (date.today() - mcct_status.registration_date).days < 272 and not mcct_status.is_booking and not mcct_status.is_stillbirth)) ] location_ids = get_location_hierarchy_by_id( self.request_params.get("location_id", None), self.domain, self.request.couch_user, CCT_only=True ) q = _get_report_query(start_date, end_date, filtered_case_ids, location_ids) if len(exclude_form_ids) > 0: q["filter"]["and"].append({"not": {"ids": {"values": exclude_form_ids}}}) xmlnss = _get_relevant_xmlnss_for_service_type(self.request.GET.get("service_type_filter")) if xmlnss: q["filter"]["and"].append({"terms": {"xmlns.exact": xmlnss}}) modify_close = [_f for _f in ['Modify/Close Client'] if _f] q["filter"]["and"].append({"not": {"terms": {"form.@name": modify_close}}}) q["sort"] = self.get_sorting_block() \ if self.get_sorting_block() else [{"form.meta.timeEnd" : {"order": "desc"}}] if paginated: self.es_response = es_query(params={"domain.exact": self.domain}, q=q, es_index='forms', start_at=self.pagination.start, size=self.pagination.count) else: self.es_response = es_query(params={"domain.exact": self.domain}, q=q, es_index='forms') return self.es_response
def es_query(self, paginated): if not getattr(self, 'es_response', None): range = self.request_params.get('range', None) start_date = None end_date = None if range is not None: dates = str(range).split(_(" to ")) start_date = dates[0] end_date = dates[1] filtered_case_ids = self._get_filtered_cases(start_date, end_date) exclude_form_ids = [ mcct_status.form_id for mcct_status in McctStatus.objects.filter( domain=self.domain, received_on__range=(start_date, end_date) ) if (mcct_status.status != "eligible" or ( not mcct_status.immunized and (date.today() - mcct_status.registration_date).days < 272 and not mcct_status.is_booking and not mcct_status.is_stillbirth)) ] location_ids = get_location_hierarchy_by_id( self.request_params.get("location_id", None), self.domain, self.request.couch_user, CCT_only=True ) q = _get_report_query(start_date, end_date, filtered_case_ids, location_ids) if len(exclude_form_ids) > 0: q["filter"]["and"].append({"not": {"ids": {"values": exclude_form_ids}}}) xmlnss = _get_relevant_xmlnss_for_service_type(self.request.GET.get("service_type_filter")) if xmlnss: q["filter"]["and"].append({"terms": {"xmlns.exact": xmlnss}}) modify_close = [_f for _f in [u'Modify/Close Client'] if _f] q["filter"]["and"].append({"not": {"terms": {"form.@name": modify_close}}}) q["sort"] = self.get_sorting_block() \ if self.get_sorting_block() else [{"form.meta.timeEnd" : {"order": "desc"}}] if paginated: self.es_response = es_query(params={"domain.exact": self.domain}, q=q, es_index='forms', start_at=self.pagination.start, size=self.pagination.count) else: self.es_response = es_query(params={"domain.exact": self.domain}, q=q, es_index='forms') return self.es_response
def get_report_data(cls, config): validate_report_parameters(["domain", "location_id", "datespan"], config) domain = config["domain"] location_id = config["location_id"] datespan = config["datespan"] sql_data = McctMonthlyAggregateFormSqlData(domain=domain, datespan=datespan).data locations = get_location_hierarchy_by_id(location_id, domain, CCT_only=True) row_data = McctMonthlyAggregateReport.get_initial_row_data() for location_id in locations: key = (domain, location_id) if key in sql_data: report_rows = _get_rows(row_data, sql_data, key) for key in report_rows: row_data.get(key)["value"] += report_rows.get(key) _add_eligible_9months(row_data, datespan.startdate_utc, datespan.enddate_utc, domain) return sorted([(key, row_data[key]) for key in row_data], key=lambda t: t[1].get("s/n"))
def get_report_data(cls, config): validate_report_parameters(["domain", "location_id", "datespan"], config) domain = config["domain"] location_id = config["location_id"] sql_data = ProjectIndicatorsCaseSqlData(domain=domain, datespan=config["datespan"]).data locations = get_location_hierarchy_by_id(location_id, domain, CCT_only=True) row_data = ProjectIndicatorsReport.get_initial_row_data() for key in sql_data: if key[2] not in locations: continue data = sql_data.get(key, {}) for row_key in row_data: value = data.get(row_key, 0) if value is None: value = 0 if row_key == "women_delivering_within_6_weeks_attending_pnc_total" and value > 1: value = 1 row_data.get(row_key, {})["value"] += value return sorted([(key, row_data[key]) for key in row_data], key=lambda t: t[1].get("s/n"))
def test_with_location(self): self.assertEqual( len(get_location_hierarchy_by_id(self.locations['Middlesex'].location_id, self.domain, self.web_user)), 3 )
def test_no_location(self): self.assertEqual( len(get_location_hierarchy_by_id(None, self.domain, self.web_user)), 8)
def test_with_location(self): self.assertEqual( len( get_location_hierarchy_by_id( self.locations['Middlesex'].location_id, self.domain, self.web_user)), 3)
def test_no_location(self): self.assertEqual(len(get_location_hierarchy_by_id(None, self.domain, self.web_user)), 8)