Skip to content

Commit

Permalink
O3-2476 - Remove unnecessary conversion from date to string back to date
Browse files Browse the repository at this point in the history
  • Loading branch information
mseaton authored Oct 10, 2023
1 parent 95f655c commit 863ca3c
Show file tree
Hide file tree
Showing 15 changed files with 24 additions and 20 deletions.
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();

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>
<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(),
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,
),
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 @@ -137,7 +137,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 @@ -137,7 +137,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 @@ -137,7 +137,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 @@ -137,7 +137,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 @@ -137,7 +137,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

0 comments on commit 863ca3c

Please sign in to comment.