74 lines
3.1 KiB
Python
74 lines
3.1 KiB
Python
from crc import session
|
|
from crc.api.common import ApiError
|
|
from crc.models.study import StudyModel, StudySchema
|
|
from crc.scripts.script import Script
|
|
from crc.services.protocol_builder import ProtocolBuilderService
|
|
from crc.services.workflow_processor import WorkflowProcessor
|
|
|
|
|
|
class StudyInfo(Script):
|
|
"""Just your basic class that can pull in data from a few api endpoints and do a basic task."""
|
|
pb = ProtocolBuilderService()
|
|
type_options = ['info', 'investigators', 'details']
|
|
|
|
def get_description(self):
|
|
return """StudyInfo [TYPE], where TYPE is one of 'info', 'investigators', or 'details'
|
|
Adds details about the current study to the Task Data. The type of information required should be
|
|
provided as an argument. Basic returns the basic information such as the title. Investigators provides
|
|
detailed information about each investigator in th study. Details provides a large number
|
|
of details about the study, as gathered within the protocol builder, and 'required_docs',
|
|
lists all the documents the Protocol Builder has determined will be required as a part of
|
|
this study.
|
|
"""
|
|
|
|
def do_task_validate_only(self, task, study_id, *args, **kwargs):
|
|
"""For validation only, pretend no results come back from pb"""
|
|
self.check_args(args)
|
|
data = {
|
|
"study":{
|
|
"info": {
|
|
"id": 12,
|
|
"title": "test",
|
|
"primary_investigator_id":21,
|
|
"user_uid": "dif84",
|
|
"sponsor": "sponsor",
|
|
"ind_number": "1234",
|
|
"inactive": False
|
|
},
|
|
"investigators":
|
|
{
|
|
"INVESTIGATORTYPE": "PI",
|
|
"INVESTIGATORTYPEFULL": "Primary Investigator",
|
|
"NETBADGEID": "dhf8r"
|
|
},
|
|
"details":
|
|
{}
|
|
}
|
|
}
|
|
self.add_data_to_task(task=task, data=data["study"])
|
|
|
|
def do_task(self, task, study_id, *args, **kwargs):
|
|
self.check_args(args)
|
|
|
|
cmd = args[0]
|
|
study_info = {}
|
|
if self.__class__.__name__ in task.data:
|
|
study_info = task.data[self.__class__.__name__]
|
|
|
|
if cmd == 'info':
|
|
study = session.query(StudyModel).filter_by(id=study_id).first()
|
|
schema = StudySchema()
|
|
study_info["info"] = schema.dump(study)
|
|
if cmd == 'investigators':
|
|
study_info["investigators"] = self.pb.get_investigators(study_id)
|
|
if cmd == 'details':
|
|
study_info["details"] = self.pb.get_study_details(study_id)
|
|
task.data["study"] = study_info
|
|
|
|
|
|
def check_args(self, args):
|
|
if len(args) != 1 or (args[0] not in StudyInfo.type_options):
|
|
raise ApiError(code="missing_argument",
|
|
message="The StudyInfo script requires a single argument which must be "
|
|
"one of %s" % ",".join(StudyInfo.type_options))
|