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 |
Nabin Hait | 041e31b | 2020-05-19 20:58:00 +0530 | [diff] [blame] | 6 | from frappe import _ |
Shivam Mishra | 8cdcb96 | 2020-05-06 15:19:22 +0530 | [diff] [blame] | 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: |
Deepesh Garg | 9f963a2 | 2020-05-24 21:55:47 +0530 | [diff] [blame] | 22 | return company[0].name |
Rucha Mahabal | 24477d5 | 2020-05-18 18:15:20 +0530 | [diff] [blame] | 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"}, |
Rucha Mahabal | de37513 | 2020-05-18 19:15:08 +0530 | [diff] [blame] | 33 | { "chart": "Lab Tests", "width": "Half"}, |
| 34 | { "chart": "Clinical Procedures", "width": "Half"}, |
Rucha Mahabal | fb29714 | 2020-05-18 16:28:11 +0530 | [diff] [blame] | 35 | { "chart": "Symptoms", "width": "Half"}, |
| 36 | { "chart": "Diagnoses", "width": "Half"}, |
Rucha Mahabal | de37513 | 2020-05-18 19:15:08 +0530 | [diff] [blame] | 37 | { "chart": "Department wise Patient Appointments", "width": "Full"} |
Rucha Mahabal | 24477d5 | 2020-05-18 18:15:20 +0530 | [diff] [blame] | 38 | ], |
| 39 | "cards": [ |
| 40 | { "card": "Total Patients" }, |
| 41 | { "card": "Total Patient Admitted" }, |
| 42 | { "card": "Open Appointments" }, |
| 43 | { "card": "Appointments to Bill" } |
Shivam Mishra | 8cdcb96 | 2020-05-06 15:19:22 +0530 | [diff] [blame] | 44 | ] |
| 45 | }] |
| 46 | |
| 47 | def get_charts(): |
Rucha Mahabal | 5162faa | 2020-05-18 18:59:59 +0530 | [diff] [blame] | 48 | company = get_company() |
Shivam Mishra | 8cdcb96 | 2020-05-06 15:19:22 +0530 | [diff] [blame] | 49 | return [ |
| 50 | { |
| 51 | "doctype": "Dashboard Chart", |
| 52 | "time_interval": "Daily", |
Shivam Mishra | 41616d4 | 2020-05-06 20:21:05 +0530 | [diff] [blame] | 53 | "name": "Patient Appointments", |
Nabin Hait | 041e31b | 2020-05-19 20:58:00 +0530 | [diff] [blame] | 54 | "chart_name": _("Patient Appointments"), |
Shivam Mishra | 8cdcb96 | 2020-05-06 15:19:22 +0530 | [diff] [blame] | 55 | "timespan": "Last Month", |
Rucha Mahabal | 5162faa | 2020-05-18 18:59:59 +0530 | [diff] [blame] | 56 | "filters_json": json.dumps([ |
| 57 | ["Patient Appointment", "company", "=", company, False], |
| 58 | ["Patient Appointment", "status", "!=", "Cancelled"] |
| 59 | ]), |
Shivam Mishra | 8cdcb96 | 2020-05-06 15:19:22 +0530 | [diff] [blame] | 60 | "chart_type": "Count", |
| 61 | "timeseries": 1, |
| 62 | "based_on": "appointment_datetime", |
| 63 | "owner": "Administrator", |
| 64 | "document_type": "Patient Appointment", |
| 65 | "type": "Line", |
| 66 | "width": "Half" |
Rucha Mahabal | fb29714 | 2020-05-18 16:28:11 +0530 | [diff] [blame] | 67 | }, |
| 68 | { |
| 69 | "doctype": "Dashboard Chart", |
| 70 | "name": "Department wise Patient Appointments", |
Nabin Hait | 041e31b | 2020-05-19 20:58:00 +0530 | [diff] [blame] | 71 | "chart_name": _("Department wise Patient Appointments"), |
Rucha Mahabal | b8db275 | 2020-05-19 01:46:48 +0530 | [diff] [blame] | 72 | "chart_type": "Custom", |
| 73 | "source": "Department wise Patient Appointments", |
Rucha Mahabal | a3dd75e | 2020-05-28 19:03:37 +0530 | [diff] [blame] | 74 | "filters_json": json.dumps([]), |
Rucha Mahabal | fb29714 | 2020-05-18 16:28:11 +0530 | [diff] [blame] | 75 | 'is_public': 1, |
| 76 | "owner": "Administrator", |
| 77 | "type": "Bar", |
| 78 | "width": "Full", |
Rucha Mahabal | b8db275 | 2020-05-19 01:46:48 +0530 | [diff] [blame] | 79 | "custom_options": json.dumps({ |
| 80 | "colors": ["#7CD5FA", "#5F62F6", "#7544E2", "#EE5555"], |
| 81 | "barOptions":{ |
| 82 | "stacked":1 |
| 83 | }, |
| 84 | "height": 300 |
| 85 | }) |
Rucha Mahabal | fb29714 | 2020-05-18 16:28:11 +0530 | [diff] [blame] | 86 | }, |
| 87 | { |
| 88 | "doctype": "Dashboard Chart", |
| 89 | "name": "Lab Tests", |
Nabin Hait | 041e31b | 2020-05-19 20:58:00 +0530 | [diff] [blame] | 90 | "chart_name": _("Lab Tests"), |
Rucha Mahabal | fb29714 | 2020-05-18 16:28:11 +0530 | [diff] [blame] | 91 | "chart_type": "Group By", |
| 92 | "document_type": "Lab Test", |
| 93 | "group_by_type": "Count", |
| 94 | "group_by_based_on": "template", |
Rucha Mahabal | 5162faa | 2020-05-18 18:59:59 +0530 | [diff] [blame] | 95 | "filters_json": json.dumps([ |
| 96 | ["Lab Test", "company", "=", company, False], |
| 97 | ["Lab Test", "docstatus", "=", 1] |
| 98 | ]), |
Rucha Mahabal | fb29714 | 2020-05-18 16:28:11 +0530 | [diff] [blame] | 99 | 'is_public': 1, |
| 100 | "owner": "Administrator", |
Rucha Mahabal | de37513 | 2020-05-18 19:15:08 +0530 | [diff] [blame] | 101 | "type": "Percentage", |
| 102 | "width": "Half", |
| 103 | }, |
| 104 | { |
| 105 | "doctype": "Dashboard Chart", |
| 106 | "name": "Clinical Procedures", |
Nabin Hait | 041e31b | 2020-05-19 20:58:00 +0530 | [diff] [blame] | 107 | "chart_name": _("Clinical Procedures"), |
Rucha Mahabal | de37513 | 2020-05-18 19:15:08 +0530 | [diff] [blame] | 108 | "chart_type": "Group By", |
| 109 | "document_type": "Clinical Procedure", |
| 110 | "group_by_type": "Count", |
| 111 | "group_by_based_on": "procedure_template", |
| 112 | "filters_json": json.dumps([ |
| 113 | ["Clinical Procedure", "company", "=", company, False], |
| 114 | ["Clinical Procedure", "docstatus", "=", 1] |
| 115 | ]), |
| 116 | 'is_public': 1, |
| 117 | "owner": "Administrator", |
| 118 | "type": "Percentage", |
| 119 | "width": "Half", |
Rucha Mahabal | fb29714 | 2020-05-18 16:28:11 +0530 | [diff] [blame] | 120 | }, |
| 121 | { |
| 122 | "doctype": "Dashboard Chart", |
| 123 | "name": "In-Patient Status", |
Nabin Hait | 041e31b | 2020-05-19 20:58:00 +0530 | [diff] [blame] | 124 | "chart_name": _("In-Patient Status"), |
Rucha Mahabal | fb29714 | 2020-05-18 16:28:11 +0530 | [diff] [blame] | 125 | "chart_type": "Group By", |
| 126 | "document_type": "Inpatient Record", |
| 127 | "group_by_type": "Count", |
| 128 | "group_by_based_on": "status", |
Rucha Mahabal | 5162faa | 2020-05-18 18:59:59 +0530 | [diff] [blame] | 129 | "filters_json": json.dumps([ |
| 130 | ["Inpatient Record", "company", "=", company, False] |
| 131 | ]), |
Rucha Mahabal | fb29714 | 2020-05-18 16:28:11 +0530 | [diff] [blame] | 132 | 'is_public': 1, |
| 133 | "owner": "Administrator", |
| 134 | "type": "Bar", |
| 135 | "width": "Half", |
| 136 | }, |
| 137 | { |
| 138 | "doctype": "Dashboard Chart", |
| 139 | "name": "Clinical Procedures Status", |
Nabin Hait | 041e31b | 2020-05-19 20:58:00 +0530 | [diff] [blame] | 140 | "chart_name": _("Clinical Procedure Status"), |
Rucha Mahabal | fb29714 | 2020-05-18 16:28:11 +0530 | [diff] [blame] | 141 | "chart_type": "Group By", |
| 142 | "document_type": "Clinical Procedure", |
| 143 | "group_by_type": "Count", |
| 144 | "group_by_based_on": "status", |
Rucha Mahabal | 5162faa | 2020-05-18 18:59:59 +0530 | [diff] [blame] | 145 | "filters_json": json.dumps([ |
| 146 | ["Clinical Procedure", "company", "=", company, False], |
| 147 | ["Clinical Procedure", "docstatus", "=", 1] |
| 148 | ]), |
Rucha Mahabal | fb29714 | 2020-05-18 16:28:11 +0530 | [diff] [blame] | 149 | 'is_public': 1, |
| 150 | "owner": "Administrator", |
| 151 | "type": "Pie", |
| 152 | "width": "Half", |
| 153 | }, |
| 154 | { |
| 155 | "doctype": "Dashboard Chart", |
| 156 | "name": "Symptoms", |
Nabin Hait | 041e31b | 2020-05-19 20:58:00 +0530 | [diff] [blame] | 157 | "chart_name": _("Symptoms"), |
Rucha Mahabal | fb29714 | 2020-05-18 16:28:11 +0530 | [diff] [blame] | 158 | "chart_type": "Group By", |
| 159 | "document_type": "Patient Encounter Symptom", |
| 160 | "group_by_type": "Count", |
| 161 | "group_by_based_on": "complaint", |
Rucha Mahabal | a3dd75e | 2020-05-28 19:03:37 +0530 | [diff] [blame] | 162 | "filters_json": json.dumps([]), |
Rucha Mahabal | fb29714 | 2020-05-18 16:28:11 +0530 | [diff] [blame] | 163 | 'is_public': 1, |
| 164 | "owner": "Administrator", |
| 165 | "type": "Percentage", |
| 166 | "width": "Half", |
| 167 | }, |
| 168 | { |
| 169 | "doctype": "Dashboard Chart", |
| 170 | "name": "Diagnoses", |
Nabin Hait | 041e31b | 2020-05-19 20:58:00 +0530 | [diff] [blame] | 171 | "chart_name": _("Diagnoses"), |
Rucha Mahabal | fb29714 | 2020-05-18 16:28:11 +0530 | [diff] [blame] | 172 | "chart_type": "Group By", |
| 173 | "document_type": "Patient Encounter Diagnosis", |
| 174 | "group_by_type": "Count", |
| 175 | "group_by_based_on": "diagnosis", |
Rucha Mahabal | a3dd75e | 2020-05-28 19:03:37 +0530 | [diff] [blame] | 176 | "filters_json": json.dumps([]), |
Rucha Mahabal | fb29714 | 2020-05-18 16:28:11 +0530 | [diff] [blame] | 177 | 'is_public': 1, |
| 178 | "owner": "Administrator", |
| 179 | "type": "Percentage", |
| 180 | "width": "Half", |
Shivam Mishra | 8cdcb96 | 2020-05-06 15:19:22 +0530 | [diff] [blame] | 181 | } |
| 182 | ] |
Rucha Mahabal | 24477d5 | 2020-05-18 18:15:20 +0530 | [diff] [blame] | 183 | |
| 184 | def get_number_cards(): |
Rucha Mahabal | 5162faa | 2020-05-18 18:59:59 +0530 | [diff] [blame] | 185 | company = get_company() |
Rucha Mahabal | 24477d5 | 2020-05-18 18:15:20 +0530 | [diff] [blame] | 186 | return [ |
| 187 | { |
| 188 | "name": "Total Patients", |
Nabin Hait | 041e31b | 2020-05-19 20:58:00 +0530 | [diff] [blame] | 189 | "label": _("Total Patients"), |
Rucha Mahabal | 24477d5 | 2020-05-18 18:15:20 +0530 | [diff] [blame] | 190 | "function": "Count", |
| 191 | "doctype": "Number Card", |
| 192 | "document_type": "Patient", |
| 193 | "filters_json": json.dumps( |
| 194 | [["Patient","status","=","Active",False]] |
| 195 | ), |
| 196 | "is_public": 1, |
| 197 | "owner": "Administrator", |
| 198 | "show_percentage_stats": 1, |
| 199 | "stats_time_interval": "Daily" |
| 200 | }, |
| 201 | { |
| 202 | "name": "Total Patients Admitted", |
Nabin Hait | 041e31b | 2020-05-19 20:58:00 +0530 | [diff] [blame] | 203 | "label": _("Total Patients Admitted"), |
Rucha Mahabal | 24477d5 | 2020-05-18 18:15:20 +0530 | [diff] [blame] | 204 | "function": "Count", |
| 205 | "doctype": "Number Card", |
| 206 | "document_type": "Patient", |
| 207 | "filters_json": json.dumps( |
| 208 | [["Patient","inpatient_status","=","Admitted",False]] |
| 209 | ), |
| 210 | "is_public": 1, |
| 211 | "owner": "Administrator", |
| 212 | "show_percentage_stats": 1, |
| 213 | "stats_time_interval": "Daily" |
| 214 | }, |
| 215 | { |
| 216 | "name": "Open Appointments", |
Nabin Hait | 041e31b | 2020-05-19 20:58:00 +0530 | [diff] [blame] | 217 | "label": _("Open Appointments"), |
Rucha Mahabal | 24477d5 | 2020-05-18 18:15:20 +0530 | [diff] [blame] | 218 | "function": "Count", |
| 219 | "doctype": "Number Card", |
| 220 | "document_type": "Patient Appointment", |
| 221 | "filters_json": json.dumps( |
Rucha Mahabal | 5162faa | 2020-05-18 18:59:59 +0530 | [diff] [blame] | 222 | [["Patient Appointment","company","=",company,False], |
Rucha Mahabal | 24477d5 | 2020-05-18 18:15:20 +0530 | [diff] [blame] | 223 | ["Patient Appointment","status","=","Open",False]] |
| 224 | ), |
| 225 | "is_public": 1, |
| 226 | "owner": "Administrator", |
| 227 | "show_percentage_stats": 1, |
| 228 | "stats_time_interval": "Daily" |
| 229 | }, |
| 230 | { |
| 231 | "name": "Appointments to Bill", |
Rucha Mahabal | a3dd75e | 2020-05-28 19:03:37 +0530 | [diff] [blame] | 232 | "label": _("Appointments To Bill"), |
Rucha Mahabal | 24477d5 | 2020-05-18 18:15:20 +0530 | [diff] [blame] | 233 | "function": "Count", |
| 234 | "doctype": "Number Card", |
| 235 | "document_type": "Patient Appointment", |
| 236 | "filters_json": json.dumps( |
Rucha Mahabal | 5162faa | 2020-05-18 18:59:59 +0530 | [diff] [blame] | 237 | [["Patient Appointment","company","=",company,False], |
Rucha Mahabal | 24477d5 | 2020-05-18 18:15:20 +0530 | [diff] [blame] | 238 | ["Patient Appointment","invoiced","=",0,False]] |
| 239 | ), |
| 240 | "is_public": 1, |
| 241 | "owner": "Administrator", |
| 242 | "show_percentage_stats": 1, |
| 243 | "stats_time_interval": "Daily" |
| 244 | } |
| 245 | ] |