Exemple #1
0
 def wrapper (self, message, *args):
     x = Provider.by_mobile(message.peer)
     if x and x.admin:
         return func(self, message, *args)
     else:
         message.respond(_(u"Sorry, only administrators of the system can perform this action."))
         return False
Exemple #2
0
    def cancel_request (self, message, cancel_id):
        ''' Cancel a transfer request
            CANCEL 908432'''
        
        # retrieve transaction
        try:
            log = TransferLog.objects.get(id=int(cancel_id))
        except TransferLog.DoesNotExist:
            message.respond(_(u"Cancellation failed. Provided transaction ID (%(lid)s) is wrong.") % {'lid': cancel_id})
            return True

        # Check request is legitimate
        peer    = Provider.by_mobile(message.peer).storeprovider_ptr
        if peer == None or (log.sender, log.receiver).count(peer) == 0:
            message.respond(_("Cancellation failed. With all due respect, you are not allowed to perform this action."))
            return True

        # Check is transfer hasn't already been cancelled
        if (TransferLog.STATUS_CANCELLED, TransferLog.STATUS_CONFLICT).count(log.status) != 0 :
            message.respond(_("Cancellation failed. Transfer #%(lid)s dated %(date)s has already been cancelled or is in conflict.") % {'lid': log.id, 'date': log.date.strftime("%b %d %y %H:%M")})
            return True
        
        # cancellation attempt
        other_peer  = log.receiver if peer == log.sender else log.sender

        # if peer is a patient, don't send messages
        try:
            peer_is_patient = not other_peer.direct().mobile
        except Provider.DoesNotExist:
            peer_is_patient = True

        try:
            cancel_transfer(log)
            msg = _(u"CANCELLED Transfer #%(lid)s dated %(date)s by request of %(peer)s. Please forward conflict to Drug Store Head.") % {'lid': log.id, 'date': log.date.strftime("%b %d %y %H:%M"), 'peer': peer.direct().display_full()}
            message.respond(msg)
            if not peer_is_patient:
                message.forward(other_peer.direct().mobile, msg)
        except (ItemNotInStore, NotEnoughItemInStock):
            # goods has been transfered elsewhere.
            msg = _(u"Cancellation failed. %(peer)s has started distributing drugs from transaction #%(lid)s. Contact Drug Store Head.") % {'lid': log.id, 'peer': peer.direct().display_full()}
            message.respond(msg)
            if not peer_is_patient:
                message.forward(other_peer.direct().mobile, msg)
        except Provider.DoesNotExist:
            pass
        return True
Exemple #3
0
    def register_provider (self, message, role, password, last, first, alias, mobile):
        ''' Adds people into the system 
            JOIN CHW PASSWORD LAST FIRST ALIAS'''
        
        # If error in role, assume CHW
        role    = role.upper()
        if role == 'PHA':
            role    = Provider.PHA_ROLE
        else:
            role    = Provider.CHW_ROLE

        # retrieve clinic
        clinic      = Facility.by_alias(password)
        
        # PHA _must_ be affiliated to a Clinic
        if role == Provider.PHA_ROLE and clinic == None:
            message.respond(_(u"Registration Failed. PHA needs correct clinic ID. '%(input)s' is not.") % {'input': password})
            return True

        # Verify alias availability
        dumb    = Provider.by_alias(alias)
        if not dumb == None:
            message.respond(_(u"Registration Failed. Alias already in use by %(prov)s") % {'prov': dumb.display_full()})
            return True

        # Verify mobile slot
        dumb    = Provider.by_mobile(mobile)
        if not dumb == None:
            message.respond(_(u"Registration Failed. mobile number already in use by %(prov)s") % {'prov': dumb.display_full()})
            return True
        
        # Create provier
        provider    = Provider(alias=alias, first_name=first, last_name=last, role=role, active=True, clinic=clinic, mobile=mobile)
        provider.save()

        # send notifications
        message.respond(_(u"SUCCESS. %(prov)s has been registered with alias %(al)s.") % {'prov': provider.display_full(), 'al': provider.alias})
        
        if not provider.mobile == None:
            message.forward(provider.mobile, _(u"Welcome %(prov)s. You have been registered with alias %(al)s.") % {'prov': provider.display_full(), 'al': provider.alias})
    
        return True
Exemple #4
0
 def wrapper (self, message, *args):
     if Provider.by_mobile(message.peer):
         return func(self, message, *args)
     else:
         message.respond(_(u"Sorry, only registered users can access this program."))
         return True