VED-747 Refactor update immunisation endpoint#966
Conversation
|
This branch is working on a ticket in the NHS England VED JIRA Project. Here's a handy link to the ticket: VED-747 |
| def __str__(self): | ||
| return f"The provided id:{self.imms_id} doesn't match with the content of the message" | ||
| return ( | ||
| f"Validation errors: The provided immunization id:{self.imms_id} doesn't match with the content of the " |
There was a problem hiding this comment.
We were previously not using this error. I adjusted the error message to avoid any regression, now that we use it when validating the IDs.
| except (ValidationError, ValueError, MandatoryError) as error: | ||
| raise CustomValidationError(message=str(error)) from error | ||
|
|
||
| patient = self._validate_patient(immunization) |
There was a problem hiding this comment.
Obsolete after removing PDS checks.
| imms_id = "an-id" | ||
| req_imms = create_covid_immunization_dict(imms_id) | ||
| self.fhir_service._validate_patient = MagicMock(return_value={}) | ||
| self.assertEqual(str(error.exception), "Immunization resource does not exist. ID: non-existent-id-123") |
There was a problem hiding this comment.
Testers: new validation error message will look like this which is consistent for 404 errors in our other endpoints.
Previously we were returning: Validation errors: The requested immunization resource with id:{imms_id} was not found. Please check if you have assertions which check this particular message in the Update endpoint, as they will need changing after this gets merged and deployed.
|
|
||
| @staticmethod | ||
| def _is_valid_resource_version(resource_version: str) -> bool: | ||
| return resource_version.isdigit() and int(resource_version) > 0 |
There was a problem hiding this comment.
Testers - minor change. Previously we permitted 0 and negative numbers. We will now catch such an error earlier on in the flow and get an error stating the the resource version is invalid.
Previously, this would have been accepted but then the update would fail on the old resource vs. new resource version check, as a resource in the database would only have a positive int as the resource version due to the constraints during both create and update operations.
|



Summary
Refactoring - no functional change with the exception of the following which I will flag to testers and mention as a comment:
General refactoring changes:
Controller:
Service:
get_immunization_by_id_allthis was called previously by the update controller, and confusingly masked a lot of business logic.Repository:
get_immunization_and_resource_meta_by_idand removedget_immunization_by_id_all. They were basically doing the same thing albeit a switch can now be passed in to specify whether we include logically deleted resources in our request. Abstracted the horrendous inconsistent dict we were returning withImmunizationRecordMetadataReviews Required
Review Checklist
ℹ️ This section is to be filled in by the reviewer.