Skip to content

Commit e74e18d

Browse files
committed
feat: add follow up
1 parent 9d986bd commit e74e18d

File tree

12 files changed

+483
-28
lines changed

12 files changed

+483
-28
lines changed

src/api/patientsAPI/patientsAPI.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
RegisterEpisodePayload,
77
HospitalMappingPayload,
88
DischargePayload,
9+
FollowUpPayload,
910
} from '../../models/apiTypes';
1011
import { METHODS, request } from '../axiosInstances';
1112

@@ -26,4 +27,5 @@ export default {
2627
createHospitalMapping: (params: HospitalMappingPayload) =>
2728
request(METHODS.POST, '/patient-hospital-mappings/', { params }),
2829
dischargePatient: (params: DischargePayload) => request(METHODS.POST, `/discharges/`, { params }),
30+
followUpPatient: (params: FollowUpPayload) => request(METHODS.POST, `/follow-ups/`, { params }),
2931
};

src/hooks/api/patientHooks.ts

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ import {
88
DischargeAPI,
99
DischargeForm,
1010
EpisodesAPI,
11+
FollowUpAPI,
12+
FollowUpForm,
13+
FollowUpPayload,
1114
HospitalMappingPayload,
1215
HospitalsAPI,
1316
HospitalsResponse,
@@ -222,7 +225,7 @@ export const useGetEpisode = (id: string) => {
222225
};
223226

224227
export const useGetEpisodeDischarge = (id: string) => {
225-
return useQuery<EpisodesAPI, AxiosError, EpisodesAPI>(
228+
return useQuery<DischargeAPI, AxiosError, DischargeAPI>(
226229
[ReactQueryKeys.EpisodesQuery, id, 'discharge'],
227230
async () => {
228231
const { request } = patientsAPI.single.getEpisodeDischarge(id);
@@ -238,7 +241,7 @@ export const useGetEpisodeDischarge = (id: string) => {
238241
};
239242

240243
export const useGetEpisodeFollowUps = (id: string) => {
241-
return useQuery<EpisodesAPI, AxiosError, EpisodesAPI>(
244+
return useQuery<FollowUpAPI, AxiosError, FollowUpAPI[]>(
242245
[ReactQueryKeys.EpisodesQuery, id, 'follow-up'],
243246
async () => {
244247
const { request } = patientsAPI.single.getEpisodeFollowUps(id);
@@ -268,6 +271,38 @@ export const useDischarge = (episodeID: string) => {
268271
return request();
269272
},
270273
{
274+
onSuccess: () => {
275+
window.location.reload();
276+
},
277+
onError: (errors) => {
278+
console.log(errors);
279+
},
280+
}
281+
);
282+
};
283+
284+
export const useFollowUp = (episodeID: string) => {
285+
return useMutation<FollowUpPayload, AxiosError, FollowUpForm>(
286+
(params) => {
287+
const payload = {
288+
episode_id: parseInt(episodeID),
289+
date: params?.date,
290+
attendee_ids: params?.attendees?.map((attendee) => attendee?.value) ?? ['1'],
291+
mesh_awareness: params?.mesh_awareness.label === 'Yes',
292+
seroma: params?.seroma.label === 'Yes',
293+
infection: params?.infection.label === 'Yes',
294+
numbness: params?.numbness.label === 'Yes',
295+
pain_severity: params?.pain_severity.label,
296+
};
297+
298+
const { request } = patientsAPI.single.followUpPatient(payload);
299+
300+
return request();
301+
},
302+
{
303+
onSuccess: () => {
304+
window.location.reload();
305+
},
271306
onError: (errors) => {
272307
console.log(errors);
273308
},

src/models/apiTypes.tsx

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,19 @@ export type FollowUpPayload = {
7474
numbness: boolean;
7575
};
7676

77+
export type FollowUpForm = {
78+
pain_severity: SelectOption;
79+
date: string;
80+
attendees: {
81+
label: string;
82+
value: number;
83+
}[];
84+
mesh_awareness: SelectOption;
85+
seroma: SelectOption;
86+
infection: SelectOption;
87+
numbness: SelectOption;
88+
};
89+
7790
export type DischargeAPI = {
7891
id: number;
7992
episode: EpisodesAPI;

src/pages/EpisodeDetails/EpisodeDetails.tsx

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,11 @@ import { Icon } from '@orfium/ictinus';
55
import { useHistory, useRouteMatch } from 'react-router-dom';
66

77
import { PageTitle } from '../../common.style';
8-
import { useGetEpisode, useGetEpisodeDischarge } from '../../hooks/api/patientHooks';
8+
import {
9+
useGetEpisode,
10+
useGetEpisodeDischarge,
11+
useGetEpisodeFollowUps,
12+
} from '../../hooks/api/patientHooks';
913
import urls from '../../routing/urls';
1014
import {
1115
Heading,
@@ -18,15 +22,13 @@ import FollowUps from './components/ExpandableContainer/components/FollowUps';
1822
import Surgery from './components/ExpandableContainer/components/Surgery';
1923
import { Container, PageWrapper } from './EpisodeDetails.style';
2024

21-
// type Props = {};
22-
2325
const EpisodeDetails: React.FC = () => {
2426
const history = useHistory();
2527
const match = useRouteMatch<{ hospitalID: string; patientID: string; episodeID: string }>();
2628
const { hospitalID, patientID, episodeID } = match.params;
2729

2830
const { data: episode } = useGetEpisode(episodeID);
29-
// const { data: followUps } = useGetEpisodeFollowUps(episodeID);
31+
const { data: followUps } = useGetEpisodeFollowUps(episodeID);
3032
const { data: discharge } = useGetEpisodeDischarge(episodeID);
3133

3234
return (
@@ -50,13 +52,34 @@ const EpisodeDetails: React.FC = () => {
5052
</TextWrapper>
5153
{/* eslint-disable-next-line @typescript-eslint/ban-ts-comment */}
5254
{/*// @ts-ignore*/}
53-
<ExpandableContainer title={'Surgery'} component={Surgery} episode={episode} />
55+
<ExpandableContainer isDone title={'Surgery'} component={Surgery} episode={episode} />
5456
{/* eslint-disable-next-line @typescript-eslint/ban-ts-comment */}
5557
{/*// @ts-ignore*/}
56-
<ExpandableContainer title={'Discharge'} component={Discharge} discharge={discharge} />
58+
<ExpandableContainer
59+
isDone={discharge?.infection !== undefined}
60+
title={'Discharge'}
61+
/* eslint-disable-next-line @typescript-eslint/ban-ts-comment */
62+
/*// @ts-ignore*/
63+
component={Discharge}
64+
discharge={discharge}
65+
/>
66+
67+
{followUps?.map((followUp, index) => (
68+
<ExpandableContainer
69+
key={`follow_up_${index}`}
70+
title={'Follow Up'}
71+
isDone
72+
/* eslint-disable-next-line @typescript-eslint/ban-ts-comment */
73+
/*// @ts-ignore*/
74+
component={FollowUps}
75+
/* eslint-disable-next-line @typescript-eslint/ban-ts-comment */
76+
/*// @ts-ignore*/
77+
followUp={followUp}
78+
/>
79+
))}
5780
{/* eslint-disable-next-line @typescript-eslint/ban-ts-comment */}
5881
{/*// @ts-ignore*/}
59-
<ExpandableContainer title={'Follow Up'} component={FollowUps} />
82+
<ExpandableContainer isDone={false} title={'Follow Up'} component={FollowUps} />
6083
</Container>
6184
)}
6285
</PageWrapper>

src/pages/EpisodeDetails/components/ExpandableContainer/ExpandableContainer.tsx

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import React, { FC, useState } from 'react';
22

33
import { Icon, useTheme } from '@orfium/ictinus';
44

5-
import { DischargeAPI, EpisodesAPI } from '../../../../models/apiTypes';
5+
import { DischargeAPI, EpisodesAPI, FollowUpAPI } from '../../../../models/apiTypes';
66
import { Header, ListItem } from './style';
77

88
const ExpandableContainer: FC<{
@@ -11,11 +11,14 @@ const ExpandableContainer: FC<{
1111
onClick?: () => void;
1212
episode?: EpisodesAPI;
1313
discharge?: DischargeAPI;
14+
followUp?: FollowUpAPI;
1415
}>;
1516
title: string;
1617
episode?: EpisodesAPI;
1718
discharge?: DischargeAPI;
18-
}> = ({ component: Component, title, episode, discharge }) => {
19+
followUp?: FollowUpAPI;
20+
isDone?: boolean;
21+
}> = ({ component: Component, title, episode, discharge, followUp, isDone = false }) => {
1922
const [toggle, setToggle] = useState(false);
2023
const {
2124
utils: { getColor },
@@ -29,15 +32,19 @@ const ExpandableContainer: FC<{
2932
}}
3033
>
3134
<Header isOpen={toggle}>
32-
{title}
35+
<div style={{ display: 'flex', gap: '4px', alignItems: 'center' }}>
36+
{title}{' '}
37+
{isDone && !toggle && <Icon name={'checkmark'} size={20} color={'green'} variant={400} />}
38+
</div>
39+
3340
<Icon
3441
name={toggle ? 'chevronLargeUp' : 'chevronLargeDown'}
3542
color={getColor('lightGray', 500)}
3643
/>
3744
</Header>
3845

3946
<div onClick={(e: any) => e.stopPropagation()}>
40-
<Component isOpen={toggle} episode={episode} discharge={discharge} />
47+
<Component isOpen={toggle} episode={episode} discharge={discharge} followUp={followUp} />
4148
</div>
4249
</ListItem>
4350
);

src/pages/EpisodeDetails/components/ExpandableContainer/components/Discharge.tsx

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,15 @@ const Discharge: FC<{
6969
<FieldWrapper>
7070
<Field
7171
name="aware_of_mesh"
72-
initialValue={BOOLEAN_OPTIONS.find((option) =>
73-
discharge?.aware_of_mesh ? option.label === 'Yes' : option.label === 'No'
74-
)}
72+
initialValue={
73+
discharge?.aware_of_mesh !== undefined
74+
? BOOLEAN_OPTIONS.find((option) =>
75+
discharge?.aware_of_mesh
76+
? option.label === 'Yes'
77+
: option.label === 'No'
78+
)
79+
: undefined
80+
}
7581
>
7682
{(props) => {
7783
const hasError =
@@ -104,9 +110,13 @@ const Discharge: FC<{
104110
<FieldWrapper>
105111
<Field
106112
name="infection"
107-
initialValue={BOOLEAN_OPTIONS.find((option) =>
108-
discharge?.infection ? option.label === 'Yes' : option.label === 'No'
109-
)}
113+
initialValue={
114+
discharge?.infection !== undefined
115+
? BOOLEAN_OPTIONS.find((option) =>
116+
discharge?.infection ? option.label === 'Yes' : option.label === 'No'
117+
)
118+
: undefined
119+
}
110120
>
111121
{(props) => {
112122
const hasError =

0 commit comments

Comments
 (0)