Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Brandon/bb2 3792 401 errors #1310

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 25 additions & 17 deletions apps/fhir/server/authentication.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,23 +79,31 @@ def search_fhir_id_by_identifier(search_identifier, request=None):
# Build URL with patient ID search by identifier.
ver = "v{}".format(request.session.get('version', 1))
url = f"{get_resourcerouter().fhir_url}/{ver}/fhir/Patient/_search"
s = requests.Session()

payload = {"identifier": search_identifier}
req = requests.Request('POST', url, headers=headers, data=payload)
prepped = req.prepare()
pre_fetch.send_robust(FhirServerAuth, request=req, auth_request=request, api_ver=ver)
response = s.send(prepped, cert=certs, verify=False)
post_fetch.send_robust(FhirServerAuth, request=req, auth_request=request, response=response, api_ver=ver)
response.raise_for_status()
backend_data = response.json()

# Parse and validate backend_data (bundle of patients) response.
fhir_id, err_detail = _validate_patient_search_result(backend_data)

if err_detail:
raise UpstreamServerException(err_detail)
return fhir_id

max_retries = 3
retries = 0
while retries <= max_retries:
try:
s = requests.Session()
payload = {"identifier": search_identifier}
req = requests.Request('POST', url, headers=headers, data=payload)
prepped = req.prepare()
pre_fetch.send_robust(FhirServerAuth, request=req, auth_request=request, api_ver=ver)
response = s.send(prepped, cert=certs, verify=False)
post_fetch.send_robust(FhirServerAuth, request=req, auth_request=request, response=response, api_ver=ver)
response.raise_for_status()
backend_data = response.json()
# Parse and validate backend_data (bundle of patients) response.
fhir_id, err_detail = _validate_patient_search_result(backend_data)
if err_detail is not None:
raise UpstreamServerException(err_detail)
return fhir_id
except requests.exceptions.RequestException as e:
if retries < max_retries:
print(f"FHIR ID search request failed. Retrying... ({retries+1}/{max_retries})")
retries += 1
else:
raise e


def match_fhir_id(mbi, mbi_hash, hicn_hash, request=None):
Expand Down
29 changes: 19 additions & 10 deletions apps/mymedicare_cb/authorization.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,16 +280,25 @@ def service_health_check(self, request):
the BB2 /health/external check.
"""
headers = self.slsx_common_headers(request)

response = requests.get(
self.healthcheck_endpoint,
headers=headers,
allow_redirects=False,
verify=self.verify_ssl_internal,
timeout=5,
)
response.raise_for_status()
return True
max_retries = 3
retries = 0
while retries < max_retries:
try:
response = requests.get(
self.healthcheck_endpoint,
headers=headers,
allow_redirects=False,
verify=self.verify_ssl_internal,
timeout=10,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh actually was wondering about this, was there a reason to increase the timeout to 10 instead of 5? I'm cool with it either way, just wanted to make sure this wasn't by mistake.

)
response.raise_for_status()
return True
except requests.exceptions.RequestException as e:
if retries < max_retries:
print(f"SLSx service health check request failed. Retrying... ({retries+1}/{max_retries})")
retries += 1
else:
raise e

def user_signout(self, request):
"""
Expand Down
Loading