...
select count(*) as count1 from txfirst_dashboarddata where unit_id = 4 and list_status = "working_up" and quarter_id=2 / select count(*) as count1 from txfirst_dashboarddata where unit_id = 4 and quarter_id=2 * 100 -> 7 → 7 / 26 * 100 = 26.92%
Patients who are still being “Working up or under discussion” (Graph2)
...
select count(*) as count1 from txfirst_dashboarddata where unit_id = 4 and list_status = "working_up" and quarter_id=2 / select count(*) as count1 from txfirst_dashboarddata where unit_id = 4 and quarter_id=2 * 100 -> 7 → 7 / 26 * 100 = 26.92%
Each point of the region line graph computed as: region_count / region_total_count * 100, is equivalent to the following query:
...
select count(*) from txfirst_dashboarddata left join users_unit on unit_id = users_unit.id where region_id = 3 and list_status = "working_up" and quarter_id=17 / select count(*) from txfirst_dashboarddata left join users_unit on unit_id = users_unit.id where region_id = 3 and quarter_id=17 * 100 -> 15 → 15 / 54 * 100 = 27.78%
Patients who have “No documented decision status” (Graph3)
...
select count(*) as count1 from txfirst_dashboarddata where unit_id = 4 and list_status = "no_decision" and quarter_id = 2 / select count(*) as count1 from txfirst_dashboarddata where unit_id = 4 and quarter_id = 2 * 100 -> 1 → 1 / 26 * 100 = 3.85%
Each point of the region line graph in the code is computed as region_count / region_total_count * 100, which is equivalent to the following query:
...
select count(*) from txfirst_dashboarddata left join users_unit on unit_id = users_unit.id where region_id = 3 and list_status = "no_decision" and quarter_id=17 / select count(*) from txfirst_dashboarddata left join users_unit on unit_id = users_unit.id where region_id = 3 and quarter_id=17 * 100 -> 4 → 4 / 54 * 100 = 7.41%
Under Reasons why patients were still in category "working up or under discussion" at time of starting dialysis
...
get_reason_counts function – sum of all dashboarddata records per reason_id, unit_id, quarter_id (all quarters: >= some quarter_id) in a unit
Ex: E.g., select quarter_id, reason_id, count(reason_id) as count1 from txfirst_dashboarddata left join txfirst_quarter on quarter_id = txfirst_quarter.id where unit_id = 4 and txfirst_quarter.quarter >= 201601 and list_status = "working_up" group by quarter_id, reason_id order by quarter_id
...
get_total_counts function – sum of all dashboarddata records per list_status and quarter_id >= some quarter_id in a unit
ExE.g., select quarter_id, count(quarter_id) as count1 from txfirst_dashboarddata left join txfirst_quarter on quarter_id = txfirst_quarter.id where unit_id = 4 and txfirst_quarter.quarter >= 201601 and list_status = "working_up" group by quarter_id order by quarter_id
...