Skip to content

Commit

Permalink
(fix) Mutate visit banner after starting new visit
Browse files Browse the repository at this point in the history
  • Loading branch information
CynthiaKamau committed Oct 26, 2023
1 parent 93fcb73 commit 98c235f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,12 @@ interface UseVisitQueueEntries {
isLoading: boolean;
isError: Error;
isValidating?: boolean;
mutate: () => void;
}

export function useVisitQueueEntry(patientUuid, visitUuid): UseVisitQueueEntries {
const apiUrl = `/ws/rest/v1/visit-queue-entry?patient=${patientUuid}`;
const { data, error, isLoading, isValidating } = useSWR<{ data: { results: Array<VisitQueueEntry> } }, Error>(
const { data, error, isLoading, isValidating, mutate } = useSWR<{ data: { results: Array<VisitQueueEntry> } }, Error>(
apiUrl,
openmrsFetch,
);
Expand Down Expand Up @@ -105,6 +106,7 @@ export function useVisitQueueEntry(patientUuid, visitUuid): UseVisitQueueEntries
isLoading,
isError: error,
isValidating,
mutate,
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ import BaseVisitType from './base-visit-type.component';
import LocationSelector from './location-selection.component';
import VisitAttributeTypeFields from './visit-attribute-type.component';
import styles from './visit-form.scss';
import { useVisitQueueEntry } from '../queue-entry/queue.resource';

export type VisitFormData = {
visitDate: Date;
Expand Down Expand Up @@ -89,6 +90,8 @@ const StartVisitForm: React.FC<DefaultWorkspaceProps> = ({ patientUuid, closeWor
const [upcomingAppointment, setUpcomingAppointment] = useState(null);
const upcomingAppointmentState = useMemo(() => ({ patientUuid, setUpcomingAppointment }), [patientUuid]);
const visitQueueNumberAttributeUuid = config.visitQueueNumberAttributeUuid;
const [visitUuid, setVisitUuid] = useState('');
const { mutate: mutateQueueEntry } = useVisitQueueEntry(patientUuid, visitUuid);

const visitFormSchema = useMemo(() => {
const visitAttributes = (config.visitAttributeTypes ?? [])?.reduce(
Expand Down Expand Up @@ -173,7 +176,7 @@ const StartVisitForm: React.FC<DefaultWorkspaceProps> = ({ patientUuid, closeWor
if (response.status === 201) {
if (config.showServiceQueueFields) {
// retrieve values from queue extension

setVisitUuid(response.data.uuid);
const queueLocation = event?.target['queueLocation']?.value;
const serviceUuid = event?.target['service']?.value;
const priority = event?.target['priority']?.value;
Expand All @@ -194,6 +197,7 @@ const StartVisitForm: React.FC<DefaultWorkspaceProps> = ({ patientUuid, closeWor
({ status }) => {
if (status === 201) {
mutate();
mutateQueueEntry();
showToast({
kind: 'success',
title: t('visitStarted', 'Visit started'),
Expand Down

0 comments on commit 98c235f

Please sign in to comment.