Merge remote-tracking branch 'origin/dev' into feature/python_eval
This commit is contained in:
commit
1052dff549
|
@ -0,0 +1,70 @@
|
|||
import json
|
||||
|
||||
from crc.api.common import ApiError
|
||||
from crc.scripts.script import Script
|
||||
from crc.services.protocol_builder import ProtocolBuilderService
|
||||
|
||||
|
||||
class StudySponsors(Script):
|
||||
"""Please see the detailed description that is provided below. """
|
||||
|
||||
pb = ProtocolBuilderService()
|
||||
|
||||
# This is used for test/workflow validation, as well as documentation.
|
||||
example_data = [
|
||||
{
|
||||
"COMMONRULEAGENCY": None,
|
||||
"SPONSOR_ID": 2453,
|
||||
"SP_NAME": "Abbott Ltd",
|
||||
"SP_TYPE": "Private",
|
||||
"SP_TYPE_GROUP_NAME": None,
|
||||
"SS_STUDY": 2
|
||||
},
|
||||
{
|
||||
"COMMONRULEAGENCY": None,
|
||||
"SPONSOR_ID": 2387,
|
||||
"SP_NAME": "Abbott-Price",
|
||||
"SP_TYPE": "Incoming Sub Award",
|
||||
"SP_TYPE_GROUP_NAME": "Government",
|
||||
"SS_STUDY": 2
|
||||
},
|
||||
{
|
||||
"COMMONRULEAGENCY": None,
|
||||
"SPONSOR_ID": 1996,
|
||||
"SP_NAME": "Abernathy-Heidenreich",
|
||||
"SP_TYPE": "Foundation/Not for Profit",
|
||||
"SP_TYPE_GROUP_NAME": "Other External Funding",
|
||||
"SS_STUDY": 2
|
||||
}
|
||||
]
|
||||
|
||||
def example_to_string(self, key):
|
||||
return json.dumps(self.example_data['StudyInfo'][key], indent=2, separators=(',', ': '))
|
||||
|
||||
def get_description(self):
|
||||
return ""
|
||||
# return """
|
||||
# Returns a list of sponsors related to a study in the following format:
|
||||
# {{example}}
|
||||
#z """.format(example=json.dumps(self.example_data, index=2, separators=(',', ': ')))
|
||||
|
||||
def check_args(self, args):
|
||||
if len(args) > 0:
|
||||
raise ApiError(code="invalid_argument",
|
||||
message="The Sponsor script does not take any arguments. "
|
||||
"It returns the list of sponsors for the current study only. ")
|
||||
|
||||
def do_task_validate_only(self, task, study_id, workflow_id, *args, **kwargs):
|
||||
"""For validation only, pretend no results come back from pb"""
|
||||
self.check_args(args)
|
||||
return self.example_data
|
||||
|
||||
def do_task(self, task, study_id, workflow_id, *args, **kwargs):
|
||||
self.check_args(args)
|
||||
retval = ProtocolBuilderService.get_sponsors(study_id)
|
||||
# Check on returning box, as in return Box(retval) - may not work with list.
|
||||
return retval
|
||||
|
||||
|
||||
|
||||
|
|
@ -13,6 +13,7 @@ class ProtocolBuilderService(object):
|
|||
INVESTIGATOR_URL = app.config['PB_INVESTIGATORS_URL']
|
||||
REQUIRED_DOCS_URL = app.config['PB_REQUIRED_DOCS_URL']
|
||||
STUDY_DETAILS_URL = app.config['PB_STUDY_DETAILS_URL']
|
||||
SPONSORS_URL = app.config['PB_STUDY_DETAILS_URL']
|
||||
|
||||
@staticmethod
|
||||
def is_enabled():
|
||||
|
@ -54,6 +55,10 @@ class ProtocolBuilderService(object):
|
|||
def get_study_details(study_id) -> {}:
|
||||
return ProtocolBuilderService.__make_request(study_id, ProtocolBuilderService.STUDY_DETAILS_URL)
|
||||
|
||||
@staticmethod
|
||||
def get_sponsors(study_id) -> {}:
|
||||
return ProtocolBuilderService.__make_request(study_id, ProtocolBuilderService.SPONSORS_URL)
|
||||
|
||||
@staticmethod
|
||||
def __enabled_or_raise():
|
||||
if not ProtocolBuilderService.is_enabled():
|
||||
|
|
|
@ -0,0 +1,26 @@
|
|||
[
|
||||
{
|
||||
"COMMONRULEAGENCY": null,
|
||||
"SPONSOR_ID": 2453,
|
||||
"SP_NAME": "Abbott Ltd",
|
||||
"SP_TYPE": "Private",
|
||||
"SP_TYPE_GROUP_NAME": null,
|
||||
"SS_STUDY": 2
|
||||
},
|
||||
{
|
||||
"COMMONRULEAGENCY": null,
|
||||
"SPONSOR_ID": 2387,
|
||||
"SP_NAME": "Abbott-Price",
|
||||
"SP_TYPE": "Incoming Sub Award",
|
||||
"SP_TYPE_GROUP_NAME": "Government",
|
||||
"SS_STUDY": 2
|
||||
},
|
||||
{
|
||||
"COMMONRULEAGENCY": null,
|
||||
"SPONSOR_ID": 1996,
|
||||
"SP_NAME": "Abernathy-Heidenreich",
|
||||
"SP_TYPE": "Foundation/Not for Profit",
|
||||
"SP_TYPE_GROUP_NAME": "Other External Funding",
|
||||
"SS_STUDY": 2
|
||||
}
|
||||
]
|
|
@ -0,0 +1,39 @@
|
|||
<?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" id="Definitions_0kmksnn" targetNamespace="http://bpmn.io/schema/bpmn" exporter="Camunda Modeler" exporterVersion="3.7.3">
|
||||
<bpmn:process id="Process_0exnnpv" isExecutable="true">
|
||||
<bpmn:startEvent id="StartEvent_1">
|
||||
<bpmn:outgoing>SequenceFlow_1nfe5m9</bpmn:outgoing>
|
||||
</bpmn:startEvent>
|
||||
<bpmn:sequenceFlow id="SequenceFlow_1nfe5m9" sourceRef="StartEvent_1" targetRef="Task_Script_Load_Study_Sponsors" />
|
||||
<bpmn:scriptTask id="Task_Script_Load_Study_Sponsors" name="Load Study Sponsors">
|
||||
<bpmn:incoming>SequenceFlow_1nfe5m9</bpmn:incoming>
|
||||
<bpmn:outgoing>SequenceFlow_1bqiin0</bpmn:outgoing>
|
||||
<bpmn:script>sponsors = study_sponsors()</bpmn:script>
|
||||
</bpmn:scriptTask>
|
||||
<bpmn:sequenceFlow id="SequenceFlow_1bqiin0" sourceRef="Task_Script_Load_Study_Sponsors" targetRef="EndEvent_171dj09" />
|
||||
<bpmn:endEvent id="EndEvent_171dj09">
|
||||
<bpmn:incoming>SequenceFlow_1bqiin0</bpmn:incoming>
|
||||
</bpmn:endEvent>
|
||||
</bpmn:process>
|
||||
<bpmndi:BPMNDiagram id="BPMNDiagram_1">
|
||||
<bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="Process_0exnnpv">
|
||||
<bpmndi:BPMNEdge id="SequenceFlow_1bqiin0_di" bpmnElement="SequenceFlow_1bqiin0">
|
||||
<di:waypoint x="370" y="117" />
|
||||
<di:waypoint x="452" y="117" />
|
||||
</bpmndi:BPMNEdge>
|
||||
<bpmndi:BPMNEdge id="SequenceFlow_1nfe5m9_di" bpmnElement="SequenceFlow_1nfe5m9">
|
||||
<di:waypoint x="215" y="117" />
|
||||
<di:waypoint x="270" 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="ScriptTask_1mp6xid_di" bpmnElement="Task_Script_Load_Study_Sponsors">
|
||||
<dc:Bounds x="270" y="77" width="100" height="80" />
|
||||
</bpmndi:BPMNShape>
|
||||
<bpmndi:BPMNShape id="EndEvent_171dj09_di" bpmnElement="EndEvent_171dj09">
|
||||
<dc:Bounds x="452" y="99" width="36" height="36" />
|
||||
</bpmndi:BPMNShape>
|
||||
</bpmndi:BPMNPlane>
|
||||
</bpmndi:BPMNDiagram>
|
||||
</bpmn:definitions>
|
|
@ -0,0 +1,39 @@
|
|||
from unittest.mock import patch
|
||||
|
||||
from tests.base_test import BaseTest
|
||||
|
||||
from crc import session, app
|
||||
from crc.models.study import StudyModel
|
||||
from crc.scripts.study_sponsors import StudySponsors
|
||||
from crc.services.study_service import StudyService
|
||||
from crc.services.workflow_processor import WorkflowProcessor
|
||||
from crc.services.workflow_service import WorkflowService
|
||||
|
||||
class TestSudySponsorsScript(BaseTest):
|
||||
test_uid = "dhf8r"
|
||||
test_study_id = 1
|
||||
|
||||
def test_study_sponsors_script_validation(self):
|
||||
self.load_test_spec("study_sponsors")
|
||||
WorkflowService.test_spec("study_sponsors") # This would raise errors if it didn't validate
|
||||
|
||||
|
||||
@patch('crc.services.protocol_builder.requests.get')
|
||||
def test_study_sponsors_script(self, mock_get):
|
||||
|
||||
mock_get.return_value.ok = True
|
||||
mock_get.return_value.text = self.protocol_builder_response('sponsors.json')
|
||||
app.config['PB_ENABLED'] = True
|
||||
|
||||
self.load_example_data()
|
||||
self.create_reference_document()
|
||||
study = session.query(StudyModel).first()
|
||||
workflow_spec_model = self.load_test_spec("study_sponsors")
|
||||
workflow_model = StudyService._create_workflow_model(study, workflow_spec_model)
|
||||
WorkflowService.test_spec("study_sponsors")
|
||||
processor = WorkflowProcessor(workflow_model)
|
||||
processor.do_engine_steps()
|
||||
self.assertTrue(processor.bpmn_workflow.is_completed())
|
||||
data = processor.next_task().data
|
||||
self.assertIn('sponsors', data)
|
||||
self.assertEquals(3, len(data['sponsors']))
|
|
@ -48,3 +48,15 @@ class TestProtocolBuilder(BaseTest):
|
|||
self.assertIsNotNone(response)
|
||||
self.assertEqual(64, len(response))
|
||||
self.assertEqual(1234, response['IND_1'])
|
||||
|
||||
@patch('crc.services.protocol_builder.requests.get')
|
||||
def test_get_study_sponsors(self, mock_get):
|
||||
app.config['PB_ENABLED'] = True
|
||||
mock_get.return_value.ok = True
|
||||
mock_get.return_value.text = self.protocol_builder_response('sponsors.json')
|
||||
response = ProtocolBuilderService.get_sponsors(self.test_study_id)
|
||||
self.assertIsNotNone(response)
|
||||
self.assertEqual(3, len(response))
|
||||
self.assertEqual(2, response[0]["SS_STUDY"])
|
||||
self.assertEqual(2453, response[0]["SPONSOR_ID"])
|
||||
self.assertEqual("Abbott Ltd", response[0]["SP_NAME"])
|
||||
|
|
Loading…
Reference in New Issue