Adds approvals to study service
This commit is contained in:
parent
ae2313203c
commit
796c109611
|
@ -6,6 +6,7 @@ from crc.models.study import StudyModel, StudySchema
|
||||||
from crc.scripts.script import Script
|
from crc.scripts.script import Script
|
||||||
from crc.services.ldap_service import LdapService
|
from crc.services.ldap_service import LdapService
|
||||||
from crc.services.protocol_builder import ProtocolBuilderService
|
from crc.services.protocol_builder import ProtocolBuilderService
|
||||||
|
from crc.services.study_service import StudyService
|
||||||
from crc.services.workflow_processor import WorkflowProcessor
|
from crc.services.workflow_processor import WorkflowProcessor
|
||||||
|
|
||||||
|
|
||||||
|
@ -13,7 +14,7 @@ class StudyInfo(Script):
|
||||||
|
|
||||||
"""Just your basic class that can pull in data from a few api endpoints and do a basic task."""
|
"""Just your basic class that can pull in data from a few api endpoints and do a basic task."""
|
||||||
pb = ProtocolBuilderService()
|
pb = ProtocolBuilderService()
|
||||||
type_options = ['info', 'investigators', 'details']
|
type_options = ['info', 'investigators', 'details', 'approvals']
|
||||||
|
|
||||||
def get_description(self):
|
def get_description(self):
|
||||||
return """StudyInfo [TYPE], where TYPE is one of 'info', 'investigators', or 'details'
|
return """StudyInfo [TYPE], where TYPE is one of 'info', 'investigators', or 'details'
|
||||||
|
@ -68,6 +69,8 @@ class StudyInfo(Script):
|
||||||
self.add_data_to_task(task, {cmd: self.organize_investigators_by_type(pb_response)})
|
self.add_data_to_task(task, {cmd: self.organize_investigators_by_type(pb_response)})
|
||||||
if cmd == 'details':
|
if cmd == 'details':
|
||||||
self.add_data_to_task(task, {cmd: self.pb.get_study_details(study_id)})
|
self.add_data_to_task(task, {cmd: self.pb.get_study_details(study_id)})
|
||||||
|
if cmd == 'approvals':
|
||||||
|
self.add_data_to_task(task, {cmd: StudyService().get_approvals(study_id)})
|
||||||
task.data["study"] = study_info
|
task.data["study"] = study_info
|
||||||
|
|
||||||
|
|
||||||
|
@ -96,4 +99,4 @@ class StudyInfo(Script):
|
||||||
return {}
|
return {}
|
||||||
except LDAPSocketOpenError:
|
except LDAPSocketOpenError:
|
||||||
app.logger.info("Failed to connect to LDAP Server.")
|
app.logger.info("Failed to connect to LDAP Server.")
|
||||||
return {}
|
return {}
|
||||||
|
|
|
@ -62,6 +62,29 @@ class StudyService(object):
|
||||||
categories.append(Category(cat_model))
|
categories.append(Category(cat_model))
|
||||||
return categories
|
return categories
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def get_approvals(study_id):
|
||||||
|
"""Returns a list of category objects, in the correct order."""
|
||||||
|
cat = session.query(WorkflowSpecCategoryModel).filter_by(name="approvals").first()
|
||||||
|
specs = session.query(WorkflowSpecModel).filter_by(category_id=cat.id).all()
|
||||||
|
spec_ids = [spec.id for spec in specs]
|
||||||
|
workflows = session.query(WorkflowModel)\
|
||||||
|
.filter(WorkflowModel.study_id == study_id)\
|
||||||
|
.filter(WorkflowModel.workflow_spec_id.in_(spec_ids))\
|
||||||
|
.all()
|
||||||
|
|
||||||
|
approvals = []
|
||||||
|
for workflow in workflows:
|
||||||
|
workflow: WorkflowModel = workflow
|
||||||
|
approvals.append({
|
||||||
|
'id': workflow.id,
|
||||||
|
'display_name': workflow.workflow_spec.display_name,
|
||||||
|
'name': workflow.workflow_spec.display_name,
|
||||||
|
'status': workflow.status,
|
||||||
|
'workflow_spec_id': workflow.workflow_spec_id,
|
||||||
|
})
|
||||||
|
return approvals
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def synch_all_studies_with_protocol_builder(user):
|
def synch_all_studies_with_protocol_builder(user):
|
||||||
"""Assures that the studies we have locally for the given user are
|
"""Assures that the studies we have locally for the given user are
|
||||||
|
|
|
@ -30,10 +30,14 @@ class TestStudyService(BaseTest):
|
||||||
db.session.add(user)
|
db.session.add(user)
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
study = StudyModel(title="My title", protocol_builder_status=ProtocolBuilderStatus.ACTIVE, user_uid=user.uid)
|
study = StudyModel(title="My title", protocol_builder_status=ProtocolBuilderStatus.ACTIVE, user_uid=user.uid)
|
||||||
cat = WorkflowSpecCategoryModel(name="cat", display_name="cat", display_order=0)
|
cat = WorkflowSpecCategoryModel(name="approvals", display_name="Approvals", display_order=0)
|
||||||
db.session.add_all([study, cat])
|
db.session.add_all([study, cat])
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
|
|
||||||
|
self.assertIsNotNone(cat.id)
|
||||||
self.load_test_spec("random_fact", category_id=cat.id)
|
self.load_test_spec("random_fact", category_id=cat.id)
|
||||||
|
|
||||||
|
self.assertIsNotNone(study.id)
|
||||||
workflow = WorkflowModel(workflow_spec_id="random_fact", study_id=study.id, status=WorkflowStatus.not_started)
|
workflow = WorkflowModel(workflow_spec_id="random_fact", study_id=study.id, status=WorkflowStatus.not_started)
|
||||||
db.session.add(workflow)
|
db.session.add(workflow)
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
|
@ -74,3 +78,7 @@ class TestStudyService(BaseTest):
|
||||||
studies = StudyService.get_studies_for_user(user)
|
studies = StudyService.get_studies_for_user(user)
|
||||||
workflow = next(iter(studies[0].categories[0].workflows)) # Workflows is a set.
|
workflow = next(iter(studies[0].categories[0].workflows)) # Workflows is a set.
|
||||||
self.assertEqual(1, workflow.completed_tasks)
|
self.assertEqual(1, workflow.completed_tasks)
|
||||||
|
|
||||||
|
# Get approvals
|
||||||
|
approvals = StudyService.get_approvals(studies[0].id)
|
||||||
|
self.assertGreater(len(approvals), 0)
|
||||||
|
|
Loading…
Reference in New Issue