@@ -39,12 +39,18 @@ def create_immunisation(vaccination_record)
39
39
" #{ vaccination_record . id } "
40
40
)
41
41
42
- response =
43
- NHS ::API . connection . post (
44
- "/immunisation-fhir-api/FHIR/R4/Immunization" ,
45
- vaccination_record . fhir_record . to_json ,
46
- "Content-Type" => "application/fhir+json"
47
- )
42
+ response , duration =
43
+ execute_and_time do
44
+ NHS ::API . connection . post (
45
+ "/immunisation-fhir-api/FHIR/R4/Immunization" ,
46
+ vaccination_record . fhir_record . to_json ,
47
+ "Content-Type" => "application/fhir+json"
48
+ )
49
+ end
50
+
51
+ Rails . logger . info (
52
+ "Create response returned with status #{ response . status } in #{ duration } s"
53
+ )
48
54
49
55
if response . status == 201
50
56
vaccination_record . update! (
@@ -94,15 +100,21 @@ def update_immunisation(vaccination_record)
94
100
)
95
101
96
102
nhs_id = vaccination_record . nhs_immunisations_api_id
97
- response =
98
- NHS ::API . connection . put (
99
- "/immunisation-fhir-api/FHIR/R4/Immunization/#{ nhs_id } " ,
100
- vaccination_record . fhir_record . to_json ,
101
- {
102
- "Content-Type" => "application/fhir+json" ,
103
- "E-Tag" => vaccination_record . nhs_immunisations_api_etag
104
- }
105
- )
103
+ response , duration =
104
+ execute_and_time do
105
+ NHS ::API . connection . put (
106
+ "/immunisation-fhir-api/FHIR/R4/Immunization/#{ nhs_id } " ,
107
+ vaccination_record . fhir_record . to_json ,
108
+ {
109
+ "Content-Type" => "application/fhir+json" ,
110
+ "E-Tag" => vaccination_record . nhs_immunisations_api_etag
111
+ }
112
+ )
113
+ end
114
+
115
+ Rails . logger . info (
116
+ "Update response returned with status #{ response . status } in #{ duration } s"
117
+ )
106
118
107
119
if response . status == 200
108
120
vaccination_record . update! (
@@ -153,15 +165,21 @@ def delete_immunisation(vaccination_record)
153
165
)
154
166
155
167
nhs_id = vaccination_record . nhs_immunisations_api_id
156
- response =
157
- NHS ::API . connection . delete (
158
- "/immunisation-fhir-api/FHIR/R4/Immunization/#{ nhs_id } " ,
159
- nil ,
160
- {
161
- "Accept" => "application/fhir+json" ,
162
- "E-Tag" => vaccination_record . nhs_immunisations_api_etag
163
- }
164
- )
168
+ response , duration =
169
+ execute_and_time do
170
+ NHS ::API . connection . delete (
171
+ "/immunisation-fhir-api/FHIR/R4/Immunization/#{ nhs_id } " ,
172
+ nil ,
173
+ {
174
+ "Accept" => "application/fhir+json" ,
175
+ "E-Tag" => vaccination_record . nhs_immunisations_api_etag
176
+ }
177
+ )
178
+ end
179
+
180
+ Rails . logger . info (
181
+ "Delete response returned with status #{ response . status } in #{ duration } s"
182
+ )
165
183
166
184
if response . status == 204
167
185
# It's not entirely clear if the e-tag should be changed here, but
@@ -226,12 +244,18 @@ def search_immunisations(patient, programmes:, date_from: nil, date_to: nil)
226
244
"-date.to" => date_to &.strftime ( "%F" )
227
245
} . compact
228
246
229
- response =
230
- NHS ::API . connection . get (
231
- "/immunisation-fhir-api/FHIR/R4/Immunization" ,
232
- params ,
233
- "Content-Type" => "application/fhir+json"
234
- )
247
+ response , duration =
248
+ execute_and_time do
249
+ NHS ::API . connection . get (
250
+ "/immunisation-fhir-api/FHIR/R4/Immunization" ,
251
+ params ,
252
+ "Content-Type" => "application/fhir+json"
253
+ )
254
+ end
255
+
256
+ Rails . logger . info (
257
+ "Search response returned with status #{ response . status } in #{ duration } s"
258
+ )
235
259
236
260
if response . status == 200
237
261
# # To create fixtures for testing
@@ -361,5 +385,12 @@ def check_operation_outcome_entry(bundle)
361
385
"OperationOutcome entry found in bundle: #{ operation_outcome_entry . resource } "
362
386
end
363
387
end
388
+
389
+ def execute_and_time ( &block )
390
+ start = Process . clock_gettime ( Process ::CLOCK_MONOTONIC )
391
+ result = block . call
392
+ duration = Process . clock_gettime ( Process ::CLOCK_MONOTONIC ) - start
393
+ [ result , duration ]
394
+ end
364
395
end
365
396
end
0 commit comments