-
Notifications
You must be signed in to change notification settings - Fork 225
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
O3-3677: Implement ability to add patient to a queue from lab app (#1258
) Co-authored-by: Dennis Kigen <[email protected]> Co-authored-by: Brandon Istenes <[email protected]>
- Loading branch information
1 parent
bac1f4d
commit 07da6a7
Showing
7 changed files
with
86 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
...-queues-app/src/transition-latest-queue-entry/transition-latest-queue-entry.component.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
30 changes: 30 additions & 0 deletions
30
...ce-queues-app/src/transition-latest-queue-entry/transition-latest-queue-entry.resource.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters