Beispiel #1
0
    def get_study(study_id, study_model: StudyModel = None):
        """Returns a study model that contains all the workflows organized by category.
        IMPORTANT:  This is intended to be a lightweight call, it should never involve
        loading up and executing all the workflows in a study to calculate information."""
        if not study_model:
            study_model = session.query(StudyModel).filter_by(id=study_id).first()
        study = Study.from_model(study_model)
        study.categories = StudyService.get_categories()
        workflow_metas = StudyService.__get_workflow_metas(study_id)
        study.approvals = ApprovalService.get_approvals_for_study(study.id)
        files = FileService.get_files_for_study(study.id)
        files = (File.from_models(model, FileService.get_file_data(model.id),
                         FileService.get_doc_dictionary()) for model in files)
        study.files = list(files)

        # Calling this line repeatedly is very very slow.  It creates the
        # master spec and runs it.  Don't execute this for Abandoned studies, as
        # we don't have the information to process them.
        if study.protocol_builder_status != ProtocolBuilderStatus.ABANDONED:
            status = StudyService.__get_study_status(study_model)
            study.warnings = StudyService.__update_status_of_workflow_meta(workflow_metas, status)

            # Group the workflows into their categories.
            for category in study.categories:
                category.workflows = {w for w in workflow_metas if w.category_id == category.id}

        return study
Beispiel #2
0
    def from_model(cls, model: ApprovalModel):
        args = dict(
            (k, v) for k, v in model.__dict__.items() if not k.startswith('_'))
        instance = cls(**args)
        instance.related_approvals = []
        instance.title = model.study.title if model.study else ''

        try:
            instance.approver = LdapService.user_info(model.approver_uid)
            instance.primary_investigator = LdapService.user_info(
                model.study.primary_investigator_id)
        except ApiError as ae:
            app.logger.error(
                f'Ldap lookup failed for approval record {model.id}',
                exc_info=True)

        doc_dictionary = FileService.get_doc_dictionary()
        instance.associated_files = []
        for approval_file in model.approval_files:
            try:
                # fixme: This is slow because we are doing a ton of queries to find the irb code.
                extra_info = doc_dictionary[
                    approval_file.file_data.file_model.irb_doc_code]
            except:
                extra_info = None
            associated_file = {}
            associated_file['id'] = approval_file.file_data.file_model.id
            if extra_info:
                associated_file['name'] = '_'.join(
                    (extra_info['category1'],
                     approval_file.file_data.file_model.name))
                associated_file['description'] = extra_info['description']
            else:
                associated_file[
                    'name'] = approval_file.file_data.file_model.name
                associated_file['description'] = 'No description available'
            associated_file[
                'name'] = '(' + model.study.primary_investigator_id + ')' + associated_file[
                    'name']
            associated_file[
                'content_type'] = approval_file.file_data.file_model.content_type
            instance.associated_files.append(associated_file)

        return instance
Beispiel #3
0
def to_file_api(file_model):
    """Converts a FileModel object to something we can return via the api"""
    return File.from_models(file_model, FileService.get_file_data(file_model.id),
                            FileService.get_doc_dictionary())