-
Notifications
You must be signed in to change notification settings - Fork 1
[GPCAPIM-396] Local SDS Int Integration #188
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
Changes from 8 commits
b744503
ceb5bfe
5d720ba
f9d30a1
5bc53ce
d919005
8896249
cd56544
b88ba00
9138dba
1bafbcb
96035bb
96c5512
d606573
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 |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| name: localInt | ||
| variables: | ||
| - name: base_url | ||
| value: http://localhost:5000 | ||
| - name: nhs_number | ||
| value: "9658218865" | ||
| - name: from_ods | ||
| value: A20047 | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,4 @@ | ||
| from gateway_api.sds.client import SdsClient | ||
| from gateway_api.sds.client import SdsClient, get | ||
| from gateway_api.sds.search_results import SdsSearchResults | ||
|
|
||
| __all__ = [ | ||
| "SdsClient", | ||
| "SdsSearchResults", | ||
| ] | ||
| __all__ = ["SdsClient", "SdsSearchResults", "get"] |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,7 +16,9 @@ | |
| from fhir import Resource | ||
| from fhir.constants import FHIRSystem | ||
| from fhir.r4 import Bundle, Device, Endpoint | ||
| from requests import HTTPError | ||
| from requests import HTTPError, Response | ||
| from requests import get as external_sds_get | ||
| from stubs import SdsFhirApiStub | ||
|
|
||
| from gateway_api.common.error import SdsRequestFailedError | ||
| from gateway_api.get_structured_record import ( | ||
|
|
@@ -25,17 +27,21 @@ | |
| ) | ||
| from gateway_api.sds.search_results import SdsSearchResults | ||
|
|
||
| # TODO [GPCAPIM-359]: Once stub servers/containers made for PDS, SDS and provider | ||
| # we should remove the SDS_URL environment variable and just | ||
| # use the stub client | ||
| STUB_SDS = os.environ["SDS_URL"].lower() == "stub" | ||
| if not STUB_SDS: | ||
| from requests import get | ||
| else: | ||
| from stubs import SdsFhirApiStub | ||
|
|
||
| sds = SdsFhirApiStub() | ||
| get = sds.get # type: ignore | ||
| def get( | ||
|
Contributor
Author
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'm interested in what other people think about this pattern, but I think it's nicer than the conditional imports. We're not planning on moving to separately deployment mocks any time soon, so I think a little wrapper function is useful. Not technically part of the scope of this ticket though, so I can revert and discuss separately if we want to.
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. Six of one ... for me. |
||
| url: str, | ||
| headers: dict[str, str], | ||
| params: dict[str, str], | ||
| timeout: int, | ||
| ) -> Response: | ||
| STUB_SDS = os.environ["SDS_URL"].lower() == "stub" | ||
| if not STUB_SDS: | ||
| return external_sds_get(url, headers=headers, params=params, timeout=timeout) | ||
| else: | ||
| return SdsFhirApiStub().get( | ||
| url, headers=headers, params=params, timeout=timeout | ||
| ) | ||
|
|
||
|
|
||
| _logger = logging.getLogger(__name__) | ||
|
|
||
|
|
@@ -83,12 +89,13 @@ class SdsClient: | |
| def __init__( | ||
| self, | ||
| base_url: str, | ||
| api_key: str, | ||
| timeout: int = 10, | ||
| service_interaction_id: str | None = None, | ||
| ) -> None: | ||
| self.base_url = base_url.rstrip("/") | ||
| self.timeout = timeout | ||
| self.api_key = self._get_api_key() | ||
| self.api_key = api_key | ||
|
Contributor
Author
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. This fits better with the env var pattern established in the previous ticket. If we try to read the config from the "app" variable in app.py we get circular imports |
||
|
|
||
| if service_interaction_id is not None: | ||
| self.service_interaction_id = service_interaction_id | ||
|
|
@@ -169,19 +176,6 @@ def get_org_details( | |
|
|
||
| return SdsSearchResults(asid=asid, endpoint=endpoint_url) | ||
|
|
||
| @staticmethod | ||
| def _get_api_key() -> str: | ||
| """ | ||
| Retrieve the API key to use for SDS requests. | ||
|
|
||
| This is a placeholder at present because we don't have a real API key. | ||
| Ultimately it will probably obtain the key from AWS secrets | ||
| """ | ||
|
|
||
| # TODO [GPCAPIM-366]: Obtain key from AWS secrets | ||
| # DO NOT PUT A REAL KEY HERE, IT WILL BE VISIBLE ON GITHUB | ||
| return "test_api_key_DO_NOT_REPLACE_HERE" | ||
|
|
||
| def _query_sds( | ||
| self, | ||
| ods_code: str, | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.