Example #1
0
 def testReportEmergencyForAnotherHSA(self):
     create_manager(self, "16175551234", "charles", role="ic")
     create_hsa(self, "16175551000", "joe")
     create_hsa(self, "16175551001", "phoneless", "2")
     a = """
        16175551000 > report 261602 eo zi 40 la 200 
        16175551000 < %(response)s
        16175551234 < %(super)s
     """ % {"response": config.Messages.EMERGENCY_SOH % \
            {"products": "zi la"},
            "super": config.Messages.SUPERVISOR_EMERGENCY_SOH_NOTIFICATION % \
            {"hsa": "phoneless", "emergency_products": "zi 160",
             "normal_products": "la 160",
             "hsa_id": "261602"}}
     self.runScript(a)
     hsa_sp = SupplyPoint.objects.get(code="261602")
     self.assertEqual(
         40,
         ProductStock.objects.get(supply_point=hsa_sp,
                                  product__sms_code="zi").quantity)
     self.assertEqual(
         200,
         ProductStock.objects.get(supply_point=hsa_sp,
                                  product__sms_code="la").quantity)
     self.assertEqual(2, StockRequest.objects.count())
     for req in StockRequest.objects.all():
         self.assertEqual(hsa_sp, req.supply_point)
         self.assertEqual(StockRequestStatus.REQUESTED, req.status)
         self.assertTrue(req.is_pending())
         if req.is_emergency:
             self.assertTrue(Product.by_code("zi"), req.product)
         else:
             self.assertTrue(Product.by_code("la"), req.product)
Example #2
0
 def testReportEmergencyForAnotherHSA(self):
     create_manager(self, "16175551234", "charles", role="ic")
     create_hsa(self, "16175551000", "joe")
     create_hsa(self, "16175551001", "phoneless", "2")
     a = """
        16175551000 > report 261602 eo zi 40 la 200 
        16175551000 < %(response)s
        16175551234 < %(super)s
     """ % {"response": config.Messages.EMERGENCY_SOH % \
            {"products": "zi la"},
            "super": config.Messages.SUPERVISOR_EMERGENCY_SOH_NOTIFICATION % \
            {"hsa": "phoneless", "emergency_products": "zi 160",
             "normal_products": "la 160",
             "hsa_id": "261602"}}
     self.runScript(a)
     hsa_sp = SupplyPoint.objects.get(code="261602")
     self.assertEqual(40, ProductStock.objects.get(supply_point=hsa_sp, product__sms_code="zi").quantity)
     self.assertEqual(200, ProductStock.objects.get(supply_point=hsa_sp, product__sms_code="la").quantity)
     self.assertEqual(2, StockRequest.objects.count())
     for req in StockRequest.objects.all():
         self.assertEqual(hsa_sp, req.supply_point)
         self.assertEqual(StockRequestStatus.REQUESTED, req.status)
         self.assertTrue(req.is_pending())
         if req.is_emergency:
             self.assertTrue(Product.by_code("zi"), req.product)
         else:
             self.assertTrue(Product.by_code("la"), req.product)
Example #3
0
    def testBasicTransfer(self):
        create_hsa(self, "16175551000", "wendy", products="zi")
        create_hsa(self, "16175551001", "steve", id="2", products="zi")
        a = """
           16175551000 > soh zi 100
           16175551000 < %(no_super)s
           16175551001 > soh zi 10
           16175551001 < %(no_super)s
        """ % {
            "no_super": config.Messages.NO_IN_CHARGE % {
                "supply_point": "Ntaja"
            }
        }
        self.runScript(a)
        stock_from = ProductStock.objects.get(
            supply_point=SupplyPoint.objects.get(code="261601"),
            product=Product.by_code("zi"))
        stock_to = ProductStock.objects.get(
            supply_point=SupplyPoint.objects.get(code="261602"),
            product=Product.by_code("zi"))
        self.assertEqual(100, stock_from.quantity)
        self.assertEqual(10, stock_to.quantity)

        b = """
           16175551000 > give 261602 zi 20
           16175551000 < %(confirm)s
           16175551001 < Confirm receipt of zi 20 from wendy? Please respond 'confirm'
        """ % {"confirm": config.Messages.TRANSFER_RESPONSE % \
                    {"giver": "wendy", "receiver": "steve",
                     "reporter": "wendy", "products": "zi 20"}}
        self.runScript(b)
        self.assertEqual(80,
                         ProductStock.objects.get(pk=stock_from.pk).quantity)
        self.assertEqual(10, ProductStock.objects.get(pk=stock_to.pk).quantity)
        [st] = StockTransfer.objects.all()
        self.assertTrue(st.is_pending())
        self.assertEqual(20, st.amount)
        self.assertEqual(Product.by_code("zi"), st.product)
        self.assertEqual(SupplyPoint.objects.get(code="261601"), st.giver)
        self.assertEqual(SupplyPoint.objects.get(code="261602"), st.receiver)

        c = """
           16175551001 > confirm
           16175551001 < Thank you steve. You have confirmed receipt of the following products: zi 20
        """
        self.runScript(c)
        self.assertEqual(80,
                         ProductStock.objects.get(pk=stock_from.pk).quantity)
        self.assertEqual(30, ProductStock.objects.get(pk=stock_to.pk).quantity)
        [st] = StockTransfer.objects.all()
        self.assertTrue(st.is_closed())
Example #4
0
 def testBasicTransfer(self):
     create_hsa(self, "16175551000", "wendy", products="zi")
     create_hsa(self, "16175551001", "steve", id="2", products="zi")
     a = """
        16175551000 > soh zi 100
        16175551000 < %(no_super)s
        16175551001 > soh zi 10
        16175551001 < %(no_super)s
     """ % {"no_super": config.Messages.NO_IN_CHARGE % {"supply_point": "Ntaja"}}
     self.runScript(a)
     stock_from = ProductStock.objects.get(supply_point=SupplyPoint.objects.get(code="261601"), 
                                           product=Product.by_code("zi"))
     stock_to = ProductStock.objects.get(supply_point=SupplyPoint.objects.get(code="261602"), 
                                         product=Product.by_code("zi"))
     self.assertEqual(100, stock_from.quantity)
     self.assertEqual(10, stock_to.quantity)
     
     b = """
        16175551000 > give 261602 zi 20
        16175551000 < %(confirm)s
        16175551001 < Confirm receipt of zi 20 from wendy? Please respond 'confirm'
     """ % {"confirm": config.Messages.TRANSFER_RESPONSE % \
                 {"giver": "wendy", "receiver": "steve", 
                  "reporter": "wendy", "products": "zi 20"}}
     self.runScript(b)
     self.assertEqual(80, ProductStock.objects.get(pk=stock_from.pk).quantity)
     self.assertEqual(10, ProductStock.objects.get(pk=stock_to.pk).quantity)
     [st] = StockTransfer.objects.all()
     self.assertTrue(st.is_pending())
     self.assertEqual(20, st.amount)
     self.assertEqual(Product.by_code("zi"), st.product)
     self.assertEqual(SupplyPoint.objects.get(code="261601"), st.giver)
     self.assertEqual(SupplyPoint.objects.get(code="261602"), st.receiver)
     
     c = """
        16175551001 > confirm
        16175551001 < Thank you steve. You have confirmed receipt of the following products: zi 20
     """
     self.runScript(c)
     self.assertEqual(80, ProductStock.objects.get(pk=stock_from.pk).quantity)
     self.assertEqual(30, ProductStock.objects.get(pk=stock_to.pk).quantity)
     [st] = StockTransfer.objects.all()
     self.assertTrue(st.is_closed())
Example #5
0
def load_products(file_path, log_to_console=True):
    if log_to_console: print "loading static products from %s" % file_path
    # give django some time to bootstrap itself
    if not os.path.exists(file_path):
        raise LoaderException("Invalid file path: %s." % file_path)

    def _int_or_nothing(val):
        try:
            return int(val)
        except ValueError:
            return None

    csv_file = open(file_path, 'r')
    try:
        count = 0
        for line in csv_file:
            # leave out first line
            if "product name" in line.lower():
                continue
            #Product Name,Code,Dose,AMC,Family,Formulation,EOP Quantity,# of patients a month,
            name, code, dose, monthly_consumption, typename, form, eop_quant, num_pats = line.strip(
            ).split(",")
            #create/load type
            type = ProductType.objects.get_or_create(name=typename,
                                                     code=typename.lower())[0]

            try:
                product = Product.objects.get(sms_code=code.lower())
            except Product.DoesNotExist:
                product = Product(sms_code=code.lower())
            product.name = name
            product.description = name  # todo
            product.type = type
            product.average_monthly_consumption = _int_or_nothing(
                monthly_consumption)
            product.emergency_order_level = _int_or_nothing(eop_quant)
            product.save()

            count += 1

        if log_to_console: print "Successfully processed %s products." % count

    finally:
        csv_file.close()
Example #6
0
def load_products(file_path, log_to_console=True):
    if log_to_console: print "loading static products from %s" % file_path
    # give django some time to bootstrap itself
    if not os.path.exists(file_path):
        raise LoaderException("Invalid file path: %s." % file_path)
    
    def _int_or_nothing(val):
        try:
            return int(val)
        except ValueError:
            return None
        
    csv_file = open(file_path, 'r')
    try:
        count = 0
        for line in csv_file:
            # leave out first line
            if "product name" in line.lower():
                continue
            #Product Name,Code,Dose,AMC,Family,Formulation,EOP Quantity,# of patients a month,
            name, code, dose, monthly_consumption, typename, form, eop_quant, num_pats = line.strip().split(",")
            #create/load type
            type = ProductType.objects.get_or_create(name=typename, code=typename.lower())[0]
            
            try:
                product = Product.objects.get(sms_code=code.lower())
            except Product.DoesNotExist:
                product = Product(sms_code=code.lower())
            product.name = name
            product.description = name # todo
            product.type = type
            product.average_monthly_consumption = _int_or_nothing(monthly_consumption)
            product.emergency_order_level = _int_or_nothing(eop_quant)
            product.save()
            
            count += 1
    
        if log_to_console: print "Successfully processed %s products." % count
    
    finally:
        csv_file.close()
Example #7
0
 def testReportEmergencyTransfers(self):
     create_hsa(self, "16175551000", "giver")
     create_hsa(self, "16175551001", "receiver", "2")
     create_hsa(self, "16175551002", "reporter", "3")
     a = """
        16175551002 > report 261601 give 261602 zi 20
        16175551002 < %(response)s
        16175551001 < %(receive)s
     """ % {"response": config.Messages.TRANSFER_RESPONSE % \
            {"reporter": "reporter", "giver": "giver",
             "receiver": "receiver", "products": "zi 20"},
            "receive": config.Messages.TRANSFER_CONFIRM % \
            {"products": "zi 20", "giver": "giver"}}
     self.runScript(a)
     [st] = StockTransfer.objects.all()
     self.assertTrue(st.is_pending())
     self.assertEqual(20, st.amount)
     self.assertEqual(Product.by_code("zi"), st.product)
     self.assertEqual(SupplyPoint.objects.get(code="261601"), st.giver)
     self.assertEqual(SupplyPoint.objects.get(code="261602"), st.receiver)
Example #8
0
 def testReportEmergencyTransfers(self):
     create_hsa(self, "16175551000", "giver")
     create_hsa(self, "16175551001", "receiver", "2")
     create_hsa(self, "16175551002", "reporter", "3")
     a = """
        16175551002 > report 261601 give 261602 zi 20
        16175551002 < %(response)s
        16175551001 < %(receive)s
     """ % {"response": config.Messages.TRANSFER_RESPONSE % \
            {"reporter": "reporter", "giver": "giver", 
             "receiver": "receiver", "products": "zi 20"},
            "receive": config.Messages.TRANSFER_CONFIRM % \
            {"products": "zi 20", "giver": "giver"}}
     self.runScript(a)
     [st] = StockTransfer.objects.all()
     self.assertTrue(st.is_pending())
     self.assertEqual(20, st.amount)
     self.assertEqual(Product.by_code("zi"), st.product)
     self.assertEqual(SupplyPoint.objects.get(code="261601"), st.giver)
     self.assertEqual(SupplyPoint.objects.get(code="261602"), st.receiver)