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

[PRMP-1257] Add log messages to adhere to audit requirements #479

Merged
merged 30 commits into from
Jan 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
cb66f3d
[PRMP-1257] Add log messages to adhere to audit requirements
steph-torres-nhs Dec 4, 2024
59b3ac1
Merge branch 'main' into PRMP-1257
steph-torres-nhs Dec 4, 2024
07e9bf9
[PRMP-1257] change delete pointer userId to our ODS code
steph-torres-nhs Dec 4, 2024
472db69
[PRMP-1257] change order of log messages
steph-torres-nhs Dec 4, 2024
b338017
[PRMP-1257] add extra logs for get pointer
steph-torres-nhs Dec 4, 2024
67a3fe8
[PRMP-1257] reformat log messages
steph-torres-nhs Dec 4, 2024
28d1411
[PRMP-1257] update UserId log
steph-torres-nhs Dec 5, 2024
12b9670
[PRMP-1257] Address code review comments
MohammadIqbalAD-NHS Dec 9, 2024
84da8b5
Merge branch 'main' into PRMP-1257
NogaNHS Dec 10, 2024
bceef6d
[PRMP-1360] add missing fields in NRL request
NogaNHS Dec 13, 2024
40aeeaf
[PRMP-1360] fix typo
NogaNHS Dec 13, 2024
890080a
Merge branch 'PRMP-1360' into PRMP-1257
steph-torres-nhs Dec 16, 2024
d53271b
[PRMP-1257] change new line to carriage return
steph-torres-nhs Dec 18, 2024
194e49c
merge in main
steph-torres-nhs Dec 19, 2024
673cf20
[PRMP-1257] add logs back in after merge with main
steph-torres-nhs Dec 19, 2024
6745ebb
[PRMP-1257] test fix
steph-torres-nhs Dec 19, 2024
6b64133
[PRMP-1257] Remove extra '$' characters
robg-nhs Dec 19, 2024
9592186
[PRMP-1257
robg-nhs Dec 19, 2024
82f28e6
[PRMP-1373] add mandatory fields
steph-torres-nhs Dec 20, 2024
e5f4e23
Merge branch 'PRMP-1373' into PRMP-1257
steph-torres-nhs Dec 20, 2024
bfd4fce
[PRMP-1373] - Move stabillity to content section
robg-nhs Dec 20, 2024
b2f149e
[PRMP-1373] adjustments made to NRL message models
steph-torres-nhs Dec 23, 2024
66e5319
Merge branch 'PRMP-1373' into PRMP-1257
steph-torres-nhs Dec 23, 2024
b4358f5
[PRMP-1257] ammend log on get pointer to include response url
steph-torres-nhs Jan 6, 2025
f6df231
Merge branch 'main' into PRMP-1257
steph-torres-nhs Jan 6, 2025
d754159
[PRMP-1257] address PR comment
steph-torres-nhs Jan 6, 2025
90758bc
Merge branch 'main' into PRMP-1257
steph-torres-nhs Jan 8, 2025
9ab8d3a
Merge branch 'main' into PRMP-1257
steph-torres-nhs Jan 13, 2025
de70673
[PRMP-1257] fix broken tests
steph-torres-nhs Jan 13, 2025
db86779
Merge branch 'main' into PRMP-1257
steph-torres-nhs Jan 17, 2025
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
10 changes: 10 additions & 0 deletions lambdas/handlers/manage_nrl_pointer_handler.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import json
from datetime import datetime

from enums.nrl_sqs_upload import NrlActionTypes
from models.nrl_fhir_document_reference import FhirDocumentReference
Expand Down Expand Up @@ -58,7 +59,16 @@ def lambda_handler(event, context):
.json()
)

logger.info(
AndyFlintNHS marked this conversation as resolved.
Show resolved Hide resolved
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))

case NrlActionTypes.DELETE:
nrl_api_service.delete_pointer(
nrl_message.nhs_number, nrl_message.snomed_code_doc_type
Expand Down
18 changes: 16 additions & 2 deletions lambdas/models/nrl_fhir_document_reference.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,27 @@ def build_fhir_dict(self):
"content": [
{
"attachment": self.attachment.model_dump(
by_alias=True, exclude_none=True, exclude_defaults=True
by_alias=True, exclude_none=True
),
"format": {
"system": "https://fhir.nhs.uk/England/CodeSystem/England-NRLFormatCode",
"code": "urn:nhs-ic:unstructured",
"display": "Unstructured document",
},
"extension": [
{
"url": "https://fhir.nhs.uk/England/StructureDefinition/Extension-England-ContentStability",
"valueCodeableConcept": {
"coding": [
{
"system": "https://fhir.nhs.uk/England/CodeSystem/England-NRLContentStability",
"code": "static",
"display": "Static",
}
]
},
}
],
}
],
"context": {
Expand All @@ -84,7 +98,7 @@ def build_fhir_dict(self):
"display": self.snomed_code_practice_setting.display_name,
}
]
}
},
},
}
return DocumentReference(**structure_json)
16 changes: 10 additions & 6 deletions lambdas/models/nrl_sqs_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,17 @@


class NrlAttachment(BaseModel):
model_config = ConfigDict(
alias_generator=AliasGenerator(serialization_alias=to_camel),
use_enum_values=True,
)
content_type: str = "application/pdf"
language: str = "en-UK"
url: str = ""
size: int = 0
hash: str = ""
title: str = ""
creation: str = ""
Comment on lines -11 to -15
Copy link
Contributor

Choose a reason for hiding this comment

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

Change defaults to none instead

url: Optional[str] = None
size: Optional[int] = None
hash: Optional[str] = None
title: Optional[str] = None
creation: Optional[str] = None


class NrlSqsMessage(BaseModel):
Expand All @@ -27,6 +31,6 @@ class NrlSqsMessage(BaseModel):
snomed_code_practice_setting: SnomedCode = (
SnomedCodes.GENERAL_MEDICAL_PRACTICE.value
)
description: str = ""
description: Optional[str] = None
attachment: Optional[NrlAttachment] = None
action: str
1 change: 1 addition & 0 deletions lambdas/services/bulk_upload_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,7 @@ def handle_sqs_message(self, message: dict):
)
doc_details = NrlAttachment(
url=document_api_endpoint,
content_type="application/pdf",
)
nrl_sqs_message = NrlSqsMessage(
nhs_number=staging_metadata.nhs_number,
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,5 +1,6 @@
import os
import uuid
from datetime import datetime

import requests
from enums.snomed_codes import SnomedCode
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"Headers: {response.headers}"
)
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: {response.url}, "
"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"Headers: {response.headers}"
)
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"Headers: {response.headers}"
)
response.raise_for_status()
except HTTPError as e:
logger.error(e.response.json())
Expand Down
1 change: 1 addition & 0 deletions lambdas/tests/unit/services/test_nrl_api_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ def test_create_new_pointer(nrl_service):
def test_create_new_pointer_raise_error(nrl_service):
mock_body = {"test": "tests"}
response = Response()
response._content = b"{}"
response.status_code = 400
nrl_service.session.post.return_value = response
pytest.raises(NrlApiException, nrl_service.create_new_pointer, mock_body)
Expand Down
Loading