Example #1
0
    def report_context(self):
        self.report_template_path = "patient_info.html"
        ret = super(PatientInfoReport, self).report_context
        self.update_app_info()
        ret['view_mode'] = 'info'
        patient_info = PatientInfoDisplay(ret['patient'])

        #  check user role:
        user = self.request.couch_user
        if is_pm_or_pi(user):
            ret['edit_patient_info_url'] = self.get_form_url(self.pm_app_dict,
                                                             self.latest_pm_build, PM_APP_PM_MODULE,
                                                             PM_PM2, ret['patient']['_id'])
        elif is_cm(user):
            ret['edit_patient_info_url'] = self.get_form_url(self.cm_app_dict, self.latest_cm_build,
                                                             CM_APP_PD_MODULE, PM_PM2, ret['patient']['_id'])
        elif is_chw(user):
            ret['edit_patient_info_url'] = self.get_form_url(self.chw_app_dict, self.latest_chw_build,
                                                             CHW_APP_PD_MODULE, PM2, ret['patient']['_id'])

        ret['upcoming_appointments_url'] = None
        if is_cm(user):
            ret['upcoming_appointments_url'] = self.get_form_url(self.cm_app_dict, self.latest_cm_build,
                                                                 CM_APP_APPOINTMENTS_MODULE, AP2,
                                                                 ret['patient']['_id'])

        ret['general_information'] = patient_info.general_information
        ret['contact_information'] = patient_info.contact_information
        ret['most_recent_lab_exams'] = patient_info.most_recent_lab_exams
        ret['allergies'] = patient_info.allergies
        return ret
    def report_context(self):
        self.report_template_path = "patient_tasks.html"
        ret = super(PatientTasksReport, self).report_context
        ret['view_mode'] = 'plan'
        case = self.get_case()

        #  check user role:
        user = self.request.couch_user
        ret['patient_task_list_url'] = html.escape(PatientTaskListReport.get_url(*[case["domain"]]) + "?patient_id=%s&task_status=%s" % (case["_id"], "open"))
        if is_cm(user):
            ret['create_new_task_url'] = self.get_form_url(self.cm_app_dict, self.latest_cm_build, CM_APP_CREATE_TASK_MODULE, CM_NEW_TASK, ret['patient']['_id'])
        elif is_chw(user):
            ret['create_new_task_url'] = self.get_form_url(self.chw_app_dict, self.latest_chw_build, CHW_APP_TASK_MODULE, CM_NEW_TASK, ret['patient']['_id'])
        return ret
    def report_context(self):
        self.report_template_path = "patient_tasks.html"
        ret = super(PatientTasksReport, self).report_context
        ret['view_mode'] = 'plan'
        case = self.get_case()

        #  check user role:
        user = self.request.couch_user
        ret['patient_task_list_url'] = html.escape(
            PatientTaskListReport.get_url(*[case["domain"]]) +
            "?patient_id=%s&task_status=%s" % (case["_id"], "open"))
        if is_cm(user):
            ret['create_new_task_url'] = self.get_form_url(
                self.cm_app_dict, self.latest_cm_build,
                CM_APP_CREATE_TASK_MODULE, CM_NEW_TASK, ret['patient']['_id'])
        elif is_chw(user):
            ret['create_new_task_url'] = self.get_form_url(
                self.chw_app_dict, self.latest_chw_build, CHW_APP_TASK_MODULE,
                CM_NEW_TASK, ret['patient']['_id'])
        return ret
Example #4
0
    def report_context(self):
        ret = {}

        try:
            case = self.get_case()
            has_error = False
        except ResourceNotFound:

            has_error = True
            case = None
        if case is None:
            self.report_template_path = "patient_error.html"
            if has_error:
                ret['error_message'] = "Patient not found"
            else:
                ret['error_message'] = "No patient selected"
            return ret


        def get_form_url(app_dict, app_build_id, module_idx, form, case_id=None):
            try:
                module = app_dict['modules'][module_idx]
                form_idx = [ix for (ix, f) in enumerate(module['forms']) if f['xmlns'] == form][0]
            except IndexError:
                form_idx = None

            return html.escape(get_cloudcare_form_url(domain=self.domain,
                                                      app_build_id=app_build_id,
                                                      module_id=module_idx,
                                                      form_id=form_idx,
                                                      case_id=case_id) + '/enter/')

        try:
            cm_app_dict = get_cloudcare_app(case['domain'], SUCCEED_CM_APPNAME)
            latest_cm_build = get_app_build(cm_app_dict)
            pm_app_dict = get_cloudcare_app(case['domain'], SUCCEED_PM_APPNAME)
            latest_pm_build = get_app_build(pm_app_dict)
            chw_app_dict = get_cloudcare_app(case['domain'], SUCCEED_CHW_APPNAME)
            latest_chw_build = get_app_build(pm_app_dict)
        except ResourceNotFound as ex:
            self.report_template_path = "patient_error.html"
            ret['error_message'] = ex.message
            return ret

        ret['patient'] = case
        ret['root_url'] = '?patient_id=%s' % case['_id']
        ret['view_mode'] = self.view_mode
        ret['patient_status_access'] = self.patient_status_access
        ret['submission_user_access'] = self.submission_user_access

        if self.view_mode == 'info':
            self.report_template_path = "patient_info.html"
            patient_info = PatientInfoDisplay(case)

            #  check user role:
            user = self.request.couch_user
            if is_pm_or_pi(user):
                ret['edit_patient_info_url'] = get_form_url(pm_app_dict, latest_pm_build, PM_APP_PM_MODULE, PM_PM2, case['_id'])
            elif is_cm(user):
                ret['edit_patient_info_url'] = get_form_url(cm_app_dict, latest_cm_build, CM_APP_PD_MODULE, PM2, case['_id'])
            elif is_chw(user):
                ret['edit_patient_info_url'] = get_form_url(chw_app_dict, latest_chw_build, CHW_APP_PD_MODULE, PM2, case['_id'])

            if is_pm_or_pi(user):
                ret['upcoming_appointments_url'] = get_form_url(pm_app_dict, latest_pm_build, PM_APP_PM_MODULE, PM_PM2, case['_id'])
            elif is_cm(user):
                ret['upcoming_appointments_url'] = get_form_url(cm_app_dict, latest_cm_build, CM_APP_PD_MODULE, PM2, case['_id'])
            elif is_chw(user):
                ret['upcoming_appointments_url'] = get_form_url(chw_app_dict, latest_chw_build, CHW_APP_MA_MODULE, AP2, case['_id'])

            ret['general_information'] = patient_info.general_information
            ret['contact_information'] = patient_info.contact_information
            ret['most_recent_lab_exams'] = patient_info.most_recent_lab_exams
            ret['allergies'] = patient_info.allergies

        elif self.view_mode == 'submissions':
            if self.submission_user_access:
                tabular_context = super(PatientInfoReport, self).report_context
                tabular_context.update(ret)
                self.report_template_path = "patient_submissions.html"
                tabular_context['patient_id'] = self.request_params['patient_id']

                return tabular_context
            else:
                self.report_template_path = "patient_error.html"
                ret['error_message'] = "Cannot access report(incorrect user role)"
                return ret
        elif self.view_mode == 'interactions':
            self.report_template_path = "patient_interactions.html"
            ret['problem_url'] = get_form_url(cm_app_dict, latest_cm_build, CM_APP_PD_MODULE, PD1, case['_id'])
            ret['huddle_url'] = get_form_url(cm_app_dict, latest_cm_build, CM_APP_HUD_MODULE, HUD2, case['_id'])
            ret['cm_phone_url'] = get_form_url(cm_app_dict, latest_cm_build, CM_APP_CM_MODULE, CM6, case['_id'])
            ret['chw_phone_url'] = get_form_url(cm_app_dict, latest_cm_build, CM_APP_CHW_MODULE, CHW3, case['_id'])
            ret['cm_visits_url'] = get_form_url(cm_app_dict, latest_cm_build, CM_APP_APPOINTMENTS_MODULE, AP2, case['_id'])

            ret['anti_thrombotic_url'] = get_form_url(cm_app_dict, latest_cm_build, CM_APP_MEDICATIONS_MODULE, PD2AM, case['_id'])
            ret['blood_pressure_url'] = get_form_url(cm_app_dict, latest_cm_build, CM_APP_MEDICATIONS_MODULE, PD2BPM, case['_id'])
            ret['cholesterol_url'] = get_form_url(cm_app_dict, latest_cm_build, CM_APP_MEDICATIONS_MODULE, PD2CHM, case['_id'])
            ret['depression_url'] = get_form_url(cm_app_dict, latest_cm_build, CM_APP_MEDICATIONS_MODULE, PD2DIABM, case['_id'])
            ret['diabetes_url'] = get_form_url(cm_app_dict, latest_cm_build, CM_APP_MEDICATIONS_MODULE, PD2DEPM, case['_id'])
            ret['smoking_cessation_url'] = get_form_url(cm_app_dict, latest_cm_build, CM_APP_MEDICATIONS_MODULE, PD2SCM, case['_id'])
            ret['other_meds_url'] = get_form_url(cm_app_dict, latest_cm_build, CM_APP_MEDICATIONS_MODULE, PD2OM, case['_id'])

            ret['interaction_table'] = []
            for visit_key, visit in enumerate(VISIT_SCHEDULE):
                if case["randomization_date"]:
                    target_date = (case["randomization_date"] + timedelta(days=visit['days'])).strftime(OUTPUT_DATE_FORMAT)
                else:
                    target_date = EMPTY_FIELD
                interaction = {
                    'url': '',
                    'name': visit['visit_name'],
                    'target_date': target_date,
                    'received_date': EMPTY_FIELD,
                    'completed_by': EMPTY_FIELD,
                    'scheduled_date': EMPTY_FIELD
                }
                for key, action in enumerate(case['actions']):
                    if visit['xmlns'] == action['xform_xmlns']:
                        interaction['received_date'] = action['date'].strftime(INTERACTION_OUTPUT_DATE_FORMAT)
                        try:
                            user = CouchUser.get(action['user_id'])
                            interaction['completed_by'] = user.raw_username
                        except ResourceNotFound:
                            interaction['completed_by'] = EMPTY_FIELD
                        del case['actions'][key]
                        break
                if visit['show_button']:
                    interaction['url'] = get_form_url(cm_app_dict, latest_cm_build, visit['module_idx'], visit['xmlns'], case['_id'])
                if 'scheduled_source' in visit and case.get_case_property(visit['scheduled_source']):
                    interaction['scheduled_date'] = format_date(case.get_case_property(visit['scheduled_source']), INTERACTION_OUTPUT_DATE_FORMAT)

                ret['interaction_table'].append(interaction)

                medication = []
                for med_prop in MEDICATION_DETAILS:
                    medication.append(getattr(case, med_prop, EMPTY_FIELD))
                ret['medication_table'] = medication

        elif self.view_mode == 'plan':
            self.report_template_path = "patient_plan.html"
        elif self.view_mode == 'status':
            if self.patient_status_access:
                self.report_template_path = "patient_status.html"
                ret['disenroll_patient_url'] = get_form_url(pm_app_dict, latest_pm_build, PM_APP_PM_MODULE, PM3)
                ret['change_patient_data_url'] = get_form_url(pm_app_dict, latest_pm_build, PM_APP_PM_MODULE, PM4)
            else:
                self.report_template_path = "patient_error.html"
                ret['error_message'] = "Only PMs can disenrollment participants"
                return ret
        else:
            raise Http404
        return ret
Example #5
0
 def submission_user_access(self):
     user = self.request.couch_user
     if user and (is_pi(user) or is_cm(user) or is_chw(user)):
         return True
     return False
    def report_context(self):
        self.report_template_path = "patient_interactions.html"
        ret = super(PatientInteractionsReport, self).report_context
        self.update_app_info()

        ret['view_mode'] = 'interactions'
        ret['problem_url'] = self.get_form_url(self.cm_app_dict, self.latest_cm_build,
                                               CM_APP_PD_MODULE, PD1, ret['patient']['_id'])
        ret['huddle_url'] = self.get_form_url(self.cm_app_dict, self.latest_cm_build,
                                              CM_APP_HUD_MODULE, HUD2, ret['patient']['_id'])
        ret['cm_phone_url'] = self.get_form_url(self.cm_app_dict, self.latest_cm_build,
                                                CM_APP_CM_MODULE, CM6_PHONE, ret['patient']['_id'])
        ret['cm_visits_url'] = self.get_form_url(self.cm_app_dict, self.latest_cm_build,
                                                 CM_APP_CM_MODULE, CM4, ret['patient']['_id'])

        ret['anti_thrombotic_url'] = self.get_form_url(self.cm_app_dict, self.latest_cm_build,
                                                       CM_APP_MEDICATIONS_MODULE, PD2AM, ret['patient']['_id'])
        ret['blood_pressure_url'] = self.get_form_url(self.cm_app_dict, self.latest_cm_build,
                                                      CM_APP_MEDICATIONS_MODULE, PD2BPM, ret['patient']['_id'])
        ret['cholesterol_url'] = self.get_form_url(self.cm_app_dict, self.latest_cm_build,
                                                   CM_APP_MEDICATIONS_MODULE, PD2CHM, ret['patient']['_id'])
        ret['diabetes_url'] = self.get_form_url(self.cm_app_dict, self.latest_cm_build,
                                                CM_APP_MEDICATIONS_MODULE, PD2DIABM, ret['patient']['_id'])
        ret['depression_url'] = self.get_form_url(self.cm_app_dict, self.latest_cm_build,
                                                  CM_APP_MEDICATIONS_MODULE, PD2DEPM, ret['patient']['_id'])
        ret['smoking_cessation_url'] = self.get_form_url(self.cm_app_dict, self.latest_cm_build,
                                                         CM_APP_MEDICATIONS_MODULE, PD2SCM, ret['patient']['_id'])
        ret['other_meds_url'] = self.get_form_url(self.cm_app_dict, self.latest_cm_build,
                                                  CM_APP_MEDICATIONS_MODULE, PD2OM, ret['patient']['_id'])

        ret['interaction_table'] = []
        for visit_key, visit in enumerate(VISIT_SCHEDULE):
            if visit['target_date_case_property'] in ret['patient'] and \
                    ret['patient'][visit['target_date_case_property']]:
                try:
                    target_date = (ret['patient'][visit['target_date_case_property']])
                except TypeError:
                    target_date = _("Bad Date Format!")
            else:
                target_date = EMPTY_FIELD

            received_date = EMPTY_FIELD
            for completed in visit['completed_date']:
                if completed in ret['patient']:
                    received_date = ret['patient'][completed]

            interaction = {
                'url': '',
                'name': visit['visit_name'],
                'target_date': target_date,
                'received_date': received_date,
            }

            if visit['show_button']:
                interaction['url'] = self.get_form_url(self.cm_app_dict, self.latest_cm_build,
                                                       visit['module_idx'], visit['xmlns'], ret['patient']['_id'])

            ret['interaction_table'].append(interaction)

            medication = []
            for med_prop in MEDICATION_DETAILS:
                if med_prop == 'MEDS_diabetes_prescribed':
                    oral = getattr(ret['patient'], 'MEDS_diabetes-oral_prescribed', None)
                    insulin = getattr(ret['patient'], 'MEDS_diabetes-insulin_prescribed', None)

                    if oral == 'yes':
                        to_append = oral
                    elif insulin == 'yes':
                        to_append = insulin
                    else:
                        to_append = EMPTY_FIELD

                    medication.append(to_append)
                else:
                    medication.append(getattr(ret['patient'], med_prop, EMPTY_FIELD))
            ret['medication_table'] = medication

        user = self.request.couch_user
        ret['patient_task_list_url'] = html.escape(
            PatientTaskListReport.get_url(*[ret['patient']["domain"]]) +
            "?patient_id=%s&task_status=%s" % (ret['patient']["_id"], "open"))
        if is_cm(user):
            ret['create_new_task_url'] = self.get_form_url(self.cm_app_dict, self.latest_cm_build,
                                                           CM_APP_CREATE_TASK_MODULE, CM_NEW_TASK,
                                                           ret['patient']['_id'])
        elif is_chw(user):
            ret['create_new_task_url'] = self.get_form_url(self.chw_app_dict, self.latest_chw_build,
                                                           CHW_APP_TASK_MODULE, CM_NEW_TASK, ret['patient']['_id'])

        ret['view_appointments_url'] = self.get_form_url(self.cm_app_dict, self.latest_cm_build,
                                                         CM_APP_APPOINTMENTS_MODULE, AP2,
                                                         parent_id=ret['patient']['_id'])
        ret['add_appointments_url'] = self.get_form_url(self.cm_app_dict, self.latest_cm_build,
                                                        CM_APP_PD_MODULE, AP1,
                                                        case_id=ret['patient']['_id'])

        # Risk Factor Table
        rows = []
        for key, val in six.iteritems(RISK_FACTOR_CONFIG):
            data = [key]
            for v in val:
                case_data = ret['patient'][v] if v in ret['patient'] else ''
                if key == 'Status:':
                    if case_data:
                        case_data = case_data.replace('-', ' ').title()
                    else:
                        case_data = EMPTY_FIELD
                data.append(case_data)
            rows.append(data)

        ret['risk_factor_table'] = rows
        return ret
    def report_context(self):
        self.report_template_path = "patient_interactions.html"
        ret = super(PatientInteractionsReport, self).report_context
        self.update_app_info()

        ret['view_mode'] = 'interactions'
        ret['problem_url'] = self.get_form_url(self.cm_app_dict, self.latest_cm_build,
                                               CM_APP_PD_MODULE, PD1, ret['patient']['_id'])
        ret['huddle_url'] = self.get_form_url(self.cm_app_dict, self.latest_cm_build,
                                              CM_APP_HUD_MODULE, HUD2, ret['patient']['_id'])
        ret['cm_phone_url'] = self.get_form_url(self.cm_app_dict, self.latest_cm_build,
                                                CM_APP_CM_MODULE, CM6_PHONE, ret['patient']['_id'])
        ret['cm_visits_url'] = self.get_form_url(self.cm_app_dict, self.latest_cm_build,
                                                 CM_APP_CM_MODULE, CM4, ret['patient']['_id'])

        ret['anti_thrombotic_url'] = self.get_form_url(self.cm_app_dict, self.latest_cm_build,
                                                       CM_APP_MEDICATIONS_MODULE, PD2AM, ret['patient']['_id'])
        ret['blood_pressure_url'] = self.get_form_url(self.cm_app_dict, self.latest_cm_build,
                                                      CM_APP_MEDICATIONS_MODULE, PD2BPM, ret['patient']['_id'])
        ret['cholesterol_url'] = self.get_form_url(self.cm_app_dict, self.latest_cm_build,
                                                   CM_APP_MEDICATIONS_MODULE, PD2CHM, ret['patient']['_id'])
        ret['diabetes_url'] = self.get_form_url(self.cm_app_dict, self.latest_cm_build,
                                                CM_APP_MEDICATIONS_MODULE, PD2DIABM, ret['patient']['_id'])
        ret['depression_url'] = self.get_form_url(self.cm_app_dict, self.latest_cm_build,
                                                  CM_APP_MEDICATIONS_MODULE, PD2DEPM, ret['patient']['_id'])
        ret['smoking_cessation_url'] = self.get_form_url(self.cm_app_dict, self.latest_cm_build,
                                                         CM_APP_MEDICATIONS_MODULE, PD2SCM, ret['patient']['_id'])
        ret['other_meds_url'] = self.get_form_url(self.cm_app_dict, self.latest_cm_build,
                                                  CM_APP_MEDICATIONS_MODULE, PD2OM, ret['patient']['_id'])

        ret['interaction_table'] = []
        for visit_key, visit in enumerate(VISIT_SCHEDULE):
            if visit['target_date_case_property'] in ret['patient'] and \
                    ret['patient'][visit['target_date_case_property']]:
                try:
                    target_date = (ret['patient'][visit['target_date_case_property']])
                except TypeError:
                    target_date = _("Bad Date Format!")
            else:
                target_date = EMPTY_FIELD

            received_date = EMPTY_FIELD
            for completed in visit['completed_date']:
                if completed in ret['patient']:
                    received_date = ret['patient'][completed]

            schedulet_date = EMPTY_FIELD
            if 'scheduled_source' in visit and ret['patient'].get_case_property(visit['scheduled_source']):
                schedulet_date = ret['patient'].get_case_property(visit['scheduled_source'])

            interaction = {
                'url': '',
                'name': visit['visit_name'],
                'target_date': target_date,
                'received_date': received_date,
                'completed_by': EMPTY_FIELD,
                'scheduled_date': schedulet_date
            }

            if visit['show_button']:
                interaction['url'] = self.get_form_url(self.cm_app_dict, self.latest_cm_build,
                                                       visit['module_idx'], visit['xmlns'], ret['patient']['_id'])


            ret['interaction_table'].append(interaction)

            medication = []
            for med_prop in MEDICATION_DETAILS:
                medication.append(getattr(ret['patient'], med_prop, EMPTY_FIELD))
            ret['medication_table'] = medication

        user = self.request.couch_user
        ret['patient_task_list_url'] = html.escape(
            PatientTaskListReport.get_url(*[ret['patient']["domain"]]) +
            "?patient_id=%s&task_status=%s" % (ret['patient']["_id"], "open"))
        if is_cm(user):
            ret['create_new_task_url'] = self.get_form_url(self.cm_app_dict, self.latest_cm_build,
                                                           CM_APP_CREATE_TASK_MODULE, CM_NEW_TASK,
                                                           ret['patient']['_id'])
        elif is_chw(user):
            ret['create_new_task_url'] = self.get_form_url(self.chw_app_dict, self.latest_chw_build,
                                                           CHW_APP_TASK_MODULE, CM_NEW_TASK, ret['patient']['_id'])

        ret['view_appointments_url'] = self.get_form_url(self.cm_app_dict, self.latest_cm_build,
                                                         CM_APP_APPOINTMENTS_MODULE, AP2,
                                                         parent_id=ret['patient']['_id'])
        ret['add_appointments_url'] = self.get_form_url(self.cm_app_dict, self.latest_cm_build,
                                                        CM_APP_PD_MODULE, AP1,
                                                        case_id=ret['patient']['_id'])

        # Risk Factor Table
        rows = []
        for key, val in RISK_FACTOR_CONFIG.iteritems():
            data = [key]
            for v in val:
                case_data = ret['patient'][v] if v in ret['patient'] else ''
                if key == 'Status:':
                    if case_data:
                        case_data = case_data.replace('-', ' ').title()
                    else:
                        case_data = EMPTY_FIELD
                data.append(case_data)
            rows.append(data)

        ret['risk_factor_table'] = rows
        return ret
Example #8
0
 def submission_user_access(self):
     user = self.request.couch_user
     if user and (is_pi(user) or is_cm(user) or is_chw(user)):
         return True
     return False
Example #9
0
        ret['patient'] = case
        ret['root_url'] = '?patient_id=%s' % case['_id']
        ret['view_mode'] = self.view_mode
        ret['patient_status_access'] = self.patient_status_access
        ret['submission_user_access'] = self.submission_user_access

        if self.view_mode == 'info':
            self.report_template_path = "patient_info.html"
            patient_info = PatientInfoDisplay(case)

            #  check user role:
            user = self.request.couch_user
            if is_pm_or_pi(user):
                ret['edit_patient_info_url'] = get_form_url(
                    pm_app_dict, latest_pm_build, PM_APP_PM_MODULE, PM2)
            elif is_cm(user):
                ret['edit_patient_info_url'] = get_form_url(
                    cm_app_dict, latest_cm_build, CM_APP_PD_MODULE, PM2)
            elif is_chw(user):
                ret['edit_patient_info_url'] = get_form_url(
                    chw_app_dict, latest_chw_build, CHW_APP_PD_MODULE, PM2)

            if is_pm_or_pi(user):
                ret['upcoming_appointments_url'] = get_form_url(
                    pm_app_dict, latest_pm_build, PM_APP_PM_MODULE, PM2)
            elif is_cm(user):
                ret['upcoming_appointments_url'] = get_form_url(
                    cm_app_dict, latest_cm_build, CM_APP_PD_MODULE, PM2)
            elif is_chw(user):
                ret['upcoming_appointments_url'] = get_form_url(
                    chw_app_dict, latest_chw_build, CHW_APP_MA_MODULE, PM2)