Example #1
0
    def test_default(self):
        block = Block(medication_name='Nicotine Patch')
        block.save()

        self.assertEquals(block.medication_name, 'Nicotine Patch')
        self.assertTrue(block.allow_redo)
        self.assertTrue(block.needs_submit())
        self.assertTrue(block.redirect_to_self_on_submit())
Example #2
0
    def create_block(self, section, medication_name):
        block = Block(medication_name=medication_name)
        block.save()

        self.section.append_pageblock(label="prescription writing",
                                      css_extra="",
                                      content_object=block)
        return block
Example #3
0
    def create_block(self, section, medication_name):
        block = Block(medication_name=medication_name)
        block.save()

        self.section.append_pageblock(label="prescription writing",
                                      css_extra="",
                                      content_object=block)
        return block
Example #4
0
    def test_edit_form(self):
        block = Block(medication_name='Nicotine Patch')
        block.save()

        form = block.edit_form()
        self.assertIsNotNone(form)
        self.assertTrue('medication_name' in form.fields)
        self.assertTrue('allow_redo' in form.fields)
        self.assertEquals(form.initial['medication_name'], 'Nicotine Patch')
        self.assertTrue(form.initial['allow_redo'])
Example #5
0
    def test_edit_form(self):
        block = Block(medication_name='Nicotine Patch')
        block.save()

        form = block.edit_form()
        self.assertIsNotNone(form)
        self.assertTrue('medication_name' in form.fields)
        self.assertTrue('allow_redo' in form.fields)
        self.assertEquals(form.initial['medication_name'], 'Nicotine Patch')
        self.assertTrue(form.initial['allow_redo'])
Example #6
0
class GetPrescriptionNodeTest(TestCase):
    fixtures = ['prescriptionwriting.json']

    def setUp(self):
        self.block = Block(medication_name='Nicotine Patch')
        self.block.save()

        self.user = User.objects.create(username="******")

    def test_render_nostate(self):
        request = FakeRequest()
        request.user = self.user

        node = GetPrescription('block', 'state')
        context = dict(request=request, block=self.block)
        result = node.render(context)
        self.assertEqual(result, '')
        self.assertTrue('state' in context)

        keys = context['state'].keys()
        self.assertFalse('dosage' in keys)
        self.assertFalse('sig' in keys)
        self.assertFalse('disp' in keys)
        self.assertFalse('refills' in keys)

        self.assertTrue('complete' in keys)
        self.assertFalse(context['state']['complete'])

    def test_render_state(self):
        data = {
            'dosage': '1.0mg',
            'disp': '5 tablets',
            'sig': 'instructions go here',
            'refills': '2'
        }
        self.block.submit(self.user, data)

        request = FakeRequest()
        request.user = self.user

        node = GetPrescription('block', 'state')
        context = dict(request=request, block=self.block)
        result = node.render(context)
        self.assertEqual(result, '')
        self.assertTrue('state' in context)

        state = context['state']
        self.assertEquals(state['dosage'], '1.0mg')
        self.assertEquals(state['disp'], '5 tablets')
        self.assertEquals(state['sig'], 'instructions go here')
        self.assertEquals(state['refills'], '2')
        self.assertTrue(state['complete'])
Example #7
0
    def test_edit(self):
        block = Block(medication_name='Nicotine Patch')
        block.save()
        self.assertEquals(block.medication_name, 'Nicotine Patch')
        self.assertTrue(block.allow_redo)

        rf = RequestFactory()
        post_request = rf.post('/',
                               {'medication_name': 'Nicotine Gum',
                                'allow_redo': False})

        block.edit(post_request.POST, None)
        self.assertEquals(block.medication_name, 'Nicotine Gum')
        self.assertFalse(block.allow_redo)
Example #8
0
 def test_create(self):
     rf = RequestFactory()
     post_request = rf.post('/',
                            {'medication_name': 'Nicotine Patch',
                             'allow_redo': False})
     block = Block.create(post_request)
     self.assertEquals(block.medication_name, 'Nicotine Patch')
     self.assertFalse(block.allow_redo)
Example #9
0
 def test_create(self):
     rf = RequestFactory()
     post_request = rf.post('/', {
         'medication_name': 'Nicotine Patch',
         'allow_redo': False
     })
     block = Block.create(post_request)
     self.assertEquals(block.medication_name, 'Nicotine Patch')
     self.assertFalse(block.allow_redo)
Example #10
0
    def test_default(self):
        block = Block(medication_name='Nicotine Patch')
        block.save()

        self.assertEquals(block.medication_name, 'Nicotine Patch')
        self.assertTrue(block.allow_redo)
        self.assertTrue(block.needs_submit())
        self.assertTrue(block.redirect_to_self_on_submit())
Example #11
0
    def test_edit(self):
        block = Block(medication_name='Nicotine Patch')
        block.save()
        self.assertEquals(block.medication_name, 'Nicotine Patch')
        self.assertTrue(block.allow_redo)

        rf = RequestFactory()
        post_request = rf.post('/', {
            'medication_name': 'Nicotine Gum',
            'allow_redo': False
        })

        block.edit(post_request.POST, None)
        self.assertEquals(block.medication_name, 'Nicotine Gum')
        self.assertFalse(block.allow_redo)
Example #12
0
    def setUp(self):
        self.block = Block(medication_name='Nicotine Patch')
        self.block.save()

        self.user = User.objects.create(username="******")
Example #13
0
 def test_add_form(self):
     form = Block.add_form()
     self.assertIsNotNone(form)
     self.assertTrue('medication_name' in form.fields)
     self.assertTrue('allow_redo' in form.fields)
Example #14
0
 def test_add_form(self):
     form = Block.add_form()
     self.assertIsNotNone(form)
     self.assertTrue('medication_name' in form.fields)
     self.assertTrue('allow_redo' in form.fields)
Example #15
0
    def test_single_prescription(self):
        user = User.objects.create(username="******")
        block = Block(medication_name='Nicotine Patch')
        block.save()

        self.assertFalse(block.unlocked(user))

        # clear with no data
        block.clear_user_submissions(user)
        self.assertFalse(block.unlocked(user))

        meds = block.medication()
        self.assertEquals(len(meds), 1)
        self.assertEquals(meds[0],
                          Medication.objects.get(name='Nicotine Patch'))

        data = {
            'dosage': '1.0mg',
            'disp': '5 tablets',
            'sig': 'instructions go here',
            'refills': '2'
        }
        block.submit(user, data)
        self.assertTrue(block.unlocked(user))

        block.clear_user_submissions(user)
        self.assertFalse(block.unlocked(user))
Example #16
0
    def test_interaction(self):
        user = User.objects.create(username="******")
        varenicline1 = Block(medication_name='Varenicline')
        varenicline1.save()

        varenicline2 = Block(medication_name='Varenicline')
        varenicline2.save()

        patch = Block(medication_name='Nicotine Patch')
        patch.save()

        self.assertFalse(varenicline1.unlocked(user))
        self.assertFalse(varenicline2.unlocked(user))
        self.assertFalse(patch.unlocked(user))

        data = {
            'dosage': '0.5mg',
            'disp': '5 tablets',
            'sig': 'instructions go here',
            'refills': '0',
            'dosage_2': '1.0mg',
            'disp_2': '56 tablets',
            'sig_2': 'more instructions go here',
            'refills_2': '2'
        }
        varenicline1.submit(user, data)
        varenicline2.submit(user, data)
        patch.submit(user, data)

        self.assertTrue(varenicline1.unlocked(user))
        self.assertTrue(varenicline2.unlocked(user))
        self.assertTrue(patch.unlocked(user))

        varenicline1.clear_user_submissions(user)
        self.assertFalse(varenicline1.unlocked(user))
        self.assertTrue(varenicline2.unlocked(user))
        self.assertTrue(patch.unlocked(user))

        patch.clear_user_submissions(user)
        self.assertFalse(varenicline1.unlocked(user))
        self.assertTrue(varenicline2.unlocked(user))
        self.assertFalse(patch.unlocked(user))
Example #17
0
    def test_double_prescription(self):
        user = User.objects.create(username="******")
        block = Block(medication_name='Varenicline')
        block.save()

        self.assertFalse(block.unlocked(user))

        meds = block.medication()
        self.assertEquals(len(meds), 2)
        self.assertEquals(meds[0].refills, 0)
        self.assertEquals(meds[0].dispensing, '11 tablets')

        self.assertEquals(meds[0].refills, 0)
        self.assertEquals(meds[0].dispensing, '11 tablets')
        self.assertEquals(meds[0].dosage, '0.5mg')

        self.assertEquals(meds[1].refills, 2)
        self.assertEquals(meds[1].dispensing, '56 tablets')
        self.assertEquals(meds[1].dosage, '1.0mg')

        data = {
            'dosage': '0.5mg',
            'disp': '5 tablets',
            'sig': 'instructions go here',
            'refills': '0',
            'dosage_2': '1.0mg',
            'disp_2': '56 tablets',
            'sig_2': 'more instructions go here',
            'refills_2': '2'
        }
        block.submit(user, data)
        self.assertTrue(block.unlocked(user))

        block.clear_user_submissions(user)
        self.assertFalse(block.unlocked(user))
Example #18
0
    def test_interaction(self):
        user = User.objects.create(username="******")
        varenicline1 = Block(medication_name='Varenicline')
        varenicline1.save()

        varenicline2 = Block(medication_name='Varenicline')
        varenicline2.save()

        patch = Block(medication_name='Nicotine Patch')
        patch.save()

        self.assertFalse(varenicline1.unlocked(user))
        self.assertFalse(varenicline2.unlocked(user))
        self.assertFalse(patch.unlocked(user))

        data = {
            'dosage': '0.5mg',
            'disp': '5 tablets',
            'sig': 'instructions go here',
            'refills': '0',
            'dosage_2': '1.0mg',
            'disp_2': '56 tablets',
            'sig_2': 'more instructions go here',
            'refills_2': '2'
        }
        varenicline1.submit(user, data)
        varenicline2.submit(user, data)
        patch.submit(user, data)

        self.assertTrue(varenicline1.unlocked(user))
        self.assertTrue(varenicline2.unlocked(user))
        self.assertTrue(patch.unlocked(user))

        varenicline1.clear_user_submissions(user)
        self.assertFalse(varenicline1.unlocked(user))
        self.assertTrue(varenicline2.unlocked(user))
        self.assertTrue(patch.unlocked(user))

        patch.clear_user_submissions(user)
        self.assertFalse(varenicline1.unlocked(user))
        self.assertTrue(varenicline2.unlocked(user))
        self.assertFalse(patch.unlocked(user))
Example #19
0
    def test_single_prescription(self):
        user = User.objects.create(username="******")
        block = Block(medication_name='Nicotine Patch')
        block.save()

        self.assertFalse(block.unlocked(user))

        # clear with no data
        block.clear_user_submissions(user)
        self.assertFalse(block.unlocked(user))

        meds = block.medication()
        self.assertEquals(len(meds), 1)
        self.assertEquals(meds[0],
                          Medication.objects.get(name='Nicotine Patch'))

        data = {
            'dosage': '1.0mg',
            'disp': '5 tablets',
            'sig': 'instructions go here',
            'refills': '2'
        }
        block.submit(user, data)
        self.assertTrue(block.unlocked(user))

        block.clear_user_submissions(user)
        self.assertFalse(block.unlocked(user))
Example #20
0
    def test_double_prescription(self):
        user = User.objects.create(username="******")
        block = Block(medication_name='Varenicline')
        block.save()

        self.assertFalse(block.unlocked(user))

        meds = block.medication()
        self.assertEquals(len(meds), 2)
        self.assertEquals(meds[0].refills, 0)
        self.assertEquals(meds[0].dispensing, '11 tablets')

        self.assertEquals(meds[0].refills, 0)
        self.assertEquals(meds[0].dispensing, '11 tablets')
        self.assertEquals(meds[0].dosage, '0.5mg')

        self.assertEquals(meds[1].refills, 2)
        self.assertEquals(meds[1].dispensing, '56 tablets')
        self.assertEquals(meds[1].dosage, '1.0mg')

        data = {
            'dosage': '0.5mg',
            'disp': '5 tablets',
            'sig': 'instructions go here',
            'refills': '0',
            'dosage_2': '1.0mg',
            'disp_2': '56 tablets',
            'sig_2': 'more instructions go here',
            'refills_2': '2'
        }
        block.submit(user, data)
        self.assertTrue(block.unlocked(user))

        block.clear_user_submissions(user)
        self.assertFalse(block.unlocked(user))