diff --git a/packages/esm-service-queues-app/src/config-schema.ts b/packages/esm-service-queues-app/src/config-schema.ts index a84f0e0f8..35fcf0dde 100644 --- a/packages/esm-service-queues-app/src/config-schema.ts +++ b/packages/esm-service-queues-app/src/config-schema.ts @@ -82,6 +82,10 @@ export const configSchema = { _description: 'The UUID of the default status for attending a service in the queues eg In Service.', _default: 'ca7494ae-437f-4fd0-8aae-b88b9a2ba47d', }, + systolicBloodPressureUuid: { + _type: Type.ConceptUuid, + _default: '5085AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA', + }, diastolicBloodPressureUuid: { _type: Type.ConceptUuid, _default: '5086AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA', @@ -112,10 +116,6 @@ export const configSchema = { _type: Type.ConceptUuid, _default: '5242AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA', }, - systolicBloodPressureUuid: { - _type: Type.ConceptUuid, - _default: '5085AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA', - }, temperatureUuid: { _type: Type.ConceptUuid, _default: '5088AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA', diff --git a/packages/esm-service-queues-app/src/index.ts b/packages/esm-service-queues-app/src/index.ts index 359158cb1..1568d0f06 100644 --- a/packages/esm-service-queues-app/src/index.ts +++ b/packages/esm-service-queues-app/src/index.ts @@ -138,6 +138,13 @@ export const addNewQueueServiceWorkspace = getAsyncLifecycle( moduleName, }, ); +export const transitionPatientToLatestQueue = getAsyncLifecycle( + () => import('./transition-latest-queue-entry/transition-latest-queue-entry.component'), + { + featureName: 'transition patient to new queue', + moduleName, + }, +); // t('addNewQueueServiceRoom', 'Add new queue service room') export const addNewQueueServiceRoomWorkspace = getAsyncLifecycle( diff --git a/packages/esm-service-queues-app/src/queue-table/queue-entry-actions/transition-queue-entry.modal.tsx b/packages/esm-service-queues-app/src/queue-table/queue-entry-actions/transition-queue-entry.modal.tsx index 5147fd095..d4b37d88f 100644 --- a/packages/esm-service-queues-app/src/queue-table/queue-entry-actions/transition-queue-entry.modal.tsx +++ b/packages/esm-service-queues-app/src/queue-table/queue-entry-actions/transition-queue-entry.modal.tsx @@ -8,16 +8,21 @@ import { convertTime12to24 } from '../../helpers/time-helpers'; interface TransitionQueueEntryModalProps { queueEntry: QueueEntry; closeModal: () => void; + modalTitle?: string; } -const TransitionQueueEntryModal: React.FC = ({ queueEntry, closeModal }) => { +const TransitionQueueEntryModal: React.FC = ({ + queueEntry, + closeModal, + modalTitle, +}) => { const { t } = useTranslation(); return ( void; + modalTitle?: string; +} + +const TransitionLatestQueueEntry: React.FC = ({ + closeModal, + patientUuid, + modalTitle, +}) => { + const { t } = useTranslation(); + const { data: queueEntry, error, isLoading } = useLatestQueueEntry(patientUuid); + + if (error || !queueEntry) { + return null; + } + + return ( + + ); +}; + +export default TransitionLatestQueueEntry; diff --git a/packages/esm-service-queues-app/src/transition-latest-queue-entry/transition-latest-queue-entry.resource.ts b/packages/esm-service-queues-app/src/transition-latest-queue-entry/transition-latest-queue-entry.resource.ts new file mode 100644 index 000000000..ee4d804f7 --- /dev/null +++ b/packages/esm-service-queues-app/src/transition-latest-queue-entry/transition-latest-queue-entry.resource.ts @@ -0,0 +1,30 @@ +import { + type FetchResponse, + openmrsFetch, + type OpenmrsResource, + type Patient, + type Visit, +} from '@openmrs/esm-framework'; +import useSWR from 'swr'; +import useSWRImmutable from 'swr/immutable'; +import { type QueueEntry } from '../types'; +import { FetcherResponse } from 'swr/_internal'; + +export function useLatestQueueEntry(patientUuid: string) { + const customRepresentation = + 'custom:(uuid,display,queue:(uuid,display,name,location:(uuid,display),service:(uuid,display),allowedPriorities:(uuid,display),allowedStatuses:(uuid,display)),status,patient:(uuid,display),visit:(uuid,display,startDatetime),priority,priorityComment,sortWeight,startedAt,endedAt,locationWaitingFor,queueComingFrom,providerWaitingFor,previousQueueEntry)'; + + const encodedRepresentation = encodeURIComponent(customRepresentation); + const url = `/ws/rest/v1/queue-entry?v=${encodedRepresentation}&patient=${patientUuid}&isEnded=false`; + const { data, error, isLoading, mutate } = useSWR>(url, openmrsFetch); + + const queueEntry = + data?.data?.results?.reduce((latestEntry, currentEntry) => { + if (!latestEntry || new Date(currentEntry.startedAt) > new Date(latestEntry.startedAt)) { + return currentEntry; + } + return latestEntry; + }, null) || null; + + return { data: queueEntry, error, isLoading, mutate }; +} diff --git a/packages/esm-service-queues-app/translations/en.json b/packages/esm-service-queues-app/translations/en.json index 0ea763fb2..b10d793e0 100644 --- a/packages/esm-service-queues-app/translations/en.json +++ b/packages/esm-service-queues-app/translations/en.json @@ -280,6 +280,7 @@ "today": "Today", "totalPatients": "Total Patients", "transition": "Transition", + "TransitionLatestQueueEntry": "Transition patient to latest queue", "transitionPatient": "Transition patient", "transitionPatientStatusOrQueue": "Select a new status or queue for patient to transition to.", "triageForm": "Triage form",