Issue with Date Displaying Incorrectly After Saving in Patient Appointment

Hello team,

I’ve encountered an issue in Frappe Health where patient appointments booked for a specific date are being displayed as the previous day after saving. I’ve reviewed the patient appointment handling code and haven’t made any modifications that could cause this.

Below is the show_availability function used in our booking system. This function sets up a dialog for booking appointments, assigns values to the form, and saves it. The issue might be related to how the appointment date is handled or saved in our system:

function show_availability() {
    let selected_practitioner = '';
    let d = new frappe.ui.Dialog({
        title: __('Available slots'),
        fields: [
            { fieldtype: 'Link', options: 'Medical Department', reqd: 1, fieldname: 'department', label: 'Medical Department' },
            { fieldtype: 'Column Break' },
            { fieldtype: 'Link', options: 'Healthcare Practitioner', reqd: 1, fieldname: 'practitioner', label: 'Healthcare Practitioner' },
            { fieldtype: 'Column Break' },
            { fieldtype: 'Date', reqd: 1, fieldname: 'appointment_date', label: 'Date', min_date: new Date(frappe.datetime.get_today()) },
            { fieldtype: 'Section Break' },
            { fieldtype: 'HTML', fieldname: 'available_slots' }
        ],
        primary_action_label: __('Book'),
        primary_action: function() {
            frm.set_value('appointment_date', d.get_value('appointment_date'));
            d.hide();
            frm.enable_save();
            frm.save();
            d.get_primary_btn().attr('disabled', true);
        }
    });

    d.set_values({
        'department': frm.doc.department,
        'practitioner': frm.doc.practitioner,
        'appointment_date': frm.doc.appointment_date
    });
}

Can anyone provide insights or suggest what might be causing this date shift? Any help would be greatly appreciated.

Thanks,
Vijayan R

Reason for date shift may be because of timezone difference. Can you confirm?

1 Like

Our server is set to the Malaysia timezone (GMT+8), as shown below:

timedatectl
    Local time: Mon 2024-04-15 21:00:14 +08
    Universal time: Mon 2024-04-15 13:00:14 UTC
    RTC time: Mon 2024-04-15 13:00:14
    Time zone: Asia/Kuala_Lumpur (+08, +0800)
    System clock synchronized: yes
    NTP service: active
    RTC in local TZ: no

Despite the database storing the appointment dates correctly, and the FormData in the console also reflecting the correct date, the display shows the appointment as being on the previous day when viewed in IST timezone, which should only have a 3-hour difference."I then checked the DocType to see if any conditions were added, but there were none.

Here’s the relevant JavaScript I used for checking the form data:

onload: function(frm) {
    if (frm.is_new()) {
        frm.set_value('appointment_time', null);
        frm.disable_save();
    }
    console.log("Current Form Data:", frm.doc);
},

Console log output:

patient_appointment__js:21 Current Form Data: {
    name: 'HLC-APP-2024-00004',
    owner: 'Administrator',
    creation: '2024-04-15 20:31:10.555613',
    modified: '2024-04-15 20:31:10.602413',
    modified_by: 'Administrator',
    ...
    appointment_date: "2024-04-15",
    appointment_datetime: "2024-04-15 19:00:00",
    appointment_time: "19:00:00",
    ...
}

However, despite this data, the appointment date is displayed incorrectly when viewed from the IST timezone. and for reference i added images also .Can anyone help me understand why this discrepancy occurs and how to correct it?

Can you please check in which timezone is your user present in ERPNext?

Yes I have given Malaysia timezone for that

Not the System Settings, the timezone for the logged in User.

timezone of logged user is IST

See the image above. When I select the appointment datetime field and complete the booking, it displays the correct date and time according to my timezone. However, the appointment date and time displayed are incorrect.

@Vijayan_R , Sorry we couldn’t replicate the issue

ok but can u provide me where will this issue can be raised it will helpful to me