コード例 #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))
コード例 #2
0
ファイル: views.py プロジェクト: joncasdam/opentrials
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))
コード例 #3
0
ファイル: views.py プロジェクト: bireme/sandbox
def new_submission(request):
    if request.method == "POST":  # If the forms were submitted...
        initial_form = InitialTrialForm(request.POST)
        sponsor_form = PrimarySponsorForm(request.POST)
        if initial_form.is_valid() and sponsor_form.is_valid():  # All validation rules pass
            trial = ClinicalTrial(scientific_title=initial_form.cleaned_data["scientific_title"])
            trial.primary_sponsor = Institution.objects.create(**sponsor_form.cleaned_data)
            trial.save()
            for country_id in initial_form.cleaned_data["recruitment_countries"]:
                trial.recruitmentcountry_set.create(country_id=country_id)
            submission = Submission(creator=request.user, trial=trial)
            submission.save()
            return HttpResponseRedirect(reverse("registry.edit", args=[trial.id]))

    else:
        initial_form = InitialTrialForm()
        sponsor_form = PrimarySponsorForm()

    return render_to_response(
        "reviewapp/new_submission.html", {"initial_form": initial_form, "sponsor_form": sponsor_form}
    )
コード例 #4
0
def new_submission(request):
    if request.method == 'POST':
        initial_form = InitialTrialForm(request.POST,request.FILES)
        sponsor_form = PrimarySponsorForm(request.POST)

        if initial_form.is_valid() and sponsor_form.is_valid():
            trial = ClinicalTrial()
            su = Submission(creator=request.user)

            trial.scientific_title = su.title = initial_form.cleaned_data['scientific_title']

            trial.save()
            su.save()

            trial.primary_sponsor = su.primary_sponsor = sponsor_form.save()
            trial.recruitment_country = [CountryCode.objects.get(pk=id) for id in initial_form.cleaned_data['recruitment_country']]
            su.trial = trial

            trial.save()
            su.save()

            return HttpResponseRedirect(reverse('repository.edittrial',args=[trial.id]))
    else:
        initial_form = InitialTrialForm()
        sponsor_form = PrimarySponsorForm()


    forms = [initial_form, sponsor_form]
    return render_to_response('reviewapp/new_submission.html', {
        'forms': forms,
        'username':request.user.username,
    })
コード例 #5
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
コード例 #6
0
ファイル: views.py プロジェクト: frac/opentrials
def new_submission(request):
    if request.method == 'POST':
        initial_form = InitialTrialForm(request.POST,request.FILES)
        sponsor_form = PrimarySponsorForm(request.POST)

        if initial_form.is_valid() and sponsor_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']
            if su.language == 'en':
                trial.scientific_title = su.title
            else:
                trial.save()
                ctt = ClinicalTrialTranslation()
                ctt.language = su.language
                ctt.scientific_title = su.title
                trial.translations.add(ctt)

            trial.save()
            su.save()
            
            sponsor = sponsor_form.save(commit=False)
            sponsor.creator = request.user
            sponsor.save()
            
            trial.primary_sponsor = su.primary_sponsor = sponsor
            trial.recruitment_country = [CountryCode.objects.get(pk=id) for id in initial_form.cleaned_data['recruitment_country']]
            su.trial = trial

            trial.save()
            su.save()
            
            # sets the initial status of the fields
            fields_status = {}
            FIELDS = {
                TRIAL_FORMS[0]: MISSING, TRIAL_FORMS[1]: PARTIAL, TRIAL_FORMS[2]: MISSING,
                TRIAL_FORMS[3]: MISSING, TRIAL_FORMS[4]: MISSING, TRIAL_FORMS[5]: MISSING, 
                TRIAL_FORMS[6]: MISSING, TRIAL_FORMS[7]: MISSING, TRIAL_FORMS[8]: PARTIAL
            }
            for lang in su.get_mandatory_languages():
                lang = lang.lower()
                fields_status.update({lang: dict(FIELDS)})
                if lang == su.language.lower():
                    fields_status[lang].update({TRIAL_FORMS[0]: PARTIAL})
            
            su.fields_status = pickle.dumps(fields_status)
            su.save()

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

    forms = [initial_form, sponsor_form]
    return render_to_response('reviewapp/new_submission.html', {
        'forms': forms },
        context_instance=RequestContext(request))