Beispiel #1
0
 def _send_submission_alert_to_msd(self, params):
     users = [
         u for u in CommCareUser.by_domain(self.domain)
         if u.user_data.get('role', None) == 'MSD'
     ]
     for user in users:
         send_translated_message(user, SUBMITTED_NOTIFICATION_MSD, **params)
Beispiel #2
0
    def send(self):
        for sql_location in self.get_sql_locations():
            stockedout_products_set = set(stockedout_products(sql_location))
            slab_config = SLABConfig.objects.get(sql_location=sql_location)
            overstocked_str = ""
            for closest_sql_location in slab_config.closest_supply_points.all(
            ):
                overstocked_products_set = set([
                    overstock[0]
                    for overstock in overstocked_products(closest_sql_location)
                ])
                intersection = stockedout_products_set.intersection(
                    overstocked_products_set)
                if intersection:
                    overstocked_str += "%s (%s)" % (closest_sql_location.name,
                                                    ', '.join(
                                                        sorted(intersection)))

            if not overstocked_str:
                continue

            for user in self.get_location_users(sql_location):
                send_translated_message(
                    user, REMINDER_STOCKOUT % {
                        'products_list': ', '.join(
                            sorted(stockedout_products_set)),
                        'overstocked_list': overstocked_str
                    })
Beispiel #3
0
    def _send_delivery_alert_to_facilities(self, location):
        locs = [c.get_id for c in location.get_children()]
        users = []
        for location_id in locs:
            users.extend(get_users_by_location_id(self.domain, location_id))

        for user in users:
            send_translated_message(user, DELIVERY_CONFIRM_CHILDREN, district_name=location.name)
Beispiel #4
0
    def _send_delivery_alert_to_facilities(self, location):
        locs = [c.get_id for c in location.get_children()]
        users = []
        for location_id in locs:
            users.extend(get_users_by_location_id(self.domain, location_id))

        for user in users:
            send_translated_message(user,
                                    DELIVERY_CONFIRM_CHILDREN,
                                    district_name=location.name)
Beispiel #5
0
def soh_summary_task():
    """
        6th business day of the month @ 3pm Tanzania time
    """
    now = datetime.utcnow()
    sixth_business_day = get_business_day_of_month(month=now.month, year=now.year, count=6)
    if now.day != sixth_business_day.day:
        return

    for domain in ILSGatewayConfig.get_all_enabled_domains():
        for user in get_district_people(domain):
            send_translated_message(user, REMINDER_MONTHLY_SOH_SUMMARY, **construct_soh_summary(user.location))
Beispiel #6
0
def soh_summary_task():
    """
        6th business day of the month @ 3pm Tanzania time
    """
    now = datetime.utcnow()
    sixth_business_day = get_business_day_of_month(month=now.month, year=now.year, count=6)
    if now.day != sixth_business_day.day:
        return

    for domain in ILSGatewayConfig.get_all_enabled_domains():
        for user in get_district_people(domain):
            send_translated_message(user, REMINDER_MONTHLY_SOH_SUMMARY, **construct_soh_summary(user.location))
Beispiel #7
0
def delivery_summary_task():
    """
        last business day of month 3pm Tanzania time
    """
    now = datetime.utcnow()
    last_business_day = get_business_day_of_month(month=now.month, year=now.year, count=-1)
    if now.day != last_business_day.day:
        return

    for domain in ILSGatewayConfig.get_all_enabled_domains():
        for user in get_district_people(domain):
            send_translated_message(
                user, REMINDER_MONTHLY_DELIVERY_SUMMARY, **construct_delivery_summary(user.location)
            )
Beispiel #8
0
def delivery_summary_task():
    """
        last business day of month 3pm Tanzania time
    """
    now = datetime.utcnow()
    last_business_day = get_business_day_of_month(month=now.month, year=now.year, count=-1)
    if now.day != last_business_day.day:
        return

    for domain in ILSGatewayConfig.get_all_enabled_domains():
        for user in get_district_people(domain):
            send_translated_message(
                user, REMINDER_MONTHLY_DELIVERY_SUMMARY, **construct_delivery_summary(user.location)
            )
Beispiel #9
0
def randr_summary_task():
    """
        on 17th day of month or before if it's not a business day @ 3pm Tanzania time
    """

    now = datetime.utcnow()
    business_day = get_business_day_of_month_before(month=now.month, year=now.year, day=17)
    if now.day != business_day.day:
        return

    for domain in ILSGatewayConfig.get_all_enabled_domains():
        for user in get_district_people(domain):
            send_translated_message(
                user, REMINDER_MONTHLY_RANDR_SUMMARY, **construct_randr_summary(user.location)
            )
Beispiel #10
0
def randr_summary_task():
    """
        on 17th day of month or before if it's not a business day @ 3pm Tanzania time
    """

    now = datetime.utcnow()
    business_day = get_business_day_of_month_before(month=now.month, year=now.year, day=17)
    if now.day != business_day.day:
        return

    for domain in ILSGatewayConfig.get_all_enabled_domains():
        for user in get_district_people(domain):
            send_translated_message(
                user, REMINDER_MONTHLY_RANDR_SUMMARY, **construct_randr_summary(user.location)
            )
Beispiel #11
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)
Beispiel #12
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)
Beispiel #13
0
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)
Beispiel #14
0
    def send(self):
        for sql_location in self.get_sql_locations():
            stockedout_products_set = set(stockedout_products(sql_location))
            slab_config = SLABConfig.objects.get(sql_location=sql_location)
            overstocked_str = ""
            for closest_sql_location in slab_config.closest_supply_points.all():
                overstocked_products_set = set(
                    [overstock[0] for overstock in overstocked_products(closest_sql_location)]
                )
                intersection = stockedout_products_set.intersection(overstocked_products_set)
                if intersection:
                    overstocked_str += "%s (%s)" % (closest_sql_location.name, ', '.join(sorted(intersection)))

            if not overstocked_str:
                continue

            for user in self.get_location_users(sql_location):
                send_translated_message(user, REMINDER_STOCKOUT % {
                    'products_list': ', '.join(sorted(stockedout_products_set)),
                    'overstocked_list': overstocked_str
                })
Beispiel #15
0
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)
Beispiel #16
0
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)
Beispiel #17
0
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)
Beispiel #18
0
    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)
Beispiel #19
0
    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)
Beispiel #20
0
 def _send_submission_alert_to_msd(self, params):
     users = [u for u in CommCareUser.by_domain(self.domain) if u.user_data.get('role', None) == 'MSD']
     for user in users:
         send_translated_message(user, SUBMITTED_NOTIFICATION_MSD, **params)
Beispiel #21
0
 def send_message(self, sql_location, message, **kwargs):
     for user in get_users_by_location_id(self.domain,
                                          sql_location.location_id):
         send_translated_message(user, message, **kwargs)
Beispiel #22
0
 def send_message(self, sql_location, message, **kwargs):
     for user in get_users_by_location_id(self.domain, sql_location.location_id):
         send_translated_message(user, message, **kwargs)