def send_ror_reminder(domain, date, loc_type='FACILITY', test_list=None): if loc_type == 'FACILITY': status_type = SupplyPointStatusTypes.R_AND_R_FACILITY sms_text = REMINDER_R_AND_R_FACILITY elif loc_type == 'DISTRICT': status_type = SupplyPointStatusTypes.R_AND_R_DISTRICT sms_text = REMINDER_R_AND_R_DISTRICT else: return current_group = DeliveryGroups().current_submitting_group(date.month) sp_ids = set() users = CommCareUser.by_domain(domain) if not test_list else test_list for user in users: location = user.location if user.is_active and location and location.location_type == loc_type: status_exists = SupplyPointStatus.objects.filter( location_id=location._id, status_type=status_type, status_date__gte=date ).exists() if current_group in location.metadata.get('group', None) and not status_exists: result = send_translated_message(user, sms_text) if not test_list and result: sp_ids.add(location._id) update_statuses(sp_ids, status_type, SupplyPointStatusValues.REMINDER_SENT)
def test_reminder_set(self): now = datetime.utcnow() people = list(RandrReminder(TEST_DOMAIN, datetime.utcnow()).get_people()) self.assertEqual(len(people), 1) self.assertEqual(people[0].get_id, self.user1.get_id) self.facility.metadata['group'] = DeliveryGroups().current_delivering_group() self.facility.save() people = list(SupervisionReminder(TEST_DOMAIN, datetime.utcnow()).get_people()) self.assertEqual(len(people), 1) update_statuses( [self.facility.get_id], SupplyPointStatusTypes.SUPERVISION_FACILITY, SupplyPointStatusValues.REMINDER_SENT ) people = list(SupervisionReminder(TEST_DOMAIN, now).get_people()) self.assertEqual(len(people), 0) SupplyPointStatus.objects.all().delete() people = list(SupervisionReminder(TEST_DOMAIN, now).get_people()) self.assertEqual(len(people), 1) SupplyPointStatus.objects.create( status_type=SupplyPointStatusTypes.SUPERVISION_FACILITY, status_value=SupplyPointStatusValues.RECEIVED, location_id=self.facility.get_id ) people = list(SupervisionReminder(TEST_DOMAIN, now).get_people()) self.assertEqual(len(people), 0)
def send_ror_reminder(domain, date, loc_type='FACILITY', test_list=None): if loc_type == 'FACILITY': status_type = SupplyPointStatusTypes.R_AND_R_FACILITY sms_text = REMINDER_R_AND_R_FACILITY elif loc_type == 'DISTRICT': status_type = SupplyPointStatusTypes.R_AND_R_DISTRICT sms_text = REMINDER_R_AND_R_DISTRICT else: return current_group = DeliveryGroups().current_submitting_group(date.month) sp_ids = set() users = CommCareUser.by_domain(domain) if not test_list else test_list for user in users: location = user.location if user.is_active and location and location.location_type == loc_type: status_exists = SupplyPointStatus.objects.filter( location_id=location._id, status_type=status_type, status_date__gte=date).exists() if current_group in location.metadata.get( 'group', None) and not status_exists: result = send_translated_message(user, sms_text) if not test_list and result: sp_ids.add(location._id) update_statuses(sp_ids, status_type, SupplyPointStatusValues.REMINDER_SENT)
def test_reminder_set(self): now = datetime.utcnow() people = list( RandrReminder(TEST_DOMAIN, datetime.utcnow()).get_people()) self.assertEqual(len(people), 1) self.assertEqual(people[0].get_id, self.user1.get_id) self.facility.metadata['group'] = DeliveryGroups( ).current_delivering_group() self.facility.save() people = list( SupervisionReminder(TEST_DOMAIN, datetime.utcnow()).get_people()) self.assertEqual(len(people), 1) update_statuses([self.facility.get_id], SupplyPointStatusTypes.SUPERVISION_FACILITY, SupplyPointStatusValues.REMINDER_SENT) people = list(SupervisionReminder(TEST_DOMAIN, now).get_people()) self.assertEqual(len(people), 0) SupplyPointStatus.objects.all().delete() people = list(SupervisionReminder(TEST_DOMAIN, now).get_people()) self.assertEqual(len(people), 1) SupplyPointStatus.objects.create( status_type=SupplyPointStatusTypes.SUPERVISION_FACILITY, status_value=SupplyPointStatusValues.RECEIVED, location_id=self.facility.get_id) people = list(SupervisionReminder(TEST_DOMAIN, now).get_people()) self.assertEqual(len(people), 0)
def send_soh_reminder(domain, date): sp_ids = set() for user in CommTrackUser.by_domain(domain): if user.is_active and user.location and user.location.location_type == 'FACILITY': sp = SupplyPointCase.get_by_location(user.location) if sp and not StockTransaction.objects.filter(case_id=sp._id, report__date__gte=date, type='stockonhand').exists(): if user.get_verified_number(): send_sms_to_verified_number(user.get_verified_number(), REMINDER_STOCKONHAND) sp_ids.add(sp._id) update_statuses(sp_ids, SupplyPointStatusTypes.SOH_FACILITY, SupplyPointStatusValues.REMINDER_SENT)
def send_soh_reminder(domain, date, test_list=None): sp_ids = set() users = CommCareUser.by_domain(domain) if not test_list else test_list for user in users: if user.is_active and user.location and user.location.location_type == 'FACILITY': sp = SupplyPointCase.get_by_location(user.location) if sp and not StockTransaction.objects.filter(case_id=sp._id, report__date__gte=date, type='stockonhand').exists(): result = send_translated_message(user, REMINDER_STOCKONHAND) if not test_list and result: sp_ids.add(sp._id) update_statuses(sp_ids, SupplyPointStatusTypes.SOH_FACILITY, SupplyPointStatusValues.REMINDER_SENT)
def send_supervision_reminder(domain, date): sp_ids = set() for user in CommTrackUser.by_domain(domain): if user.is_active and user.location and user.location.location_type == 'FACILITY': sp = SupplyPointCase.get_by_location(user.location) if sp and not SupplyPointStatus.objects.filter(supply_point=sp._id, status_type=SupplyPointStatusTypes.SUPERVISION_FACILITY, status_date__gte=date).exists(): if user.get_verified_number(): send_sms_to_verified_number(user.get_verified_number(), REMINDER_SUPERVISION) sp_ids.add(sp._id) update_statuses(sp_ids, SupplyPointStatusTypes.SUPERVISION_FACILITY, SupplyPointStatusValues.REMINDER_SENT)
def send_soh_reminder(domain, date, test_list=None): sp_ids = set() users = CommCareUser.by_domain(domain) if not test_list else test_list for user in users: if user.is_active and user.location and user.location.location_type == 'FACILITY': sp = SupplyPointCase.get_by_location(user.location) if sp and not StockTransaction.objects.filter( case_id=sp._id, report__date__gte=date, type='stockonhand').exists(): result = send_translated_message(user, REMINDER_STOCKONHAND) if not test_list and result: sp_ids.add(sp._id) update_statuses(sp_ids, SupplyPointStatusTypes.SOH_FACILITY, SupplyPointStatusValues.REMINDER_SENT)
def send_supervision_reminder(domain, date, test_list=None): sp_ids = set() users = CommCareUser.by_domain(domain) if not test_list else test_list for user in users: location = user.location if user.is_active and location and location.location_type == 'FACILITY': if not SupplyPointStatus.objects.filter(location_id=location._id, status_type=SupplyPointStatusTypes.SUPERVISION_FACILITY, status_date__gte=date).exists(): result = send_translated_message(user, REMINDER_SUPERVISION) if not test_list and result: sp_ids.add(location.get_id) update_statuses(sp_ids, SupplyPointStatusTypes.SUPERVISION_FACILITY, SupplyPointStatusValues.REMINDER_SENT)
def send(self): locations_ids = set() status_type = self.get_status_type() for sql_location in self.get_sql_locations(): if not self.location_filter(sql_location): continue sent = None for user in self.get_location_users(sql_location): result = send_translated_message(user, self.get_message()) if result: sent = result if sent: locations_ids.add(sql_location.location_id) update_statuses(locations_ids, status_type, SupplyPointStatusValues.REMINDER_SENT)
def send_supervision_reminder(domain, date, test_list=None): sp_ids = set() users = CommCareUser.by_domain(domain) if not test_list else test_list for user in users: location = user.location if user.is_active and location and location.location_type == 'FACILITY': if not SupplyPointStatus.objects.filter( location_id=location._id, status_type=SupplyPointStatusTypes.SUPERVISION_FACILITY, status_date__gte=date).exists(): result = send_translated_message(user, REMINDER_SUPERVISION) if not test_list and result: sp_ids.add(location.get_id) update_statuses(sp_ids, SupplyPointStatusTypes.SUPERVISION_FACILITY, SupplyPointStatusValues.REMINDER_SENT)
def send(self): locations_ids = set() status_type = self.get_status_type() for sql_location in self.get_sql_locations(): if not self.location_filter(sql_location): continue sent = None for user in self.get_location_users(sql_location): result = send_translated_message(user, self.get_message()) if result: sent = result if sent: locations_ids.add(sql_location.location_id) if status_type: update_statuses(locations_ids, status_type, SupplyPointStatusValues.REMINDER_SENT)
def send_ror_reminder(domain, date, loc_type='FACILITY'): if loc_type == 'FACILITY': status_type = SupplyPointStatusTypes.R_AND_R_FACILITY sms_text = REMINDER_R_AND_R_FACILITY elif loc_type == 'DISTRICT': status_type = SupplyPointStatusTypes.R_AND_R_DISTRICT sms_text = REMINDER_R_AND_R_DISTRICT else: return current_group = DeliveryGroups().current_submitting_group(date.month) sp_ids = set() for user in CommTrackUser.by_domain(domain): if user.is_active and user.location and user.location.location_type == loc_type: sp = SupplyPointCase.get_by_location(user.location) if current_group in get_groups(sp.location.metadata.get('groups', None)) \ and not SupplyPointStatus.objects.filter(supply_point=sp._id, status_type=status_type, status_date__gte=date).exists(): if user.get_verified_number(): send_sms_to_verified_number(user.get_verified_number(), sms_text) sp_ids.add(sp._id) update_statuses(sp_ids, status_type, SupplyPointStatusValues.REMINDER_SENT)