コード例 #1
0
ファイル: views.py プロジェクト: urbanintell/team_falls
def history(request):
    data_client = DataClient()
    encounter_list = []
    if (request.GET.get('patient') != None):
        data_client.patient = literal_eval(request.GET.get('patient'))
        data_client.fhir_client.select_patient(
            data_client.patient['resource']['id'])
        encounter_list = sorted(data_client.fhir_client.search_encounter_all(),
                                key=cmp_to_key(mycmp))
    # encounter_order = ['in-progress', 'arrived', 'finished']
    for encounter in encounter_list:
        # patient_id_list = encounter['resource']['patient']['reference'].split('/')
        # patient_id = ""
        # if len(patient_id_list) > 1:
        #     patient_id = patient_id_list[1]
        observations = data_client.fhir_client.search_observations(
            enc=encounter['resource']['id'])
        if data_client.risk_list['code'] in observations.keys():
            encounter['risk_level'] = observations[
                data_client.risk_list['code']]

    return render(request, 'app/history.html', {
        'encounters': encounter_list,
        'patient': data_client.patient
    })
コード例 #2
0
ファイル: views.py プロジェクト: urbanintell/team_falls
def questions(request):
    data_client = DataClient()
    completed = get_sidebar_completed()
    if request.method == 'POST':
        question_form = QuestionForm(request.POST)
        if question_form.is_valid():
            score = 0
            key_score = 0
            for i, question in enumerate(data_client.questions['questions']):
                code = data_client.questions['questions'][i]['code']
                field_name = code
                answer = question_form.cleaned_data[field_name]
                data_client.observations[code] = answer
                flag = False
                # This could be fragile if changed to >=2 falls? Or something non 1
                if isinstance(answer, int):
                    if answer >= 1:
                        flag = True
                else:
                    flag = answer
                if flag:
                    score += int(
                        data_client.questions['questions'][i]['score'])
                    if data_client.questions['questions'][i]['is_key']:
                        key_score += 1
            questions_code = data_client.questions['code']
            if (key_score < data_client.questions['question_logic']['min_key']
                    and score <
                    data_client.questions['question_logic']['min_score']):
                data_client.observations[questions_code] = "Pass"
            else:
                data_client.observations[questions_code] = "Fail"
            # save observations to FHIR server
            data_client.fhir_client.write_list_of_observations_to_fhir(
                data=data_client.observations)
            if data_client.identity == 'patient':
                return HttpResponseRedirect('/app/thankyou/')
            else:
                calculate_risk()
                if data_client.risk_level == "incomplete":
                    return HttpResponseRedirect('/app/assessments/')
                elif data_client.risk_level is not None:
                    return HttpResponseRedirect('/app/risks/')
    else:
        if (request.GET.get('patient') != None):
            if (request.GET.get('encounter_id') != None):
                data_client.fhir_client.select_encounter(
                    request.GET.get('encounter_id'))
                data_client.observations = data_client.fhir_client.search_observations(
                )
            elif (request.GET.get('button_type') != None
                  and request.GET.get('button_type') == "start"):
                data_client.reload_data()
                data_client.fhir_client.create_new_encounter(
                    set_as_active_encounter=True)
            data_client.patient = literal_eval(request.GET.get('patient'))
            data_client.fhir_client.select_patient(
                data_client.patient['resource']['id'])
        question_answers = {}
        for i, question in enumerate(data_client.questions['questions']):
            code = data_client.questions['questions'][i]['code']
            if code in data_client.observations:
                code = data_client.questions['questions'][i]['code']
                field_name = code
                question_answers[field_name] = data_client.observations[code]

        completed = get_sidebar_completed()
        question_form = QuestionForm(initial=question_answers)
    if data_client.identity == "patient":
        extends_variable = getattr(settings, 'AUTHBACKEND_LAYOUT_TEMPLATE',
                                   'app/base.html')
    else:
        extends_variable = getattr(settings, 'AUTHBACKEND_LAYOUT_TEMPLATE',
                                   'app/baseWithSideBar.html')

    return render(
        request, 'app/questions.html', {
            'question_form': question_form,
            'patient': data_client.patient,
            'identity': data_client.identity,
            'extends_variable': extends_variable,
            'completed': completed
        })