Skip to content

Commit e1e1b56

Browse files
Appointment edit: reject past End Date/Time with a clear error
In the patient chart appointment edit form, the End Date/Time was accepting dates in the past. Now block save when the end is before now (message: "We can't assign a previous end date — choose a future date and time") and when the end is not after the start, with an inline field error on the End field. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent ecf8f34 commit e1e1b56

1 file changed

Lines changed: 38 additions & 0 deletions

File tree

src/vs/workbench/contrib/ciyexEhr/browser/editors/patientChartEditor.ts

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5483,6 +5483,44 @@ export class PatientChartEditor extends EditorPane {
54835483
return;
54845484
}
54855485

5486+
// Appointments: the End Date/Time must not be in the past, and must come
5487+
// after the Start — editing an appointment to a previous end date is
5488+
// invalid (a date-comparison rule a regex pattern can't express).
5489+
if (tab.key === 'appointments') {
5490+
const endEl = dialogInputs.get('end');
5491+
const startEl = dialogInputs.get('start');
5492+
const endVal = String(endEl?.value ?? '').trim();
5493+
const startVal = String(startEl?.value ?? '').trim();
5494+
const endDate = endVal ? new Date(endVal) : null;
5495+
let apptErr = '';
5496+
if (endDate && !isNaN(endDate.getTime())) {
5497+
if (endDate.getTime() < Date.now()) {
5498+
apptErr = 'We can\'t assign a previous end date — choose a future date and time.';
5499+
} else if (startVal) {
5500+
const startDate = new Date(startVal);
5501+
if (!isNaN(startDate.getTime()) && endDate.getTime() <= startDate.getTime()) {
5502+
apptErr = 'End Date/Time must be after the Start Date/Time.';
5503+
}
5504+
}
5505+
}
5506+
if (apptErr) {
5507+
const cell = dialogCells.get('end');
5508+
if (cell) {
5509+
const errMsg = DOM.append(cell, DOM.$('div.field-error'));
5510+
errMsg.textContent = apptErr;
5511+
errMsg.style.cssText = 'color:#ef4444;font-size:11px;margin-top:3px;';
5512+
}
5513+
const focusEl = (this._dateVisibleByKey.get('end') ?? (endEl as HTMLElement | undefined));
5514+
if (focusEl) {
5515+
focusEl.style.borderColor = '#ef4444';
5516+
focusEl.scrollIntoView({ behavior: 'smooth', block: 'center' });
5517+
if (typeof focusEl.focus === 'function') { focusEl.focus(); }
5518+
}
5519+
this.notificationService.warn(apptErr);
5520+
return;
5521+
}
5522+
}
5523+
54865524
const isFhir = this._isFhirResourceTab(tab);
54875525
// FHIR endpoints take patientId from the URL path, not the body.
54885526
// apiPath endpoints (e.g. /api/cds/alerts) still need patientId in the body.

0 commit comments

Comments
 (0)