diff --git a/pb/__init__.py b/pb/__init__.py index fbd325e..ab8998d 100644 --- a/pb/__init__.py +++ b/pb/__init__.py @@ -36,6 +36,11 @@ def get_study_details(studyid): return StudyDetailsSchema().dump(details) +def sponsors(studyid): + sponsors = db.session.query(StudySponsor).filter(StudySponsor.SS_STUDY == studyid).all() + return StudySponsorSchema(many=True).dump(sponsors) + + def get_form(id, requirement_code): return @@ -152,7 +157,7 @@ def site_map(): # ************************** from pb.forms import StudyForm, StudyTable, InvestigatorForm, StudyDetailsForm, ConfirmDeleteForm, StudySponsorForm from pb.models import Study, RequiredDocument, Investigator, StudySchema, RequiredDocumentSchema, InvestigatorSchema, \ - StudyDetails, StudyDetailsSchema, StudySponsor, Sponsor + StudyDetails, StudyDetailsSchema, StudySponsor, Sponsor, SponsorSchema, StudySponsorSchema @app.route('/', methods=['GET', 'POST']) @@ -219,7 +224,7 @@ def new_investigator(study_id): form = InvestigatorForm(request.form) # Remove options from form if unique investigator already exist, but AS_C and SI can happen many times. - investigators = db.session.query(Investigator).filter(Study.STUDYID == study_id).all() + investigators = db.session.query(Investigator).filter(Investigator.STUDYID == study_id).all() choices = form.INVESTIGATORTYPE.choices existing_types = [i.INVESTIGATORTYPE for i in investigators] existing_types = list(filter(lambda a: a != "AS_C", existing_types)) diff --git a/pb/api.yml b/pb/api.yml index 6893ea9..ff153cb 100644 --- a/pb/api.yml +++ b/pb/api.yml @@ -90,6 +90,29 @@ paths: type: array items: $ref: "#/components/schemas/Investigator" + /sponsors: + get: + tags: + - CR-Connect + summary: Sponsors associated with a study. + operationId: pb.sponsors + description: A list of all the sponsors related to a study + parameters: + - in: query + name: studyid + description: A valid studyid, as provided in the call to list all studies. + required: true + schema: + type: string + responses: + '200': + description: A list of sponsors + content: + application/json: + schema: + type: array + items: + $ref: "#/components/schemas/Sponsor" /study: parameters: - in: query @@ -155,6 +178,32 @@ components: format: string example: IDS - Investigational Drug Service Approval description: A descriptive name of the required dcoument. + Sponsor: + properties: + SP_NAME: + type: string + example: "AstraZeneca Pharmaceuticals LP (Wilmington, DE)" + description: A descriptive name + SP_TYPE: + type: string + example: "Industry" + description: the type of sponsor + SP_TYPE_GROUP_NAME: + type: string + example: "Industry" + description: The category of the type of sponsor + SS_STUDY: + type: number + example: 15333 + description: The unqiue id of the associated study + COMMONRULEAGENCY: + type: boolean + example: true + description: Is this a common rule agency + SPONSOR_ID: + type: number + example: 1022 + description: The unique id of the sponsor Investigator: properties: STUDYID: diff --git a/pb/models.py b/pb/models.py index 2312af6..fd521fe 100644 --- a/pb/models.py +++ b/pb/models.py @@ -52,6 +52,7 @@ class StudySponsor(db.Model): class StudySponsorSchema(ma.Schema): + class Meta: fields = ("SS_STUDY", "SPONSOR_ID", "SP_NAME", "SP_TYPE", "SP_TYPE_GROUP_NAME", "COMMONRULEAGENCY")