Exemplo n.º 1
0
    def handle(self, *args, **options):
        self.IS_VERBOSE = False
        if options['verbosity'] > 1:
            self.IS_VERBOSE = True

        if options['db_name']:
            db_name = options['db_name']
        else:
            db_name = utils.get_env_setting('DB_NAME')
        if options['db_user']:
            db_user = options['db_user']
        else:
            db_user = utils.get_env_setting('DB_USER')
        if options['db_pass']:
            db_pass = options['db_pass']
        else:
            db_pass = utils.get_env_setting('DB_PASS')
        db_host = utils.get_env_setting('DB_HOST')
        self.conn = psycopg2.connect(database=db_name,
                                     user=db_user,
                                     password=db_pass,
                                     host=db_host)
        cursor = self.conn.cursor()

        self.refresh_matviews(cursor)
        self.vacuum_db(cursor)
        self.analyze_db(cursor)

        self.conn.close()
Exemplo n.º 2
0
def mailchimp_subscribe(request, email, first_name, last_name, organisation,
                        job_title):
    """Subscribe `email` to newsletter.

    Returns boolean indicating success
    """
    del (request.session['newsletter_email'])
    email_hash = hashlib.md5(email).hexdigest()
    data = {
        'email_address': email,
        'status': 'subscribed',
        'merge_fields': {
            'FNAME': first_name,
            'LNAME': last_name,
            'MMERGE3': organisation,
            'MMERGE4': job_title
        }
    }
    client = MailChimp(mc_user=get_env_setting('MAILCHIMP_USER'),
                       mc_api=get_env_setting('MAILCHIMP_API_KEY'))
    try:
        client.lists.members.get(list_id=settings.MAILCHIMP_LIST_ID,
                                 subscriber_hash=email_hash)
        return True
    except MailChimpError:
        try:
            client.lists.members.create(list_id=settings.MAILCHIMP_LIST_ID,
                                        data=data)
            return True
        except MailChimpError:
            # things like blacklisted emails, etc
            logger.warn("Unable to subscribe %s to newsletter", email)
            return False
    def handle(self, *args, **options):
        self.IS_VERBOSE = False
        if options['verbosity'] > 1:
            self.IS_VERBOSE = True

        if options['db_name']:
            db_name = options['db_name']
        else:
            db_name = utils.get_env_setting('DB_NAME')
        if options['db_user']:
            db_user = options['db_user']
        else:
            db_user = utils.get_env_setting('DB_USER')
        if options['db_pass']:
            db_pass = options['db_pass']
        else:
            db_pass = utils.get_env_setting('DB_PASS')

        self.conn = psycopg2.connect(database=db_name, user=db_user,
                                     password=db_pass)
        cursor = self.conn.cursor()

        self.create_indexes(cursor)
        self.analyze_db(cursor)

        self.conn.commit()
        self.conn.close()
Exemplo n.º 4
0
    def handle(self, *args, **options):
        self.IS_VERBOSE = False
        if options['verbosity'] > 1:
            self.IS_VERBOSE = True

        if options['db_name']:
            db_name = options['db_name']
        else:
            db_name = utils.get_env_setting('DB_NAME')
        if options['db_user']:
            db_user = options['db_user']
        else:
            db_user = utils.get_env_setting('DB_USER')
        if options['db_pass']:
            db_pass = options['db_pass']
        else:
            db_pass = utils.get_env_setting('DB_PASS')
        db_host = utils.get_env_setting('DB_HOST')
        self.conn = psycopg2.connect(database=db_name, user=db_user,
                                     password=db_pass, host=db_host)
        cursor = self.conn.cursor()

        self.refresh_matviews(cursor)
        self.vacuum_db(cursor)
        self.analyze_db(cursor)

        self.conn.close()
Exemplo n.º 5
0
    def handle(self, *args, **options):
        self.IS_VERBOSE = False
        if options["verbosity"] > 1:
            self.IS_VERBOSE = True

        if options["db_name"]:
            db_name = options["db_name"]
        else:
            db_name = utils.get_env_setting("DB_NAME")
        if options["db_user"]:
            db_user = options["db_user"]
        else:
            db_user = utils.get_env_setting("DB_USER")
        if options["db_pass"]:
            db_pass = options["db_pass"]
        else:
            db_pass = utils.get_env_setting("DB_PASS")
        db_host = utils.get_env_setting("DB_HOST")
        self.conn = psycopg2.connect(database=db_name,
                                     user=db_user,
                                     password=db_pass,
                                     host=db_host)
        cursor = self.conn.cursor()

        self.create_foreign_keys(cursor)
        self.analyze_db(cursor)

        self.conn.commit()
        self.conn.close()
Exemplo n.º 6
0
def setUpModule():
    fix_dir = 'frontend/tests/fixtures/'
    management.call_command('loaddata',
                            fix_dir + 'chemicals.json',
                            verbosity=0)
    management.call_command('loaddata', fix_dir + 'products.json', verbosity=0)
    management.call_command('loaddata', fix_dir + 'sections.json', verbosity=0)
    management.call_command('loaddata',
                            fix_dir + 'presentations.json',
                            verbosity=0)
    management.call_command('loaddata', fix_dir + 'ccgs.json', verbosity=0)
    management.call_command('loaddata',
                            fix_dir + 'practices.json',
                            verbosity=0)
    management.call_command('loaddata', fix_dir + 'shas.json', verbosity=0)
    management.call_command('loaddata',
                            fix_dir + 'prescriptions.json',
                            verbosity=0)
    db_name = utils.get_env_setting('DB_NAME')
    db_user = utils.get_env_setting('DB_USER')
    db_pass = utils.get_env_setting('DB_PASS')
    management.call_command('create_matviews',
                            db_name='test_' + db_name,
                            db_user=db_user,
                            db_pass=db_pass)
Exemplo n.º 7
0
def mailchimp_subscribe(request, email, first_name, last_name, organisation, job_title):
    """Subscribe `email` to newsletter.

    Returns boolean indicating success
    """
    del request.session["newsletter_email"]
    email_hash = hashlib.md5(email.encode("utf8")).hexdigest()
    data = {
        "email_address": email,
        "status": "subscribed",
        "merge_fields": {
            "FNAME": first_name,
            "LNAME": last_name,
            "MMERGE3": organisation,
            "MMERGE4": job_title,
        },
    }
    client = MailChimp(
        mc_user=get_env_setting("MAILCHIMP_USER"),
        mc_api=get_env_setting("MAILCHIMP_API_KEY"),
    )
    try:
        client.lists.members.get(
            list_id=settings.MAILCHIMP_LIST_ID, subscriber_hash=email_hash
        )
        return True
    except MailChimpError:
        try:
            client.lists.members.create(list_id=settings.MAILCHIMP_LIST_ID, data=data)
            return True
        except MailChimpError:
            # things like blacklisted emails, etc
            logger.warn("Unable to subscribe %s to newsletter", email)
            return False
def setUpModule():
    fix_dir = 'frontend/tests/fixtures/'
    management.call_command('loaddata', fix_dir + 'chemicals.json',
                            verbosity=0)
    management.call_command('loaddata', fix_dir + 'products.json',
                            verbosity=0)
    management.call_command('loaddata', fix_dir + 'sections.json',
                            verbosity=0)
    management.call_command('loaddata', fix_dir + 'presentations.json',
                            verbosity=0)
    management.call_command('loaddata', fix_dir + 'ccgs.json',
                            verbosity=0)
    management.call_command('loaddata', fix_dir + 'practices.json',
                            verbosity=0)
    management.call_command('loaddata', fix_dir + 'shas.json',
                            verbosity=0)
    management.call_command('loaddata', fix_dir + 'prescriptions.json',
                            verbosity=0)
    db_name = utils.get_env_setting('DB_NAME')
    db_user = utils.get_env_setting('DB_USER')
    db_pass = utils.get_env_setting('DB_PASS')
    management.call_command('create_matviews',
                            db_name='test_' + db_name,
                            db_user=db_user,
                            db_pass=db_pass)
def tearDownModule():
    args = []
    db_name = "test_" + utils.get_env_setting("DB_NAME")
    db_user = utils.get_env_setting("DB_USER")
    db_pass = utils.get_env_setting("DB_PASS")
    opts = {"db_name": db_name, "db_user": db_user, "db_pass": db_pass}
    call_command("drop_matviews", *args, **opts)
    call_command("flush", verbosity=0, interactive=False)
Exemplo n.º 10
0
def tearDownModule():
    args = []
    db_name = 'test_' + utils.get_env_setting('DB_NAME')
    db_user = utils.get_env_setting('DB_USER')
    db_pass = utils.get_env_setting('DB_PASS')
    opts = {'db_name': db_name, 'db_user': db_user, 'db_pass': db_pass}
    management.call_command('drop_matviews', *args, **opts)
    management.call_command('flush', verbosity=0, interactive=False)
Exemplo n.º 11
0
def setUpModule():
        SHA.objects.create(code='Q51')
        bassetlaw = PCT.objects.create(code='02Q', org_type='CCG')
        lincs_west = PCT.objects.create(code='04D', org_type='CCG')
        lincs_east = PCT.objects.create(code='03T', org_type='CCG')
        Chemical.objects.create(bnf_code='0212000AA',
                                    chem_name='Rosuvastatin Calcium')
        Chemical.objects.create(bnf_code='0212000B0',
                                    chem_name='Atorvastatin')
        Practice.objects.create(code='C84001', ccg=bassetlaw,
                                name='LARWOOD SURGERY', setting=4)
        Practice.objects.create(code='C84024', ccg=bassetlaw,
                                name='NEWGATE MEDICAL GROUP', setting=4)
        Practice.objects.create(code='B82005', ccg=bassetlaw,
                                name='PRIORY MEDICAL GROUP', setting=4,
                                open_date='2015-01-01')
        Practice.objects.create(code='B82010', ccg=bassetlaw,
                                name='RIPON SPA SURGERY', setting=4)
        Practice.objects.create(code='A85017', ccg=bassetlaw,
                                name='BEWICK ROAD SURGERY', setting=4)
        Practice.objects.create(code='A86030', ccg=bassetlaw,
                                name='BETTS AVENUE MEDICAL GROUP', setting=4)
        # Ensure we only include open practices in our calculations.
        Practice.objects.create(code='B82008', ccg=bassetlaw,
                                name='NORTH HOUSE SURGERY', setting=4,
                                open_date='2010-04-01',
                                close_date='2012-01-01')
        # Ensure we only include standard practices in our calculations.
        Practice.objects.create(code='Y00581', ccg=bassetlaw,
                                name='BASSETLAW DRUG & ALCOHOL SERVICE',
                                setting=1)
        Practice.objects.create(code='C83051', ccg=lincs_west,
                                name='ABBEY MEDICAL PRACTICE', setting=4)
        Practice.objects.create(code='C83019', ccg=lincs_east,
                                name='BEACON MEDICAL PRACTICE', setting=4)

        args = []
        db_name = 'test_' + utils.get_env_setting('DB_NAME')
        db_user = utils.get_env_setting('DB_USER')
        db_pass = utils.get_env_setting('DB_PASS')
        test_file = 'frontend/tests/fixtures/commands/'
        test_file += 'T201509PDPI+BNFT_formatted.CSV'
        new_opts = {
            'db_name': db_name,
            'db_user': db_user,
            'db_pass': db_pass,
            'filename': test_file
        }
        management.call_command('import_hscic_prescribing', *args, **new_opts)

        month = '2015-09-01'
        measure_id = 'rosuvastatin'
        args = []
        opts = {
            'month': month,
            'measure': measure_id
        }
        management.call_command('import_measures', *args, **opts)
    def test_import_create_matviews(self):
        db_name = 'test_' + utils.get_env_setting('DB_NAME')
        db_user = utils.get_env_setting('DB_USER')
        db_pass = utils.get_env_setting('DB_PASS')
        self.conn = psycopg2.connect(database=db_name, user=db_user,
                                     password=db_pass)
        with self.conn.cursor() as c:

            cmd = 'SELECT * from vw_practice_summary '
            cmd += 'order by processing_date'
            c.execute(cmd)
            results = c.fetchall()
            self.assertEqual(len(results), 10)
            self.assertEqual(results[9][1], 'P87629')
            self.assertEqual(results[9][2], 55)
            self.assertEqual(results[9][3], 64.26)

            cmd = 'SELECT * from vw_presentation_summary '
            cmd += 'order by processing_date'
            c.execute(cmd)
            results = c.fetchall()
            self.assertEqual(len(results), 11)
            self.assertEqual(results[9][1], '0204000I0BCAAAB')
            self.assertEqual(results[9][2], 29)
            self.assertEqual(results[9][3], 32.26)

            cmd = 'SELECT * from vw_presentation_summary_by_ccg '
            cmd += 'order by processing_date, presentation_code'
            c.execute(cmd)
            results = c.fetchall()
            self.assertEqual(len(results), 12)
            self.assertEqual(results[9][1], '03V')
            self.assertEqual(results[9][2], '0202010B0AAABAB')
            self.assertEqual(results[9][3], 62)
            self.assertEqual(results[9][4], 54.26)

            cmd = 'SELECT * from vw_chemical_summary_by_ccg '
            cmd += 'order by processing_date, chemical_id'
            c.execute(cmd)
            results = c.fetchall()
            self.assertEqual(len(results), 11)
            self.assertEqual(results[10][1], '03V')
            self.assertEqual(results[10][2], '0204000I0')
            self.assertEqual(results[10][3], 33)
            self.assertEqual(results[10][4], 36.28)

            cmd = 'SELECT * from vw_chemical_summary_by_practice '
            cmd += 'order by processing_date, practice_id'
            c.execute(cmd)
            results = c.fetchall()
            self.assertEqual(len(results), 13)
            self.assertEqual(results[10][1], 'K83059')
            self.assertEqual(results[10][2], '0204000I0')
            self.assertEqual(results[10][3], 16)
            self.assertEqual(results[10][4], 14.15)

        self.conn.close()
Exemplo n.º 13
0
 def setup_db(self):
     """Create a connection to postgres database
     """
     db_name = utils.get_env_setting('DB_NAME')
     db_user = utils.get_env_setting('DB_USER')
     db_pass = utils.get_env_setting('DB_PASS')
     db_host = utils.get_env_setting('DB_HOST', '127.0.0.1')
     self.conn = psycopg2.connect(database=db_name, user=db_user,
                                  password=db_pass, host=db_host)
Exemplo n.º 14
0
 def setup_db(self):
     """Create a connection to postgres database
     """
     db_name = utils.get_env_setting('DB_NAME')
     db_user = utils.get_env_setting('DB_USER')
     db_pass = utils.get_env_setting('DB_PASS')
     db_host = utils.get_env_setting('DB_HOST', '127.0.0.1')
     self.conn = psycopg2.connect(database=db_name, user=db_user,
                                  password=db_pass, host=db_host)
def tearDownModule():
    args = []
    db_name = 'test_' + utils.get_env_setting('DB_NAME')
    db_user = utils.get_env_setting('DB_USER')
    db_pass = utils.get_env_setting('DB_PASS')
    opts = {
        'db_name': db_name,
        'db_user': db_user,
        'db_pass': db_pass
    }
    call_command('drop_matviews', *args, **opts)
    call_command('flush', verbosity=0, interactive=False)
def setUpModule():
    fix_dir = 'frontend/tests/fixtures/'
    call_command('loaddata', fix_dir + 'chemicals.json', verbosity=0)
    call_command('loaddata', fix_dir + 'ccgs.json', verbosity=0)
    call_command('loaddata', fix_dir + 'practices.json', verbosity=0)
    call_command('loaddata', fix_dir + 'shas.json', verbosity=0)
    call_command('loaddata', fix_dir + 'prescriptions.json', verbosity=0)
    call_command('loaddata', fix_dir + 'practice_listsizes.json', verbosity=0)
    args = []
    db_name = 'test_' + utils.get_env_setting('DB_NAME')
    db_user = utils.get_env_setting('DB_USER')
    db_pass = utils.get_env_setting('DB_PASS')
    opts = {'db_name': db_name, 'db_user': db_user, 'db_pass': db_pass}
    call_command('create_matviews', *args, **opts)
def setUpModule():
    fix_dir = "frontend/tests/fixtures/"
    call_command("loaddata", fix_dir + "chemicals.json", verbosity=0)
    call_command("loaddata", fix_dir + "ccgs.json", verbosity=0)
    call_command("loaddata", fix_dir + "practices.json", verbosity=0)
    call_command("loaddata", fix_dir + "shas.json", verbosity=0)
    call_command("loaddata", fix_dir + "prescriptions.json", verbosity=0)
    call_command("loaddata", fix_dir + "practice_listsizes.json", verbosity=0)
    args = []
    db_name = "test_" + utils.get_env_setting("DB_NAME")
    db_user = utils.get_env_setting("DB_USER")
    db_pass = utils.get_env_setting("DB_PASS")
    opts = {"db_name": db_name, "db_user": db_user, "db_pass": db_pass}
    call_command("create_matviews", *args, **opts)
 def setUp(self):
     if 'SKIP_BQ_LOAD' not in os.environ:
         # Create local test data from fixtures, then upload this to a
         # test project in bigquery
         call_command('loaddata',
                      'frontend/tests/fixtures/ccgs.json',
                      verbosity=0)
         call_command('loaddata',
                      'frontend/tests/fixtures/practices.json',
                      verbosity=0)
         call_command('loaddata',
                      'frontend/tests/fixtures/practice_listsizes.json',
                      verbosity=0)
         fixtures_base = 'frontend/tests/fixtures/commands/'
         prescribing_fixture = (fixtures_base +
                                'prescribing_bigquery_views_fixture.csv')
         db_name = 'test_' + utils.get_env_setting('DB_NAME')
         env = patch.dict('os.environ', {'DB_NAME': db_name})
         with env:
             # We patch the environment as this is how the
             # ebmdatalab/bigquery library selects a database
             bigquery.load_prescribing_data_from_file(
                 'test_hscic', 'prescribing', prescribing_fixture)
             bigquery.load_ccgs_from_pg('test_hscic')
             bigquery.load_statistics_from_pg('test_hscic')
     ImportLog.objects.create(category='prescribing',
                              current_at='2015-10-01')
     # Create view tables and indexes
     with open('frontend/management/commands/replace_matviews.sql',
               'r') as f:
         with connection.cursor() as c:
             c.execute(f.read())
     args = []
     opts = {'dataset': 'test_hscic'}
     call_command('create_views', *args, **opts)
    def handle(self, *args, **options):
        self.IS_VERBOSE = False
        if options['verbosity'] > 1:
            self.IS_VERBOSE = True

        if options['db_name']:
            db_name = options['db_name']
        else:
            db_name = utils.get_env_setting('DB_NAME')
        if options['db_user']:
            db_user = options['db_user']
        else:
            db_user = utils.get_env_setting('DB_USER')
        if options['db_pass']:
            db_pass = options['db_pass']
        else:
            db_pass = utils.get_env_setting('DB_PASS')
        db_host = utils.get_env_setting('DB_HOST', '127.0.0.1')
        self.conn = psycopg2.connect(database=db_name,
                                     user=db_user,
                                     password=db_pass,
                                     host=db_host)
        cursor = self.conn.cursor()

        if options['filename']:
            files_to_import = [options['filename']]
        else:
            filepath = './data/raw_data/T*PDPI+BNFT_formatted*'
            files_to_import = glob.glob(filepath)

        for f in files_to_import:
            self.import_shas_and_pcts(f)
            self.delete_existing_prescriptions(f)
            self.import_prescriptions(f, cursor)

        self.vacuum_db(cursor)
        self.analyze_db(cursor)

        self.conn.close()
def setUpModule():
    fix_dir = 'frontend/tests/fixtures/'
    call_command('loaddata', fix_dir + 'chemicals.json',
                 verbosity=0)
    call_command('loaddata', fix_dir + 'ccgs.json',
                 verbosity=0)
    call_command('loaddata', fix_dir + 'practices.json',
                 verbosity=0)
    call_command('loaddata', fix_dir + 'shas.json',
                 verbosity=0)
    call_command('loaddata', fix_dir + 'prescriptions.json',
                 verbosity=0)
    args = []
    db_name = 'test_' + utils.get_env_setting('DB_NAME')
    db_user = utils.get_env_setting('DB_USER')
    db_pass = utils.get_env_setting('DB_PASS')
    opts = {
        'db_name': db_name,
        'db_user': db_user,
        'db_pass': db_pass
    }
    call_command('create_matviews', *args, **opts)
    def test_import_hscic_prescribing(self):
        args = []
        db_name = 'test_' + utils.get_env_setting('DB_NAME')
        db_user = utils.get_env_setting('DB_USER')
        db_pass = utils.get_env_setting('DB_PASS')
        test_file = 'frontend/tests/fixtures/commands/'
        test_file += 'T201304PDPI+BNFT_formatted.CSV'
        new_opts = {
            'db_name': db_name,
            'db_user': db_user,
            'db_pass': db_pass,
            'filename': test_file
        }
        call_command('import_hscic_prescribing', *args, **new_opts)

        shas = SHA.objects.all()
        self.assertEqual(shas.count(), 1)
        pcts = PCT.objects.all()
        self.assertEqual(pcts.count(), 1)

        prescriptions = Prescription.objects.all()
        self.assertEqual(prescriptions.count(), 15)

        p = Prescription.objects.filter(presentation_code='0401020K0AAAIAI')
        self.assertEqual(p.count(), 3)

        p = Prescription.objects.get(presentation_code='0410030C0AAAFAF')
        self.assertEqual(p.sha.code, 'Q30')
        self.assertEqual(p.pct.code, '5D7')
        self.assertEqual(p.practice.code, 'Y01957')
        self.assertEqual(p.chemical.bnf_code, '0410030C0')
        self.assertEqual(p.presentation_name, 'Methadone HCl_Mix 1mg/1ml S/F')
        self.assertEqual(p.total_items, 1346)
        self.assertEqual(p.net_cost, 12038.02)
        self.assertEqual(p.actual_cost, 11270.33)
        self.assertEqual(p.quantity, 878870)
        self.assertEqual(p.processing_date, datetime.date(2013, 4, 1))
        self.assertEqual(p.price_per_unit, 0.0128236599269517)
    def test_import_hscic_prescribing(self):
        args = []
        db_name = 'test_' + utils.get_env_setting('DB_NAME')
        db_user = utils.get_env_setting('DB_USER')
        db_pass = utils.get_env_setting('DB_PASS')
        test_file = 'frontend/tests/fixtures/commands/'
        test_file += 'T201304PDPI+BNFT_formatted.CSV'
        new_opts = {
            'db_name': db_name,
            'db_user': db_user,
            'db_pass': db_pass,
            'filename': test_file
        }
        call_command('import_hscic_prescribing', *args, **new_opts)

        shas = SHA.objects.all()
        self.assertEqual(shas.count(), 1)
        pcts = PCT.objects.all()
        self.assertEqual(pcts.count(), 1)

        prescriptions = Prescription.objects.all()
        self.assertEqual(prescriptions.count(), 15)

        p = Prescription.objects.filter(presentation_code='0401020K0AAAIAI')
        self.assertEqual(p.count(), 3)

        p = Prescription.objects.get(presentation_code='0410030C0AAAFAF')
        self.assertEqual(p.sha.code, 'Q30')
        self.assertEqual(p.pct.code, '5D7')
        self.assertEqual(p.practice.code, 'Y01957')
        self.assertEqual(p.chemical.bnf_code, '0410030C0')
        self.assertEqual(p.presentation_name, 'Methadone HCl_Mix 1mg/1ml S/F')
        self.assertEqual(p.total_items, 1346)
        self.assertEqual(p.net_cost, 12038.02)
        self.assertEqual(p.actual_cost, 11270.33)
        self.assertEqual(p.quantity, 878870)
        self.assertEqual(p.processing_date, datetime.date(2013, 4, 1))
        self.assertEqual(p.price_per_unit, 0.0128236599269517)
    def handle(self, *args, **options):
        self.IS_VERBOSE = False
        if options['verbosity'] > 1:
            self.IS_VERBOSE = True

        if options['db_name']:
            db_name = options['db_name']
        else:
            db_name = utils.get_env_setting('DB_NAME')
        if options['db_user']:
            db_user = options['db_user']
        else:
            db_user = utils.get_env_setting('DB_USER')
        if options['db_pass']:
            db_pass = options['db_pass']
        else:
            db_pass = utils.get_env_setting('DB_PASS')
        db_host = utils.get_env_setting('DB_HOST', '127.0.0.1')
        self.conn = psycopg2.connect(database=db_name, user=db_user,
                                     password=db_pass, host=db_host)
        cursor = self.conn.cursor()

        if options['filename']:
            files_to_import = [options['filename']]
        else:
            filepath = './data/raw_data/T*PDPI+BNFT_formatted*'
            files_to_import = glob.glob(filepath)

        for f in files_to_import:
            self.import_shas_and_pcts(f)
            self.delete_existing_prescriptions(f)
            self.import_prescriptions(f, cursor)

        self.vacuum_db(cursor)
        self.analyze_db(cursor)

        self.conn.close()
Exemplo n.º 24
0
    def setUp(self):
        self.chemical = Chemical.objects.create(bnf_code='0401020K0',
                                                chem_name='test')
        self.practice = Practice.objects.create(code='Y03375', name='test')
        self.pct = PCT.objects.create(code='5D7', name='test')
        Chemical.objects.create(bnf_code='0410030C0', chem_name='test')
        Practice.objects.create(code='Y00135', name='test')
        Practice.objects.create(code='Y01957', name='test')

        test_file = 'frontend/tests/fixtures/commands/'
        test_file += 'T201304PDPI+BNFT_formatted.CSV'
        self.new_opts = {'filename': test_file}
        db_name = 'test_' + utils.get_env_setting('DB_NAME')
        self.env = patch.dict('os.environ', {'DB_NAME': db_name})
        with self.env:
            call_command('import_hscic_prescribing', **self.new_opts)
Exemplo n.º 25
0
 def handle(self, *args, **options):
     db_name = options['db_name']
     db_user = options['db_user']
     db_pass = options['db_pass']
     db_host = utils.get_env_setting('DB_HOST')
     self.conn = psycopg2.connect(database=db_name, user=db_user,
                                  password=db_pass, host=db_host)
     with self.conn.cursor() as c:
         cmd = 'DROP MATERIALIZED VIEW vw__presentation_summary; '
         cmd += 'DROP MATERIALIZED VIEW vw__presentation_summary_by_ccg; '
         cmd += 'DROP MATERIALIZED VIEW vw__chemical_summary_by_ccg; '
         cmd += 'DROP MATERIALIZED VIEW vw__chemical_summary_by_practice; '
         cmd += 'DROP MATERIALIZED VIEW vw__practice_summary; '
         cmd += 'DROP MATERIALIZED VIEW vw__ccgstatistics; '
         c.execute(cmd)
     self.conn.commit()
     self.conn.close()
Exemplo n.º 26
0
    def setUp(self):
        self.chemical = Chemical.objects.create(bnf_code='0401020K0',
                                                chem_name='test')
        self.practice = Practice.objects.create(code='Y03375', name='test')
        self.pct = PCT.objects.create(code='5D7', name='test')
        Chemical.objects.create(bnf_code='0410030C0', chem_name='test')
        Practice.objects.create(code='Y00135', name='test')
        p = Practice.objects.create(code='Y01957', name='test')
        Section.objects.create(bnf_id='0401', bnf_chapter=4, is_current=False)
        Section.objects.create(bnf_id='0909', bnf_chapter=9, is_current=False)
        Presentation.objects.create(bnf_code='0401020K0AAAHAH',
                                    is_current=False)
        Presentation.objects.create(bnf_code='0401020K0AAAIAZ',
                                    is_current=False)
        PracticeStatistics.objects.create(practice=p,
                                          date='2001-01-01',
                                          male_0_4=1,
                                          female_0_4=1,
                                          male_5_14=1,
                                          female_5_14=1,
                                          male_15_24=1,
                                          female_15_24=1,
                                          male_25_34=1,
                                          female_25_34=1,
                                          male_35_44=1,
                                          female_35_44=1,
                                          male_45_54=1,
                                          female_45_54=1,
                                          male_55_64=1,
                                          female_55_64=1,
                                          male_65_74=1,
                                          female_65_74=1,
                                          male_75_plus=1,
                                          female_75_plus=1,
                                          total_list_size=28,
                                          astro_pu_cost=205.7,
                                          astro_pu_items=400.2)

        test_file = 'frontend/tests/fixtures/commands/'
        test_file += 'T201304PDPI+BNFT_formatted.CSV'
        self.new_opts = {'filename': test_file}
        db_name = 'test_' + utils.get_env_setting('DB_NAME')
        self.env = patch.dict('os.environ', {'DB_NAME': db_name})
        with self.env:
            call_command('import_hscic_prescribing', **self.new_opts)
    def setUp(self):
        self.chemical = Chemical.objects.create(
            bnf_code='0401020K0', chem_name='test')
        self.practice = Practice.objects.create(code='Y03375', name='test')
        self.pct = PCT.objects.create(code='5D7', name='test')
        self.sha = SHA.objects.create(code='Q30', name='test')
        Chemical.objects.create(bnf_code='0410030C0', chem_name='test')
        Practice.objects.create(code='Y00135', name='test')
        Practice.objects.create(code='Y01957', name='test')

        test_file = 'frontend/tests/fixtures/commands/'
        test_file += 'T201304PDPI+BNFT_formatted.CSV'
        self.new_opts = {
            'filename': test_file
        }
        db_name = 'test_' + utils.get_env_setting('DB_NAME')
        self.env = patch.dict(
            'os.environ', {'DB_NAME': db_name})
        with self.env:
            call_command('import_hscic_prescribing', **self.new_opts)
    def handle(self, *args, **options):
        self.IS_VERBOSE = False
        if options['verbosity'] > 1:
            self.IS_VERBOSE = True

        BASE_URL = 'http://api.opencagedata.com/geocode/v1/json?'
        BASE_URL += '&key=%s' % utils.get_env_setting('OPENCAGEDATA_KEY')
        practices = Practice.objects.all().reverse()
        for practice in practices:
            if practice.location:
                continue
            geom = self.fetch_from_opencage(BASE_URL,
                                            practice.address_pretty())
            if not geom:
                address = practice.address_pretty_minus_firstline()
                geom = self.fetch_from_opencage(BASE_URL, address)
            if geom:
                lat = geom['lat']
                lng = geom['lng']
                practice.location = 'POINT(%s %s)' % (lng, lat)
                practice.save()
Exemplo n.º 29
0
 def setUp(self):
     if 'SKIP_BQ_LOAD' not in os.environ:
         # Create local test data from fixtures, then upload this to a
         # test project in bigquery
         call_command('loaddata',
                      'frontend/tests/fixtures/ccgs.json',
                      verbosity=0)
         call_command('loaddata',
                      'frontend/tests/fixtures/practices.json',
                      verbosity=0)
         call_command('loaddata',
                      'frontend/tests/fixtures/practice_listsizes.json',
                      verbosity=0)
         fixtures_base = 'frontend/tests/fixtures/commands/'
         prescribing_fixture = (fixtures_base +
                                'prescribing_bigquery_views_fixture.csv')
         db_name = 'test_' + utils.get_env_setting('DB_NAME')
         env = patch.dict(
             'os.environ', {'DB_NAME': db_name})
         with env:
             # We patch the environment as this is how the
             # ebmdatalab/bigquery library selects a database
             bigquery.load_prescribing_data_from_file(
                 'test_hscic',
                 'prescribing',
                 prescribing_fixture)
             bigquery.load_ccgs_from_pg('test_hscic')
             bigquery.load_statistics_from_pg('test_hscic')
     ImportLog.objects.create(
         category='prescribing', current_at='2015-10-01')
     # Create view tables and indexes
     with open(
             'frontend/management/commands/replace_matviews.sql', 'r') as f:
         with connection.cursor() as c:
             c.execute(f.read())
     args = []
     opts = {
         'dataset': 'test_hscic'
     }
     call_command('create_views', *args, **opts)
Exemplo n.º 30
0
ALLOWED_HOSTS = ['localhost', 'openprescribing.net', 'openprescriptions.net']
########## END SITE CONFIGURATION


########## EMAIL CONFIGURATION
# See: https://docs.djangoproject.com/en/dev/ref/settings/#email-backend
EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'
########## END EMAIL CONFIGURATION


########## DATABASE CONFIGURATION
# See: https://docs.djangoproject.com/en/dev/ref/settings/#databases
DATABASES = {
    'default': {
        'ENGINE': 'django.contrib.gis.db.backends.postgis',
        'NAME': utils.get_env_setting('DB_NAME'),
        'USER': utils.get_env_setting('DB_USER'),
        'PASSWORD': utils.get_env_setting('DB_PASS'),
        'HOST': '127.0.0.1'
    }
}
########## END DATABASE CONFIGURATION


########## CACHE CONFIGURATION
# See: https://docs.djangoproject.com/en/dev/ref/settings/#caches
CACHES = {
    'default': {
        'BACKEND': 'django.core.cache.backends.locmem.LocMemCache',
    }
}
Exemplo n.º 31
0
# See: https://docs.djangoproject.com/en/dev/ref/settings/#email-subject-prefix
EMAIL_SUBJECT_PREFIX = '[%s] ' % SITE_NAME

# See: https://docs.djangoproject.com/en/dev/ref/settings/#email-use-tls
EMAIL_USE_TLS = True

# See: https://docs.djangoproject.com/en/dev/ref/settings/#server-email
SERVER_EMAIL = EMAIL_HOST_USER
########## END EMAIL CONFIGURATION

########## DATABASE CONFIGURATION
DATABASES = {
    'default': {
        'ENGINE': 'django.contrib.gis.db.backends.postgis',
        'NAME': utils.get_env_setting('DB_NAME_STAGING', ''),
        'USER': utils.get_env_setting('DB_USER_STAGING', ''),
        'PASSWORD': utils.get_env_setting('DB_PASS_STAGING', ''),
        'HOST': '127.0.0.1'
    }
}
########## END DATABASE CONFIGURATION

########## CACHE CONFIGURATION
# See: https://docs.djangoproject.com/en/dev/ref/settings/#caches
CACHES = {
    'default': {
        'BACKEND': 'django.core.cache.backends.locmem.LocMemCache',
    }
}
########## END CACHE CONFIGURATION
Exemplo n.º 32
0
# See: https://docs.djangoproject.com/en/dev/ref/settings/#static-url
STATIC_URL = '/static/'

# See: https://docs.djangoproject.com/en/dev/ref/contrib/staticfiles/#std:setting-STATICFILES_DIRS
STATICFILES_DIRS = (normpath(join(SITE_ROOT, 'static')), )

# See: https://docs.djangoproject.com/en/dev/ref/contrib/staticfiles/#staticfiles-finders
STATICFILES_FINDERS = (
    'django.contrib.staticfiles.finders.FileSystemFinder',
    'django.contrib.staticfiles.finders.AppDirectoriesFinder',
)
########## END STATIC FILE CONFIGURATION

########## SECRET CONFIGURATION
# See: https://docs.djangoproject.com/en/dev/ref/settings/#secret-key
SECRET_KEY = utils.get_env_setting('SECRET_KEY')
########## END SECRET CONFIGURATION

########## SITE CONFIGURATION
# Hosts/domain names that are valid for this site
# See https://docs.djangoproject.com/en/1.5/ref/settings/#allowed-hosts
ALLOWED_HOSTS = []
########## END SITE CONFIGURATION

########## FIXTURE CONFIGURATION
# See: https://docs.djangoproject.com/en/dev/ref/settings/#std:setting-FIXTURE_DIRS
FIXTURE_DIRS = (normpath(join(SITE_ROOT, 'fixtures')), )
########## END FIXTURE CONFIGURATION

########## TEMPLATE CONFIGURATION
TEMPLATES = [
Exemplo n.º 33
0
https://docs.djangoproject.com/en/1.10/ref/settings/
"""

import os
import socket
from common import utils

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(
    os.path.dirname(os.path.dirname(os.path.abspath(__file__))))

# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/1.10/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = utils.get_env_setting("SECRET_KEY")

# Application definition

INSTALLED_APPS = [
    "django.contrib.admin",
    "django.contrib.auth",
    "django.contrib.contenttypes",
    "django.contrib.sessions",
    "django.contrib.messages",
    "django.contrib.staticfiles",
    "anymail",
    "nimodipine",
]

MIDDLEWARE = [
Exemplo n.º 34
0
    "openprescribing.net",
    "deploy.openprescribing.net",
    "openprescriptions.net",
]
# END HOST CONFIGURATION

# See: https://docs.djangoproject.com/en/dev/ref/settings/#email-subject-prefix
EMAIL_SUBJECT_PREFIX = "[%s] " % SITE_NAME

# END EMAIL CONFIGURATION

# DATABASE CONFIGURATION
DATABASES = {
    "default": {
        "ENGINE": "django.contrib.gis.db.backends.postgis",
        "NAME": utils.get_env_setting("DB_NAME"),
        "USER": utils.get_env_setting("DB_USER"),
        "PASSWORD": utils.get_env_setting("DB_PASS"),
        "HOST": utils.get_env_setting("DB_HOST", "127.0.0.1"),
        "CONN_MAX_AGE": 0,
    },
    "old": {
        "ENGINE": "django.contrib.gis.db.backends.postgis",
        "NAME": utils.get_env_setting("DB_NAME"),
        "USER": utils.get_env_setting("DB_USER"),
        "PASSWORD": utils.get_env_setting("DB_PASS"),
        "HOST": utils.get_env_setting("DB_HOST", "138.68.140.164"),
    },
}
# END DATABASE CONFIGURATION
Exemplo n.º 35
0
# https://docs.djangoproject.com/en/dev/ref/contrib/staticfiles/#std:setting-STATICFILES_DIRS
STATICFILES_DIRS = (normpath(join(APPS_ROOT, 'static')), )

# See:
# https://docs.djangoproject.com/en/dev/ref/contrib/staticfiles/#staticfiles-finders
STATICFILES_FINDERS = (
    'django.contrib.staticfiles.finders.FileSystemFinder',
    'django.contrib.staticfiles.finders.AppDirectoriesFinder',
)

STATICFILES_STORAGE = 'django.contrib.staticfiles.storage.ManifestStaticFilesStorage'
# END STATIC FILE CONFIGURATION

# SECRET CONFIGURATION
# See: https://docs.djangoproject.com/en/dev/ref/settings/#secret-key
SECRET_KEY = utils.get_env_setting('SECRET_KEY')
# END SECRET CONFIGURATION

# SITE CONFIGURATION
# Hosts/domain names that are valid for this site
# See https://docs.djangoproject.com/en/1.5/ref/settings/#allowed-hosts
ALLOWED_HOSTS = []
# END SITE CONFIGURATION

# FIXTURE CONFIGURATION
# See:
# https://docs.djangoproject.com/en/dev/ref/settings/#std:setting-FIXTURE_DIRS
FIXTURE_DIRS = (normpath(join(APPS_ROOT, 'frontend', 'tests', 'fixtures')), )
# END FIXTURE CONFIGURATION

# TEMPLATE CONFIGURATION
Exemplo n.º 36
0
# https://docs.djangoproject.com/en/dev/ref/contrib/staticfiles/#std:setting-STATICFILES_DIRS
STATICFILES_DIRS = (normpath(join(APPS_ROOT, "static")), )

# See:
# https://docs.djangoproject.com/en/dev/ref/contrib/staticfiles/#staticfiles-finders
STATICFILES_FINDERS = (
    "django.contrib.staticfiles.finders.FileSystemFinder",
    "django.contrib.staticfiles.finders.AppDirectoriesFinder",
)

STATICFILES_STORAGE = "django.contrib.staticfiles.storage.ManifestStaticFilesStorage"
# END STATIC FILE CONFIGURATION

# SECRET CONFIGURATION
# See: https://docs.djangoproject.com/en/dev/ref/settings/#secret-key
SECRET_KEY = utils.get_env_setting("SECRET_KEY")
# END SECRET CONFIGURATION

# SITE CONFIGURATION
# Hosts/domain names that are valid for this site
# See https://docs.djangoproject.com/en/1.5/ref/settings/#allowed-hosts
ALLOWED_HOSTS = []
# END SITE CONFIGURATION

# FIXTURE CONFIGURATION
# See:
# https://docs.djangoproject.com/en/dev/ref/settings/#std:setting-FIXTURE_DIRS
FIXTURE_DIRS = (normpath(join(APPS_ROOT, "frontend", "tests", "fixtures")), )
# END FIXTURE CONFIGURATION

# TEMPLATE CONFIGURATION
Exemplo n.º 37
0
# See: https://docs.djangoproject.com/en/dev/ref/settings/#email-subject-prefix
EMAIL_SUBJECT_PREFIX = '[%s] ' % SITE_NAME

# See: https://docs.djangoproject.com/en/dev/ref/settings/#email-use-tls
EMAIL_USE_TLS = True

# See: https://docs.djangoproject.com/en/dev/ref/settings/#server-email
SERVER_EMAIL = EMAIL_HOST_USER
########## END EMAIL CONFIGURATION

########## DATABASE CONFIGURATION
DATABASES = {
    'default': {
        'ENGINE': 'django.contrib.gis.db.backends.postgis',
        'NAME': utils.get_env_setting('DB_NAME_STAGING', ''),
        'USER': utils.get_env_setting('DB_USER_STAGING', ''),
        'PASSWORD': utils.get_env_setting('DB_PASS_STAGING', ''),
        'HOST': '127.0.0.1'
    }
}
########## END DATABASE CONFIGURATION


########## CACHE CONFIGURATION
# See: https://docs.djangoproject.com/en/dev/ref/settings/#caches
CACHES = {
    'default': {
        'BACKEND': 'django.core.cache.backends.locmem.LocMemCache',
    }
}
Exemplo n.º 38
0
ALLOWED_HOSTS = ['localhost', 'openprescribing.net', 'openprescriptions.net']
# END SITE CONFIGURATION

# EMAIL CONFIGURATION
# See: https://docs.djangoproject.com/en/dev/ref/settings/#email-backend
# EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'
# EMAIL_BACKEND = "anymail.backends.mailgun.MailgunBackend"
EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'
# END EMAIL CONFIGURATION

# DATABASE CONFIGURATION
# See: https://docs.djangoproject.com/en/dev/ref/settings/#databases
DATABASES = {
    'default': {
        'ENGINE': 'django.contrib.gis.db.backends.postgis',
        'NAME': utils.get_env_setting('DB_NAME'),
        'USER': utils.get_env_setting('DB_USER'),
        'PASSWORD': utils.get_env_setting('DB_PASS'),
        'HOST': utils.get_env_setting('DB_HOST', '127.0.0.1')
    }
}
# END DATABASE CONFIGURATION

# CACHE CONFIGURATION
# See: https://docs.djangoproject.com/en/dev/ref/settings/#caches
CACHES = {
    'default': {
        'BACKEND': 'django.core.cache.backends.locmem.LocMemCache',
    }
}
# END CACHE CONFIGURATION
Exemplo n.º 39
0

# EMAIL CONFIGURATION
# See: https://docs.djangoproject.com/en/dev/ref/settings/#email-backend
# EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'
# EMAIL_BACKEND = "anymail.backends.mailgun.MailgunBackend"
EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'
# END EMAIL CONFIGURATION


# DATABASE CONFIGURATION
# See: https://docs.djangoproject.com/en/dev/ref/settings/#databases
DATABASES = {
    'default': {
        'ENGINE': 'django.contrib.gis.db.backends.postgis',
        'NAME': utils.get_env_setting('DB_NAME'),
        'USER': utils.get_env_setting('DB_USER'),
        'PASSWORD': utils.get_env_setting('DB_PASS'),
        'HOST': utils.get_env_setting('DB_HOST', '127.0.0.1')
    }
}
# END DATABASE CONFIGURATION


# CACHE CONFIGURATION
# See: https://docs.djangoproject.com/en/dev/ref/settings/#caches
CACHES = {
    'default': {
        'BACKEND': 'django.core.cache.backends.locmem.LocMemCache',
    }
}
    def test_import_create_matviews(self):
        db_name = 'test_' + utils.get_env_setting('DB_NAME')
        db_user = utils.get_env_setting('DB_USER')
        db_pass = utils.get_env_setting('DB_PASS')
        db_host = utils.get_env_setting('DB_HOST')
        self.conn = psycopg2.connect(database=db_name, user=db_user,
                                     password=db_pass, host=db_host)
        with self.conn.cursor() as c:

            cmd = 'SELECT * FROM vw__practice_summary '
            cmd += 'ORDER BY processing_date, practice_id'
            c.execute(cmd)
            results = c.fetchall()
            self.assertEqual(len(results), 10)
            self.assertEqual(results[9][1], 'P87629')
            self.assertEqual(results[9][2], 55)
            self.assertEqual(results[9][3], 64.26)
            self.assertEqual(results[9][4], 2599)

            cmd = 'SELECT * FROM vw__presentation_summary '
            cmd += 'ORDER BY processing_date'
            c.execute(cmd)
            results = c.fetchall()
            self.assertEqual(len(results), 11)
            self.assertEqual(results[9][1], '0204000I0BCAAAB')
            self.assertEqual(results[9][2], 29)
            self.assertEqual(results[9][3], 32.26)
            self.assertEqual(results[9][4], 2350)

            cmd = 'SELECT * FROM vw__presentation_summary_by_ccg '
            cmd += 'ORDER BY processing_date, presentation_code'
            c.execute(cmd)
            results = c.fetchall()
            self.assertEqual(len(results), 12)
            self.assertEqual(results[9][1], '03V')
            self.assertEqual(results[9][2], '0202010B0AAABAB')
            self.assertEqual(results[9][3], 62)
            self.assertEqual(results[9][4], 54.26)
            self.assertEqual(results[9][5], 2788)

            cmd = 'SELECT * FROM vw__chemical_summary_by_ccg '
            cmd += 'ORDER BY processing_date, chemical_id'
            c.execute(cmd)
            results = c.fetchall()
            self.assertEqual(len(results), 11)
            self.assertEqual(results[10][1], '03V')
            self.assertEqual(results[10][2], '0204000I0')
            self.assertEqual(results[10][3], 33)
            self.assertEqual(results[10][4], 36.28)
            self.assertEqual(results[10][5], 2354)

            cmd = 'SELECT * FROM vw__chemical_summary_by_practice '
            cmd += 'ORDER BY processing_date, practice_id'
            c.execute(cmd)
            results = c.fetchall()
            self.assertEqual(len(results), 13)
            self.assertEqual(results[10][1], 'K83059')
            self.assertEqual(results[10][2], '0204000I0')
            self.assertEqual(results[10][3], 16)
            self.assertEqual(results[10][4], 14.15)
            self.assertEqual(results[10][5], 1154)

            cmd = 'SELECT * FROM vw__ccgstatistics '
            cmd += 'ORDER BY date, pct_id'
            c.execute(cmd)
            results = c.fetchall()
            self.assertEqual(len(results), 3)
            self.assertEqual(results[0][1], '03Q')
            self.assertEqual(results[0][2], 'NHS Vale of York')
            self.assertEqual(results[0][3], 25)
            self.assertEqual(results[0][4], 819.2)
            self.assertEqual(results[0][5], 489.7)
            self.assertEqual(results[0][-1]['oral_antibacterials_item'], 10)

        self.conn.close()
Exemplo n.º 41
0
# See: https://docs.djangoproject.com/en/dev/ref/settings/#debug
DEBUG = False  # Not so safe to set to True as staging is not behind a password
TEMPLATES[0]['OPTIONS']['debug'] = DEBUG
# END DEBUG CONFIGURATION

# HOST CONFIGURATION
# See:
# https://docs.djangoproject.com/en/1.5/releases/1.5/#allowed-hosts-required-in-production
ALLOWED_HOSTS = ['staging.openprescribing.net']
# END HOST CONFIGURATION

# DATABASE CONFIGURATION
DATABASES = {
    'default': {
        'ENGINE': 'django.contrib.gis.db.backends.postgis',
        'NAME': utils.get_env_setting('STAGING_DB_NAME', ''),
        'USER': utils.get_env_setting('DB_USER', ''),
        'PASSWORD': utils.get_env_setting('DB_PASS', ''),
        'HOST': utils.get_env_setting('DB_HOST', '127.0.0.1')
    }
}
# END DATABASE CONFIGURATION

ANYMAIL["MAILGUN_SENDER_DOMAIN"] = "staging.openprescribing.net"
SUPPORT_FROM_EMAIL = '*****@*****.**'
DEFAULT_FROM_EMAIL = 'OpenPrescribing <{}>'.format(SUPPORT_FROM_EMAIL)

# LOGGING CONFIGURATION
# See: https://docs.djangoproject.com/en/dev/ref/settings/#logging
LOGGING = {
    'version': 1,
Exemplo n.º 42
0
# Hosts/domain names that are valid for this site
# See https://docs.djangoproject.com/en/1.5/ref/settings/#allowed-hosts
ALLOWED_HOSTS = ['localhost', 'openprescribing.net', 'openprescriptions.net']
########## END SITE CONFIGURATION

########## EMAIL CONFIGURATION
# See: https://docs.djangoproject.com/en/dev/ref/settings/#email-backend
EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'
########## END EMAIL CONFIGURATION

########## DATABASE CONFIGURATION
# See: https://docs.djangoproject.com/en/dev/ref/settings/#databases
DATABASES = {
    'default': {
        'ENGINE': 'django.contrib.gis.db.backends.postgis',
        'NAME': utils.get_env_setting('DB_NAME'),
        'USER': utils.get_env_setting('DB_USER'),
        'PASSWORD': utils.get_env_setting('DB_PASS'),
        'HOST': utils.get_env_setting('DB_HOST', '127.0.0.1')
    }
}
########## END DATABASE CONFIGURATION

########## CACHE CONFIGURATION
# See: https://docs.djangoproject.com/en/dev/ref/settings/#caches
CACHES = {
    'default': {
        'BACKEND': 'django.core.cache.backends.locmem.LocMemCache',
    }
}
########## END CACHE CONFIGURATION
Exemplo n.º 43
0
ALLOWED_HOSTS = ['localhost', 'openprescribing.net', 'openprescriptions.net']
########## END SITE CONFIGURATION


########## EMAIL CONFIGURATION
# See: https://docs.djangoproject.com/en/dev/ref/settings/#email-backend
EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'
########## END EMAIL CONFIGURATION


########## DATABASE CONFIGURATION
# See: https://docs.djangoproject.com/en/dev/ref/settings/#databases
DATABASES = {
    'default': {
        'ENGINE': 'django.contrib.gis.db.backends.postgis',
        'NAME': utils.get_env_setting('DB_NAME'),
        'USER': utils.get_env_setting('DB_USER'),
        'PASSWORD': utils.get_env_setting('DB_PASS'),
        'HOST': utils.get_env_setting('DB_HOST', '127.0.0.1')
    }
}
########## END DATABASE CONFIGURATION


########## CACHE CONFIGURATION
# See: https://docs.djangoproject.com/en/dev/ref/settings/#caches
CACHES = {
    'default': {
        'BACKEND': 'django.core.cache.backends.locmem.LocMemCache',
    }
}
Exemplo n.º 44
0
STATICFILES_DIRS = (normpath(join(APPS_ROOT, "static")),)

# See:
# https://docs.djangoproject.com/en/dev/ref/contrib/staticfiles/#staticfiles-finders
STATICFILES_FINDERS = (
    "django.contrib.staticfiles.finders.FileSystemFinder",
    "django.contrib.staticfiles.finders.AppDirectoriesFinder",
)

STATICFILES_STORAGE = "django.contrib.staticfiles.storage.ManifestStaticFilesStorage"
# END STATIC FILE CONFIGURATION


# SECRET CONFIGURATION
# See: https://docs.djangoproject.com/en/dev/ref/settings/#secret-key
SECRET_KEY = utils.get_env_setting("SECRET_KEY")
# END SECRET CONFIGURATION

# SITE CONFIGURATION
# Hosts/domain names that are valid for this site
# See https://docs.djangoproject.com/en/1.5/ref/settings/#allowed-hosts
ALLOWED_HOSTS = []
# END SITE CONFIGURATION


# FIXTURE CONFIGURATION
# See:
# https://docs.djangoproject.com/en/dev/ref/settings/#std:setting-FIXTURE_DIRS
FIXTURE_DIRS = (normpath(join(APPS_ROOT, "frontend", "tests", "fixtures")),)
# END FIXTURE CONFIGURATION
Exemplo n.º 45
0
 def test_falsey_default(self):
     from common.utils import get_env_setting
     self.assertEqual(get_env_setting('FROB123', ''), '')
    def test_import_create_matviews(self):
        db_name = "test_" + utils.get_env_setting("DB_NAME")
        db_user = utils.get_env_setting("DB_USER")
        db_pass = utils.get_env_setting("DB_PASS")
        self.conn = psycopg2.connect(database=db_name, user=db_user, password=db_pass)
        with self.conn.cursor() as c:

            cmd = "SELECT * FROM vw__practice_summary "
            cmd += "ORDER BY processing_date, practice_id"
            c.execute(cmd)
            results = c.fetchall()
            self.assertEqual(len(results), 10)
            self.assertEqual(results[9][1], "P87629")
            self.assertEqual(results[9][2], 55)
            self.assertEqual(results[9][3], 64.26)
            self.assertEqual(results[9][4], 2599)

            cmd = "SELECT * FROM vw__presentation_summary "
            cmd += "ORDER BY processing_date"
            c.execute(cmd)
            results = c.fetchall()
            self.assertEqual(len(results), 11)
            self.assertEqual(results[9][1], "0204000I0BCAAAB")
            self.assertEqual(results[9][2], 29)
            self.assertEqual(results[9][3], 32.26)
            self.assertEqual(results[9][4], 2350)

            cmd = "SELECT * FROM vw__presentation_summary_by_ccg "
            cmd += "ORDER BY processing_date, presentation_code"
            c.execute(cmd)
            results = c.fetchall()
            self.assertEqual(len(results), 12)
            self.assertEqual(results[9][1], "03V")
            self.assertEqual(results[9][2], "0202010B0AAABAB")
            self.assertEqual(results[9][3], 62)
            self.assertEqual(results[9][4], 54.26)
            self.assertEqual(results[9][5], 2788)

            cmd = "SELECT * FROM vw__chemical_summary_by_ccg "
            cmd += "ORDER BY processing_date, chemical_id"
            c.execute(cmd)
            results = c.fetchall()
            self.assertEqual(len(results), 11)
            self.assertEqual(results[10][1], "03V")
            self.assertEqual(results[10][2], "0204000I0")
            self.assertEqual(results[10][3], 33)
            self.assertEqual(results[10][4], 36.28)
            self.assertEqual(results[10][5], 2354)

            cmd = "SELECT * FROM vw__chemical_summary_by_practice "
            cmd += "ORDER BY processing_date, practice_id"
            c.execute(cmd)
            results = c.fetchall()
            self.assertEqual(len(results), 13)
            self.assertEqual(results[10][1], "K83059")
            self.assertEqual(results[10][2], "0204000I0")
            self.assertEqual(results[10][3], 16)
            self.assertEqual(results[10][4], 14.15)
            self.assertEqual(results[10][5], 1154)

            cmd = "SELECT * FROM vw__ccgstatistics "
            cmd += "ORDER BY date, pct_id"
            c.execute(cmd)
            results = c.fetchall()
            self.assertEqual(len(results), 3)
            self.assertEqual(results[0][1], "03Q")
            self.assertEqual(results[0][2], "NHS Vale of York")
            self.assertEqual(results[0][3], 25)
            self.assertEqual(results[0][4], 819.2)
            self.assertEqual(results[0][5], 489.7)
            self.assertEqual(results[0][-1]["oral_antibacterials_item"], 10)

        self.conn.close()
Exemplo n.º 47
0
# Hosts/domain names that are valid for this site
# See https://docs.djangoproject.com/en/1.5/ref/settings/#allowed-hosts
ALLOWED_HOSTS = ['localhost', 'openprescribing.net', 'openprescriptions.net']
########## END SITE CONFIGURATION

########## EMAIL CONFIGURATION
# See: https://docs.djangoproject.com/en/dev/ref/settings/#email-backend
EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'
########## END EMAIL CONFIGURATION

########## DATABASE CONFIGURATION
# See: https://docs.djangoproject.com/en/dev/ref/settings/#databases
DATABASES = {
    'default': {
        'ENGINE': 'django.contrib.gis.db.backends.postgis',
        'NAME': utils.get_env_setting('DB_NAME'),
        'USER': utils.get_env_setting('DB_USER'),
        'PASSWORD': utils.get_env_setting('DB_PASS'),
        'HOST': '127.0.0.1'
    }
}
########## END DATABASE CONFIGURATION

########## CACHE CONFIGURATION
# See: https://docs.djangoproject.com/en/dev/ref/settings/#caches
CACHES = {
    'default': {
        'BACKEND': 'django.core.cache.backends.locmem.LocMemCache',
    }
}
########## END CACHE CONFIGURATION
Exemplo n.º 48
0
STATICFILES_DIRS = (
    normpath(join(SITE_ROOT, 'static')),
)

# See:
# https://docs.djangoproject.com/en/dev/ref/contrib/staticfiles/#staticfiles-finders
STATICFILES_FINDERS = (
    'django.contrib.staticfiles.finders.FileSystemFinder',
    'django.contrib.staticfiles.finders.AppDirectoriesFinder',
)
# END STATIC FILE CONFIGURATION


# SECRET CONFIGURATION
# See: https://docs.djangoproject.com/en/dev/ref/settings/#secret-key
SECRET_KEY = utils.get_env_setting('SECRET_KEY')
# END SECRET CONFIGURATION

# SITE CONFIGURATION
# Hosts/domain names that are valid for this site
# See https://docs.djangoproject.com/en/1.5/ref/settings/#allowed-hosts
ALLOWED_HOSTS = []
# END SITE CONFIGURATION


# FIXTURE CONFIGURATION
# See:
# https://docs.djangoproject.com/en/dev/ref/settings/#std:setting-FIXTURE_DIRS
FIXTURE_DIRS = (
    normpath(join(SITE_ROOT, 'frontend', 'tests', 'fixtures')),
)
Exemplo n.º 49
0
# See:
# https://docs.djangoproject.com/en/dev/ref/contrib/staticfiles/#std:setting-STATICFILES_DIRS
STATICFILES_DIRS = (normpath(join(SITE_ROOT, "static")),)

# See:
# https://docs.djangoproject.com/en/dev/ref/contrib/staticfiles/#staticfiles-finders
STATICFILES_FINDERS = (
    "django.contrib.staticfiles.finders.FileSystemFinder",
    "django.contrib.staticfiles.finders.AppDirectoriesFinder",
)
# END STATIC FILE CONFIGURATION


# SECRET CONFIGURATION
# See: https://docs.djangoproject.com/en/dev/ref/settings/#secret-key
SECRET_KEY = utils.get_env_setting("SECRET_KEY")
# END SECRET CONFIGURATION

# SITE CONFIGURATION
# Hosts/domain names that are valid for this site
# See https://docs.djangoproject.com/en/1.5/ref/settings/#allowed-hosts
ALLOWED_HOSTS = []
# END SITE CONFIGURATION


# FIXTURE CONFIGURATION
# See:
# https://docs.djangoproject.com/en/dev/ref/settings/#std:setting-FIXTURE_DIRS
FIXTURE_DIRS = (normpath(join(SITE_ROOT, "frontend", "tests", "fixtures")),)
# END FIXTURE CONFIGURATION
Exemplo n.º 50
0
# See: https://docs.djangoproject.com/en/dev/ref/settings/#email-subject-prefix
EMAIL_SUBJECT_PREFIX = '[%s] ' % SITE_NAME

# See: https://docs.djangoproject.com/en/dev/ref/settings/#email-use-tls
EMAIL_USE_TLS = True

# See: https://docs.djangoproject.com/en/dev/ref/settings/#server-email
SERVER_EMAIL = EMAIL_HOST_USER
########## END EMAIL CONFIGURATION

########## DATABASE CONFIGURATION
DATABASES = {
    'default': {
        'ENGINE': 'django.contrib.gis.db.backends.postgis',
        'NAME': utils.get_env_setting('DB_NAME_STAGING', ''),
        'USER': utils.get_env_setting('DB_USER_STAGING', ''),
        'PASSWORD': utils.get_env_setting('DB_PASS_STAGING', ''),
        'HOST': utils.get_env_setting('DB_HOST', '127.0.0.1')
    }
}
########## END DATABASE CONFIGURATION

########## CACHE CONFIGURATION
# See: https://docs.djangoproject.com/en/dev/ref/settings/#caches
CACHES = {
    'default': {
        'BACKEND': 'django.core.cache.backends.locmem.LocMemCache',
    }
}
########## END CACHE CONFIGURATION
Exemplo n.º 51
0
# See: https://docs.djangoproject.com/en/dev/ref/contrib/staticfiles/#std:setting-STATICFILES_DIRS
STATICFILES_DIRS = (
    normpath(join(SITE_ROOT, 'static')),
)

# See: https://docs.djangoproject.com/en/dev/ref/contrib/staticfiles/#staticfiles-finders
STATICFILES_FINDERS = (
    'django.contrib.staticfiles.finders.FileSystemFinder',
    'django.contrib.staticfiles.finders.AppDirectoriesFinder',
)
########## END STATIC FILE CONFIGURATION


########## SECRET CONFIGURATION
# See: https://docs.djangoproject.com/en/dev/ref/settings/#secret-key
SECRET_KEY = utils.get_env_setting('SECRET_KEY')
########## END SECRET CONFIGURATION

########## SITE CONFIGURATION
# Hosts/domain names that are valid for this site
# See https://docs.djangoproject.com/en/1.5/ref/settings/#allowed-hosts
ALLOWED_HOSTS = []
########## END SITE CONFIGURATION


########## FIXTURE CONFIGURATION
# See: https://docs.djangoproject.com/en/dev/ref/settings/#std:setting-FIXTURE_DIRS
FIXTURE_DIRS = (
    normpath(join(SITE_ROOT, 'fixtures')),
)
########## END FIXTURE CONFIGURATION