Exemplo n.º 1
0
 def update_app_info(self):
     self.cm_app_dict = get_cloudcare_app(SUCCEED_DOMAIN, SUCCEED_CM_APPNAME)
     self.latest_cm_build = get_app_build(self.cm_app_dict)
     self.pm_app_dict = get_cloudcare_app(SUCCEED_DOMAIN, SUCCEED_PM_APPNAME)
     self.latest_pm_build = get_app_build(self.pm_app_dict)
     self.chw_app_dict = get_cloudcare_app(SUCCEED_DOMAIN, SUCCEED_CHW_APPNAME)
     self.latest_chw_build = get_app_build(self.chw_app_dict)
Exemplo n.º 2
0
 def update_app_info(self):
     self.cm_app_dict = get_cloudcare_app(SUCCEED_DOMAIN, SUCCEED_CM_APPNAME)
     self.latest_cm_build = get_app_build(self.cm_app_dict)
     self.pm_app_dict = get_cloudcare_app(SUCCEED_DOMAIN, SUCCEED_PM_APPNAME)
     self.latest_pm_build = get_app_build(self.pm_app_dict)
     self.chw_app_dict = get_cloudcare_app(SUCCEED_DOMAIN, SUCCEED_CHW_APPNAME)
     self.latest_chw_build = get_app_build(self.chw_app_dict)
Exemplo n.º 3
0
def get_cloudcare_app():
    """
    Total hack function to get direct links to the cloud care application pages
    """

    from corehq.apps.cloudcare import api

    app = api.get_cloudcare_app(PACT_DOMAIN, PACT_CLOUD_APPNAME)
    app_id = app['_id']

    pact_cloudcare = filter(lambda x: x['name']['en'] == PACT_CLOUDCARE_MODULE,
                            app['modules'])
    forms = pact_cloudcare[0]['forms']
    ret = dict((f['name']['en'], ix) for (ix, f) in enumerate(forms))

    url_root = '/a/%(domain)s/cloudcare/apps/view/%(build_id)s/%(module_id)s/%(form_id)s/case/%(case_id)s/enter/'
    ret['url_root'] = url_root
    ret['domain'] = PACT_DOMAIN
    ret['app_id'] = app_id
    latest_build = ApplicationBase.get_latest_build(PACT_DOMAIN, app_id)
    if latest_build is not None:
        latest_build_id = latest_build['_id']
        ret['build_id'] = latest_build_id
    ret['module_id'] = 0
    return ret
Exemplo n.º 4
0
 def __init__(self, request, base_context=None, domain=None, **kwargs):
     super(PatientTaskListReport, self).__init__(request,
                                                 base_context=base_context,
                                                 domain=domain,
                                                 **kwargs)
     self.app_dict = get_cloudcare_app(domain, SUCCEED_CM_APPNAME)
     self.latest_build = get_app_build(self.app_dict)
Exemplo n.º 5
0
    def __init__(self, report, case_dict):

        next_visit = VISIT_SCHEDULE[0]
        last_inter = None
        for action in case_dict['actions']:
            if action['xform_xmlns'] in LAST_INTERACTION_LIST:
                last_inter = action

        for visit_key, visit in enumerate(VISIT_SCHEDULE):
            for key, action in enumerate(case_dict['actions']):
                if visit['xmlns'] == action['xform_xmlns']:
                    try:
                        next_visit = VISIT_SCHEDULE[visit_key + 1]
                        del case_dict['actions'][key]
                        break
                    except IndexError:
                        next_visit = 'last'
        self.next_visit = next_visit
        if last_inter:
            self.last_interaction = last_inter['date']
        self.app_dict = get_cloudcare_app(report.domain, SUCCEED_CM_APPNAME)
        self.latest_build = ApplicationBase.get_latest_build(
            report.domain, self.app_dict['_id'])['_id']
        super(PatientListReportDisplay, self).__init__(report, case_dict)
        self.update_target_date_case_properties()
Exemplo n.º 6
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

        try:
            self.cm_app_dict = get_cloudcare_app(case['domain'], SUCCEED_CM_APPNAME)
            self.latest_cm_build = get_app_build(self.cm_app_dict)
            self.pm_app_dict = get_cloudcare_app(case['domain'], SUCCEED_PM_APPNAME)
            self.latest_pm_build = get_app_build(self.pm_app_dict)
            self.chw_app_dict = get_cloudcare_app(case['domain'], SUCCEED_CHW_APPNAME)
            self.latest_chw_build = get_app_build(self.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['patient_info_url'] = self.patient_info_url
        ret['patient_submission_url'] = self.patient_submission_url
        ret['patient_interactions_url'] = self.patient_interactions_url
        ret['patient_careplan_url'] = self.patient_careplan_url
        ret['patient_status_url'] = self.patient_status_url
        return ret
Exemplo n.º 7
0
def get_cloudcare_app():
    """
    Total hack function to get direct links to the cloud care application pages
    """

    from corehq.apps.cloudcare import api

    app = api.get_cloudcare_app(PACT_DOMAIN, PACT_CLOUD_APPNAME)
    app_id = app['_id']

    pact_cloudcare = [x for x in app['modules'] if x['name']['en'] == PACT_CLOUDCARE_MODULE]
    forms = pact_cloudcare[0]['forms']
    ret = dict((f['name']['en'], ix) for (ix, f) in enumerate(forms))

    ret['app_id'] = app_id
    ret['build_id'] = get_latest_build_id(PACT_DOMAIN, app_id)
    return ret
Exemplo n.º 8
0
def get_cloudcare_app():
    """
    Total hack function to get direct links to the cloud care application pages
    """

    from corehq.apps.cloudcare import api

    app = api.get_cloudcare_app(PACT_DOMAIN, PACT_CLOUD_APPNAME)
    app_id = app['_id']

    pact_cloudcare = [x for x in app['modules'] if x['name']['en'] == PACT_CLOUDCARE_MODULE]
    forms = pact_cloudcare[0]['forms']
    ret = dict((f['name']['en'], ix) for (ix, f) in enumerate(forms))

    ret['app_id'] = app_id
    ret['build_id'] = get_latest_build_id(PACT_DOMAIN, app_id)
    return ret
Exemplo n.º 9
0
def get_cloudcare_app():
    """
    Total hack function to get direct links to the cloud care application pages
    """

    from corehq.apps.cloudcare import api

    app = api.get_cloudcare_app(PACT_DOMAIN, PACT_CLOUD_APPNAME)
    app_id = app['_id']

    pact_cloudcare = filter(lambda x: x['name']['en'] == PACT_CLOUDCARE_MODULE, app['modules'])
    forms = pact_cloudcare[0]['forms']
    ret = dict((f['name']['en'], ix) for (ix, f) in enumerate(forms))

    url_root = '/a/%(domain)s/cloudcare/apps/view/%(build_id)s/%(module_id)s/%(form_id)s/case/%(case_id)s/enter/'
    ret['url_root'] = url_root
    ret['domain'] = PACT_DOMAIN
    ret['app_id'] = app_id
    latest_build_id = get_latest_build_id(PACT_DOMAIN, app_id)
    if latest_build_id is not None:
        ret['build_id'] = latest_build_id
    ret['module_id'] = 0
    return ret
Exemplo n.º 10
0
 def columns(self):
     app_dict = get_cloudcare_app(SUCCEED_DOMAIN, SUCCEED_CM_APPNAME)
     latest_build = get_app_build(app_dict)
     return [
         DatabaseColumn('Modify Schedule', SimpleColumn('doc_id', alias='case_id'),
                        format_fn=lambda x: edit_link(x, app_dict, latest_build)),
         AggregateColumn('Name', aggregate_fn=case_link,
                         columns=[SimpleColumn('name'), AliasColumn('case_id')], sort_type=''),
         DatabaseColumn('MRN', SimpleColumn('mrn')),
         DatabaseColumn('Randomization Date', SimpleColumn('date', alias='rand_date')),
         DatabaseColumn('Visit Name', SimpleColumn('visit_name', alias='vis_name')),
         AggregateColumn('Target Date',
                         aggregate_fn=target_date,
                         columns=[
                             AliasColumn('vis_name'),
                             SimpleColumn('visit_days'),
                             AliasColumn('rand_date')
                         ], sort_type=DTSortType.NUMERIC),
         DatabaseColumn('Most Recent', SimpleColumn('bp_category')),
         DatabaseColumn('Last Interaction Date', SimpleColumn('last_interaction'), format_fn=date_format),
         DatabaseColumn('Tasks', AliasColumn('case_id'), format_fn=tasks),
         DatabaseColumn('Care Team', SimpleColumn('owner_id'), format_fn=group_name)
     ]
Exemplo n.º 11
0
 def columns(self):
     app_dict = get_cloudcare_app(SUCCEED_DOMAIN, SUCCEED_CM_APPNAME)
     latest_build = get_app_build(app_dict)
     return [
         DatabaseColumn('Modify Schedule', SimpleColumn('doc_id', alias='case_id'),
                        format_fn=lambda x: edit_link(x, app_dict, latest_build)),
         AggregateColumn('Name', aggregate_fn=case_link,
                         columns=[SimpleColumn('name'), AliasColumn('case_id')], sort_type=''),
         DatabaseColumn('MRN', SimpleColumn('mrn')),
         DatabaseColumn('Randomization Date', SimpleColumn('date', alias='rand_date')),
         DatabaseColumn('Visit Name', SimpleColumn('visit_name', alias='vis_name')),
         AggregateColumn('Target Date',
                         aggregate_fn=target_date,
                         columns=[
                             AliasColumn('vis_name'),
                             SimpleColumn('visit_days'),
                             AliasColumn('rand_date')
                         ], sort_type=DTSortType.NUMERIC),
         DatabaseColumn('Most Recent', SimpleColumn('bp_category')),
         DatabaseColumn('Last Interaction Date', SimpleColumn('last_interaction'), format_fn=date_format),
         DatabaseColumn('Tasks', AliasColumn('case_id'), format_fn=tasks),
         DatabaseColumn('Care Team', SimpleColumn('owner_id'), format_fn=group_name)
     ]
Exemplo n.º 12
0
    def __init__(self, report, case_dict):

        next_visit = VISIT_SCHEDULE[0]
        last_inter = None
        for action in case_dict['actions']:
            if action['xform_xmlns'] in LAST_INTERACTION_LIST:
                last_inter = action

        for visit_key, visit in enumerate(VISIT_SCHEDULE):
            for key, action in enumerate(case_dict['actions']):
                if visit['xmlns'] == action['xform_xmlns']:
                    try:
                        next_visit = VISIT_SCHEDULE[visit_key + 1]
                        del case_dict['actions'][key]
                        break
                    except IndexError:
                        next_visit = 'last'
        self.next_visit = next_visit
        if last_inter:
            self.last_interaction = last_inter['date']
        self.app_dict = get_cloudcare_app(report.domain, SUCCEED_CM_APPNAME)
        self.latest_build = get_app_build(self.app_dict)
        super(PatientListReportDisplay, self).__init__(report, case_dict)
Exemplo n.º 13
0
def get_cloudcare_app():
    """
    Total hack function to get direct links to the cloud care application pages
    """

    from corehq.apps.cloudcare import api

    app = api.get_cloudcare_app(PACT_DOMAIN, PACT_CLOUD_APPNAME)
    app_id = app["_id"]

    pact_cloudcare = filter(lambda x: x["name"]["en"] == PACT_CLOUDCARE_MODULE, app["modules"])
    forms = pact_cloudcare[0]["forms"]
    ret = dict((f["name"]["en"], ix) for (ix, f) in enumerate(forms))

    url_root = "/a/%(domain)s/cloudcare/apps/view/%(build_id)s/%(module_id)s/%(form_id)s/case/%(case_id)s/enter/"
    ret["url_root"] = url_root
    ret["domain"] = PACT_DOMAIN
    ret["app_id"] = app_id
    latest_build = ApplicationBase.get_latest_build(PACT_DOMAIN, app_id)
    if latest_build is not None:
        latest_build_id = latest_build["_id"]
        ret["build_id"] = latest_build_id
    ret["module_id"] = 0
    return ret
Exemplo n.º 14
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
Exemplo n.º 15
0
 def __init__(self, request, base_context=None, domain=None, **kwargs):
     super(PatientTaskListReport, self).__init__(request, base_context=base_context, domain=domain, **kwargs)
     self.app_dict = get_cloudcare_app(domain, SUCCEED_CM_APPNAME)
     self.latest_build = get_app_build(self.app_dict)