Skip to content

Commit

Permalink
Correctly handle when we can't find a GP by ODS code or postcode
Browse files Browse the repository at this point in the history
I had ported across the unit tests from my other branch but hadn't changed the behaviour of the helper functions:

- Manually check for a 404 when looking up by ODS code
- Raise exceptions for anything else
  • Loading branch information
mbarton committed Sep 19, 2024
1 parent f98d445 commit f441274
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 18 deletions.
1 change: 0 additions & 1 deletion project/npda/general_functions/csv_upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,6 @@ def validate_patient_using_form(row):
"death_date": "Death Date",
},
)
# TODO MRB: check we Validate gp practice ods code
form = PatientForm(fields)
assign_original_row_indices_to_errors(form, row)
return form
Expand Down
31 changes: 14 additions & 17 deletions project/npda/general_functions/nhs_ods_requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,11 @@ def gp_ods_code_for_postcode(postcode: str):
f"{url}/organisations/?PostCode={postcode}&Status=Active&PrimaryRoleId=RO177"
)

try:
response = requests.get(
url=request_url,
timeout=10, # times out after 10 seconds
)
response.raise_for_status()
except HTTPError:
raise Exception(f"{postcode} not found")
response = requests.get(
url=request_url,
timeout=10, # times out after 10 seconds
)
response.raise_for_status()

organisations = response.json()["Organisations"]

Expand All @@ -46,14 +43,14 @@ def gp_details_for_ods_code(ods_code: str):

url = f"{settings.NHS_SPINE_SERVICES_URL}/organisations/{ods_code}"

try:
response = requests.get(
url=url,
timeout=10, # times out after 10 seconds
)
response.raise_for_status()
except HTTPError as e:
return {"error": e}
response = requests.get(
url=url,
timeout=10, # times out after 10 seconds
)

if response.status_code == 404:
return None

response.raise_for_status()

logger.warning(response.json())
return response.json()["Organisation"]

0 comments on commit f441274

Please sign in to comment.