def on_going_non_reporting(): now = datetime.datetime.utcnow() date = now - datetime.timedelta(days=21) domains = EWSGhanaConfig.get_all_enabled_domains() for domain in domains: for user in CommCareUser.by_domain(domain): try: user_location = SQLLocation.objects.get(domain=domain, location_id=user.location._id) except AttributeError: continue if user_location: facilities = [] if user_location.location_type == 'district': facilities = user_location.get_children() elif user_location.location_type == 'region': facilities = SQLLocation.objects.filter(domain=domain, parent__parent__location_id=user.location._id) fac = set() for facility in facilities: sp = facility.supply_point_id if sp and not StockTransaction.objects.filter( case_id=sp, type="stockonhand", report__date__gte=date).exists(): fac.add(str(facility.name)) if fac and user.get_verified_number(): message = ONGOING_NON_REPORTING % " \n".join(fac) send_sms_to_verified_number(user.get_verified_number(), message) if user.email: email = str(user.email) send_mail('ONGOING NON REPORTING', message, '*****@*****.**', [email])
def third_soh_to_super(): domains = EWSGhanaConfig.get_all_enabled_domains() for domain in domains: facilities = SQLLocation.objects.filter( location_type__name__in=reporting_types(domain)) users = CommCareUser.by_domain(domain) third_soh_process_users_and_facilities(users, facilities)
def first_soh_reminder(): domains = EWSGhanaConfig.get_all_enabled_domains() for domain in domains: for user in CommCareUser.by_domain(domain): role = user.user_data.get('role') if role and role != IN_CHARGE_ROLE: first_soh_process_user(user)
def second_soh_reminder(): now = datetime.datetime.utcnow() date = now - datetime.timedelta(days=DAYS_UNTIL_LATE) domains = EWSGhanaConfig.get_all_enabled_domains() for domain in domains: for user in CommCareUser.by_domain(domain): second_soh_process_user(user, date)
def second_soh_reminder(): domains = EWSGhanaConfig.get_all_enabled_domains() for domain in domains: for user in CommCareUser.by_domain(domain): roles = user.user_data.get('role') if roles and IN_CHARGE_ROLE in roles: second_soh_process_user(user)
def second_soh_reminder(): domains = EWSGhanaConfig.get_all_enabled_domains() for domain in domains: for user in CommCareUser.by_domain(domain): roles = user.user_data.get('role') if roles and IN_CHARGE_ROLE in roles: second_soh_process_user(user)
def reminder_to_visit_website(): domains = EWSGhanaConfig.get_all_enabled_domains() for domain in domains: for user in CommCareUser.by_domain(domain): thirteen_days_ago = datetime.datetime.utcnow() - datetime.timedelta(weeks=13) if user.location and user.last_login < thirteen_days_ago and user.get_verified_number()\ and user.location.location_type.name in ['district', 'region', 'country']: message = WEB_REMINDER % user.name verified_number = user.get_verified_number() send_sms_to_verified_number(verified_number, message) if can_receive_email(user, verified_number): email = str(user.email) send_mail('REMINDER TO VISIT WEBSITE', message, '*****@*****.**', [email])
def reminder_to_visit_website(): domains = EWSGhanaConfig.get_all_enabled_domains() for domain in domains: for user in CommCareUser.by_domain(domain): if user.location and user.last_login < datetime.datetime.now() - datetime.timedelta(weeks=13) and\ user.get_verified_number() and \ (user.location.location_type == 'district' or user.location.location_type == 'region' or user.location.location_type == 'country'): message = WEB_REMINDER % user.name send_sms_to_verified_number(user.get_verified_number(), message) if user.email: email = str(user.email) send_mail('REMINDER TO VISIT WEBSITE', message, '*****@*****.**', [email])
def reminder_to_visit_website(): domains = EWSGhanaConfig.get_all_enabled_domains() for domain in domains: for user in CommCareUser.by_domain(domain): thirteen_days_ago = datetime.datetime.utcnow( ) - datetime.timedelta(weeks=13) if user.location and user.last_login < thirteen_days_ago and user.get_verified_number()\ and user.location.location_type.name in ['district', 'region', 'country']: message = WEB_REMINDER % user.name verified_number = user.get_verified_number() send_sms_to_verified_number(verified_number, message) if can_receive_email(user, verified_number): email = str(user.email) send_mail('REMINDER TO VISIT WEBSITE', message, '*****@*****.**', [email])
def report_reminder(): sp_ids = set() now = datetime.datetime.utcnow() date = now - datetime.timedelta(days=7) domains = EWSGhanaConfig.get_all_enabled_domains() for domain in domains: for user in CommCareUser.by_domain(domain): if user.location: sp = SupplyPointCase.get_by_location(user.location) if sp and not StockTransaction.objects.filter( case_id=sp._id, type="stockonhand", report__date__gte=date).exists()\ and user.get_verified_number(): sp_ids.add(sp._id) message = REPORT_REMINDER % (user.name, user.location.name) send_sms_to_verified_number(user.get_verified_number(), message) if user.email: email = str(user.email) send_mail('REPORT REMINDER', message, '*****@*****.**', [email])
def urgent_stockout(): domains = EWSGhanaConfig.get_all_enabled_domains() for domain in domains: for user in CommCareUser.by_domain(domain): try: user_location = SQLLocation.objects.get(domain=domain, location_id=user.location._id) except AttributeError: continue if user_location: facilities = [] if user_location.location_type == 'district': facilities = user_location.get_children() elif user_location.location_type == 'region': facilities = SQLLocation.objects.filter(domain=domain, parent__parent__location_id=user.location._id) elif user_location.location_type == 'country': facilities = SQLLocation.objects.filter(domain=domain, parent__parent__parent__location_id=user.location._id) stocked_out_products = set() fac = set() no_rep = 0 for facility in facilities: sp = facility.supply_point_id if sp: stocked_out = StockTransaction.objects.filter( case_id=sp, type="stockonhand", stock_on_hand=0) if stocked_out.exists(): no_rep += 1 fac.add(str(facility)) for product in stocked_out: stocked_out_products.add( SQLProduct.objects.get(product_id=product.product_id).name) if fac and no_rep >= len(facilities) / 2 and user.get_verified_number(): message = URGENT_STOCKOUT % (user_location.name, ", ".join(sorted( [str(product) for product in stocked_out_products]))) send_sms_to_verified_number(user.get_verified_number(), message) if user.email: email = str(user.email) send_mail('URGENT STOCKOUT', message, '*****@*****.**', [email])
def reminder_to_visit_website(): domains = EWSGhanaConfig.get_all_enabled_domains() for domain in domains: VisitWebsiteReminder(domain).send()
def stockout_notification_to_web_supers(): domains = EWSGhanaConfig.get_all_enabled_domains() for domain in domains: StockoutReminder(domain).send()
def second_soh_reminder(): domains = EWSGhanaConfig.get_all_enabled_domains() for domain in domains: SecondSOHReminder(domain).send()
def stockout_notification_to_web_supers(): domains = EWSGhanaConfig.get_all_enabled_domains() for domain in domains: StockoutReminder(domain).send()
def second_soh_reminder(): domains = EWSGhanaConfig.get_all_enabled_domains() for domain in domains: SecondSOHReminder(domain).send()
def urgent_stockout(): domains = EWSGhanaConfig.get_all_enabled_domains() for domain in domains: UrgentStockoutAlert(domain).send()
def reminder_to_submit_rrirv(): domains = EWSGhanaConfig.get_all_enabled_domains() for domain in domains: for user in CommCareUser.by_domain(domain): rrirv_process_user(user)
def _get_logistics_domains(self): return ILSGatewayConfig.get_all_enabled_domains() + EWSGhanaConfig.get_all_enabled_domains()
def report_reminder(): domains = EWSGhanaConfig.get_all_enabled_domains() for domain in domains: for user in CommCareUser.by_domain(domain): report_reminder_process_user(user)
def on_going_stockout(): domains = EWSGhanaConfig.get_all_enabled_domains() for domain in domains: for user in CommCareUser.by_domain(domain): on_going_stockout_process_user(user)
def stockout_notification_to_web_supers(): domains = EWSGhanaConfig.get_all_enabled_domains() for domain in domains: for user in CommCareUser.by_domain(domain): stockout_process_user(user)
def on_going_stockout(): domains = EWSGhanaConfig.get_all_enabled_domains() for domain in domains: OnGoingStockouts(domain).send() OnGoingStockoutsRMS(domain).send()
def urgent_stockout(): domains = EWSGhanaConfig.get_all_enabled_domains() for domain in domains: UrgentStockoutAlert(domain)
def _get_logistics_domains(self): from custom.ewsghana.models import EWSGhanaConfig return ILSGatewayConfig.get_all_enabled_domains( ) + EWSGhanaConfig.get_all_enabled_domains()
def urgent_non_reporting(): domains = EWSGhanaConfig.get_all_enabled_domains() for domain in domains: UrgentNonReporting(domain).send()
def third_soh_to_super(): domains = EWSGhanaConfig.get_all_enabled_domains() for domain in domains: facilities = SQLLocation.objects.filter(location_type__name__in=reporting_types(domain)) users = CommCareUser.by_domain(domain) third_soh_process_users_and_facilities(users, facilities)
def first_soh_reminder(): domains = EWSGhanaConfig.get_all_enabled_domains() for domain in domains: FirstSOHReminder(domain).send()
def stockout_notification_to_web_supers(): domains = EWSGhanaConfig.get_all_enabled_domains() for domain in domains: for user in CommCareUser.by_domain(domain): stockout_process_user(user)
def third_soh_to_super(): domains = EWSGhanaConfig.get_all_enabled_domains() for domain in domains: ThirdSOHReminder(domain).send()
def reminder_to_submit_rrirv(): domains = EWSGhanaConfig.get_all_enabled_domains() for domain in domains: for user in CommCareUser.by_domain(domain): rrirv_process_user(user)
def reminder_to_submit_rrirv(): domains = EWSGhanaConfig.get_all_enabled_domains() for domain in domains: RRIRVReminder(domain).send()
def reminder_to_visit_website(): domains = EWSGhanaConfig.get_all_enabled_domains() for domain in domains: for user in CommCareUser.by_domain(domain): visit_website_process_user(user)
def third_soh_to_super(): domains = EWSGhanaConfig.get_all_enabled_domains() for domain in domains: ThirdSOHReminder(domain).send()
def urgent_non_reporting(): domains = EWSGhanaConfig.get_all_enabled_domains() for domain in domains: for user in CommCareUser.by_domain(domain): urgent_non_reporting_process_user(user)
def reminder_to_submit_rrirv(): domains = EWSGhanaConfig.get_all_enabled_domains() for domain in domains: RRIRVReminder(domain).send()
def report_reminder(): domains = EWSGhanaConfig.get_all_enabled_domains() for domain in domains: for user in CommCareUser.by_domain(domain): report_reminder_process_user(user)
def on_going_non_reporting(): domains = EWSGhanaConfig.get_all_enabled_domains() for domain in domains: OnGoingNonReporting(domain).send()
def on_going_non_reporting(): domains = EWSGhanaConfig.get_all_enabled_domains() for domain in domains: OnGoingNonReporting(domain).send()
def urgent_non_reporting(): domains = EWSGhanaConfig.get_all_enabled_domains() for domain in domains: UrgentNonReporting(domain)
def on_going_stockout(): domains = EWSGhanaConfig.get_all_enabled_domains() for domain in domains: OnGoingStockouts(domain).send() OnGoingStockoutsRMS(domain).send()
def first_soh_reminder(): domains = EWSGhanaConfig.get_all_enabled_domains() for domain in domains: FirstSOHReminder(domain).send()
def reminder_to_visit_website(): domains = EWSGhanaConfig.get_all_enabled_domains() for domain in domains: for user in CommCareUser.by_domain(domain): visit_website_process_user(user)
def _get_logistics_domains(self): from custom.ewsghana.models import EWSGhanaConfig return ILSGatewayConfig.get_all_enabled_domains() + EWSGhanaConfig.get_all_enabled_domains()
def reminder_to_visit_website(): domains = EWSGhanaConfig.get_all_enabled_domains() for domain in domains: VisitWebsiteReminder(domain).send()
def on_going_stockout(): domains = EWSGhanaConfig.get_all_enabled_domains() for domain in domains: for user in CommCareUser.by_domain(domain): on_going_stockout_process_user(user)
def urgent_non_reporting(): domains = EWSGhanaConfig.get_all_enabled_domains() for domain in domains: for user in CommCareUser.by_domain(domain): urgent_non_reporting_process_user(user)