blob: 4fb05a8f81f83f0c330d37617e438280cb1d708d [file] [log] [blame]
Shivam Mishra8cdcb962020-05-06 15:19:22 +05301# Copyright (c) 2020, Frappe Technologies Pvt. Ltd. and Contributors
2# License: GNU General Public License v3. See license.txt
3
4import frappe
5import json
6
7
8def get_data():
9 return frappe._dict({
10 "dashboards": get_dashboards(),
11 "charts": get_charts(),
Rucha Mahabal24477d52020-05-18 18:15:20 +053012 "number_cards": get_number_cards(),
Shivam Mishra8cdcb962020-05-06 15:19:22 +053013 })
14
Rucha Mahabal24477d52020-05-18 18:15:20 +053015def 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 Mishra8cdcb962020-05-06 15:19:22 +053025def get_dashboards():
26 return [{
27 "name": "Healthcare",
28 "dashboard_name": "Healthcare",
29 "charts": [
Rucha Mahabalfb297142020-05-18 16:28:11 +053030 { "chart": "Patient Appointments", "width": "Full"},
31 { "chart": "In-Patient Status", "width": "Half"},
32 { "chart": "Clinical Procedures Status", "width": "Half"},
Rucha Mahabalde375132020-05-18 19:15:08 +053033 { "chart": "Lab Tests", "width": "Half"},
34 { "chart": "Clinical Procedures", "width": "Half"},
Rucha Mahabalfb297142020-05-18 16:28:11 +053035 { "chart": "Symptoms", "width": "Half"},
36 { "chart": "Diagnoses", "width": "Half"},
Rucha Mahabalde375132020-05-18 19:15:08 +053037 { "chart": "Department wise Patient Appointments", "width": "Full"}
Rucha Mahabal24477d52020-05-18 18:15:20 +053038 ],
39 "cards": [
40 { "card": "Total Patients" },
41 { "card": "Total Patient Admitted" },
42 { "card": "Open Appointments" },
43 { "card": "Appointments to Bill" }
Shivam Mishra8cdcb962020-05-06 15:19:22 +053044 ]
45 }]
46
47def get_charts():
Rucha Mahabal5162faa2020-05-18 18:59:59 +053048 company = get_company()
Shivam Mishra8cdcb962020-05-06 15:19:22 +053049 return [
50 {
51 "doctype": "Dashboard Chart",
52 "time_interval": "Daily",
Shivam Mishra41616d42020-05-06 20:21:05 +053053 "name": "Patient Appointments",
Shivam Mishra8cdcb962020-05-06 15:19:22 +053054 "chart_name": "Patient Appointments",
55 "timespan": "Last Month",
Rucha Mahabal5162faa2020-05-18 18:59:59 +053056 "filters_json": json.dumps([
57 ["Patient Appointment", "company", "=", company, False],
58 ["Patient Appointment", "status", "!=", "Cancelled"]
59 ]),
Shivam Mishra8cdcb962020-05-06 15:19:22 +053060 "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 Mahabalfb297142020-05-18 16:28:11 +053067 },
68 {
69 "doctype": "Dashboard Chart",
70 "name": "Department wise Patient Appointments",
71 "chart_name": "Department wise Patient Appointments",
Rucha Mahabalb8db2752020-05-19 01:46:48 +053072 "chart_type": "Custom",
73 "source": "Department wise Patient Appointments",
74 "filters_json": json.dumps({}),
Rucha Mahabalfb297142020-05-18 16:28:11 +053075 'is_public': 1,
76 "owner": "Administrator",
77 "type": "Bar",
78 "width": "Full",
Rucha Mahabalb8db2752020-05-19 01:46:48 +053079 "custom_options": json.dumps({
80 "colors": ["#7CD5FA", "#5F62F6", "#7544E2", "#EE5555"],
81 "barOptions":{
82 "stacked":1
83 },
84 "height": 300
85 })
Rucha Mahabalfb297142020-05-18 16:28:11 +053086 },
87 {
88 "doctype": "Dashboard Chart",
89 "name": "Lab Tests",
90 "chart_name": "Lab Tests",
91 "chart_type": "Group By",
92 "document_type": "Lab Test",
93 "group_by_type": "Count",
94 "group_by_based_on": "template",
Rucha Mahabal5162faa2020-05-18 18:59:59 +053095 "filters_json": json.dumps([
96 ["Lab Test", "company", "=", company, False],
97 ["Lab Test", "docstatus", "=", 1]
98 ]),
Rucha Mahabalfb297142020-05-18 16:28:11 +053099 'is_public': 1,
100 "owner": "Administrator",
Rucha Mahabalde375132020-05-18 19:15:08 +0530101 "type": "Percentage",
102 "width": "Half",
103 },
104 {
105 "doctype": "Dashboard Chart",
106 "name": "Clinical Procedures",
107 "chart_name": "Clinical Procedures",
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 Mahabalfb297142020-05-18 16:28:11 +0530120 },
121 {
122 "doctype": "Dashboard Chart",
123 "name": "In-Patient Status",
124 "chart_name": "In-Patient Status",
125 "chart_type": "Group By",
126 "document_type": "Inpatient Record",
127 "group_by_type": "Count",
128 "group_by_based_on": "status",
Rucha Mahabal5162faa2020-05-18 18:59:59 +0530129 "filters_json": json.dumps([
130 ["Inpatient Record", "company", "=", company, False]
131 ]),
Rucha Mahabalfb297142020-05-18 16:28:11 +0530132 'is_public': 1,
133 "owner": "Administrator",
134 "type": "Bar",
135 "width": "Half",
136 },
137 {
138 "doctype": "Dashboard Chart",
139 "name": "Clinical Procedures Status",
140 "chart_name": "Clinical Procedure Status",
141 "chart_type": "Group By",
142 "document_type": "Clinical Procedure",
143 "group_by_type": "Count",
144 "group_by_based_on": "status",
Rucha Mahabal5162faa2020-05-18 18:59:59 +0530145 "filters_json": json.dumps([
146 ["Clinical Procedure", "company", "=", company, False],
147 ["Clinical Procedure", "docstatus", "=", 1]
148 ]),
Rucha Mahabalfb297142020-05-18 16:28:11 +0530149 'is_public': 1,
150 "owner": "Administrator",
151 "type": "Pie",
152 "width": "Half",
153 },
154 {
155 "doctype": "Dashboard Chart",
156 "name": "Symptoms",
157 "chart_name": "Symptoms",
158 "chart_type": "Group By",
159 "document_type": "Patient Encounter Symptom",
160 "group_by_type": "Count",
161 "group_by_based_on": "complaint",
Rucha Mahabal5162faa2020-05-18 18:59:59 +0530162 "filters_json": json.dumps({}),
Rucha Mahabalfb297142020-05-18 16:28:11 +0530163 'is_public': 1,
164 "owner": "Administrator",
165 "type": "Percentage",
166 "width": "Half",
167 },
168 {
169 "doctype": "Dashboard Chart",
170 "name": "Diagnoses",
171 "chart_name": "Diagnoses",
172 "chart_type": "Group By",
173 "document_type": "Patient Encounter Diagnosis",
174 "group_by_type": "Count",
175 "group_by_based_on": "diagnosis",
Rucha Mahabal5162faa2020-05-18 18:59:59 +0530176 "filters_json": json.dumps({}),
Rucha Mahabalfb297142020-05-18 16:28:11 +0530177 'is_public': 1,
178 "owner": "Administrator",
179 "type": "Percentage",
180 "width": "Half",
Shivam Mishra8cdcb962020-05-06 15:19:22 +0530181 }
182 ]
Rucha Mahabal24477d52020-05-18 18:15:20 +0530183
184def get_number_cards():
Rucha Mahabal5162faa2020-05-18 18:59:59 +0530185 company = get_company()
Rucha Mahabal24477d52020-05-18 18:15:20 +0530186 return [
187 {
188 "name": "Total Patients",
189 "label": "Total Patients",
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",
203 "label": "Total Patients Admitted",
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",
217 "label": "Open Appointments",
218 "function": "Count",
219 "doctype": "Number Card",
220 "document_type": "Patient Appointment",
221 "filters_json": json.dumps(
Rucha Mahabal5162faa2020-05-18 18:59:59 +0530222 [["Patient Appointment","company","=",company,False],
Rucha Mahabal24477d52020-05-18 18:15:20 +0530223 ["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",
232 "label": "Appointments to Bill",
233 "function": "Count",
234 "doctype": "Number Card",
235 "document_type": "Patient Appointment",
236 "filters_json": json.dumps(
Rucha Mahabal5162faa2020-05-18 18:59:59 +0530237 [["Patient Appointment","company","=",company,False],
Rucha Mahabal24477d52020-05-18 18:15:20 +0530238 ["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 ]