Skip to content

Measure queries

Peter Inglesby edited this page Aug 2, 2018 · 1 revision

Here is a table of the kinds of queries that we make when calculating measures.

count columns from

Analyse-style queries against prescribing

50

SUM(items)

{hscic}.normalised_prescribing_standard

18

SUM(actual_cost)

{hscic}.normalised_prescribing_standard

16

SUM(quantity)

{hscic}.normalised_prescribing_standard

1

SUM(denominator)/17

{measures}.practice_data_all_low_priority

1

SUM(numerator)

{measures}.practice_data_all_low_priority

Analyse-style queries against practice statistics

24

SUM(total_list_size / 1000.0)

{hscic}.practice_statistics

1

CAST(JSON_EXTRACT(MAX(star_pu), '$.oral_antibacterials_item') AS FLOAT64)

{hscic}.practice_statistics

Custom weightings

1

SUM(lyrica_mg)

{measures}.pregabalin_total_mg

1

SUM(total_ome)

{measures}.opioid_total_ome

1

SUM(p.quantity * r.percent_of_adq)

{hscic}.normalised_prescribing_standard p LEFT JOIN {hscic}.presentation r ON p.bnf_code = r.bnf_code

1

SUM(quantity/ CASE WHEN bnf_name LIKE '%Oral%' THEN 10 WHEN bnf_name LIKE '%Liq%' THEN 10 WHEN RTRIM(bnf_name) LIKE '%10mg' THEN 2 WHEN RTRIM(bnf_name) LIKE '%40mg' THEN 0.5 ELSE 1 END)

{hscic}.normalised_prescribing_standard

Other

1

(max(female_35_44) + max(female_45_54) + max(female_55_64) + max(female_65_74)) / 1000.0

{hscic}.practice_statistics

Generated with the following (and a little bit of tidying up):

nc = Counter(
        (m.numerator_columns.replace('AS numerator,', '').strip(), m.numerator_from.strip())
        for m in Measure.objects.all()
    )
dc = Counter(
        (m.denominator_columns.replace('AS denominator,', '').strip(), m.denominator_from.strip())
        for m in Measure.objects.all()
    )

for (columns, from_clause), count in (nc + dc).most_common():
    print '|', count, '|', columns, '|', from_clause