def test_should_make_proper_report_after_complete_flow(self):
        fake_incoming('recv.600.sc1', self.connection)
        fake_incoming('send.600.sc1.dp1', self.connection)
        fake_incoming('recv.600.dp1', self.connection)
        fake_incoming('dist.500.dp1', self.connection)

        row = BednetsReport.objects.all()

        self.assertEquals(len(row),2)
        self.assertEquals(row[0].sub_county,"sc1")
        self.assertEquals(row[0].quantity_at_subcounty,600)

        self.assertEquals(row[1].sub_county,"sc1")
        self.assertEquals(row[1].quantity_sent_to_dp,600)
        self.assertEquals(row[1].quantity_received_at_dp,600)
        self.assertEquals(row[1].quantity_distributed_at_dp,500)
        self.assertEquals(row[1].in_stock,100)
        self.assertEquals(row[1].distribution_point,"dp1")

        row = DumpReport.objects.all()

        self.assertEquals(len(row),4)
        self.assertFalse(row[0].invalid_submission)
        self.assertFalse(row[1].invalid_submission)
        self.assertFalse(row[2].invalid_submission)
        self.assertFalse(row[3].invalid_submission)

        fake_incoming('recv.400.dp1', self.connection)
        row = BednetsReport.objects.all()

        self.assertEquals(len(row),2)
        self.assertEquals(row[1].quantity_received_at_dp,400)
        self.assertEquals(row[1].in_stock,-100)
Example #2
0
    def testResponses(self):
        fake_incoming('+reg David McCann')
        self.incomingResponse('+BIRTH Terra Weikel, F, HOME', 'Thank you for registering the birth of Terra Weikel, female (infant). We have recorded that the birth took place at home.')
#        self.incomingResponse('+DEATH Malthe Borch, M,1DAY', 'We have recorded the death of Malthe Borch, male (infant).')
        self.incomingResponse('+muac Matt Berg, M,5months,yellow', 'Matt Berg, male (5 months old) has been identified with Risk of Malnutrition')
        self.incomingResponse('+epi ma 12, bd 5', 'You reported Bloody diarrhea (Dysentery) 5, and Malaria 12.If there is an error,please resend.')
        self.incomingResponse('+home 12, wa 1, it 6', 'You reported Total Homesteads Visited 12,ITTNs/LLINs 6, and Safe Drinking Water 1.If there is an error,please resend.')
    def test_should_add_single_row_with_only_sc_entry_in_bednets_report_table(self):
        fake_incoming('recv.100.sc1', self.connection)

        row = BednetsReport.objects.filter(sub_county="sc1")

        self.assertEquals(len(row),1)
        self.assertEquals(row[0].sub_county,"sc1")
        self.assertEquals(row[0].quantity_at_subcounty,100)
    def test_should_add_single_row_in_dump_reports_table(self):
        fake_incoming('recv.100.foosc', self.connection)
        row = DumpReport.objects.filter(keyword="recv")

        self.assertEquals(len(row),1)
        self.assertEquals(row[0].at_location,"foosc")
        self.assertEquals(row[0].number_of_bednets,100)
        self.assertEquals(row[0].invalid_submission,False)
        self.assertEquals(row[0].invalid_reporter,False)
Example #5
0
 def testRegister(self):
     b = Backend.objects.get(name='test')
     c = Connection.objects.create(identity='8675310', backend=b)
     s = fake_incoming('+muac Sean Blaschke, M,2 dys,yellow', c)
     self.failUnless(s.has_errors)
     c = Connection.objects.get(identity='8675310')
     s = fake_incoming('+reg David McCann', c)
     c = Connection.objects.get(identity='8675310')
     self.assertEquals(c.contact.name, 'David McCann')
     c.contact.active = True
     c.contact.save()
     s = fake_incoming('+muac Sean Blaschke, M,2 dys,yellow', c)
     self.failIf(s.has_errors)
Example #6
0
    def testValidity(self):
        s = fake_incoming('+muac Sean Blascke, M,2 dys,yellow')
        s1 = fake_incoming('+muac Sean Blaschke, M,2 dys,yellow')
        s = XFormSubmission.objects.get(pk=s.pk)
        self.assertEquals(s.has_errors, True)
        self.failIf(PatientEncounter.objects.get(submission=s).valid)

        s = fake_incoming('+birth terra weikel, F, Home')
        s1 = fake_incoming('+birth terra weikel, F, Facility')
        s = XFormSubmission.objects.get(pk=s.pk)
        self.assertEquals(s.has_errors, True)
        self.failIf(PatientEncounter.objects.get(submission=s).valid)

#        s = fake_incoming('+DEATH maltheSMS, M, 2Y')
#        s1 = fake_incoming('+DEATH maltheSMS, M, 3Y')
#        s = XFormSubmission.objects.get(pk=s.pk)
#        self.assertEquals(s.has_errors, True)
#        self.failIf(PatientEncounter.objects.get(submission=s).valid)

        s = fake_incoming('+epi bd 5,ma 12,tb 1,ab 2,af 3,mg 4,me 5, ch 6, gw 7, nt 8, yf 9, pl 10, ra 11, vf 12, ei 13')
        s1 = fake_incoming('+epi bd 5,ma 12')
        s = XFormSubmission.objects.get(pk=s.pk)
        self.failUnless(s.has_errors)

        s = fake_incoming('+home 13, wa 9, it 10, la 11, ha 12')
        s1 = fake_incoming('+home 23, wa 9, it 10, la 11, ha 12')
        s = XFormSubmission.objects.get(pk=s.pk)
        self.failUnless(s.has_errors)
    def test_should_invalidate_submission_if_same_message_in_24_hours(self):
        submission1 = fake_incoming('recv.100.foosc', self.connection)
        row = DumpReport.objects.filter(keyword="recv")

        self.assertEquals(len(row),1)
        self.assertEquals(row[0].invalid_submission,False)

        submission2 = fake_incoming('recv.100.foosc', self.connection)
        row = DumpReport.objects.filter(keyword="recv")

        self.assertEquals(len(row),2)
        self.assertEquals(row[0].invalid_submission,True)
        self.assertEquals(row[0].submission_id,submission1.id)
        self.assertEquals(row[1].invalid_submission,False)
        self.assertEquals(row[1].submission_id,submission2.id)
Example #8
0
    def testBasicSubmission(self):
        fake_incoming('+BIRTH Terra Weikel, F, HOME')
#        fake_incoming('+DEATH Malthe Borch, M,1DAY')
        fake_incoming('+muac Matt Berg, M,5months,yellow')
        fake_incoming('+epi ma 12, bd 5')
        fake_incoming('+home 12, wa 1, it 6')
        self.assertEquals(XFormSubmission.objects.count(), 4)
        self.assertEquals(PatientEncounter.objects.count(), 2)
Example #9
0
 def testHome(self):
     s = fake_incoming('+home 13, wa 9, it 10, la 11, ha 12')
     self.assertEquals(s.eav.home_wa, 9)
     self.assertEquals(s.eav.home_it, 10)
     self.assertEquals(s.eav.home_la, 11)
     self.assertEquals(s.eav.home_ha, 12)
     self.assertEquals(s.eav.home_to, 13)
Example #10
0
 def testBirth(self):
     s = fake_incoming('+birth David McCann, M, Facility')
     # test submission parsing
     self.assertEquals(s.eav.birth_place, 'FACILITY')
     self.assertEquals(s.eav.birth_name, 'David McCann')
     self.assertEquals(s.eav.birth_gender, 'M')
     self.assertEquals(PatientEncounter.objects.filter(submission=s).count(), 1)
     pe = PatientEncounter.objects.get(submission=s)
     p = pe.patient
     # test patient creation
     self.assertEquals(p.first_name, 'David')
     self.assertEquals(p.last_name, 'McCann')
     self.failUnless(p.age.days <= 1)
     s = fake_incoming('+birth terra weikel, F, Home')
     self.assertEquals(s.eav.birth_place, 'HOME')
     self.assertEquals(s.eav.birth_gender, 'F')
Example #11
0
 def testMuac(self):
     s = fake_incoming('+muac Sean Blaschke, M,5months,yellow')
     self.assertEquals(s.eav.muac_name, 'Sean Blaschke')
     self.assertEquals(s.eav.muac_gender, 'M')
     self.failUnless(s.eav.muac_age - 150 < 2)
     self.assertEquals(s.eav.muac_category, 'Y')
     self.assertEquals(s.eav.muac_ignored, 'F')
     pe = PatientEncounter.objects.get(submission=s)
     p = pe.patient
     self.assertEquals(p.first_name, 'Sean')
     self.assertEquals(p.last_name, 'Blaschke')
     self.failUnless(p.age.days - 150 < 2)
     s = fake_incoming('+muac Terra Weikel, F,5months,red')
     self.assertEquals(s.eav.muac_category, 'R')
     self.assertEquals(s.eav.muac_gender, 'F')
     s = fake_incoming('+muac Alexis Coppola, F, 5months, green, oedema')
     self.assertEquals(s.eav.muac_category, 'G')
     self.assertEquals(s.eav.muac_ignored, 'T')
    def test_should_map_valid_values_to_xform_fields(self):
        message = fake_incoming('dist.100.at')
        values = message.submission_values()
        submission = XFormSubmission.objects.get(xform=message.xform)

        self.assertEquals(2,len(values))
        self.assertEquals(100, values[0].value)
        self.assertEquals("at", values[1].value)
        self.assertEquals('dist.100.at',submission.raw)
Example #13
0
 def testACT(self):
     s = fake_incoming('act 1, 2, 3, 4, 5, 6, 7, 8')
     self.assertEquals(s.eav.act_spd, 1)
     self.assertEquals(s.eav.act_sps, 2)
     self.assertEquals(s.eav.act_tpd, 3)
     self.assertEquals(s.eav.act_tps, 4)
     self.assertEquals(s.eav.act_epd, 5)
     self.assertEquals(s.eav.act_eps, 6)
     self.assertEquals(s.eav.act_fpd, 7)
     self.assertEquals(s.eav.act_fps, 8)
Example #14
0
 def testCom(self):
     s = fake_incoming('com 1, 2, 3, 4, 5, 6, 7, 8')
     self.assertEquals(s.eav.com_fever, 1)
     self.assertEquals(s.eav.com_diarrhea, 2)
     self.assertEquals(s.eav.com_pneumonia, 3)
     self.assertEquals(s.eav.com_death, 4)
     self.assertEquals(s.eav.com_bi_od, 5)
     self.assertEquals(s.eav.com_muac_red, 6)
     self.assertEquals(s.eav.com_muac_yellow, 7)
     self.assertEquals(s.eav.com_muac_green, 8)
    def test_should_map_valid_values_to_xform_fields(self):
        message = fake_incoming('send.112.from.to')
        values = message.submission_values()
        submission = XFormSubmission.objects.get(xform=message.xform)

        self.assertEquals(3,len(values))
        self.assertEquals(112, values[0].value)
        self.assertEquals("from", values[1].value)
        self.assertEquals("to", values[2].value)
        self.assertEquals('send.112.from.to', submission.raw)
Example #16
0
    def testTimeDeltas(self):
        s = fake_incoming('+muac Sean Blaschke, M,5months,yellow')
        pe = PatientEncounter.objects.get(submission=s)
        p = pe.patient
        self.failUnless(p.age.days - 150 < 2)

        s = fake_incoming('+muac Sean Blaschke, M,2 wks,yellow')
        pe = PatientEncounter.objects.get(submission=s)
        p = pe.patient
        self.failUnless(p.age.days - 14 < 2)

        s = fake_incoming('+muac Sean Blaschke, M,3 yeers,yellow')
        pe = PatientEncounter.objects.get(submission=s)
        p = pe.patient
        self.failUnless(p.age.days - 1095 < 2)

        s = fake_incoming('+muac Sean Blaschke, M,2 dys,yellow')
        pe = PatientEncounter.objects.get(submission=s)
        p = pe.patient
        self.failUnless(p.age.days - 2 < 2)
Example #17
0
    def testEpi(self):
        s = fake_incoming('+epi bd 5,ma 12,tb 1,ab 2,af 3,mg 4,me 5, ch 6, gw 7, nt 8, yf 9, pl 10, ra 11, vf 12, ei 13')
        self.assertEquals(s.eav.epi_bd, 5)
        self.assertEquals(s.eav.epi_ma, 12)
        self.assertEquals(s.eav.epi_tb, 1)
        self.assertEquals(s.eav.epi_ab, 2)
        self.assertEquals(s.eav.epi_af, 3)
        self.assertEquals(s.eav.epi_mg, 4)
        self.assertEquals(s.eav.epi_me, 5)
        self.assertEquals(s.eav.epi_ch, 6)
        self.assertEquals(s.eav.epi_gw, 7)
        self.assertEquals(s.eav.epi_nt, 8)
        self.assertEquals(s.eav.epi_yf, 9)
        self.assertEquals(s.eav.epi_pl, 10)
        self.assertEquals(s.eav.epi_ra, 11)
        self.assertEquals(s.eav.epi_vf, 12)
        self.assertEquals(s.eav.epi_ei, 13)

        #new EPI doesn't require +, and has dy and rb indicators
        s = fake_incoming('epi dy 5,ma 12,tb 1,ab 2,af 3,mg 4,me 5, ch 6, gw 7, nt 8, yf 9, pl 1O, rb 11, vf 12, ei 13')
        # DY should alias to BD to make reporting easier (since they're actually the same indicator
        self.assertEquals(s.eav.epi_bd, 5)
        self.assertEquals(s.eav.epi_dy, None)
        self.assertEquals(s.eav.epi_ma, 12)
        self.assertEquals(s.eav.epi_tb, 1)
        self.assertEquals(s.eav.epi_ab, 2)
        self.assertEquals(s.eav.epi_af, 3)
        self.assertEquals(s.eav.epi_mg, 4)
        self.assertEquals(s.eav.epi_me, 5)
        self.assertEquals(s.eav.epi_ch, 6)
        self.assertEquals(s.eav.epi_gw, 7)
        self.assertEquals(s.eav.epi_nt, 8)
        self.assertEquals(s.eav.epi_yf, 9)
        self.assertEquals(s.eav.epi_pl, 10)
        # RB should alias to RB to make reporting easier (since they're actually the same indicator
        self.assertEquals(s.eav.epi_ra, 11)
        self.assertEquals(s.eav.epi_rb, None)
        self.assertEquals(s.eav.epi_vf, 12)
        self.assertEquals(s.eav.epi_ei, 13)
    def test_should_map_outer_join_on_single_row_for_sent_recv_dist_xforms(self):
        fake_incoming("send.100.scw.dp1")
        fake_incoming("recv.100.dp1")
        fake_incoming("dist.50.dp1")
        fake_incoming("dist.30.dp1")

        sent_xform = XForm.objects.get(keyword="send")
        received_xform = XForm.objects.get(keyword="recv")
        distributed_xform = XForm.objects.get(keyword="dist")

        join_sent_recv_dist_data = get_outer_join_sent_recv_dist(
            sent_xform=sent_xform, received_xform=received_xform, distributed_xform=distributed_xform
        )
        expected_list = ["scw", 100, "dp1", 100, 80, 20]

        self.assertTrue(len(join_sent_recv_dist_data), 1)
        self.assertEquals(join_sent_recv_dist_data[0], expected_list)
    def test_should_change_bednets_report_if_duplicate_submission(self):
        fake_incoming('recv.600.foosc1', self.connection)
        fake_incoming('recv.600.foosc2', self.connection)
        fake_incoming('recv.400.foosc1', self.connection)
        row = BednetsReport.objects.filter(sub_county__in = ["foosc1","foosc2"])

        self.assertEquals(len(row),2)
        self.assertEquals(row[0].sub_county,"foosc2")
        self.assertEquals(row[0].quantity_at_subcounty,600)

        self.assertEquals(row[1].sub_county,"foosc1")
        self.assertEquals(row[1].quantity_at_subcounty,400)
Example #20
0
 def testDoubleRegister(self):
     fake_incoming('+reg newname')
     self.assertEquals(Contact.objects.all()[0].name, 'newname')
Example #21
0
 def testMal(self):
     s = fake_incoming('mal 1, 2, 3, 4')
     self.assertEquals(s.eav.mal_total_new, 1)
     self.assertEquals(s.eav.mal_total_death, 2)
     self.assertEquals(s.eav.mal_total_default, 3)
     self.assertEquals(s.eav.mal_total_admissions, 4)
    def test_should_return_successful_response_for_complete_message(self):
        message = fake_incoming('dist.11.from')

        self.assertTrue(message.response.__contains__("Thank you for your report!"))
    def test_should_invalidate_incomplete_message_without_received_at_location(self):
        message = fake_incoming('dist.11')

        self.assertTrue(message.response.__contains__("Location where bednets were distributed is required."))
    def test_should_invalidate_incomplete_message_without_number_of_bednets(self):
        message = fake_incoming('dist')

        self.assertTrue(message.response.__contains__("Number of bednets distributed is required."))
    def test_should_invalidate_incomplete_message_without_destination(self):
        message = fake_incoming('send.11.from')

        self.assertTrue(message.response.__contains__("Location to which you are sending bednets is required."))
Example #26
0
 def testRutf(self):
     s = fake_incoming('rutf 1, 2, 3, 4')
     self.assertEquals(s.eav.rutf_new_f75_stock, 1)
     self.assertEquals(s.eav.rutf_closing_f75_stock, 2)
     self.assertEquals(s.eav.rutf_new_rutf_stock, 3)
     self.assertEquals(s.eav.rutf_closing_rutf_stock, 4)
Example #27
0
 def testReport(self):
     s = fake_incoming('cases ma.1o')
     self.assertEquals(s.eav.cases_ma, 10)
Example #28
0
 def testPatientMatching(self):
     s = fake_incoming('+muac Sean Blascke, M,2 dys,yellow')
     s1 = fake_incoming('+muac Sean Blaschke, M,2 dys,yellow')
     self.assertEquals(s.report.patient.pk, s1.report.patient.pk)
     p = s1.report.patient
     self.assertEquals(p.last_name, 'Blaschke')
Example #29
0
 def incomingResponse(self, message, expected_response, connection=None):
     s = fake_incoming(message, connection)
     self.assertEquals(s.response, expected_response)
Example #30
0
 def testVHTRegistration(self):
     ht = HealthFacilityType.objects.create(name="Drug Store", slug="ds")
     hc = HealthFacility.objects.create(name="Dave's Drug Emporium", code="AWESOME", type=ht)
     s = fake_incoming('+vht AWESOME')
     self.assertEquals(hc, HealthProvider.objects.all()[0].facility)