def post(self, study_id):
     request_data = request.get_json()
     study_investigators = self.schema.load(request_data, many=True).data
     db.session.query(StudyInvestigator).filter_by(study_id=study_id).delete()
     for c in study_investigators:
         db.session.add(StudyInvestigator(study_id=study_id,
                        investigator_id=c.investigator_id))
     db.session.commit()
     return self.get(study_id)
示例#2
0
    def load_studies(self):
        with open(self.study_file, newline='') as csvfile:
            reader = csv.reader(csvfile, delimiter=csv.excel.delimiter, quotechar=csv.excel.quotechar)
            next(reader, None)  # skip the headers
            for row in reader:
                org = self.get_org_by_name(row[4]) if row[4] else None
                study = Study(title=row[0], description=row[1], participant_description=row[2],
                              benefit_description=row[3], organization=org, location=row[5],
                              short_title=row[6], short_description=row[7], image_url=row[8], coordinator_email=row[22],
                              eligibility_url=row[23], ages=[])

                if row[9].strip() == 'Currently Enrolling':
                    study.status = Status.currently_enrolling
                elif row[9].strip() == 'Study In Progress':
                    study.status = Status.study_in_progress
                elif row[9].strip() == 'Results Being Analyzed':
                    study.status = Status.results_being_analyzed
                elif row[9].strip() == 'Study Results Published':
                    study.status = Status.study_results_published

                for i in range(31, len(row)):
                    if row[i]:
                        study.ages.extend(AgeRange.get_age_range_for_csv_data(row[i]))

                db.session.add(study)
                self.__increment_id_sequence(Study)

                for i in range(24, 31):
                    if row[i] and row[i] is not '':
                        category = self.get_category_by_name(row[i].strip())
                        study_id = study.id
                        category_id = category.id
                        study_category = StudyCategory(study_id=study_id, category_id=category_id)
                        db.session.add(study_category)

                for i in [10, 14, 18]:
                    if row[i]:
                        investigator = db.session.query(Investigator).filter(Investigator.name == row[i]).first()
                        if investigator is None:
                            investigator = Investigator(name=row[i], title=row[i+1],
                                                        organization_id=self.get_org_by_name(row[i+2]).id, bio_link=row[i+3])
                        db.session.add(investigator)
                        db.session.commit()
                        study_investigator = StudyInvestigator(study_id=study.id, investigator_id=investigator.id)
                        db.session.add(study_investigator)
            print("Studies loaded.  There are now %i studies in the database." % db.session.query(
                Study).count())
            print("There are now %i links between studies and categories in the database." %
                  db.session.query(StudyCategory).count())
            print("There are now %i study investigators in the database." %
                  db.session.query(Investigator).count())
        db.session.commit()
    def test_delete_investigator_deletes_relationship(self):
        i = self.construct_investigator()
        s = self.construct_study()
        si = StudyInvestigator(investigator_id=i.id, study_id=s.id)
        db.session.add(si)
        db.session.commit()
        si_id = si.id

        rv = self.app.get('api/study_investigator/%i' % si_id, content_type="application/json", headers=self.logged_in_headers())
        self.assert_success(rv)

        rv = self.app.delete('api/investigator/%i' % i.id, content_type="application/json",
                             headers=self.logged_in_headers())
        self.assert_success(rv)

        rv = self.app.get('api/study_investigator/%i' % si_id, content_type="application/json", headers=self.logged_in_headers())
        self.assertEqual(404, rv.status_code)
示例#4
0
 def construct_everything(self):
     self.construct_all_questionnaires()
     cat = self.construct_category()
     org = self.construct_organization()
     self.construct_resource()
     study = self.construct_study()
     location = self.construct_location()
     event = self.construct_event()
     self.construct_location_category(location.id, cat.name)
     self.construct_study_category(study.id, cat.name)
     self.construct_zip_code()
     investigator = Investigator(name="Sam I am", organization_id=org.id)
     db.session.add(StudyInvestigator(study = study, investigator = investigator))
     db.session.add(StudyUser(study=study, user=self.construct_user()))
     db.session.add(AdminNote(user_id=self.construct_user().id, resource_id=self.construct_resource().id, note=''))
     db.session.add(investigator)
     db.session.add(EmailLog())
     db.session.add(StepLog())
     db.session.commit()