From e598994d34cbd1fcd21b7719b6a0c87007d89b3f Mon Sep 17 00:00:00 2001 From: Kelly McDonald Date: Thu, 5 Nov 2020 10:31:47 -0500 Subject: [PATCH] Change the study_sponsors script so that we can actually call it : var = study_info('sponsors') to keep it more in line with other scripts that we have --- crc/scripts/study_info.py | 54 ++++++++++++++ crc/scripts/study_sponsors.py | 70 ------------------- tests/data/study_sponsors/study_sponsors.bpmn | 5 +- tests/study/test_study_sponsors_script.py | 6 +- 4 files changed, 62 insertions(+), 73 deletions(-) delete mode 100644 crc/scripts/study_sponsors.py diff --git a/crc/scripts/study_info.py b/crc/scripts/study_info.py index 922df5d2..c4b1bffd 100644 --- a/crc/scripts/study_info.py +++ b/crc/scripts/study_info.py @@ -29,6 +29,33 @@ class StudyInfo(Script): "ind_number": "1234", "inactive": False }, + "sponsors": [ + { + "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 + } + ], + "investigators": { 'PI': { 'label': ProtocolBuilderInvestigatorType.PI.value, @@ -165,6 +192,33 @@ Returns information specific to the protocol. "ind_number": "1234", "inactive": False }, + "sponsors": [ + { + "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 + } + ], + "investigators": { "PI": { "label": ProtocolBuilderInvestigatorType.PI.value, diff --git a/crc/scripts/study_sponsors.py b/crc/scripts/study_sponsors.py deleted file mode 100644 index 90231472..00000000 --- a/crc/scripts/study_sponsors.py +++ /dev/null @@ -1,70 +0,0 @@ -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 - - - - diff --git a/tests/data/study_sponsors/study_sponsors.bpmn b/tests/data/study_sponsors/study_sponsors.bpmn index 966ca8ea..5b600571 100644 --- a/tests/data/study_sponsors/study_sponsors.bpmn +++ b/tests/data/study_sponsors/study_sponsors.bpmn @@ -1,5 +1,5 @@ - + SequenceFlow_1nfe5m9 @@ -8,7 +8,8 @@ SequenceFlow_1nfe5m9 SequenceFlow_1bqiin0 - sponsors = study_sponsors() + sponsors = study_info('sponsors') + diff --git a/tests/study/test_study_sponsors_script.py b/tests/study/test_study_sponsors_script.py index d9efd5d6..3dff8c7c 100644 --- a/tests/study/test_study_sponsors_script.py +++ b/tests/study/test_study_sponsors_script.py @@ -4,7 +4,6 @@ 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 @@ -13,7 +12,12 @@ class TestSudySponsorsScript(BaseTest): test_uid = "dhf8r" test_study_id = 1 + def test_study_sponsors_script_validation(self): + self.load_example_data() # study_info script complains if irb_documents.xls is not loaded + # during the validate phase I'm going to assume that we will never + # have a case where irb_documents.xls is not loaded ?? + self.load_test_spec("study_sponsors") WorkflowService.test_spec("study_sponsors") # This would raise errors if it didn't validate