Example #1
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)
            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))
Example #2
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,
    })
Example #3
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))
Example #4
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
Example #5
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))
def post_save_submission(xml_file_path):
    clinical_trial_xpath = {
        'trial_id':'',
        'date_registration':'',
        'scientific_title':'trial_identification/scientific_title',
        'scientific_acronym':'trial_identification/scientific_acronym',
        'public_title':'trial_identification/public_title',
        'acronym':'trial_identification/acronym',
        'hc_freetext':'health_conditions/freetext',
        'i_freetext':'interventions/freetext',
        'inclusion_criteria':'recruitment/inclusion_criteria',
        'gender':'recruitment/gender/@value',
        'agemin_value':'recruitment/agemin',
        'agemin_unit':'recruitment/agemin/@unit',
        'agemax_value':'recruitment/agemax',
        'agemax_unit':'recruitment/agemax/@unit',
        'exclusion_criteria':'recruitment/exclusion_criteria',
        'study_design':'study_type/study_design',
        'expanded_access_program':'study_type/study_design/@expanded_access_program',
        'number_of_arms':'study_type/study_design/@number_of_arms',
        'date_enrollment_anticipated':'recruitment/date_enrolment_anticipated',
        'date_enrollment_actual':'recruitment/date_enrolment_actual',
        'target_sample_size':'recruitment/target_size',
        'created':'',
        'updated':'',
        'exported':'',
        'status':'',
        'staff_note':''
    }

    contact_types_map = {
        'public_contact':PublicContact,
        'scientific_contact':ScientificContact,
        'site_contact':SiteContact
    }

    study_design_map = {
        'allocation': StudyAllocation,
        'intervention_assignment':InterventionAssigment,
        'masking': StudyMasking,
        'purpose':  StudyPurpose
    }

    xml = open(xml_file_path)
    tree = ElementTree()
    root = tree.parse(xml)

    ct = ClinicalTrial()
    ct.save()

    # Non-relational Fields from Clinical Trial
    for field,xpath in clinical_trial_xpath.items():
        if xpath != '':
            resultEl = root.xpath(xpath)
            if len(resultEl) > 0:
                if hasattr(resultEl[0],'text'):
                    setattr(ct, field, resultEl[0].text)
                else:
                    setattr(ct, field, resultEl[0])

    # Add Sponsors
    for sponsorNode in root.xpath('sponsors_and_support/*'):
        sponsor = Institution()
        sponsor.name = sponsorNode.find('name').text
        sponsor.address = sponsorNode.find('address').text
        sponsor.country = CountryCode.objects.get(label=sponsorNode.attrib['country_code'])
        sponsor.save()
        if sponsorNode.tag == 'primary_sponsor':
            ct.primary_sponsor = sponsor
        elif sponsorNode.tag == 'secondary_sponsor':
            TrialSecondarySponsor.objects.create(trial=ct,institution=sponsor)
        elif sponsorNode.tag == 'source_support':
            TrialSupportSource.objects.create(trial=ct,institution=sponsor)

    # Add Contacts
    contactList = {}
    for personNode in root.xpath('contacts/person'):
        contact = Contact()

        for attr in ['firstname','middlename','lastname','email','address','city','zip','telephone']:
            value = personNode.find(attr)
            if value is not None:
                setattr(contact, attr, value.text)
        contact.country = CountryCode.objects.get(label=sponsorNode.attrib['country_code'])
        contact.save()
        contactList[ personNode.attrib['pid'] ] = contact

    # Assign PublicContact, ScientificContact and SiteContact to the trial
    for cType,model in contact_types_map.items():
        for typeNode in root.xpath('contacts/'+cType):
            pattern = re.compile('p[0-9]+')
            for person in pattern.findall(typeNode.attrib['persons']):
                model.objects.create(trial=ct,contact=contactList[person])

    # Interventions
    for icodeNode in root.xpath('interventions/i_code'):
        i_code = InterventionCode.objects.get(label=icodeNode.attrib['value'])
        if isinstance(i_code,InterventionCode):
            ct.i_code.add(i_code)

    # Recruitment Country
    for rcountryNode in root.xpath('recruitment/recruitment_country'):
        ccode = CountryCode.objects.get(label=rcountryNode.attrib['value'])
        if isinstance(ccode,CountryCode):
            ct.recruitment_country.add(ccode)

    # StudyType
    study_type_node = StudyType.objects.get(label=root.attrib['type'])
    if study_type_node is not None:
        ct.study_type = study_type_node

    study_design_node = root.find('study_type/study_design')
    if study_design_node is not None:
        for attr,model in study_design_map.items():
            setattr(ct, attr, model.objects.get(label=study_design_node.attrib[attr]))

    study_phase_node = root.find('study_type/phase')
    if study_phase_node is not None:
        ct.phase = StudyPhase.objects.get(label=study_phase_node.attrib['value'])

    recruitment_status = RecruitmentStatus.objects.get(label = root.find('recruitment').attrib['study_status'])
    if recruitment_status is not None:
        ct.status = recruitment_status