Exemple #1
0
    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)
Exemple #2
0
 def _get_normal_form_links(self):
     default_context = self.patient_model.default_context(
         self.registry_model)
     if default_context is None:
         raise LauncherError("Expected a default context for patient")
     else:
         return get_form_links(self.user, self.patient_model.id,
                               self.registry_model, default_context,
                               self.current_form_name)
Exemple #3
0
    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)
Exemple #4
0
 def _get_current_multiple_context(self):
     # def get_form_links(user, patient_id, registry_model, context_model=None, current_form_name=""):
     # provide links to other forms in this current context
     # used when landing on a form in multiple context
     registry_type = self.registry_model.registry_type
     fg = None
     if registry_type == RegistryType.HAS_CONTEXT_GROUPS:
         if self.current_rdrf_context_model and self.current_rdrf_context_model.context_form_group:
             cfg = self.current_rdrf_context_model.context_form_group
             if cfg.context_type == "M":
                 fg = _FormGroup(
                     self.current_rdrf_context_model.display_name)
                 for form_link in get_form_links(
                         self.user, self.patient_model.pk,
                         self.registry_model,
                         self.current_rdrf_context_model,
                         self.current_form_name):
                     form = _Form(form_link.url,
                                  form_link.text,
                                  current=form_link.selected)
                     fg.forms.append(form)
     return fg
Exemple #5
0
 def _get_visible_form_links(self, fixed_context_group, rdrf_context):
     return get_form_links(self.user, self.patient_model.id,
                           self.registry_model, rdrf_context,
                           self.current_form_name)