Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

O3-2476 - Remove unnecessary conversion from date to string back to date #836

Merged
merged 4 commits into from
Oct 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React from 'react';
import { render, screen, act } from '@testing-library/react';
import VisitDetailComponent from './visit-detail.component';
import { useVisit } from './visit.resource';
import { formatDate } from '@openmrs/esm-framework';

jest.mock('./visit.resource');

Expand All @@ -23,11 +24,12 @@ describe('VisitDetailComponent', () => {
});

it('should render visit details and switches when data is available', () => {
let visitDate = new Date();
mockedUseVisit.mockReturnValueOnce({
visit: {
uuid: visitUuid,
visitType: { display: 'Some Visit Type' },
startDatetime: '2023-07-29T12:34:56Z',
startDatetime: visitDate,
encounters: [],
},
isLoading: false,
Expand All @@ -36,7 +38,7 @@ describe('VisitDetailComponent', () => {
render(<VisitDetailComponent visitUuid={visitUuid} patientUuid={patientUuid} />);

expect(screen.getByText(/Some Visit Type/)).toBeInTheDocument();
expect(screen.getByText(/29-Jul-2023, 12:34 PM/)).toBeInTheDocument();
expect(screen.getByText(formatDate(visitDate))).toBeInTheDocument();

Copy link
Member Author

Choose a reason for hiding this comment

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

This test started failing after I made the changes described. But this should not have been passing before if I'm understanding right, because a startDatetime with a "Z" at the end indicates UTC, but my computer running these tests is in EDT, so this shows up as 08:34 AM, not 12:34 PM. I've just changed the test to use a locally generated date, so whatever is passed is the same as what is tested. But it seems that this is potentially a fixed bug.

expect(screen.getByText('All Encounters')).toBeInTheDocument();
expect(screen.getByText('Visit Summary')).toBeInTheDocument();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ const AppointmentDetails: React.FC<AppointmentDetailsProps> = ({ appointment })
<span className={styles.historyGridCount}>{appointmentsCount.cancelledAppointments}</span>
</div>
<div>
<p className={styles.historyGridLabel}>{t('upcomming', 'Upcoming')}</p>
<p className={styles.historyGridLabel}>{t('upcoming', 'Upcoming')}</p>
Copy link
Member Author

Choose a reason for hiding this comment

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

Not sure where this came from - this cropped up as message changes when I tried to commit, I noticed this typo, so I fixed it (which enabled us to not lose the existing translations).

<span className={styles.historyGridCount}>{appointmentsCount.upcomingAppointments}</span>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export async function saveQueueEntry(
patient: {
uuid: patientUuid,
},
startedAt: toDateObjectStrict(toOmrsIsoString(new Date())),
startedAt: new Date(),
Copy link
Member Author

Choose a reason for hiding this comment

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

Most of the changes in this PR are this. Find/replace wherever we are converting from date->string->date and just using the original date instead.

sortWeight: sortWeight,
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,12 @@ const VisitForm: React.FC<VisitFormProps> = ({ patientUuid, appointment }) => {

const payload: NewVisitPayload = {
patient: patientUuid,
startDatetime: toDateObjectStrict(
toOmrsIsoString(
new Date(dayjs(visitDate).year(), dayjs(visitDate).month(), dayjs(visitDate).date(), hours, minutes),
),
startDatetime: new Date(
dayjs(visitDate).year(),
dayjs(visitDate).month(),
dayjs(visitDate).date(),
hours,
minutes,
),
Comment on lines +101 to 107
Copy link
Member

Choose a reason for hiding this comment

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

It might be easier to write this as:

Suggested change
startDatetime: new Date(
dayjs(visitDate).year(),
dayjs(visitDate).month(),
dayjs(visitDate).date(),
hours,
minutes,
),
startDatetime: dayjs(visitDate).set('hour', hours).set('minute', minutes).startOf('minute').toDate()

Copy link
Member Author

Choose a reason for hiding this comment

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

Agreed that this might be better, but since I haven't tested that, and the current retains the existing approach, I'll leave it for now.

visitType: visitType,
location: selectedLocation,
Expand Down
2 changes: 1 addition & 1 deletion packages/esm-appointments-app/translations/am.json
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@
"unscheduled": "Unscheduled",
"unscheduledAppointments": "Unscheduled appointments",
"unscheduledAppointments_lower": "unscheduled appointments",
"upcomming": "Upcoming",
"upcoming": "Upcoming",
"view": "View",
"viewCalendar": "View Calendar",
"visitLocation": "Visit Location",
Expand Down
2 changes: 1 addition & 1 deletion packages/esm-appointments-app/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@
"unscheduled": "Unscheduled",
"unscheduledAppointments": "Unscheduled appointments",
"unscheduledAppointments_lower": "unscheduled appointments",
"upcomming": "Upcoming",
"upcoming": "Upcoming",
"view": "View",
"viewCalendar": "View Calendar",
"visitLocation": "Visit Location",
Expand Down
2 changes: 1 addition & 1 deletion packages/esm-appointments-app/translations/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@
"unscheduled": "Unscheduled",
"unscheduledAppointments": "Unscheduled appointments",
"unscheduledAppointments_lower": "unscheduled appointments",
"upcomming": "Upcoming",
"upcoming": "Upcoming",
"view": "View",
"viewCalendar": "View Calendar",
"visitLocation": "Visit Location",
Expand Down
2 changes: 1 addition & 1 deletion packages/esm-appointments-app/translations/he.json
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@
"unscheduled": "Unscheduled",
"unscheduledAppointments": "Unscheduled appointments",
"unscheduledAppointments_lower": "unscheduled appointments",
"upcomming": "Upcoming",
"upcoming": "Upcoming",
"view": "הצג",
"viewCalendar": "הצג לוח שנה",
"visitLocation": "מיקום הביקור",
Expand Down
2 changes: 1 addition & 1 deletion packages/esm-appointments-app/translations/km.json
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@
"unscheduled": "មិនបានគ្រោងទុក",
"unscheduledAppointments": "ការណាត់ជួបដែលមិនបានគ្រោងទុក",
"unscheduledAppointments_lower": "unscheduled appointments",
"upcomming": "Upcoming",
"upcoming": "Upcoming",
"view": "ពិនិត្យមើល",
"viewCalendar": "ពិនិត្យមើលប្រតិទិន",
"visitLocation": "ទីតាំងមកពិនិត្យ",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ export async function updateQueueEntry(
patient: {
uuid: patientUuid,
},
startedAt: toDateObjectStrict(toOmrsIsoString(new Date())),
startedAt: new Date(),
sortWeight: sortWeight,
queueComingFrom: previousQueueUuid,
},
Expand Down Expand Up @@ -396,7 +396,7 @@ export async function addQueueEntry(
patient: {
uuid: patientUuid,
},
startedAt: toDateObjectStrict(toOmrsIsoString(new Date())),
startedAt: new Date(),
sortWeight: sortWeight,
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ const ChangeStatus: React.FC<ChangeStatusDialogProps> = ({ queueEntry, closeModa
const queuePriority = priority === '' ? defaultPriority : priority;
const emergencyPriorityConceptUuid = config.concepts.emergencyPriorityConceptUuid;
const sortWeight = priority === emergencyPriorityConceptUuid ? 1.0 : 0.0;
const endDate = toDateObjectStrict(toOmrsIsoString(new Date()));
const endDate = new Date();
updateQueueEntry(
queueEntry?.visitUuid,
queueEntry?.queueUuid,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export async function batchClearQueueEntries(queueEntries: Array<MappedVisitQueu
while (curReq < queueEntries.length) {
const end = queueEntries.length < curReq + batchSize ? queueEntries.length : curReq + batchSize;
const concurrentReq = new Array(batchSize);
const endedAt = toDateObjectStrict(toOmrsIsoString(new Date()));
const endedAt = new Date();
for (let index = curReq; index < end; index++) {
await Promise.all([
endPatientStatus(queueEntries[index]?.queueUuid, queueEntries[index]?.queueEntryUuid, endedAt),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export async function addQueueEntry(
patient: {
uuid: patientUuid,
},
startedAt: toDateObjectStrict(toOmrsIsoString(new Date())),
startedAt: new Date(),
},
},
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ const RemoveQueueEntryDialog: React.FC<RemoveQueueEntryDialogProps> = ({ queueEn
stopDatetime: new Date(),
};

const endedAt = toDateObjectStrict(toOmrsIsoString(new Date()));
const endedAt = new Date();

voidQueueEntry(
queueEntry.queueUuid,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ const TransitionQueueEntryModal: React.FC<TransitionQueueEntryModalProps> = ({ q
const { mutate } = useVisitQueueEntries('', '');

const launchEditPriorityModal = useCallback(() => {
const endedAt = toDateObjectStrict(toOmrsIsoString(new Date()));
const endedAt = new Date();
updateQueueEntry(
queueEntry?.visitUuid,
queueEntry?.queueUuid,
Expand Down
Loading