Supporting study status update

This commit is contained in:
Carlos Lopez 2020-07-23 10:58:24 -06:00
parent 6fae89b1fc
commit 842d2ee100
4 changed files with 37 additions and 14 deletions

View File

@ -1046,22 +1046,24 @@ components:
example: dhf8r
protocol_builder_status:
type: string
enum: [INCOMPLETE, ACTIVE, HOLD, OPEN, ABANDONED]
enum: [incomplete, active, hold, open, abandoned]
example: done
sponsor:
type: string
x-nullable: true
example: "Sartography Pharmaceuticals"
ind_number:
type: string
x-nullable: true
example: "27b-6-42"
hsr_number:
type: string
x-nullable: true
example: "27b-6-1212"
categories:
type: array
items:
$ref: "#/components/schemas/WorkflowSpecCategory"
# categories:
# type: array
# items:
# $ref: "#/components/schemas/WorkflowSpecCategory"
WorkflowSpec:
properties:
id:

View File

@ -6,7 +6,7 @@ from sqlalchemy.exc import IntegrityError
from crc import session
from crc.api.common import ApiError, ApiErrorSchema
from crc.models.protocol_builder import ProtocolBuilderStatus
from crc.models.study import StudySchema, StudyModel, Study
from crc.models.study import StudySchema, StudyForUpdateSchema, StudyModel, Study
from crc.services.study_service import StudyService
@ -40,10 +40,12 @@ def update_study(study_id, body):
if study_model is None:
raise ApiError('unknown_study', 'The study "' + study_id + '" is not recognized.')
study: Study = StudySchema().load(body)
study: Study = StudyForUpdateSchema().load(body)
study.update_model(study_model)
session.add(study_model)
session.commit()
# Need to reload the full study to return it to the frontend
study = StudyService.get_study(study_id)
return StudySchema().dump(study)

View File

@ -23,10 +23,10 @@ class ProtocolBuilderStatus(enum.Enum):
# • Open To Enrollment: has start date and HSR number?
# • Abandoned: deleted in PB
INCOMPLETE = 'incomplete' # Found in PB but not ready to start (not q_complete)
ACTIVE = 'active', # found in PB, marked as "q_complete" and no HSR number and not hold
HOLD = 'hold', # CR Connect side, if the Study ias marked as "hold".
OPEN = 'open', # Open To Enrollment: has start date and HSR number?
ABANDONED = 'Abandoned' # Not found in PB
ACTIVE = 'active' # found in PB, marked as "q_complete" and no HSR number and not hold
HOLD = 'hold' # CR Connect side, if the Study ias marked as "hold".
OPEN = 'open' # Open To Enrollment: has start date and HSR number?
ABANDONED = 'abandoned' # Not found in PB
#DRAFT = 'draft', # !Q_COMPLETE

View File

@ -133,9 +133,7 @@ class Study(object):
return instance
def update_model(self, study_model: StudyModel):
for k,v in self.__dict__.items():
if not k.startswith('_'):
study_model.__dict__[k] = v
study_model.protocol_builder_status = ProtocolBuilderStatus(self.protocol_builder_status)
def model_args(self):
"""Arguments that can be passed into the Study Model to update it."""
@ -145,6 +143,27 @@ class Study(object):
return self_dict
class StudyForUpdateSchema(ma.Schema):
id = fields.Integer(required=False, allow_none=True)
protocol_builder_status = EnumField(ProtocolBuilderStatus, by_value=True)
hsr_number = fields.String(allow_none=True)
sponsor = fields.String(allow_none=True)
ind_number = fields.String(allow_none=True)
enrollment_date = fields.Date(allow_none=True)
class Meta:
model = Study
# additional = ["id", "title", "last_updated", "primary_investigator_id", "user_uid",
# "sponsor", "ind_number", "approvals", "files", "enrollment_date"]
unknown = INCLUDE
@marshmallow.post_load
def make_study(self, data, **kwargs):
"""Can load the basic study data for updates to the database, but categories are write only"""
return Study(**data)
class StudySchema(ma.Schema):
id = fields.Integer(required=False, allow_none=True)