-
Notifications
You must be signed in to change notification settings - Fork 1
[GPDAPIM-258] SDS access module #79
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
base: main
Are you sure you want to change the base?
Changes from all commits
93d1124
f6236e8
eccff4e
d9996ea
eae26cb
3de8f28
f67258a
afe0f8e
3320c0d
af0024d
8bb8a10
758861b
d523e09
bb7b2fa
de073fa
08f8d6b
db8aa1c
bce9d50
ff9623a
e6cf45d
06920d2
a53e4be
85fb596
20f757e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,6 +9,12 @@ | |
| # The alias is used to make intent clearer in function signatures. | ||
| type json_str = str | ||
|
|
||
| # Access record structured interaction ID from | ||
| # https://developer.nhs.uk/apis/gpconnect/accessrecord_structured_development.html#spine-interactions | ||
| ACCESS_RECORD_STRUCTURED_INTERACTION_ID = ( | ||
| "urn:nhs:names:services:gpconnect:fhir:operation:gpc.getstructuredrecord-1" | ||
| ) | ||
|
|
||
|
Comment on lines
+12
to
+17
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. IMO this didn't need to go into a common class. It is intrinsically linked to the GetStructuredRecordRequest. Yes it is going to be use in multiple places, and thus it is a common piece of code, but by placing it as it's own constant in the |
||
|
|
||
| @dataclass | ||
| class FlaskResponse: | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,6 +18,7 @@ | |
|
|
||
| from gateway_api.common.common import FlaskResponse | ||
| from gateway_api.pds_search import PdsClient, PdsSearchResults | ||
| from gateway_api.sds_search import SdsClient, SdsSearchResults | ||
|
|
||
|
|
||
| @dataclass | ||
|
|
@@ -44,62 +45,6 @@ def __str__(self) -> str: | |
| return self.message | ||
|
|
||
|
|
||
| @dataclass | ||
| class SdsSearchResults: | ||
| """ | ||
| Stub SDS search results dataclass. | ||
|
|
||
| Replace this with the real one once it's implemented. | ||
|
|
||
| :param asid: Accredited System ID. | ||
| :param endpoint: Endpoint URL associated with the organisation, if applicable. | ||
| """ | ||
|
|
||
| asid: str | ||
| endpoint: str | None | ||
|
|
||
|
|
||
| class SdsClient: | ||
| """ | ||
| Stub SDS client for obtaining ASID from ODS code. | ||
|
|
||
| Replace this with the real one once it's implemented. | ||
| """ | ||
|
|
||
| SANDBOX_URL = "https://example.invalid/sds" | ||
|
|
||
| def __init__( | ||
| self, | ||
| auth_token: str, | ||
| base_url: str = SANDBOX_URL, | ||
| timeout: int = 10, | ||
| ) -> None: | ||
| """ | ||
| Create an SDS client. | ||
|
|
||
| :param auth_token: Authentication token to present to SDS. | ||
| :param base_url: Base URL for SDS. | ||
| :param timeout: Timeout in seconds for SDS calls. | ||
| """ | ||
| self.auth_token = auth_token | ||
| self.base_url = base_url | ||
| self.timeout = timeout | ||
|
|
||
| def get_org_details(self, ods_code: str) -> SdsSearchResults | None: | ||
| """ | ||
| Retrieve SDS org details for a given ODS code. | ||
|
|
||
| This is a placeholder implementation that always returns an ASID and endpoint. | ||
|
|
||
| :param ods_code: ODS code to look up. | ||
| :returns: SDS search results or ``None`` if not found. | ||
| """ | ||
| # Placeholder implementation | ||
| return SdsSearchResults( | ||
| asid=f"asid_{ods_code}", endpoint="https://example-provider.org/endpoint" | ||
| ) | ||
|
|
||
|
|
||
| class Controller: | ||
| """ | ||
| Orchestrates calls to PDS -> SDS -> GP provider. | ||
|
|
@@ -113,7 +58,7 @@ class Controller: | |
| def __init__( | ||
| self, | ||
| pds_base_url: str = PdsClient.SANDBOX_URL, | ||
| sds_base_url: str = "https://example.invalid/sds", | ||
| sds_base_url: str = SdsClient.SANDBOX_URL, | ||
| nhsd_session_urid: str | None = None, | ||
| timeout: int = 10, | ||
| ) -> None: | ||
|
|
@@ -252,20 +197,22 @@ def _get_sds_details( | |
| - provider details (ASID + endpoint) | ||
| - consumer details (ASID) | ||
|
|
||
| :param auth_token: Authorization token to use for SDS. | ||
| :param auth_token: Authorization token to use for SDS (used as API key). | ||
| :param consumer_ods: Consumer organisation ODS code (from request headers). | ||
| :param provider_ods: Provider organisation ODS code (from PDS). | ||
| :returns: Tuple of (consumer_asid, provider_asid, provider_endpoint). | ||
| :raises RequestError: If SDS data is missing or incomplete for provider/consumer | ||
| """ | ||
| # SDS: Get provider details (ASID + endpoint) for provider ODS | ||
| sds = SdsClient( | ||
| auth_token=auth_token, | ||
| api_key=auth_token, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The API key is not the auth token.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think leaving auth journey out the client at the moment makes the most sense. In that way, once we have set up our own mock. |
||
| base_url=self.sds_base_url, | ||
| timeout=self.timeout, | ||
| ) | ||
|
|
||
| provider_details: SdsSearchResults | None = sds.get_org_details(provider_ods) | ||
| provider_details: SdsSearchResults | None = sds.get_org_details( | ||
| provider_ods, get_endpoint=True | ||
| ) | ||
| if provider_details is None: | ||
| raise RequestError( | ||
| status_code=404, | ||
|
|
@@ -293,7 +240,9 @@ def _get_sds_details( | |
| ) | ||
|
|
||
| # SDS: Get consumer details (ASID) for consumer ODS | ||
| consumer_details: SdsSearchResults | None = sds.get_org_details(consumer_ods) | ||
| consumer_details: SdsSearchResults | None = sds.get_org_details( | ||
| consumer_ods, get_endpoint=False | ||
| ) | ||
| if consumer_details is None: | ||
| raise RequestError( | ||
| status_code=404, | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Make the variable value meaningful to the context.