Skip to content

(fix) O3-5387: Remove redundant mathematical operation and improve type safety in appointments#2233

Open
sanks011 wants to merge 5 commits intoopenmrs:mainfrom
sanks011:O3-5387-redundant-mathematical-operation-in-use-patient-appointment-history
Open

(fix) O3-5387: Remove redundant mathematical operation and improve type safety in appointments#2233
sanks011 wants to merge 5 commits intoopenmrs:mainfrom
sanks011:O3-5387-redundant-mathematical-operation-in-use-patient-appointment-history

Conversation

@sanks011
Copy link

Requirements

  • This PR has a title that briefly describes the work done including the ticket number. If there is a ticket, make sure your PR title includes a conventional commit label. See existing PR titles for inspiration.
  • My work is based on designs, which are linked or shown either in the Jira ticket or the description below.
  • My work includes tests or is validated by existing tests.

Summary

This PR addresses code quality and type safety issues in the appointments app:

1. Removed Redundant Mathematical Operation

  • Fixed redundant calculation (appointment.startDateTime / 1000) * 1000 in usePatientAppointmentHistory.ts
  • This was a mathematical no-op that provided no functional benefit
  • Replaced with consistent date handling pattern: dayjs(new Date(appointment.startDateTime).toISOString())
  • Now matches the pattern used in 8+ other files across the appointments codebase

2. Improved Type Safety

  • Changed startDateTime type from string | any to string | number in the Appointment interface
  • Removed unsafe any type annotation that defeated TypeScript's type checking
  • Added explicit String() conversion for parseDate calls in 3 component files to handle both formats
  • Properly handles both Unix timestamp (number) and ISO string (string) formats from the API

Benefits

  • ✅ Improved code maintainability and readability
  • ✅ Better TypeScript type safety without using any
  • ✅ Consistent date handling across the codebase
  • ✅ No breaking changes - all existing tests pass (44 passed)

Screenshots

N/A - No UI changes

Related Issue

https://openmrs.atlassian.net/browse/O3-5387

Other

All existing tests pass successfully. The changes maintain backward compatibility while improving code quality.

Copy link
Contributor

@jwnasambu jwnasambu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sanks011 Kindly resolve the merge conflicts please!

renderIcon={Download}
onClick={() => {
const date = appointments[0]?.startDateTime
? formatDate(parseDate(String(appointments[0]?.startDateTime)), {
Copy link
Contributor

@jwnasambu jwnasambu Feb 18, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Kindly this parseDate(appointment.startDateTime) should work because parseDate likely already handles both formats.

Alternatively convert number timestamps to ISO strings before parsing

const dateString = typeof appointment.startDateTime === 'number'
  ? new Date(appointment.startDateTime).toISOString()
  : appointment.startDateTime;

parseDate(dateString)

cc @denniskigen , @NethmiRodrigo , @ibacher Kindly can I learn from you please!

return {
id: appointment.uuid,
date: formatDatetime(parseDate(appointment.startDateTime), { mode: 'wide' }),
date: formatDatetime(parseDate(String(appointment.startDateTime)), { mode: 'wide' }),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Kindly we should remove String() wrapper entirely because type is updated to string | number in the interface so parseDate() should handle both formats natively.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed - removed the String() wrappers entirely and rebased on latest [main]. [usePatientAppointmentHistory.ts] (removed the redundant math) and [index.ts] ([startDateTime: string | any] → [startDateTime: string])

<StructuredListRow key={index} className={styles.structuredList}>
<StructuredListCell>
{formatDate(parseDate(appointment.startDateTime), { mode: 'wide' })}
{formatDate(parseDate(String(appointment.startDateTime)), { mode: 'wide' })}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Kindly remove the String() wrapper entirely. The parseDate() already handles both formats.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed - removed the String() wrappers entirely and rebased on latest [main]. [usePatientAppointmentHistory.ts] (removed the redundant math) and [index.ts] ([startDateTime: string | any] → [startDateTime: string])

@sanks011 sanks011 force-pushed the O3-5387-redundant-mathematical-operation-in-use-patient-appointment-history branch from 14b9062 to 9087750 Compare February 18, 2026 16:41
@sanks011
Copy link
Author

@jwnasambu Thanks for the review! The String() wrapper has been removed. Also worth noting - the entire download button section where this code lived was subsequently removed in a later upstream commit (#2263), so this file no longer contains that code at all after the rebase.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants