blob: 647d91ab604c40f5534e35ce4f45a500446a061a [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"},
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 Mahabal24477d52020-05-18 18:15:20 +053037 ],
38 "cards": [
39 { "card": "Total Patients" },
40 { "card": "Total Patient Admitted" },
41 { "card": "Open Appointments" },
42 { "card": "Appointments to Bill" }
Shivam Mishra8cdcb962020-05-06 15:19:22 +053043 ]
44 }]
45
46def get_charts():
Rucha Mahabal5162faa2020-05-18 18:59:59 +053047 company = get_company()
Shivam Mishra8cdcb962020-05-06 15:19:22 +053048 return [
49 {
50 "doctype": "Dashboard Chart",
51 "time_interval": "Daily",
Shivam Mishra41616d42020-05-06 20:21:05 +053052 "name": "Patient Appointments",
Shivam Mishra8cdcb962020-05-06 15:19:22 +053053 "chart_name": "Patient Appointments",
54 "timespan": "Last Month",
Rucha Mahabal5162faa2020-05-18 18:59:59 +053055 "filters_json": json.dumps([
56 ["Patient Appointment", "company", "=", company, False],
57 ["Patient Appointment", "status", "!=", "Cancelled"]
58 ]),
Shivam Mishra8cdcb962020-05-06 15:19:22 +053059 "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 Mahabalfb297142020-05-18 16:28:11 +053066 },
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 Mahabal5162faa2020-05-18 18:59:59 +053075 "filters_json": json.dumps([
76 ["Patient Appointment", "company", "=", company, False],
77 ["Patient Appointment", "status", "!=", "Cancelled"]
78 ]),
Rucha Mahabalfb297142020-05-18 16:28:11 +053079 '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 Mahabal5162faa2020-05-18 18:59:59 +053093 "filters_json": json.dumps([
94 ["Lab Test", "company", "=", company, False],
95 ["Lab Test", "docstatus", "=", 1]
96 ]),
Rucha Mahabalfb297142020-05-18 16:28:11 +053097 '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 Mahabal5162faa2020-05-18 18:59:59 +0530111 "filters_json": json.dumps([
112 ["Inpatient Record", "company", "=", company, False]
113 ]),
Rucha Mahabalfb297142020-05-18 16:28:11 +0530114 '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 Mahabal5162faa2020-05-18 18:59:59 +0530127 "filters_json": json.dumps([
128 ["Clinical Procedure", "company", "=", company, False],
129 ["Clinical Procedure", "docstatus", "=", 1]
130 ]),
Rucha Mahabalfb297142020-05-18 16:28:11 +0530131 '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 Mahabal5162faa2020-05-18 18:59:59 +0530144 "filters_json": json.dumps({}),
Rucha Mahabalfb297142020-05-18 16:28:11 +0530145 '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 Mahabal5162faa2020-05-18 18:59:59 +0530158 "filters_json": json.dumps({}),
Rucha Mahabalfb297142020-05-18 16:28:11 +0530159 'is_public': 1,
160 "owner": "Administrator",
161 "type": "Percentage",
162 "width": "Half",
Shivam Mishra8cdcb962020-05-06 15:19:22 +0530163 }
164 ]
Rucha Mahabal24477d52020-05-18 18:15:20 +0530165
166def get_number_cards():
Rucha Mahabal5162faa2020-05-18 18:59:59 +0530167 company = get_company()
Rucha Mahabal24477d52020-05-18 18:15:20 +0530168 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 Mahabal5162faa2020-05-18 18:59:59 +0530204 [["Patient Appointment","company","=",company,False],
Rucha Mahabal24477d52020-05-18 18:15:20 +0530205 ["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 Mahabal5162faa2020-05-18 18:59:59 +0530219 [["Patient Appointment","company","=",company,False],
Rucha Mahabal24477d52020-05-18 18:15:20 +0530220 ["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 ]