@@ -11,8 +11,11 @@ import {
11
11
PatientAPI ,
12
12
PatientsPayload ,
13
13
PatientsResponse ,
14
+ RegisterEpisodePayload ,
14
15
RegisterPatientPayload ,
16
+ SurgeonsResponse ,
15
17
} from '../../models/apiTypes' ;
18
+ import { RegisterEpisodeFormType } from '../../pages/RegisterEpisode/types' ;
16
19
import { RegisterPatientFormType } from '../../pages/RegisterPatient/types' ;
17
20
import urls from '../../routing/urls' ;
18
21
@@ -77,6 +80,22 @@ export const useGetPatients = (params?: PatientsPayload) => {
77
80
) ;
78
81
} ;
79
82
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
+
80
99
export const useGetPatient = ( id : string ) => {
81
100
return useQuery < PatientAPI , AxiosError , PatientAPI > (
82
101
[ ReactQueryKeys . PatientsQuery , id ] ,
@@ -122,3 +141,44 @@ export const useRegisterPatient = () => {
122
141
}
123
142
) ;
124
143
} ;
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
+ } ;
0 commit comments