Skip to content

Commit 051fd26

Browse files
anglocmcheung-nhs
authored andcommitted
cmsnav-747 Update OAS spec., sandbox examples
1 parent 4b19ff9 commit 051fd26

38 files changed

Lines changed: 17575 additions & 10995 deletions

pyproject.toml

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,26 @@
1-
[project]
2-
python = "^3.8"
3-
41
[tool.poetry]
52
name = "nhs-website-content-api"
6-
version = "0.0.1-alpha"
3+
version = "2.2.0"
74
description = "TODO"
8-
authors = [
9-
#TODO add authors
10-
]
11-
readme = 'README.md'
5+
authors = ["TODO <todo@example.com>"]
6+
readme = "README.md"
127
license = "MIT"
138
repository = "https://github.com/NHSDigital/nhs-website-content-api"
149
homepage = "https://digital.nhs.uk/developer/api-catalogue/nhs-website-content/v2"
15-
keywords = ["healthcare", "uk", "nhs"] #TODO add additional keywords
16-
10+
keywords = ["healthcare", "uk", "nhs"]
11+
package-mode = false
1712

1813
[tool.poetry.dependencies]
19-
python = "^3.8"
14+
python = ">=3.9,<4.0"
2015
pytest-nhsd-apim = "^2.0.2"
16+
requests = "2.27.1"
2117

22-
[tool.poetry.dev-dependencies]
18+
[tool.poetry.group.dev.dependencies]
2319
flake8 = "^3.7.9"
2420
black = "^20.8b1"
2521
pip-licenses = "^2.0.1"
2622
jinja2 = "^2.11.1"
27-
pyyaml = "^5.2"
23+
pyyaml = "^6.0"
2824
docopt = "^0.6.2"
2925
jsonpath-rw = "^1.4.0"
3026
semver = "^2.9.0"
@@ -33,5 +29,6 @@ pytest = "^6.1.2"
3329
coverage = "^5.5"
3430
aiohttp = "^3.8.6"
3531
pytest-asyncio = "^0.14.0"
32+
pre-commit = "^4.2.0"
3633

3734
[tool.poetry.scripts]

sandbox/Sandbox endpoints - localhost.md

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@
2121

2222
[Conditions Root - Category: A & Genre: Condition](http://localhost:9000/conditions/?category=a&genre=condition)
2323

24-
[Conditions Root - Category: A & Genre: Guide](http://localhost:9000/conditions/?category=a&genre=guide)
25-
2624
[Conditions Root - Category: A & Genre: Hub](http://localhost:9000/conditions/?category=a&genre=hub)
2725

2826
[Conditions Root - Category: B](http://localhost:9000/conditions/?category=b)
@@ -33,7 +31,7 @@
3331

3432
[Conditions Root - Page: 2](http://localhost:9000/conditions/?page=2)
3533

36-
[Conditions Root - Page: 70](http://localhost:9000/conditions/?page=70)
34+
[Conditions Root - Page: 29](http://localhost:9000/conditions/?page=29)
3735

3836
[Conditions Wildcard - Modules: false](http://localhost:9000/conditions/*?modules=false)
3937

@@ -146,3 +144,27 @@
146144
[Periods](http://localhost:9000/womens-health/periods/)
147145

148146
[Anaemia](http://localhost:9000/womens-health/anaemia/)
147+
148+
## Symptoms
149+
150+
[Symptoms Root](http://localhost:9000/symptoms/)
151+
152+
[Symptoms Root - Category: A](http://localhost:9000/symptoms/?category=a)
153+
154+
[Symptoms Root - Category: B](http://localhost:9000/symptoms/?category=b)
155+
156+
[Symptoms Root - Page: 1](http://localhost:9000/symptoms/?page=1)
157+
158+
[Symptoms Root - Page: 6](http://localhost:9000/symptoms/?page=6)
159+
160+
## Tests and treatments
161+
162+
[Tests and treatments Root](http://localhost:9000/tests-and-treatments/)
163+
164+
[Tests and treatments - Category: A](http://localhost:9000/tests-and-treatments/?category=a)
165+
166+
[Tests and treatments - Category: B](http://localhost:9000/tests-and-treatments/?category=b)
167+
168+
[Tests and treatments - Page: 1](http://localhost:9000/tests-and-treatments/?page=1)
169+
170+
[Tests and treatments - Page: 7](http://localhost:9000/tests-and-treatments/?page=7)

sandbox/app.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,16 @@ app.all('/womens-health/', handlers.womensHealthRoot)
215215
app.all('/womens-health/periods/', handlers.womensHealthPeriods)
216216
app.all('/womens-health/anaemia/', handlers.womensHealthAnaemia)
217217

218+
// ******************************************************************
219+
// ** Symptoms
220+
// ******************************************************************
221+
app.all('/symptoms/', handlers.symptomsRoot)
222+
223+
// ******************************************************************
224+
// ** Tests and treatments
225+
// ******************************************************************
226+
app.all('/tests-and-treatments/', handlers.testsAndTreatmentsRoot)
227+
218228
app.use((req, res, next) => {
219229
res.status(404).json(errorResourceNotFoundResponse)
220230
})

sandbox/handlers.js

Lines changed: 120 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,13 @@ const conditionsAcneModulesTrueResponse = require('./responses/conditions-acne-m
1919
const conditionsAngiographyResponse = require('./responses/conditions-angiography-no-params.json')
2020
const conditionsCancerResponse = require('./responses/conditions-cancer-no-params.json')
2121
const conditionsRootCategoryAGenreConditionResponse = require('./responses/conditions-root-category-a-genre-condition.json')
22-
const conditionsRootCategoryAGenreGuideResponse = require('./responses/conditions-root-category-a-genre-guide.json')
2322
const conditionsRootCategoryAGenreHubResponse = require('./responses/conditions-root-category-a-genre-hub.json')
2423
const conditionsRootCategoryAResponse = require('./responses/conditions-root-category-a.json')
2524
const conditionsRootCategoryBResponse = require('./responses/conditions-root-category-b.json')
2625
const conditionsRootCategoryZResponse = require('./responses/conditions-root-category-z.json')
2726
const conditionsRootPage1Response = require('./responses/conditions-root-page-1.json')
2827
const conditionsRootPage2Response = require('./responses/conditions-root-page-2.json')
29-
const conditionsRootPage70Response = require('./responses/conditions-root-page-70.json')
28+
const conditionsRootPage29Response = require('./responses/conditions-root-page-29.json')
3029
const conditionsWildcardResponseNoParams = require('./responses/conditions-acne-no-params.json')
3130
const conditionsWildcardModulesTrueResponse = require('./responses/conditions-acne-modules-true.json')
3231
const conditionsZikaResponse = require('./responses/conditions-zika-no-params.json')
@@ -86,6 +85,20 @@ const womensHealthRootResponse = require('./responses/womens-health-root-no-para
8685
const womensHealthPeriodsResponse = require('./responses/womens-health-periods-no-params.json')
8786
const womensHealthAnaemiaResponse = require('./responses/womens-health-anaemia-no-params.json')
8887

88+
// Symptoms - Responses
89+
const symptomsRootNoParamsResponse = require('./responses/symptoms-root-no-params.json')
90+
const symptomsRootCategoryAResponse = require('./responses/symptoms-root-category-a.json')
91+
const symptomsRootCategoryBResponse = require('./responses/symptoms-root-category-b.json')
92+
const symptomsRootPage1Response = require('./responses/symptoms-root-page-1.json')
93+
const symptomsRootPage6Response = require('./responses/symptoms-root-page-6.json')
94+
95+
// Tests and treatments - Responses
96+
const testsAndTreatmentsRootNoParamsResponse = require('./responses/tests-and-treatments-root-no-params.json')
97+
const testsAndTreatmentsRootCategoryAResponse = require('./responses/tests-and-treatments-root-category-a.json')
98+
const testsAndTreatmentsRootCategoryBResponse = require('./responses/tests-and-treatments-root-category-b.json')
99+
const testsAndTreatmentsRootPage1Response = require('./responses/tests-and-treatments-root-page-1.json')
100+
const testsAndTreatmentsRootPage7Response = require('./responses/tests-and-treatments-root-page-7.json')
101+
89102
// ******************************************************************
90103
// ** Root page
91104
// ******************************************************************
@@ -173,9 +186,6 @@ async function conditionsRoot(req, res, next) {
173186
if (req.query.category.toLowerCase() === 'a' && req.query.genre.toLowerCase() === 'condition') {
174187
// http://localhost:9000/conditions/?category=a&genre=condition
175188
responseJson = conditionsRootCategoryAGenreConditionResponse
176-
} else if (req.query.category.toLowerCase() === 'a' && req.query.genre.toLowerCase() === 'guide') {
177-
// http://localhost:9000/conditions/?category=a&genre=guide
178-
responseJson = conditionsRootCategoryAGenreGuideResponse
179189
} else if (req.query.category.toLowerCase() === 'a' && req.query.genre.toLowerCase() === 'hub') {
180190
// http://localhost:9000/conditions/?category=a&genre=hub
181191
responseJson = conditionsRootCategoryAGenreHubResponse
@@ -202,9 +212,9 @@ async function conditionsRoot(req, res, next) {
202212
} else if (req.query.page === '2') {
203213
// http://localhost:9000/conditions/?page=2
204214
responseJson = conditionsRootPage2Response
205-
} else if (req.query.page === '70') {
206-
// http://localhost:9000/conditions/?page=70
207-
responseJson = conditionsRootPage70Response
215+
} else if (req.query.page === '29') {
216+
// http://localhost:9000/conditions/?page=29
217+
responseJson = conditionsRootPage29Response
208218
} else {
209219
responseJson = errorSandboxResponseNotFound
210220
}
@@ -1108,6 +1118,106 @@ async function womensHealthAnaemia(req, res, next) {
11081118
next()
11091119
}
11101120

1121+
// ******************************************************************
1122+
// ** Symptoms pages
1123+
// ******************************************************************
1124+
1125+
// Live website URL
1126+
// https://www.nhs.uk/symptoms/
1127+
// This sandbox on localhost
1128+
// http://localhost:9000/symptoms/
1129+
// API on Azure API Management
1130+
// https://api.nhs.uk/symptoms/
1131+
// Wagtail (Python) Application (no auth key required)
1132+
// https://www.nhs.uk/content-api/symptoms/
1133+
// Apigee Sandbox environment (no auth key required)
1134+
// https://sandbox.api.service.nhs.uk/nhs-website-content/symptoms/
1135+
// Apigee Integration environment ('apikey' required in Header)
1136+
// https://int.api.service.nhs.uk/nhs-website-content/symptoms/
1137+
// Apigee Production environment ('apikey' required in Header)
1138+
// https://api.service.nhs.uk/nhs-website-content/symptoms/
1139+
async function symptomsRoot(req, res, next) {
1140+
let responseJson
1141+
if (req.query.category) {
1142+
if (req.query.category.toLowerCase() === 'a') {
1143+
// http://localhost:9000/symptoms/?category=a
1144+
responseJson = symptomsRootCategoryAResponse
1145+
} else if (req.query.category.toLowerCase() === 'b') {
1146+
// http://localhost:9000/symptoms/?category=b
1147+
responseJson = symptomsRootCategoryBResponse
1148+
} else {
1149+
responseJson = errorSandboxResponseNotFound
1150+
}
1151+
} else if (req.query.page) {
1152+
if (req.query.page === '1') {
1153+
// http://localhost:9000/symptoms/?page=1
1154+
responseJson = symptomsRootPage1Response
1155+
} else if (req.query.page === '6') {
1156+
// http://localhost:9000/symptoms/?page=6
1157+
responseJson = symptomsRootPage6Response
1158+
} else {
1159+
responseJson = errorSandboxResponseNotFound
1160+
}
1161+
} else {
1162+
// http://localhost:9000/symptoms/
1163+
responseJson = symptomsRootNoParamsResponse
1164+
}
1165+
res.status(200).json(responseJson)
1166+
1167+
res.end()
1168+
next()
1169+
}
1170+
1171+
// ******************************************************************
1172+
// ** Tests and treatment pages
1173+
// ******************************************************************
1174+
1175+
// Live website URL
1176+
// https://www.nhs.uk/tests-and-treatments/
1177+
// This sandbox on localhost
1178+
// http://localhost:9000/tests-and-treatments/
1179+
// API on Azure API Management
1180+
// https://api.nhs.uk/tests-and-treatments/
1181+
// Wagtail (Python) Application (no auth key required)
1182+
// https://www.nhs.uk/content-api/tests-and-treatments/
1183+
// Apigee Sandbox environment (no auth key required)
1184+
// https://sandbox.api.service.nhs.uk/nhs-website-content/tests-and-treatments/
1185+
// Apigee Integration environment ('apikey' required in Header)
1186+
// https://int.api.service.nhs.uk/nhs-website-content/tests-and-treatments/
1187+
// Apigee Production environment ('apikey' required in Header)
1188+
// https://api.service.nhs.uk/nhs-website-content/tests-and-treatments/
1189+
async function testsAndTreatmentsRoot(req, res, next) {
1190+
let responseJson
1191+
if (req.query.category) {
1192+
if (req.query.category.toLowerCase() === 'a') {
1193+
// http://localhost:9000/tests-and-treatments/?category=a
1194+
responseJson = testsAndTreatmentsRootCategoryAResponse
1195+
} else if (req.query.category.toLowerCase() === 'b') {
1196+
// http://localhost:9000/tests-and-treatments/?category=b
1197+
responseJson = testsAndTreatmentsRootCategoryBResponse
1198+
} else {
1199+
responseJson = errorSandboxResponseNotFound
1200+
}
1201+
} else if (req.query.page) {
1202+
if (req.query.page === '1') {
1203+
// http://localhost:9000/tests-and-treatments/?page=1
1204+
responseJson = testsAndTreatmentsRootPage1Response
1205+
} else if (req.query.page === '7') {
1206+
// http://localhost:9000/tests-and-treatments/?page=7
1207+
responseJson = testsAndTreatmentsRootPage7Response
1208+
} else {
1209+
responseJson = errorSandboxResponseNotFound
1210+
}
1211+
} else {
1212+
// http://localhost:9000/tests-and-treatments/
1213+
responseJson = testsAndTreatmentsRootNoParamsResponse
1214+
}
1215+
res.status(200).json(responseJson)
1216+
1217+
res.end()
1218+
next()
1219+
}
1220+
11111221
// ******************************************************************
11121222
// ** Status
11131223
// ******************************************************************
@@ -1167,4 +1277,6 @@ module.exports = {
11671277
womensHealthAnaemia,
11681278
womensHealthPeriods,
11691279
womensHealthRoot,
1280+
symptomsRoot,
1281+
testsAndTreatmentsRoot,
11701282
}

0 commit comments

Comments
 (0)