Example #1
0
 def handle(self):
     location = get_location(self.domain, self.user, None)
     SupplyPointStatus.objects.create(supply_point=location['case']._id,
                                      status_type=SupplyPointStatusTypes.DELIVERY_FACILITY,
                                      status_value=SupplyPointStatusValues.RECEIVED,
                                      status_date=datetime.utcnow())
     return False
Example #2
0
 def handle(self):
     location = get_location(self.domain, self.user, self.args[0])
     if location['location'].location_type == 'FACILITY':
         SupplyPointStatus.objects.create(supply_point=location['case']._id,
                                          status_type=SupplyPointStatusTypes.SOH_FACILITY,
                                          status_value=SupplyPointStatusValues.SUBMITTED,
                                          status_date=datetime.utcnow())
Example #3
0
 def handle(self):
     location = get_location(self.domain, self.user, None)
     SupplyPointStatus.objects.create(supply_point=location['case']._id,
                                      status_type=SupplyPointStatusTypes.R_AND_R_FACILITY,
                                      status_value=SupplyPointStatusValues.NOT_SUBMITTED,
                                      status_date=datetime.utcnow())
     self.respond(NOT_SUBMITTED_CONFIRM)
     return True
Example #4
0
    def handle(self):
        location = get_location(self.domain, self.user, None)
        status_type = None
        if location['location'].location_type == 'FACILITY':
            status_type = SupplyPointStatusTypes.DELIVERY_FACILITY
        elif location['location'].location_type == 'DISTRICT':
            status_type = SupplyPointStatusTypes.DELIVERY_DISTRICT

        SupplyPointStatus.objects.create(supply_point=location['case']._id,
                                         status_type=status_type,
                                         status_value=SupplyPointStatusValues.NOT_RECEIVED,
                                         status_date=datetime.utcnow())
Example #5
0
 def help(self):
     location = get_location(self.domain, self.user, None)
     status_type = None
     if location['location'].location_type == 'FACILITY':
         status_type = SupplyPointStatusTypes.DELIVERY_FACILITY
         self.respond(DELIVERY_CONFIRM_DISTRICT, contact_name=self.user.first_name + " " + self.user.last_name,
                      facility_name=location['case'].name)
     elif location['location'].location_type == 'DISTRICT':
         status_type = SupplyPointStatusTypes.DELIVERY_DISTRICT
         self._send_delivery_alert_to_facilities(location['case'].name, location['location'])
         self.respond(DELIVERY_PARTIAL_CONFIRM)
     SupplyPointStatus.objects.create(supply_point=location['case']._id,
                                      status_type=status_type,
                                      status_value=SupplyPointStatusValues.RECEIVED,
                                      status_date=datetime.utcnow())
Example #6
0
    def handle(self):
        subcommand = self.args[0].strip().lower()
        location = get_location(self.domain, self.user, None)
        if not location:
            return
        if re.match("hap", subcommand) or re.match("no", subcommand):
            status_value = SupplyPointStatusValues.NOT_RECEIVED
        elif re.match("ndi", subcommand) or re.match("yes", subcommand):
            status_value = SupplyPointStatusValues.RECEIVED
        else:
            self.help()
            return

        SupplyPointStatus.objects.create(status_type=SupplyPointStatusTypes.SUPERVISION_FACILITY,
                                             status_value=status_value,
                                             supply_point=location['case']._id,
                                             status_date=datetime.utcnow())
Example #7
0
 def _handle(self, help=False):
     location = get_location(self.domain, self.user, None)
     status_type = None
     if location['location'].location_type == 'FACILITY':
         status_type = SupplyPointStatusTypes.R_AND_R_FACILITY
         self.respond(SUBMITTED_CONFIRM % {"sp_name": location['location'].name,
                                           "contact_name": self.user.name})
     elif location['location'].location_type == 'DISTRICT':
         if help:
             quantities = [0, 0, 0]
             self.respond(SUBMITTED_REMINDER_DISTRICT)
         else:
             quantities = [self.args[1], self.args[3], self.args[5]]
             DeliveryGroupReport.objects.create(
                 supply_point=location['case']._id,
                 quantity=quantities[0],
                 message=self.msg._id,
                 delivery_group="A")
             DeliveryGroupReport.objects.create(
                 supply_point=location['case']._id,
                 quantity=quantities[1],
                 message=self.msg._id,
                 delivery_group="B")
             DeliveryGroupReport.objects.create(
                 supply_point=location['case']._id,
                 quantity=quantities[2],
                 message=self.msg._id,
                 delivery_group="C")
             self.respond(SUBMITTED_CONFIRM % {
                 "sp_name": location['case'].name,
                 "contact_name": self.user.first_name + " " + self.user.last_name}
             )
         status_type = SupplyPointStatusTypes.R_AND_R_DISTRICT
         params = {
             'district_name': location['case'].name,
             'group_a': quantities[0],
             'group_b': quantities[1],
             'group_c': quantities[2]
         }
         self._send_submission_alert_to_msd(params)
     SupplyPointStatus.objects.create(supply_point=location['case']._id,
                                      status_type=status_type,
                                      status_value=SupplyPointStatusValues.SUBMITTED,
                                      status_date=datetime.utcnow())
     return True
Example #8
0
 def _get_facility_location(self, domain, msd_code):
     sp = get_location(domain, None, msd_code)
     return sp['location']
Example #9
0
    def handle(self):
        if len(self.args) < 2:
            return self.help()

        command = self.args[0]
        rest = " ".join(self.args[1:])
        msd_code = self.args[1]
        fw_message = " ".join(self.args[2:])

        loc = get_location(self.domain, None, msd_code) or self.get_district_by_name(rest)
        if not loc['location']:
            self.respond(TEST_HANDLER_BAD_CODE, code=msd_code)
            return

        if command in ['soh', 'hmk']:
            self.send_message(loc['location'], SOH_HELP_MESSAGE)
            now = datetime.utcnow()
            SupplyPointStatus.objects.create(supply_point=loc['case']._id,
                                             status_type=SupplyPointStatusTypes.SOH_FACILITY,
                                             status_value=SupplyPointStatusValues.REMINDER_SENT,
                                             status_date=now)
        elif command in ['supervision']:
            self.send_message(loc['location'], SUPERVISION_REMINDER)
            now = datetime.utcnow()
            SupplyPointStatus.objects.create(supply_point=loc['case']._id,
                                             status_type=SupplyPointStatusTypes.SUPERVISION_FACILITY,
                                             status_value=SupplyPointStatusValues.REMINDER_SENT,
                                             status_date=now)
        elif command in ['randr']:
            if loc['location'].location_type == 'DISTRICT':
                self.send_message(loc['location'], SUBMITTED_REMINDER_DISTRICT)
                status_type = SupplyPointStatusTypes.R_AND_R_DISTRICT
            else:
                self.send_message(loc['location'], SUBMITTED_REMINDER_FACILITY)
                status_type = SupplyPointStatusTypes.R_AND_R_FACILITY
            now = datetime.utcnow()
            SupplyPointStatus.objects.create(supply_point=loc['case']._id,
                                             status_type=status_type,
                                             status_value=SupplyPointStatusValues.REMINDER_SENT,
                                             status_date=now)
        elif command in ['delivery']:
            if loc['location'].location_type == 'DISTRICT':
                self.send_message(loc['location'], DELIVERY_REMINDER_DISTRICT)
                status_type = SupplyPointStatusTypes.DELIVERY_DISTRICT
            else:
                self.send_message(loc['location'], DELIVERY_REMINDER_FACILITY)
                status_type = SupplyPointStatusTypes.DELIVERY_FACILITY
            now = datetime.utcnow()
            SupplyPointStatus.objects.create(supply_point=loc['case']._id,
                                             status_type=status_type,
                                             status_value=SupplyPointStatusValues.REMINDER_SENT,
                                             status_date=now)
        elif command in ['fw']:
            if fw_message:
                self.send_message(loc['location'], fw_message)
        elif command in ["latedelivery"]:
            self.send_message(loc['location'], DELIVERY_LATE_DISTRICT, group_name="changeme", group_total=1,
                              not_responded_count=2, not_received_count=3)
            self.respond(TEST_HANDLER_CONFIRM)
        elif command in ["randr_report"]:
            now = datetime.utcnow()
            self.respond(REMINDER_MONTHLY_RANDR_SUMMARY,
                         **reports.construct_summary(loc['case'],
                                                     SupplyPointStatusTypes.R_AND_R_FACILITY,
                                                     [SupplyPointStatusValues.SUBMITTED, SupplyPointStatusValues.NOT_SUBMITTED],
                                                     get_business_day_of_month_before(now.year, now.month, 5)))
        elif command in ["soh_report"]:
            now = datetime.utcnow()
            self.respond(REMINDER_MONTHLY_SOH_SUMMARY,
                         **reports.construct_summary(loc['case'],
                                                     SupplyPointStatusTypes.SOH_FACILITY,
                                                     [SupplyPointStatusValues.SUBMITTED],
                                                     get_business_day_of_month_before(now.year, now.month, -1)))
        elif command in ["delivery_report"]:
            now = datetime.utcnow()
            self.respond(REMINDER_MONTHLY_DELIVERY_SUMMARY,
                         **reports.construct_summary(loc['case'],
                                                     SupplyPointStatusTypes.DELIVERY_FACILITY,
                                                     [SupplyPointStatusValues.RECEIVED,
                                                     SupplyPointStatusValues.NOT_RECEIVED],
                                                     get_business_day_of_month_before(now.year, now.month, 15)))
        elif command in ["soh_thank_you"]:
            self.respond(SOH_THANK_YOU)
Example #10
0
 def _get_facility_location(self, domain, msd_code):
     sp = get_location(domain, None, msd_code)
     return sp['location']