Merge pull request #485 from sartography/bug/validating-associates-659

Bug/validating associates #659
This commit is contained in:
Dan Funk 2022-03-07 14:20:20 -05:00 committed by GitHub
commit 3f82cdae48
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 234 additions and 29 deletions

View File

@ -1,4 +1,3 @@
from crc.api.common import ApiError
from crc.models.study import StudyAssociatedSchema
from crc.scripts.script import Script
from crc.services.study_service import StudyService
@ -6,12 +5,6 @@ from crc.services.study_service import StudyService
class GetStudyAssociates(Script):
argument_error_message = "You must supply at least one argument to the " \
"update_study_associates task, an array of objects in the form " \
"{'uid':'someid', 'role': 'text', 'send_email: 'boolean', " \
"'access':'boolean'} "
def get_description(self):
return """Returns all people associated with the study - Will always return the study owner as assocated
example : get_study_associates() => [{'uid':'sbp3ey','role':'Unicorn Herder', 'send_email': False, 'access':True}]
@ -19,33 +12,45 @@ example : get_study_associates() => [{'uid':'sbp3ey','role':'Unicorn Herder', 's
"""
def do_task_validate_only(self, task, study_id, workflow_id, *args, **kwargs):
study_associates = [
{'uid': 'dhf8r', 'role': 'Chief Bee Keeper', 'send_email': True, 'access': True,
'ldap_info': {
'uid': 'dhf8r',
'display_name': "Dan Funk",
if study_id:
return self.do_task(task, study_id, workflow_id, args, kwargs)
else:
study_associates = [
{'uid': 'dhf8r', 'role': 'Department Chair', 'send_email': True, 'access': True,
'ldap_info': {
'uid': 'dhf8r',
'display_name': "Dan Funk",
'email_address': 'dhf8r@virginia.edu',
'telephone_number': '',
'title': '',
'department': '',
'affiliation': '',
'sponsor_type': '',
}},
{'uid': 'lb3dp', 'role': 'Primary Investigator', 'send_email': True, 'access': True,
'ldap_info': {
'uid': 'dhf8r',
'display_name': "Dan Funk",
'email_address': 'dhf8r@virginia.edu',
'telephone_number': '',
'title': '',
'department': '',
'affiliation': '',
'sponsor_type': '',
}},
{'uid': 'lb3dp', 'role': 'Chief Cat Herder', 'send_email': True, 'access': True,
'ldap_info': {
'uid': 'dhf8r',
'display_name': "Dan Funk",
'email_address': 'dhf8r@virginia.edu',
'telephone_number': '',
'title': '',
'department': '',
'affiliation': '',
'sponsor_type': ''
}},
]
return study_associates
'sponsor_type': ''
}},
{'uid': 'lb3dp', 'role': 'Study Coordinator I', 'send_email': True, 'access': True,
'ldap_info': {
'uid': 'dhf8r',
'display_name': "Dan Funk",
'email_address': 'dhf8r@virginia.edu',
'telephone_number': '',
'title': '',
'department': '',
'affiliation': '',
'sponsor_type': ''
}},
]
return study_associates
def do_task(self, task, study_id, workflow_id, *args, **kwargs):
return StudyAssociatedSchema(many=True).dump(StudyService.get_study_associates(study_id))

View File

@ -0,0 +1,116 @@
<?xml version="1.0" encoding="UTF-8"?>
<bpmn:definitions xmlns:bpmn="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" xmlns:di="http://www.omg.org/spec/DD/20100524/DI" xmlns:camunda="http://camunda.org/schema/1.0/bpmn" id="Definitions_507ba7d" targetNamespace="http://bpmn.io/schema/bpmn" exporter="Camunda Modeler" exporterVersion="4.2.0">
<bpmn:process id="Process_507ba7d" isExecutable="true">
<bpmn:startEvent id="StartEvent_1">
<bpmn:outgoing>Flow_14snzg4</bpmn:outgoing>
</bpmn:startEvent>
<bpmn:sequenceFlow id="Flow_14snzg4" sourceRef="StartEvent_1" targetRef="Activity_GetAssocRole" />
<bpmn:scriptTask id="Activity_GetAssociates" name="Get Associates">
<bpmn:incoming>Flow_0h4fy1y</bpmn:incoming>
<bpmn:outgoing>Flow_1n8quj6</bpmn:outgoing>
<bpmn:script># Get List of Associates
assoc_list = get_study_associates()
# Get Associates by Role
# Roles: "Primary Investigator", "Department Chair", "Study Coordinator I", "Study Coordinator II", "IRB Coordinator", "Department Contact", "Sub Investigator", "Additional Study Coordinators"
# assoc_role = "Primary Investigator"
if assoc_role_enum == 'pi':
assoc_role = "Primary Investigator"
elif assoc_role_enum == 'dc':
assoc_role = "Department Chair"
elif assoc_role_enum == 'sc_i':
assoc_role = 'Study Coordinator I'
# Set PI Status initially to "Not Found"
# Update later to "Found" or "New", if appropriate
assoc_info = None
assoc_status = "Not Found"
assoc_cid = ""
for assoc in assoc_list:
if assoc["role"] == assoc_role:
assoc_info = assoc
assoc_status = "Found"
assoc_cid = assoc_info["uid"]
if assoc_cid != study_data_get("sdsPI_ComputingID", False):
assoc_status = "New"
</bpmn:script>
</bpmn:scriptTask>
<bpmn:sequenceFlow id="Flow_1n8quj6" sourceRef="Activity_GetAssociates" targetRef="Activity_DisplayAssociates" />
<bpmn:endEvent id="Event_045dwkc">
<bpmn:incoming>Flow_0ok145v</bpmn:incoming>
</bpmn:endEvent>
<bpmn:sequenceFlow id="Flow_0ok145v" sourceRef="Activity_DisplayAssociates" targetRef="Event_045dwkc" />
<bpmn:manualTask id="Activity_DisplayAssociates" name="Display Associates">
<bpmn:documentation>## Associates
{{ assoc_list }}
## Assoc Role
{{ assoc_role }}
## Assoc Status
{{ assoc_status }}
## Assoc Info
{{ assoc_info }}</bpmn:documentation>
<bpmn:incoming>Flow_1n8quj6</bpmn:incoming>
<bpmn:outgoing>Flow_0ok145v</bpmn:outgoing>
</bpmn:manualTask>
<bpmn:sequenceFlow id="Flow_0h4fy1y" sourceRef="Activity_GetAssocRole" targetRef="Activity_GetAssociates" />
<bpmn:userTask id="Activity_GetAssocRole" name="Get Assoc Role" camunda:formKey="AssocForm">
<bpmn:extensionElements>
<camunda:formData>
<camunda:formField id="assoc_role_enum" label="&#39;Associate Role&#39;" type="enum">
<camunda:validation>
<camunda:constraint name="required" config="True" />
</camunda:validation>
<camunda:value id="pi" name="&#39;Primary Investigator&#39;" />
<camunda:value id="dc" name="&#39;Department Chair&#39;" />
<camunda:value id="sc_i" name="&#39;Study Coordinator I&#39;" />
</camunda:formField>
</camunda:formData>
</bpmn:extensionElements>
<bpmn:incoming>Flow_14snzg4</bpmn:incoming>
<bpmn:outgoing>Flow_0h4fy1y</bpmn:outgoing>
</bpmn:userTask>
</bpmn:process>
<bpmndi:BPMNDiagram id="BPMNDiagram_1">
<bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="Process_507ba7d">
<bpmndi:BPMNEdge id="Flow_14snzg4_di" bpmnElement="Flow_14snzg4">
<di:waypoint x="215" y="117" />
<di:waypoint x="270" y="117" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="Flow_0h4fy1y_di" bpmnElement="Flow_0h4fy1y">
<di:waypoint x="370" y="117" />
<di:waypoint x="430" y="117" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="Flow_1n8quj6_di" bpmnElement="Flow_1n8quj6">
<di:waypoint x="530" y="117" />
<di:waypoint x="590" y="117" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="Flow_0ok145v_di" bpmnElement="Flow_0ok145v">
<di:waypoint x="690" y="117" />
<di:waypoint x="752" y="117" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNShape id="_BPMNShape_StartEvent_2" bpmnElement="StartEvent_1">
<dc:Bounds x="179" y="99" width="36" height="36" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Activity_1qxoqjy_di" bpmnElement="Activity_GetAssociates">
<dc:Bounds x="430" y="77" width="100" height="80" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Event_045dwkc_di" bpmnElement="Event_045dwkc">
<dc:Bounds x="752" y="99" width="36" height="36" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Activity_0tm3f8v_di" bpmnElement="Activity_DisplayAssociates">
<dc:Bounds x="590" y="77" width="100" height="80" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Activity_1e65teg_di" bpmnElement="Activity_GetAssocRole">
<dc:Bounds x="270" y="77" width="100" height="80" />
</bpmndi:BPMNShape>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
</bpmn:definitions>

View File

@ -0,0 +1,84 @@
from tests.base_test import BaseTest
from crc import session
from crc.models.ldap import LdapModel
from crc.models.study import StudyAssociated
from crc.services.workflow_service import WorkflowService
class TestStudyAssociatesValidation(BaseTest):
@staticmethod
def add_study_associated(workflow):
ldap_model = session.query(LdapModel).first()
study_associated = StudyAssociated(study_id=workflow.study_id,
uid=ldap_model.uid,
role='Department Chair',
send_email=True,
access=True,
ldap_info=ldap_model)
session.add(study_associated)
study_associated = StudyAssociated(study_id=workflow.study_id,
uid=ldap_model.uid,
role='Primary Investigator',
send_email=True,
access=True,
ldap_info=ldap_model)
session.add(study_associated)
study_associated = StudyAssociated(study_id=workflow.study_id,
uid=ldap_model.uid,
role='Study Coordinator I',
send_email=True,
access=True,
ldap_info=ldap_model)
session.add(study_associated)
session.commit()
def test_study_associates_validation_with_study_id(self):
self.load_test_spec('empty_workflow', master_spec=True)
self.create_reference_document()
workflow = self.create_workflow('study_associates_validation')
self.add_study_associated(workflow)
rv = self.app.get('/v1.0/workflow-specification/%s/validate?study_id=%i' % (workflow.workflow_spec_id, workflow.study_id),
headers=self.logged_in_headers())
self.assertEqual(0, len(rv.json))
def test_study_associates_validation_without_study_id(self):
self.load_test_spec('empty_workflow', master_spec=True)
self.create_reference_document()
workflow = self.create_workflow('study_associates_validation')
self.add_study_associated(workflow)
rv = self.app.get('/v1.0/workflow-specification/%s/validate' % workflow.workflow_spec_id,
headers=self.logged_in_headers())
self.assertEqual(0, len(rv.json))
def test_study_associates_test_spec_with_study(self):
# call test_spec directly so we can see what the script actually returns
self.load_test_spec('empty_workflow', master_spec=True)
self.create_reference_document()
workflow = self.create_workflow('study_associates_validation')
self.add_study_associated(workflow)
result = WorkflowService.test_spec('study_associates_validation', validate_study_id=workflow.study_id)
# assert we get information we added with add_study_associated
self.assertIsInstance(result['assoc_info'], dict)
self.assertEqual('New', result['assoc_status'])
self.assertEqual(4, len(result['assoc_list']))
self.assertEqual(result['assoc_role'], result['assoc_info']['role'])
self.assertIn(result['assoc_role'], ['Department Chair', 'Primary Investigator', 'Study Coordinator I'])
def test_study_associates_test_spec_no_study(self):
# call test_spec directly so we can see what the script actually returns
self.load_test_spec('empty_workflow', master_spec=True)
self.create_reference_document()
workflow = self.create_workflow('study_associates_validation')
self.add_study_associated(workflow)
result = WorkflowService.test_spec('study_associates_validation')
# assert we get mock information
self.assertIn(result['assoc_role_enum'], ['pi', 'dc', 'sc_i'])
self.assertIsNone(result['assoc_info'])
self.assertEqual('Not Found', result['assoc_status'])
self.assertEqual('test', result['assoc_list'][0]['uid'])
self.assertEqual('owner', result['assoc_list'][0]['role'])