def test_new_approval_requests_after_file_modification_create_new_requests( self): self.load_example_data() self.create_reference_document() workflow = self.create_workflow('empty_workflow') FileService.add_workflow_file(workflow_id=workflow.id, name="anything.png", content_type="text", binary_data=b'5678', irb_doc_code="AD_CoCAppr") ApprovalService.add_approval(study_id=workflow.study_id, workflow_id=workflow.id, approver_uid="dhf8r") FileService.add_workflow_file(workflow_id=workflow.id, name="anything.png", content_type="text", binary_data=b'5678', irb_doc_code="UVACompl_PRCAppr") ApprovalService.add_approval(study_id=workflow.study_id, workflow_id=workflow.id, approver_uid="dhf8r") self.assertEqual(2, db.session.query(ApprovalModel).count()) models = db.session.query(ApprovalModel).order_by( ApprovalModel.version).all() self.assertEqual(1, models[0].version) self.assertEqual(2, models[1].version)
def do_task(self, task, study_id, workflow_id, *args, **kwargs): uids = self.get_uids(task, args) if isinstance(uids, str): ApprovalService.add_approval(study_id, workflow_id, args) elif isinstance(uids, list): for id in uids: if id: ## Assure it's not empty or null ApprovalService.add_approval(study_id, workflow_id, id)
def test_get_not_really_csv_content(self): self.load_example_data() self.create_reference_document() workflow = self.create_workflow('empty_workflow') FileService.add_workflow_file(workflow_id=workflow.id, name="anything.png", content_type="text", binary_data=b'5678', irb_doc_code="AD_CoCAppr") ApprovalService.add_approval(study_id=workflow.study_id, workflow_id=workflow.id, approver_uid="dhf8r") records = ApprovalService.get_not_really_csv_content() self.assertEqual(len(records), 2)
def get_study(study_id, study_model: StudyModel = None): """Returns a study model that contains all the workflows organized by category. IMPORTANT: This is intended to be a lightweight call, it should never involve loading up and executing all the workflows in a study to calculate information.""" if not study_model: study_model = session.query(StudyModel).filter_by(id=study_id).first() study = Study.from_model(study_model) study.categories = StudyService.get_categories() workflow_metas = StudyService.__get_workflow_metas(study_id) study.approvals = ApprovalService.get_approvals_for_study(study.id) files = FileService.get_files_for_study(study.id) files = (File.from_models(model, FileService.get_file_data(model.id), FileService.get_doc_dictionary()) for model in files) study.files = list(files) # Calling this line repeatedly is very very slow. It creates the # master spec and runs it. Don't execute this for Abandoned studies, as # we don't have the information to process them. if study.protocol_builder_status != ProtocolBuilderStatus.ABANDONED: status = StudyService.__get_study_status(study_model) study.warnings = StudyService.__update_status_of_workflow_meta(workflow_metas, status) # Group the workflows into their categories. for category in study.categories: category.workflows = {w for w in workflow_metas if w.category_id == category.id} return study
def get_health_attesting_csv(): records = ApprovalService.get_health_attesting_records() si = io.StringIO() cw = csv.writer(si) cw.writerows(records) output = make_response(si.getvalue()) output.headers["Content-Disposition"] = "attachment; filename=health_attesting.csv" output.headers["Content-type"] = "text/csv" return output
def get_approvals(status=None, as_user=None): #status = ApprovalStatus.PENDING.value user = g.user.uid if as_user: user = as_user approvals = ApprovalService.get_approvals_per_user(user, status, include_cancelled=False) results = ApprovalSchema(many=True).dump(approvals) return results
def test_create_approval_record(self): self.create_reference_document() workflow = self.create_workflow("empty_workflow") FileService.add_workflow_file(workflow_id=workflow.id, name="anything.png", content_type="text", binary_data=b'5678', irb_doc_code="UVACompl_PRCAppr") ApprovalService.add_approval(study_id=workflow.study_id, workflow_id=workflow.id, approver_uid="dhf8r") self.assertEqual(1, db.session.query(ApprovalModel).count()) model = db.session.query(ApprovalModel).first() self.assertEqual(workflow.study_id, model.study_id) self.assertEqual(workflow.id, model.workflow_id) self.assertEqual("dhf8r", model.approver_uid) self.assertEqual(1, model.version)
def test_delete_file_after_approval(self): self.create_reference_document() workflow = self.create_workflow("empty_workflow") FileService.add_workflow_file(workflow_id=workflow.id, name="anything.png", content_type="text", binary_data=b'5678', irb_doc_code="UVACompl_PRCAppr") FileService.add_workflow_file(workflow_id=workflow.id, name="anotother_anything.png", content_type="text", binary_data=b'1234', irb_doc_code="Study_App_Doc") ApprovalService.add_approval(study_id=workflow.study_id, workflow_id=workflow.id, approver_uid="dhf8r") file = session.query(FileModel).\ filter(FileModel.workflow_id == workflow.id).\ filter(FileModel.name == "anything.png").first() self.assertFalse(file.archived) rv = self.app.get('/v1.0/file/%i' % file.id, headers=self.logged_in_headers()) self.assert_success(rv) rv = self.app.delete('/v1.0/file/%i' % file.id, headers=self.logged_in_headers()) self.assert_success(rv) session.refresh(file) self.assertTrue(file.archived) ApprovalService.add_approval(study_id=workflow.study_id, workflow_id=workflow.id, approver_uid="dhf8r") approvals = session.query(ApprovalModel)\ .filter(ApprovalModel.status == ApprovalStatus.PENDING.value)\ .filter(ApprovalModel.study_id == workflow.study_id).all() self.assertEqual(1, len(approvals)) self.assertEqual(1, len(approvals[0].approval_files))
def update_approval(approval_id, body): if approval_id is None: raise ApiError('unknown_approval', 'Please provide a valid Approval ID.') approval_model = session.query(ApprovalModel).get(approval_id) if approval_model is None: raise ApiError('unknown_approval', 'The approval "' + str(approval_id) + '" is not recognized.') if approval_model.approver_uid != g.user.uid: raise ApiError("not_your_approval", "You may not modify this approval. It belongs to another user.") approval_model.status = body['status'] approval_model.message = body['message'] approval_model.date_approved = datetime.now() session.add(approval_model) session.commit() # Called only to send emails approver = body['approver']['uid'] ApprovalService.update_approval(approval_id, approver) result = ApprovalSchema().dump(approval_model) return result
def test_new_approval_cancels_all_previous_approvals(self): self.create_reference_document() workflow = self.create_workflow("empty_workflow") FileService.add_workflow_file(workflow_id=workflow.id, name="anything.png", content_type="text", binary_data=b'5678', irb_doc_code="UVACompl_PRCAppr") ApprovalService.add_approval(study_id=workflow.study_id, workflow_id=workflow.id, approver_uid="dhf8r") ApprovalService.add_approval(study_id=workflow.study_id, workflow_id=workflow.id, approver_uid="lb3dp") current_count = ApprovalModel.query.count() self.assertTrue(current_count, 2) FileService.add_workflow_file(workflow_id=workflow.id, name="borderline.png", content_type="text", binary_data=b'906090', irb_doc_code="AD_CoCAppr") ApprovalService.add_approval(study_id=workflow.study_id, workflow_id=workflow.id, approver_uid="dhf8r") current_count = ApprovalModel.query.count() canceled_count = ApprovalModel.query.filter( ApprovalModel.status == ApprovalStatus.CANCELED.value) self.assertTrue(current_count, 2) self.assertTrue(current_count, 3) ApprovalService.add_approval(study_id=workflow.study_id, workflow_id=workflow.id, approver_uid="lb3dp") current_count = ApprovalModel.query.count() self.assertTrue(current_count, 4)
def get_approvals_for_study(study_id=None): db_approvals = ApprovalService.get_approvals_for_study(study_id) approvals = [Approval.from_model(approval_model) for approval_model in db_approvals] results = ApprovalSchema(many=True).dump(approvals) return results
def get_all_approvals(status=None): approvals = ApprovalService.get_all_approvals(include_cancelled=status is True) results = ApprovalSchema(many=True).dump(approvals) return results
def get_csv(): """A damn lie, it's a json file. A huge bit of a one-off for RRT, but 3 weeks of midnight work can convince a man to do just about anything""" content = ApprovalService.get_not_really_csv_content() return content