Skip to content

Commit

Permalink
O3-3677: Implement ability to add patient to a queue from lab app (#1258
Browse files Browse the repository at this point in the history
)

Co-authored-by: Dennis Kigen <[email protected]>
Co-authored-by: Brandon Istenes <[email protected]>
  • Loading branch information
3 people authored Sep 15, 2024
1 parent bac1f4d commit 07da6a7
Show file tree
Hide file tree
Showing 7 changed files with 86 additions and 6 deletions.
8 changes: 4 additions & 4 deletions packages/esm-service-queues-app/src/config-schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -112,10 +116,6 @@ export const configSchema = {
_type: Type.ConceptUuid,
_default: '5242AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA',
},
systolicBloodPressureUuid: {
_type: Type.ConceptUuid,
_default: '5085AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA',
},
temperatureUuid: {
_type: Type.ConceptUuid,
_default: '5088AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA',
Expand Down
7 changes: 7 additions & 0 deletions packages/esm-service-queues-app/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,21 @@ import { convertTime12to24 } from '../../helpers/time-helpers';
interface TransitionQueueEntryModalProps {
queueEntry: QueueEntry;
closeModal: () => void;
modalTitle?: string;
}

const TransitionQueueEntryModal: React.FC<TransitionQueueEntryModalProps> = ({ queueEntry, closeModal }) => {
const TransitionQueueEntryModal: React.FC<TransitionQueueEntryModalProps> = ({
queueEntry,
closeModal,
modalTitle,
}) => {
const { t } = useTranslation();
return (
<QueueEntryActionModal
queueEntry={queueEntry}
closeModal={closeModal}
modalParams={{
modalTitle: t('transitionPatient', 'Transition patient'),
modalTitle: modalTitle || t('transitionPatient', 'Transition patient'),
modalInstruction: t(
'transitionPatientStatusOrQueue',
'Select a new status or queue for patient to transition to.',
Expand Down
4 changes: 4 additions & 0 deletions packages/esm-service-queues-app/src/routes.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@
"name": "transition-queue-entry-modal",
"component": "transitionQueueEntryModal"
},
{
"name": "transition-patient-to-latest-queue-modal",
"component": "transitionPatientToLatestQueue"
},
{
"name": "edit-queue-entry-modal",
"component": "editQueueEntryModal"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import React, { useEffect } from 'react';
import { useTranslation } from 'react-i18next';
import { useLatestQueueEntry } from './transition-latest-queue-entry.resource';
import TransitionQueueEntryModal from '../queue-table/queue-entry-actions/transition-queue-entry.modal';

interface TransitionLatestQueueEntryProps {
patientUuid: string;
closeModal: () => void;
modalTitle?: string;
}

const TransitionLatestQueueEntry: React.FC<TransitionLatestQueueEntryProps> = ({
closeModal,
patientUuid,
modalTitle,
}) => {
const { t } = useTranslation();
const { data: queueEntry, error, isLoading } = useLatestQueueEntry(patientUuid);

if (error || !queueEntry) {
return null;
}

return (
<TransitionQueueEntryModal
queueEntry={queueEntry}
closeModal={closeModal}
modalTitle={t('TransitionLatestQueueEntry', "Transition patient's latest queue")}
/>
);
};

export default TransitionLatestQueueEntry;
Original file line number Diff line number Diff line change
@@ -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<FetchResponse<{ results: QueueEntry[] }>>(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 };
}
1 change: 1 addition & 0 deletions packages/esm-service-queues-app/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 07da6a7

Please sign in to comment.