Skip to content

Commit c121d50

Browse files
committed
feat: add RegisterEpisode and connect with api
1 parent d646798 commit c121d50

File tree

20 files changed

+986
-24
lines changed

20 files changed

+986
-24
lines changed

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"@emotion/jest": "^11.2.1",
1111
"@emotion/react": "^11.4.1",
1212
"@emotion/styled": "^11.3.0",
13-
"@orfium/ictinus": "^3.9.1",
13+
"@orfium/ictinus": "^3.14.1",
1414
"@testing-library/jest-dom": "^5.11.9",
1515
"@testing-library/react": "^12.1.2",
1616
"@testing-library/user-event": "^13.1.3",
@@ -23,11 +23,13 @@
2323
"axios": "^0.21.1",
2424
"customize-cra": "^1.0.0",
2525
"final-form": "^4.20.2",
26+
"final-form-arrays": "^3.0.2",
2627
"history": "^4.10.1",
2728
"lodash": "^4.17.21",
2829
"react": "^17.0.2",
2930
"react-dom": "^17.0.2",
3031
"react-final-form": "^6.5.3",
32+
"react-final-form-arrays": "^3.1.3",
3133
"react-final-form-listeners": "^1.0.3",
3234
"react-query": "^3.16.0",
3335
"react-router-dom": "^5.2.0",

src/api/patientsAPI/patientsAPI.tsx

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,21 @@
11
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
2-
import { RegisterPatientPayload, PatientsPayload, PaginationParams } from '../../models/apiTypes';
2+
import {
3+
RegisterPatientPayload,
4+
PatientsPayload,
5+
PaginationParams,
6+
RegisterEpisodePayload,
7+
} from '../../models/apiTypes';
38
import { METHODS, request } from '../axiosInstances';
49

510
export default {
611
getHospitals: (params?: PaginationParams) => request(METHODS.GET, '/hospitals/', { params }),
7-
getHospital: (id: string) => request(METHODS.GET, `/hospitals/${id}`, {}),
12+
getHospital: (id: string) => request(METHODS.GET, `/hospitals/${id}/`, {}),
813
getPatients: (params?: PatientsPayload) => request(METHODS.GET, '/patients/', { params }),
9-
getPatient: (id: string) => request(METHODS.GET, `/patients/${id}`, {}),
14+
getSurgeons: (params?: PaginationParams) =>
15+
request(METHODS.GET, '/medical-personnel/', { params }),
16+
getPatient: (id: string) => request(METHODS.GET, `/patients/${id}/`, {}),
1017
registerPatient: (params: RegisterPatientPayload) =>
1118
request(METHODS.POST, '/patients/', { params }),
19+
registerEpisode: (params: RegisterEpisodePayload) =>
20+
request(METHODS.POST, '/episodes/', { params }),
1221
};

src/common.style.tsx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,15 @@ export const PageTitle = styled.div`
7676
padding: 16px;
7777
`;
7878

79+
export const PageSubtitle = styled.div`
80+
color: ${(props) => props.theme.utils.getColor('darkGray', 400)};
81+
display: flex;
82+
font-size: 18px;
83+
font-weight: 400;
84+
gap: 16px;
85+
padding: 16px;
86+
`;
87+
7988
export const SectionTitle = styled.div`
8089
color: ${(props) => props.theme.utils.getColor('blue', 500)};
8190
font-size: 18px;

src/hooks/api/patientHooks.ts

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,11 @@ import {
1111
PatientAPI,
1212
PatientsPayload,
1313
PatientsResponse,
14+
RegisterEpisodePayload,
1415
RegisterPatientPayload,
16+
SurgeonsResponse,
1517
} from '../../models/apiTypes';
18+
import { RegisterEpisodeFormType } from '../../pages/RegisterEpisode/types';
1619
import { RegisterPatientFormType } from '../../pages/RegisterPatient/types';
1720
import urls from '../../routing/urls';
1821

@@ -77,6 +80,22 @@ export const useGetPatients = (params?: PatientsPayload) => {
7780
);
7881
};
7982

83+
export const useGetSurgeons = (params?: PaginationParams) => {
84+
return useQuery<SurgeonsResponse, AxiosError, SurgeonsResponse>(
85+
[ReactQueryKeys.SurgeonsQuery, params?.limit, params?.offset, params?.ordering],
86+
async () => {
87+
const { request } = patientsAPI.single.getSurgeons(params);
88+
return await request();
89+
},
90+
{
91+
onError: (errors) => {
92+
console.log(errors);
93+
},
94+
retry: false,
95+
}
96+
);
97+
};
98+
8099
export const useGetPatient = (id: string) => {
81100
return useQuery<PatientAPI, AxiosError, PatientAPI>(
82101
[ReactQueryKeys.PatientsQuery, id],
@@ -122,3 +141,44 @@ export const useRegisterPatient = () => {
122141
}
123142
);
124143
};
144+
145+
export const useRegisterEpisode = (
146+
hospitalID?: string,
147+
patientID?: string,
148+
episodeType = 'Inguinal Mesh Hernia Repair'
149+
) => {
150+
const history = useHistory();
151+
152+
return useMutation<RegisterEpisodePayload, AxiosError, RegisterEpisodeFormType>(
153+
(params) => {
154+
const payload = {
155+
hospital_id: params?.hospital?.value,
156+
patient_id: parseInt(patientID ?? '0'),
157+
anaesthetic_type: params?.anaestheticType?.label,
158+
diathermy_used: params?.diathermyUsed?.label === 'True',
159+
surgeon_ids: params?.surgeons?.map((surgeon) => surgeon?.value) ?? ['1'],
160+
comments: params?.comments,
161+
mesh_type: params?.meshType?.label,
162+
episode_type: episodeType,
163+
type: params.type?.label,
164+
cepod: params.cepod?.label,
165+
complexity: params?.complexity?.label,
166+
occurence: params?.occurence?.label,
167+
side: params?.side?.label,
168+
surgery_date: params?.surgeryDate,
169+
};
170+
171+
const { request } = patientsAPI.single.registerEpisode(payload);
172+
173+
return request();
174+
},
175+
{
176+
onSuccess: () => {
177+
history.replace(`${urls.patients()}/${hospitalID}/${patientID}`);
178+
},
179+
onError: (errors) => {
180+
console.log(errors);
181+
},
182+
}
183+
);
184+
};

src/hooks/constants.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
export const ReactQueryKeys = {
22
PatientsQuery: 'patientsQuery',
33
HospitalsQuery: 'hospitalsQuery',
4+
SurgeonsQuery: 'surgeonsQuery',
45
};

src/models/apiTypes.tsx

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,36 @@ export type HospitalsAPI = {
3636
patient_hospital_id?: number;
3737
};
3838

39-
// export type EpisodesAPI = {};
39+
export type EpisodesAPI = {
40+
episode_type: string;
41+
cepod: string;
42+
side: string;
43+
occurence: string;
44+
type: string;
45+
complexity: string;
46+
mesh_type: string;
47+
diathermy_used: boolean;
48+
comments?: string;
49+
anaesthetic_type: string;
50+
surgeons: SurgeonsAPI[];
51+
};
52+
53+
export type RegisterEpisodePayload = {
54+
hospital_id: number;
55+
patient_id: number;
56+
surgery_date: string;
57+
episode_type: string;
58+
cepod: string;
59+
side: string;
60+
occurence: string;
61+
type: string;
62+
complexity: string;
63+
mesh_type: string;
64+
diathermy_used: boolean;
65+
comments?: string;
66+
anaesthetic_type: string;
67+
surgeon_ids: number[];
68+
};
4069

4170
export interface HospitalsResponse extends PaginationResponse, PaginationParams {
4271
results: HospitalsAPI[];
@@ -73,9 +102,20 @@ export type PatientAPI = {
73102
phone_2: string;
74103
address: string;
75104
hospital_mappings: HospitalsAPI[];
76-
// episodes: EpisodesAPI[];
105+
episodes: EpisodesAPI[];
77106
};
78107

79108
export interface PatientsResponse extends PaginationResponse, PaginationParams {
80109
results: PatientAPI[];
81110
}
111+
112+
export type SurgeonsAPI = {
113+
id: number;
114+
user: {
115+
email: string;
116+
};
117+
level: string;
118+
};
119+
export interface SurgeonsResponse extends PaginationResponse, PaginationParams {
120+
results: SurgeonsAPI[];
121+
}

src/pages/PatientDetails/PatientDetails.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,14 @@ const PatientDetails: React.FC = () => {
5757
)}
5858
</ComponentWrapper>
5959
<ButtonContainer>
60-
<Button color={'blue-500'} buttonType="button" disabled={isLoading} block size="md">
60+
<Button
61+
color={'blue-500'}
62+
buttonType="button"
63+
disabled={isLoading}
64+
block
65+
size="md"
66+
onClick={() => history.push(`${history.location.pathname}/add-episode`)}
67+
>
6168
Register new episode
6269
</Button>
6370
</ButtonContainer>

src/pages/PatientDetails/components/GeneralInformation/GeneralInformation.tsx

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,19 @@ const GeneralInformation: React.FC<Props> = ({ patient, hospital }) => {
2222
locked
2323
label="Full Name"
2424
styleType="outlined"
25-
size="sm"
25+
size="md"
2626
value={patient?.full_name}
2727
/>
2828

29-
<TextField locked label="Gender" styleType="outlined" size="sm" value={patient?.gender} />
29+
<TextField locked label="Gender" styleType="outlined" size="md" value={patient?.gender} />
3030
<FieldsContainer>
3131
<TextField
3232
locked
3333
id="year_of_birth"
3434
label="Year Of Birth"
3535
styleType="outlined"
3636
type="number"
37-
size="sm"
37+
size="md"
3838
value={patient?.year_of_birth}
3939
/>
4040
<TextField
@@ -43,32 +43,32 @@ const GeneralInformation: React.FC<Props> = ({ patient, hospital }) => {
4343
label="Age"
4444
type="number"
4545
styleType="outlined"
46-
size="sm"
46+
size="md"
4747
value={patient?.age}
4848
/>
4949
</FieldsContainer>
5050
<TextField
5151
id="national_id"
5252
label="National ID"
5353
styleType="outlined"
54-
size="sm"
54+
size="md"
5555
locked
5656
value={patient?.national_id}
5757
/>
5858
<TextField
5959
id="hospital"
6060
label="Hospital"
6161
styleType="outlined"
62-
size="sm"
62+
size="md"
6363
locked
6464
value={hospital?.name}
6565
/>
6666
<TextField
6767
id="patient_hospital_id"
6868
label="Patient Hospital ID"
69-
required
7069
styleType="outlined"
71-
size="sm"
70+
size="md"
71+
locked
7272
value={hospitalPatientID}
7373
/>
7474
</Container>
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import styled from '@emotion/styled';
2+
3+
export const FormHeading = styled.span`
4+
font-size: 14px;
5+
font-weight: 700;
6+
margin-bottom: 12px;
7+
padding: 18px;
8+
`;

0 commit comments

Comments
 (0)