Skip to content

Commit

Permalink
fix start visit
Browse files Browse the repository at this point in the history
  • Loading branch information
jabahum committed Oct 31, 2024
1 parent e9f81c3 commit 79f337c
Show file tree
Hide file tree
Showing 5 changed files with 5,180 additions and 5,827 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -146,54 +146,52 @@ const ChangeStatus: React.FC<ChangeStatusDialogProps> = ({ queueEntry, currentEn
};

const abortController = new AbortController();
updateVisit(activeVisit.uuid, endVisitPayload, abortController)
.pipe(first())
.subscribe(
(response) => {
if (response.status === 200) {
const comment = event?.target['nextNotes']?.value ?? 'Not Set';
updateQueueEntry(
QueueStatus.Completed,
provider,
queueEntry?.id,
contentSwitcherIndex,
priorityComment,
comment,
).then(
() => {
showSnackbar({
isLowContrast: true,
kind: 'success',
subtitle: t('visitEndSuccessfully', `${response?.data?.visitType?.display} ended successfully`),
title: t('visitEnded', 'Visit ended'),
});
navigate({ to: `\${openmrsSpaBase}/home` });

closeModal();
mutate();
},
(error) => {
showNotification({
title: t('queueEntryUpdateFailed', 'Error ending visit'),
kind: 'error',
critical: true,
description: error?.message,
});
},
);
mutate();
closeModal();
}
},
(error) => {
showSnackbar({
title: t('errorEndingVisit', 'Error ending visit'),
kind: 'error',
isLowContrast: false,
subtitle: error?.message,
});
},
);
updateVisit(activeVisit.uuid, endVisitPayload, abortController).then(
(response) => {
if (response.status === 200) {
const comment = event?.target['nextNotes']?.value ?? 'Not Set';
updateQueueEntry(
QueueStatus.Completed,
provider,
queueEntry?.id,
contentSwitcherIndex,
priorityComment,
comment,
).then(
() => {
showSnackbar({
isLowContrast: true,
kind: 'success',
subtitle: t('visitEndSuccessfully', `${response?.data?.visitType?.display} ended successfully`),
title: t('visitEnded', 'Visit ended'),
});
navigate({ to: `\${openmrsSpaBase}/home` });

closeModal();
mutate();
},
(error) => {
showNotification({
title: t('queueEntryUpdateFailed', 'Error ending visit'),
kind: 'error',
critical: true,
description: error?.message,
});
},
);
mutate();
closeModal();
}
},
(error) => {
showSnackbar({
title: t('errorEndingVisit', 'Error ending visit'),
kind: 'error',
isLowContrast: false,
subtitle: error?.message,
});
},
);
};

// change to picked
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import {
import { addQueueEntry, getCareProvider, updateQueueEntry } from './active-visits-table.resource';
import { useQueueRoomLocations } from '../hooks/useQueueRooms';
import styles from './change-status-dialog.scss';
import { first } from 'rxjs/operators';
import { QueueStatus, extractErrorMessagesFromResponse } from '../utils/utils';
import { getCurrentPatientQueueByPatientUuid, useProviders } from './visit-form/queue.resource';

Expand Down Expand Up @@ -144,112 +143,110 @@ const ChangeStatusMoveToNext: React.FC<ChangeStatusDialogProps> = ({ patientUuid
};

const abortController = new AbortController();
updateVisit(activeVisit.uuid, endVisitPayload, abortController)
.pipe(first())
.subscribe(
(response) => {
mutate();

if (response.status === 200) {
const comment = event?.target['nextNotes']?.value ?? 'Not Set';

getCurrentPatientQueueByPatientUuid(patientUuid, sessionUser?.sessionLocation?.uuid).then(
(res) => {
const queues = res.data?.results[0]?.patientQueues;
const queueEntry = queues?.filter((item) => item?.patient?.uuid === patientUuid);

if (queueEntry.length > 0) {
updateQueueEntry(
QueueStatus.Completed,
provider,
queueEntry[0]?.uuid,
contentSwitcherIndex,
priorityComment,
comment,
).then(
() => {
showSnackbar({
isLowContrast: true,
kind: 'success',
subtitle: t('visitEndSuccessfully', `${response?.data?.visitType?.display} ended successfully`),
title: t('visitEnded', 'Visit ended'),
});

navigate({ to: `\${openmrsSpaBase}/home` });

closeModal();
mutate();
},
(error) => {
showNotification({
title: t('queueEntryUpdateFailed', 'Error ending visit'),
kind: 'error',
critical: true,
description: error?.message,
});
},
);
} else if (queueEntry.length === 1) {
updateQueueEntry(
QueueStatus.Completed,
provider,
queueEntry[0]?.uuid,
contentSwitcherIndex,
priorityComment,
comment,
).then(
() => {
showSnackbar({
isLowContrast: true,
kind: 'success',
subtitle: t('visitEndSuccessfully', `${response?.data?.visitType?.display} ended successfully`),
title: t('visitEnded', 'Visit ended'),
});
updateVisit(activeVisit.uuid, endVisitPayload, abortController).then(
(response) => {
mutate();

const roles = getSessionStore().getState().session?.user?.roles;
const roleName = roles[0]?.display;
if (roles && roles?.length > 0) {
if (roles?.filter((item) => item?.display === 'Organizational: Clinician').length > 0) {
navigate({
to: `${window.getOpenmrsSpaBase()}home/clinical-room-patient-queues`,
});
} else if (roleName === 'Triage') {
navigate({
to: `${window.getOpenmrsSpaBase()}home/triage-patient-queues`,
});
} else {
navigate({ to: `${window.getOpenmrsSpaBase()}home` });
}
if (response.status === 200) {
const comment = event?.target['nextNotes']?.value ?? 'Not Set';

getCurrentPatientQueueByPatientUuid(patientUuid, sessionUser?.sessionLocation?.uuid).then(
(res) => {
const queues = res.data?.results[0]?.patientQueues;
const queueEntry = queues?.filter((item) => item?.patient?.uuid === patientUuid);

if (queueEntry.length > 0) {
updateQueueEntry(
QueueStatus.Completed,
provider,
queueEntry[0]?.uuid,
contentSwitcherIndex,
priorityComment,
comment,
).then(
() => {
showSnackbar({
isLowContrast: true,
kind: 'success',
subtitle: t('visitEndSuccessfully', `${response?.data?.visitType?.display} ended successfully`),
title: t('visitEnded', 'Visit ended'),
});

navigate({ to: `\${openmrsSpaBase}/home` });

closeModal();
mutate();
},
(error) => {
showNotification({
title: t('queueEntryUpdateFailed', 'Error ending visit'),
kind: 'error',
critical: true,
description: error?.message,
});
},
);
} else if (queueEntry.length === 1) {
updateQueueEntry(
QueueStatus.Completed,
provider,
queueEntry[0]?.uuid,
contentSwitcherIndex,
priorityComment,
comment,
).then(
() => {
showSnackbar({
isLowContrast: true,
kind: 'success',
subtitle: t('visitEndSuccessfully', `${response?.data?.visitType?.display} ended successfully`),
title: t('visitEnded', 'Visit ended'),
});

const roles = getSessionStore().getState().session?.user?.roles;
const roleName = roles[0]?.display;
if (roles && roles?.length > 0) {
if (roles?.filter((item) => item?.display === 'Organizational: Clinician').length > 0) {
navigate({
to: `${window.getOpenmrsSpaBase()}home/clinical-room-patient-queues`,
});
} else if (roleName === 'Triage') {
navigate({
to: `${window.getOpenmrsSpaBase()}home/triage-patient-queues`,
});
} else {
navigate({ to: `${window.getOpenmrsSpaBase()}home` });
}
closeModal();
mutate();
},
(error) => {
showNotification({
title: t('queueEntryUpdateFailed', 'Error ending visit'),
kind: 'error',
critical: true,
description: error?.message,
});
},
);
}
},
() => {},
);
mutate();
closeModal();
}
},
(error) => {
showSnackbar({
title: t('errorEndingVisit', 'Error ending visit'),
kind: 'error',
isLowContrast: false,
subtitle: error?.message,
});
},
);
}
closeModal();
mutate();
},
(error) => {
showNotification({
title: t('queueEntryUpdateFailed', 'Error ending visit'),
kind: 'error',
critical: true,
description: error?.message,
});
},
);
}
},
() => {},
);
mutate();
closeModal();
}
},
(error) => {
showSnackbar({
title: t('errorEndingVisit', 'Error ending visit'),
kind: 'error',
isLowContrast: false,
subtitle: error?.message,
});
},
);
};

// change to picked
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { openmrsFetch } from '@openmrs/esm-framework';
import { openmrsFetch, restBaseUrl } from '@openmrs/esm-framework';
import useSWR from 'swr';
import { Appointment, ProviderResponse } from '../../types';

export async function saveAppointment(appointment: Appointment) {
const abortController = new AbortController();

await openmrsFetch(`/ws/rest/v1/appointment`, {
await openmrsFetch(`${restBaseUrl}/appointment`, {
method: 'POST',
signal: abortController.signal,
headers: {
Expand All @@ -29,7 +29,7 @@ export async function saveAppointment(appointment: Appointment) {

// fetch providers of a service point
export function useProviders() {
const apiUrl = `/ws/rest/v1/provider?q=&v=full`;
const apiUrl = `${restBaseUrl}/provider?q=&v=full`;
const { data, error, isLoading, isValidating } = useSWR<{ data: { results: Array<ProviderResponse> } }, Error>(
apiUrl,
openmrsFetch,
Expand All @@ -44,7 +44,7 @@ export function useProviders() {
}

export async function getCurrentPatientQueueByPatientUuid(patientUuid: string, currentLocation: string) {
const apiUrl = `/ws/rest/v1/incompletequeue?queueRoom=${currentLocation}&patient=${patientUuid}&v=full`;
const apiUrl = `${restBaseUrl}/incompletequeue?queueRoom=${currentLocation}&patient=${patientUuid}&v=full`;

const abortController = new AbortController();

Expand Down
Loading

0 comments on commit 79f337c

Please sign in to comment.