Exemple #1
0
def get_study(study_id):
    study = StudyService.get_study(study_id)
    if (study is None):
        raise ApiError("unknown_study",
                       'The study "' + study_id + '" is not recognized.',
                       status_code=404)
    return StudySchema().dump(study)
Exemple #2
0
 def do_task_validate_only(self, task, study_id, workflow_id, *args,
                           **kwargs):
     study = StudyService.get_study(study_id)
     if study:
         return {"DETAIL": "Passed validation.", "STATUS": "No Error"}
     else:
         raise ApiError.from_task(
             code='bad_study',
             message=f'No study for study_id {study_id}',
             task=task)
def update_study(study_id, body):
    """Pretty limited, but allows manual modifications to the study status """
    if study_id is None:
        raise ApiError('unknown_study', 'Please provide a valid Study ID.')

    study_model = session.query(StudyModel).filter_by(id=study_id).first()
    if study_model is None:
        raise ApiError('unknown_study',
                       'The study "' + study_id + '" is not recognized.')

    study: Study = StudyForUpdateSchema().load(body)

    status = StudyStatus(study.status)
    study_model.last_updated = datetime.utcnow()

    if study_model.status != status:
        study_model.status = status
        StudyService.add_study_update_event(
            study_model,
            status,
            StudyEventType.user,
            user_uid=UserService.current_user().uid
            if UserService.has_user() else None,
            comment='' if not hasattr(study, 'comment') else study.comment,
        )

    if status == StudyStatus.open_for_enrollment:
        study_model.enrollment_date = study.enrollment_date

    session.add(study_model)
    session.commit()

    if status == StudyStatus.abandoned or status == StudyStatus.hold:
        WorkflowService.process_workflows_for_cancels(study_id)

    # Need to reload the full study to return it to the frontend
    study = StudyService.get_study(study_id)
    return StudySchema().dump(study)