Esempio n. 1
0
def new_submission(request):

    if request.method == 'POST':
        initial_form = InitialTrialForm(request.POST,
                                        request.FILES,
                                        user=request.user)

        if initial_form.is_valid():
            trial = ClinicalTrial()

            su = Submission(creator=request.user)
            su.language = initial_form.cleaned_data['language']
            su.title = initial_form.cleaned_data['scientific_title']
            su.primary_sponsor = initial_form.cleaned_data['primary_sponsor']

            trial.utrn_number = initial_form.cleaned_data['utrn_number']
            trial.language = settings.DEFAULT_SUBMISSION_LANGUAGE
            trial.primary_sponsor = su.primary_sponsor

            if su.language == settings.DEFAULT_SUBMISSION_LANGUAGE:
                trial.scientific_title = su.title
            else:
                trial.save()
                ctt = ClinicalTrialTranslation.objects.get_translation_for_object(
                    su.language, trial, create_if_not_exist=True)
                ctt.scientific_title = su.title
                ctt.save()

            trial.save()

            for country in initial_form.cleaned_data['recruitment_country']:
                trial.recruitment_country.add(
                    country)  # What about the removed ones? FIXME
            su.trial = trial

            trial.save()
            su.save()

            # sets the initial status of the fields
            su.init_fields_status()

            return HttpResponseRedirect(
                reverse('repository.edittrial', args=[trial.id]))
    else:
        initial_form = InitialTrialForm(
            user=request.user, display_language=request.trials_language)

    forms = [initial_form]
    return render_to_response('reviewapp/new_submission.html', {
        'forms': forms,
    },
                              context_instance=RequestContext(request))
Esempio n. 2
0
def new_submission(request):

    if request.method == 'POST':
        initial_form = InitialTrialForm(request.POST, request.FILES, user=request.user)

        if initial_form.is_valid():
            trial = ClinicalTrial()

            su = Submission(creator=request.user)
            su.language = initial_form.cleaned_data['language']
            su.title = initial_form.cleaned_data['scientific_title']
            su.primary_sponsor = initial_form.cleaned_data['primary_sponsor']
            su.status = STATUS_DRAFT

            trial.utrn_number = initial_form.cleaned_data['utrn_number']
            trial.language = settings.DEFAULT_SUBMISSION_LANGUAGE
            trial.primary_sponsor = su.primary_sponsor

            if su.language == settings.DEFAULT_SUBMISSION_LANGUAGE:
                trial.scientific_title = su.title
            else:
                trial.save()
                ctt = ClinicalTrialTranslation.objects.get_translation_for_object(
                        su.language, trial, create_if_not_exist=True
                        )
                ctt.scientific_title = su.title
                ctt.save()

            trial.save()

            for country in initial_form.cleaned_data['recruitment_country']:
                trial.recruitment_country.add(country) # What about the removed ones? FIXME
            su.trial = trial

            trial.save()
            su.save()

            # sets the initial status of the fields
            su.init_fields_status()

            log_actions(request.user,'Created a submission')

            return HttpResponseRedirect(reverse('repository.edittrial',args=[trial.id]))
    else:
        initial_form = InitialTrialForm(user=request.user, display_language=request.trials_language)

    forms = [initial_form]
    return render_to_response('reviewapp/new_submission.html', {
                              'forms': forms,},
                              context_instance=RequestContext(request))
Esempio n. 3
0
    def import_parsed(self, if_exists=UPDATE_IF_EXISTS):
        """
        Imports from parsed trials, stored in the attribute '_parsed_trials'. They
        should be collected using the method 'parse_opentrials'.

        Case "if_exists" ==

        - UPDATE_IF_EXISTS: will keep the trials exactly as they are, just updating their fields.
                            This means that existing child objects will keep as they are, just updating.
        - REPLACE_IF_EXISTS: will empty the current trial and fill its fields again with imported field values.
                             This means that existing child objects will be deleted to have only the imported ones.
        - SKIP_IF_EXISTS: will not import anything for existing trials
        """

        if not hasattr(self, '_parsed_trials'):
            raise Exception(_("To import parsed trials it's necessary to call method 'parse_opentrials' before."))

        imported_trials = []

        for fields, ct in self._parsed_trials:
            # Loads the trial from database and clear it or just create a new instance in memory
            if not ct:
                try:
                    ct = ClinicalTrial.objects.get(trial_id=fields['trial_id'])
                except ClinicalTrial.DoesNotExist:
                    ct = None

            if ct:
                if if_exists == SKIP_IF_EXISTS:
                    continue

                elif if_exists == REPLACE_IF_EXISTS:
                    self.clear_fields(ct)
            else:
                ct = ClinicalTrial()

            # Sets the field values and clean them
            self.set_trial_fields(ct, fields)

            # Children objects
            self.set_trial_children(ct, fields)

            # Set translations
            self.set_trial_translations(ct, fields)

            # TODO: call validation

            # Set the status as draft
            ct.status = 'draft'
            ct.language = fields.get('language', settings.DEFAULT_SUBMISSION_LANGUAGE)
            ct.save()
            imported_trials.append(ct)

            #Creating submission
            submission = Submission(creator=self.creator)
            submission.title = ct.public_title
            submission.language = ct.language
            submission.trial = ct

            submission.save()
            submission.init_fields_status()

            ct.save()

        return imported_trials