Exemplo n.º 1
0
def health_center_unable_resupply_emergency(request):
    hsas = hsa_supply_points_below(request.location)
    return [HealthCenterUnableResupplyEmergencyAlert(s.supply_point, s.product)\
            for s in StockRequest.pending_requests()\
                            .filter(is_emergency=True,
                                    status=StockRequestStatus.STOCKED_OUT,
                                    supply_point__in=hsas)]
Exemplo n.º 2
0
def health_center_unable_resupply_emergency(request):
    hsas = hsa_supply_points_below(request.location)
    return [HealthCenterUnableResupplyEmergencyAlert(s.supply_point, s.product)\
            for s in StockRequest.pending_requests()\
                            .filter(is_emergency=True,
                                    status=StockRequestStatus.STOCKED_OUT,
                                    supply_point__in=hsas)]
Exemplo n.º 3
0
def health_center_unable_resupply_stockout(request):
    r = []
    hsas = hsa_supply_points_below(request.location)
    for s in StockRequest.pending_requests().filter(supply_point__in=hsas,
                                                    status=StockRequestStatus.STOCKED_OUT):
        if s.supply_point.stock(s.product) == 0:
            r += [HealthCenterUnableResupplyStockoutAlert(s.supply_point, s.product)]
    return r
Exemplo n.º 4
0
    def handle_custom(self, text):
        now = datetime.utcnow()
        
        # Currently we just mark these stock requests stocked out.
        # Note that this has a different meaning for emergency orders
        # in which case we only confirm the emergency products.
        # However in the interest of simplicity we won't worry about that (yet?).
        pending_reqs = StockRequest.pending_requests().filter(supply_point=self.hsa.supply_point)
        for req in pending_reqs:
            req.mark_stockout(self.msg.logistics_contact, now)
        
        # if there were any emergency orders, only report those as stockouts
        # this is pretty confusing/hacky
        emergencies = pending_reqs.filter(is_emergency=True)
        stockouts = pending_reqs.filter(balance=0)
        if stockouts.count() > 0:
            reqs = stockouts
        elif emergencies.count() > 0:
            reqs = emergencies
        else:
            reqs = pending_reqs

        def _message_supervisors(message):
            supplier = self.msg.logistics_contact.supply_point.supplied_by
            if supplier is not None:
                supervisors = Contact.objects.filter(is_active=True,
                                                     supply_point__location=supplier.location,
                                                     role__in=[ContactRole.objects.get(code=config.Roles.DISTRICT_PHARMACIST),
                                                               ContactRole.objects.get(code=config.Roles.IMCI_COORDINATOR)])
                # note that if there are no supervisors registered, this will silently
                # not send notifications
                for super in supervisors:
                    super.message(message,
                                  contact=self.msg.logistics_contact.name,
                                  supply_point=self.msg.logistics_contact.supply_point.name,
                                  products=", ".join(req.product.sms_code for req in reqs))

        if emergencies.count() > 0:
            # Unable to resupply stocked out/emergency products.
            self.respond(config.Messages.HF_UNABLE_RESTOCK_EO, products=", ".join(req.product.sms_code for req in reqs))
            self.hsa.message(config.Messages.HSA_UNABLE_RESTOCK_EO, hsa=self.hsa.name,products=", ".join(req.product.sms_code for req in reqs))
            if stockouts.count() > 0:
                _message_supervisors(config.Messages.DISTRICT_UNABLE_RESTOCK_STOCKOUT)
            else:
                _message_supervisors(config.Messages.DISTRICT_UNABLE_RESTOCK_EO)
        else:
            self.respond(config.Messages.HF_UNABLE_RESTOCK_EO,
                         products=", ".join(req.product.sms_code for req in reqs))
            self.hsa.message(config.Messages.HSA_UNABLE_RESTOCK_ANYTHING, hsa=self.hsa.name)
            _message_supervisors(config.Messages.DISTRICT_UNABLE_RESTOCK_NORMAL)

            
        # this is pretty hacky, but set the SoH to 0 for the stocked out products
        # so that they show properly in things like alerts
        for req in reqs:
            self.msg.logistics_contact.supply_point.update_stock(req.product, 0)
Exemplo n.º 5
0
def health_center_unable_resupply_stockout(request):
    r = []
    hsas = hsa_supply_points_below(request.location)
    for s in StockRequest.pending_requests().filter(
            supply_point__in=hsas, status=StockRequestStatus.STOCKED_OUT):
        if s.supply_point.stock(s.product) == 0:
            r += [
                HealthCenterUnableResupplyStockoutAlert(
                    s.supply_point, s.product)
            ]
    return r
Exemplo n.º 6
0
def hsa_below_emergency_quantity(request):
    '''
    This query finds HSA/product pairs where the product is below emergency level but there are no pending requests.
    '''
    hsas = hsa_supply_points_below(request.location)
    r = []
    for p in ProductStock.objects.filter(is_active=True,
            supply_point__in=hsas,
            quantity__lte = F('product__emergency_order_level')):
        if not StockRequest.pending_requests().filter(product=p.product, supply_point=p.supply_point).exists():
            r += [HSABelowEmergencyQuantityAlert(p.supply_point, p.product)]
    return r
Exemplo n.º 7
0
 def handle_custom(self, text):
     now = datetime.utcnow()
     pending_reqs = StockRequest.pending_requests().filter(supply_point=self.hsa.supply_point)
     for req in pending_reqs:
         req.approve(self.msg.logistics_contact, now, req.amount_requested)
     
     self.respond(config.Messages.APPROVAL_RESPONSE, hsa=self.hsa.name)
     self.hsa.message(config.Messages.APPROVAL_NOTICE, hsa=self.hsa.name)
 
     # this is really hacky, but set the SoH to non-zero for the reported products
     # so that they show no longer stocked out in things like alerts
     for req in pending_reqs:
         if self.msg.logistics_contact.supply_point.stock(req.product) == 0:
             self.msg.logistics_contact.supply_point.update_stock(req.product, 1)
Exemplo n.º 8
0
def hsa_below_emergency_quantity(request):
    '''
    This query finds HSA/product pairs where the product is below emergency level but there are no pending requests.
    '''
    hsas = hsa_supply_points_below(request.location)
    r = []
    for p in ProductStock.objects.filter(
            is_active=True,
            supply_point__in=hsas,
            quantity__lte=F('product__emergency_order_level')):
        if not StockRequest.pending_requests().filter(
                product=p.product, supply_point=p.supply_point).exists():
            r += [HSABelowEmergencyQuantityAlert(p.supply_point, p.product)]
    return r
Exemplo n.º 9
0
    def handle_custom(self, text):
        now = datetime.utcnow()
        pending_reqs = StockRequest.pending_requests().filter(
            supply_point=self.hsa.supply_point)
        for req in pending_reqs:
            req.approve(self.msg.logistics_contact, now, req.amount_requested)

        self.respond(config.Messages.APPROVAL_RESPONSE, hsa=self.hsa.name)
        self.hsa.message(config.Messages.APPROVAL_NOTICE, hsa=self.hsa.name)

        # this is really hacky, but set the SoH to non-zero for the reported products
        # so that they show no longer stocked out in things like alerts
        for req in pending_reqs:
            if self.msg.logistics_contact.supply_point.stock(req.product) == 0:
                self.msg.logistics_contact.supply_point.update_stock(
                    req.product, 1)
Exemplo n.º 10
0
    def handle_custom(self, text):
        now = datetime.utcnow()

        # Currently we just mark these stock requests stocked out.
        # Note that this has a different meaning for emergency orders
        # in which case we only confirm the emergency products.
        # However in the interest of simplicity we won't worry about that (yet?).
        pending_reqs = StockRequest.pending_requests().filter(
            supply_point=self.hsa.supply_point)
        for req in pending_reqs:
            req.mark_stockout(self.msg.logistics_contact, now)

        # if there were any emergency orders, only report those as stockouts
        # this is pretty confusing/hacky
        emergencies = pending_reqs.filter(is_emergency=True)
        stockouts = pending_reqs.filter(balance=0)
        if stockouts.count() > 0:
            reqs = stockouts
        elif emergencies.count() > 0:
            reqs = emergencies
        else:
            reqs = pending_reqs

        def _message_supervisors(message):
            supplier = self.msg.logistics_contact.supply_point.supplied_by
            if supplier is not None:
                supervisors = Contact.objects.filter(
                    is_active=True,
                    supply_point__location=supplier.location,
                    role__in=[
                        ContactRole.objects.get(
                            code=config.Roles.DISTRICT_PHARMACIST),
                        ContactRole.objects.get(
                            code=config.Roles.IMCI_COORDINATOR)
                    ])
                # note that if there are no supervisors registered, this will silently
                # not send notifications
                for super in supervisors:
                    super.message(message,
                                  contact=self.msg.logistics_contact.name,
                                  supply_point=self.msg.logistics_contact.
                                  supply_point.name,
                                  products=", ".join(req.product.sms_code
                                                     for req in reqs))

        if emergencies.count() > 0:
            # Unable to resupply stocked out/emergency products.
            self.respond(config.Messages.HF_UNABLE_RESTOCK_EO,
                         products=", ".join(req.product.sms_code
                                            for req in reqs))
            self.hsa.message(config.Messages.HSA_UNABLE_RESTOCK_EO,
                             hsa=self.hsa.name,
                             products=", ".join(req.product.sms_code
                                                for req in reqs))
            if stockouts.count() > 0:
                _message_supervisors(
                    config.Messages.DISTRICT_UNABLE_RESTOCK_STOCKOUT)
            else:
                _message_supervisors(
                    config.Messages.DISTRICT_UNABLE_RESTOCK_EO)
        else:
            self.respond(config.Messages.HF_UNABLE_RESTOCK_EO,
                         products=", ".join(req.product.sms_code
                                            for req in reqs))
            self.hsa.message(config.Messages.HSA_UNABLE_RESTOCK_ANYTHING,
                             hsa=self.hsa.name)
            _message_supervisors(
                config.Messages.DISTRICT_UNABLE_RESTOCK_NORMAL)

        # this is pretty hacky, but set the SoH to 0 for the stocked out products
        # so that they show properly in things like alerts
        for req in reqs:
            self.msg.logistics_contact.supply_point.update_stock(
                req.product, 0)
Exemplo n.º 11
0
def _get_resupply_amounts(hsa):
    return [req.sms_format() for req in StockRequest.pending_requests().filter(supply_point=hsa.supply_point)]
Exemplo n.º 12
0
def _get_resupply_amounts(hsa):
    return [
        req.sms_format() for req in StockRequest.pending_requests().filter(
            supply_point=hsa.supply_point)
    ]