def test_iodu_get_study_sponsor(self):
        """ Tests the insertion of a `StudySponsor` record via the
            `iodu_study_sponsor` method of the `DalClinicalTrials` class and its
             retrieval via the get` method.
        """

        # Create fixtures.
        study_id, _ = create_study(dal=self.dal)
        sponsor_id, _ = create_sponsor(dal=self.dal)

        # IODU a new `StudySponsor` record.
        obj_id = self.dal.iodu_study_sponsor(
            study_id=study_id,
            sponsor_id=sponsor_id,
            sponsor_type=SponsorType.COLLABORATOR,
        )

        self.assertEqual(obj_id, 1)

        # Retrieve the new record.
        obj = self.dal.get(StudySponsor, obj_id)  # type: StudySponsor

        # Assert that the different fields of the record match.
        self.assertEqual(obj.study_sponsor_id, 1)
        self.assertEqual(obj.study_id, study_id)
        self.assertEqual(obj.sponsor_id, sponsor_id)
        self.assertEqual(obj.sponsor_type, SponsorType.COLLABORATOR)
Example #2
0
    def test_iodu_get_study_outcome(self):
        """ Tests the insertion of a `StudyOutcome` record via the
            `iodu_study_outcome` method of the `DalClinicalTrials` class and its
            retrieval via the get` method.
        """

        # Create fixtures.
        study_id, _ = create_study(dal=self.dal)
        protocol_outcome_id, _ = create_protocol_outcome(dal=self.dal)

        # IODU a new `StudyOutcome` record.
        obj_id = self.dal.iodu_study_outcome(
            study_id=study_id,
            protocol_outcome_id=protocol_outcome_id,
            outcome_type=OutcomeType.PRIMARY,
        )

        self.assertEqual(obj_id, 1)

        # Retrieve the new record.
        obj = self.dal.get(StudyOutcome, obj_id)  # type: StudyOutcome

        # Assert that the different fields of the record match.
        self.assertEqual(obj.study_outcome_id, 1)
        self.assertEqual(obj.study_id, study_id)
        self.assertEqual(obj.protocol_outcome_id, protocol_outcome_id)
        self.assertEqual(obj.outcome_type, OutcomeType.PRIMARY)
Example #3
0
    def test_iodu_get_study_facility(self):
        """ Tests the insertion of a `StudyFacility` record via the
            `iodu_study_facility` method of the `DalClinicalTrials` class and its
            retrieval via the get` method.
        """

        # Create fixtures.
        study_id, _ = create_study(dal=self.dal)
        facility_id, _ = create_facility(dal=self.dal)

        # IODU a new `StudyFacility` record.
        obj_id = self.dal.iodu_study_facility(
            study_id=study_id,
            facility_id=facility_id,
            facility_canonical_id=None,
        )

        self.assertEqual(obj_id, 1)

        # Retrieve the new record.
        obj = self.dal.get(StudyFacility, obj_id)  # type: StudyFacility

        # Assert that the different fields of the record match.
        self.assertEqual(obj.study_facility_id, 1)
        self.assertEqual(obj.study_id, study_id)
        self.assertEqual(obj.facility_id, facility_id)
        self.assertEqual(obj.facility_canonical_id, None)
    def test_delete_study_sponsor(self):
        """ Tests the deletion of a `StudySponsor` record via the `delete`
            method of the `DalClinicalTrials` class.
        """

        # Create fixtures.
        study_id, _ = create_study(dal=self.dal)
        sponsor_id, _ = create_sponsor(dal=self.dal)

        # IODU a new `StudySponsor` record.
        obj_id = self.dal.iodu_study_sponsor(
            study_id=study_id,
            sponsor_id=sponsor_id,
            sponsor_type=SponsorType.COLLABORATOR,
        )

        self.assertEqual(obj_id, 1)

        # Delete the new record.
        self.dal.delete(StudySponsor, obj_id)

        # (Attempt to) retrieve the deleted record.
        obj = self.dal.get(StudySponsor, obj_id)  # type: StudySponsor

        self.assertIsNone(obj)
    def test_iodu_get_study_descriptor(self):
        """ Tests the insertion of a `StudyDescriptor` record via the
            `iodu_study_descriptor` method of the `DalClinicalTrials` class and
            its retrieval via the get` method.
        """

        # Create fixtures.
        study_id, _ = create_study(dal=self.dal)
        descriptor_id, _ = create_descriptor(dal=self.dal_mesh)

        # IODU a new `StudyDescriptor` record.
        obj_id = self.dal.iodu_study_descriptor(
            study_id=study_id,
            descriptor_id=descriptor_id,
            study_descriptor_type=MeshTermType.CONDITION,
        )

        self.assertEqual(obj_id, 1)

        # Retrieve the new record.
        obj = self.dal.get(StudyDescriptor, obj_id)  # type: StudyDescriptor

        # Assert that the different fields of the record match.
        self.assertEqual(obj.study_descriptor_id, 1)
        self.assertEqual(obj.study_id, study_id)
        self.assertEqual(obj.descriptor_id, descriptor_id)
        self.assertEqual(obj.study_descriptor_type, MeshTermType.CONDITION)
Example #6
0
    def test_delete_study_facility(self):
        """ Tests the deletion of a `StudyFacility` record via the `delete`
            method of the `DalClinicalTrials` class.
        """

        # Create fixtures.
        study_id, _ = create_study(dal=self.dal)
        facility_id, _ = create_facility(dal=self.dal)

        # IODU a new `StudyFacility` record.
        obj_id = self.dal.iodu_study_facility(
            study_id=study_id,
            facility_id=facility_id,
            facility_canonical_id=None,
        )

        self.assertEqual(obj_id, 1)

        # Delete the new record.
        self.dal.delete(StudyFacility, obj_id)

        # (Attempt to) retrieve the deleted record.
        obj = self.dal.get(StudyFacility, obj_id)  # type: StudyFacility

        self.assertIsNone(obj)
Example #7
0
    def test_delete_study_investigator(self):
        """ Tests the deletion of a `StudyInvestigator` record via the `delete`
            method of the `DalClinicalTrials` class.
        """

        # Create fixtures.
        study_id, _ = create_study(dal=self.dal)
        investigator_id, _ = create_investigator(dal=self.dal)

        # IODI a new `StudyInvestigator` record.
        obj_id = self.dal.iodi_study_investigator(
            study_id=study_id,
            investigator_id=investigator_id,
        )

        self.assertEqual(obj_id, 1)

        # Delete the new record.
        self.dal.delete(StudyInvestigator, obj_id)

        # (Attempt to) retrieve the deleted record.
        obj = self.dal.get(StudyInvestigator,
                           obj_id)  # type: StudyInvestigator

        self.assertIsNone(obj)
    def test_delete_study_descriptor(self):
        """ Tests the deletion of a `StudyDescriptor` record via the `delete`
            method of the `DalClinicalTrials` class.
        """

        # Create fixtures.
        study_id, _ = create_study(dal=self.dal)
        descriptor_id, _ = create_descriptor(dal=self.dal_mesh)

        # IODU a new `StudyDescriptor` record.
        obj_id = self.dal.iodu_study_descriptor(
            study_id=study_id,
            descriptor_id=descriptor_id,
            study_descriptor_type=MeshTermType.CONDITION,
        )

        self.assertEqual(obj_id, 1)

        # Delete the new record.
        self.dal.delete(StudyDescriptor, obj_id)

        # (Attempt to) retrieve the deleted record.
        obj = self.dal.get(StudyDescriptor, obj_id)  # type: StudyDescriptor

        self.assertIsNone(obj)
Example #9
0
    def test_delete_study_outcome(self):
        """ Tests the deletion of a `StudyOutcome` record via the `delete`
            method of the `DalClinicalTrials` class.
        """

        # Create fixtures.
        study_id, _ = create_study(dal=self.dal)
        protocol_outcome_id, _ = create_protocol_outcome(dal=self.dal)

        # IODU a new `StudyOutcome` record.
        obj_id = self.dal.iodu_study_outcome(
            study_id=study_id,
            protocol_outcome_id=protocol_outcome_id,
            outcome_type=OutcomeType.PRIMARY,
        )

        self.assertEqual(obj_id, 1)

        # Delete the new record.
        self.dal.delete(StudyOutcome, obj_id)

        # (Attempt to) retrieve the deleted record.
        obj = self.dal.get(StudyOutcome, obj_id)  # type: StudyOutcome

        self.assertIsNone(obj)
    def test_iodi_get_study_keyword(self):
        """ Tests the insertion of a `StudyKeyword` record via the
            `iodi_study_keyword` method of the `DalClinicalTrials` class and its
             retrieval via the get` method.
        """

        # Create fixtures.
        study_id, _ = create_study(dal=self.dal)
        keyword_id, _ = create_keyword(dal=self.dal)

        # IODI a new `StudyKeyword` record.
        obj_id = self.dal.iodi_study_keyword(
            study_id=study_id,
            keyword_id=keyword_id,
        )

        self.assertEqual(obj_id, 1)

        # Retrieve the new record.
        obj = self.dal.get(StudyKeyword, obj_id)  # type: StudyKeyword

        # Assert that the different fields of the record match.
        self.assertEqual(obj.study_keyword_id, 1)
        self.assertEqual(obj.study_id, study_id)
        self.assertEqual(obj.keyword_id, keyword_id)
    def test_iodu_study_descriptor_duplicate(self):
        """ Tests the IODU insertion of duplicate `StudyDescriptor` records to
            ensure deduplication functions as intended.
        """

        # Create fixtures.
        study_id, _ = create_study(dal=self.dal)
        descriptor_id, _ = create_descriptor(dal=self.dal_mesh)
        descriptor_02_id, _ = create_descriptor(
            dal=self.dal_mesh,
            ui="new_ui",
            name="new_name",
        )

        # IODU a new `StudyDescriptor` record.
        obj_id = self.dal.iodu_study_descriptor(
            study_id=study_id,
            descriptor_id=descriptor_id,
            study_descriptor_type=MeshTermType.CONDITION,
        )

        # The PK should be `1` as this is the first record.
        self.assertEqual(obj_id, 1)

        # IODU the same `StudyDescriptor` record as before.
        obj_id = self.dal.iodu_study_descriptor(
            study_id=study_id,
            descriptor_id=descriptor_id,
            study_descriptor_type=MeshTermType.CONDITION,
        )

        # The PK should still be `1` as the record was identical thus no
        # insertion should've occured.
        self.assertEqual(obj_id, 1)

        # IODU a new `StudyDescriptor` record.
        obj_id = self.dal.iodu_study_descriptor(
            study_id=study_id,
            descriptor_id=descriptor_02_id,
            study_descriptor_type=MeshTermType.CONDITION,
        )

        # The PK should be `3` as the previous failed INSERT will have
        # incremented the PK by 1.
        self.assertEqual(obj_id, 3)

        # IODU the same `StudyDescriptor` record as before.
        obj_id = self.dal.iodu_study_descriptor(
            study_id=study_id,
            descriptor_id=descriptor_02_id,
            study_descriptor_type=MeshTermType.CONDITION,
        )

        # The PK should still be `3` as the record is identical to the one
        # before.
        self.assertEqual(obj_id, 3)
    def test_iodi_study_location_duplicate(self):
        """ Tests the IODI insertion of duplicate `StudyLocation` records
            to ensure deduplication functions as intended.
        """

        # Create fixtures.
        study_id, _ = create_study(dal=self.dal)
        location_id, _ = create_location(dal=self.dal)
        facility_id, _ = create_facility(dal=self.dal, name="new_facility")
        location_02_id, _ = create_location(
            dal=self.dal,
            facility_id=facility_id,
        )

        # IODI a new `StudyLocation` record.
        obj_id = self.dal.iodi_study_location(
            study_id=study_id,
            location_id=location_id,
        )

        # The PK should be `1` as this is the first record.
        self.assertEqual(obj_id, 1)

        # IODI the same `StudyLocation` record as before.
        obj_id = self.dal.iodi_study_location(
            study_id=study_id,
            location_id=location_id,
        )

        # The PK should still be `1` as the record was identical thus no
        # insertion should've occured.
        self.assertEqual(obj_id, 1)

        # IODI a new `StudyLocation` record.
        obj_id = self.dal.iodi_study_location(
            study_id=study_id,
            location_id=location_02_id,
        )

        # The PK should be `3` as the previous failed INSERT will have
        # incremented the PK by 1.
        self.assertEqual(obj_id, 3)

        # IODU the same `StudyLocation` record as before.
        obj_id = self.dal.iodi_study_location(
            study_id=study_id,
            location_id=location_02_id,
        )

        # The PK should still be `3` as the record is identical to the one
        # before.
        self.assertEqual(obj_id, 3)
Example #13
0
    def test_iodi_study_investigator_duplicate(self):
        """ Tests the IODI insertion of duplicate `StudyInvestigator` records
            to ensure deduplication functions as intended.
        """

        # Create fixtures.
        study_id, _ = create_study(dal=self.dal)
        investigator_id, _ = create_investigator(dal=self.dal)
        investigator_02_id, _ = create_investigator(
            dal=self.dal,
            affiliation="new_affiliation",
        )

        # IODI a new `StudyInvestigator` record.
        obj_id = self.dal.iodi_study_investigator(
            study_id=study_id,
            investigator_id=investigator_id,
        )

        # The PK should be `1` as this is the first record.
        self.assertEqual(obj_id, 1)

        # IODI the same `StudyInvestigator` record as before.
        obj_id = self.dal.iodi_study_investigator(
            study_id=study_id,
            investigator_id=investigator_id,
        )

        # The PK should still be `1` as the record was identical thus no
        # insertion should've occured.
        self.assertEqual(obj_id, 1)

        # IODI a new `StudyInvestigator` record.
        obj_id = self.dal.iodi_study_investigator(
            study_id=study_id,
            investigator_id=investigator_02_id,
        )

        # The PK should be `3` as the previous failed INSERT will have
        # incremented the PK by 1.
        self.assertEqual(obj_id, 3)

        # IODU the same `StudyInvestigator` record as before.
        obj_id = self.dal.iodi_study_investigator(
            study_id=study_id,
            investigator_id=investigator_02_id,
        )

        # The PK should still be `3` as the record is identical to the one
        # before.
        self.assertEqual(obj_id, 3)
Example #14
0
    def test_iodi_study_arm_group_duplicate(self):
        """ Tests the IODI insertion of duplicate `StudyArmGroup` records to
            ensure deduplication functions as intended.
        """

        # Create fixtures.
        study_id, _ = create_study(dal=self.dal)
        arm_group_id, _ = create_arm_group(dal=self.dal)
        arm_group_02_id, _ = create_arm_group(dal=self.dal, label="new_label")

        # IODI a new `StudyArmGroup` record.
        obj_id = self.dal.iodi_study_arm_group(
            study_id=study_id,
            arm_group_id=arm_group_id,
        )

        # The PK should be `1` as this is the first record.
        self.assertEqual(obj_id, 1)

        # IODI the same `StudyArmGroup` record as before.
        obj_id = self.dal.iodi_study_arm_group(
            study_id=study_id,
            arm_group_id=arm_group_id,
        )

        # The PK should still be `1` as the record was identical thus no
        # insertion should've occured.
        self.assertEqual(obj_id, 1)

        # IODI a new `StudyArmGroup` record.
        obj_id = self.dal.iodi_study_arm_group(
            study_id=study_id,
            arm_group_id=arm_group_02_id,
        )

        # The PK should be `3` as the previous failed INSERT will have
        # incremented the PK by 1.
        self.assertEqual(obj_id, 3)

        # IODU the same `StudyArmGroup` record as before.
        obj_id = self.dal.iodi_study_arm_group(
            study_id=study_id,
            arm_group_id=arm_group_02_id,
        )

        # The PK should still be `3` as the record is identical to the one
        # before.
        self.assertEqual(obj_id, 3)
Example #15
0
    def test_insert_study_secondary_id_duplicate(self):
        """ Tests the Inserts insertion of duplicate `StudySecondaryId` records
            to ensure that no deduplication checks occurs.
        """

        # Create fixtures.
        study_id, _ = create_study(dal=self.dal)

        # Insert a new `StudySecondaryId` record.
        obj_id = self.dal.insert_study_secondary_id(
            study_id=study_id,
            secondary_id="secondary_id",
        )

        self.assertEqual(obj_id, 1)

        # Inserts an identical `StudySecondaryId` record.
        obj_id = self.dal.insert_study_secondary_id(
            study_id=study_id,
            secondary_id="secondary_id",
        )

        self.assertEqual(obj_id, 2)

        # Inserts a new `StudySecondaryId` record.
        obj_id = self.dal.insert_study_secondary_id(
            study_id=study_id,
            secondary_id="new_secondary_id",
        )

        self.assertEqual(obj_id, 3)

        # Inserts the same `StudySecondaryId` record as before.
        obj_id = self.dal.insert_study_secondary_id(
            study_id=study_id,
            secondary_id="secondary_id",
        )

        self.assertEqual(obj_id, 4)
Example #16
0
    def test_delete_study_secondary_id(self):
        """ Tests the deletion of a `StudySecondaryId` record via the `delete`
            method of the `DalClinicalTrials` class.
        """

        # Create fixtures.
        study_id, _ = create_study(dal=self.dal)

        # Inserts a new `StudySecondaryId` record.
        obj_id = self.dal.insert_study_secondary_id(
            study_id=study_id,
            secondary_id="secondary_id",
        )

        self.assertEqual(obj_id, 1)

        # Delete the new record.
        self.dal.delete(StudySecondaryId, obj_id)

        # (Attempt to) retrieve the deleted record.
        obj = self.dal.get(StudySecondaryId, obj_id)  # type: StudySecondaryId

        self.assertIsNone(obj)
Example #17
0
    def test_delete_study_arm_group(self):
        """ Tests the deletion of a `StudyArmGroup` record via the `delete`
            method of the `DalClinicalTrials` class.
        """

        # Create fixtures.
        study_id, _ = create_study(dal=self.dal)
        arm_group_id, _ = create_arm_group(dal=self.dal)

        # IODI a new `StudyArmGroup` record.
        obj_id = self.dal.iodi_study_arm_group(
            study_id=study_id,
            arm_group_id=arm_group_id,
        )

        self.assertEqual(obj_id, 1)

        # Delete the new record.
        self.dal.delete(StudyArmGroup, obj_id)

        # (Attempt to) retrieve the deleted record.
        obj = self.dal.get(StudyArmGroup, obj_id)  # type: StudyArmGroup

        self.assertIsNone(obj)
Example #18
0
    def test_insert_get_study_secondary_id(self):
        """ Tests the insertion of a `StudySecondaryId` record via the
            `insert_study_secondary_id` method of the `DalClinicalTrials` class
            and its retrieval via the `get` method.
        """

        # Create fixtures.
        study_id, _ = create_study(dal=self.dal)

        # Insert a new `StudySecondaryId` record.
        obj_id = self.dal.insert_study_secondary_id(
            study_id=study_id,
            secondary_id="secondary_id",
        )

        self.assertEqual(obj_id, 1)

        # Retrieve the new record.
        obj = self.dal.get(StudySecondaryId, obj_id)  # type: StudySecondaryId

        # Assert that the different fields of the record match.
        self.assertEqual(obj.study_secondary_id_id, 1)
        self.assertEqual(obj.study_id, study_id)
        self.assertEqual(obj.secondary_id, "secondary_id")
Example #19
0
    def test_iodu_study_outcome_duplicate(self):
        """ Tests the IODU insertion of duplicate `StudyOutcome` records to
            ensure deduplication functions as intended.
        """

        # Create fixtures.
        study_id, _ = create_study(dal=self.dal)
        protocol_outcome_id, _ = create_protocol_outcome(dal=self.dal)
        protocol_outcome_02_id, _ = create_protocol_outcome(
            dal=self.dal,
            measure="new_measure",
        )

        # IODU a new `StudyOutcome` record.
        obj_id = self.dal.iodu_study_outcome(
            study_id=study_id,
            protocol_outcome_id=protocol_outcome_id,
            outcome_type=OutcomeType.PRIMARY,
        )

        # The PK should be `1` as this is the first record.
        self.assertEqual(obj_id, 1)

        # IODU the same `StudyOutcome` record as before.
        obj_id = self.dal.iodu_study_outcome(
            study_id=study_id,
            protocol_outcome_id=protocol_outcome_id,
            outcome_type=OutcomeType.PRIMARY,
        )

        # The PK should still be `1` as the record was identical thus no
        # insertion should've occured.
        self.assertEqual(obj_id, 1)

        # IODU the same `StudyOutcome` record with a changed `outcome_type`
        # field which should trigger an update on the existing record.
        obj_id = self.dal.iodu_study_outcome(
            study_id=study_id,
            protocol_outcome_id=protocol_outcome_id,
            outcome_type=OutcomeType.SECONDARY,
        )

        self.assertEqual(obj_id, 1)

        # Retrieve the new record.
        obj = self.dal.get(StudyOutcome, obj_id)  # type: StudyOutcome

        self.assertEqual(obj.outcome_type, OutcomeType.SECONDARY)

        # IODU a new `StudyOutcome` record.
        obj_id = self.dal.iodu_study_outcome(
            study_id=study_id,
            protocol_outcome_id=protocol_outcome_02_id,
            outcome_type=OutcomeType.POST_HOC,
        )

        # The PK should be `4` as the previous failed INSERT will have
        # incremented the PK by 1.
        self.assertEqual(obj_id, 4)

        # IODU the same `StudyOutcome` record as before.
        obj_id = self.dal.iodu_study_outcome(
            study_id=study_id,
            protocol_outcome_id=protocol_outcome_02_id,
            outcome_type=OutcomeType.POST_HOC,
        )

        # The PK should still be `4` as the record is identical to the one
        # before.
        self.assertEqual(obj_id, 4)
    def test_iodu_study_sponsor_duplicate(self):
        """ Tests the IODU insertion of duplicate `StudySponsor` records to
            ensure deduplication functions as intended.
        """

        # Create fixtures.
        study_id, _ = create_study(dal=self.dal)
        sponsor_id, _ = create_sponsor(dal=self.dal)
        sponsor_02_id, _ = create_sponsor(dal=self.dal, agency="new_agency")

        # IODU a new `StudySponsor` record.
        obj_id = self.dal.iodu_study_sponsor(
            study_id=study_id,
            sponsor_id=sponsor_id,
            sponsor_type=SponsorType.COLLABORATOR,
        )

        # The PK should be `1` as this is the first record.
        self.assertEqual(obj_id, 1)

        # IODU the same `StudySponsor` record as before.
        obj_id = self.dal.iodu_study_sponsor(
            study_id=study_id,
            sponsor_id=sponsor_id,
            sponsor_type=SponsorType.COLLABORATOR,
        )

        # The PK should still be `1` as the record was identical thus no
        # insertion should've occured.
        self.assertEqual(obj_id, 1)

        # IODU the same `StudySponsor` record with a changed `sponsor_type`
        # field which should trigger an update on the existing record.
        obj_id = self.dal.iodu_study_sponsor(
            study_id=study_id,
            sponsor_id=sponsor_id,
            sponsor_type=SponsorType.LEAD,
        )

        self.assertEqual(obj_id, 1)

        # Retrieve the new record.
        obj = self.dal.get(StudySponsor, obj_id)  # type: StudySponsor

        self.assertEqual(obj.sponsor_type, SponsorType.LEAD)

        # IODU a new `StudySponsor` record.
        obj_id = self.dal.iodu_study_sponsor(
            study_id=study_id,
            sponsor_id=sponsor_02_id,
            sponsor_type=SponsorType.COLLABORATOR,
        )

        # The PK should be `4` as the previous failed INSERT will have
        # incremented the PK by 1.
        self.assertEqual(obj_id, 4)

        # IODU the same `StudySponsor` record as before.
        obj_id = self.dal.iodu_study_sponsor(
            study_id=study_id,
            sponsor_id=sponsor_02_id,
            sponsor_type=SponsorType.COLLABORATOR,
        )

        # The PK should still be `4` as the record is identical to the one
        # before.
        self.assertEqual(obj_id, 4)