Skip to content

Commit

Permalink
[PRMP-1257] add logs back in after merge with main
Browse files Browse the repository at this point in the history
  • Loading branch information
steph-torres-nhs committed Dec 19, 2024
1 parent 194e49c commit 673cf20
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 6 deletions.
10 changes: 5 additions & 5 deletions lambdas/handlers/manage_nrl_pointer_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,11 @@ def lambda_handler(event, context):
)

logger.info(
f"Create pointer request: Body: {json.loads(document)}, \n"
f"RequestURL: {nrl_api_service.endpoint}, \n"
"HTTP Verb: POST, \n"
f"NHS Number: {nrl_message.nhs_number}, \n"
f"ODS Code: {nrl_api_service.end_user_ods_code}, \n"
f"Create pointer request: Body: {json.loads(document)}, "
f"RequestURL: {nrl_api_service.endpoint}, "
"HTTP Verb: POST, "
f"NHS Number: {nrl_message.nhs_number}, "
f"ODS Code: {nrl_api_service.end_user_ods_code}, "
f"Datetime: {int(datetime.now().timestamp())} "
)
nrl_api_service.create_new_pointer(json.loads(document))
Expand Down
33 changes: 32 additions & 1 deletion lambdas/services/nrl_api_service.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import datetime
import os
import uuid

Expand All @@ -10,6 +11,7 @@
from utils.exceptions import NrlApiException

logger = LoggingService(__name__)
NRL_USER_ID = "National-Document-Repository"


class NrlApiService:
Expand Down Expand Up @@ -45,6 +47,11 @@ def create_new_pointer(self, body, retry_on_expired: bool = True):
response = self.session.post(
url=self.endpoint, headers=self.headers, json=body
)
logger.info(
f"Create pointer response: Status code: ${response.status_code}, "
f"Body: {response.json()}, "
f"Date: ${response.headers.get('date', 'No date found.')}"
)
response.raise_for_status()
logger.info("Successfully created new pointer")
except (ConnectionError, Timeout, HTTPError) as e:
Expand All @@ -70,6 +77,18 @@ def get_pointer(
response = self.session.get(
url=self.endpoint, params=params, headers=self.headers
)
logger.info(
f"Get pointer request: URL: {self.endpoint}/{params}, "
"HTTP Verb: GET, "
f"ODS Code: {self.end_user_ods_code}, "
f"Datetime: {int(datetime.now().timestamp())}, "
f"UserID: {self.end_user_ods_code} - {NRL_USER_ID}"
)
logger.info(
f"Get pointer response: Status code: {response.status_code}, "
f"Body: {response.json()}, "
f"Date: {response.headers.get('date', 'No date found.')}"
)
response.raise_for_status()
return response.json()
except HTTPError as e:
Expand All @@ -90,7 +109,19 @@ def delete_pointer(self, nhs_number, record_type: SnomedCode = None):
url_endpoint = self.endpoint + f"/{pointer_id}"
try:
response = self.session.delete(url=url_endpoint, headers=self.headers)
logger.info(response.json())
logger.info(
f"Delete pointer request: URL: {url_endpoint}, "
f"HTTP Verb: DELETE, "
f"ODS Code: {self.end_user_ods_code}, "
f"NHS Number: {nhs_number}, "
f"Datetime: {int(datetime.now().timestamp())}, "
f"UserID: {self.end_user_ods_code} - {NRL_USER_ID}."
)
logger.info(
f"Delete pointer response: Body: {response.json()}, "
f"Status Code: {response.status_code}, "
f"Date: {response.headers.get('date', 'No date found.')}"
)
response.raise_for_status()
except HTTPError as e:
logger.error(e.response.json())
Expand Down

0 comments on commit 673cf20

Please sign in to comment.