feat: Department wise Patient Appointments custom chart
This commit is contained in:
parent
de3751387a
commit
b8db275a35
@ -0,0 +1,14 @@
|
|||||||
|
frappe.provide('frappe.dashboards.chart_sources');
|
||||||
|
|
||||||
|
frappe.dashboards.chart_sources["Department wise Patient Appointments"] = {
|
||||||
|
method: "erpnext.healthcare.dashboard_chart_source.department_wise_patient_appointments.department_wise_patient_appointments.get",
|
||||||
|
filters: [
|
||||||
|
{
|
||||||
|
fieldname: "company",
|
||||||
|
label: __("Company"),
|
||||||
|
fieldtype: "Link",
|
||||||
|
options: "Company",
|
||||||
|
default: frappe.defaults.get_user_default("Company")
|
||||||
|
}
|
||||||
|
]
|
||||||
|
};
|
@ -0,0 +1,13 @@
|
|||||||
|
{
|
||||||
|
"creation": "2020-05-18 19:18:42.571045",
|
||||||
|
"docstatus": 0,
|
||||||
|
"doctype": "Dashboard Chart Source",
|
||||||
|
"idx": 0,
|
||||||
|
"modified": "2020-05-18 19:18:42.571045",
|
||||||
|
"modified_by": "Administrator",
|
||||||
|
"module": "Healthcare",
|
||||||
|
"name": "Department wise Patient Appointments",
|
||||||
|
"owner": "Administrator",
|
||||||
|
"source_name": "Department wise Patient Appointments",
|
||||||
|
"timeseries": 0
|
||||||
|
}
|
@ -0,0 +1,75 @@
|
|||||||
|
# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
|
||||||
|
# License: GNU General Public License v3. See license.txt
|
||||||
|
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
import frappe, json
|
||||||
|
from frappe import _
|
||||||
|
from frappe.utils.dashboard import cache_source
|
||||||
|
from erpnext.stock.utils import get_stock_value_from_bin
|
||||||
|
|
||||||
|
@frappe.whitelist()
|
||||||
|
@cache_source
|
||||||
|
def get(chart_name = None, chart = None, no_cache = None, filters = None, from_date = None,
|
||||||
|
to_date = None, timespan = None, time_interval = None, heatmap_year = None):
|
||||||
|
if chart_name:
|
||||||
|
chart = frappe.get_doc('Dashboard Chart', chart_name)
|
||||||
|
else:
|
||||||
|
chart = frappe._dict(frappe.parse_json(chart))
|
||||||
|
|
||||||
|
labels, datapoints = [], []
|
||||||
|
filters = frappe.parse_json(filters)
|
||||||
|
|
||||||
|
data = frappe.db.get_list('Medical Department', fields=['name'])
|
||||||
|
if not filters:
|
||||||
|
filters = {}
|
||||||
|
|
||||||
|
status = ['Open', 'Scheduled', 'Closed', 'Cancelled']
|
||||||
|
for department in data:
|
||||||
|
filters['department'] = department.name
|
||||||
|
department['total_appointments'] = frappe.db.count('Patient Appointment', filters=filters)
|
||||||
|
|
||||||
|
for entry in status:
|
||||||
|
filters['status'] = entry
|
||||||
|
department[frappe.scrub(entry)] = frappe.db.count('Patient Appointment', filters=filters)
|
||||||
|
filters.pop('status')
|
||||||
|
|
||||||
|
sorted_department_map = sorted(data, key = lambda i: i['total_appointments'],reverse=True)
|
||||||
|
|
||||||
|
if len(sorted_department_map) > 10:
|
||||||
|
sorted_department_map = sorted_department_map[:10]
|
||||||
|
|
||||||
|
labels = []
|
||||||
|
open_appointments = []
|
||||||
|
scheduled = []
|
||||||
|
closed = []
|
||||||
|
cancelled = []
|
||||||
|
|
||||||
|
for department in sorted_department_map:
|
||||||
|
labels.append(department.name)
|
||||||
|
open_appointments.append(department.open)
|
||||||
|
scheduled.append(department.scheduled)
|
||||||
|
closed.append(department.closed)
|
||||||
|
cancelled.append(department.cancelled)
|
||||||
|
|
||||||
|
return {
|
||||||
|
'labels': labels,
|
||||||
|
'datasets': [
|
||||||
|
{
|
||||||
|
'name': 'Open',
|
||||||
|
'values': open_appointments
|
||||||
|
},
|
||||||
|
{
|
||||||
|
'name': 'Scheduled',
|
||||||
|
'values': scheduled
|
||||||
|
},
|
||||||
|
{
|
||||||
|
'name': 'Closed',
|
||||||
|
'values': closed
|
||||||
|
},
|
||||||
|
{
|
||||||
|
'name': 'Cancelled',
|
||||||
|
'values': cancelled
|
||||||
|
}
|
||||||
|
],
|
||||||
|
'type': 'bar'
|
||||||
|
}
|
@ -69,19 +69,20 @@ def get_charts():
|
|||||||
"doctype": "Dashboard Chart",
|
"doctype": "Dashboard Chart",
|
||||||
"name": "Department wise Patient Appointments",
|
"name": "Department wise Patient Appointments",
|
||||||
"chart_name": "Department wise Patient Appointments",
|
"chart_name": "Department wise Patient Appointments",
|
||||||
"chart_type": "Group By",
|
"chart_type": "Custom",
|
||||||
"document_type": "Patient Appointment",
|
"source": "Department wise Patient Appointments",
|
||||||
"group_by_type": "Count",
|
"filters_json": json.dumps({}),
|
||||||
"group_by_based_on": "department",
|
|
||||||
"filters_json": json.dumps([
|
|
||||||
["Patient Appointment", "company", "=", company, False],
|
|
||||||
["Patient Appointment", "status", "!=", "Cancelled"]
|
|
||||||
]),
|
|
||||||
'is_public': 1,
|
'is_public': 1,
|
||||||
"owner": "Administrator",
|
"owner": "Administrator",
|
||||||
"type": "Bar",
|
"type": "Bar",
|
||||||
"width": "Full",
|
"width": "Full",
|
||||||
"color": "#5F62F6"
|
"custom_options": json.dumps({
|
||||||
|
"colors": ["#7CD5FA", "#5F62F6", "#7544E2", "#EE5555"],
|
||||||
|
"barOptions":{
|
||||||
|
"stacked":1
|
||||||
|
},
|
||||||
|
"height": 300
|
||||||
|
})
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"doctype": "Dashboard Chart",
|
"doctype": "Dashboard Chart",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user