Skip to content

Commit b14f14b

Browse files
authored
[GPCAPIM-338] Remove party key (#186)
<!-- markdownlint-disable-next-line first-line-heading --> ## Description This ticket removes support for use of a party key from the SDS client and stub. It also adds a new interaction ID that is expected by the SDS sandbox environment and uses that as default if the SDS sandbox environment is selected. Note that the location of the constant for the SDS sandbox interaction ID isn't ideal. However, putting it in a sensible place in SDS causes a circular reference, and we're removing support for sandbox anyway so it'll be disappearing again shortly, so putting it alongside the existing interaction ID seemed to make the most sense. ## Context Use of party key was confusing, it wasn't clear what it was for or whether it was necessary. It turns out not to be necessary, so removing it makes the code cleaner and more maintainable. ## Type of changes <!-- What types of changes does your code introduce? Put an `x` in all the boxes that apply. --> - [X] Refactoring (non-breaking change) - [ ] New feature (non-breaking change which adds functionality) - [X] Breaking change (fix or feature that would change existing functionality) - [ ] Bug fix (non-breaking change which fixes an issue) ## Checklist <!-- Go over all the following points, and put an `x` in all the boxes that apply. --> - [X] I have followed the code style of the project - [X] I have added tests to cover my changes - [ ] I have updated the documentation accordingly - [ ] This PR is a result of pair or mob programming - [ ] Exceptions/Exclusions to coding standards (e.g. #noqa or #NOSONAR) are included within this Pull Request. --- ## Sensitive Information Declaration To ensure the utmost confidentiality and protect your and others privacy, we kindly ask you to NOT including [PII (Personal Identifiable Information) / PID (Personal Identifiable Data)](https://digital.nhs.uk/data-and-information/keeping-data-safe-and-benefitting-the-public) or any other sensitive data in this PR (Pull Request) and the codebase changes. We will remove any PR that do contain any sensitive information. We really appreciate your cooperation in this matter. - [X] I confirm that neither PII/PID nor sensitive data are included in this PR and the codebase changes.
1 parent 49cd720 commit b14f14b

12 files changed

Lines changed: 156 additions & 307 deletions

File tree

Makefile

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,18 @@ deploy: clean build # Deploy the project artefact to the target environment @Pip
7575
else \
7676
$(docker) run --platform linux/amd64 --name gateway-api -p 5000:8080 $${ENVIRONMENT_STRING} -d ${IMAGE_NAME} ; \
7777
fi
78+
@max_attempts=5 ; \
79+
attempt=1 ; \
80+
while [[ $$attempt -le $$max_attempts ]]; do \
81+
if $(docker) ps --filter "name=gateway-api" --filter "status=running" --format "{{.Names}}" | grep -q "^gateway-api$$"; then \
82+
exit 0 ; \
83+
fi ; \
84+
sleep $$((attempt * 2)) ; \
85+
attempt=$$((attempt + 1)) ; \
86+
done ; \
87+
echo "ERROR: gateway-api container failed to start. Logs:" ; \
88+
$(docker) logs gateway-api ; \
89+
exit 1
7890

7991
clean:: stop # Clean-up project resources (main) @Operations
8092
@echo "Removing Gateway API container..."

gateway-api/src/fhir/constants.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,4 @@ class FHIRSystem(StrEnum):
1111
SDS_USER_ID = "https://fhir.nhs.uk/Id/sds-user-id"
1212
SDS_ROLE_PROFILE_ID = "https://fhir.nhs.uk/Id/sds-role-profile-id"
1313
NHS_SERVICE_INTERACTION_ID = "https://fhir.nhs.uk/Id/nhsServiceInteractionId"
14-
NHS_MHS_PARTY_KEY = "https://fhir.nhs.uk/Id/nhsMhsPartyKey"
1514
NHS_SPINE_ASID = "https://fhir.nhs.uk/Id/nhsSpineASID"

gateway-api/src/fhir/r4/__init__.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
from .elements.identifier import (
55
ASIDIdentifier,
66
OrganizationIdentifier,
7-
PartyKeyIdentifier,
87
PatientIdentifier,
98
UUIDIdentifier,
109
)
@@ -25,7 +24,6 @@
2524
"GeneralPractitioner",
2625
"OrganizationIdentifier",
2726
"Organization",
28-
"PartyKeyIdentifier",
2927
"Patient",
3028
"PatientIdentifier",
3129
"Practitioner",

gateway-api/src/fhir/r4/elements/identifier.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,6 @@ class ASIDIdentifier(Identifier, expected_system="https://fhir.nhs.uk/Id/nhsSpin
3333
"""A FHIR R4 ASID Identifier."""
3434

3535

36-
class PartyKeyIdentifier(
37-
Identifier, expected_system="https://fhir.nhs.uk/Id/nhsMhsPartyKey"
38-
):
39-
"""A FHIR R4 Party Key Identifier."""
40-
41-
4236
class AgnosticDeviceIdentifier(Identifier, expected_system="__unknown__"):
4337
"""TODO [GPCAPIM-358]: define system once JWT Device details are understood."""
4438

gateway-api/src/fhir/r4/resources/device.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
from ..elements.identifier import (
88
AgnosticDeviceIdentifier,
99
ASIDIdentifier,
10-
PartyKeyIdentifier,
1110
)
1211

1312

@@ -17,6 +16,6 @@ class Device(Resource, resource_type="Device"):
1716
model_config = ConfigDict(extra="allow")
1817

1918
identifier: Annotated[
20-
list[ASIDIdentifier | PartyKeyIdentifier | AgnosticDeviceIdentifier],
19+
list[ASIDIdentifier | AgnosticDeviceIdentifier],
2120
Field(frozen=True, min_length=1),
2221
]

gateway-api/src/fhir/r4/resources/test_resources.py

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
Entry,
1313
GeneralPractitioner,
1414
OrganizationIdentifier,
15-
PartyKeyIdentifier,
1615
Patient,
1716
PatientIdentifier,
1817
Practitioner,
@@ -375,46 +374,11 @@ def test_create_with_asid_identifier(self) -> None:
375374
"identifier value should match"
376375
)
377376

378-
def test_create_with_party_key_identifier(self) -> None:
379-
device = Device.create(
380-
identifier=[
381-
PartyKeyIdentifier(
382-
system="https://fhir.nhs.uk/Id/nhsMhsPartyKey",
383-
value="P12345-000001",
384-
)
385-
],
386-
)
387-
388-
assert device.identifier[0].system == "https://fhir.nhs.uk/Id/nhsMhsPartyKey", (
389-
"system should match the party key URI"
390-
)
391-
392-
def test_create_with_mixed_identifiers(self) -> None:
393-
device = Device.create(
394-
identifier=[
395-
ASIDIdentifier(
396-
system="https://fhir.nhs.uk/Id/nhsSpineASID",
397-
value="123",
398-
),
399-
PartyKeyIdentifier(
400-
system="https://fhir.nhs.uk/Id/nhsMhsPartyKey",
401-
value="PK-1",
402-
),
403-
],
404-
)
405-
406-
assert len(device.identifier) == 2, "should have two identifiers"
407-
408377
def test_asid_identifier_expected_system(self) -> None:
409378
assert ASIDIdentifier._expected_system == (
410379
"https://fhir.nhs.uk/Id/nhsSpineASID"
411380
), "_expected_system should be the ASID URI"
412381

413-
def test_party_key_identifier_expected_system(self) -> None:
414-
assert PartyKeyIdentifier._expected_system == (
415-
"https://fhir.nhs.uk/Id/nhsMhsPartyKey"
416-
), "_expected_system should be the party key URI"
417-
418382

419383
class TestDeviceModelValidate:
420384
def test_valid_device(self) -> None:

gateway-api/src/gateway_api/get_structured_record/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
from gateway_api.get_structured_record.request import (
44
ACCESS_RECORD_STRUCTURED_INTERACTION_ID,
5+
SDS_SANDBOX_INTERACTION_ID,
56
GetStructuredRecordRequest,
67
)
78
from gateway_api.get_structured_record.response import GetStructuredRecordResponse
@@ -10,4 +11,5 @@
1011
"GetStructuredRecordRequest",
1112
"GetStructuredRecordResponse",
1213
"ACCESS_RECORD_STRUCTURED_INTERACTION_ID",
14+
"SDS_SANDBOX_INTERACTION_ID",
1315
]

gateway-api/src/gateway_api/get_structured_record/request.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@
1818
"urn:nhs:names:services:gpconnect:fhir:operation:gpc.getstructuredrecord-1"
1919
)
2020

21+
# The SDS Sandbox environment only returns results for this interaction ID.
22+
# Non-sandbox environments should use ACCESS_RECORD_STRUCTURED_INTERACTION_ID.
23+
# TODO: Remove this once we no longer support sandbox (probably in GPCAPIM-396).
24+
SDS_SANDBOX_INTERACTION_ID = "urn:nhs:names:services:psis:REPC_IN150016UK05"
25+
2126

2227
class GetStructuredRecordRequest:
2328
INTERACTION_ID: ClassVar[str] = ACCESS_RECORD_STRUCTURED_INTERACTION_ID

gateway-api/src/gateway_api/sds/client.py

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,10 @@
1818
from requests import HTTPError
1919

2020
from gateway_api.common.error import SdsRequestFailedError
21-
from gateway_api.get_structured_record import ACCESS_RECORD_STRUCTURED_INTERACTION_ID
21+
from gateway_api.get_structured_record import (
22+
ACCESS_RECORD_STRUCTURED_INTERACTION_ID,
23+
SDS_SANDBOX_INTERACTION_ID,
24+
)
2225
from gateway_api.sds.search_results import SdsSearchResults
2326

2427
# TODO [GPCAPIM-359]: Once stub servers/containers made for PDS, SDS and provider
@@ -86,11 +89,15 @@ def __init__(
8689
) -> None:
8790
self.base_url = base_url.rstrip("/")
8891
self.timeout = timeout
89-
self.service_interaction_id = (
90-
service_interaction_id or self.DEFAULT_SERVICE_INTERACTION_ID
91-
)
9292
self.api_key = self._get_api_key()
9393

94+
if service_interaction_id is not None:
95+
self.service_interaction_id = service_interaction_id
96+
elif self.base_url == self.SANDBOX_URL:
97+
self.service_interaction_id = SDS_SANDBOX_INTERACTION_ID
98+
else:
99+
self.service_interaction_id = self.DEFAULT_SERVICE_INTERACTION_ID
100+
94101
def _build_headers(self, correlation_id: str | None = None) -> dict[str, str]:
95102
"""
96103
Build mandatory and optional headers for an SDS request.
@@ -134,9 +141,6 @@ def get_org_details(
134141
return empty_search_results
135142

136143
asid = self._extract_device_identifier(device, FHIRSystem.NHS_SPINE_ASID)
137-
party_key = self._extract_device_identifier(
138-
device, FHIRSystem.NHS_MHS_PARTY_KEY
139-
)
140144

141145
# Step 2: Get Endpoint to obtain endpoint URL
142146
endpoint_url: str | None = None
@@ -146,7 +150,6 @@ def get_org_details(
146150

147151
endpoint_bundle = self._query_sds(
148152
ods_code=ods_code,
149-
party_key=party_key,
150153
correlation_id=correlation_id,
151154
timeout=timeout,
152155
querytype=SdsResourceType.ENDPOINT,
@@ -173,7 +176,6 @@ def _get_api_key() -> str:
173176
def _query_sds(
174177
self,
175178
ods_code: str,
176-
party_key: str | None = None,
177179
correlation_id: str | None = None,
178180
timeout: int | None = 10,
179181
querytype: SdsResourceType = SdsResourceType.DEVICE,
@@ -191,9 +193,6 @@ def _query_sds(
191193
],
192194
}
193195

194-
if party_key is not None:
195-
params["identifier"].append(f"{FHIRSystem.NHS_MHS_PARTY_KEY}|{party_key}")
196-
197196
response = get(
198197
url,
199198
headers=headers,

0 commit comments

Comments
 (0)