def exams(request): data_client = DataClient() completed = get_sidebar_completed() if request.method == 'POST': exams_form = ExamsForm(request.POST) if exams_form.is_valid(): chosen_list = [] for field in exams_form.fields: if (exams_form.cleaned_data[field]): chosen_list.append(field) if not chosen_list: return HttpResponseRedirect('/app/exams/') else: data_client.exams_chosen = chosen_list return HttpResponseRedirect('/app/exams/details') else: exams_form = ExamsForm() completed = get_sidebar_completed() exams_completed = get_exams_completed() # Delete this out later, just want to see that it works print(exams_completed) return render( request, 'app/exams.html', { 'exams_form': exams_form, 'patient': data_client.patient, 'completed': completed, 'exams_completed': exams_completed })
def exams_details(request): data_client = DataClient() exams_chosen = data_client.exams_chosen completed = get_sidebar_completed() if request.method == 'POST': exams_form = ExamsDetailsForm(request.POST, exams_chosen=exams_chosen) if exams_form.is_valid(): # Local obs just in case observations = {} for exam in data_client.physical_exam: if exam['code'] in exams_chosen: for i, form in enumerate(exam['forms']): code = exam['forms'][i]['code'] field_name = code answer = exams_form.cleaned_data[field_name] data_client.observations[code] = answer observations[code] = answer # Clear this for the next iteration... data_client.exams_chosen = [] # Exams is last stop before risks, all levels go to risks including incomplete #save observations to FHIR server data_client.fhir_client.write_list_of_observations_to_fhir( data=data_client.observations) return HttpResponseRedirect('/app/risks/') else: exam_answers = {} for exam in data_client.physical_exam: if exam['code'] in exams_chosen: for i, form in enumerate(exam['forms']): code = exam['forms'][i]['code'] if code in data_client.observations: field_name = code exam_answers[field_name] = data_client.observations[ code] if isinstance(exam_answers[field_name], str): if exam_answers[field_name] == "True": exam_answers[field_name] = True elif exam_answers[field_name] == "False": exam_answers[field_name] = False exams_form = ExamsDetailsForm(initial=exam_answers, exams_chosen=exams_chosen) return render( request, 'app/exams.html', { 'exams_form': exams_form, 'patient': data_client.patient, 'completed': completed })