Пример #1
0
    def test_iodu_study_facility_duplicate(self):
        """ Tests the IODU insertion of duplicate `StudyFacility` records to
            ensure deduplication functions as intended.
        """

        # Create fixtures.
        study_id, _ = create_study(dal=self.dal)
        facility_id, _ = create_facility(dal=self.dal)
        facility_02_id, _ = create_facility(dal=self.dal, name="new_name")

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

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

        # IODU the same `StudyFacility` record as before.
        obj_id = self.dal.iodu_study_facility(
            study_id=study_id,
            facility_id=facility_id,
            facility_canonical_id=None,
        )

        # 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 `StudyFacility` record.
        obj_id = self.dal.iodu_study_facility(
            study_id=study_id,
            facility_id=facility_02_id,
            facility_canonical_id=None,
        )

        # 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 `StudyFacility` record as before.
        obj_id = self.dal.iodu_study_facility(
            study_id=study_id,
            facility_id=facility_02_id,
            facility_canonical_id=None,
        )

        # The PK should still be `3` as the record is identical to the one
        # before.
        self.assertEqual(obj_id, 3)
Пример #2
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)
Пример #3
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)
Пример #4
0
    def test_iodi_location_investigator_duplicate(self):
        """ Tests the IODI insertion of duplicate `LocationInvestigator` records
            to ensure deduplication functions as intended.
        """

        # Create a `Location` record as a fixture.
        facility_id, _ = create_facility(dal=self.dal)
        person_id, _ = create_person(dal=self.dal)
        contact_id, _ = create_contact(dal=self.dal, person_id=person_id)
        location_id, _ = create_location(
            dal=self.dal,
            facility_id=facility_id,
            contact_primary_id=contact_id,
            contact_backup_id=contact_id,
        )
        # Create an `Investigator` record as a fixture.
        investigator_id, _ = create_investigator(
            dal=self.dal,
            person_id=person_id,
        )
        # Create additional `Investigator` record.
        investigator_02_id, _ = create_investigator(
            dal=self.dal,
            person_id=person_id,
            affiliation="NewAffiliation"
        )

        # IODI a new `LocationInvestigator` record.
        obj_id = self.dal.iodi_location_investigator(
            location_id=location_id,
            investigator_id=investigator_id,
        )

        self.assertEqual(obj_id, 1)

        # IODI an identical `Intervention` record.
        obj_id = self.dal.iodi_location_investigator(
            location_id=location_id,
            investigator_id=investigator_id,
        )

        self.assertEqual(obj_id, 1)

        # IODI a new `Intervention` record.
        obj_id = self.dal.iodi_location_investigator(
            location_id=location_id,
            investigator_id=investigator_02_id,
        )

        self.assertEqual(obj_id, 3)

        # IODI the same `Intervention` record as before.
        obj_id = self.dal.iodi_location_investigator(
            location_id=location_id,
            investigator_id=investigator_02_id,
        )

        self.assertEqual(obj_id, 3)
Пример #5
0
    def test_iodi_get_location_investigator(self):
        """ Tests the insertion of a `LocationInvestigator` record via the
            `iodi_location_investigator` method of the `DalClinicalTrials` class
            and its retrieval via the `get` method.
        """

        # Create a `Location` record as a fixture.
        facility_id, _ = create_facility(dal=self.dal)
        person_id, _ = create_person(dal=self.dal)
        contact_id, _ = create_contact(dal=self.dal, person_id=person_id)
        location_id, _ = create_location(
            dal=self.dal,
            facility_id=facility_id,
            contact_primary_id=contact_id,
            contact_backup_id=contact_id,
        )
        # Create an `Investigator` record as a fixture.
        investigator_id, _ = create_investigator(
            dal=self.dal,
            person_id=person_id,
        )

        # IODI a new `LocationInvestigator` record.
        obj_id = self.dal.iodi_location_investigator(
            location_id=location_id,
            investigator_id=investigator_id,
        )

        self.assertEqual(obj_id, 1)

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

        # Assert that the different fields of the record match.
        self.assertEqual(obj.location_investigator_id, 1)
        self.assertEqual(obj.location_id, location_id)
        self.assertEqual(obj.investigator_id, investigator_id)
Пример #6
0
    def test_delete_location_investigator(self):
        """ Tests the deletion of a `LocationInvestigator` record via the
            `delete` method of the `DalClinicalTrials` class.
        """

        # Create a `Location` record as a fixture.
        facility_id, _ = create_facility(dal=self.dal)
        person_id, _ = create_person(dal=self.dal)
        contact_id, _ = create_contact(dal=self.dal, person_id=person_id)
        location_id, _ = create_location(
            dal=self.dal,
            facility_id=facility_id,
            contact_primary_id=contact_id,
            contact_backup_id=contact_id,
        )
        # Create an `Investigator` record as a fixture.
        investigator_id, _ = create_investigator(
            dal=self.dal,
            person_id=person_id,
        )

        # IODI a new `LocationInvestigator` record.
        obj_id = self.dal.iodi_location_investigator(
            location_id=location_id,
            investigator_id=investigator_id,
        )

        self.assertEqual(obj_id, 1)

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

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

        self.assertIsNone(obj)