def _build_context(self, request, registry_model, patient_model, form, form_state="initial", errors=[]): options = [(VerificationStatus.UNVERIFIED, "Unverified"), (VerificationStatus.VERIFIED, "Verified"), (VerificationStatus.CORRECTED, "Corrected")] patient_locator = PatientLocator(registry_model, patient_model) demographics_link = patient_locator.get_link() context = { "location": "Patient Verification Form", "form": form, "demographics_link": demographics_link, "form_state": form_state, "errors": errors, "patient": patient_model, "options": options } context.update(csrf(request)) return context
def post(self, request, registry_code, patient_id, context_id): registry_model = Registry.objects.get(code=registry_code) context_model = RDRFContext.objects.get(pk=context_id) context_form_group_model = context_model.context_form_group if context_form_group_model: naming_info = context_form_group_model.naming_info else: naming_info = self.get_naming_info(None) context_name = context_model.registry.metadata.get("context_name", "Context") patient_model = Patient.objects.get(id=patient_id) form = ContextForm(request.POST, instance=context_model) if form.is_valid(): content_type = ContentType.objects.get_for_model(patient_model) context_model = form.save(commit=False) context_model.registry = registry_model context_model.content_type = content_type context_model.content_object = patient_model context_model.save() form_links = get_form_links(request.user, context_model.object_id, context_model.registry, context_model) context = {"location": "Edit %s" % context_name, "patient_name": patient_model.display_name, 'patient_link': PatientLocator(registry_model, patient_model).link, "form_links": form_links, "context_launcher": self.get_context_launcher(request.user, registry_model, patient_model), "message": "%s saved successfully" % context_name, "error_messages": [], "registry": registry_model.code, "naming_info": naming_info, "patient_id": patient_id, "form": ContextForm(instance=context_model), } else: error_messages = get_error_messages([form]) context = {"location": "Add %s" % context_name, "errors": True, "error_messages": error_messages, "registry": registry_model.code, "patient_id": patient_id, "form_links": [], 'patient_link': PatientLocator(registry_model, patient_model).link, "context_launcher": self.get_context_launcher(request.user, registry_model, patient_model), "error_messages": error_messages, "naming_info": naming_info, "patient_name": patient_model.display_name, "form": ContextForm(request.POST)} return render(request, "rdrf_cdes/rdrf_context.html", context)
def _build_context(self): context = { "location": "Clinician", 'patient_link': PatientLocator(self.registry_model, self.patient_model).link, "previous_form_link": self.wizard.previous_link, "next_form_link": self.wizard.next_link, "form_name": _("Supervising Clinician"), "registry_code": self.registry_model.code, "patient_model": self.patient_model, "parent": self.parent, "form": self.clinician_form, "context_launcher": self.context_launcher.html, } return context
def _build_context(self, user, registry_model, patient_model): survey_requests = self._get_survey_requests(registry_model, patient_model) context_launcher = RDRFContextLauncherComponent( user, registry_model, patient_model, "PROMS") survey_request_form = self._build_survey_request_form( registry_model, patient_model, user) context = { "context_launcher": context_launcher.html, "location": "Patient Reported Outcomes", "patient": patient_model, "survey_requests": survey_requests, "patient_link": PatientLocator(registry_model, patient_model).link, "patient_info": RDRFPatientInfoComponent(registry_model, patient_model).html, "survey_request_form": survey_request_form, } return context
def _build_context(self, user, registry_model, patient_model): survey_requests = self._get_survey_requests(registry_model, patient_model) context_launcher = RDRFContextLauncherComponent(user, registry_model, patient_model, "PROMS") survey_request_form = self._build_survey_request_form(registry_model, patient_model, user) custom_actions = [CustomActionWrapper(registry_model, user, custom_action, patient_model) for custom_action in user.get_custom_actions_by_scope(registry_model)] context = { 'custom_actions': custom_actions, "context_launcher": context_launcher.html, "location": "Patient Reported Outcomes", "patient": patient_model, "survey_requests": survey_requests, "patient_link": PatientLocator(registry_model, patient_model).link, "patient_info": RDRFPatientInfoComponent(registry_model, patient_model).html, "survey_request_form": survey_request_form, } return context
def get(self, request, registry_code, patient_id, context_form_group_id=None): registry_model = Registry.objects.get(code=registry_code) self.sanity_check(registry_model) patient_model = Patient.objects.get(pk=patient_id) context_form_group = self.get_context_form_group(context_form_group_id) naming_info = self.get_naming_info(context_form_group_id) context_name = self.get_context_name(registry_model, context_form_group) default_display_name = self.get_default_name(patient_model, context_form_group) default_values = {"display_name": default_display_name} if context_form_group and context_form_group.supports_direct_linking: return self.create_context_and_goto_form(registry_model, patient_model, context_form_group) context = {"location": "Add %s" % context_name, "registry": registry_model.code, "patient_id": patient_id, "form_links": [], "context_name": context_name, 'patient_link': PatientLocator(registry_model, patient_model).link, "patient_name": patient_model.display_name, "context_launcher": self.get_context_launcher(request.user, registry_model, patient_model), "naming_info": naming_info, "form": ContextForm(initial=default_values)} return render(request, "rdrf_cdes/rdrf_context.html", context)
def get(self, request, registry_code, patient_id, context_id): rdrf_context_model = get_object_or_404(RDRFContext, pk=context_id) if not self.allowed(request.user, registry_code, patient_id, context_id): raise PermissionDenied context_form = ContextForm(instance=rdrf_context_model) patient_model = rdrf_context_model.content_object registry_model = rdrf_context_model.registry patient_name = patient_model.display_name if rdrf_context_model.context_form_group: context_form_group_model = self.get_context_form_group( rdrf_context_model.context_form_group.pk) naming_info = context_form_group_model.naming_info else: context_form_group_model = None naming_info = self.get_naming_info(None) context_name = self.get_context_name(registry_model, context_form_group_model) form_links = get_form_links( request.user, rdrf_context_model.object_id, rdrf_context_model.registry, rdrf_context_model, ) context = { "location": "Edit %s" % context_name, "context_id": context_id, "patient_name": patient_name, "form_links": form_links, 'patient_link': PatientLocator(registry_model, patient_model).link, "context_launcher": self.get_context_launcher(request.user, registry_model, patient_model), "context_name": context_name, "registry": registry_model.code, "naming_info": naming_info, "patient_id": patient_id, "form": context_form } return render(request, "rdrf_cdes/rdrf_context.html", context)
def post(self, request, registry_code, patient_id, context_form_group_id=None): form = ContextForm(request.POST) registry_model = Registry.objects.get(code=registry_code) self.sanity_check(registry_model) patient_model = Patient.objects.get(pk=patient_id) context_form_group_model = self.get_context_form_group(context_form_group_id) naming_info = self.get_naming_info(context_form_group_id) context_name = self.get_context_name(registry_model, context_form_group_model) if form.is_valid(): patient_model = Patient.objects.get(id=patient_id) registry_model = Registry.objects.get(code=registry_code) content_type = ContentType.objects.get_for_model(patient_model) context_model = form.save(commit=False) context_model.registry = registry_model context_model.content_type = content_type context_model.content_object = patient_model if context_form_group_model: context_model.context_form_group = context_form_group_model context_model.save() context_edit = reverse('context_edit', kwargs={"registry_code": registry_model.code, "patient_id": patient_model.pk, "context_id": context_model.pk}) return HttpResponseRedirect(context_edit) else: error_messages = get_error_messages([form]) context = {"location": "Add %s" % context_name, "errors": True, "error_messages": error_messages, "registry": registry_model.code, 'patient_link': PatientLocator(registry_model, patient_model).link, "patient_id": patient_id, "form_links": [], "naming_info": naming_info, "context_launcher": self.get_context_launcher(request.user, registry_model, patient_model), "patient_name": patient_model.display_name, "form": ContextForm(request.POST)} return render(request, "rdrf_cdes/rdrf_context.html", context)