From 745d9db7881880add9f4ab4fe53c6d448276ec6f Mon Sep 17 00:00:00 2001 From: jabahum Date: Tue, 13 May 2025 18:06:20 +0300 Subject: [PATCH 01/17] chore --- ...e-status-move-to-next-dialog.component.tsx | 539 ------------------ ...patient-to-next-action-menu.components.tsx | 36 -- ...rvice-point-patient-action.components.tsx} | 16 +- ...ervice-point-reassign-action.component.tsx | 28 + ...g.scss => move-to-next-service-point.scss} | 6 + ... move-to-next-service-point.workspace.tsx} | 112 ++-- .../notes-action-menu.components.tsx | 2 +- .../{ => notes}/notes-dialog.component.tsx | 2 +- ...atient-queue-validation-schema.resource.ts | 4 +- .../queue-clinical-table.component.tsx | 17 +- .../queue-triage-table.component.tsx | 32 +- ...ue-table-move-to-next-dialog.component.tsx | 454 --------------- packages/esm-patient-queues-app/src/index.ts | 27 +- .../esm-patient-queues-app/src/routes.json | 44 +- packages/esm-ugandaemr-app/src/index.ts | 4 - packages/esm-ugandaemr-app/src/routes.json | 13 +- 16 files changed, 168 insertions(+), 1168 deletions(-) delete mode 100644 packages/esm-patient-queues-app/src/active-visits/change-status-move-to-next-dialog.component.tsx delete mode 100644 packages/esm-patient-queues-app/src/active-visits/move-patient-to-next-action-menu.components.tsx rename packages/esm-patient-queues-app/src/active-visits/{move-to-next-service-point-action.components.tsx => move-to-next-service-point-patient-action.components.tsx} (59%) create mode 100644 packages/esm-patient-queues-app/src/active-visits/move-to-next-service-point-reassign-action.component.tsx rename packages/esm-patient-queues-app/src/active-visits/{change-status-dialog.scss => move-to-next-service-point.scss} (89%) rename packages/esm-patient-queues-app/src/active-visits/{change-status-dialog.component.tsx => move-to-next-service-point.workspace.tsx} (85%) rename packages/esm-patient-queues-app/src/active-visits/{ => notes}/notes-action-menu.components.tsx (93%) rename packages/esm-patient-queues-app/src/active-visits/{ => notes}/notes-dialog.component.tsx (94%) delete mode 100644 packages/esm-patient-queues-app/src/active-visits/queue-table-move-to-next-dialog.component.tsx diff --git a/packages/esm-patient-queues-app/src/active-visits/change-status-move-to-next-dialog.component.tsx b/packages/esm-patient-queues-app/src/active-visits/change-status-move-to-next-dialog.component.tsx deleted file mode 100644 index 189b7a80..00000000 --- a/packages/esm-patient-queues-app/src/active-visits/change-status-move-to-next-dialog.component.tsx +++ /dev/null @@ -1,539 +0,0 @@ -import React, { useCallback, useEffect, useMemo, useState } from 'react'; -import { - Button, - ContentSwitcher, - Form, - ModalBody, - ModalFooter, - ModalHeader, - Select, - SelectItem, - Switch, - TextArea, - InlineLoading, - Layer, - InlineNotification, -} from '@carbon/react'; -import { useTranslation } from 'react-i18next'; -import { - getSessionStore, - navigate, - parseDate, - restBaseUrl, - showNotification, - showToast, - useLayoutType, - useSession, - useVisit, -} from '@openmrs/esm-framework'; -import { useQueueRoomLocations } from '../hooks/useQueueRooms'; -import styles from './change-status-dialog.scss'; -import { QueueStatus, extractErrorMessagesFromResponse, handleMutate } from '../utils/utils'; -import { - NewQueuePayload, - addQueueEntry, - getCareProvider, - getCurrentPatientQueueByPatientUuid, - updateQueueEntry, - updateVisit, - useProviders, -} from './patient-queues.resource'; -import { zodResolver } from '@hookform/resolvers/zod'; -import { CreateQueueEntryFormData, createQueueEntrySchema } from './patient-queue-validation-schema.resource'; -import { Controller, useForm } from 'react-hook-form'; - -interface ChangeStatusDialogProps { - patientUuid: string; - closeModal: () => void; -} - -const ChangeStatusMoveToNext: React.FC = ({ patientUuid, closeModal }) => { - const { t } = useTranslation(); - - const isTablet = useLayoutType() === 'tablet'; - - const sessionUser = useSession(); - - const [contentSwitcherIndex, setContentSwitcherIndex] = useState(1); - - const [statusSwitcherIndex, setStatusSwitcherIndex] = useState(1); - - const [status, setStatus] = useState(''); - - const { queueRoomLocations, error: errorLoadingQueueRooms } = useQueueRoomLocations( - sessionUser?.sessionLocation?.uuid, - ); - - const [selectedNextQueueLocation, setSelectedNextQueueLocation] = useState(queueRoomLocations[0]?.uuid); - - const { activeVisit } = useVisit(patientUuid); - - const [isLoading, setIsLoading] = useState(true); - - const [provider, setProvider] = useState(''); - - const [selectedProvider, setSelectedProvider] = useState(''); - - const [priorityComment, setPriorityComment] = useState(''); - - const [isSubmitting, setIsSubmitting] = useState(false); - - const [isEndingVisit, setIsEndingVisit] = useState(false); - - const { providers, error: errorLoadingProviders } = useProviders(selectedNextQueueLocation); - - // Memoize the function to fetch the provider using useCallback - const fetchProvider = useCallback(() => { - if (!sessionUser?.user?.uuid) return; - - setIsLoading(true); - - getCareProvider(sessionUser?.user?.uuid).then( - (response) => { - const uuid = response?.data?.results[0].uuid; - setIsLoading(false); - setProvider(uuid); - }, - (error) => { - const errorMessages = extractErrorMessagesFromResponse(error); - setIsLoading(false); - showNotification({ - title: "Couldn't get provider", - kind: 'error', - critical: true, - description: errorMessages.join(','), - }); - }, - ); - }, [sessionUser?.user?.uuid]); - - useEffect(() => fetchProvider(), [fetchProvider]); - - const priorityLabels = useMemo(() => ['Not Urgent', 'Urgent', 'Emergency'], []); - - const statusLabels = useMemo( - () => [ - { status: 'pending', label: 'Move to Pending' }, - { status: 'completed', label: 'Move to Completed' }, - ], - [], - ); - - const { - handleSubmit, - control, - formState: { errors }, - } = useForm({ - mode: 'all', - resolver: zodResolver(createQueueEntrySchema), - }); - - useEffect(() => { - setPriorityComment(priorityLabels[contentSwitcherIndex]); - }, [contentSwitcherIndex, priorityLabels]); - - useEffect(() => { - setStatus(statusLabels[statusSwitcherIndex].status); - }, [statusSwitcherIndex, statusLabels]); - - // endVisit - const endCurrentVisit = async (event) => { - event.preventDefault(); - - setIsEndingVisit(true); - const endVisitPayload = { - location: activeVisit.location.uuid, - startDatetime: parseDate(activeVisit.startDatetime), - visitType: activeVisit.visitType.uuid, - stopDatetime: new Date(), - }; - - try { - const response = await updateVisit(activeVisit.uuid, endVisitPayload); - - if (response.status === 200) { - // const comment = event?.target['nextNotes']?.value ?? 'Not Set'; - - const patientQueueEntryResponse = await getCurrentPatientQueueByPatientUuid( - patientUuid, - sessionUser?.sessionLocation?.uuid, - ); - - const queues = patientQueueEntryResponse.data?.results[0]?.patientQueues; - const queueEntry = queues?.filter((item) => item?.patient?.uuid === patientUuid); - - if (queueEntry.length > 0) { - await updateQueueEntry( - QueueStatus.Completed, - provider, - queueEntry[0]?.uuid, - contentSwitcherIndex, - priorityComment, - 'comment', - ); - - let navigateTo = `${window.getOpenmrsSpaBase()}home`; - - if (queueEntry.length === 1) { - const roles = getSessionStore().getState().session?.user?.roles || []; - const hasClinicianRole = roles.some((role) => role?.display === 'Organizational: Clinician'); - - if (hasClinicianRole) { - navigateTo = `${window.getOpenmrsSpaBase()}home/clinical-room-patient-queues`; - } else if (roles.some((role) => role?.display === 'Triage')) { - navigateTo = `${window.getOpenmrsSpaBase()}home/triage-patient-queues`; - } - } - - showToast({ - critical: true, - title: t('endedVisit', 'Ended Visit'), - kind: 'success', - description: t('endedVisitSuccessfully', 'Successfully ended visit'), - }); - setIsEndingVisit(false); - closeModal(); - navigate({ to: navigateTo }); - handleMutate(`${restBaseUrl}/patientqueue`); - } - } - } catch (error) { - setIsEndingVisit(false); - const errorMessages = extractErrorMessagesFromResponse(error); - showNotification({ - title: t('endVisit', 'Error ending visit succcessfully'), - kind: 'error', - critical: true, - description: errorMessages.join(','), - }); - } - }; - - // change to picked - const onSubmit = useCallback(async () => { - try { - setIsSubmitting(true); - // get queue entry by patient id - const patientQueueEntryResponse = await getCurrentPatientQueueByPatientUuid( - patientUuid, - sessionUser?.sessionLocation?.uuid, - ); - - const queues = patientQueueEntryResponse.data?.results[0]?.patientQueues; - const queueEntry = queues?.filter((item) => item?.patient?.uuid === patientUuid); - - if (status === QueueStatus.Pending) { - if (queueEntry.length > 0) { - await updateQueueEntry(status, provider, queueEntry[0]?.uuid, 0, priorityComment, 'NA').then(() => { - showToast({ - critical: true, - title: t('moveToNextServicePoint', 'Move back your service point'), - kind: 'success', - description: t('backToQueue', 'Successfully moved back patient to your service point'), - }); - closeModal(); - handleMutate(`${restBaseUrl}/patientqueue`); - setIsSubmitting(false); - }); - } - } - - if (status === QueueStatus.Completed) { - if (queueEntry.length > 0) { - await updateQueueEntry( - QueueStatus.Completed, - provider, - queueEntry[0]?.uuid, - contentSwitcherIndex, - priorityComment, - 'NA', - ); - - const request: NewQueuePayload = { - patient: patientUuid, - provider: selectedProvider ?? '', - locationFrom: sessionUser?.sessionLocation?.uuid, - locationTo: selectedNextQueueLocation, - status: QueueStatus.Pending, - priority: contentSwitcherIndex, - priorityComment: priorityComment, - comment: 'NA', - queueRoom: selectedNextQueueLocation, - }; - - const createQueueResponse = await addQueueEntry(request); - - const response = await updateQueueEntry( - QueueStatus.Pending, - provider, - createQueueResponse.data?.uuid, - contentSwitcherIndex, - priorityComment, - 'NA', - ); - - if (response.status === 200) { - showToast({ - critical: true, - title: t('moveToNextServicePoint', 'Move to next service point'), - kind: 'success', - description: t('movetonextservicepoint', 'Moved to next service point successfully'), - }); - handleMutate(`${restBaseUrl}/patientqueue`); - closeModal(); - setIsSubmitting(false); - // view patient summary - // navigate({ to: `\${openmrsSpaBase}/home` }); - 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` }); - } - } - } - } - } - } catch (error) { - setIsSubmitting(false); - const errorMessages = extractErrorMessagesFromResponse(error); - showNotification({ - title: t('moveToNextServicePoint', 'Error moving to next service point'), - kind: 'error', - critical: true, - description: errorMessages.join(','), - }); - } - }, [ - closeModal, - contentSwitcherIndex, - patientUuid, - priorityComment, - provider, - selectedNextQueueLocation, - selectedProvider, - sessionUser?.sessionLocation?.uuid, - status, - t, - ]); - - return ( - <> -
- {isLoading && } -
- - -
-
-

Queue to next service area

-
-
-
-
{t('priority', 'Priority')}
- ( - { - field.onChange(index); - setContentSwitcherIndex(index); - }} - > - {priorityLabels.map((label, index) => ( - - ))} - - )} - /> -
- -
-
{t('status', 'Status')}
- ( - { - field.onChange(index); - setStatusSwitcherIndex(index); - }} - > - {statusLabels.map((status, index) => ( - - ))} - - )} - /> -
- - {status === QueueStatus.Completed && ( - <> -
-
{t('nextServicePoint', 'Next service point')}
- - ( - - )} - /> - - {errorLoadingQueueRooms && ( - {}} - /> - )} - -
-
-
{t('selectAProvider', 'Select a provider')}
- - ( - - )} - /> - - {errorLoadingProviders && ( - {}} - /> - )} - -
-
-
{t('notes', 'Notes')}
- - ( -