def construct_investigator(self, name="Judith Wonder", title="Ph.D., Assistant Professor of Mereology"): investigator = Investigator(name=name, title=title) investigator.organization_id = self.construct_organization().id db.session.add(investigator) db.session.commit() db_inv = db.session.query(Investigator).filter_by(name=investigator.name).first() self.assertEqual(db_inv.title, investigator.title) return db_inv
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 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()