@@ -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' ;
1619import { RegisterPatientFormType } from '../../pages/RegisterPatient/types' ;
1720import 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+
8099export 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+ } ;
0 commit comments