Skip to content

Commit b7b0d7d

Browse files
committed
BN-173|Fix models for Active Visit and tests
1 parent c27edfb commit b7b0d7d

File tree

7 files changed

+37
-4
lines changed

7 files changed

+37
-4
lines changed

apps/registration/src/pages/createPatientPage/__tests__/index.test.tsx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,16 @@ jest.mock('@bahmni-frontend/bahmni-services', () => ({
6565
getGenders: jest.fn(),
6666
createPatient: jest.fn(),
6767
getAddressHierarchyEntries: jest.fn(),
68+
getUserLoginLocation: jest.fn(() => ({
69+
uuid: 'test-location-uuid',
70+
name: 'Test Location',
71+
})),
72+
getVisitLocationUUID: jest.fn(() =>
73+
Promise.resolve({ uuid: '72636eba-29bf-4d6c-97c4-4b04d87a95b5' }),
74+
),
75+
getVisitTypes: jest.fn(() => Promise.resolve([])),
76+
getActiveVisitByPatient: jest.fn(() => Promise.resolve({ results: [] })),
77+
createVisit: jest.fn(() => Promise.resolve({})),
6878
notificationService: {
6979
showSuccess: jest.fn(),
7080
showError: jest.fn(),

apps/registration/src/pages/createPatientPage/__tests__/visitTypeSelector.test.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ const mockGetVisitTypes = jest.fn();
99
const mockCreateVisit = jest.fn();
1010
const mockGetUserLoginLocation = jest.fn();
1111
const mockGetActiveVisitByPatient = jest.fn();
12+
const mockGetVisitLocationUUID = jest.fn();
1213

1314
const mockNotificationService = {
1415
showError: jest.fn(),
@@ -21,6 +22,8 @@ jest.mock('@bahmni-frontend/bahmni-services', () => ({
2122
getUserLoginLocation: () => mockGetUserLoginLocation(),
2223
getActiveVisitByPatient: (patientUuid: string) =>
2324
mockGetActiveVisitByPatient(patientUuid),
25+
getVisitLocationUUID: (loginLocation: string) =>
26+
mockGetVisitLocationUUID(loginLocation),
2427
get notificationService() {
2528
return mockNotificationService;
2629
},
@@ -67,6 +70,9 @@ describe('VisitTypeSelector', () => {
6770
mockGetUserLoginLocation.mockReturnValue(mockLoginLocation);
6871
mockGetVisitTypes.mockResolvedValue(mockVisitTypes);
6972
mockGetActiveVisitByPatient.mockResolvedValue({ results: [] });
73+
mockGetVisitLocationUUID.mockResolvedValue({
74+
uuid: '72636eba-29bf-4d6c-97c4-4b04d87a95b5',
75+
});
7076
mockCreateVisit.mockResolvedValue({
7177
location: mockLoginLocation.uuid,
7278
patient: '9891a8b4-7404-4c05-a207-5ec9d34fc719',

apps/registration/src/pages/createPatientPage/visitTypeSelector.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export const VisitTypeSelector = ({ onVisitSave }: VisitTypeSelectorProps) => {
3636
});
3737

3838
const { data: visitLocationUUID } = useQuery({
39-
queryKey: ['visitLocationUUID'],
39+
queryKey: ['visitLocationUUID', getUserLoginLocation().uuid],
4040
queryFn: () => getVisitLocationUUID(getUserLoginLocation().uuid),
4141
staleTime: 5 * 60 * 1000,
4242
gcTime: 10 * 60 * 1000,

packages/bahmni-services/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ export {
3030
type AddressHierarchyEntry,
3131
type VisitType,
3232
type VisitLocationResponse,
33+
type ActiveVisit,
3334
} from './patientService';
3435
export { getFormattedError } from './errorHandling';
3536
export {

packages/bahmni-services/src/patientService/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,5 @@ export {
3030
type AddressHierarchyEntry,
3131
type VisitType,
3232
type VisitLocationResponse,
33+
type ActiveVisit,
3334
} from './models';

packages/bahmni-services/src/patientService/models.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,3 +158,7 @@ export interface CreateVisitRequest {
158158
export interface VisitLocationResponse {
159159
uuid: string;
160160
}
161+
162+
export interface ActiveVisit {
163+
results: unknown[];
164+
}

packages/bahmni-services/src/patientService/patientService.ts

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import {
3232
VisitType,
3333
CreateVisitRequest,
3434
VisitLocationResponse,
35+
ActiveVisit,
3536
} from './models';
3637

3738
export const getPatientById = async (patientUUID: string): Promise<Patient> => {
@@ -359,6 +360,11 @@ export const getVisitTypes = async (): Promise<VisitType[]> => {
359360
}));
360361
};
361362

363+
/**
364+
* Create a new visit for a patient
365+
* @param visitData - The visit data including patient UUID, visit type, and location
366+
* @returns Promise<unknown> - The created visit object
367+
*/
362368
export const createVisit = async (
363369
visitData: CreateVisitRequest,
364370
): Promise<unknown> => {
@@ -368,14 +374,19 @@ export const createVisit = async (
368374
/**
369375
* Get active visits for a patient
370376
* @param patientUuid - The UUID of the patient
371-
* @returns Promise<unknown> - The active visit data
377+
* @returns Promise<ActiveVisit> - The active visit data
372378
*/
373379
export const getActiveVisitByPatient = async (
374380
patientUuid: string,
375-
): Promise<unknown> => {
376-
return get<unknown>(GET_ACTIVE_VISIT_URL(patientUuid));
381+
): Promise<ActiveVisit> => {
382+
return get<ActiveVisit>(GET_ACTIVE_VISIT_URL(patientUuid));
377383
};
378384

385+
/**
386+
* Get visit location UUID for a given login location
387+
* @param loginLocation - The login location UUID
388+
* @returns Promise<VisitLocationResponse> - The visit location details including UUID
389+
*/
379390
export const getVisitLocationUUID = async (
380391
loginLocation: string,
381392
): Promise<VisitLocationResponse> => {

0 commit comments

Comments
 (0)