Skip to content

Commit d1c659c

Browse files
authored
Merge pull request #184 from NHSDigital/dev/NPA-4689_GET_QuestionnaireResponse_endpoint
NPA-4689 Add `GET /QuestionnaireResponse` Endpoint To Sandbox
2 parents f354222 + 6a77cc4 commit d1c659c

File tree

10 files changed

+184
-187
lines changed

10 files changed

+184
-187
lines changed

.github/workflows/openapi-validate.yml

Lines changed: 39 additions & 161 deletions
Original file line numberDiff line numberDiff line change
@@ -5,165 +5,46 @@ name: Open API Validate
55
permissions:
66
contents: read
77
jobs:
8-
GET_Consent:
9-
name: GET Consent test
8+
ExamplesSchemasChecks:
9+
name: Examples Schemas Checks
1010
runs-on: ubuntu-latest
11+
strategy:
12+
fail-fast: false
13+
matrix:
14+
endpoint:
15+
[
16+
{
17+
name: "GET /Consent",
18+
make_target: "schema-get-consent",
19+
},
20+
{
21+
name: "POST /Consent",
22+
make_target: "schema-post-consent",
23+
},
24+
{
25+
name: "PATCH /Consent",
26+
make_target: "schema-patch-consent",
27+
},
28+
{
29+
name: "GET /RelatedPerson",
30+
make_target: "schema-related-person",
31+
},
32+
{
33+
name: "POST /Questionnaire",
34+
make_target: "schema-questionnaire",
35+
},
36+
{
37+
name: "GET /Questionnaire",
38+
make_target: "schema-get-questionnaire",
39+
},
40+
{ name: "Errors", make_target: "schema-errors" },
41+
]
1142
steps:
1243
- name: Checkout repository
1344
uses: actions/checkout@v4
14-
15-
- name: Set up Python
16-
uses: actions/setup-python@v5
17-
with:
18-
python-version: 3.9
19-
20-
- name: Install Poetry
21-
shell: bash
22-
run: |
23-
pipx install poetry==1.8.5
24-
25-
- name: Install Script Packages with Poetry
26-
shell: bash
27-
run: |
28-
poetry install --all-extras
29-
30-
- name: Run Python script for all files
31-
run: |
32-
make schema-get-consent
33-
34-
POST_Consent:
35-
name: POST Consent test
36-
runs-on: ubuntu-latest
37-
steps:
38-
- name: Checkout repository
39-
uses: actions/checkout@v4
40-
41-
- name: Set up Python
42-
uses: actions/setup-python@v5
43-
with:
44-
python-version: 3.9
45-
46-
- name: Install Poetry
47-
shell: bash
48-
run: |
49-
pipx install poetry==1.8.5
50-
51-
- name: Install Script Packages with Poetry
52-
shell: bash
53-
run: |
54-
poetry install --all-extras
55-
56-
- name: Run Python script for all files
57-
run: |
58-
make schema-post-consent
59-
60-
PATCH_Consent:
61-
name: PATCH Consent test
62-
runs-on: ubuntu-latest
63-
steps:
64-
- name: Checkout repository
65-
uses: actions/checkout@v4
66-
67-
- name: Set up Python
68-
uses: actions/setup-python@v5
69-
with:
70-
python-version: 3.9
71-
72-
- name: Install Poetry
73-
shell: bash
74-
run: |
75-
pipx install poetry==1.8.5
76-
77-
- name: Install Script Packages with Poetry
78-
shell: bash
79-
run: |
80-
poetry install --all-extras
81-
82-
- name: Run Python script for all files
83-
run: |
84-
make schema-patch-consent
85-
86-
GET_RelatedPerson:
87-
name: GET Related Person test
88-
runs-on: ubuntu-latest
89-
steps:
90-
- name: Checkout repository
91-
uses: actions/checkout@v4
92-
93-
- name: Set up Python
94-
uses: actions/setup-python@v5
9545
with:
96-
python-version: 3.9
97-
98-
- name: Install Poetry
99-
shell: bash
100-
run: |
101-
pipx install poetry==1.8.5
102-
103-
- name: Install Script Packages with Poetry
104-
shell: bash
105-
run: |
106-
poetry install --all-extras
107-
108-
- name: Run Python script for all files
109-
run: |
110-
make schema-related-person
111-
112-
POST_Questionnaire:
113-
name: POST questionnaire test
114-
runs-on: ubuntu-latest
115-
steps:
116-
- name: Checkout repository
117-
uses: actions/checkout@v4
118-
119-
- name: Set up Python
120-
uses: actions/setup-python@v5
121-
with:
122-
python-version: 3.9
123-
124-
- name: Install Poetry
125-
shell: bash
126-
run: |
127-
pipx install poetry==1.8.5
128-
129-
- name: Install Script Packages with Poetry
130-
shell: bash
131-
run: |
132-
poetry install --all-extras
133-
134-
- name: Run Python script for all files
135-
run: |
136-
make schema-questionnaire
137-
138-
GET_Questionnaire:
139-
name: GET questionnaire test
140-
runs-on: ubuntu-latest
141-
steps:
142-
- name: Checkout repository
143-
uses: actions/checkout@v4
144-
145-
- name: Set up Python
146-
uses: actions/setup-python@v5
147-
with:
148-
python-version: 3.9
149-
150-
- name: Install Poetry
151-
shell: bash
152-
run: |
153-
pipx install poetry==1.8.5
154-
- name: Install Script Packages with Poetry
155-
shell: bash
156-
run: |
157-
poetry install --all-extras
158-
- name: Run Python script for all files
159-
run: |
160-
make schema-get-questionnaire
161-
Errors:
162-
name: Error schema test
163-
runs-on: ubuntu-latest
164-
steps:
165-
- name: Checkout repository
166-
uses: actions/checkout@v4
46+
fetch-depth: 0
47+
persist-credentials: false
16748

16849
- name: Set up Python
16950
uses: actions/setup-python@v5
@@ -172,14 +53,11 @@ jobs:
17253

17354
- name: Install Poetry
17455
shell: bash
175-
run: |
176-
pipx install poetry==1.8.5
56+
run: pipx install poetry==1.8.5
17757

17858
- name: Install Script Packages with Poetry
17959
shell: bash
180-
run: |
181-
poetry install --all-extras
60+
run: poetry install --all-extras
18261

183-
- name: Run Python script for all files
184-
run: |
185-
make schema-errors
62+
- name: Check Examples against Endpoint Schemas
63+
run: make ${{ matrix.endpoint.make_target }}

.github/workflows/run-postman-collection.yml

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@ jobs:
55
run-postman-collection:
66
runs-on: ubuntu-latest
77
steps:
8-
- name: Check out the repository
9-
uses: actions/checkout@v4
10-
- name: Set up Node.js
11-
uses: actions/setup-node@v4
12-
with:
13-
node-version: '22'
14-
- name: Install Newman
15-
run: npm install -g newman
16-
- name: Run Postman Collection
17-
run: newman run ./postman/Validate\ Relationship\ Service\ Sandbox.postman_collection.json
8+
- name: Check out the repository
9+
uses: actions/checkout@v4
10+
- name: Set up Node.js
11+
uses: actions/setup-node@v4
12+
with:
13+
node-version: "22"
14+
- name: Install Newman
15+
run: npm install -g newman
16+
- name: Run Postman Collection
17+
run: newman run ./postman/Validate\ Relationship\ Service\ Sandbox.postman_collection.json

.github/workflows/sandbox-checks.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ jobs:
1010
run: pipx install poetry
1111
- uses: actions/setup-python@v5
1212
with:
13-
python-version: '3.8'
14-
cache: 'poetry'
13+
python-version: "3.8"
14+
cache: "poetry"
1515
- name: Install Sandbox dependencies
1616
run: make install
1717
working-directory: ./sandbox

sandbox/api/app.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from flask import Flask
55

66
from .get_consent import get_consent_response
7+
from .get_questionnaire_response import get_questionnaire_response_response
78
from .get_related_person import get_related_person_response
89
from .patch_consent import patch_consent_response
910
from .post_consent import post_consent_response
@@ -37,6 +38,16 @@ def get_related_persons() -> Union[dict, tuple]:
3738
return get_related_person_response()
3839

3940

41+
@app.route(f"/{COMMON_PATH}/QuestionnaireResponse", methods=["GET"])
42+
def get_questionnaire_response() -> Union[dict, tuple]:
43+
"""Sandbox API for GET /QuestionnaireResponse
44+
45+
Returns:
46+
Union[dict, tuple]: Response for GET /QuestionnaireResponse
47+
"""
48+
return get_questionnaire_response_response()
49+
50+
4051
@app.route(f"/{COMMON_PATH}/QuestionnaireResponse", methods=["POST"])
4152
def post_questionnaire_response() -> Union[dict, tuple]:
4253
"""Sandbox API for POST /QuestionnaireResponse

sandbox/api/constants.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,20 @@
6262
PATCH_CONSENT__RESOURCE_NOT_FOUND = f"{PATCH_CONSENT__DIRECTORY}errors/resource_not_found.yaml"
6363
PATCH_CONSENT__INVALID_STATE_TRANSITION = f"{PATCH_CONSENT__DIRECTORY}errors/invalid_state_transition.yaml"
6464

65-
QR_DIRECTORY = "./api/examples/POST_QuestionnaireResponse/"
66-
QUESTIONNAIRE_RESPONSE__SUCCESS = f"{QR_DIRECTORY}success.yaml"
65+
# POST QuestionnaireResponse
66+
POST_QUESTIONNAIRE_RESPONSE_DIRECTORY = "./api/examples/POST_QuestionnaireResponse/"
67+
POST_QUESTIONNAIRE_RESPONSE__SUCCESS = f"{POST_QUESTIONNAIRE_RESPONSE_DIRECTORY}success.yaml"
6768

69+
# GET QuestionnaireResponse
70+
GET_QUESTIONNAIRE_RESPONSE_DIRECTORY = "./api/examples/GET_QuestionnaireResponse/"
71+
GET_QUESTIONNAIRE_RESPONSE__SUCCESS = f"{GET_QUESTIONNAIRE_RESPONSE_DIRECTORY}success.yaml"
72+
GET_QUESTIONNAIRE_RESPONSE__INVALID = f"{GET_QUESTIONNAIRE_RESPONSE_DIRECTORY}errors/invalid-reference-code.yaml"
73+
GET_QUESTIONNAIRE_RESPONSE__MISSING = f"{GET_QUESTIONNAIRE_RESPONSE_DIRECTORY}errors/missing-reference-code.yaml"
74+
GET_QUESTIONNAIRE_RESPONSE__NOT_FOUND = (
75+
f"{GET_QUESTIONNAIRE_RESPONSE_DIRECTORY}errors/questionnaire_response_not_found.yaml"
76+
)
77+
78+
# GET RelatedPerson
6879
RELATED_DIRECTORY = "./api/examples/GET_RelatedPerson/"
6980
RELATED__ERROR_IDENTIFIER_MISSING = f"{RELATED_DIRECTORY}errors/invalid-identifier-missing.yaml"
7081
RELATED__ERROR_IDENTIFIER_SYSTEM = f"{RELATED_DIRECTORY}errors/invalid-identifier-system.yaml"

sandbox/api/get_consent.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@
2020
INVALIDATED_RESOURCE,
2121
)
2222
from .utils import (
23-
check_for_get_consent_errors,
2423
check_for_consent_filtering,
2524
check_for_consent_include_params,
25+
check_for_get_consent_errors,
2626
generate_response_from_example,
2727
remove_system,
2828
)
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
from logging import INFO, basicConfig, getLogger
2+
from typing import Union
3+
4+
from flask import request
5+
6+
from .constants import (
7+
GET_QUESTIONNAIRE_RESPONSE__INVALID,
8+
GET_QUESTIONNAIRE_RESPONSE__MISSING,
9+
GET_QUESTIONNAIRE_RESPONSE__NOT_FOUND,
10+
GET_QUESTIONNAIRE_RESPONSE__SUCCESS,
11+
INTERNAL_SERVER_ERROR_EXAMPLE,
12+
)
13+
from .utils import generate_response_from_example
14+
15+
basicConfig(level=INFO, format="%(asctime)s - %(message)s")
16+
logger = getLogger(__name__)
17+
18+
19+
def get_questionnaire_response_response() -> Union[dict, tuple]:
20+
"""Sandbox API for GET /QuestionnaireResponse
21+
22+
Returns:
23+
Union[dict, tuple]: Response for GET /QuestionnaireResponse
24+
"""
25+
try:
26+
reference_code = request.args.get("referenceCode")
27+
if reference_code == "19318ZGLAB":
28+
return generate_response_from_example(GET_QUESTIONNAIRE_RESPONSE__SUCCESS, 200)
29+
elif reference_code == "INVALID":
30+
return generate_response_from_example(GET_QUESTIONNAIRE_RESPONSE__INVALID, 400)
31+
elif reference_code == "" or reference_code is None:
32+
return generate_response_from_example(GET_QUESTIONNAIRE_RESPONSE__MISSING, 404)
33+
elif reference_code == "ABC123XY":
34+
return generate_response_from_example(GET_QUESTIONNAIRE_RESPONSE__NOT_FOUND, 404)
35+
else:
36+
raise ValueError("Invalid reference code")
37+
except Exception:
38+
logger.exception("GET questionnaire response failed")
39+
return generate_response_from_example(INTERNAL_SERVER_ERROR_EXAMPLE, 500)

sandbox/api/post_questionnaire_response.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from logging import INFO, basicConfig, getLogger
22
from typing import Union
33

4-
from .constants import INTERNAL_SERVER_ERROR_EXAMPLE, QUESTIONNAIRE_RESPONSE__SUCCESS
4+
from .constants import INTERNAL_SERVER_ERROR_EXAMPLE, POST_QUESTIONNAIRE_RESPONSE__SUCCESS
55
from .utils import generate_response_from_example
66

77
basicConfig(level=INFO, format="%(asctime)s - %(message)s")
@@ -15,7 +15,7 @@ def post_questionnaire_response_response() -> Union[dict, tuple]:
1515
Union[dict, tuple]: Response for POST /QuestionnaireResponse
1616
"""
1717
try:
18-
return generate_response_from_example(QUESTIONNAIRE_RESPONSE__SUCCESS, 200)
18+
return generate_response_from_example(POST_QUESTIONNAIRE_RESPONSE__SUCCESS, 200)
1919
except Exception:
2020
logger.exception("POST questionnaire response failed")
2121
return generate_response_from_example(INTERNAL_SERVER_ERROR_EXAMPLE, 500)

0 commit comments

Comments
 (0)