Esempio n. 1
0
    def test_create_action_item(self):

        assert models.ActionItem.objects.count() == 0

        submitted_ai = {
            "instruction": factories.ActionInstructionFactory(),
            "due_date": str(datetime.date.today() + datetime.timedelta(10)),
            "comments": "an arbitrary string comment"
        }

        pt = factories.PatientFactory()
        url = reverse('core:new-action-item', kwargs={'pt_id': pt.id})
        response = self.client.post(url, submitted_ai)

        assert response.status_code == 302
        assert reverse('core:patient-detail', args=(pt.id, )) in response.url
        assert models.ActionItem.objects.count() == 1

        new_ai = models.ActionItem.objects.first()

        submitted_ai['due_date'] = datetime.date(
            *([int(i) for i in submitted_ai['due_date'].split('-')]))

        for param in submitted_ai:
            assert str(submitted_ai[param]) == str(getattr(new_ai, param))

        assert new_ai.author.id == self.coordinator.id
        assert new_ai.author_type.id == self.coordinator.groups.first().id
        assert new_ai.patient.id == pt.id

        assert (now() - new_ai.written_datetime).total_seconds() <= 10
        assert (now() - new_ai.last_modified).total_seconds() <= 10
Esempio n. 2
0
    def test_action_item_urls(self):
        ai = models.ActionItem.objects.create(
            instruction=factories.ActionInstructionFactory(),
            due_date=now().today(),
            author=self.coordinator,
            author_type=self.coordinator.groups.first(),
            patient=factories.PatientFactory())

        response = self.client.get(
            reverse('core:patient-detail', args=(ai.patient.id, )))
        self.assertTemplateUsed(response, 'core/patient_detail.html')
        self.assertContains(response,
                            reverse('core:done-action-item', args=(ai.id, )))

        # new action items should not be done
        assert not ai.done()

        # submit a request to mark the new ai as done. should redirect to
        # choose a followup type.
        response = self.client.get(
            reverse('core:done-action-item', args=(ai.id, )))
        assert response.status_code == 302
        assert reverse("new-actionitem-followup",
                       kwargs={
                           'pt_id': ai.patient.pk,
                           'ai_id': ai.pk
                       }) in response.url
        assert models.ActionItem.objects.first().done()
        assert \
            models.ActionItem.objects.first().written_datetime != \
            models.ActionItem.objects.first().last_modified

        # submit a request to reset the ai. should redirect to pt
        prev_mod_datetime = models.ActionItem.objects.first().last_modified
        response = self.client.get(
            reverse('core:reset-action-item', args=(ai.id, )))
        assert response.status_code == 302
        assert reverse('core:patient-detail',
                       args=(ai.patient.id, )) in response.url
        assert not models.ActionItem.objects.first().done()

        assert (models.ActionItem.objects.first().written_datetime !=
                models.ActionItem.objects.first().last_modified)
        assert prev_mod_datetime != \
            models.ActionItem.objects.first().last_modified

        # make sure updating the action items url works
        response = self.client.get(
            reverse('core:update-action-item', args=(ai.pk, )))
        assert response.status_code == 200
Esempio n. 3
0
    def test_action_item_completeable_functions(self):

        ai = models.ActionItem.objects.create(
            author=self.coordinator,
            author_type=self.coordinator.groups.first(),
            due_date=(now() + datetime.timedelta(days=3)).date(),
            instruction=factories.ActionInstructionFactory(),
            patient=factories.PatientFactory())

        self.assertEqual(
            ai.attribution(),
            "Added by %s on %s" % (self.coordinator.name, now().date()))

        coordinator2 = build_user([user_factories.CaseManagerGroupFactory])
        ai.mark_done(coordinator2)
        ai.save()

        assert ai.attribution() == ("Marked done by %s on %s" %
                                    (coordinator2.name, now().date()))