diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md new file mode 100644 index 00000000..5453e59b --- /dev/null +++ b/.github/pull_request_template.md @@ -0,0 +1,25 @@ +## Requirements +- [ ] This PR has a title that briefly describes the work done including a [conventional commit](https://o3-docs.openmrs.org/#/getting_started/contributing?id=your-pr-title-should-indicate-the-type-of-change-it-is) type prefix and a Jira ticket number if applicable. See existing PR titles for inspiration. + +#### For changes to apps +- [ ] My work conforms to the [**OpenMRS 3.0 Styleguide**](https://om.rs/styleguide) and [**design documentation**](https://zeroheight.com/23a080e38/p/880723-introduction). + +#### If applicable +- [ ] My work includes tests or is validated by existing tests. + +## Summary + + + +## Screenshots + + + +## Related Issue + + + + +## Other + + diff --git a/packages/esm-patient-queues-app/src/active-visits/change-status-dialog.component.tsx b/packages/esm-patient-queues-app/src/active-visits/change-status-dialog.component.tsx index db36dd12..30b4b1d2 100644 --- a/packages/esm-patient-queues-app/src/active-visits/change-status-dialog.component.tsx +++ b/packages/esm-patient-queues-app/src/active-visits/change-status-dialog.component.tsx @@ -193,9 +193,9 @@ const ChangeStatus: React.FC = ({ queueEntry, currentEn () => { showToast({ critical: true, - title: t('endVisit', 'End Vist'), + title: t('completePatient', 'Completed Patient'), kind: 'success', - description: t('endVisitSuccessfully', 'You have successfully ended patient visit'), + description: t('endVisitSuccessfully', 'You have successfully completed working on the pa'), }); closeModal(); mutate(); @@ -374,23 +374,25 @@ const ChangeStatus: React.FC = ({ queueEntry, currentEn )} -
- -
+ {status === 'completed' && ( +
+ +
+ )} {status === 'completed' && (
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 new file mode 100644 index 00000000..02b568e1 --- /dev/null +++ b/packages/esm-patient-queues-app/src/active-visits/change-status-move-to-next-dialog.component.tsx @@ -0,0 +1,377 @@ +import React, { useCallback, useEffect, useMemo, useState } from 'react'; + +import { + Button, + ContentSwitcher, + Form, + ModalBody, + ModalFooter, + ModalHeader, + Select, + SelectItem, + Switch, + TextArea, +} from '@carbon/react'; + +import { showNotification, showToast, useLocations, useSession } from '@openmrs/esm-framework'; + +import { addQueueEntry, getCareProvider, updateQueueEntry } from './active-visits-table.resource'; + +import { useTranslation } from 'react-i18next'; +import { useQueueRoomLocations } from '../patient-search/hooks/useQueueRooms'; + +import styles from './change-status-dialog.scss'; +import { getCurrentPatientQueueByPatientUuid, useProviders } from '../patient-search/visit-form/queue.resource'; +import { MappedQueueEntry, QueueRecord } from '../types'; + +interface ChangeStatusDialogProps { + patientUuid: string; + closeModal: () => void; +} + +const ChangeStatusMoveToNext: React.FC = ({ patientUuid, closeModal }) => { + const { t } = useTranslation(); + + const locations = useLocations(); + + const sessionUser = useSession(); + + const { providers } = useProviders(); + + const [selectedLocation, setSelectedLocation] = useState(''); + + const [contentSwitcherIndex, setContentSwitcherIndex] = useState(1); + + const [statusSwitcherIndex, setStatusSwitcherIndex] = useState(1); + + const [status, setStatus] = useState(''); + + const { queueRoomLocations } = useQueueRoomLocations(sessionUser?.sessionLocation?.uuid); + + const [selectedNextQueueLocation, setSelectedNextQueueLocation] = useState(queueRoomLocations[0]?.uuid); + + const [provider, setProvider] = useState(''); + + const [priorityComment, setPriorityComment] = useState(''); + + const [selectedProvider, setSelectedProvider] = useState(''); + + let mappedQueueEntry: QueueRecord; + + useEffect(() => { + getCareProvider(sessionUser?.user?.systemId).then( + (response) => { + setProvider(response?.data?.results[0].uuid); + // mutate(); + }, + (error) => { + showNotification({ + title: t(`errorGettingProvider', 'Couldn't get provider`), + kind: 'error', + critical: true, + description: error?.message, + }); + }, + ); + }); + + getCurrentPatientQueueByPatientUuid(patientUuid, sessionUser?.sessionLocation?.uuid).then( + (res) => { + mappedQueueEntry = res.data.results[0]; + + console.info('mappedQueueEntry', JSON.stringify(mappedQueueEntry, null, 2)); + }, + (error) => { + showNotification({ + title: t('errorGettingPatientQueueEntry', 'Error Getting Patient Queue Entry'), + kind: 'error', + critical: true, + description: error?.message, + }); + }, + ); + + useEffect(() => { + if (locations?.length && sessionUser) { + setSelectedLocation(sessionUser?.sessionLocation?.uuid); + } + }, [locations, sessionUser]); + + useMemo(() => { + switch (statusSwitcherIndex) { + case 0: { + setStatus('pending'); + break; + } + case 1: { + setStatus('completed'); + break; + } + } + }, [statusSwitcherIndex]); + + useMemo(() => { + switch (contentSwitcherIndex) { + case 0: { + setPriorityComment('Not Urgent'); + break; + } + case 1: { + setPriorityComment('Urgent'); + break; + } + case 2: { + setPriorityComment('Emergency'); + break; + } + } + }, [contentSwitcherIndex]); + + const filteredlocations = queueRoomLocations?.filter((location) => location.uuid != selectedLocation); + + const filteredProviders = providers?.flatMap((provider) => + provider.attributes.filter( + (item) => + item.attributeType.display === 'Default Location' && + typeof item.value === 'object' && + item?.value?.uuid === selectedNextQueueLocation, + ).length > 0 + ? provider + : [], + ); + + // change to picked + const changeQueueStatus = useCallback( + (event: { preventDefault: () => void; target: { [x: string]: { value: string } } }) => { + event.preventDefault(); + + // check status + + if (status === 'pending') { + const comment = event?.target['nextNotes']?.value ?? 'Not Set'; + updateQueueEntry(status, provider, mappedQueueEntry?.uuid, 0, priorityComment, comment).then( + () => { + showToast({ + critical: true, + title: t('updateEntry', 'Update entry'), + kind: 'success', + description: t('queueEntryUpdateSuccessfully', 'Queue Entry Updated Successfully'), + }); + closeModal(); + // mutate(); + }, + (error) => { + showNotification({ + title: t('queueEntryUpdateFailed', 'Error updating queue entry status'), + kind: 'error', + critical: true, + description: error?.message, + }); + }, + ); + } else if (status === 'completed') { + const comment = event?.target['nextNotes']?.value ?? 'Not Set'; + const nextQueueLocationUuid = event?.target['nextQueueLocation']?.value; + + updateQueueEntry( + 'Completed', + provider, + mappedQueueEntry?.uuid, + contentSwitcherIndex, + priorityComment, + comment, + ).then( + () => { + showToast({ + critical: true, + title: t('endVisit', 'End Vist'), + kind: 'success', + description: t('endVisitSuccessfully', 'You have successfully ended patient visit'), + }); + closeModal(); + // mutate(); + }, + (error) => { + showNotification({ + title: t('queueEntryUpdateFailed', 'Error ending visit'), + kind: 'error', + critical: true, + description: error?.message, + }); + }, + ); + + addQueueEntry( + mappedQueueEntry?.uuid, + nextQueueLocationUuid, + '', + selectedProvider, + contentSwitcherIndex, + patientUuid, + 'pending', + selectedLocation, + priorityComment, + comment, + ).then( + () => { + showToast({ + critical: true, + title: t('updateEntry', 'Move to next queue'), + kind: 'success', + description: t('movetonextqueue', 'Move to next queue successfully'), + }); + //pick and route + const status = 'picked'; + updateQueueEntry( + status, + provider, + mappedQueueEntry?.uuid, + contentSwitcherIndex, + priorityComment, + 'comment', + ).then( + () => { + closeModal(); + }, + (error) => { + showNotification({ + title: t('queueEntryUpdateFailed', 'Error updating queue entry status'), + kind: 'error', + critical: true, + description: error?.message, + }); + }, + ); + + closeModal(); + // mutate(); + }, + (error) => { + showNotification({ + title: t('queueEntryUpdateFailed', 'Error updating queue entry status'), + kind: 'error', + critical: true, + description: error?.message, + }); + }, + ); + } + }, + [ + closeModal, + contentSwitcherIndex, + mappedQueueEntry?.uuid, + patientUuid, + priorityComment, + provider, + selectedLocation, + selectedProvider, + status, + t, + ], + ); + + return ( +
+
+ + +
+
+

Queue to next service area

+
+
+
+
{t('priority', 'Priority')}
+ setContentSwitcherIndex(index)} + > + + + + +
+ +
+
{t('status', 'Status')}
+ setStatusSwitcherIndex(index)} + > + + + +
+ + {status === 'completed' && ( +
+ +
+ )} + + {status === 'completed' && ( +
+ +
+ )} + + {status === 'completed' && ( +
+