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

(fix) O3-3158: Follow-up commit fixing patientUuid sometimes undefined #1831

Merged
merged 2 commits into from
May 10, 2024
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 @@ -35,6 +35,7 @@ import {
useConnectivity,
formatDatetime,
usePatient,
useAbortController,
} from '@openmrs/esm-framework';
import {
convertTime12to24,
Expand Down Expand Up @@ -69,7 +70,7 @@ interface StartVisitFormProps extends DefaultPatientWorkspaceProps {
}

const StartVisitForm: React.FC<StartVisitFormProps> = ({
patientUuid,
patientUuid: initialPatientUuid,
closeWorkspace,
promptBeforeClosing,
visitToEdit,
Expand All @@ -81,10 +82,11 @@ const StartVisitForm: React.FC<StartVisitFormProps> = ({
const isOnline = useConnectivity();
const sessionUser = useSession();
const { error } = useLocations();
const abortController = useAbortController();
const errorFetchingLocations = isOnline ? error : false;
const sessionLocation = sessionUser?.sessionLocation;
const config = useConfig() as ChartConfig;
const { patient } = usePatient(patientUuid);
const { patientUuid, patient } = usePatient(initialPatientUuid);
const [contentSwitcherIndex, setContentSwitcherIndex] = useState(config.showRecommendedVisitTypeTab ? 0 : 1);
const [isSubmitting, setIsSubmitting] = useState(false);
const visitHeaderSlotState = useMemo(() => ({ patientUuid }), [patientUuid]);
Expand Down Expand Up @@ -322,10 +324,10 @@ const StartVisitForm: React.FC<StartVisitFormProps> = ({
visitType: visitType,
location: visitLocation?.uuid,
attributes: Object.entries(visitAttributes)
.filter(([key, value]) => !!value)
.filter(([, value]) => !!value)
.map(([key, value]) => ({
attributeType: key,
value: value as string,
value: value,
})),
};
if (visitToEdit?.uuid) {
Expand All @@ -336,23 +338,19 @@ const StartVisitForm: React.FC<StartVisitFormProps> = ({
if (displayVisitStopDateTimeFields) {
const [visitStopHours, visitStopMinutes] = convertTime12to24(visitStopTime, visitStopTimeFormat);

payload = {
...payload,
stopDatetime: toDateObjectStrict(
toOmrsIsoString(
new Date(
dayjs(visitStopDate).year(),
dayjs(visitStopDate).month(),
dayjs(visitStopDate).date(),
visitStopHours,
visitStopMinutes,
),
payload.stopDatetime = toDateObjectStrict(
toOmrsIsoString(
new Date(
dayjs(visitStopDate).year(),
dayjs(visitStopDate).month(),
dayjs(visitStopDate).date(),
visitStopHours,
visitStopMinutes,
),
),
};
);
}

const abortController = new AbortController();
if (config.showExtraVisitAttributesSlot) {
const { handleCreateExtraVisitInfo, attributes } = extraVisitInfo ?? {};
payload.attributes.push(...attributes);
Expand All @@ -371,11 +369,11 @@ const StartVisitForm: React.FC<StartVisitFormProps> = ({
if (config.showServiceQueueFields) {
// retrieve values from queue extension
setVisitUuid(response.data.uuid);
const queueLocation = event?.target['queueLocation']?.value;
const serviceUuid = event?.target['service']?.value;
const priority = event?.target['priority']?.value;
const status = event?.target['status']?.value;
const sortWeight = event?.target['sortWeight']?.value;
const queueLocation = event.target['queueLocation']?.value;
const serviceUuid = event.target['service']?.value;
const priority = event.target['priority']?.value;
const status = event.target['status']?.value;
const sortWeight = event.target['sortWeight']?.value;

saveQueueEntry(
response.data.uuid,
Expand All @@ -384,7 +382,7 @@ const StartVisitForm: React.FC<StartVisitFormProps> = ({
priority,
status,
sortWeight,
new AbortController(),
abortController,
queueLocation,
visitQueueNumberAttributeUuid,
).then(
Expand All @@ -410,8 +408,9 @@ const StartVisitForm: React.FC<StartVisitFormProps> = ({
},
);
}

if (config.showUpcomingAppointments && upcomingAppointment) {
updateAppointmentStatus('CheckedIn', upcomingAppointment?.uuid, abortController).then(
updateAppointmentStatus('CheckedIn', upcomingAppointment.uuid, abortController).then(
() => {
mutateCurrentVisit();
mutateVisits();
Expand Down Expand Up @@ -472,7 +471,7 @@ const StartVisitForm: React.FC<StartVisitFormProps> = ({
config.offlineVisitTypeUuid,
payload.startDatetime,
).then(
(offlineVisit) => {
() => {
mutate();
closeWorkspace({ ignoreChanges: true });
showSnackbar({
Expand All @@ -497,6 +496,7 @@ const StartVisitForm: React.FC<StartVisitFormProps> = ({
}
},
[
abortController,
closeWorkspace,
config.showServiceQueueFields,
config.showUpcomingAppointments,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ jest.mock('@openmrs/esm-framework', () => {
useLocations: jest.fn(),
toDateObjectStrict: jest.fn(),
useVisitTypes: jest.fn().mockImplementation(() => mockVisitTypes),
usePatient: jest.fn().mockImplementation((patientUuid) => ({ patientUuid, patient: {} })),
};
});

Expand Down Expand Up @@ -215,7 +216,7 @@ describe('Visit Form', () => {
patient: mockPatient.id,
visitType: 'some-uuid1',
}),
new AbortController(),
expect.any(Function),
);

expect(showSnackbar).toHaveBeenCalledTimes(1);
Expand Down