コード例 #1
0
 def setUp(self):
     TestScript.setUp(self)
     location = Location.objects.get(code='de')
     facilitytype = SupplyPointType.objects.get(code='hc')
     facility, created = SupplyPoint.objects.get_or_create(
         code='dedh',
         name='Dangme East District Hospital',
         location=location,
         active=True,
         type=facilitytype,
         supplied_by=None)
     mc = Product.objects.get(sms_code='mc')
     lf = Product.objects.get(sms_code='lf')
     mg = Product.objects.get(sms_code='mg')
     ng = Product.objects.get(sms_code='ng')
     ProductStock(is_active=True,
                  product=mc,
                  supply_point=facility,
                  monthly_consumption=5).save()
     ProductStock(is_active=True,
                  product=lf,
                  supply_point=facility,
                  monthly_consumption=5).save()
     ProductStock(is_active=True,
                  product=mg,
                  supply_point=facility,
                  monthly_consumption=5).save()
     ProductStock(is_active=False,
                  product=ng,
                  supply_point=facility,
                  monthly_consumption=5).save()
     contact = register_user(self, "888", "testuser", "dedh")
     contact.commodities.add(mc)
     contact.commodities.add(lf)
コード例 #2
0
def _load_DELIVER_products_into_facility(fac, max_facility_consumption,
                                         facility_consumption):
    from logistics.models import Product, ProductStock
    commodity_codes = [
        'zt', 'lt', 'ef', 'nv', 'te', 'em', 'zs', 'co', 'fr', 'oq', 'rs'
    ]
    for code in commodity_codes:
        product = Product.objects.get(sms_code=code)
        try:
            ps = ProductStock.objects.get(supply_point=fac, product=product)
        except ProductStock.DoesNotExist:
            # no preexisting product stock, which is fine.
            pass
        else:
            print "ProductStock %s for %s already exists!" % (product.name,
                                                              fac.name)
            continue
        # facilities get all products by default active, 10 stock
        ProductStock(quantity=None,
                     is_active=True,
                     supply_point=fac,
                     product=product,
                     monthly_consumption=facility_consumption,
                     use_auto_consumption=False).save()
    print "Products loaded into %s" % fac.name
コード例 #3
0
ファイル: stockonhand.py プロジェクト: andile2012/logistics
    def setUp(self):
        settings.LOGISTICS_STOCKED_BY = 'user'
        TestScript.setUp(self)
        location = Location.objects.get(code='de')
        facilitytype = SupplyPointType.objects.get(code='hc')
        self.rms = SupplyPoint.objects.get(code='garms')
        facility, created = SupplyPoint.objects.get_or_create(code='dedh',
                                                           name='Dangme East District Hospital',
                                                           location=location, active=True,
                                                           type=facilitytype, supplied_by=self.rms)
        assert facility.supplied_by == self.rms
        mc = Product.objects.get(sms_code='mc')
        self.lf = Product.objects.get(sms_code='lf')
        ProductStock(product=mc, supply_point=facility,
                     monthly_consumption=8).save()
        ProductStock(product=self.lf, supply_point=facility,
                     monthly_consumption=5).save()
        facility = SupplyPoint(code='tf', name='Test Facility',
                       location=location, active=True,
                       type=facilitytype, supplied_by=self.rms)
        facility.save()
        mc = Product.objects.get(sms_code='mc')
        mg = Product.objects.get(sms_code='mg')
        self.mc_stock = ProductStock(is_active=True, supply_point=facility,
                                    product=mc, monthly_consumption=10)
        self.mc_stock.save()
        self.lf_stock = ProductStock(is_active=True, supply_point=facility,
                                    product=self.lf, monthly_consumption=10)
        self.lf_stock.save()
        self.mg_stock = ProductStock(is_active=False, supply_point=facility,
                                     product=mg, monthly_consumption=10)
        self.mg_stock.save()

        ng = Product.objects.get(sms_code='ng')
        self.ng_stock = ProductStock(is_active=True, supply_point=facility,
                                    product=ng, monthly_consumption=None)
        self.ng_stock.save()
        
        self.contact = Contact(name='test user')
        self.contact.save()
        self.connection = Connection(backend=Backend.objects.all()[0],
                                     identity="888",
                                     contact=self.contact)
        self.connection.save()
        self.contact.supply_point = facility
        self.contact.save()
        self.contact.commodities.add(ng)
コード例 #4
0
def LoadProductsIntoFacilities(demo=False):
    from logistics.models import SupplyPoint, ProductStock, Product
    facilities = SupplyPoint.objects.order_by('type')
    print facilities.count()

    if demo:
        RMS_consumption = 100
        max_RMS_consumption = 330
        facility_consumption = 10
        max_facility_consumption = 33
    else:
        RMS_consumption = None
        max_RMS_consumption = 0
        facility_consumption = None
        max_facility_consumption = 0
    for fac in facilities:
        products = Product.objects.all()
        for product in products:
            try:
                ps = ProductStock.objects.get(supply_point=fac,
                                              product=product)
            except ProductStock.DoesNotExist:
                # no preexisting product stock, which is fine.
                pass
            else:
                ps.delete()
            if fac.type.code == config.SupplyPointCodes.REGIONAL_MEDICAL_STORE:
                # RMS get all products by default active, 100 stock
                ProductStock(quantity=random.randint(0, max_RMS_consumption),
                             supply_point=fac,
                             product=product,
                             monthly_consumption=RMS_consumption).save()
            else:
                # facilities get all products by default active, 10 stock
                ProductStock(quantity=random.randint(0,
                                                     max_facility_consumption),
                             is_active=demo,
                             supply_point=fac,
                             product=product,
                             monthly_consumption=facility_consumption).save()
        print "Loaded products into %(fac)s" % {'fac': fac.name}
コード例 #5
0
ファイル: util.py プロジェクト: dslowikowski/logistics
def add_products(contact, products):
    """
    Adds products to a contact
    """
    for product_code in products:
        product = Product.objects.get(sms_code__iexact=product_code)
        if not ProductStock.objects.filter(supply_point=contact.supply_point,
                                           product=product).exists():
            ProductStock(supply_point=contact.supply_point,
                         product=product).save()
            contact.commodities.add(product)
    contact.save()
コード例 #6
0
 def handle(self, text):
     words = text.split(" ")
     if not len(words):
         return self.help()
     self.hsa = self.msg.logistics_contact.supply_point
     for code in words:
         if not Product.objects.filter(sms_code__iexact=code).exists():
             self.respond_error(config.Messages.UNKNOWN_CODE, product=code)
             return
     for f in [
             Product.objects.get(sms_code__iexact=code) for code in words
     ]:
         if not ProductStock.objects.filter(supply_point=self.hsa,
                                            product=f).exists():
             ProductStock(supply_point=self.hsa, product=f).save()
         self.msg.logistics_contact.commodities.add(f)
         self.hsa.activate_product(f)
     self.msg.logistics_contact.save()
     self.respond(config.Messages.ADD_SUCCESS_MESSAGE, products=" ".join\
                     (self.msg.logistics_contact.commodities.values_list\
                         ("sms_code", flat=True).order_by("sms_code")))
コード例 #7
0
def load_products_into_facilities(demo=False):
    import random
    from logistics.models import SupplyPoint, ProductStock, Product
    facilities = SupplyPoint.objects.order_by('type')
    if demo:
        facility_consumption = 10
        max_facility_consumption = 33
    else:
        facility_consumption = None
    for fac in facilities:
        ps_loaded = 0
        products = Product.objects.all()
        for product in products:
            try:
                ps = ProductStock.objects.get(supply_point=fac,
                                              product=product)
            except ProductStock.DoesNotExist:
                # no preexisting product stock, which is fine.
                pass
            else:
                # don't touch product stocks which exist already
                continue
            # facilities get all products by default active, 10 stock
            quantity = None
            if demo:
                quantity = random.randint(0, max_facility_consumption)
            ProductStock(quantity=quantity,
                         is_active=True,
                         supply_point=fac,
                         product=product,
                         monthly_consumption=facility_consumption).save()
            ps_loaded += 1
        if ps_loaded > 0:
            print "Loaded %(count)s stocks into %(fac)s" % {
                'count': ps_loaded,
                'fac': fac.name
            }
コード例 #8
0
ファイル: stockonhand.py プロジェクト: dslowikowski/logistics
    def setUp(self):
        settings.LOGISTICS_STOCKED_BY = 'user'
        TestScript.setUp(self)
        location = Location.objects.get(code='de')
        facilitytype = SupplyPointType.objects.get(code='hc')
        self.rms = SupplyPoint.objects.get(code='garms')
        facility, created = SupplyPoint.objects.get_or_create(
            code='dedh',
            name='Dangme East District Hospital',
            location=location,
            active=True,
            type=facilitytype,
            supplied_by=self.rms)
        assert facility.supplied_by == self.rms
        mc = Product.objects.get(sms_code='mc')
        self.lf = Product.objects.get(sms_code='lf')
        ProductStock(product=mc, supply_point=facility,
                     monthly_consumption=8).save()
        ProductStock(product=self.lf,
                     supply_point=facility,
                     monthly_consumption=5).save()
        facility = SupplyPoint(code='tf',
                               name='Test Facility',
                               location=location,
                               active=True,
                               type=facilitytype,
                               supplied_by=self.rms)
        facility.save()
        mc = Product.objects.get(sms_code='mc')
        mg = Product.objects.get(sms_code='mg')
        self.mc_stock = ProductStock(is_active=True,
                                     supply_point=facility,
                                     product=mc,
                                     monthly_consumption=10)
        self.mc_stock.save()
        self.lf_stock = ProductStock(is_active=True,
                                     supply_point=facility,
                                     product=self.lf,
                                     monthly_consumption=10)
        self.lf_stock.save()
        self.mg_stock = ProductStock(is_active=False,
                                     supply_point=facility,
                                     product=mg,
                                     monthly_consumption=10)
        self.mg_stock.save()

        ng = Product.objects.get(sms_code='ng')
        self.ng_stock = ProductStock(is_active=True,
                                     supply_point=facility,
                                     product=ng,
                                     monthly_consumption=None)
        self.ng_stock.save()

        self.contact = Contact(name='test user')
        self.contact.save()
        self.connection = Connection(backend=Backend.objects.all()[0],
                                     identity="888",
                                     contact=self.contact)
        self.connection.save()
        self.contact.supply_point = facility
        self.contact.save()
        self.contact.commodities.add(ng)
コード例 #9
0
ファイル: stockonhand.py プロジェクト: dslowikowski/logistics
class TestStockOnHand(TestScript):
    apps = ([logistics_app.App])
    fixtures = ["ghana_initial_data.json"]

    def setUp(self):
        settings.LOGISTICS_STOCKED_BY = 'user'
        TestScript.setUp(self)
        location = Location.objects.get(code='de')
        facilitytype = SupplyPointType.objects.get(code='hc')
        self.rms = SupplyPoint.objects.get(code='garms')
        facility, created = SupplyPoint.objects.get_or_create(
            code='dedh',
            name='Dangme East District Hospital',
            location=location,
            active=True,
            type=facilitytype,
            supplied_by=self.rms)
        assert facility.supplied_by == self.rms
        mc = Product.objects.get(sms_code='mc')
        self.lf = Product.objects.get(sms_code='lf')
        ProductStock(product=mc, supply_point=facility,
                     monthly_consumption=8).save()
        ProductStock(product=self.lf,
                     supply_point=facility,
                     monthly_consumption=5).save()
        facility = SupplyPoint(code='tf',
                               name='Test Facility',
                               location=location,
                               active=True,
                               type=facilitytype,
                               supplied_by=self.rms)
        facility.save()
        mc = Product.objects.get(sms_code='mc')
        mg = Product.objects.get(sms_code='mg')
        self.mc_stock = ProductStock(is_active=True,
                                     supply_point=facility,
                                     product=mc,
                                     monthly_consumption=10)
        self.mc_stock.save()
        self.lf_stock = ProductStock(is_active=True,
                                     supply_point=facility,
                                     product=self.lf,
                                     monthly_consumption=10)
        self.lf_stock.save()
        self.mg_stock = ProductStock(is_active=False,
                                     supply_point=facility,
                                     product=mg,
                                     monthly_consumption=10)
        self.mg_stock.save()

        ng = Product.objects.get(sms_code='ng')
        self.ng_stock = ProductStock(is_active=True,
                                     supply_point=facility,
                                     product=ng,
                                     monthly_consumption=None)
        self.ng_stock.save()

        self.contact = Contact(name='test user')
        self.contact.save()
        self.connection = Connection(backend=Backend.objects.all()[0],
                                     identity="888",
                                     contact=self.contact)
        self.connection.save()
        self.contact.supply_point = facility
        self.contact.save()
        self.contact.commodities.add(ng)

    def testProductReportsHelper(self):
        sdp = SupplyPoint()
        m = Message()
        p = ProductReportsHelper(sdp, Reports.SOH, m)
        p.add_product_stock('lf', 10, save=False)
        p.add_product_stock('mc', 30, save=False)
        p.add_product_stock('aa', 0, save=False)
        p.add_product_stock('oq', 0, save=False)
        self.assertEquals(p.all(), "lf 10, aa 0, oq 0, mc 30")
        self.assertEquals(p.stockouts(), "aa oq")
        my_iter = p._getTokens("ab10cd20")
        self.assertEquals(my_iter.next(), 'ab')
        self.assertEquals(my_iter.next(), '10')
        self.assertEquals(my_iter.next(), 'cd')
        self.assertEquals(my_iter.next(), '20')

    def testStockOnHand(self):
        a = """
           16176023315 > register stella dedh
           16176023315 < Congratulations stella, you have successfully been registered for the Early Warning System. Your facility is Dangme East District Hospital
           16176023315 > soh lf 10
           16176023315 < Dear stella, thank you for reporting the commodities you have in stock.
           16176023315 > soh lf 10 mc 20
           16176023315 < Dear stella, thank you for reporting the commodities you have in stock.
           16176023315 > SOH LF 10 MC 20
           16176023315 < Dear stella, thank you for reporting the commodities you have in stock.
           """
        self.runScript(a)

    def testNothing(self):
        a = """
           16176023315 > register stella dedh
           16176023315 < Congratulations stella, you have successfully been registered for the Early Warning System. Your facility is Dangme East District Hospital
           16176023315 >
           16176023315 < Sorry, I could not understand your message. Please contact your DHIO for help, or visit http://www.ewsghana.com
           16176023315 > soh
           16176023315 < To report stock on hand, send SOH [space] [product code] [space] [amount] 
           """
        self.runScript(a)

    def testStockout(self):
        a = """
           16176023315 > register cynthia dedh
           16176023315 < Congratulations cynthia, you have successfully been registered for the Early Warning System. Your facility is Dangme East District Hospital
           16176023315 > soh lf 0 mc 0
           16176023315 < Dear cynthia, these items are stocked out: lf mc. Please order 24 mc, 15 lf.
           """
        self.runScript(a)

    def testStockoutNoConsumption(self):
        a = """
           16176023315 > register cynthia dedh
           16176023315 < Congratulations cynthia, you have successfully been registered for the Early Warning System. Your facility is Dangme East District Hospital
           16176023315 > soh ng 0
           16176023315 < Dear cynthia, these items are stocked out: ng.
           """
        self.runScript(a)

    def testLowSupply(self):
        a = """
           16176023315 > register cynthia dedh
           16176023315 < Congratulations cynthia, you have successfully been registered for the Early Warning System. Your facility is Dangme East District Hospital
           16176023315 > soh lf 7 mc 9
           16176023315 < Dear cynthia, these items need to be reordered: lf mc. Please order 15 mc, 8 lf.
           """
        self.runScript(a)

    def testLowSupplyNoConsumption(self):
        a = """
           16176023315 > register cynthia dedh
           16176023315 < Congratulations cynthia, you have successfully been registered for the Early Warning System. Your facility is Dangme East District Hospital
           16176023315 > soh ng 3
           16176023315 < Dear cynthia, thank you for reporting the commodities you have in stock.
           """
        self.runScript(a)

    def testOverSupply(self):
        a = """
           16176023315 > register cynthia dedh
           16176023315 < Congratulations cynthia, you have successfully been registered for the Early Warning System. Your facility is Dangme East District Hospital
           16176023315 > soh lf 30 mc 40
           16176023315 < Dear cynthia, these items are overstocked: lf mc. The district admin has been informed.
           """
        self.runScript(a)

    def testSohAndReceipts(self):
        a = """
           16176023315 > register cynthia dedh
           16176023315 < Congratulations cynthia, you have successfully been registered for the Early Warning System. Your facility is Dangme East District Hospital
           16176023315 > soh lf 10 20 mc 20
           16176023315 < Dear cynthia, thank you for reporting the commodities you have. You received lf 20.
           """
        self.runScript(a)

    def testCombined1(self):
        a = """
           pharmacist > register cynthia tf
           pharmacist < Congratulations cynthia, you have successfully been registered for the Early Warning System. Your facility is Test Facility
           super > register super tf incharge
           super < Congratulations super, you have successfully been registered for the Early Warning System. Your facility is Test Facility
           pharmacist > soh lf 0 mc 1
           super < Dear super, Test Facility is experiencing the following problems: stockouts Lofem; below reorder level Male Condom
           pharmacist < Dear cynthia, these items are stocked out: lf. these items need to be reordered: mc. Please order 29 mc, 30 lf.
           """
        self.runScript(a)

    def testCombined2(self):
        a = """
           pharmacist > register cynthia tf
           pharmacist < Congratulations cynthia, you have successfully been registered for the Early Warning System. Your facility is Test Facility
           super > register super tf incharge
           super < Congratulations super, you have successfully been registered for the Early Warning System. Your facility is Test Facility
           pharmacist > mc 0 mg 1
           super < Dear super, Test Facility is experiencing the following problems: stockouts Male Condom; below reorder level Micro-G
           pharmacist < Dear cynthia, these items are stocked out: mc. these items need to be reordered: mg. Please order 30 mc, 29 mg.
           pharmacist > mc 0 mg 1 lf 100
           super < Dear super, Test Facility is experiencing the following problems: stockouts Male Condom; below reorder level Micro-G; overstocked Lofem
           pharmacist < Dear cynthia, these items are stocked out: mc. these items need to be reordered: mg. Please order 30 mc, 29 mg.
           """
        self.runScript(a)

    def testCombined3(self):
        a = """
           pharmacist > register cynthia tf
           pharmacist < Congratulations cynthia, you have successfully been registered for the Early Warning System. Your facility is Test Facility
           super > register super tf incharge
           super < Congratulations super, you have successfully been registered for the Early Warning System. Your facility is Test Facility
           pharmacist > soh mc 0 mg 1 ng 300
           super < Dear super, Test Facility is experiencing the following problems: stockouts Male Condom; below reorder level Micro-G
           pharmacist <  Dear cynthia, these items are stocked out: mc. these items need to be reordered: mg. Please order 30 mc, 29 mg.
           pharmacist > soh mc 0-2 mg 1-1 ng 300-1
           super < Dear super, Test Facility is experiencing the following problems: stockouts Male Condom; below reorder level Micro-G
           pharmacist <  Dear cynthia, these items are stocked out: mc. these items need to be reordered: mg. Please order 30 mc, 29 mg.
           """
        self.runScript(a)

    def testCombined4(self):
        a = """
           pharmacist > register cynthia tf
           pharmacist < Congratulations cynthia, you have successfully been registered for the Early Warning System. Your facility is Test Facility
           super > register super tf incharge
           super < Congratulations super, you have successfully been registered for the Early Warning System. Your facility is Test Facility
           pharmacist > soh mc 0 mg 1 ng300-4
           super < Dear super, Test Facility is experiencing the following problems: stockouts Male Condom; below reorder level Micro-G
           pharmacist < Dear cynthia, these items are stocked out: mc. these items need to be reordered: mg. Please order 30 mc, 29 mg.
           """
        self.runScript(a)

    def testCombined5(self):
        a = """
           pharmacist > register cynthia tf
           pharmacist < Congratulations cynthia, you have successfully been registered for the Early Warning System. Your facility is Test Facility
           super > register super tf incharge
           super < Congratulations super, you have successfully been registered for the Early Warning System. Your facility is Test Facility
           pharmacist > mc 16 lf 16 mg300
           super < Dear super, Test Facility is experiencing the following problems: overstocked Micro-G
           pharmacist < Dear cynthia, these items are overstocked: mg. The district admin has been informed.
           """
        self.runScript(a)

    def testStringCleaner(self):
        a = """
           16176023315 > register cynthia dedh
           16176023315 < Congratulations cynthia, you have successfully been registered for the Early Warning System. Your facility is Dangme East District Hospital
           16176023315 > soh lf 10-20 mc 20
           16176023315 < Dear cynthia, thank you for reporting the commodities you have. You received lf 20.
           """
        self.runScript(a)

    def testBadCode(self):
        a = """
           16176023315 > register cynthia dedh
           16176023315 < Congratulations cynthia, you have successfully been registered for the Early Warning System. Your facility is Dangme East District Hospital
           16176023315 > lf 0 badcode 10
           16176023315 < You reported: lf, but there were errors: Unrecognized commodity codes: badcode. Please contact your DHIO for assistance.
           16176023315 > badcode 10
           16176023315 < badcode is not a recognized commodity code. Please contact your DHIO for assistance.
           16176023315 > soh lf 10.10 m20
           16176023315 < You reported: lf, but there were errors: Unrecognized commodity codes: m. Please contact your DHIO for assistance.
           16176023315 > ad50 -0 as65-0 al25-0 qu0-0 sp0-0 rd0-0
           16176023315 < You reported: rd, sp, qu, ad, al, but there were errors: Unrecognized commodity codes: as. Please contact your DHIO for assistance.
           """
        self.runScript(a)

    def FAILSbadcode(self):
        a = """
           16176023315 > register cynthia dedh
           16176023315 < Congratulations cynthia, you have successfully been registered for the Early Warning System. Your facility is Dangme East District Hospital
           16176023315 > soh lf 0 bad_code 10
           16176023315 < You reported: lf, but there were errors: BAD_CODE is/are not part of our commodity codes. Please contact your DHIO for assistance.
           16176023315 > soh bad_code 10
           16176023315 < BAD_CODE is/are not part of our commodity codes. Please contact your DHIO for assistance.
           """
        self.runScript(a)

    def testPunctuation(self):
        a = """
           16176023315 > register cynthia dedh
           16176023315 < Congratulations cynthia, you have successfully been registered for the Early Warning System. Your facility is Dangme East District Hospital
           16176023315 >   soh lf 10 mc 20
           16176023315 < Dear cynthia, thank you for reporting the commodities you have in stock.
           16176023315 > sohlf10mc20
           16176023315 < Dear cynthia, thank you for reporting the commodities you have in stock.
           16176023315 > lf10mc20
           16176023315 < Dear cynthia, thank you for reporting the commodities you have in stock.
           16176023315 > LF10MC 20
           16176023315 < Dear cynthia, thank you for reporting the commodities you have in stock.
           16176023315 > LF10-1MC 20,3
           16176023315 < Dear cynthia, thank you for reporting the commodities you have. You received lf 1, mc 3.
           16176023315 > LF(10), mc (20)
           16176023315 < Dear cynthia, thank you for reporting the commodities you have in stock.
           16176023315 > LF10-mc20
           16176023315 < Dear cynthia, thank you for reporting the commodities you have in stock.
           16176023315 > LF10-mc20-
           16176023315 < Dear cynthia, thank you for reporting the commodities you have in stock.
           16176023315 > LF10-3mc20
           16176023315 < Dear cynthia, thank you for reporting the commodities you have. You received lf 3.
           16176023315 > LF10----3mc20
           16176023315 < Dear cynthia, thank you for reporting the commodities you have. You received lf 3.
           """
        self.runScript(a)

    def failTestRMSStockout(self):
        """ This test doesn't pass yet. Something about signals not firing? """
        a = """
           111 > register garep garms
           111 < Congratulations garep, you have successfully been registered for the Early Warning System. Your facility is Greater Accra Regional Medical Store
           222 > register derep dedh
           222 < Congratulations derep, you have successfully been registered for the Early Warning System. Your facility is Dangme East District Hospital
           111 > soh lf 0
           111 < Dear garep, these items are stocked out: lf.
           222 < Dear derep, Greater Accra Regional Medical Store is STOCKED OUT of: lf
           111 > soh lf 10
           111 < Dear garep, thank you for reporting the commodities you have in stock.
           222 < Dear derep, Greater Accra Regional Medical Store has RESOLVED the following stockouts: lf
           """
        self.runScript(a)

    def tearDown(self):
        TestScript.tearDown(self)
        self.mc_stock.delete()
        self.mg_stock.delete()
        self.lf_stock.delete()
コード例 #10
0
ファイル: stockonhand.py プロジェクト: andile2012/logistics
class TestStockOnHand (TestScript):
    apps = ([logistics_app.App])
    fixtures = ["ghana_initial_data.json"] 
    def setUp(self):
        settings.LOGISTICS_STOCKED_BY = 'user'
        TestScript.setUp(self)
        location = Location.objects.get(code='de')
        facilitytype = SupplyPointType.objects.get(code='hc')
        self.rms = SupplyPoint.objects.get(code='garms')
        facility, created = SupplyPoint.objects.get_or_create(code='dedh',
                                                           name='Dangme East District Hospital',
                                                           location=location, active=True,
                                                           type=facilitytype, supplied_by=self.rms)
        assert facility.supplied_by == self.rms
        mc = Product.objects.get(sms_code='mc')
        self.lf = Product.objects.get(sms_code='lf')
        ProductStock(product=mc, supply_point=facility,
                     monthly_consumption=8).save()
        ProductStock(product=self.lf, supply_point=facility,
                     monthly_consumption=5).save()
        facility = SupplyPoint(code='tf', name='Test Facility',
                       location=location, active=True,
                       type=facilitytype, supplied_by=self.rms)
        facility.save()
        mc = Product.objects.get(sms_code='mc')
        mg = Product.objects.get(sms_code='mg')
        self.mc_stock = ProductStock(is_active=True, supply_point=facility,
                                    product=mc, monthly_consumption=10)
        self.mc_stock.save()
        self.lf_stock = ProductStock(is_active=True, supply_point=facility,
                                    product=self.lf, monthly_consumption=10)
        self.lf_stock.save()
        self.mg_stock = ProductStock(is_active=False, supply_point=facility,
                                     product=mg, monthly_consumption=10)
        self.mg_stock.save()

        ng = Product.objects.get(sms_code='ng')
        self.ng_stock = ProductStock(is_active=True, supply_point=facility,
                                    product=ng, monthly_consumption=None)
        self.ng_stock.save()
        
        self.contact = Contact(name='test user')
        self.contact.save()
        self.connection = Connection(backend=Backend.objects.all()[0],
                                     identity="888",
                                     contact=self.contact)
        self.connection.save()
        self.contact.supply_point = facility
        self.contact.save()
        self.contact.commodities.add(ng)
    
    
    def testProductReportsHelper(self):
        sdp = SupplyPoint()
        m = Message()
        p = ProductReportsHelper(sdp, Reports.SOH, m)
        p.add_product_stock('lf',10, save=False)
        p.add_product_stock('mc',30, save=False)
        p.add_product_stock('aa',0, save=False)
        p.add_product_stock('oq',0, save=False)
        self.assertEquals(p.all(), "lf 10, aa 0, oq 0, mc 30")
        self.assertEquals(p.stockouts(), "aa oq")
        my_iter = p._getTokens("ab10cd20")
        self.assertEquals(my_iter.next(),'ab')
        self.assertEquals(my_iter.next(),'10')
        self.assertEquals(my_iter.next(),'cd')
        self.assertEquals(my_iter.next(),'20')

    def testStockOnHand(self):
        a = """
           16176023315 > register stella dedh
           16176023315 < Congratulations stella, you have successfully been registered for the Early Warning System. Your facility is Dangme East District Hospital
           16176023315 > soh lf 10
           16176023315 < Dear stella, thank you for reporting the commodities you have in stock.
           16176023315 > soh lf 10 mc 20
           16176023315 < Dear stella, thank you for reporting the commodities you have in stock.
           16176023315 > SOH LF 10 MC 20
           16176023315 < Dear stella, thank you for reporting the commodities you have in stock.
           """
        self.runScript(a)

    def testNothing(self):
        a = """
           16176023315 > register stella dedh
           16176023315 < Congratulations stella, you have successfully been registered for the Early Warning System. Your facility is Dangme East District Hospital
           16176023315 >
           16176023315 < Sorry, I could not understand your message. Please contact your DHIO for help, or visit http://www.ewsghana.com
           16176023315 > soh
           16176023315 < To report stock on hand, send SOH [space] [product code] [space] [amount] 
           """
        self.runScript(a)

    def testStockout(self):
        a = """
           16176023315 > register cynthia dedh
           16176023315 < Congratulations cynthia, you have successfully been registered for the Early Warning System. Your facility is Dangme East District Hospital
           16176023315 > soh lf 0 mc 0
           16176023315 < Dear cynthia, these items are stocked out: lf mc. Please order 24 mc, 15 lf.
           """
        self.runScript(a)

    def testStockoutNoConsumption(self):
        a = """
           16176023315 > register cynthia dedh
           16176023315 < Congratulations cynthia, you have successfully been registered for the Early Warning System. Your facility is Dangme East District Hospital
           16176023315 > soh ng 0
           16176023315 < Dear cynthia, these items are stocked out: ng.
           """
        self.runScript(a)

    def testLowSupply(self):
        a = """
           16176023315 > register cynthia dedh
           16176023315 < Congratulations cynthia, you have successfully been registered for the Early Warning System. Your facility is Dangme East District Hospital
           16176023315 > soh lf 7 mc 9
           16176023315 < Dear cynthia, these items need to be reordered: lf mc. Please order 15 mc, 8 lf.
           """
        self.runScript(a)

    def testLowSupplyNoConsumption(self):
        a = """
           16176023315 > register cynthia dedh
           16176023315 < Congratulations cynthia, you have successfully been registered for the Early Warning System. Your facility is Dangme East District Hospital
           16176023315 > soh ng 3
           16176023315 < Dear cynthia, thank you for reporting the commodities you have in stock.
           """
        self.runScript(a)

    def testOverSupply(self):
        a = """
           16176023315 > register cynthia dedh
           16176023315 < Congratulations cynthia, you have successfully been registered for the Early Warning System. Your facility is Dangme East District Hospital
           16176023315 > soh lf 30 mc 40
           16176023315 < Dear cynthia, these items are overstocked: lf mc. The district admin has been informed.
           """
        self.runScript(a)

    def testSohAndReceipts(self):
        a = """
           16176023315 > register cynthia dedh
           16176023315 < Congratulations cynthia, you have successfully been registered for the Early Warning System. Your facility is Dangme East District Hospital
           16176023315 > soh lf 10 20 mc 20
           16176023315 < Dear cynthia, thank you for reporting the commodities you have. You received lf 20.
           """
        self.runScript(a)

    def testCombined1(self):
        a = """
           pharmacist > register cynthia tf
           pharmacist < Congratulations cynthia, you have successfully been registered for the Early Warning System. Your facility is Test Facility
           super > register super tf incharge
           super < Congratulations super, you have successfully been registered for the Early Warning System. Your facility is Test Facility
           pharmacist > soh lf 0 mc 1
           super < Dear super, Test Facility is experiencing the following problems: stockouts Lofem; below reorder level Male Condom
           pharmacist < Dear cynthia, these items are stocked out: lf. these items need to be reordered: mc. Please order 29 mc, 30 lf.
           """
        self.runScript(a)

    def testCombined2(self):
        a = """
           pharmacist > register cynthia tf
           pharmacist < Congratulations cynthia, you have successfully been registered for the Early Warning System. Your facility is Test Facility
           super > register super tf incharge
           super < Congratulations super, you have successfully been registered for the Early Warning System. Your facility is Test Facility
           pharmacist > mc 0 mg 1
           super < Dear super, Test Facility is experiencing the following problems: stockouts Male Condom; below reorder level Micro-G
           pharmacist < Dear cynthia, these items are stocked out: mc. these items need to be reordered: mg. Please order 30 mc, 29 mg.
           pharmacist > mc 0 mg 1 lf 100
           super < Dear super, Test Facility is experiencing the following problems: stockouts Male Condom; below reorder level Micro-G; overstocked Lofem
           pharmacist < Dear cynthia, these items are stocked out: mc. these items need to be reordered: mg. Please order 30 mc, 29 mg.
           """
        self.runScript(a)

    def testCombined3(self):
        a = """
           pharmacist > register cynthia tf
           pharmacist < Congratulations cynthia, you have successfully been registered for the Early Warning System. Your facility is Test Facility
           super > register super tf incharge
           super < Congratulations super, you have successfully been registered for the Early Warning System. Your facility is Test Facility
           pharmacist > soh mc 0 mg 1 ng 300
           super < Dear super, Test Facility is experiencing the following problems: stockouts Male Condom; below reorder level Micro-G
           pharmacist <  Dear cynthia, these items are stocked out: mc. these items need to be reordered: mg. Please order 30 mc, 29 mg.
           pharmacist > soh mc 0-2 mg 1-1 ng 300-1
           super < Dear super, Test Facility is experiencing the following problems: stockouts Male Condom; below reorder level Micro-G
           pharmacist <  Dear cynthia, these items are stocked out: mc. these items need to be reordered: mg. Please order 30 mc, 29 mg.
           """
        self.runScript(a)

    def testCombined4(self):
        a = """
           pharmacist > register cynthia tf
           pharmacist < Congratulations cynthia, you have successfully been registered for the Early Warning System. Your facility is Test Facility
           super > register super tf incharge
           super < Congratulations super, you have successfully been registered for the Early Warning System. Your facility is Test Facility
           pharmacist > soh mc 0 mg 1 ng300-4
           super < Dear super, Test Facility is experiencing the following problems: stockouts Male Condom; below reorder level Micro-G
           pharmacist < Dear cynthia, these items are stocked out: mc. these items need to be reordered: mg. Please order 30 mc, 29 mg.
           """
        self.runScript(a)

    def testCombined5(self):
        a = """
           pharmacist > register cynthia tf
           pharmacist < Congratulations cynthia, you have successfully been registered for the Early Warning System. Your facility is Test Facility
           super > register super tf incharge
           super < Congratulations super, you have successfully been registered for the Early Warning System. Your facility is Test Facility
           pharmacist > mc 16 lf 16 mg300
           super < Dear super, Test Facility is experiencing the following problems: overstocked Micro-G
           pharmacist < Dear cynthia, these items are overstocked: mg. The district admin has been informed.
           """
        self.runScript(a)

    def testStringCleaner(self):
        a = """
           16176023315 > register cynthia dedh
           16176023315 < Congratulations cynthia, you have successfully been registered for the Early Warning System. Your facility is Dangme East District Hospital
           16176023315 > soh lf 10-20 mc 20
           16176023315 < Dear cynthia, thank you for reporting the commodities you have. You received lf 20.
           """
        self.runScript(a)

    def testBadCode(self):
        a = """
           16176023315 > register cynthia dedh
           16176023315 < Congratulations cynthia, you have successfully been registered for the Early Warning System. Your facility is Dangme East District Hospital
           16176023315 > lf 0 badcode 10
           16176023315 < You reported: lf, but there were errors: Unrecognized commodity codes: badcode. Please contact your DHIO for assistance.
           16176023315 > badcode 10
           16176023315 < badcode is not a recognized commodity code. Please contact your DHIO for assistance.
           16176023315 > soh lf 10.10 m20
           16176023315 < You reported: lf, but there were errors: Unrecognized commodity codes: m. Please contact your DHIO for assistance.
           16176023315 > ad50 -0 as65-0 al25-0 qu0-0 sp0-0 rd0-0
           16176023315 < You reported: rd, sp, qu, ad, al, but there were errors: Unrecognized commodity codes: as. Please contact your DHIO for assistance.
           """
        self.runScript(a)

    def FAILSbadcode(self):
        a = """
           16176023315 > register cynthia dedh
           16176023315 < Congratulations cynthia, you have successfully been registered for the Early Warning System. Your facility is Dangme East District Hospital
           16176023315 > soh lf 0 bad_code 10
           16176023315 < You reported: lf, but there were errors: BAD_CODE is/are not part of our commodity codes. Please contact your DHIO for assistance.
           16176023315 > soh bad_code 10
           16176023315 < BAD_CODE is/are not part of our commodity codes. Please contact your DHIO for assistance.
           """
        self.runScript(a)

    def testPunctuation(self):
        a = """
           16176023315 > register cynthia dedh
           16176023315 < Congratulations cynthia, you have successfully been registered for the Early Warning System. Your facility is Dangme East District Hospital
           16176023315 >   soh lf 10 mc 20
           16176023315 < Dear cynthia, thank you for reporting the commodities you have in stock.
           16176023315 > sohlf10mc20
           16176023315 < Dear cynthia, thank you for reporting the commodities you have in stock.
           16176023315 > lf10mc20
           16176023315 < Dear cynthia, thank you for reporting the commodities you have in stock.
           16176023315 > LF10MC 20
           16176023315 < Dear cynthia, thank you for reporting the commodities you have in stock.
           16176023315 > LF10-1MC 20,3
           16176023315 < Dear cynthia, thank you for reporting the commodities you have. You received lf 1, mc 3.
           16176023315 > LF(10), mc (20)
           16176023315 < Dear cynthia, thank you for reporting the commodities you have in stock.
           16176023315 > LF10-mc20
           16176023315 < Dear cynthia, thank you for reporting the commodities you have in stock.
           16176023315 > LF10-mc20-
           16176023315 < Dear cynthia, thank you for reporting the commodities you have in stock.
           16176023315 > LF10-3mc20
           16176023315 < Dear cynthia, thank you for reporting the commodities you have. You received lf 3.
           16176023315 > LF10----3mc20
           16176023315 < Dear cynthia, thank you for reporting the commodities you have. You received lf 3.
           """
        self.runScript(a)

    def failTestRMSStockout(self):
        """ This test doesn't pass yet. Something about signals not firing? """
        a = """
           111 > register garep garms
           111 < Congratulations garep, you have successfully been registered for the Early Warning System. Your facility is Greater Accra Regional Medical Store
           222 > register derep dedh
           222 < Congratulations derep, you have successfully been registered for the Early Warning System. Your facility is Dangme East District Hospital
           111 > soh lf 0
           111 < Dear garep, these items are stocked out: lf.
           222 < Dear derep, Greater Accra Regional Medical Store is STOCKED OUT of: lf
           111 > soh lf 10
           111 < Dear garep, thank you for reporting the commodities you have in stock.
           222 < Dear derep, Greater Accra Regional Medical Store has RESOLVED the following stockouts: lf
           """
        self.runScript(a)

    def tearDown(self):
        TestScript.tearDown(self)
        self.mc_stock.delete()
        self.mg_stock.delete()
        self.lf_stock.delete()