Skip to content

Commit 7bb40d3

Browse files
eli-540 refactored get person
1 parent 00e9c7e commit 7bb40d3

File tree

1 file changed

+14
-13
lines changed

1 file changed

+14
-13
lines changed

src/eligibility_signposting_api/repos/person_repo.py

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -55,28 +55,29 @@ def get_person_record(self, nhs_hash: str | None) -> Any:
5555
return None
5656

5757
def get_eligibility_data(self, nhs_number: NHSNumber) -> Person:
58-
# AWSCURRENT secret
59-
nhs_hash = self._hashing_service.hash_with_current_secret(nhs_number)
60-
items = self.get_person_record(nhs_hash)
61-
58+
# Hash using AWSCURRENT secret and fetch items
59+
items = None
60+
nhs_hashed_with_current = self._hashing_service.hash_with_current_secret(nhs_number)
61+
if nhs_hashed_with_current:
62+
items = self.get_person_record(nhs_hashed_with_current)
6263
if not items:
63-
logger.error("No person record found for hashed nhs_number using secret AWSCURRENT")
64-
65-
# AWSPREVIOUS secret
66-
nhs_hash = self._hashing_service.hash_with_previous_secret(nhs_number)
64+
logger.warning("The AWSPREVIOUS secret was tried, but no person record was found")
6765

68-
if nhs_hash is not None:
69-
items = self.get_person_record(nhs_hash)
66+
# Hash using AWSPREVIOUS secret and fetch items
67+
nhs_hashed_with_previous = self._hashing_service.hash_with_previous_secret(nhs_number)
68+
if nhs_hashed_with_previous:
69+
items = self.get_person_record(nhs_hashed_with_previous)
7070
if not items:
71-
logger.error("No person record found for hashed nhs_number using secret AWSPREVIOUS")
71+
logger.error("The AWSPREVIOUS secret was also tried, but no person record was found")
7272
message = "Person not found after checking AWSCURRENT and AWSPREVIOUS."
7373
raise NotFoundError(message)
7474
else:
75-
# fallback not hashed NHS number
75+
# fallback : Fetch using Raw NHS number
7676
items = self.get_person_record(nhs_number)
7777
if not items:
78-
logger.error("No person record found for not hashed nhs_number")
78+
logger.error("The not hashed nhs number was also tried, but no person record was found")
7979
message = "Person not found after checking AWSCURRENT, AWSPREVIOUS, and not hashed NHS numbers."
8080
raise NotFoundError(message)
8181

82+
logger.info("Person record found")
8283
return Person(data=items)

0 commit comments

Comments
 (0)