This repository has been archived by the owner on Mar 19, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #140 from nhsuk/feature/replace-postcodes-io
Use in-house postcode search
- Loading branch information
Showing
42 changed files
with
441 additions
and
582 deletions.
There are no files selected for viewing
This file contains 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 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 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 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,17 +1,12 @@ | ||
function mandatorySelectionMessage() { | ||
return 'You must choose one of the options.'; | ||
return 'Please choose one of the options.'; | ||
} | ||
|
||
function emptyPostcodeMessage() { | ||
return 'You must enter a postcode.'; | ||
} | ||
|
||
function invalidPostcodeMessage(location) { | ||
return `We can't find the postcode '${location.toUpperCase()}'. Check the postcode is correct and try again.`; | ||
return 'Please enter a postcode.'; | ||
} | ||
|
||
module.exports = { | ||
emptyPostcodeMessage, | ||
invalidPostcodeMessage, | ||
mandatorySelectionMessage, | ||
}; |
This file contains 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 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 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,9 @@ | ||
function build(location) { | ||
return { | ||
search: location, | ||
select: 'Latitude,Longitude,Type,Name1', | ||
top: 1, | ||
}; | ||
} | ||
|
||
module.exports = build; |
This file contains 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,15 +1,16 @@ | ||
const rp = require('request-promise-native'); | ||
|
||
const search = require('../../../config/config').search; | ||
const headers = require('./headers'); | ||
const search = require('../../../config/config').search; | ||
|
||
async function request(query) { | ||
return rp({ | ||
async function request(query, path) { | ||
const response = await rp({ | ||
body: JSON.stringify(query), | ||
headers, | ||
method: 'POST', | ||
url: `https://${search.host}/service-search/search?api-version=${search.version}`, | ||
url: `https://${search.host}/service-search/${path}?api-version=${search.version}`, | ||
}); | ||
return JSON.parse(response); | ||
} | ||
|
||
module.exports = request; |
File renamed without changes.
This file contains 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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains 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,60 @@ | ||
const errorCounter = require('../lib/prometheus/counters').errorPageViews; | ||
const log = require('../lib/logger'); | ||
const postcodeNotFoundWarnings = require('../lib/prometheus/counters').postcodeNotFoundWarnings; | ||
const postcodeSearchHistogram = require('../lib/prometheus/histograms').postcodeSearch; | ||
const queryBuilder = require('../lib/search/postcodeSearchQueryBuilder'); | ||
const renderer = require('./renderer'); | ||
const searchRequest = require('../lib/search/request'); | ||
|
||
function isOutcode(postcodeDetails) { | ||
return postcodeDetails.Type === 'PostcodeOutCode'; | ||
} | ||
|
||
function postcodeDetailsMapper(postcodeDetails) { | ||
return { | ||
isOutcode: isOutcode(postcodeDetails), | ||
location: { | ||
lat: postcodeDetails.Latitude, | ||
lon: postcodeDetails.Longitude, | ||
}, | ||
}; | ||
} | ||
|
||
async function performPostcodeSearch(location) { | ||
const query = queryBuilder(location); | ||
const path = 'postcodesandplaces/search'; | ||
const response = await searchRequest(query, path); | ||
log.debug({ postcodeSearchResponse: { response } }, 'Postcode Search response'); | ||
return response; | ||
} | ||
|
||
async function postcodeSearch(req, res, next) { | ||
const location = res.locals.location; | ||
|
||
log.debug({ location }, 'Postcode search text'); | ||
const endTimer = postcodeSearchHistogram.startTimer(); | ||
if (location) { | ||
try { | ||
const postcodeDetails = await performPostcodeSearch(location); | ||
|
||
if (postcodeDetails && postcodeDetails.value && postcodeDetails.value.length) { | ||
res.locals.postcodeLocationDetails = postcodeDetailsMapper(postcodeDetails.value[0]); | ||
next(); | ||
} else { | ||
postcodeNotFoundWarnings.inc(1); | ||
renderer.postcodeNotFound(req, res); | ||
} | ||
} catch (error) { | ||
log.debug({ location }, 'Error in postcode Search'); | ||
errorCounter.inc(1); | ||
next(error); | ||
} finally { | ||
endTimer(); | ||
} | ||
} else { | ||
log.debug('No postcode'); | ||
next(); | ||
} | ||
} | ||
|
||
module.exports = postcodeSearch; |
This file contains 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 was deleted.
Oops, something went wrong.
This file contains 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,3 @@ | ||
We can't find the postcode '{{ location }}'. Please check the postcode is correct and try again. | ||
<br> | ||
Or get help to find a chlamydia test in <a href="{{ siteRoot }}/#scotland"><span class='sr-only'>find a chlamydia test in </span>Scotland</a>, <a href="{{ siteRoot }}/#wales"><span class='sr-only'>find a chlamydia test in </span>Wales</a> or <a href="{{ siteRoot }}/#northern"><span class='sr-only'>find a chlamydia test in </span>Northern Ireland</a>. |
This file contains 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 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 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.