Skip to content

Commit

Permalink
Merge branch 'main' into HIE-9
Browse files Browse the repository at this point in the history
  • Loading branch information
denniskigen authored Oct 31, 2024
2 parents 7752cfd + 74707b3 commit 1efc7dd
Show file tree
Hide file tree
Showing 50 changed files with 1,059 additions and 967 deletions.
144 changes: 72 additions & 72 deletions __mocks__/inpatient-request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,81 +3,81 @@ import { mockLocationInpatientWard } from './locations.mock';
import { mockPatientAlice } from './patient.mock';
import { mockVisitAlice } from './visits.mock';

export const mockInpatientRequest: InpatientRequest[] = [
{
patient: mockPatientAlice,
visit: mockVisitAlice,
dispositionLocation: mockLocationInpatientWard,
dispositionType: 'ADMIT',
disposition: {
uuid: '6c047a20-c2bf-43ef-9e88-6da7b17e8c1a',
export const mockInpatientRequestAlice: InpatientRequest = {
patient: mockPatientAlice,
visit: mockVisitAlice,
dispositionLocation: mockLocationInpatientWard,
dispositionType: 'ADMIT',
disposition: {
uuid: '6c047a20-c2bf-43ef-9e88-6da7b17e8c1a',
display: 'Admit to hospital',
name: {
display: 'Admit to hospital',
name: {
display: 'Admit to hospital',
uuid: 'b1e494ef-4779-4262-bc42-56a79c39303c',
name: 'Admit to hospital',
locale: 'en',
localePreferred: true,
conceptNameType: 'FULLY_SPECIFIED',
},
datatype: {
uuid: '8d4a4c94-c2cc-11de-8d13-0010c6dffd0f',
display: 'N/A',
},
conceptClass: {
uuid: '8d492774-c2cc-11de-8d13-0010c6dffd0f',
display: 'Misc',
},
set: false,
version: null,
retired: false,
names: [
{
uuid: '122a523c-cbec-4283-991f-858f44ffccca',
display: 'Hospital admission',
},
{
uuid: 'b1e494ef-4779-4262-bc42-56a79c39303c',
name: 'Admit to hospital',
locale: 'en',
localePreferred: true,
conceptNameType: 'FULLY_SPECIFIED',
display: 'Admit to hospital',
},
datatype: {
uuid: '8d4a4c94-c2cc-11de-8d13-0010c6dffd0f',
display: 'N/A',
{
uuid: 'f72fadb0-d5db-102d-ad2a-000c29c2a5d7',
display: "ADMIS Á L'HÔPITAL",
},
conceptClass: {
uuid: '8d492774-c2cc-11de-8d13-0010c6dffd0f',
display: 'Misc',
{
uuid: 'acdcc1d2-7414-4337-890e-c8ccbccda41a',
display: 'Admèt nan lopital',
},
set: false,
version: null,
retired: false,
names: [
{
uuid: '122a523c-cbec-4283-991f-858f44ffccca',
display: 'Hospital admission',
},
{
uuid: 'b1e494ef-4779-4262-bc42-56a79c39303c',
display: 'Admit to hospital',
},
{
uuid: 'f72fadb0-d5db-102d-ad2a-000c29c2a5d7',
display: "ADMIS Á L'HÔPITAL",
},
{
uuid: 'acdcc1d2-7414-4337-890e-c8ccbccda41a',
display: 'Admèt nan lopital',
},
{
uuid: '4f12edd7-e516-493b-bc21-da1a9d29873f',
display: "Admettre à l'hôpital",
},
],
descriptions: [
{
uuid: '7d29309b-faaa-4767-83e6-6c75117fc569',
display: 'patient will be admitted from the clinic to the hospital for managment of an acute problem.',
},
],
mappings: [
{
uuid: '75a1a11e-4943-102e-96e9-000c29c2a5d7',
display: 'PIH: ADMIT TO HOSPITAL',
},
{
uuid: 'b260d122-4864-102e-96e9-000c29c2a5d7',
display: 'PIH: 3799',
},
],
answers: [],
setMembers: [],
attributes: [],
resourceVersion: '2.0',
},
dispositionEncounter: {
uuid: '6c047a20-c2bf-43ef-9e88-6da7b17e8c1a',
display: 'Admit to hospital',
encounterDatetime: '2021-09-28T11:00:00.000Z',
},
{
uuid: '4f12edd7-e516-493b-bc21-da1a9d29873f',
display: "Admettre à l'hôpital",
},
],
descriptions: [
{
uuid: '7d29309b-faaa-4767-83e6-6c75117fc569',
display: 'patient will be admitted from the clinic to the hospital for managment of an acute problem.',
},
],
mappings: [
{
uuid: '75a1a11e-4943-102e-96e9-000c29c2a5d7',
display: 'PIH: ADMIT TO HOSPITAL',
},
{
uuid: 'b260d122-4864-102e-96e9-000c29c2a5d7',
display: 'PIH: 3799',
},
],
answers: [],
setMembers: [],
attributes: [],
resourceVersion: '2.0',
},
dispositionEncounter: {
uuid: '6c047a20-c2bf-43ef-9e88-6da7b17e8c1a',
display: 'Admit to hospital',
encounterDatetime: '2021-09-28T11:00:00.000Z',
},
];
};

export const mockInpatientRequests = [mockInpatientRequestAlice];
4 changes: 2 additions & 2 deletions __mocks__/wards.mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export const mockAdmissionLocation: AdmissionLocationFetchResponse = {
rowNumber: 1,
columnNumber: 2,
bedNumber: 'bed2',
bedId: 1,
bedId: 2,
bedUuid: '0000-bed2',
status: 'AVAILABLE',
bedType: mockBedType,
Expand Down Expand Up @@ -79,4 +79,4 @@ export const mockInpatientAdmissions: InpatientAdmission[] = [
currentInpatientRequest: null,
firstAdmissionOrTransferEncounter: null,
},
];
];
2 changes: 1 addition & 1 deletion e2e/support/bamboo/playwright.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# The image version should match the Playwright version specified in the package.json file
FROM mcr.microsoft.com/playwright:v1.45.2-jammy
FROM mcr.microsoft.com/playwright:v1.48.2-jammy

ARG USER_ID
ARG GROUP_ID
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"@carbon/react": "~1.37.0",
"@openmrs/esm-framework": "next",
"@openmrs/esm-patient-common-lib": "next",
"@playwright/test": "1.45.2",
"@playwright/test": "1.48.2",
"@swc/core": "^1.2.165",
"@swc/jest": "^0.2.29",
"@testing-library/dom": "^9.3.3",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import React, { useCallback } from 'react';
import { useTranslation } from 'react-i18next';
import { useVisit, updateVisit, parseDate, showSnackbar } from '@openmrs/esm-framework';
import { showSnackbar, updateVisit, useVisit } from '@openmrs/esm-framework';
import { Button, ModalBody, ModalFooter, ModalHeader } from '@carbon/react';
import { changeAppointmentStatus } from '../../patient-appointments/patient-appointments.resource';
import { useMutateAppointments } from '../../form/appointments-form.resource';
Expand All @@ -12,48 +12,43 @@ interface EndAppointmentModalProps {
}

const EndAppointmentModal: React.FC<EndAppointmentModalProps> = ({ patientUuid, appointmentUuid, closeModal }) => {
const { activeVisit, mutate } = useVisit(patientUuid);
const { t } = useTranslation();
const { activeVisit, mutate } = useVisit(patientUuid);
const { mutateAppointments } = useMutateAppointments();

const endAppointment = () => {
return changeAppointmentStatus('Completed', appointmentUuid)
const handleEndAppointment = useCallback(() => {
changeAppointmentStatus('Completed', appointmentUuid)
.then(() => {
mutateAppointments();
if (activeVisit) {
const abortController = new AbortController();
const endVisitPayload = {
location: activeVisit.location.uuid,
startDatetime: parseDate(activeVisit.startDatetime),
visitType: activeVisit.visitType.uuid,
stopDatetime: new Date(),
};
updateVisit(activeVisit.uuid, endVisitPayload, abortController)
.toPromise()
const endVisitPayload = { stopDatetime: new Date() };

return updateVisit(activeVisit.uuid, endVisitPayload, abortController)
.then(() => {
mutate();
showSnackbar({
title: t('appointmentEnded', 'Appointment ended'),
subtitle: t(
'appointmentEndedAndVisitClosedSuccessfully',
'Appointment successfully ended and visit successfully closed.',
'Appointment successfully ended and visit successfully closed',
),
isLowContrast: true,
kind: 'success',
});
closeModal();
mutate();
})
.catch((err) => {
closeModal();
.catch((error) => {
showSnackbar({
title: t('appointmentEndedButVisitNotClosedError', 'Appointment ended, but error closing visit'),
subtitle: err?.message,
title: t(
'appointmentEndedButVisitNotClosedError',
'Appointment ended successfully, but there was an error closing the visit.',
),
subtitle: error?.message,
kind: 'error',
isLowContrast: true,
});
});
} else {
closeModal();
showSnackbar({
title: t('appointmentEnded', 'Appointment ended'),
subtitle: t('appointmentEndedSuccessfully', 'Appointment successfully ended.'),
Expand All @@ -62,16 +57,18 @@ const EndAppointmentModal: React.FC<EndAppointmentModalProps> = ({ patientUuid,
});
}
})
.catch((err) => {
closeModal();
.catch((error) => {
showSnackbar({
title: t('appointmentEndError', 'Error ending appointment'),
subtitle: err?.message,
subtitle: error?.message,
kind: 'error',
isLowContrast: true,
});
})
.finally(() => {
closeModal();
});
};
}, [activeVisit, mutate, mutateAppointments, closeModal, patientUuid, appointmentUuid]);

return (
<div>
Expand All @@ -84,7 +81,7 @@ const EndAppointmentModal: React.FC<EndAppointmentModalProps> = ({ patientUuid,
{activeVisit
? t(
'endAppointmentAndVisitConfirmationMessage',
'Checking the patient out will mark the appointment as complete, and close out the active visit for this patient.',
'Checking the patient out will mark the appointment as complete and close out the active visit for this patient.',
)
: t('endAppointmentConfirmationMessage', 'Checking the patient out will mark the appointment as complete.')}
</p>
Expand All @@ -93,7 +90,7 @@ const EndAppointmentModal: React.FC<EndAppointmentModalProps> = ({ patientUuid,
<Button kind="secondary" onClick={closeModal}>
{t('cancel', 'Cancel')}
</Button>
<Button kind="danger" onClick={endAppointment}>
<Button kind="danger" onClick={handleEndAppointment}>
{t('checkOut', 'Check out')}
</Button>
</ModalFooter>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
import React from 'react';
import { of } from 'rxjs';
import { render, screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import { updateVisit, showSnackbar, useVisit, type VisitReturnType } from '@openmrs/esm-framework';
import {
updateVisit,
showSnackbar,
useVisit,
type VisitReturnType,
type FetchResponse,
type Visit,
} from '@openmrs/esm-framework';
import { changeAppointmentStatus } from '../../patient-appointments/patient-appointments.resource';
import EndAppointmentModal from './end-appointment.modal';

Expand All @@ -20,7 +26,7 @@ jest.mock('../../form/appointments-form.resource', () => ({

describe('EndAppointmentModal', () => {
beforeEach(() => {
mockUpdateVisit.mockImplementation(() => of({}));
mockUpdateVisit.mockResolvedValue({} as FetchResponse<Visit>);
});

it('has a cancel button that closes the modal', async () => {
Expand Down Expand Up @@ -73,7 +79,7 @@ describe('EndAppointmentModal', () => {
expect(closeModal).toHaveBeenCalled();
expect(showSnackbar).toHaveBeenCalledWith({
title: 'Appointment ended',
subtitle: 'Appointment successfully ended and visit successfully closed.',
subtitle: 'Appointment successfully ended and visit successfully closed',
isLowContrast: true,
kind: 'success',
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -837,7 +837,7 @@ const AppointmentsForm: React.FC<AppointmentsFormProps> = ({
datePickerType="single"
dateFormat={datePickerFormat}
value={value}
maxDate={new Date()}
maxDate={new Date().toISOString()}
onChange={([date]) => onChange(date)}
invalid={!!fieldState?.error?.message}
invalidText={fieldState?.error?.message}>
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 @@ -12,7 +12,7 @@
"appointmentEdited": "Appointment edited",
"appointmentEditError": "Error editing appointment",
"appointmentEnded": "Appointment ended",
"appointmentEndedAndVisitClosedSuccessfully": "Appointment successfully ended and visit successfully closed.",
"appointmentEndedAndVisitClosedSuccessfully": "Appointment successfully ended and visit successfully closed",
"appointmentEndedButVisitNotClosedError": "Appointment ended, but error closing visit",
"appointmentEndedSuccessfully": "Appointment successfully ended.",
"appointmentEndError": "Error ending appointment",
Expand Down
Loading

0 comments on commit 1efc7dd

Please sign in to comment.