2020-03-19 21:13:30 +00:00
|
|
|
from crc.api.common import ApiError
|
|
|
|
from crc.scripts.script import Script, ScriptValidationError
|
|
|
|
from crc.services.file_service import FileService
|
|
|
|
from crc.services.protocol_builder import ProtocolBuilderService
|
|
|
|
|
|
|
|
|
2020-04-06 20:56:00 +00:00
|
|
|
class Documents(Script):
|
2020-03-19 21:13:30 +00:00
|
|
|
"""Provides information about the documents required by Protocol Builder."""
|
|
|
|
pb = ProtocolBuilderService()
|
|
|
|
|
|
|
|
def get_description(self):
|
|
|
|
return """
|
2020-04-06 20:56:00 +00:00
|
|
|
Provides detailed information about the documents loaded as a part of completing tasks.
|
2020-03-19 21:13:30 +00:00
|
|
|
Makes an immediate call to the IRB Protocol Builder API to get a list of currently required
|
|
|
|
documents. It then collects all the information in a reference file called 'irb_pro_categories.xls',
|
2020-03-26 16:51:53 +00:00
|
|
|
if the Id from Protocol Builder matches an Id in this table, all data available in that row
|
2020-03-19 21:13:30 +00:00
|
|
|
is also provided.
|
|
|
|
|
2020-04-06 20:56:00 +00:00
|
|
|
This place a dictionary of values in the current task, where the key is the code in the lookup table.
|
2020-03-19 21:13:30 +00:00
|
|
|
|
|
|
|
For example:
|
2020-04-07 18:09:21 +00:00
|
|
|
``` "Documents" :
|
2020-03-19 21:13:30 +00:00
|
|
|
{
|
2020-04-06 20:56:00 +00:00
|
|
|
"UVACompliance_PRCApproval": {
|
2020-03-19 21:13:30 +00:00
|
|
|
"name": "Cancer Center's PRC Approval Form",
|
|
|
|
"category1": "UVA Compliance",
|
|
|
|
"category2": "PRC Approval",
|
|
|
|
"category3": "",
|
|
|
|
"Who Uploads?": "CRC",
|
|
|
|
"required": True,
|
2020-04-07 18:09:21 +00:00
|
|
|
"Id": 6
|
|
|
|
"count": 0
|
2020-03-19 21:13:30 +00:00
|
|
|
},
|
|
|
|
24: { ...
|
|
|
|
}
|
|
|
|
```
|
|
|
|
"""
|
2020-03-27 12:29:31 +00:00
|
|
|
def do_task_validate_only(self, task, study_id, *args, **kwargs):
|
|
|
|
"""For validation only, pretend no results come back from pb"""
|
|
|
|
pb_docs = []
|
2020-04-07 18:09:21 +00:00
|
|
|
self.add_data_to_task(task, self.get_documents(study_id, pb_docs))
|
2020-03-19 21:13:30 +00:00
|
|
|
|
|
|
|
def do_task(self, task, study_id, *args, **kwargs):
|
|
|
|
"""Takes data from the protocol builder, and merges it with data from the IRB Pro Categories
|
2020-03-26 16:51:53 +00:00
|
|
|
spreadsheet to return pertinent details about the required documents."""
|
2020-04-03 20:24:38 +00:00
|
|
|
pb_docs = self.pb.get_required_docs(study_id, as_objects=True)
|
2020-04-07 18:09:21 +00:00
|
|
|
self.add_data_to_task(task, self.get_documents(study_id, pb_docs))
|
2020-03-19 21:13:30 +00:00
|
|
|
|
2020-04-06 20:56:00 +00:00
|
|
|
def get_documents(self, study_id, pb_docs):
|
2020-03-19 21:13:30 +00:00
|
|
|
"""Takes data from the protocol builder, and merges it with data from the IRB Pro Categories spreadsheet to return
|
2020-04-23 23:25:01 +00:00
|
|
|
pertinent details about the required documents."""
|
2020-03-27 12:29:31 +00:00
|
|
|
|
2020-03-19 21:13:30 +00:00
|
|
|
doc_dictionary = FileService.get_file_reference_dictionary()
|
2020-03-26 16:51:53 +00:00
|
|
|
required_docs = {}
|
2020-04-06 20:56:00 +00:00
|
|
|
for code, required_doc in doc_dictionary.items():
|
|
|
|
try:
|
|
|
|
pb_data = next((item for item in pb_docs if int(item.AUXDOCID) == int(required_doc['Id'])), None)
|
|
|
|
except:
|
|
|
|
pb_data = None
|
2020-04-07 18:14:43 +00:00
|
|
|
required_doc['count'] = self.get_count(study_id, code)
|
2020-04-06 20:56:00 +00:00
|
|
|
required_doc['required'] = False
|
|
|
|
if pb_data:
|
|
|
|
required_doc['required'] = True
|
|
|
|
required_docs[code] = required_doc
|
2020-03-19 21:13:30 +00:00
|
|
|
return required_docs
|
|
|
|
|
|
|
|
def get_count(self, study_id, irb_doc_code):
|
|
|
|
"""Returns the total number of documents that have been uploaded that match
|
|
|
|
the given document id. """
|
|
|
|
return(len(FileService.get_files(study_id=study_id, irb_doc_code=irb_doc_code)))
|
|
|
|
|
|
|
|
# Verifies that information is available for this script task to function
|
|
|
|
# correctly. Returns a list of validation errors.
|
|
|
|
@staticmethod
|
|
|
|
def validate():
|
|
|
|
errors = []
|
|
|
|
try:
|
|
|
|
dict = FileService.get_file_reference_dictionary()
|
|
|
|
except ApiError as ae:
|
|
|
|
errors.append(ScriptValidationError.from_api_error(ae))
|
|
|
|
return errors
|