Merge branch 'rrt/dev' into dev
This commit is contained in:
commit
0368a12eda
|
@ -40,7 +40,7 @@ def get_approvals_for_study(study_id=None):
|
|||
def get_csv():
|
||||
"""A huge bit of a one-off for RRT, but 3 weeks of midnight work can convince a
|
||||
man to do just about anything"""
|
||||
approvals = ApprovalService.get_all_approvals()
|
||||
approvals = ApprovalService.get_all_approvals(ignore_cancelled=True)
|
||||
output = []
|
||||
errors = []
|
||||
ldapService = LdapService()
|
||||
|
@ -52,7 +52,11 @@ def get_csv():
|
|||
if related_approval.status != ApprovalStatus.APPROVED.value:
|
||||
continue
|
||||
workflow = db.session.query(WorkflowModel).filter(WorkflowModel.id == approval.workflow_id).first()
|
||||
personnel = extract_personnel(workflow.bpmn_workflow_json)
|
||||
data = json.loads(workflow.bpmn_workflow_json)
|
||||
last_task = find_task(data['last_task']['__uuid__'], data['task_tree'])
|
||||
personnel = extract_value(last_task, 'personnel')
|
||||
training_val = extract_value(last_task, 'RequiredTraining')
|
||||
review_complete = 'AllRequiredTraining' in training_val
|
||||
pi_uid = workflow.study.primary_investigator_id
|
||||
pi_details = ldapService.user_info(pi_uid)
|
||||
details = []
|
||||
|
@ -63,20 +67,22 @@ def get_csv():
|
|||
|
||||
for person in details:
|
||||
output.append({
|
||||
"study_id": approval.study_id,
|
||||
"pi_uid": pi_details.uid,
|
||||
"pi": pi_details.display_name,
|
||||
"name": person.display_name,
|
||||
"email": person.email_address
|
||||
"email": person.email_address,
|
||||
"review_complete": review_complete,
|
||||
})
|
||||
except Exception as e:
|
||||
errors.append("Error pulling data for workflow #%i: %s" % (approval.workflow_id, str(e)))
|
||||
return {"results": output, "errors": errors }
|
||||
|
||||
def extract_personnel(data):
|
||||
data = json.loads(data)
|
||||
last_task = find_task(data['last_task']['__uuid__'], data['task_tree'])
|
||||
last_task_personnel = pickle.loads(b64decode(last_task['data']['personnel']['__bytes__']))
|
||||
return last_task_personnel
|
||||
def extract_value(task, key):
|
||||
if key in task['data']:
|
||||
return pickle.loads(b64decode(task['data'][key]['__bytes__']))
|
||||
else:
|
||||
return ""
|
||||
|
||||
def find_task(uuid, task):
|
||||
if task['id']['__uuid__'] == uuid:
|
||||
|
|
|
@ -15,13 +15,18 @@ class ApprovalService(object):
|
|||
"""Provides common tools for working with an Approval"""
|
||||
|
||||
@staticmethod
|
||||
def __one_approval_from_study(study, approver_uid = None):
|
||||
def __one_approval_from_study(study, approver_uid = None, ignore_cancelled=False):
|
||||
"""Returns one approval, with all additional approvals as 'related_approvals',
|
||||
the main approval can be pinned to an approver with an optional argument.
|
||||
Will return null if no approvals exist on the study."""
|
||||
main_approval = None
|
||||
related_approvals = []
|
||||
approvals = db.session.query(ApprovalModel).filter(ApprovalModel.study_id == study.id).all()
|
||||
query = db.session.query(ApprovalModel).\
|
||||
filter(ApprovalModel.study_id == study.id)
|
||||
if ignore_cancelled:
|
||||
query=query.filter(ApprovalModel.status != ApprovalStatus.CANCELED.value)
|
||||
|
||||
approvals = query.all()
|
||||
for approval_model in approvals:
|
||||
if approval_model.approver_uid == approver_uid:
|
||||
main_approval = Approval.from_model(approval_model)
|
||||
|
@ -48,13 +53,13 @@ class ApprovalService(object):
|
|||
return approvals
|
||||
|
||||
@staticmethod
|
||||
def get_all_approvals():
|
||||
def get_all_approvals(ignore_cancelled=False):
|
||||
"""Returns a list of all approval objects (not db models), one record
|
||||
per study, with any associated approvals grouped under the first approval."""
|
||||
studies = db.session.query(StudyModel).all()
|
||||
approvals = []
|
||||
for study in studies:
|
||||
approval = ApprovalService.__one_approval_from_study(study)
|
||||
approval = ApprovalService.__one_approval_from_study(study, ignore_cancelled=ignore_cancelled)
|
||||
if approval:
|
||||
approvals.append(approval)
|
||||
return approvals
|
||||
|
|
Loading…
Reference in New Issue