blob: faa83cccf3d46c1aae2db2207fa578760d3d86f3 [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",
72 "chart_type": "Group By",
73 "document_type": "Patient Appointment",
74 "group_by_type": "Count",
75 "group_by_based_on": "department",
Rucha Mahabal5162faa2020-05-18 18:59:59 +053076 "filters_json": json.dumps([
77 ["Patient Appointment", "company", "=", company, False],
78 ["Patient Appointment", "status", "!=", "Cancelled"]
79 ]),
Rucha Mahabalfb297142020-05-18 16:28:11 +053080 'is_public': 1,
81 "owner": "Administrator",
82 "type": "Bar",
83 "width": "Full",
84 "color": "#5F62F6"
85 },
86 {
87 "doctype": "Dashboard Chart",
88 "name": "Lab Tests",
89 "chart_name": "Lab Tests",
90 "chart_type": "Group By",
91 "document_type": "Lab Test",
92 "group_by_type": "Count",
93 "group_by_based_on": "template",
Rucha Mahabal5162faa2020-05-18 18:59:59 +053094 "filters_json": json.dumps([
95 ["Lab Test", "company", "=", company, False],
96 ["Lab Test", "docstatus", "=", 1]
97 ]),
Rucha Mahabalfb297142020-05-18 16:28:11 +053098 'is_public': 1,
99 "owner": "Administrator",
Rucha Mahabalde375132020-05-18 19:15:08 +0530100 "type": "Percentage",
101 "width": "Half",
102 },
103 {
104 "doctype": "Dashboard Chart",
105 "name": "Clinical Procedures",
106 "chart_name": "Clinical Procedures",
107 "chart_type": "Group By",
108 "document_type": "Clinical Procedure",
109 "group_by_type": "Count",
110 "group_by_based_on": "procedure_template",
111 "filters_json": json.dumps([
112 ["Clinical Procedure", "company", "=", company, False],
113 ["Clinical Procedure", "docstatus", "=", 1]
114 ]),
115 'is_public': 1,
116 "owner": "Administrator",
117 "type": "Percentage",
118 "width": "Half",
Rucha Mahabalfb297142020-05-18 16:28:11 +0530119 },
120 {
121 "doctype": "Dashboard Chart",
122 "name": "In-Patient Status",
123 "chart_name": "In-Patient Status",
124 "chart_type": "Group By",
125 "document_type": "Inpatient Record",
126 "group_by_type": "Count",
127 "group_by_based_on": "status",
Rucha Mahabal5162faa2020-05-18 18:59:59 +0530128 "filters_json": json.dumps([
129 ["Inpatient Record", "company", "=", company, False]
130 ]),
Rucha Mahabalfb297142020-05-18 16:28:11 +0530131 'is_public': 1,
132 "owner": "Administrator",
133 "type": "Bar",
134 "width": "Half",
135 },
136 {
137 "doctype": "Dashboard Chart",
138 "name": "Clinical Procedures Status",
139 "chart_name": "Clinical Procedure Status",
140 "chart_type": "Group By",
141 "document_type": "Clinical Procedure",
142 "group_by_type": "Count",
143 "group_by_based_on": "status",
Rucha Mahabal5162faa2020-05-18 18:59:59 +0530144 "filters_json": json.dumps([
145 ["Clinical Procedure", "company", "=", company, False],
146 ["Clinical Procedure", "docstatus", "=", 1]
147 ]),
Rucha Mahabalfb297142020-05-18 16:28:11 +0530148 'is_public': 1,
149 "owner": "Administrator",
150 "type": "Pie",
151 "width": "Half",
152 },
153 {
154 "doctype": "Dashboard Chart",
155 "name": "Symptoms",
156 "chart_name": "Symptoms",
157 "chart_type": "Group By",
158 "document_type": "Patient Encounter Symptom",
159 "group_by_type": "Count",
160 "group_by_based_on": "complaint",
Rucha Mahabal5162faa2020-05-18 18:59:59 +0530161 "filters_json": json.dumps({}),
Rucha Mahabalfb297142020-05-18 16:28:11 +0530162 'is_public': 1,
163 "owner": "Administrator",
164 "type": "Percentage",
165 "width": "Half",
166 },
167 {
168 "doctype": "Dashboard Chart",
169 "name": "Diagnoses",
170 "chart_name": "Diagnoses",
171 "chart_type": "Group By",
172 "document_type": "Patient Encounter Diagnosis",
173 "group_by_type": "Count",
174 "group_by_based_on": "diagnosis",
Rucha Mahabal5162faa2020-05-18 18:59:59 +0530175 "filters_json": json.dumps({}),
Rucha Mahabalfb297142020-05-18 16:28:11 +0530176 'is_public': 1,
177 "owner": "Administrator",
178 "type": "Percentage",
179 "width": "Half",
Shivam Mishra8cdcb962020-05-06 15:19:22 +0530180 }
181 ]
Rucha Mahabal24477d52020-05-18 18:15:20 +0530182
183def get_number_cards():
Rucha Mahabal5162faa2020-05-18 18:59:59 +0530184 company = get_company()
Rucha Mahabal24477d52020-05-18 18:15:20 +0530185 return [
186 {
187 "name": "Total Patients",
188 "label": "Total Patients",
189 "function": "Count",
190 "doctype": "Number Card",
191 "document_type": "Patient",
192 "filters_json": json.dumps(
193 [["Patient","status","=","Active",False]]
194 ),
195 "is_public": 1,
196 "owner": "Administrator",
197 "show_percentage_stats": 1,
198 "stats_time_interval": "Daily"
199 },
200 {
201 "name": "Total Patients Admitted",
202 "label": "Total Patients Admitted",
203 "function": "Count",
204 "doctype": "Number Card",
205 "document_type": "Patient",
206 "filters_json": json.dumps(
207 [["Patient","inpatient_status","=","Admitted",False]]
208 ),
209 "is_public": 1,
210 "owner": "Administrator",
211 "show_percentage_stats": 1,
212 "stats_time_interval": "Daily"
213 },
214 {
215 "name": "Open Appointments",
216 "label": "Open Appointments",
217 "function": "Count",
218 "doctype": "Number Card",
219 "document_type": "Patient Appointment",
220 "filters_json": json.dumps(
Rucha Mahabal5162faa2020-05-18 18:59:59 +0530221 [["Patient Appointment","company","=",company,False],
Rucha Mahabal24477d52020-05-18 18:15:20 +0530222 ["Patient Appointment","status","=","Open",False]]
223 ),
224 "is_public": 1,
225 "owner": "Administrator",
226 "show_percentage_stats": 1,
227 "stats_time_interval": "Daily"
228 },
229 {
230 "name": "Appointments to Bill",
231 "label": "Appointments to Bill",
232 "function": "Count",
233 "doctype": "Number Card",
234 "document_type": "Patient Appointment",
235 "filters_json": json.dumps(
Rucha Mahabal5162faa2020-05-18 18:59:59 +0530236 [["Patient Appointment","company","=",company,False],
Rucha Mahabal24477d52020-05-18 18:15:20 +0530237 ["Patient Appointment","invoiced","=",0,False]]
238 ),
239 "is_public": 1,
240 "owner": "Administrator",
241 "show_percentage_stats": 1,
242 "stats_time_interval": "Daily"
243 }
244 ]