Example #1
0
    def test_build_bnf_codes_query_excludes_only(self):
        filter_ = [
            "~010101000BBABA0 # Langdales_Cinnamon Tab",
            "~0302000N0%AV # Fluticasone Prop_Inh Soln 500mcg/2ml Ud (brands and generic)",
        ]

        expected_sql = """
        WITH subquery AS (SELECT bnf_code FROM {hscic}.presentation)
        SELECT bnf_code
        FROM subquery
        WHERE NOT (bnf_code = '010101000BBABA0' OR bnf_code LIKE '0302000N0%AV')
        """

        self.assertEqual(build_bnf_codes_query(None, filter_), expected_sql)
Example #2
0
    def test_build_bnf_codes_query(self):
        base_query = "SELECT bnf_code FROM {hscic}.presentation WHERE name LIKE '% Tab'"
        filter_ = [
            "010101 # Everything in 1.1.1",
            "~010101000BBABA0 # Langdales_Cinnamon Tab",
            "~0302000N0%AV # Fluticasone Prop_Inh Soln 500mcg/2ml Ud (brands and generic)",
        ]

        expected_sql = """
        WITH subquery AS (SELECT bnf_code FROM {hscic}.presentation WHERE name LIKE '% Tab')
        SELECT bnf_code
        FROM subquery
        WHERE (bnf_code LIKE '010101%') AND NOT (bnf_code = '010101000BBABA0' OR bnf_code LIKE '0302000N0%AV')
        """

        self.assertEqual(build_bnf_codes_query(base_query, filter_),
                         expected_sql)
Example #3
0
    def test_build_bnf_codes_query_without_filter(self):
        base_query = "SELECT bnf_code FROM {hscic}.presentation WHERE name LIKE '% Tab'"

        self.assertEqual(build_bnf_codes_query(base_query, None), base_query)