Skip to content

Commit 0cf9876

Browse files
committed
VED-457: Return updated version in two missed places.
1 parent e1ad434 commit 0cf9876

File tree

3 files changed

+29
-27
lines changed

3 files changed

+29
-27
lines changed

backend/src/fhir_controller.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ def update_immunization(self, aws_event):
225225

226226
# Validate the imms id - start
227227
if id_error := self._validate_id(imms_id):
228-
return FhirController.create_response(400, json.dumps(id_error))
228+
return FhirController.create_response(400, json.dumps(id_error))
229229
# Validate the imms id - end
230230

231231
# Validate the body of the request - start
@@ -281,9 +281,13 @@ def update_immunization(self, aws_event):
281281
try:
282282
# Validate if the imms resource to be updated is a logically deleted resource - start
283283
if existing_record["DeletedAt"] == True:
284-
285284
outcome, resource, updated_version = self.fhir_service.reinstate_immunization(
286-
imms_id, imms, existing_resource_version, imms_vax_type_perms, supplier_system)
285+
imms_id,
286+
imms,
287+
existing_resource_version,
288+
imms_vax_type_perms,
289+
supplier_system
290+
)
287291
# Validate if the imms resource to be updated is a logically deleted resource-end
288292
else:
289293
# Validate if imms resource version is part of the request - start
@@ -332,7 +336,7 @@ def update_immunization(self, aws_event):
332336

333337
# Check if the record is reinstated record - start
334338
if existing_record["Reinstated"] == True:
335-
outcome, resource = self.fhir_service.update_reinstated_immunization(
339+
outcome, resource, updated_version = self.fhir_service.update_reinstated_immunization(
336340
imms_id,
337341
imms,
338342
existing_resource_version,
@@ -360,7 +364,7 @@ def update_immunization(self, aws_event):
360364
)
361365
return self.create_response(400, json.dumps(exp_error))
362366
if outcome == UpdateOutcome.UPDATE:
363-
return self.create_response(200, {"E-Tag": updated_version}) #include e-tag here, is it not included in the response resource
367+
return self.create_response(200, {"E-Tag": updated_version}) #include e-tag here, is it not included in the response resource
364368
except ValidationError as error:
365369
return self.create_response(400, error.to_operation_outcome())
366370
except IdentifierDuplicationError as duplicate:
@@ -543,7 +547,7 @@ def _create_bad_request(self, message):
543547
)
544548
return self.create_response(400, error)
545549

546-
550+
547551
def authorize_request(self, aws_event: dict) -> Optional[dict]:
548552
try:
549553
self.authorizer.authorize(aws_event)

backend/src/fhir_repository.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -194,9 +194,9 @@ def update_immunization(
194194
immunization: dict,
195195
patient: any,
196196
existing_resource_version: int,
197-
imms_vax_type_perms: str,
197+
imms_vax_type_perms: list[str],
198198
supplier_system: str,
199-
) -> dict:
199+
) -> tuple[dict, int]:
200200
attr = RecordAttributes(immunization, patient)
201201
self._handle_permissions(imms_vax_type_perms, attr)
202202
update_exp = self._build_update_expression(is_reinstate=False)
@@ -219,10 +219,10 @@ def reinstate_immunization(
219219
immunization: dict,
220220
patient: any,
221221
existing_resource_version: int,
222-
imms_vax_type_perms: str,
222+
imms_vax_type_perms: list[str],
223223
supplier_system: str,
224224

225-
) -> dict:
225+
) -> tuple[dict, int]:
226226
attr = RecordAttributes(immunization, patient)
227227
self._handle_permissions(imms_vax_type_perms, attr)
228228
update_exp = self._build_update_expression(is_reinstate=True)
@@ -245,9 +245,9 @@ def update_reinstated_immunization(
245245
immunization: dict,
246246
patient: any,
247247
existing_resource_version: int,
248-
imms_vax_type_perms: str,
248+
imms_vax_type_perms: list[str],
249249
supplier_system: str,
250-
) -> dict:
250+
) -> tuple[dict, int]:
251251
attr = RecordAttributes(immunization, patient)
252252
self._handle_permissions(imms_vax_type_perms, attr)
253253
update_exp = self._build_update_expression(is_reinstate=False)
@@ -353,12 +353,12 @@ def _perform_dynamo_update(
353353
def delete_immunization(
354354
self, imms_id: str, imms_vax_type_perms: str, supplier_system: str) -> dict:
355355
now_timestamp = int(time.time())
356-
356+
357357
try:
358358
item = self.table.get_item(Key={"PK": _make_immunization_pk(imms_id)}).get("Item")
359359
if not item:
360360
raise ResourceNotFoundError(resource_type="Immunization", resource_id=imms_id)
361-
361+
362362
if not item.get("DeletedAt") or item.get("DeletedAt") == "reinstated":
363363
vaccine_type = self._vaccine_type(item["PatientSK"])
364364
if not validate_permissions(imms_vax_type_perms, ApiOperationCode.DELETE, [vaccine_type]):
@@ -381,7 +381,7 @@ def delete_immunization(
381381
(Attr("DeletedAt").not_exists() | Attr("DeletedAt").eq("reinstated"))
382382
),
383383
)
384-
384+
385385
return self._handle_dynamo_response(response)
386386
except botocore.exceptions.ClientError as error:
387387
if error.response["Error"]["Code"] == "ConditionalCheckFailedException":

backend/src/fhir_service.py

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -136,12 +136,12 @@ def update_immunization(
136136
existing_resource_version: int,
137137
imms_vax_type_perms: list[str],
138138
supplier_system: str,
139-
) -> tuple[UpdateOutcome, Immunization]:
139+
) -> tuple[UpdateOutcome, Immunization, int]:
140140
immunization["id"] = imms_id
141141

142142
patient = self._validate_patient(immunization)
143143
if "diagnostics" in patient:
144-
return (None, patient)
144+
return (None, patient, None)
145145
imms, updated_version = self.immunization_repo.update_immunization(
146146
imms_id,
147147
immunization,
@@ -160,12 +160,12 @@ def reinstate_immunization(
160160
existing_resource_version: int,
161161
imms_vax_type_perms: list[str],
162162
supplier_system: str,
163-
) -> tuple[UpdateOutcome, Immunization]:
163+
) -> tuple[UpdateOutcome, Immunization, int]:
164164
immunization["id"] = imms_id
165165
patient = self._validate_patient(immunization)
166166
if "diagnostics" in patient:
167-
return (None, patient)
168-
imms = self.immunization_repo.reinstate_immunization(
167+
return (None, patient, None)
168+
imms, updated_version = self.immunization_repo.reinstate_immunization(
169169
imms_id,
170170
immunization,
171171
patient,
@@ -174,7 +174,7 @@ def reinstate_immunization(
174174
supplier_system,
175175
)
176176

177-
return UpdateOutcome.UPDATE, Immunization.parse_obj(imms)
177+
return UpdateOutcome.UPDATE, Immunization.parse_obj(imms), updated_version
178178

179179
def update_reinstated_immunization(
180180
self,
@@ -183,14 +183,12 @@ def update_reinstated_immunization(
183183
existing_resource_version: int,
184184
imms_vax_type_perms: list[str],
185185
supplier_system: str,
186-
) -> tuple[UpdateOutcome, Immunization]:
186+
) -> tuple[UpdateOutcome, Immunization, int]:
187187
immunization["id"] = imms_id
188-
189-
patient = None
190188
patient = self._validate_patient(immunization)
191189
if "diagnostics" in patient:
192-
return (None, patient)
193-
imms = self.immunization_repo.update_reinstated_immunization(
190+
return (None, patient, None)
191+
imms, updated_version = self.immunization_repo.update_reinstated_immunization(
194192
imms_id,
195193
immunization,
196194
patient,
@@ -199,7 +197,7 @@ def update_reinstated_immunization(
199197
supplier_system,
200198
)
201199

202-
return UpdateOutcome.UPDATE, Immunization.parse_obj(imms)
200+
return UpdateOutcome.UPDATE, Immunization.parse_obj(imms), updated_version
203201

204202
def delete_immunization(self, imms_id, imms_vax_type_perms, supplier_system) -> Immunization:
205203
"""

0 commit comments

Comments
 (0)