diff --git a/lambdas/handlers/manage_nrl_pointer_handler.py b/lambdas/handlers/manage_nrl_pointer_handler.py index 84e035320..4b8525113 100644 --- a/lambdas/handlers/manage_nrl_pointer_handler.py +++ b/lambdas/handlers/manage_nrl_pointer_handler.py @@ -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)) diff --git a/lambdas/services/nrl_api_service.py b/lambdas/services/nrl_api_service.py index 52f3ed5bb..03ad1fb7e 100644 --- a/lambdas/services/nrl_api_service.py +++ b/lambdas/services/nrl_api_service.py @@ -1,3 +1,4 @@ +import datetime import os import uuid @@ -10,6 +11,7 @@ from utils.exceptions import NrlApiException logger = LoggingService(__name__) +NRL_USER_ID = "National-Document-Repository" class NrlApiService: @@ -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: @@ -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: @@ -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())