Skip to content

Commit 7f37ac4

Browse files
Changed GetScrIdUAT to return 400 if unable to retrieve user role code
- corrected path problem when building attachment resource url - corrected documentation to advise using combined auth-authentication
1 parent a60f35e commit 7f37ac4

File tree

4 files changed

+147
-127
lines changed

4 files changed

+147
-127
lines changed

docker/service/src/integration-test/java/uk/nhs/adaptors/scr/uat/GetScrIdUAT.java

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,10 @@
4343

4444
@SpringBootTest
4545
@AutoConfigureMockMvc
46-
@ExtendWith({SpringExtension.class})
46+
@ExtendWith({ SpringExtension.class })
4747
@DirtiesContext
4848
@Slf4j
49-
@ContextConfiguration(initializers = {WireMockInitializer.class})
49+
@ContextConfiguration(initializers = { WireMockInitializer.class })
5050
public class GetScrIdUAT {
5151

5252
private static final String EVENT_LIST_QUERY_HEADER = "urn:nhs:names:services:psisquery/QUPC_IN180000SM04";
@@ -57,11 +57,11 @@ public class GetScrIdUAT {
5757
private static final String TYPE_PARAM = "http://snomed.info/sct|196981000000101";
5858
private static final String NHSD_ASID = "1029384756";
5959
private static final String CLIENT_IP = "192.168.0.24";
60-
private static final String[] IGNORED_JSON_PATHS = new String[]{
61-
"id",
62-
"entry[*].fullUrl",
63-
"entry[*].resource.subject.reference",
64-
"entry[*].resource.id"
60+
private static final String[] IGNORED_JSON_PATHS = new String[] {
61+
"id",
62+
"entry[*].fullUrl",
63+
"entry[*].resource.subject.reference",
64+
"entry[*].resource.id"
6565
};
6666

6767
@Value("classpath:uat/responses/event-list-query/success.xml")
@@ -113,24 +113,24 @@ void testRetrieveLatestScrIdNoConsent(TestData testData) throws Exception {
113113

114114
private void performRequestAndAssert(TestData testData, HttpStatus expectedHttpStatus) throws Exception {
115115
mockMvc.perform(get(GET_SCR_ID_ENDPOINT)
116-
.contentType(APPLICATION_FHIR_JSON_VALUE)
117-
.header(ScrHttpHeaders.NHSD_ASID, NHSD_ASID)
118-
.header(ScrHttpHeaders.CLIENT_IP, CLIENT_IP)
119-
.queryParam("patient", NHS_NUMBER)
120-
.queryParam("type", TYPE_PARAM)
121-
.queryParam("_sort", SORT_PARAM)
122-
.queryParam("_count", COUNT_PARAM))
123-
.andExpect(status().is(expectedHttpStatus.value()))
124-
.andExpect(fhirJson(testData.getFhirResponse(), IGNORED_JSON_PATHS));
116+
.contentType(APPLICATION_FHIR_JSON_VALUE)
117+
.header(ScrHttpHeaders.NHSD_ASID, NHSD_ASID)
118+
.header(ScrHttpHeaders.CLIENT_IP, CLIENT_IP)
119+
.queryParam("patient", NHS_NUMBER)
120+
.queryParam("type", TYPE_PARAM)
121+
.queryParam("_sort", SORT_PARAM)
122+
.queryParam("_count", COUNT_PARAM))
123+
.andExpect(status().is(expectedHttpStatus.value()))
124+
.andExpect(fhirJson(testData.getFhirResponse(), IGNORED_JSON_PATHS));
125125
}
126126

127127
private void stubSpinePsisEndpoint(Resource response) throws IOException {
128128
wireMockServer.stubFor(
129-
WireMock.post(spineConfiguration.getPsisQueriesEndpoint())
130-
.withHeader(SOAP_ACTION, equalTo(EVENT_LIST_QUERY_HEADER))
131-
.withHeader(CONTENT_TYPE, equalTo(TEXT_XML_VALUE))
132-
.willReturn(aResponse()
133-
.withStatus(OK.value())
134-
.withBody(readString(response.getFile().toPath(), UTF_8))));
129+
WireMock.post(spineConfiguration.getPsisQueriesEndpoint())
130+
.withHeader(SOAP_ACTION, equalTo(EVENT_LIST_QUERY_HEADER))
131+
.withHeader(CONTENT_TYPE, equalTo(TEXT_XML_VALUE))
132+
.willReturn(aResponse()
133+
.withStatus(OK.value())
134+
.withBody(readString(response.getFile().toPath(), UTF_8))));
135135
}
136136
}

docker/service/src/integration-test/java/uk/nhs/adaptors/scr/uat/SetAcsUAT.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,19 @@ public void testSetAcsPermissionBadRequest(TestData testData) throws Exception {
121121
.andExpect(content().json(testData.getFhirResponse()));
122122
}
123123

124+
@ParameterizedTest(name = "[{index}] - {0}")
125+
@ArgumentsSource(SetAcsBadRequest.class)
126+
public void testSetAcsPermissionNoRoleCodeBadRequest(TestData testData) throws Exception {
127+
// FLAGSAPI-1046 should return Bad Request if no role code is returned from SDS or Identity Service
128+
stubFailedIdentityService();
129+
stubFailedSdsService();
130+
stubSpineAcsEndpoint(acsErrorResponse);
131+
132+
performRequest(testData.getFhirRequest())
133+
.andExpect(status().isBadRequest())
134+
.andExpect(content().json(testData.getFhirResponse()));
135+
}
136+
124137
private ResultActions performRequest(String request) throws Exception {
125138
return mockMvc.perform(post(ACS_ENDPOINT)
126139
.contentType(APPLICATION_FHIR_JSON)
@@ -154,6 +167,17 @@ private void stubSdsService(Resource response) throws IOException {
154167
.withBody(readString(response.getFile().toPath(), UTF_8))));
155168
}
156169

170+
private void stubFailedSdsService(Resource response) throws IOException {
171+
wireMockServer.stubFor(
172+
WireMock.get(WireMock.urlPathEqualTo(PRACTITIONER_ROLE_ENDPOINT))
173+
.withQueryParam(USER_ID_QUERY_PARAM,
174+
containing(NHSD_SESSION_URID))
175+
.willReturn(aResponse()
176+
.withStatus(OK.value())
177+
.withHeader(CONTENT_TYPE, APPLICATION_JSON_VALUE)
178+
.withBody(readString(response.getFile().toPath(), UTF_8))));
179+
}
180+
157181
private void stubIdentityService(Resource response) throws IOException {
158182
wireMockServer.stubFor(
159183
WireMock.get(USER_INFO_ENDPOINT)

docker/service/src/main/java/uk/nhs/adaptors/scr/services/GetScrService.java

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ public class GetScrService {
8080
private static final String SNOMED_SYSTEM = "http://snomed.info/sct";
8181
private static final String GP_SUMMARY_SNOMED_CODE = "196981000000101";
8282
private static final String GP_SUMMARY_DISPLAY = " General Practice Summary";
83-
private static final String ATTACHMENT_URL = "%s/Bundle?composition.identifier=%s"
83+
private static final String ATTACHMENT_URL = "%sBundle?composition.identifier=%s"
8484
+ "&composition.subject:Patient.identifier=https://fhir.nhs.uk/Id/nhs-number|%s";
8585

8686
private static final CodeableConcept GP_SUMMARY_SNOMED = new CodeableConcept(new Coding()
@@ -133,13 +133,11 @@ public Bundle getScrId(String nhsNumber, String nhsdAsid, String clientIp) {
133133
bundle.addEntry(new BundleEntryComponent()
134134
.setFullUrl(getScrUrl() + "/DocumentReference/" + documentReference.getId())
135135
.setResource(documentReference)
136-
.setSearch(new Bundle.BundleEntrySearchComponent().setMode(MATCH))
137-
);
136+
.setSearch(new Bundle.BundleEntrySearchComponent().setMode(MATCH)));
138137

139138
bundle.addEntry(new BundleEntryComponent()
140139
.setFullUrl(patient.getId())
141-
.setResource(patient)
142-
);
140+
.setResource(patient));
143141
} else {
144142
bundle.setTotal(0);
145143
}
@@ -235,8 +233,8 @@ private void checkDetectedIssues(Document document) {
235233
}
236234

237235
private DocumentReference buildDocumentReference(String nhsNumber,
238-
EventListQueryResponse response,
239-
Patient patient) {
236+
EventListQueryResponse response,
237+
Patient patient) {
240238
DocumentReference documentReference = new DocumentReference();
241239
documentReference.setId(randomUUID());
242240

@@ -248,8 +246,7 @@ private DocumentReference buildDocumentReference(String nhsNumber,
248246
documentReference.setType(GP_SUMMARY_SNOMED);
249247
documentReference.setSubject(new Reference(patient));
250248

251-
DocumentReferenceContentComponent content =
252-
buildDocumentReferenceContent(nhsNumber, response.getLatestScrId());
249+
DocumentReferenceContentComponent content = buildDocumentReferenceContent(nhsNumber, response.getLatestScrId());
253250
documentReference.addContent(content);
254251

255252
documentReference.setMasterIdentifier(new Identifier()
@@ -270,7 +267,6 @@ private DocumentReferenceContentComponent buildDocumentReferenceContent(String n
270267
return content;
271268
}
272269

273-
274270
private Patient buildPatientResource(String nhsNumber) {
275271
Patient patient = new Patient();
276272
String patientResourceId = randomUUID();
@@ -285,7 +281,8 @@ private Patient buildPatientResource(String nhsNumber) {
285281
private String prepareEventListQueryRequest(String nhsNumber, String nhsdAsid, String clientIp) {
286282
EventListQueryParams eventListQueryParams = new EventListQueryParams()
287283
.setGeneratedMessageId(MDC.get(CORRELATION_ID_MDC_KEY))
288-
.setMessageCreationTime(DateTimeFormatter.ofPattern("yyyyMMddHHmmss").format(now(ZoneId.of("Europe/London"))))
284+
.setMessageCreationTime(
285+
DateTimeFormatter.ofPattern("yyyyMMddHHmmss").format(now(ZoneId.of("Europe/London"))))
289286
.setNhsNumber(nhsNumber)
290287
.setSenderFromASID(nhsdAsid)
291288
.setSpineToASID(scrConfiguration.getNhsdAsidTo())
@@ -297,7 +294,8 @@ private String prepareEventListQueryRequest(String nhsNumber, String nhsdAsid, S
297294
private String prepareEventQueryRequest(String psisEventId, String nhsNumber, String nhsdAsid, String clientIp) {
298295
var eventListQueryParams = new EventQueryParams()
299296
.setGeneratedMessageId(MDC.get(CORRELATION_ID_MDC_KEY))
300-
.setMessageCreationTime(DateTimeFormatter.ofPattern("yyyyMMddHHmmss").format(now(ZoneId.of("Europe/London"))))
297+
.setMessageCreationTime(
298+
DateTimeFormatter.ofPattern("yyyyMMddHHmmss").format(now(ZoneId.of("Europe/London"))))
301299
.setNhsNumber(nhsNumber)
302300
.setSenderFromASID(nhsdAsid)
303301
.setSpineToASID(scrConfiguration.getNhsdAsidTo())

0 commit comments

Comments
 (0)