-
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
Open
ian-robinson-35
wants to merge
11
commits into
main
Choose a base branch
from
feature/GPCAPIM-396-sds-int
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
b744503
Working connection
ian-robinson-35 ceb5bfe
Tidy up
ian-robinson-35 5d720ba
Improve test
ian-robinson-35 f9d30a1
Merge branch 'main' into feature/GPCAPIM-396-sds-int
ian-robinson-35 5bc53ce
Add tests
ian-robinson-35 d919005
Merge remote-tracking branch 'origin/feature/GPCAPIM-396-sds-int' int…
ian-robinson-35 8896249
Remove debug
ian-robinson-35 cd56544
Merge remote-tracking branch 'origin/main' into feature/GPCAPIM-396-s…
ian-robinson-35 b88ba00
Added tests
ian-robinson-35 9138dba
Tidy up
ian-robinson-35 1bafbcb
Merge remote-tracking branch 'origin/main' into feature/GPCAPIM-396-s…
ian-robinson-35 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
bruno/gateway-api/collections/Steel_Thread/environments/localInt.yml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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( | ||
| 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, | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
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.