diff --git a/erpnext/healthcare/doctype/healthcare_service_unit/healthcare_service_unit.json b/erpnext/healthcare/doctype/healthcare_service_unit/healthcare_service_unit.json
index a7e69329de..79af7ae15c 100644
--- a/erpnext/healthcare/doctype/healthcare_service_unit/healthcare_service_unit.json
+++ b/erpnext/healthcare/doctype/healthcare_service_unit/healthcare_service_unit.json
@@ -116,7 +116,7 @@
"allow_bulk_edit": 0,
"allow_in_quick_entry": 0,
"allow_on_submit": 0,
- "bold": 0,
+ "bold": 1,
"collapsible": 0,
"columns": 0,
"depends_on": "eval:doc.is_group != 1",
@@ -461,7 +461,7 @@
"issingle": 0,
"istable": 0,
"max_attachments": 0,
- "modified": "2018-07-30 15:09:57.016256",
+ "modified": "2018-08-01 17:32:53.968441",
"modified_by": "Administrator",
"module": "Healthcare",
"name": "Healthcare Service Unit",
diff --git a/erpnext/healthcare/doctype/healthcare_service_unit/healthcare_service_unit_tree.js b/erpnext/healthcare/doctype/healthcare_service_unit/healthcare_service_unit_tree.js
index 4eb9475a33..a03b579c50 100644
--- a/erpnext/healthcare/doctype/healthcare_service_unit/healthcare_service_unit_tree.js
+++ b/erpnext/healthcare/doctype/healthcare_service_unit/healthcare_service_unit_tree.js
@@ -1,3 +1,35 @@
frappe.treeview_settings["Healthcare Service Unit"] = {
- ignore_fields:["parent_healthcare_service_unit"]
+ breadcrumbs: "Healthcare Service Unit",
+ title: __("Healthcare Service Unit"),
+ get_tree_root: false,
+ filters: [{
+ fieldname: "company",
+ fieldtype: "Select",
+ options: erpnext.utils.get_tree_options("company"),
+ label: __("Company"),
+ default: erpnext.utils.get_tree_default("company")
+ }],
+ get_tree_nodes: 'erpnext.healthcare.utils.get_children',
+ ignore_fields:["parent_healthcare_service_unit"],
+ onrender: function(node) {
+ if (node.data.occupied_out_of_vacant!==undefined){
+ $(''
+ + " " + node.data.occupied_out_of_vacant
+ + '').insertBefore(node.$ul);
+ }
+ if (node.data && node.data.inpatient_occupancy!==undefined) {
+ if (node.data.inpatient_occupancy == 1){
+ if (node.data.occupancy_status == "Occupied"){
+ $(''
+ + " " + node.data.occupancy_status
+ + '').insertBefore(node.$ul);
+ }
+ if (node.data.occupancy_status == "Vacant"){
+ $(''
+ + " " + node.data.occupancy_status
+ + '').insertBefore(node.$ul);
+ }
+ }
+ }
+ },
};
diff --git a/erpnext/healthcare/utils.py b/erpnext/healthcare/utils.py
index b6b733025c..3372e1d81e 100644
--- a/erpnext/healthcare/utils.py
+++ b/erpnext/healthcare/utils.py
@@ -350,3 +350,52 @@ def get_drugs_to_invoice(encounter):
item_to_invoice.append({'drug_code': drug_line.drug_code, 'quantity': qty,
'description': drug_line.dosage+" for "+drug_line.period})
return item_to_invoice
+
+@frappe.whitelist()
+def get_children(doctype, parent, company, is_root=False):
+ parent_fieldname = 'parent_' + doctype.lower().replace(' ', '_')
+ fields = [
+ 'name as value',
+ 'is_group as expandable',
+ 'lft',
+ 'rgt'
+ ]
+ # fields = [ 'name', 'is_group', 'lft', 'rgt' ]
+ filters = [['ifnull(`{0}`,"")'.format(parent_fieldname), '=', '' if is_root else parent]]
+
+ if is_root:
+ fields += ['service_unit_type'] if doctype == 'Healthcare Service Unit' else []
+ filters.append(['company', '=', company])
+
+ else:
+ fields += ['service_unit_type', 'allow_appointments', 'inpatient_occupancy', 'occupancy_status'] if doctype == 'Healthcare Service Unit' else []
+ fields += [parent_fieldname + ' as parent']
+
+ hc_service_units = frappe.get_list(doctype, fields=fields, filters=filters)
+
+ if doctype == 'Healthcare Service Unit':
+ for each in hc_service_units:
+ occupancy_msg = ""
+ if each['expandable'] == 1:
+ occupied = False
+ vacant = False
+ child_list = frappe.db.sql("""
+ select name, occupancy_status from `tabHealthcare Service Unit`
+ where inpatient_occupancy = 1 and
+ lft > %s and rgt < %s""",
+ (each['lft'], each['rgt']))
+ for child in child_list:
+ print child[0], child[1]
+ if not occupied:
+ occupied = 0
+ if child[1] == "Occupied":
+ occupied += 1
+ if not vacant:
+ vacant = 0
+ if child[1] == "Vacant":
+ vacant += 1
+ if vacant and occupied:
+ occupancy_total = vacant+occupied
+ occupancy_msg = str(occupied) + " Occupied out of " + str(occupancy_total)
+ each["occupied_out_of_vacant"] = occupancy_msg
+ return hc_service_units