Exemplo n.º 1
0
def login(request):
    data_client = DataClient()
    data_client.reload_data()
    # Wipe whatever is in memory...?
    # data_client = DataClient().clean()

    if request.method == 'POST':
        login_form = LoginForm(request.POST)
        if login_form.is_valid():
            identity = login_form.cleaned_data['identity']
            if identity == 'patient':
                url = '/app/login/patient/'
                data_client.identity = 'patient'
            elif identity == "care_provider":
                url = '/app/login/care_provider/'
                data_client.identity = 'care_provider'
            return HttpResponseRedirect(url)
    else:
        login_form = LoginForm()

    return render(request, 'app/login.html', {'login_form': login_form})
Exemplo n.º 2
0
def search_patient(request):
    data_client = DataClient()
    # patient_list = []
    data_client.reload_data()
    if request.method == 'POST':
        search_patient_form = SearchPatientForm(request.POST)
        if search_patient_form.is_valid():
            data_client = DataClient()
            patient_name = search_patient_form.cleaned_data[
                'patient_name'].split()
            # Search for a patient by first and last name
            data_client.patient_list = data_client.fhir_client.search_patient(
                patient_name[0], patient_name[1])
            # if patient_list:
            # data_client.patient = patient_list[0]
            # data_client.fhir_client.select_patient(data_client.patient['resource']['id'])
            # url = '/app/questions/'
            # return HttpResponseRedirect(url)
    else:
        search_patient_form = SearchPatientForm()
        if data_client.identity != "care_provider":
            return HttpResponseRedirect('/app/login/')

    patient_paginator = Paginator(data_client.patient_list, 3)

    try:
        page = int(request.GET.get('page', '1'))
        patients = patient_paginator.page(page)
    except PageNotAnInteger:
        # If page is not an integer, deliver first page.
        patients = patient_paginator.page(1)
    except EmptyPage:
        # If page is out of range (e.g. 9999), deliver last page of results.
        patients = patient_paginator.page(patient_paginator.num_pages)

    return render(request, 'app/search_patient.html', {
        'search_patient_form': search_patient_form,
        'patients': patients
    })
Exemplo n.º 3
0
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
        })