From c9900d787e2875420d1f1e0c7118adacad100be2 Mon Sep 17 00:00:00 2001 From: Dan Funk Date: Fri, 27 Mar 2020 15:48:21 -0400 Subject: [PATCH] Every good deed goes punished. --- crc/scripts/study_info.py | 4 ++-- crc/services/protocol_builder.py | 21 +++++++++++++++------ 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/crc/scripts/study_info.py b/crc/scripts/study_info.py index 2a9d9edd..2da06f83 100644 --- a/crc/scripts/study_info.py +++ b/crc/scripts/study_info.py @@ -39,9 +39,9 @@ class StudyInfo(Script): schema = StudyModelSchema() study_info["info"] = schema.dump(study) if cmd == 'investigators': - study_info["investigators"] = self.pb.get_investigators(study_id) + study_info["investigators"] = self.pb.get_investigators(study_id, as_json=True) if cmd == 'details': - study_info["details"] = self.pb.get_study_details(study_id) + study_info["details"] = self.pb.get_study_details(study_id, as_json=True) task.data["study"] = study_info diff --git a/crc/services/protocol_builder.py b/crc/services/protocol_builder.py index 982d47ef..2604bf01 100644 --- a/crc/services/protocol_builder.py +++ b/crc/services/protocol_builder.py @@ -30,36 +30,45 @@ class ProtocolBuilderService(object): (response.status_code, response.text)) @staticmethod - def get_investigators(study_id) -> Optional[List[ProtocolBuilderInvestigator]]: + def get_investigators(study_id, as_json=False) -> Optional[List[ProtocolBuilderInvestigator]]: ProtocolBuilderService.check_args(study_id) response = requests.get(ProtocolBuilderService.INVESTIGATOR_URL % study_id) if response.ok and response.text: pb_studies = ProtocolBuilderInvestigatorSchema(many=True).loads(response.text) - return pb_studies + if as_json: + return ProtocolBuilderInvestigatorSchema(many=True).dump(pb_studies) + else: + return pb_studies else: raise ApiError("protocol_builder_error", "Received an invalid response from the protocol builder (status %s): %s" % (response.status_code, response.text)) @staticmethod - def get_required_docs(study_id) -> Optional[List[ProtocolBuilderRequiredDocument]]: + def get_required_docs(study_id, as_json=False) -> Optional[List[ProtocolBuilderRequiredDocument]]: ProtocolBuilderService.check_args(study_id) response = requests.get(ProtocolBuilderService.REQUIRED_DOCS_URL % study_id) if response.ok and response.text: pb_studies = ProtocolBuilderRequiredDocumentSchema(many=True).loads(response.text) - return pb_studies + if as_json: + return ProtocolBuilderRequiredDocumentSchema(many=True).dump(pb_studies) + else: + return pb_studies else: raise ApiError("protocol_builder_error", "Received an invalid response from the protocol builder (status %s): %s" % (response.status_code, response.text)) @staticmethod - def get_study_details(study_id) -> Optional[ProtocolBuilderStudyDetails]: + def get_study_details(study_id, as_json=False) -> Optional[ProtocolBuilderStudyDetails]: ProtocolBuilderService.check_args(study_id) response = requests.get(ProtocolBuilderService.STUDY_DETAILS_URL % study_id) if response.ok and response.text: pb_study_details = ProtocolBuilderStudyDetailsSchema().loads(response.text) - return pb_study_details + if as_json: + return ProtocolBuilderStudyDetailsSchema().dump(pb_study_details) + else: + return pb_study_details else: raise ApiError("protocol_builder_error", "Received an invalid response from the protocol builder (status %s): %s" %