Supporting study status update
This commit is contained in:
parent
6fae89b1fc
commit
842d2ee100
12
crc/api.yml
12
crc/api.yml
|
@ -1046,22 +1046,24 @@ components:
|
||||||
example: dhf8r
|
example: dhf8r
|
||||||
protocol_builder_status:
|
protocol_builder_status:
|
||||||
type: string
|
type: string
|
||||||
enum: [INCOMPLETE, ACTIVE, HOLD, OPEN, ABANDONED]
|
enum: [incomplete, active, hold, open, abandoned]
|
||||||
example: done
|
example: done
|
||||||
sponsor:
|
sponsor:
|
||||||
type: string
|
type: string
|
||||||
|
x-nullable: true
|
||||||
example: "Sartography Pharmaceuticals"
|
example: "Sartography Pharmaceuticals"
|
||||||
ind_number:
|
ind_number:
|
||||||
type: string
|
type: string
|
||||||
|
x-nullable: true
|
||||||
example: "27b-6-42"
|
example: "27b-6-42"
|
||||||
hsr_number:
|
hsr_number:
|
||||||
type: string
|
type: string
|
||||||
x-nullable: true
|
x-nullable: true
|
||||||
example: "27b-6-1212"
|
example: "27b-6-1212"
|
||||||
categories:
|
# categories:
|
||||||
type: array
|
# type: array
|
||||||
items:
|
# items:
|
||||||
$ref: "#/components/schemas/WorkflowSpecCategory"
|
# $ref: "#/components/schemas/WorkflowSpecCategory"
|
||||||
WorkflowSpec:
|
WorkflowSpec:
|
||||||
properties:
|
properties:
|
||||||
id:
|
id:
|
||||||
|
|
|
@ -6,7 +6,7 @@ from sqlalchemy.exc import IntegrityError
|
||||||
from crc import session
|
from crc import session
|
||||||
from crc.api.common import ApiError, ApiErrorSchema
|
from crc.api.common import ApiError, ApiErrorSchema
|
||||||
from crc.models.protocol_builder import ProtocolBuilderStatus
|
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
|
from crc.services.study_service import StudyService
|
||||||
|
|
||||||
|
|
||||||
|
@ -40,10 +40,12 @@ def update_study(study_id, body):
|
||||||
if study_model is None:
|
if study_model is None:
|
||||||
raise ApiError('unknown_study', 'The study "' + study_id + '" is not recognized.')
|
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)
|
study.update_model(study_model)
|
||||||
session.add(study_model)
|
session.add(study_model)
|
||||||
session.commit()
|
session.commit()
|
||||||
|
# Need to reload the full study to return it to the frontend
|
||||||
|
study = StudyService.get_study(study_id)
|
||||||
return StudySchema().dump(study)
|
return StudySchema().dump(study)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -23,10 +23,10 @@ class ProtocolBuilderStatus(enum.Enum):
|
||||||
# • Open To Enrollment: has start date and HSR number?
|
# • Open To Enrollment: has start date and HSR number?
|
||||||
# • Abandoned: deleted in PB
|
# • Abandoned: deleted in PB
|
||||||
INCOMPLETE = 'incomplete' # Found in PB but not ready to start (not q_complete)
|
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
|
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".
|
HOLD = 'hold' # CR Connect side, if the Study ias marked as "hold".
|
||||||
OPEN = 'open', # Open To Enrollment: has start date and HSR number?
|
OPEN = 'open' # Open To Enrollment: has start date and HSR number?
|
||||||
ABANDONED = 'Abandoned' # Not found in PB
|
ABANDONED = 'abandoned' # Not found in PB
|
||||||
|
|
||||||
|
|
||||||
#DRAFT = 'draft', # !Q_COMPLETE
|
#DRAFT = 'draft', # !Q_COMPLETE
|
||||||
|
|
|
@ -133,9 +133,7 @@ class Study(object):
|
||||||
return instance
|
return instance
|
||||||
|
|
||||||
def update_model(self, study_model: StudyModel):
|
def update_model(self, study_model: StudyModel):
|
||||||
for k,v in self.__dict__.items():
|
study_model.protocol_builder_status = ProtocolBuilderStatus(self.protocol_builder_status)
|
||||||
if not k.startswith('_'):
|
|
||||||
study_model.__dict__[k] = v
|
|
||||||
|
|
||||||
def model_args(self):
|
def model_args(self):
|
||||||
"""Arguments that can be passed into the Study Model to update it."""
|
"""Arguments that can be passed into the Study Model to update it."""
|
||||||
|
@ -145,6 +143,27 @@ class Study(object):
|
||||||
return self_dict
|
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):
|
class StudySchema(ma.Schema):
|
||||||
|
|
||||||
id = fields.Integer(required=False, allow_none=True)
|
id = fields.Integer(required=False, allow_none=True)
|
||||||
|
|
Loading…
Reference in New Issue