コード例 #1
0
    def report_context(self):
        from pact import api
        ret = {}
        try:
            patient_doc = self.get_case()
            has_error = False
        except Exception as ex:
            logging.exception('problem getting pact patient data for patient {}. {}'.format(
                self.patient_id, ex
            ))
            has_error = True
            patient_doc = None

        if patient_doc is None:
            self.report_template_path = "pact/patient/nopatient.html"
            if has_error:
                ret['error_message'] = "Patient not found"
            else:
                ret['error_message'] = "No patient selected"
            return ret

        view_mode = self.request.GET.get('view', 'info')
        ret['patient_doc'] = patient_doc
        ret['pt_root_url'] = patient_doc.get_info_url()
        ret['view_mode'] = view_mode

        if view_mode == 'info':
            self.report_template_path = "pact/patient/pactpatient_info.html"
            ret['cloudcare_addr_edit_url'] = api.get_cloudcare_url(patient_doc._id,
                                                                   api.FORM_ADDRESS)
            ret['cloudcare_pn_url'] = api.get_cloudcare_url(patient_doc._id, api.FORM_PROGRESS_NOTE)
            ret['cloudcare_dot_url'] = api.get_cloudcare_url(patient_doc._id, api.FORM_DOT)
            ret['cloudcare_bw_url'] = api.get_cloudcare_url(patient_doc._id, api.FORM_BLOODWORK)
        elif view_mode == 'submissions':
            tabular_context = super(PactPatientInfoReport, self).report_context
            tabular_context.update(ret)
            self.report_template_path = "pact/patient/pactpatient_submissions.html"
            return tabular_context
        elif view_mode == 'schedule':
            the_form = ScheduleForm()
            ret['schedule_form'] = the_form
            ret['schedule_fields'] = json.dumps(list(the_form.fields.keys()))
            self.report_template_path = "pact/patient/pactpatient_schedule.html"
        elif view_mode == 'edit':
            the_form = PactPatientForm(self.request, patient_doc)
            ret['patient_form'] = the_form
            self.report_template_path = "pact/patient/pactpatient_edit.html"
        elif view_mode == 'providers':
            self.report_template_path = "pact/patient/pactpatient_providers.html"
        elif view_mode == 'careplan':
            ret.update(case_hierarchy_context(patient_doc,
                lambda case_id: reverse('case_data', args=[PACT_DOMAIN, case_id]),
                show_view_buttons=False
            ))
            self.report_template_path = "pact/patient/pactpatient_careplan.html"
        else:
            raise Http404
        return ret
コード例 #2
0
ファイル: api.py プロジェクト: tstalka/commcare-hq
    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 'rm_schedule' in self.request.POST:
                #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 as ex:
                        resp.write("Error submitting: %s" % ex)
                        resp.status_code=500
                else:
                    resp.write("")
                    resp.status_code=304
            except Exception as ex:
                resp.write("Error submitting: %s" % ex)
                resp.status_code=500
            return resp

        elif self.method == "patient_edit":
            form = PactPatientForm(self.request, pdoc, data=self.request.POST)
            if form.is_valid():
                update_data = form.clean_changed_data
                submit_case_update_form(pdoc, update_data, self.request.couch_user)
                resp.status_code = 204
                return resp
            else:
                resp.write(str(form.errors))
                resp.status_code = 406
                return resp
コード例 #3
0
ファイル: patient.py プロジェクト: zbidi/commcare-hq
class PactPatientInfoReport(PactDrilldownReportMixin,
                            PactElasticTabularReportMixin):
    slug = "patient"
    description = "some patient"

    hide_filters = True
    filters = []
    ajax_pagination = True
    xform_es = ReportXFormES(PACT_DOMAIN)

    default_sort = {"received_on": "desc"}

    name = "Patient Info"

    @use_timeago
    def decorator_dispatcher(self, request, *args, **kwargs):
        return super(PactPatientInfoReport,
                     self).decorator_dispatcher(request, *args, **kwargs)

    @property
    def patient_id(self):
        return self.request.GET.get('patient_id')

    def get_case(self):
        if self.patient_id is None:
            return None
        return PactPatientCase.get(self.patient_id)

    @property
    def report_context(self):
        from pact import api
        ret = {}
        try:
            patient_doc = self.get_case()
            has_error = False
        except Exception, ex:
            logging.exception(
                u'problem getting pact patient data for patient {}. {}'.format(
                    self.patient_id, ex))
            has_error = True
            patient_doc = None

        if patient_doc is None:
            self.report_template_path = "pact/patient/nopatient.html"
            if has_error:
                ret['error_message'] = "Patient not found"
            else:
                ret['error_message'] = "No patient selected"
            return ret

        view_mode = self.request.GET.get('view', 'info')
        ret['patient_doc'] = patient_doc
        ret['pt_root_url'] = patient_doc.get_info_url()
        ret['view_mode'] = view_mode

        if view_mode == 'info':
            self.report_template_path = "pact/patient/pactpatient_info.html"
            ret['cloudcare_addr_edit_url'] = api.get_cloudcare_url(
                patient_doc._id, api.FORM_ADDRESS)
            ret['cloudcare_pn_url'] = api.get_cloudcare_url(
                patient_doc._id, api.FORM_PROGRESS_NOTE)
            ret['cloudcare_dot_url'] = api.get_cloudcare_url(
                patient_doc._id, api.FORM_DOT)
            ret['cloudcare_bw_url'] = api.get_cloudcare_url(
                patient_doc._id, api.FORM_BLOODWORK)
        elif view_mode == 'submissions':
            tabular_context = super(PactPatientInfoReport, self).report_context
            tabular_context.update(ret)
            self.report_template_path = "pact/patient/pactpatient_submissions.html"
            return tabular_context
        elif view_mode == 'schedule':
            the_form = ScheduleForm()
            ret['schedule_form'] = the_form
            ret['schedule_fields'] = json.dumps(the_form.fields.keys())
            self.report_template_path = "pact/patient/pactpatient_schedule.html"
        elif view_mode == 'edit':
            the_form = PactPatientForm(self.request, patient_doc)
            ret['patient_form'] = the_form
            self.report_template_path = "pact/patient/pactpatient_edit.html"
        elif view_mode == 'providers':
            self.report_template_path = "pact/patient/pactpatient_providers.html"
        elif view_mode == 'careplan':
            ret.update({
                'case_hierarchy_options': {
                    "show_view_buttons":
                    False,
                    "get_case_url":
                    lambda case_id: reverse('case_details',
                                            args=[PACT_DOMAIN, case_id])
                },
                'case': patient_doc,
            })
            self.report_template_path = "pact/patient/pactpatient_careplan.html"
        else:
            raise Http404
        return ret
コード例 #4
0
ファイル: api.py プロジェクト: LifeCoaching/commcare-hq
                        resp.status_code=204
                    except Exception, ex:
                        resp.write("Error submitting: %s" % ex)
                        resp.status_code=500
                else:
                    resp.write("")
                    resp.status_code=304
            except Exception, ex:
                resp.write("Error submitting: %s" % ex)
                resp.status_code=500
            return resp



        elif self.method == "patient_edit":
            form = PactPatientForm(self.request, pdoc, data=self.request.POST)
            if form.is_valid():
                update_data = form.clean_changed_data
                submit_case_update_form(pdoc, update_data, self.request.couch_user)
                resp.status_code = 204
                return resp
            else:
                resp.write(str(form.errors))
                resp.status_code = 406
                return resp

    def head(self, *args, **kwargs):
        raise NotImplementedError("Not implemented")


    @method_decorator(login_or_digest)
コード例 #5
0
ファイル: api.py プロジェクト: ekush/commcare-hq
                                              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
            except Exception, ex:
                resp.write("Error submitting: %s" % ex)
                resp.status_code = 500
            return resp

        elif self.method == "patient_edit":
            form = PactPatientForm(self.request, pdoc, data=self.request.POST)
            if form.is_valid():
                update_data = form.clean_changed_data
                submit_case_update_form(pdoc, update_data,
                                        self.request.couch_user)
                resp.status_code = 204
                return resp
            else:
                resp.write(str(form.errors))
                resp.status_code = 406
                return resp

    def head(self, *args, **kwargs):
        raise NotImplementedError("Not implemented")

    @method_decorator(login_or_digest)