Healthcare Service Unit - Tree View Updated

This commit is contained in:
Jamsheer 2018-08-01 18:40:05 +05:30
parent c64880b578
commit 4371c7e492
3 changed files with 84 additions and 3 deletions

View File

@ -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",

View File

@ -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){
$('<span class="balance-area pull-right text-muted small">'
+ " " + node.data.occupied_out_of_vacant
+ '</span>').insertBefore(node.$ul);
}
if (node.data && node.data.inpatient_occupancy!==undefined) {
if (node.data.inpatient_occupancy == 1){
if (node.data.occupancy_status == "Occupied"){
$('<span class="balance-area pull-right small">'
+ " " + node.data.occupancy_status
+ '</span>').insertBefore(node.$ul);
}
if (node.data.occupancy_status == "Vacant"){
$('<span class="balance-area pull-right text-muted small">'
+ " " + node.data.occupancy_status
+ '</span>').insertBefore(node.$ul);
}
}
}
},
};

View File

@ -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