Skip to content

Commit 4dc4747

Browse files
committed
added first version of the patients-without-episodes warning table in the landing page
1 parent 655fc98 commit 4dc4747

File tree

5 files changed

+85
-3
lines changed

5 files changed

+85
-3
lines changed

src/api/patientsAPI/patientsAPI.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ export default {
1717
getSurgeons: (params?: PaginationParams) =>
1818
request(METHODS.GET, '/medical-personnel/', { params }),
1919
getPatient: (id: string) => request(METHODS.GET, `/patients/${id}/`, {}),
20+
getUnlinkedPatients: () => request(METHODS.GET, '/unlinked-patients/', {}),
2021
getEpisode: (id: string) => request(METHODS.GET, `/episodes/${id}/`, {}),
2122
getEpisodeDischarge: (id: string) => request(METHODS.GET, `/episodes/${id}/discharge/`, {}),
2223
getEpisodeFollowUps: (id: string) => request(METHODS.GET, `/episodes/${id}/follow-ups/`, {}),

src/hooks/api/patientHooks.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import {
2323
RegisterEpisodePayload,
2424
RegisterPatientPayload,
2525
SurgeonEpisodeSummaryAPI,
26-
SurgeonsResponse,
26+
SurgeonsResponse, UnlinkedPatientsResponse,
2727
} from '../../models/apiTypes';
2828
import { RegisterEpisodeFormType } from '../../pages/RegisterEpisode/types';
2929
import { RegisterPatientFormType } from '../../pages/RegisterPatient/types';
@@ -138,6 +138,22 @@ export const useGetPatients = (params?: PatientsPayload) => {
138138
);
139139
};
140140

141+
export const useGetUnlinkedPatients = () => {
142+
return useQuery<UnlinkedPatientsResponse, AxiosError>(
143+
ReactQueryKeys.UnlinkedPatientsQuery,
144+
async () => {
145+
const { request } = patientsAPI.single.getUnlinkedPatients();
146+
return await request();
147+
},
148+
{
149+
onError: (error: AxiosError) => {
150+
console.error("Error fetching unlinked patients:", error);
151+
},
152+
retry: false,
153+
}
154+
);
155+
};
156+
141157
export const useGetSurgeons = (params?: PaginationParams) => {
142158
return useQuery<SurgeonsResponse, AxiosError, SurgeonsResponse>(
143159
[ReactQueryKeys.SurgeonsQuery, params?.limit, params?.offset, params?.ordering],

src/hooks/constants.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@ export const ReactQueryKeys = {
66
PreferredHospitalQuery: 'preferredHospital',
77
SurgeonEpisodeSummaryQuery: 'surgeonEpisodeSummary',
88
OwnedEpisodesQuery: 'ownedEpisodes',
9+
UnlinkedPatientsQuery: 'unlinkedPatientsQuery',
910
};

src/models/apiTypes.tsx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,4 +235,13 @@ export type OwnedEpisodeAPI = {
235235
follow_up_dates: FollowUpAPI[];
236236
patient_id: number;
237237
hospital_id: number;
238-
};
238+
};
239+
240+
export type UnlinkedPatient = {
241+
id: string;
242+
full_name: string;
243+
hospital_id: string;
244+
patient_hospital_id: string;
245+
};
246+
247+
export type UnlinkedPatientsResponse = UnlinkedPatient[];

src/pages/LandingPage/LandingPage.tsx

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
import React, { useState } from 'react';
22

33
import { Button } from '@orfium/ictinus';
4-
import { useGetSurgeonEpisodeSummary, useGetOwnedEpisodes } from 'hooks/api/patientHooks';
4+
import {
5+
useGetSurgeonEpisodeSummary,
6+
useGetOwnedEpisodes,
7+
useGetUnlinkedPatients,
8+
useGetPreferredHospital,
9+
} from 'hooks/api/patientHooks';
510
import { useHistory } from 'react-router-dom';
611
import urls from 'routing/urls';
712

@@ -19,6 +24,9 @@ const LandingPage: React.FC = () => {
1924
const history = useHistory();
2025
const { isDesktop } = useResponsiveLayout();
2126

27+
const { data: preferredHospital, isLoading: isLoadingHospital, error: hospitalError } = useGetPreferredHospital();
28+
const { data: unlinkedPatients = [] } = useGetUnlinkedPatients();
29+
2230
// State to handle sorting
2331
const [sortConfig, setSortConfig] = useState<{
2432
key: keyof OwnedEpisodeAPI | 'discharged';
@@ -105,6 +113,53 @@ const LandingPage: React.FC = () => {
105113
<DashboardText>Loading surgeon summary...</DashboardText>
106114
)}
107115

116+
{/* Display unlinked patients section */}
117+
{isLoadingHospital ? (
118+
<DashboardText>Loading preferred hospital...</DashboardText>
119+
) : hospitalError ? (
120+
<DashboardText style={{ color: 'red' }}>
121+
Failed to load preferred hospital: {hospitalError.message}
122+
</DashboardText>
123+
) : !preferredHospital || Object.keys(preferredHospital).length === 0 ? (
124+
<DashboardText style={{ color: 'red', fontStyle: 'italic' }}>
125+
Configure your preferred hospital to view any patients missing an episode.
126+
</DashboardText>
127+
) : unlinkedPatients.length > 0 ? (
128+
<div style={{ marginBottom: '2rem' }}>
129+
<DashboardTextHeader>
130+
<h2>Patients without Episodes Registered in Your Hospital</h2>
131+
</DashboardTextHeader>
132+
<div style={{ maxHeight: '150px', overflowY: 'auto' }}>
133+
<table style={{ width: '100%', borderCollapse: 'collapse' }}>
134+
<thead>
135+
<tr>
136+
<th style={{ border: '1px solid lightgrey', padding: '8px' }}>Patient Name</th>
137+
<th style={{ border: '1px solid lightgrey', padding: '8px' }}>Patient Hospital ID</th>
138+
</tr>
139+
</thead>
140+
<tbody>
141+
{unlinkedPatients.map((patient) => (
142+
<tr
143+
key={patient.id}
144+
onClick={() =>
145+
history.push(`${urls.patients()}/${patient.hospital_id}/${patient.id}`)
146+
}
147+
style={{
148+
backgroundColor: '#fc7c7c',
149+
cursor: 'pointer',
150+
borderBottom: '1px solid lightgrey',
151+
}}
152+
>
153+
<td style={{ border: '1px solid lightgrey', padding: '8px' }}>{patient.full_name}</td>
154+
<td style={{ border: '1px solid lightgrey', padding: '8px' }}>{patient.patient_hospital_id}</td>
155+
</tr>
156+
))}
157+
</tbody>
158+
</table>
159+
</div>
160+
</div>
161+
) : null}
162+
108163
{/* Render owned episodes table */}
109164
{ownedEpisodes ? (
110165
ownedEpisodes.length > 0 ? (

0 commit comments

Comments
 (0)