Beispiel #1
0
    def dispense_drug_patient (self, message, first, last, gender, age, code, quantity):

        age     = Patient.age_from_str(age)
        gender  = Patient.SEXE_MALE if gender.upper() == 'M' else Patient.SEXE_FEMALE
        receiver= Patient(first_name=first, last_name=last, sexe=gender,age=age)
        receiver.save()
        sender      = StoreProvider.cls().by_mobile(message.peer)
        item        = Item.by_code(code)

        if item == None or sender == None or receiver == None:
            message.respond(_(u"Dispense request failed. Either Item ID or Patient datas are wrong."))
            return True

        try:
            log = transfer_item(sender=sender, receiver=receiver, item=item, quantity=int(quantity))
        except ItemNotInStore:
            message.respond(_(u"Dispense request failed. You do not have %(med)s") % {'med': item})
            return True
        except NotEnoughItemInStock:
            message.respond(_(u"Dispense request failed. You can't dispense %(q)s %(it)s to %(rec)s because you only have %(stk)s.") % {'q': quantity, 'it': item.name, 'rec': receiver.display_full(), 'stk': StockItem.objects.get(peer=sender, item=item).quantity})
            return True

        message.respond("CONFIRMATION #%(d)s-%(sid)s-%(rid)s-%(lid)s You have dispensed %(quantity)s %(item)s to %(receiver)s. If not correct please reply: CANCEL %(lid)s" % {
            'quantity': quantity,
            'item': item.name,
            'receiver': receiver.display_full(),
            'd': log.date.strftime("%d%m%y"),
            'sid': sender.id,
            'rid': receiver.id,
            'lid': log.id
        })
        return True
Beispiel #2
0
    def add_stock (self, message, code, quantity, note):
        
        ''' Add stock for item. Used by main drug distribution point'''
        
        sender      = StoreProvider.cls().by_mobile(message.peer)
        receiver = sender
        #receiver   = StoreProvider.cls().by_alias(receiver)
        item        = Item.by_code(code)
        if item == None or sender == None or receiver == None:
            message.respond(_(u"Distribution request failed. Either Item ID or CHW alias is wrong."))
            return True
        
        try:
            log = add_stock_for_item(receiver=receiver, item=item, quantity=int(quantity))
        
            message.respond("CONFIRMATION #%(d)s-%(sid)s-%(lid)s You have added %(quantity)s %(item)s to your stock. If not correct please reply: CANCEL %(lid)s" % {
            'quantity': quantity,
            'item': item.name,
            'receiver': receiver.display_full(),
            'd': log.date.strftime("%d%m%y"),
            'sid': sender.id,
            'rid': receiver.id,
            'lid': log.id
            })
        except:
            pass

        return True
Beispiel #3
0
    def transfer_clinic_chw(self, message, receiver, code, quantity):
        """ Transfer Drug from Clinic to CHW or CHW to Clinic
            DIST @mdiallo #001 10"""

        sender = StoreProvider.cls().objects.get(id=message.persistant_connection.reporter.id)
        receiver = StoreProvider.cls().objects.get(alias=receiver.lower())
        item = Item.by_code(code)
        if item == None or sender == None or receiver == None:
            message.respond(_(u"Distribution request failed. Either Item ID or CHW alias is wrong."))
            return True

        try:
            return self.do_transfer_drug(message, sender, receiver, item, quantity)
        except ItemNotInStore:
            message.respond(_(u"Distribution request failed. You do not have %(med)s") % {"med": item})
            return True
        except NotEnoughItemInStock:
            message.respond(
                _(
                    u"Distribution request failed. You can't transfer %(q)s %(it)s to %(rec)s because you only have %(stk)s."
                )
                % {
                    "q": quantity,
                    "it": item.name,
                    "rec": receiver.display_full(),
                    "stk": StockItem.objects.get(peer=sender, item=item).quantity,
                }
            )
            return True
Beispiel #4
0
 def parse_sku_quantities(self, sku_quantities):
     couples  = sku_quantities.split(" %s" % self.drug_code)
     skq = {}
     try:
         for couple in couples:
             x = couple.split(" ")
             code = x[0].replace(self.drug_code, "")
             item = Item.by_code(code)
             if skq.has_key(code) or item == None:
                 raise MalformedRequest
             skq[code]   = {'code': code, 'quantity': int(x[1]), 'item': item}
         return skq
     except IndexError:
         raise MalformedRequest
Beispiel #5
0
    def transfer_clinic_chw (self, message, receiver, code, quantity):
        ''' Transfer Drug from Clinic to CHW or CHW to Clinic
            DIST @mdiallo #001 10'''
        
        sender      = StoreProvider.cls().by_mobile(message.peer)
        receiver   = StoreProvider.cls().by_alias(receiver)
        item        = Item.by_code(code)
        if item == None or sender == None or receiver == None:
            message.respond(_(u"Distribution request failed. Either Item ID or CHW alias is wrong."))
            return True

        try:
            return self.do_transfer_drug(message, sender, receiver, item, quantity)
        except ItemNotInStore:
            message.respond(_(u"Distribution request failed. You do not have %(med)s") % {'med': item})
            return True
        except NotEnoughItemInStock:
            message.respond(_(u"Distribution request failed. You can't transfer %(q)s %(it)s to %(rec)s because you only have %(stk)s.") % {'q': quantity, 'it': item.name, 'rec': receiver.display_full(), 'stk': StockItem.objects.get(peer=sender, item=item).quantity})
            return True
Beispiel #6
0
    def add_stock(self, message, code, quantity, note):

        """ Add stock for item. Used by main drug distribution point"""

        sender = StoreProvider.cls().objects.get(id=message.persistant_connection.reporter.id)

        # only PHA can add drugs
        try:
            no_pha = not sender.direct().role == Role.objects.get(code="pha")
        except:
            no_pha = True

        if no_pha:
            message.respond(_(u"Addition request failed. Only PHA can perform such action."))
            return True

        receiver = sender
        item = Item.by_code(code)
        if item == None or sender == None or receiver == None:
            message.respond(_(u"Addition request failed. Either Item ID or CHW alias is wrong."))
            return True

        try:
            log = add_stock_for_item(receiver=receiver, item=item, quantity=int(quantity))

            message.respond(
                "CONFIRMATION #%(d)s-%(sid)s-%(lid)s You have added %(quantity)s %(item)s to your stock. If not correct please reply: CANCEL %(lid)s"
                % {
                    "quantity": quantity,
                    "item": item.name,
                    "receiver": receiver.display_full(),
                    "d": log.date.strftime("%d%m%y"),
                    "sid": sender.id,
                    "rid": receiver.id,
                    "lid": log.id,
                }
            )
        except:
            pass

        return True