Exemplo n.º 1
0
    def post(self,  *args, **kwargs):
        from pact.models import PactPatientCase, CDotWeeklySchedule

        pdoc = PactPatientCase.get(self.request.GET['case_id'])
        resp = HttpResponse()
        if self.method == "rm_schedule":
            if self.request.POST.has_key('rm_schedule'):
                #hacky remove schedule method
                pdoc.rm_last_schedule()
                pdoc.save()
                resp.status_code = 204
                return resp

        elif self.method == "schedule":
            form = ScheduleForm(data=self.request.POST)
            if form.is_valid():
                sched = CDotWeeklySchedule()
                for day in DAYS_OF_WEEK:
                    if form.cleaned_data[day] != 'None':
                        setattr(sched, day, form.cleaned_data[day])
                if form.cleaned_data['active_date'] == None:
                    sched.started = datetime.utcnow()
                else:
                    sched.started = datetime.combine(form.cleaned_data['active_date'], time.min)
                sched.comment = form.cleaned_data['comment']
                sched.created_by = self.request.user.username
                sched.deprecated = False
                pdoc.set_schedule(sched)
                pdoc.save()
                set_schedule_case_properties(pdoc)
                resp.status_code = 204
                return resp
            else:
                resp.write(str(form.errors))
                resp.status_code = 406
                return resp

        elif self.method == 'providers':
            try:
                submitted_provider_ids = json.loads(self.request.POST['selected_providers'])
                case_provider_ids = list(pdoc.get_provider_ids())

                if submitted_provider_ids != case_provider_ids:
                    try:
                        #len difference
                        submitted_len = len(submitted_provider_ids)
                        case_len = len(case_provider_ids)
                        if submitted_len < case_len:
                            for x in range(case_len-submitted_len):
                                submitted_provider_ids.append('')
                        pdoc.update_providers(self.request.couch_user, submitted_provider_ids)
                        resp.write("success")
                        resp.status_code=204
                    except Exception, ex:
                        resp.write("Error submitting: %s" % ex)
                        resp.status_code=500
                else:
                    resp.write("")
                    resp.status_code=304
Exemplo n.º 2
0
    def post(self,  *args, **kwargs):
        from pact.models import PactPatientCase, CDotWeeklySchedule

        pdoc = PactPatientCase.get(self.request.GET['case_id'])
        resp = HttpResponse()
        if self.method == "rm_schedule":
            if self.request.POST.has_key('rm_schedule'):
                #hacky remove schedule method
                pdoc.rm_last_schedule()
                pdoc.save()
                resp.status_code = 204
                return resp

        elif self.method == "schedule":
            form = ScheduleForm(data=self.request.POST)
            if form.is_valid():
                sched = CDotWeeklySchedule()
                for day in DAYS_OF_WEEK:
                    if form.cleaned_data[day] != 'None':
                        setattr(sched, day, form.cleaned_data[day])
                if form.cleaned_data['active_date'] == None:
                    sched.started = datetime.utcnow()
                else:
                    sched.started = datetime.combine(form.cleaned_data['active_date'], time.min)
                sched.comment = form.cleaned_data['comment']
                sched.created_by = self.request.user.username
                sched.deprecated = False
                pdoc.set_schedule(sched)
                pdoc.save()
                set_schedule_case_properties(pdoc)
                resp.status_code = 204
                return resp
            else:
                resp.write(str(form.errors))
                resp.status_code = 406
                return resp

        elif self.method == 'providers':
            try:
                submitted_provider_ids = json.loads(self.request.POST['selected_providers'])
                case_provider_ids = list(pdoc.get_provider_ids())

                if submitted_provider_ids != case_provider_ids:
                    try:
                        #len difference
                        submitted_len = len(submitted_provider_ids)
                        case_len = len(case_provider_ids)
                        if submitted_len < case_len:
                            for x in range(case_len-submitted_len):
                                submitted_provider_ids.append('')
                        pdoc.update_providers(self.request.couch_user, submitted_provider_ids)
                        resp.write("success")
                        resp.status_code=204
                    except Exception, ex:
                        resp.write("Error submitting: %s" % ex)
                        resp.status_code=500
                else:
                    resp.write("")
                    resp.status_code=304
Exemplo n.º 3
0
    def testExtendingPatientSchedule(self):
        def fmt_datetime(dt):
            """Hacky timezone somewhat aware way to get date outputs right"""
            return utc.localize(dt).strftime("%Y-%m-%dT%H:%M:%SZ")
            #return dt.strftime("%Y-%m-%dT%H:%M:%SZ")


        test_patient = PactPatientCase()
        test_patient.computed_ = {}

        #hand make it
        #test_patient.computed_[WEEKLY_SCHEDULE_KEY] = [CDotWeeklySchedule.wrap(x) for x in WEEKLY_SCHEDULE_EXAMPLES]
        test_patient.computed_[WEEKLY_SCHEDULE_KEY] = WEEKLY_SCHEDULE_EXAMPLES

        #verify that tail is <date> - null
        api_schedules =  test_patient.get_schedules(raw_json=True)
        self.assertIsNone(api_schedules[-1]['ended'])
        self.assertEquals(api_schedules[-1]['started'], '2011-02-25T14:05:32Z')

        self.assertEquals(len(api_schedules), len(WEEKLY_SCHEDULE_EXAMPLES))

        #add a new schedule, verify tail is <date>-present, and [-2] is <datex> - <datey>


        test_patient.set_schedule(CDotWeeklySchedule.wrap(NEW_SCHEDULE))

        updated_schedules = test_patient.get_schedules(raw_json=True)
        self.assertIsNone(updated_schedules[-1]['ended'])
        self.assertEquals(len(updated_schedules), len(WEEKLY_SCHEDULE_EXAMPLES)+1)
        #pdb.set_trace()

        self.assertEquals(updated_schedules[-1]['started'][0:10], datetime.utcnow().isoformat()[0:10])

        self.assertIsNotNone(updated_schedules[-2]['ended'])
        print updated_schedules[-2]['ended']
        print datetime.utcnow().isoformat()
        self.assertLess(updated_schedules[-2]['ended'], datetime.utcnow().isoformat())

        ### remove tail
        test_patient.save()
        loaded_patient = PactPatientCase.get(test_patient.get_id)

        loaded_patient.rm_last_schedule()

        removed_schedules = loaded_patient.get_schedules(raw_json=True)
        self.assertEquals(len(removed_schedules), len(WEEKLY_SCHEDULE_EXAMPLES))
        self.assertIsNone(removed_schedules[-1]['ended'])
        self.assertEquals(removed_schedules[-1]['started'], '2011-02-25T14:05:32Z')
Exemplo n.º 4
0
    def testCreatePatientSchedule(self):
        """
        Single schedule create/remove
        """
        test_patient = PactPatientCase()
        test_patient.computed_ = {}
        test_patient.set_schedule(CDotWeeklySchedule.wrap(NEW_SCHEDULE))
        schedules = test_patient.get_schedules()

        self.assertEqual(len(schedules), 1)

        self.assertIsNone(schedules[0].ended)
        self.assertEquals(schedules[0].started.isoformat()[0:10], datetime.utcnow().isoformat()[0:10])
        self.assertTrue(schedules[0].is_current)
        test_patient.rm_last_schedule()
        updated_schedules = test_patient.get_schedules()

        self.assertEqual(len(updated_schedules), 0)
Exemplo n.º 5
0
    def testCreatePatientSchedule(self):
        """
        Single schedule create/remove
        """
        test_patient = PactPatientCase()
        test_patient.computed_ = {}
        test_patient.set_schedule(CDotWeeklySchedule.wrap(NEW_SCHEDULE))
        schedules = test_patient.get_schedules()

        self.assertEqual(len(schedules), 1)

        self.assertIsNone(schedules[0].ended)
        self.assertEquals(schedules[0].started.isoformat()[0:10], datetime.utcnow().isoformat()[0:10])
        self.assertTrue(schedules[0].is_current)
        test_patient.rm_last_schedule()
        updated_schedules = test_patient.get_schedules()

        self.assertEqual(len(updated_schedules), 0)
Exemplo n.º 6
0
    def testExtendingPatientSchedule(self):

        test_patient = PactPatientCase()
        test_patient.computed_ = {}

        # hand make it
        test_patient.computed_[WEEKLY_SCHEDULE_KEY] = WEEKLY_SCHEDULE_EXAMPLES

        # verify that tail is <date> - null
        api_schedules = test_patient.get_schedules(raw_json=True)
        self.assertIsNone(api_schedules[-1]['ended'])
        self.assertEquals(api_schedules[-1]['started'], '2011-02-25T14:05:32Z')

        self.assertEquals(len(api_schedules), len(WEEKLY_SCHEDULE_EXAMPLES))

        # add a new schedule, verify tail is <date>-present, and [-2] is <datex> - <datey>

        test_patient.set_schedule(CDotWeeklySchedule.wrap(NEW_SCHEDULE))

        updated_schedules = test_patient.get_schedules(raw_json=True)
        self.assertIsNone(updated_schedules[-1]['ended'])
        self.assertEquals(len(updated_schedules),
                          len(WEEKLY_SCHEDULE_EXAMPLES) + 1)

        self.assertEquals(updated_schedules[-1]['started'][0:10],
                          datetime.utcnow().isoformat()[0:10])

        self.assertIsNotNone(updated_schedules[-2]['ended'])
        self.assertLess(updated_schedules[-2]['ended'],
                        datetime.utcnow().isoformat())

        # remove tail
        test_patient.save()
        loaded_patient = PactPatientCase.get(test_patient.get_id)

        loaded_patient.rm_last_schedule()

        removed_schedules = loaded_patient.get_schedules(raw_json=True)
        self.assertEquals(len(removed_schedules),
                          len(WEEKLY_SCHEDULE_EXAMPLES))
        self.assertIsNone(removed_schedules[-1]['ended'])
        self.assertEquals(removed_schedules[-1]['started'],
                          '2011-02-25T14:05:32Z')
Exemplo n.º 7
0
    def testExtendingPatientSchedule(self):

        test_patient = PactPatientCase()
        test_patient.computed_ = {}

        # hand make it
        test_patient.computed_[WEEKLY_SCHEDULE_KEY] = WEEKLY_SCHEDULE_EXAMPLES

        # verify that tail is <date> - null
        api_schedules = test_patient.get_schedules(raw_json=True)
        self.assertIsNone(api_schedules[-1]['ended'])
        self.assertEquals(api_schedules[-1]['started'],
                          '2011-02-25T14:05:32Z')

        self.assertEquals(len(api_schedules), len(WEEKLY_SCHEDULE_EXAMPLES))

        # add a new schedule, verify tail is <date>-present, and [-2] is <datex> - <datey>

        test_patient.set_schedule(CDotWeeklySchedule.wrap(NEW_SCHEDULE))

        updated_schedules = test_patient.get_schedules(raw_json=True)
        self.assertIsNone(updated_schedules[-1]['ended'])
        self.assertEquals(len(updated_schedules), len(WEEKLY_SCHEDULE_EXAMPLES)+1)

        self.assertEquals(updated_schedules[-1]['started'][0:10], datetime.utcnow().isoformat()[0:10])

        self.assertIsNotNone(updated_schedules[-2]['ended'])
        self.assertLess(updated_schedules[-2]['ended'], datetime.utcnow().isoformat())

        # remove tail
        test_patient.save()
        loaded_patient = PactPatientCase.get(test_patient.get_id)

        loaded_patient.rm_last_schedule()

        removed_schedules = loaded_patient.get_schedules(raw_json=True)
        self.assertEquals(len(removed_schedules), len(WEEKLY_SCHEDULE_EXAMPLES))
        self.assertIsNone(removed_schedules[-1]['ended'])
        self.assertEquals(removed_schedules[-1]['started'],
                          '2011-02-25T14:05:32Z')