def test_iodi_study_intervention_duplicate(self):
        """ Tests the IODI insertion of duplicate `StudyIntervention` records
            to ensure deduplication functions as intended.
        """

        # Create fixtures.
        study_id, _ = create_study(dal=self.dal)
        intervention_id, _ = create_intervention(dal=self.dal)
        intervention_02_id, _ = create_intervention(
            dal=self.dal,
            name="new_name",
        )

        # IODI a new `StudyIntervention` record.
        obj_id = self.dal.iodi_study_intervention(
            study_id=study_id,
            intervention_id=intervention_id,
        )

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

        # IODI the same `StudyIntervention` record as before.
        obj_id = self.dal.iodi_study_intervention(
            study_id=study_id,
            intervention_id=intervention_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 `StudyIntervention` record.
        obj_id = self.dal.iodi_study_intervention(
            study_id=study_id,
            intervention_id=intervention_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 `StudyIntervention` record as before.
        obj_id = self.dal.iodi_study_intervention(
            study_id=study_id,
            intervention_id=intervention_02_id,
        )

        # The PK should still be `3` as the record is identical to the one
        # before.
        self.assertEqual(obj_id, 3)
    def test_iodi_get_study_intervention(self):
        """ Tests the insertion of a `StudyIntervention` record via the
            `iodi_study_intervention` method of the `DalClinicalTrials` class
            and its retrieval via the get` method.
        """

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

        # IODI a new `StudyIntervention` record.
        obj_id = self.dal.iodi_study_intervention(
            study_id=study_id,
            intervention_id=intervention_id,
        )

        self.assertEqual(obj_id, 1)

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

        # Assert that the different fields of the record match.
        self.assertEqual(obj.study_intervention_id, 1)
        self.assertEqual(obj.study_id, study_id)
        self.assertEqual(obj.intervention_id, intervention_id)
    def test_delete_intervention_alias(self):
        """ Tests the deletion of a `InterventionAlias` record via the
            `delete` method of the `DalClinicalTrials` class.
        """

        # Create an `Alias` record as a fixture.
        alias_id, _ = create_alias(dal=self.dal)
        # Create an `Intervention` record as a fixture.
        intervention_id, _ = create_intervention(dal=self.dal)

        # IODI a new `InterventionAlias` record.
        obj_id = self.dal.iodi_intervention_alias(
            alias_id=alias_id,
            intervention_id=intervention_id,
        )

        self.assertEqual(obj_id, 1)

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

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

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

        # Create an `Alias` record as a fixture.
        alias_id, _ = create_alias(dal=self.dal)
        # Create an `Intervention` record as a fixture.
        intervention_id, _ = create_intervention(dal=self.dal)

        # IODI a new `InterventionAlias` record.
        obj_id = self.dal.iodi_intervention_alias(
            alias_id=alias_id,
            intervention_id=intervention_id,
        )

        self.assertEqual(obj_id, 1)

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

        # Assert that the different fields of the record match.
        self.assertEqual(obj.intervention_alias_id, 1)
        self.assertEqual(obj.alias_id, alias_id)
        self.assertEqual(obj.intervention_id, intervention_id)
    def test_iodi_intervention_alias_duplicate(self):
        """ Tests the IODI insertion of duplicate `InterventionAlias` records
            to ensure deduplication functions as intended.
        """

        # Create two `Alias` records as fixtures.
        alias_id, _ = create_alias(dal=self.dal)
        alias_02_id, _ = create_alias(dal=self.dal, alias="NewAlias")
        # Create an `Intervention` record as a fixture.
        intervention_id, _ = create_intervention(dal=self.dal)

        # IODI a new `InterventionAlias` record.
        obj_id = self.dal.iodi_intervention_alias(
            alias_id=alias_id,
            intervention_id=intervention_id,
        )

        self.assertEqual(obj_id, 1)

        # IODI an identical `Intervention` record.
        obj_id = self.dal.iodi_intervention_alias(
            alias_id=alias_id,
            intervention_id=intervention_id,
        )

        self.assertEqual(obj_id, 1)

        # IODI a new `Intervention` record.
        obj_id = self.dal.iodi_intervention_alias(
            alias_id=alias_02_id,
            intervention_id=intervention_id,
        )

        self.assertEqual(obj_id, 3)

        # IODI the same `Intervention` record as before.
        obj_id = self.dal.iodi_intervention_alias(
            alias_id=alias_02_id,
            intervention_id=intervention_id,
        )

        self.assertEqual(obj_id, 3)
    def test_delete_study_intervention(self):
        """ Tests the deletion of a `StudyIntervention` record via the `delete`
            method of the `DalClinicalTrials` class.
        """

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

        # IODI a new `StudyIntervention` record.
        obj_id = self.dal.iodi_study_intervention(
            study_id=study_id,
            intervention_id=intervention_id,
        )

        self.assertEqual(obj_id, 1)

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

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

        self.assertIsNone(obj)