2020-05-06 09:49:22 +00:00
|
|
|
# Copyright (c) 2020, Frappe Technologies Pvt. Ltd. and Contributors
|
|
|
|
# License: GNU General Public License v3. See license.txt
|
|
|
|
|
|
|
|
import frappe
|
|
|
|
import json
|
2020-05-19 15:28:00 +00:00
|
|
|
from frappe import _
|
2020-05-06 09:49:22 +00:00
|
|
|
|
|
|
|
def get_data():
|
|
|
|
return frappe._dict({
|
|
|
|
"dashboards": get_dashboards(),
|
|
|
|
"charts": get_charts(),
|
2020-05-18 12:45:20 +00:00
|
|
|
"number_cards": get_number_cards(),
|
2020-05-06 09:49:22 +00:00
|
|
|
})
|
|
|
|
|
2020-05-18 12:45:20 +00:00
|
|
|
def get_company():
|
|
|
|
company = frappe.defaults.get_defaults().company
|
|
|
|
if company:
|
|
|
|
return company
|
|
|
|
else:
|
|
|
|
company = frappe.get_list("Company", limit=1)
|
|
|
|
if company:
|
2020-05-24 16:25:47 +00:00
|
|
|
return company[0].name
|
2020-05-18 12:45:20 +00:00
|
|
|
return None
|
|
|
|
|
2020-05-06 09:49:22 +00:00
|
|
|
def get_dashboards():
|
|
|
|
return [{
|
|
|
|
"name": "Healthcare",
|
|
|
|
"dashboard_name": "Healthcare",
|
|
|
|
"charts": [
|
2020-05-18 10:58:11 +00:00
|
|
|
{ "chart": "Patient Appointments", "width": "Full"},
|
|
|
|
{ "chart": "In-Patient Status", "width": "Half"},
|
|
|
|
{ "chart": "Clinical Procedures Status", "width": "Half"},
|
2020-05-18 13:45:08 +00:00
|
|
|
{ "chart": "Lab Tests", "width": "Half"},
|
|
|
|
{ "chart": "Clinical Procedures", "width": "Half"},
|
2020-05-18 10:58:11 +00:00
|
|
|
{ "chart": "Symptoms", "width": "Half"},
|
|
|
|
{ "chart": "Diagnoses", "width": "Half"},
|
2020-05-18 13:45:08 +00:00
|
|
|
{ "chart": "Department wise Patient Appointments", "width": "Full"}
|
2020-05-18 12:45:20 +00:00
|
|
|
],
|
|
|
|
"cards": [
|
|
|
|
{ "card": "Total Patients" },
|
|
|
|
{ "card": "Total Patient Admitted" },
|
|
|
|
{ "card": "Open Appointments" },
|
|
|
|
{ "card": "Appointments to Bill" }
|
2020-05-06 09:49:22 +00:00
|
|
|
]
|
|
|
|
}]
|
|
|
|
|
|
|
|
def get_charts():
|
2020-05-18 13:29:59 +00:00
|
|
|
company = get_company()
|
2020-05-06 09:49:22 +00:00
|
|
|
return [
|
|
|
|
{
|
|
|
|
"doctype": "Dashboard Chart",
|
|
|
|
"time_interval": "Daily",
|
2020-05-06 14:51:05 +00:00
|
|
|
"name": "Patient Appointments",
|
2020-05-19 15:28:00 +00:00
|
|
|
"chart_name": _("Patient Appointments"),
|
2020-05-06 09:49:22 +00:00
|
|
|
"timespan": "Last Month",
|
2020-05-18 13:29:59 +00:00
|
|
|
"filters_json": json.dumps([
|
|
|
|
["Patient Appointment", "company", "=", company, False],
|
|
|
|
["Patient Appointment", "status", "!=", "Cancelled"]
|
|
|
|
]),
|
2020-05-06 09:49:22 +00:00
|
|
|
"chart_type": "Count",
|
|
|
|
"timeseries": 1,
|
|
|
|
"based_on": "appointment_datetime",
|
|
|
|
"owner": "Administrator",
|
|
|
|
"document_type": "Patient Appointment",
|
|
|
|
"type": "Line",
|
|
|
|
"width": "Half"
|
2020-05-18 10:58:11 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
"doctype": "Dashboard Chart",
|
|
|
|
"name": "Department wise Patient Appointments",
|
2020-05-19 15:28:00 +00:00
|
|
|
"chart_name": _("Department wise Patient Appointments"),
|
2020-05-18 20:16:48 +00:00
|
|
|
"chart_type": "Custom",
|
|
|
|
"source": "Department wise Patient Appointments",
|
2020-05-28 13:33:37 +00:00
|
|
|
"filters_json": json.dumps([]),
|
2020-05-18 10:58:11 +00:00
|
|
|
'is_public': 1,
|
|
|
|
"owner": "Administrator",
|
|
|
|
"type": "Bar",
|
|
|
|
"width": "Full",
|
2020-05-18 20:16:48 +00:00
|
|
|
"custom_options": json.dumps({
|
|
|
|
"colors": ["#7CD5FA", "#5F62F6", "#7544E2", "#EE5555"],
|
|
|
|
"barOptions":{
|
|
|
|
"stacked":1
|
|
|
|
},
|
|
|
|
"height": 300
|
|
|
|
})
|
2020-05-18 10:58:11 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
"doctype": "Dashboard Chart",
|
|
|
|
"name": "Lab Tests",
|
2020-05-19 15:28:00 +00:00
|
|
|
"chart_name": _("Lab Tests"),
|
2020-05-18 10:58:11 +00:00
|
|
|
"chart_type": "Group By",
|
|
|
|
"document_type": "Lab Test",
|
|
|
|
"group_by_type": "Count",
|
|
|
|
"group_by_based_on": "template",
|
2020-05-18 13:29:59 +00:00
|
|
|
"filters_json": json.dumps([
|
|
|
|
["Lab Test", "company", "=", company, False],
|
|
|
|
["Lab Test", "docstatus", "=", 1]
|
|
|
|
]),
|
2020-05-18 10:58:11 +00:00
|
|
|
'is_public': 1,
|
|
|
|
"owner": "Administrator",
|
2020-05-18 13:45:08 +00:00
|
|
|
"type": "Percentage",
|
|
|
|
"width": "Half",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"doctype": "Dashboard Chart",
|
|
|
|
"name": "Clinical Procedures",
|
2020-05-19 15:28:00 +00:00
|
|
|
"chart_name": _("Clinical Procedures"),
|
2020-05-18 13:45:08 +00:00
|
|
|
"chart_type": "Group By",
|
|
|
|
"document_type": "Clinical Procedure",
|
|
|
|
"group_by_type": "Count",
|
|
|
|
"group_by_based_on": "procedure_template",
|
|
|
|
"filters_json": json.dumps([
|
|
|
|
["Clinical Procedure", "company", "=", company, False],
|
|
|
|
["Clinical Procedure", "docstatus", "=", 1]
|
|
|
|
]),
|
|
|
|
'is_public': 1,
|
|
|
|
"owner": "Administrator",
|
|
|
|
"type": "Percentage",
|
|
|
|
"width": "Half",
|
2020-05-18 10:58:11 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
"doctype": "Dashboard Chart",
|
|
|
|
"name": "In-Patient Status",
|
2020-05-19 15:28:00 +00:00
|
|
|
"chart_name": _("In-Patient Status"),
|
2020-05-18 10:58:11 +00:00
|
|
|
"chart_type": "Group By",
|
|
|
|
"document_type": "Inpatient Record",
|
|
|
|
"group_by_type": "Count",
|
|
|
|
"group_by_based_on": "status",
|
2020-05-18 13:29:59 +00:00
|
|
|
"filters_json": json.dumps([
|
|
|
|
["Inpatient Record", "company", "=", company, False]
|
|
|
|
]),
|
2020-05-18 10:58:11 +00:00
|
|
|
'is_public': 1,
|
|
|
|
"owner": "Administrator",
|
|
|
|
"type": "Bar",
|
|
|
|
"width": "Half",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"doctype": "Dashboard Chart",
|
|
|
|
"name": "Clinical Procedures Status",
|
2020-05-19 15:28:00 +00:00
|
|
|
"chart_name": _("Clinical Procedure Status"),
|
2020-05-18 10:58:11 +00:00
|
|
|
"chart_type": "Group By",
|
|
|
|
"document_type": "Clinical Procedure",
|
|
|
|
"group_by_type": "Count",
|
|
|
|
"group_by_based_on": "status",
|
2020-05-18 13:29:59 +00:00
|
|
|
"filters_json": json.dumps([
|
|
|
|
["Clinical Procedure", "company", "=", company, False],
|
|
|
|
["Clinical Procedure", "docstatus", "=", 1]
|
|
|
|
]),
|
2020-05-18 10:58:11 +00:00
|
|
|
'is_public': 1,
|
|
|
|
"owner": "Administrator",
|
|
|
|
"type": "Pie",
|
|
|
|
"width": "Half",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"doctype": "Dashboard Chart",
|
|
|
|
"name": "Symptoms",
|
2020-05-19 15:28:00 +00:00
|
|
|
"chart_name": _("Symptoms"),
|
2020-05-18 10:58:11 +00:00
|
|
|
"chart_type": "Group By",
|
|
|
|
"document_type": "Patient Encounter Symptom",
|
|
|
|
"group_by_type": "Count",
|
|
|
|
"group_by_based_on": "complaint",
|
2020-05-28 13:33:37 +00:00
|
|
|
"filters_json": json.dumps([]),
|
2020-05-18 10:58:11 +00:00
|
|
|
'is_public': 1,
|
|
|
|
"owner": "Administrator",
|
|
|
|
"type": "Percentage",
|
|
|
|
"width": "Half",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"doctype": "Dashboard Chart",
|
|
|
|
"name": "Diagnoses",
|
2020-05-19 15:28:00 +00:00
|
|
|
"chart_name": _("Diagnoses"),
|
2020-05-18 10:58:11 +00:00
|
|
|
"chart_type": "Group By",
|
|
|
|
"document_type": "Patient Encounter Diagnosis",
|
|
|
|
"group_by_type": "Count",
|
|
|
|
"group_by_based_on": "diagnosis",
|
2020-05-28 13:33:37 +00:00
|
|
|
"filters_json": json.dumps([]),
|
2020-05-18 10:58:11 +00:00
|
|
|
'is_public': 1,
|
|
|
|
"owner": "Administrator",
|
|
|
|
"type": "Percentage",
|
|
|
|
"width": "Half",
|
2020-05-06 09:49:22 +00:00
|
|
|
}
|
|
|
|
]
|
2020-05-18 12:45:20 +00:00
|
|
|
|
|
|
|
def get_number_cards():
|
2020-05-18 13:29:59 +00:00
|
|
|
company = get_company()
|
2020-05-18 12:45:20 +00:00
|
|
|
return [
|
|
|
|
{
|
|
|
|
"name": "Total Patients",
|
2020-05-19 15:28:00 +00:00
|
|
|
"label": _("Total Patients"),
|
2020-05-18 12:45:20 +00:00
|
|
|
"function": "Count",
|
|
|
|
"doctype": "Number Card",
|
|
|
|
"document_type": "Patient",
|
|
|
|
"filters_json": json.dumps(
|
|
|
|
[["Patient","status","=","Active",False]]
|
|
|
|
),
|
|
|
|
"is_public": 1,
|
|
|
|
"owner": "Administrator",
|
|
|
|
"show_percentage_stats": 1,
|
|
|
|
"stats_time_interval": "Daily"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"name": "Total Patients Admitted",
|
2020-05-19 15:28:00 +00:00
|
|
|
"label": _("Total Patients Admitted"),
|
2020-05-18 12:45:20 +00:00
|
|
|
"function": "Count",
|
|
|
|
"doctype": "Number Card",
|
|
|
|
"document_type": "Patient",
|
|
|
|
"filters_json": json.dumps(
|
|
|
|
[["Patient","inpatient_status","=","Admitted",False]]
|
|
|
|
),
|
|
|
|
"is_public": 1,
|
|
|
|
"owner": "Administrator",
|
|
|
|
"show_percentage_stats": 1,
|
|
|
|
"stats_time_interval": "Daily"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"name": "Open Appointments",
|
2020-05-19 15:28:00 +00:00
|
|
|
"label": _("Open Appointments"),
|
2020-05-18 12:45:20 +00:00
|
|
|
"function": "Count",
|
|
|
|
"doctype": "Number Card",
|
|
|
|
"document_type": "Patient Appointment",
|
|
|
|
"filters_json": json.dumps(
|
2020-05-18 13:29:59 +00:00
|
|
|
[["Patient Appointment","company","=",company,False],
|
2020-05-18 12:45:20 +00:00
|
|
|
["Patient Appointment","status","=","Open",False]]
|
|
|
|
),
|
|
|
|
"is_public": 1,
|
|
|
|
"owner": "Administrator",
|
|
|
|
"show_percentage_stats": 1,
|
|
|
|
"stats_time_interval": "Daily"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"name": "Appointments to Bill",
|
2020-05-28 13:33:37 +00:00
|
|
|
"label": _("Appointments To Bill"),
|
2020-05-18 12:45:20 +00:00
|
|
|
"function": "Count",
|
|
|
|
"doctype": "Number Card",
|
|
|
|
"document_type": "Patient Appointment",
|
|
|
|
"filters_json": json.dumps(
|
2020-05-18 13:29:59 +00:00
|
|
|
[["Patient Appointment","company","=",company,False],
|
2020-05-18 12:45:20 +00:00
|
|
|
["Patient Appointment","invoiced","=",0,False]]
|
|
|
|
),
|
|
|
|
"is_public": 1,
|
|
|
|
"owner": "Administrator",
|
|
|
|
"show_percentage_stats": 1,
|
|
|
|
"stats_time_interval": "Daily"
|
|
|
|
}
|
|
|
|
]
|