Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,5 @@ __pycache__/
.venv/
smoketest-report.xml
*.code-workspace
.python-version
Comment thread
stuartmcneill1-nhs marked this conversation as resolved.
Outdated

Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@

@SpringBootTest
@AutoConfigureMockMvc
@ExtendWith({SpringExtension.class})
@ExtendWith({ SpringExtension.class })
@DirtiesContext
@Slf4j
@ContextConfiguration(initializers = {WireMockInitializer.class})
@ContextConfiguration(initializers = { WireMockInitializer.class })
public class SetAcsUAT {
private static final String SPINE_ACS_ENDPOINT = "/sync-service";
private static final String ACS_QUERY_HEADER = "urn:nhs:names:services:lrs/SET_RESOURCE_PERMISSIONS_INUK01";
Expand Down Expand Up @@ -87,7 +87,7 @@ public void testSetAcsPermissionViaSds(TestData testData) throws Exception {
stubSdsService(practitionerRoleResponse);

performRequest(testData.getFhirRequest())
.andExpect(status().isCreated());
.andExpect(status().isCreated());
}

@ParameterizedTest(name = "[{index}] - {0}")
Expand All @@ -97,7 +97,7 @@ public void testSetAcsPermissionViaUserInfo(TestData testData) throws Exception
stubIdentityService(userInfoResponse);

performRequest(testData.getFhirRequest())
.andExpect(status().isCreated());
.andExpect(status().isCreated());
}

@ParameterizedTest(name = "[{index}] - {0}")
Expand All @@ -107,8 +107,8 @@ public void testSetAcsPermissionSpineError(TestData testData) throws Exception {
stubIdentityService(userInfoResponse);

performRequest(testData.getFhirRequest())
.andExpect(status().isBadRequest())
.andExpect(content().json(testData.getFhirResponse()));
.andExpect(status().isBadRequest())
.andExpect(content().json(testData.getFhirResponse()));
}

@ParameterizedTest(name = "[{index}] - {0}")
Expand All @@ -117,59 +117,84 @@ public void testSetAcsPermissionBadRequest(TestData testData) throws Exception {
stubIdentityService(userInfoResponse);

performRequest(testData.getFhirRequest())
.andExpect(status().isBadRequest())
.andExpect(content().json(testData.getFhirResponse()));
.andExpect(status().isBadRequest())
.andExpect(content().json(testData.getFhirResponse()));
}

@ParameterizedTest(name = "[{index}] - {0}")
@ArgumentsSource(SetAcsBadRequest.class)
public void testSetAcsPermissionNoRoleCodeBadRequest(TestData testData) throws Exception {
// FLAGSAPI-1046 should return Bad Request if no role code is returned from SDS
// or Identity Service
stubFailedIdentityService();
stubFailedSdsService();
stubSpineAcsEndpoint(acsErrorResponse);

performRequest(testData.getFhirRequest())
.andExpect(status().isBadRequest())
.andExpect(content().json(testData.getFhirResponse()));
}

private ResultActions performRequest(String request) throws Exception {
return mockMvc.perform(post(ACS_ENDPOINT)
.contentType(APPLICATION_FHIR_JSON)
.header(ScrHttpHeaders.NHSD_ASID, NHSD_ASID)
.header(ScrHttpHeaders.CLIENT_IP, CLIENT_IP)
.header(ScrHttpHeaders.NHSD_SESSION_URID, NHSD_SESSION_URID)
.header(ScrHttpHeaders.NHSD_IDENTITY, NHSD_IDENTITY_UUID)
.header(AUTHORIZATION, BEARER_TOKEN)
.content(request));
.contentType(APPLICATION_FHIR_JSON)
.header(ScrHttpHeaders.NHSD_ASID, NHSD_ASID)
.header(ScrHttpHeaders.CLIENT_IP, CLIENT_IP)
.header(ScrHttpHeaders.NHSD_SESSION_URID, NHSD_SESSION_URID)
.header(ScrHttpHeaders.NHSD_IDENTITY, NHSD_IDENTITY_UUID)
.header(AUTHORIZATION, BEARER_TOKEN)
.content(request));

}

private void stubSpineAcsEndpoint(Resource response) throws IOException {
wireMockServer.stubFor(
WireMock.post(SPINE_ACS_ENDPOINT)
.withHeader(SOAP_ACTION, equalTo(ACS_QUERY_HEADER))
.withHeader(CONTENT_TYPE, equalTo(TEXT_XML_VALUE))
.willReturn(aResponse()
.withStatus(OK.value())
.withBody(readString(response.getFile().toPath(), UTF_8))));
WireMock.post(SPINE_ACS_ENDPOINT)
.withHeader(SOAP_ACTION, equalTo(ACS_QUERY_HEADER))
.withHeader(CONTENT_TYPE, equalTo(TEXT_XML_VALUE))
.willReturn(aResponse()
.withStatus(OK.value())
.withBody(readString(response.getFile().toPath(), UTF_8))));
}

private void stubSdsService(Resource response) throws IOException {
wireMockServer.stubFor(
WireMock.get(WireMock.urlPathEqualTo(PRACTITIONER_ROLE_ENDPOINT))
.withQueryParam(USER_ID_QUERY_PARAM,
containing(NHSD_SESSION_URID))
.willReturn(aResponse()
.withStatus(OK.value())
.withHeader(CONTENT_TYPE, APPLICATION_JSON_VALUE)
.withBody(readString(response.getFile().toPath(), UTF_8))));
WireMock.get(WireMock.urlPathEqualTo(PRACTITIONER_ROLE_ENDPOINT))
.withQueryParam(USER_ID_QUERY_PARAM,
containing(NHSD_SESSION_URID))
.willReturn(aResponse()
.withStatus(OK.value())
.withHeader(CONTENT_TYPE, APPLICATION_JSON_VALUE)
.withBody(readString(response.getFile().toPath(), UTF_8))));
}

private void stubFailedSdsService() {
wireMockServer.stubFor(
WireMock.get(WireMock.urlPathEqualTo(PRACTITIONER_ROLE_ENDPOINT))
.withQueryParam(USER_ID_QUERY_PARAM,
containing(NHSD_SESSION_URID))
.willReturn(aResponse()
.withStatus(OK.value())
.withHeader(CONTENT_TYPE, APPLICATION_JSON_VALUE)
.withBody("")));
}

private void stubIdentityService(Resource response) throws IOException {
wireMockServer.stubFor(
WireMock.get(USER_INFO_ENDPOINT)
.withHeader(AUTHORIZATION, equalTo(BEARER_TOKEN))
.willReturn(aResponse()
.withStatus(OK.value())
.withHeader(CONTENT_TYPE, APPLICATION_JSON_VALUE)
.withBody(readString(response.getFile().toPath(), UTF_8))));
WireMock.get(USER_INFO_ENDPOINT)
.withHeader(AUTHORIZATION, equalTo(BEARER_TOKEN))
.willReturn(aResponse()
.withStatus(OK.value())
.withHeader(CONTENT_TYPE, APPLICATION_JSON_VALUE)
.withBody(readString(response.getFile().toPath(), UTF_8))));
}

private void stubFailedIdentityService() {
wireMockServer.stubFor(
WireMock.get(USER_INFO_ENDPOINT)
.withHeader(AUTHORIZATION, equalTo(BEARER_TOKEN))
.willReturn(aResponse()
.withStatus(BAD_REQUEST.value())
.withHeader(CONTENT_TYPE, APPLICATION_JSON_VALUE)));
WireMock.get(USER_INFO_ENDPOINT)
.withHeader(AUTHORIZATION, equalTo(BEARER_TOKEN))
.willReturn(aResponse()
.withStatus(BAD_REQUEST.value())
.withHeader(CONTENT_TYPE, APPLICATION_JSON_VALUE)));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,22 @@ private Pair<String, String> getUserRoleCodeAndId(String authorisation, String n

}

// if we haven't retrieved a role code from openID we try the SDS service
try {
return Pair.of(sdsService.getUserRoleCode(nhsdSessionUrid), nhsdIdentity);
var roleCode = sdsService.getUserRoleCode(nhsdSessionUrid);
if (roleCode != null && !roleCode.isEmpty()) {
return Pair.of(roleCode, nhsdIdentity);
}
} catch (BadRequestException | URISyntaxException e) {
LOGGER.info(String.format("Unable to determine Job Role Code for "
+ "the given RoleID via the SDS Service: %s", nhsdSessionUrid));
throw new BadRequestException(String.format("Unable to determine SDS Job Role Code for "
+ "the given RoleID: %s", nhsdSessionUrid));
}
LOGGER.info(String.format("Unable to determine Job Role Code for "
+ "the given RoleID via the SDS Service: %s", nhsdSessionUrid));
throw new BadRequestException(String.format("Unable to determine SDS Job Role Code for "
+ "the given RoleID: %s", nhsdSessionUrid));
Comment thread
stuartmcneill1-nhs marked this conversation as resolved.
Outdated
}

private String prepareAcsRequest(ParametersParameterComponent parameter, RequestData requestData, String sdsJobRoleCode,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public class GetScrService {
private static final String SNOMED_SYSTEM = "http://snomed.info/sct";
private static final String GP_SUMMARY_SNOMED_CODE = "196981000000101";
private static final String GP_SUMMARY_DISPLAY = " General Practice Summary";
private static final String ATTACHMENT_URL = "%s/Bundle?composition.identifier=%s"
private static final String ATTACHMENT_URL = "%sBundle?composition.identifier=%s"
+ "&composition.subject:Patient.identifier=https://fhir.nhs.uk/Id/nhs-number|%s";

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

bundle.addEntry(new BundleEntryComponent()
.setFullUrl(patient.getId())
.setResource(patient)
);
.setResource(patient));
} else {
bundle.setTotal(0);
}
Expand Down Expand Up @@ -235,8 +233,8 @@ private void checkDetectedIssues(Document document) {
}

private DocumentReference buildDocumentReference(String nhsNumber,
EventListQueryResponse response,
Patient patient) {
EventListQueryResponse response,
Patient patient) {
DocumentReference documentReference = new DocumentReference();
documentReference.setId(randomUUID());

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

DocumentReferenceContentComponent content =
buildDocumentReferenceContent(nhsNumber, response.getLatestScrId());
DocumentReferenceContentComponent content = buildDocumentReferenceContent(nhsNumber, response.getLatestScrId());
documentReference.addContent(content);

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


private Patient buildPatientResource(String nhsNumber) {
Patient patient = new Patient();
String patientResourceId = randomUUID();
Expand All @@ -285,7 +281,8 @@ private Patient buildPatientResource(String nhsNumber) {
private String prepareEventListQueryRequest(String nhsNumber, String nhsdAsid, String clientIp) {
EventListQueryParams eventListQueryParams = new EventListQueryParams()
.setGeneratedMessageId(MDC.get(CORRELATION_ID_MDC_KEY))
.setMessageCreationTime(DateTimeFormatter.ofPattern("yyyyMMddHHmmss").format(now(ZoneId.of("Europe/London"))))
.setMessageCreationTime(
DateTimeFormatter.ofPattern("yyyyMMddHHmmss").format(now(ZoneId.of("Europe/London"))))
.setNhsNumber(nhsNumber)
.setSenderFromASID(nhsdAsid)
.setSpineToASID(scrConfiguration.getNhsdAsidTo())
Expand All @@ -297,7 +294,8 @@ private String prepareEventListQueryRequest(String nhsNumber, String nhsdAsid, S
private String prepareEventQueryRequest(String psisEventId, String nhsNumber, String nhsdAsid, String clientIp) {
var eventListQueryParams = new EventQueryParams()
.setGeneratedMessageId(MDC.get(CORRELATION_ID_MDC_KEY))
.setMessageCreationTime(DateTimeFormatter.ofPattern("yyyyMMddHHmmss").format(now(ZoneId.of("Europe/London"))))
.setMessageCreationTime(
DateTimeFormatter.ofPattern("yyyyMMddHHmmss").format(now(ZoneId.of("Europe/London"))))
.setNhsNumber(nhsNumber)
.setSenderFromASID(nhsdAsid)
.setSpineToASID(scrConfiguration.getNhsdAsidTo())
Expand Down
Loading
Loading