-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathget_pds_details.py
More file actions
33 lines (28 loc) · 1.11 KB
/
get_pds_details.py
File metadata and controls
33 lines (28 loc) · 1.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
"""
Operations related to PDS (Patient Demographic Service)
"""
import os
import tempfile
from common.api_clients.authentication import AppRestrictedAuth
from common.api_clients.errors import PdsSyncException
from common.api_clients.pds_service import PdsService
from common.cache import Cache
from common.clients import get_secrets_manager_client, logger
PDS_ENV = os.getenv("PDS_ENV", "int")
safe_tmp_dir = tempfile.mkdtemp(dir="/tmp") # NOSONAR(S5443)
# Get Patient details from external service PDS using NHS number from MNS notification
def pds_get_patient_details(nhs_number: str) -> dict:
try:
cache = Cache(directory=safe_tmp_dir)
authenticator = AppRestrictedAuth(
secret_manager_client=get_secrets_manager_client(),
environment=PDS_ENV,
cache=cache,
)
pds_service = PdsService(authenticator, PDS_ENV)
patient = pds_service.get_patient_details(nhs_number)
return patient
except Exception as e:
msg = "Error retrieving patient details from PDS"
logger.exception(msg)
raise PdsSyncException(message=msg) from e