Shivam Mishra | 8cdcb96 | 2020-05-06 15:19:22 +0530 | [diff] [blame] | 1 | # Copyright (c) 2020, Frappe Technologies Pvt. Ltd. and Contributors |
| 2 | # License: GNU General Public License v3. See license.txt |
| 3 | |
| 4 | import frappe |
| 5 | import json |
| 6 | |
| 7 | |
| 8 | def get_data(): |
| 9 | return frappe._dict({ |
| 10 | "dashboards": get_dashboards(), |
| 11 | "charts": get_charts(), |
Rucha Mahabal | 24477d5 | 2020-05-18 18:15:20 +0530 | [diff] [blame] | 12 | "number_cards": get_number_cards(), |
Shivam Mishra | 8cdcb96 | 2020-05-06 15:19:22 +0530 | [diff] [blame] | 13 | }) |
| 14 | |
Rucha Mahabal | 24477d5 | 2020-05-18 18:15:20 +0530 | [diff] [blame] | 15 | def get_company(): |
| 16 | company = frappe.defaults.get_defaults().company |
| 17 | if company: |
| 18 | return company |
| 19 | else: |
| 20 | company = frappe.get_list("Company", limit=1) |
| 21 | if company: |
| 22 | return company.name |
| 23 | return None |
| 24 | |
Shivam Mishra | 8cdcb96 | 2020-05-06 15:19:22 +0530 | [diff] [blame] | 25 | def get_dashboards(): |
| 26 | return [{ |
| 27 | "name": "Healthcare", |
| 28 | "dashboard_name": "Healthcare", |
| 29 | "charts": [ |
Rucha Mahabal | fb29714 | 2020-05-18 16:28:11 +0530 | [diff] [blame] | 30 | { "chart": "Patient Appointments", "width": "Full"}, |
| 31 | { "chart": "In-Patient Status", "width": "Half"}, |
| 32 | { "chart": "Clinical Procedures Status", "width": "Half"}, |
| 33 | { "chart": "Symptoms", "width": "Half"}, |
| 34 | { "chart": "Diagnoses", "width": "Half"}, |
| 35 | { "chart": "Department wise Patient Appointments", "width": "Full"}, |
| 36 | { "chart": "Lab Tests", "width": "Full"}, |
Rucha Mahabal | 24477d5 | 2020-05-18 18:15:20 +0530 | [diff] [blame] | 37 | ], |
| 38 | "cards": [ |
| 39 | { "card": "Total Patients" }, |
| 40 | { "card": "Total Patient Admitted" }, |
| 41 | { "card": "Open Appointments" }, |
| 42 | { "card": "Appointments to Bill" } |
Shivam Mishra | 8cdcb96 | 2020-05-06 15:19:22 +0530 | [diff] [blame] | 43 | ] |
| 44 | }] |
| 45 | |
| 46 | def get_charts(): |
Rucha Mahabal | 5162faa | 2020-05-18 18:59:59 +0530 | [diff] [blame^] | 47 | company = get_company() |
Shivam Mishra | 8cdcb96 | 2020-05-06 15:19:22 +0530 | [diff] [blame] | 48 | return [ |
| 49 | { |
| 50 | "doctype": "Dashboard Chart", |
| 51 | "time_interval": "Daily", |
Shivam Mishra | 41616d4 | 2020-05-06 20:21:05 +0530 | [diff] [blame] | 52 | "name": "Patient Appointments", |
Shivam Mishra | 8cdcb96 | 2020-05-06 15:19:22 +0530 | [diff] [blame] | 53 | "chart_name": "Patient Appointments", |
| 54 | "timespan": "Last Month", |
Rucha Mahabal | 5162faa | 2020-05-18 18:59:59 +0530 | [diff] [blame^] | 55 | "filters_json": json.dumps([ |
| 56 | ["Patient Appointment", "company", "=", company, False], |
| 57 | ["Patient Appointment", "status", "!=", "Cancelled"] |
| 58 | ]), |
Shivam Mishra | 8cdcb96 | 2020-05-06 15:19:22 +0530 | [diff] [blame] | 59 | "chart_type": "Count", |
| 60 | "timeseries": 1, |
| 61 | "based_on": "appointment_datetime", |
| 62 | "owner": "Administrator", |
| 63 | "document_type": "Patient Appointment", |
| 64 | "type": "Line", |
| 65 | "width": "Half" |
Rucha Mahabal | fb29714 | 2020-05-18 16:28:11 +0530 | [diff] [blame] | 66 | }, |
| 67 | { |
| 68 | "doctype": "Dashboard Chart", |
| 69 | "name": "Department wise Patient Appointments", |
| 70 | "chart_name": "Department wise Patient Appointments", |
| 71 | "chart_type": "Group By", |
| 72 | "document_type": "Patient Appointment", |
| 73 | "group_by_type": "Count", |
| 74 | "group_by_based_on": "department", |
Rucha Mahabal | 5162faa | 2020-05-18 18:59:59 +0530 | [diff] [blame^] | 75 | "filters_json": json.dumps([ |
| 76 | ["Patient Appointment", "company", "=", company, False], |
| 77 | ["Patient Appointment", "status", "!=", "Cancelled"] |
| 78 | ]), |
Rucha Mahabal | fb29714 | 2020-05-18 16:28:11 +0530 | [diff] [blame] | 79 | 'is_public': 1, |
| 80 | "owner": "Administrator", |
| 81 | "type": "Bar", |
| 82 | "width": "Full", |
| 83 | "color": "#5F62F6" |
| 84 | }, |
| 85 | { |
| 86 | "doctype": "Dashboard Chart", |
| 87 | "name": "Lab Tests", |
| 88 | "chart_name": "Lab Tests", |
| 89 | "chart_type": "Group By", |
| 90 | "document_type": "Lab Test", |
| 91 | "group_by_type": "Count", |
| 92 | "group_by_based_on": "template", |
Rucha Mahabal | 5162faa | 2020-05-18 18:59:59 +0530 | [diff] [blame^] | 93 | "filters_json": json.dumps([ |
| 94 | ["Lab Test", "company", "=", company, False], |
| 95 | ["Lab Test", "docstatus", "=", 1] |
| 96 | ]), |
Rucha Mahabal | fb29714 | 2020-05-18 16:28:11 +0530 | [diff] [blame] | 97 | 'is_public': 1, |
| 98 | "owner": "Administrator", |
| 99 | "type": "Bar", |
| 100 | "width": "Full", |
| 101 | "color": "#8548EB" |
| 102 | }, |
| 103 | { |
| 104 | "doctype": "Dashboard Chart", |
| 105 | "name": "In-Patient Status", |
| 106 | "chart_name": "In-Patient Status", |
| 107 | "chart_type": "Group By", |
| 108 | "document_type": "Inpatient Record", |
| 109 | "group_by_type": "Count", |
| 110 | "group_by_based_on": "status", |
Rucha Mahabal | 5162faa | 2020-05-18 18:59:59 +0530 | [diff] [blame^] | 111 | "filters_json": json.dumps([ |
| 112 | ["Inpatient Record", "company", "=", company, False] |
| 113 | ]), |
Rucha Mahabal | fb29714 | 2020-05-18 16:28:11 +0530 | [diff] [blame] | 114 | 'is_public': 1, |
| 115 | "owner": "Administrator", |
| 116 | "type": "Bar", |
| 117 | "width": "Half", |
| 118 | }, |
| 119 | { |
| 120 | "doctype": "Dashboard Chart", |
| 121 | "name": "Clinical Procedures Status", |
| 122 | "chart_name": "Clinical Procedure Status", |
| 123 | "chart_type": "Group By", |
| 124 | "document_type": "Clinical Procedure", |
| 125 | "group_by_type": "Count", |
| 126 | "group_by_based_on": "status", |
Rucha Mahabal | 5162faa | 2020-05-18 18:59:59 +0530 | [diff] [blame^] | 127 | "filters_json": json.dumps([ |
| 128 | ["Clinical Procedure", "company", "=", company, False], |
| 129 | ["Clinical Procedure", "docstatus", "=", 1] |
| 130 | ]), |
Rucha Mahabal | fb29714 | 2020-05-18 16:28:11 +0530 | [diff] [blame] | 131 | 'is_public': 1, |
| 132 | "owner": "Administrator", |
| 133 | "type": "Pie", |
| 134 | "width": "Half", |
| 135 | }, |
| 136 | { |
| 137 | "doctype": "Dashboard Chart", |
| 138 | "name": "Symptoms", |
| 139 | "chart_name": "Symptoms", |
| 140 | "chart_type": "Group By", |
| 141 | "document_type": "Patient Encounter Symptom", |
| 142 | "group_by_type": "Count", |
| 143 | "group_by_based_on": "complaint", |
Rucha Mahabal | 5162faa | 2020-05-18 18:59:59 +0530 | [diff] [blame^] | 144 | "filters_json": json.dumps({}), |
Rucha Mahabal | fb29714 | 2020-05-18 16:28:11 +0530 | [diff] [blame] | 145 | 'is_public': 1, |
| 146 | "owner": "Administrator", |
| 147 | "type": "Percentage", |
| 148 | "width": "Half", |
| 149 | }, |
| 150 | { |
| 151 | "doctype": "Dashboard Chart", |
| 152 | "name": "Diagnoses", |
| 153 | "chart_name": "Diagnoses", |
| 154 | "chart_type": "Group By", |
| 155 | "document_type": "Patient Encounter Diagnosis", |
| 156 | "group_by_type": "Count", |
| 157 | "group_by_based_on": "diagnosis", |
Rucha Mahabal | 5162faa | 2020-05-18 18:59:59 +0530 | [diff] [blame^] | 158 | "filters_json": json.dumps({}), |
Rucha Mahabal | fb29714 | 2020-05-18 16:28:11 +0530 | [diff] [blame] | 159 | 'is_public': 1, |
| 160 | "owner": "Administrator", |
| 161 | "type": "Percentage", |
| 162 | "width": "Half", |
Shivam Mishra | 8cdcb96 | 2020-05-06 15:19:22 +0530 | [diff] [blame] | 163 | } |
| 164 | ] |
Rucha Mahabal | 24477d5 | 2020-05-18 18:15:20 +0530 | [diff] [blame] | 165 | |
| 166 | def get_number_cards(): |
Rucha Mahabal | 5162faa | 2020-05-18 18:59:59 +0530 | [diff] [blame^] | 167 | company = get_company() |
Rucha Mahabal | 24477d5 | 2020-05-18 18:15:20 +0530 | [diff] [blame] | 168 | return [ |
| 169 | { |
| 170 | "name": "Total Patients", |
| 171 | "label": "Total Patients", |
| 172 | "function": "Count", |
| 173 | "doctype": "Number Card", |
| 174 | "document_type": "Patient", |
| 175 | "filters_json": json.dumps( |
| 176 | [["Patient","status","=","Active",False]] |
| 177 | ), |
| 178 | "is_public": 1, |
| 179 | "owner": "Administrator", |
| 180 | "show_percentage_stats": 1, |
| 181 | "stats_time_interval": "Daily" |
| 182 | }, |
| 183 | { |
| 184 | "name": "Total Patients Admitted", |
| 185 | "label": "Total Patients Admitted", |
| 186 | "function": "Count", |
| 187 | "doctype": "Number Card", |
| 188 | "document_type": "Patient", |
| 189 | "filters_json": json.dumps( |
| 190 | [["Patient","inpatient_status","=","Admitted",False]] |
| 191 | ), |
| 192 | "is_public": 1, |
| 193 | "owner": "Administrator", |
| 194 | "show_percentage_stats": 1, |
| 195 | "stats_time_interval": "Daily" |
| 196 | }, |
| 197 | { |
| 198 | "name": "Open Appointments", |
| 199 | "label": "Open Appointments", |
| 200 | "function": "Count", |
| 201 | "doctype": "Number Card", |
| 202 | "document_type": "Patient Appointment", |
| 203 | "filters_json": json.dumps( |
Rucha Mahabal | 5162faa | 2020-05-18 18:59:59 +0530 | [diff] [blame^] | 204 | [["Patient Appointment","company","=",company,False], |
Rucha Mahabal | 24477d5 | 2020-05-18 18:15:20 +0530 | [diff] [blame] | 205 | ["Patient Appointment","status","=","Open",False]] |
| 206 | ), |
| 207 | "is_public": 1, |
| 208 | "owner": "Administrator", |
| 209 | "show_percentage_stats": 1, |
| 210 | "stats_time_interval": "Daily" |
| 211 | }, |
| 212 | { |
| 213 | "name": "Appointments to Bill", |
| 214 | "label": "Appointments to Bill", |
| 215 | "function": "Count", |
| 216 | "doctype": "Number Card", |
| 217 | "document_type": "Patient Appointment", |
| 218 | "filters_json": json.dumps( |
Rucha Mahabal | 5162faa | 2020-05-18 18:59:59 +0530 | [diff] [blame^] | 219 | [["Patient Appointment","company","=",company,False], |
Rucha Mahabal | 24477d5 | 2020-05-18 18:15:20 +0530 | [diff] [blame] | 220 | ["Patient Appointment","invoiced","=",0,False]] |
| 221 | ), |
| 222 | "is_public": 1, |
| 223 | "owner": "Administrator", |
| 224 | "show_percentage_stats": 1, |
| 225 | "stats_time_interval": "Daily" |
| 226 | } |
| 227 | ] |