-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathpds_details.py
More file actions
39 lines (32 loc) · 1.41 KB
/
pds_details.py
File metadata and controls
39 lines (32 loc) · 1.41 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
34
35
36
37
38
39
"""
Operations related to PDS (Patient Demographic Service)
"""
import tempfile
from common.api_clients.authentication import AppRestrictedAuth
from common.api_clients.pds_service import PdsService
from common.cache import Cache
from common.clients import get_secrets_manager_client, logger
from exceptions.id_sync_exception import IdSyncException
from os_vars import get_pds_env
pds_env = get_pds_env()
safe_tmp_dir = tempfile.mkdtemp(dir="/tmp")
# 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 IdSyncException(message=msg) from e
def get_nhs_number_from_pds_resource(pds_resource: dict) -> str:
"""Simple helper to get the NHS Number from a PDS Resource. No handling as this is a mandatory field in the PDS
response. Must only use where we have ensured an object has been returned."""
return pds_resource["identifier"][0]["value"]