Skip to content

API calls for the analyse page

Peter Inglesby edited this page Oct 31, 2018 · 6 revisions

Here's a list of the API calls that get made when showing different charts on the analyse page:

And here's a list of the charts that make each API call:

This was generated with the following:

import subprocess
from collections import defaultdict

numerators = [
    ('cerazette', 'numIds=0703021Q0BB'),
]

denominators = [
    ('nothing', 'denom=nothing'),
    ('desogestrel', 'denomIds=0703021Q0'),
    ('total list size', 'denom=total_list_size'),
    ('STAR-PUs', 'denom=star_pu.oral_antibacterials_item'),
]

highlights = [
    ('nothing', 'org=CCG'),
    ('a CCG', 'org=CCG&orgIds=11M'),
    ('practices in a CCG', 'org=practice&orgIds=11M'),
    ('one practice in a CCG', 'org=practice&orgIds=L84613'),
]

chart_to_api_calls = defaultdict(list)
api_call_to_charts = defaultdict(list)

for numerator in numerators:
    for denominator in denominators:
        for highlight in highlights:
            title = f'{numerator[0]} vs {denominator[0]}, highlighting {highlight[0]}'
            url = f'https://openprescribing.net/analyse/#{highlight[1]}&{numerator[1]}&{denominator[1]}&selectedTab=summary'
            chart = (title, url)

            output = subprocess.check_output(['phantomjs', 'show-api-calls.js', url])

            for line in output.decode('utf8').splitlines() :
                if 'https://openprescribing.net/api/1.0/' not in line:
                    continue
                assert '/?format=json&' in line
                chart_to_api_calls[chart].append(line)
                api_call_to_charts[line].append(chart)


for chart, api_calls in chart_to_api_calls.items():
    title, url = chart
    print(f'* [{title}]({url})')

    for api_call in api_calls:
        view_name = api_call.split('/')[-2]
        qs = api_call.split('/?format=json&')[-1]
        print(f'   * [{view_name}]({api_call})')
        for kv in sorted(qs.split('&')):
            k, v = kv.split('=')
            print(f'     * {k}: {v}')

print()
print()
print()

for api_call, charts in sorted(api_call_to_charts.items()):
    path = api_call.split('1.0/')[1]
    print(f'* [{path}]({api_call})')
    for chart in charts:
        title, url = chart
        print(f'  * [{title}]({url})')