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(): |
| 47 | return [ |
| 48 | { |
| 49 | "doctype": "Dashboard Chart", |
| 50 | "time_interval": "Daily", |
Shivam Mishra | 41616d4 | 2020-05-06 20:21:05 +0530 | [diff] [blame] | 51 | "name": "Patient Appointments", |
Shivam Mishra | 8cdcb96 | 2020-05-06 15:19:22 +0530 | [diff] [blame] | 52 | "chart_name": "Patient Appointments", |
| 53 | "timespan": "Last Month", |
Shivam Mishra | 8cdcb96 | 2020-05-06 15:19:22 +0530 | [diff] [blame] | 54 | "filters_json": json.dumps({}), |
| 55 | "chart_type": "Count", |
| 56 | "timeseries": 1, |
| 57 | "based_on": "appointment_datetime", |
| 58 | "owner": "Administrator", |
| 59 | "document_type": "Patient Appointment", |
| 60 | "type": "Line", |
| 61 | "width": "Half" |
Rucha Mahabal | fb29714 | 2020-05-18 16:28:11 +0530 | [diff] [blame] | 62 | }, |
| 63 | { |
| 64 | "doctype": "Dashboard Chart", |
| 65 | "name": "Department wise Patient Appointments", |
| 66 | "chart_name": "Department wise Patient Appointments", |
| 67 | "chart_type": "Group By", |
| 68 | "document_type": "Patient Appointment", |
| 69 | "group_by_type": "Count", |
| 70 | "group_by_based_on": "department", |
| 71 | 'is_public': 1, |
| 72 | "owner": "Administrator", |
| 73 | "type": "Bar", |
| 74 | "width": "Full", |
| 75 | "color": "#5F62F6" |
| 76 | }, |
| 77 | { |
| 78 | "doctype": "Dashboard Chart", |
| 79 | "name": "Lab Tests", |
| 80 | "chart_name": "Lab Tests", |
| 81 | "chart_type": "Group By", |
| 82 | "document_type": "Lab Test", |
| 83 | "group_by_type": "Count", |
| 84 | "group_by_based_on": "template", |
| 85 | 'is_public': 1, |
| 86 | "owner": "Administrator", |
| 87 | "type": "Bar", |
| 88 | "width": "Full", |
| 89 | "color": "#8548EB" |
| 90 | }, |
| 91 | { |
| 92 | "doctype": "Dashboard Chart", |
| 93 | "name": "In-Patient Status", |
| 94 | "chart_name": "In-Patient Status", |
| 95 | "chart_type": "Group By", |
| 96 | "document_type": "Inpatient Record", |
| 97 | "group_by_type": "Count", |
| 98 | "group_by_based_on": "status", |
| 99 | 'is_public': 1, |
| 100 | "owner": "Administrator", |
| 101 | "type": "Bar", |
| 102 | "width": "Half", |
| 103 | }, |
| 104 | { |
| 105 | "doctype": "Dashboard Chart", |
| 106 | "name": "Clinical Procedures Status", |
| 107 | "chart_name": "Clinical Procedure Status", |
| 108 | "chart_type": "Group By", |
| 109 | "document_type": "Clinical Procedure", |
| 110 | "group_by_type": "Count", |
| 111 | "group_by_based_on": "status", |
| 112 | 'is_public': 1, |
| 113 | "owner": "Administrator", |
| 114 | "type": "Pie", |
| 115 | "width": "Half", |
| 116 | }, |
| 117 | { |
| 118 | "doctype": "Dashboard Chart", |
| 119 | "name": "Symptoms", |
| 120 | "chart_name": "Symptoms", |
| 121 | "chart_type": "Group By", |
| 122 | "document_type": "Patient Encounter Symptom", |
| 123 | "group_by_type": "Count", |
| 124 | "group_by_based_on": "complaint", |
| 125 | 'is_public': 1, |
| 126 | "owner": "Administrator", |
| 127 | "type": "Percentage", |
| 128 | "width": "Half", |
| 129 | }, |
| 130 | { |
| 131 | "doctype": "Dashboard Chart", |
| 132 | "name": "Diagnoses", |
| 133 | "chart_name": "Diagnoses", |
| 134 | "chart_type": "Group By", |
| 135 | "document_type": "Patient Encounter Diagnosis", |
| 136 | "group_by_type": "Count", |
| 137 | "group_by_based_on": "diagnosis", |
| 138 | 'is_public': 1, |
| 139 | "owner": "Administrator", |
| 140 | "type": "Percentage", |
| 141 | "width": "Half", |
Shivam Mishra | 8cdcb96 | 2020-05-06 15:19:22 +0530 | [diff] [blame] | 142 | } |
| 143 | ] |
Rucha Mahabal | 24477d5 | 2020-05-18 18:15:20 +0530 | [diff] [blame^] | 144 | |
| 145 | def get_number_cards(): |
| 146 | return [ |
| 147 | { |
| 148 | "name": "Total Patients", |
| 149 | "label": "Total Patients", |
| 150 | "function": "Count", |
| 151 | "doctype": "Number Card", |
| 152 | "document_type": "Patient", |
| 153 | "filters_json": json.dumps( |
| 154 | [["Patient","status","=","Active",False]] |
| 155 | ), |
| 156 | "is_public": 1, |
| 157 | "owner": "Administrator", |
| 158 | "show_percentage_stats": 1, |
| 159 | "stats_time_interval": "Daily" |
| 160 | }, |
| 161 | { |
| 162 | "name": "Total Patients Admitted", |
| 163 | "label": "Total Patients Admitted", |
| 164 | "function": "Count", |
| 165 | "doctype": "Number Card", |
| 166 | "document_type": "Patient", |
| 167 | "filters_json": json.dumps( |
| 168 | [["Patient","inpatient_status","=","Admitted",False]] |
| 169 | ), |
| 170 | "is_public": 1, |
| 171 | "owner": "Administrator", |
| 172 | "show_percentage_stats": 1, |
| 173 | "stats_time_interval": "Daily" |
| 174 | }, |
| 175 | { |
| 176 | "name": "Open Appointments", |
| 177 | "label": "Open Appointments", |
| 178 | "function": "Count", |
| 179 | "doctype": "Number Card", |
| 180 | "document_type": "Patient Appointment", |
| 181 | "filters_json": json.dumps( |
| 182 | [["Patient Appointment","company","=",get_company(),False], |
| 183 | ["Patient Appointment","status","=","Open",False]] |
| 184 | ), |
| 185 | "is_public": 1, |
| 186 | "owner": "Administrator", |
| 187 | "show_percentage_stats": 1, |
| 188 | "stats_time_interval": "Daily" |
| 189 | }, |
| 190 | { |
| 191 | "name": "Appointments to Bill", |
| 192 | "label": "Appointments to Bill", |
| 193 | "function": "Count", |
| 194 | "doctype": "Number Card", |
| 195 | "document_type": "Patient Appointment", |
| 196 | "filters_json": json.dumps( |
| 197 | [["Patient Appointment","company","=",get_company(),False], |
| 198 | ["Patient Appointment","invoiced","=",0,False]] |
| 199 | ), |
| 200 | "is_public": 1, |
| 201 | "owner": "Administrator", |
| 202 | "show_percentage_stats": 1, |
| 203 | "stats_time_interval": "Daily" |
| 204 | } |
| 205 | ] |