[Feature] Add default duration and color to appointment type (#13296)

* Add default duration and color to appointment type

When creating a Patient Appointment, the Duration field will be populated when the Appointment Type is set. This is preserved when checking availability and booking an appointment.
`Appointment Type.color` is used in the calendar display.

* Remove accidental fixed date from git

* Update modified timestamp to ensure migrations.

Set to the timestamp of dd506a0961437540872c01d3487b8e37806c0bb0
This commit is contained in:
Tom Price 2018-03-20 06:38:44 +00:00 committed by Nabin Hait
parent f572522f25
commit cd525299ee
5 changed files with 93 additions and 14 deletions

View File

@ -71,6 +71,67 @@
"search_index": 0, "search_index": 0,
"set_only_once": 0, "set_only_once": 0,
"unique": 0 "unique": 0
},
{
"allow_bulk_edit": 0,
"allow_on_submit": 0,
"bold": 1,
"collapsible": 0,
"columns": 0,
"description": "In Minutes",
"fieldname": "default_duration",
"fieldtype": "Int",
"hidden": 1,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 1,
"in_global_search": 0,
"in_list_view": 1,
"in_standard_filter": 0,
"label": "Default Duration",
"length": 0,
"no_copy": 0,
"permlevel": 0,
"precision": "",
"print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 0,
"remember_last_selected_value": 0,
"report_hide": 0,
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
"unique": 0
},
{
"allow_bulk_edit": 0,
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"columns": 0,
"fieldname": "color",
"fieldtype": "Color",
"hidden": 1,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_global_search": 0,
"in_list_view": 1,
"in_standard_filter": 0,
"label": "Color",
"length": 0,
"no_copy": 1,
"permlevel": 0,
"precision": "",
"print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 0,
"remember_last_selected_value": 0,
"report_hide": 1,
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
"unique": 0
} }
], ],
"has_web_view": 0, "has_web_view": 0,
@ -83,7 +144,7 @@
"issingle": 0, "issingle": 0,
"istable": 0, "istable": 0,
"max_attachments": 0, "max_attachments": 0,
"modified": "2017-10-05 11:07:26.369657", "modified": "2018-03-13 12:10:00.123456",
"modified_by": "Administrator", "modified_by": "Administrator",
"module": "Healthcare", "module": "Healthcare",
"name": "Appointment Type", "name": "Appointment Type",

View File

@ -137,6 +137,7 @@ frappe.ui.form.on('Patient Appointment', {
var slot_details = data.slot_details; var slot_details = data.slot_details;
var slot_html = ""; var slot_html = "";
var duration = frm.doc.duration | 0;
$.each(slot_details, function(i, slot_detail){ $.each(slot_details, function(i, slot_detail){
slot_html = slot_html + `<label>${slot_detail['slot_name']}</label>`; slot_html = slot_html + `<label>${slot_detail['slot_name']}</label>`;
slot_html = slot_html + `<br/>` + slot_detail['avail_slot'].map(slot => { slot_html = slot_html + `<br/>` + slot_detail['avail_slot'].map(slot => {
@ -155,7 +156,7 @@ frappe.ui.form.on('Patient Appointment', {
} }
start_time = booked_moment; start_time = booked_moment;
let end_time = booked_moment.add(booked.duration, 'minutes'); let end_time = booked_moment.add(booked.duration, 'minutes');
if(end_time.isSameOrAfter(to_time)){ if(end_time.isSameOrAfter(to_time) || end_time.add(duration).isAfter(to_time)){
disabled = 'disabled="disabled"'; disabled = 'disabled="disabled"';
return false; return false;
}else{ }else{
@ -163,9 +164,10 @@ frappe.ui.form.on('Patient Appointment', {
} }
} }
}); });
return `<button class="btn btn-default" return `<button class="btn btn-default"
data-name=${start_str} data-name=${start_str}
data-duration=${interval} data-duration=${duration || interval}
data-service-unit="${slot_detail['service_unit'] || ''}" data-service-unit="${slot_detail['service_unit'] || ''}"
style="margin: 0 10px 10px 0; width: 72px;" ${disabled}> style="margin: 0 10px 10px 0; width: 72px;" ${disabled}>
${start_str.substring(0, start_str.length - 3)} ${start_str.substring(0, start_str.length - 3)}
@ -293,6 +295,21 @@ frappe.ui.form.on("Patient Appointment", "patient", function(frm) {
} }
}); });
frappe.ui.form.on("Patient Appointment", "appointment_type", function(frm) {
if(frm.doc.appointment_type) {
frappe.call({
"method": "frappe.client.get",
args: {
doctype: "Appointment Type",
name: frm.doc.appointment_type
},
callback: function (data) {
frappe.model.set_value(frm.doctype,frm.docname, "duration",data.message.default_duration);
}
});
}
});
var calculate_age = function(birth) { var calculate_age = function(birth) {
var ageMS = Date.parse(Date()) - Date.parse(birth); var ageMS = Date.parse(Date()) - Date.parse(birth);
var age = new Date(); var age = new Date();

View File

@ -176,17 +176,16 @@
"allow_on_submit": 0, "allow_on_submit": 0,
"bold": 0, "bold": 0,
"collapsible": 0, "collapsible": 0,
"columns": 0, "columns": 0,
"depends_on": "eval:!doc.__islocal",
"description": "In Minutes", "description": "In Minutes",
"fieldname": "duration", "fieldname": "duration",
"fieldtype": "Int", "fieldtype": "Int",
"hidden": 0, "hidden": 0,
"ignore_user_permissions": 0, "ignore_user_permissions": 0,
"ignore_xss_filter": 0, "ignore_xss_filter": 0,
"in_filter": 0, "in_filter": 1,
"in_global_search": 0, "in_global_search": 0,
"in_list_view": 0, "in_list_view": 1,
"in_standard_filter": 0, "in_standard_filter": 0,
"label": "Duration", "label": "Duration",
"length": 0, "length": 0,
@ -755,7 +754,7 @@
"issingle": 0, "issingle": 0,
"istable": 0, "istable": 0,
"max_attachments": 0, "max_attachments": 0,
"modified": "2018-02-26 12:44:33.756124", "modified": "2018-03-13 12:10:00.123456",
"modified_by": "Administrator", "modified_by": "Administrator",
"module": "Healthcare", "module": "Healthcare",
"name": "Patient Appointment", "name": "Patient Appointment",

View File

@ -327,11 +327,12 @@ def get_events(start, end, filters=None):
""" """
from frappe.desk.calendar import get_event_conditions from frappe.desk.calendar import get_event_conditions
conditions = get_event_conditions("Patient Appointment", filters) conditions = get_event_conditions("Patient Appointment", filters)
data = frappe.db.sql("""select name, patient, physician, status, data = frappe.db.sql("""select `tabPatient Appointment`.name, patient, physician, status,
duration, timestamp(appointment_date, appointment_time) as duration, timestamp(appointment_date, appointment_time) as 'start', type.color as 'color'
'start' from `tabPatient Appointment` where from `tabPatient Appointment`
(appointment_date between %(start)s and %(end)s) left join `tabAppointment Type` as type on `tabPatient Appointment`.appointment_type=type.name
and docstatus < 2 {conditions}""".format(conditions=conditions), where (appointment_date between %(start)s and %(end)s )
and `tabPatient Appointment`.docstatus < 2 {conditions}""".format(conditions=conditions),
{"start": start, "end": end}, as_dict=True, update={"allDay": 0}) {"start": start, "end": end}, as_dict=True, update={"allDay": 0})
for item in data: for item in data:
item.end = item.start + datetime.timedelta(minutes = item.duration) item.end = item.start + datetime.timedelta(minutes = item.duration)

View File

@ -5,7 +5,8 @@ frappe.views.calendar["Patient Appointment"] = {
"end": "end", "end": "end",
"id": "name", "id": "name",
"title": "patient", "title": "patient",
"allDay": "allDay" "allDay": "allDay",
"eventColor": "color"
}, },
gantt: true, gantt: true,
get_events_method: "erpnext.healthcare.doctype.patient_appointment.patient_appointment.get_events", get_events_method: "erpnext.healthcare.doctype.patient_appointment.patient_appointment.get_events",