Skip to content

Commit fb4bbde

Browse files
NIAD-1456: started implementing new exception when ehr is unextractable (#1363)
1 parent e444da4 commit fb4bbde

File tree

13 files changed

+753
-8
lines changed

13 files changed

+753
-8
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1515
* The GP2GP Adaptor now adds the EhrComposition / confidentialityCode field when Encounter.meta.security contains NOPAT security entry
1616
* The GP2GP Adaptor now populates the ObservationStatement / confidentialityCode field when the .meta.security field of an Uncategorized Data Observation contains NOPAT
1717
* When List.meta.security field contains NOPAT, the GP2GP Adaptor will now populate the CompoundStatement.confidentialityCode
18+
* The GP2GP Adaptor now throws an exception when the Access Structure Record is empty, thereby rejecting the transfer
1819

1920
### Fixed
2021
* When DiagnosticReport doesn't contain a Specimen reference, instead of "DUMMY" "NOT-PRESENT" value is used

docker/run-e2e-tests.sh

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

33
set -e
44

5-
if [ -f "vars.sh" ]; then
6-
source vars.sh
5+
if [ -f "vars.local.e2e.sh" ]; then
6+
source vars.local.e2e.sh
77
else
8-
echo "No vars.sh defined. Using docker-compose defaults."
8+
echo "No vars.local.e2e.sh defined. Using docker-compose defaults."
99
fi
1010
if [[ "$(docker network ls | grep "commonforgp2gp")" == "" ]] ; then
1111
docker network create commonforgp2gp

e2e-tests/src/test/java/uk/nhs/adaptors/gp2gp/e2e/EhrExtractTest.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ class EhrExtractTest {
7272
private static final String NHS_NUMBER_RESPONSE_MISSING_PATIENT_RESOURCE = "2906543841";
7373
private static final String NHS_NUMBER_MEDICUS_BASED_ON = "9302014592";
7474
private static final String NHS_NUMBER_INVALID_CONTENT_TYPE_DOC = "9817280691";
75+
private static final String NHS_NUMBER_NO_CLINICAL_CONTENT_STRUCTURE = "9736435687";
7576
private static final String NHS_NUMBER_BODY_SITE = "1239577290";
7677
private static final String EHR_EXTRACT_REQUEST_TEST_FILE = "/ehrExtractRequest.json";
7778
private static final String EHR_EXTRACT_REQUEST_WITHOUT_NHS_NUMBER_TEST_FILE = "/ehrExtractRequestWithoutNhsNumber.json";
@@ -442,6 +443,30 @@ void When_ExtractRequestReceivedForMedicusPatientWithBasedOn_Expect_ExtractStatu
442443

443444
}
444445

446+
@Test
447+
void When_ExtractRequestReceivedForPatientWithoutClinicalContent_Expect_ExtractStatusAndDocumentDataAddedToDbAndReturnCode10() throws Exception {
448+
String conversationId = UUID.randomUUID().toString();
449+
String ehrExtractRequest = buildEhrExtractRequest(conversationId, NHS_NUMBER_NO_CLINICAL_CONTENT_STRUCTURE, FROM_ODS_CODE_1);
450+
MessageQueue.sendToMhsInboundQueue(ehrExtractRequest);
451+
452+
var requestJournal = waitFor(() -> {
453+
try {
454+
return mhsMockRequestsJournal.getRequestsJournal(conversationId);
455+
} catch (IOException | InterruptedException e) {
456+
throw new RuntimeException(e);
457+
}
458+
});
459+
460+
assertThat(requestJournal).hasSize(1);
461+
462+
var ehrExtractStatus = waitFor(() -> Mongo.findEhrExtractStatus(conversationId));
463+
assertThatInitialRecordWasCreated(conversationId, ehrExtractStatus, NHS_NUMBER_NO_CLINICAL_CONTENT_STRUCTURE, FROM_ODS_CODE_1);
464+
465+
var error = (Document) ehrExtractStatus.get("error");
466+
assertThat(error).isNotEmpty();
467+
softly.assertThat(error.get("code")).isEqualTo(NACK_CODE_FAILED_TO_GENERATE_EHR);
468+
}
469+
445470
@Test
446471
void When_ExtractRequestReceivedForEMISPWTP2_Expect_ExtractStatusAndDocumentDataAddedToDatabase() throws IOException, NamingException, JMSException {
447472
String conversationId = UUID.randomUUID().toString();

service/build.gradle

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,13 +84,13 @@ dependencies {
8484
testImplementation 'org.wiremock:wiremock-standalone:3.13.1'
8585
testImplementation 'com.squareup.okhttp3:okhttp:5.1.0'
8686
testImplementation 'com.squareup.okhttp3:mockwebserver3:5.1.0'
87-
testImplementation 'com.adobe.testing:s3mock-testcontainers:4.9.1'
87+
testImplementation 'com.adobe.testing:s3mock-testcontainers:4.7.0'
8888

8989
spotbugs 'com.github.spotbugs:spotbugs:4.9.6'
9090
spotbugs 'com.github.spotbugs:spotbugs-annotations:4.9.6'
9191

9292
pitest 'com.arcmutate:base:1.3.2'
93-
pitest 'com.arcmutate:pitest-git-plugin:2.2.4'
93+
pitest 'com.arcmutate:pitest-git-plugin:2.1.0'
9494
}
9595

9696
test {
@@ -165,7 +165,7 @@ spotbugsMain {
165165
}
166166

167167
pitest {
168-
pitestVersion = '1.16.1'
168+
pitestVersion = '1.16.3'
169169
junit5PluginVersion = '1.2.1'
170170
outputFormats = ['gitci']
171171

service/src/intTest/java/uk/nhs/adaptors/gp2gp/ehr/SendEhrExtractCoreComponentTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@
6464
@ExtendWith({SpringExtension.class, MongoDBExtension.class, ActiveMQExtension.class, MockitoExtension.class})
6565
@SpringBootTest
6666
@DirtiesContext
67+
@SuppressWarnings("SpringJavaInjectionPointsAutowiringInspection")
6768
public class SendEhrExtractCoreComponentTest extends BaseTaskTest {
6869
private static final String OUTBOUND_MESSAGE = serializeOutboundMessage("payload");
6970
public static final String OUTBOUND_MESSAGE_WITH_PLACEHOLDER =

service/src/intTest/java/uk/nhs/adaptors/gp2gp/testcontainers/ActiveMqContainer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public static ActiveMqContainer getInstance() {
2222
@Override
2323
public void start() {
2424
super.start();
25-
var containerBrokerUri = "amqp://" + getContainerIpAddress() + ":" + getMappedPort(ACTIVEMQ_PORT);
25+
var containerBrokerUri = "amqp://" + getHost() + ":" + getMappedPort(ACTIVEMQ_PORT);
2626
System.setProperty("GP2GP_AMQP_BROKERS", containerBrokerUri);
2727
}
2828
}

service/src/main/java/uk/nhs/adaptors/gp2gp/common/task/TaskErrorHandler.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import uk.nhs.adaptors.gp2gp.ehr.SendAcknowledgementTaskDefinition;
1616
import uk.nhs.adaptors.gp2gp.ehr.exception.EhrExtractException;
1717
import uk.nhs.adaptors.gp2gp.ehr.exception.EhrMapperException;
18+
import uk.nhs.adaptors.gp2gp.ehr.exception.EhrValidationException;
1819
import uk.nhs.adaptors.gp2gp.gpc.exception.EhrRequestException;
1920
import uk.nhs.adaptors.gp2gp.gpc.exception.GpConnectException;
2021
import uk.nhs.adaptors.gp2gp.gpc.exception.GpConnectInvalidException;
@@ -30,6 +31,7 @@ public class TaskErrorHandler {
3031
EhrRequestException.class, this::handleRequestError,
3132
EhrExtractException.class, this::handleTranslationError,
3233
EhrMapperException.class, this::handleTranslationError,
34+
EhrValidationException.class, this::handleTranslationError,
3335
FhirValidationException.class, this::handleTranslationError,
3436
GpConnectException.class, this::handleGpConnectError,
3537
GpConnectInvalidException.class, this::handleInvalidNotAuthError,
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package uk.nhs.adaptors.gp2gp.ehr.exception;
2+
3+
public class EhrValidationException extends RuntimeException {
4+
5+
public EhrValidationException(String message) {
6+
super(message);
7+
}
8+
}

service/src/main/java/uk/nhs/adaptors/gp2gp/ehr/mapper/EhrExtractMapper.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
import uk.nhs.adaptors.gp2gp.ehr.utils.TemplateUtils;
2222
import uk.nhs.adaptors.gp2gp.gpc.GetGpcStructuredTaskDefinition;
2323

24+
import uk.nhs.adaptors.gp2gp.ehr.exception.EhrValidationException;
25+
2426
import java.util.List;
2527
import java.util.Optional;
2628
import java.util.stream.Collectors;
@@ -56,6 +58,12 @@ public EhrExtractTemplateParameters mapBundleToEhrFhirExtractParams(
5658
mappedComponents.addAll(nonConsultationResourceMapper.mapRemainingResourcesToEhrCompositions(bundle));
5759
ehrExtractTemplateParameters.setComponents(mappedComponents);
5860

61+
if (mappedComponents.isEmpty()) {
62+
final String message = "could not extract EHR Extract: empty structured access record.";
63+
LOGGER.error(message);
64+
throw new EhrValidationException(message);
65+
}
66+
5967
ehrExtractTemplateParameters.setAgentDirectory(
6068
agentDirectoryMapper.mapEHRFolderToAgentDirectory(bundle, getPatientNhsNumber(getGpcStructuredTaskDefinition))
6169
);

service/src/test/java/uk/nhs/adaptors/gp2gp/common/task/TaskErrorHandlerTest.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import uk.nhs.adaptors.gp2gp.common.service.ProcessFailureHandlingService;
3131
import uk.nhs.adaptors.gp2gp.ehr.exception.EhrExtractException;
3232
import uk.nhs.adaptors.gp2gp.ehr.exception.EhrMapperException;
33+
import uk.nhs.adaptors.gp2gp.ehr.exception.EhrValidationException;
3334
import uk.nhs.adaptors.gp2gp.gpc.exception.EhrRequestException;
3435
import uk.nhs.adaptors.gp2gp.gpc.exception.GpConnectException;
3536
import uk.nhs.adaptors.gp2gp.gpc.exception.GpConnectInvalidException;
@@ -65,6 +66,17 @@ void When_HandleProcessingError_WithEhrRequestException_Expect_ProcessToBeFailed
6566
any());
6667
}
6768

69+
@Test
70+
void When_HandleProcessingError_WithEhrValidationException_Expect_ProcessToBeFailedWithCorrectCode() {
71+
taskErrorHandler.handleProcessingError(new EhrValidationException(TEST_EXCEPTION_MESSAGE), taskDefinition);
72+
73+
verify(processFailureHandlingService).failProcess(
74+
any(),
75+
eq("10"),
76+
eq("Failed to successfully generate EHR Extract."),
77+
any());
78+
}
79+
6880
@Test
6981
void When_HandleProcessingError_WithEhrRequestException_Expect_ReturnValueOfFailService() {
7082
when(processFailureHandlingService.failProcess(any(), any(), any(), any()))

0 commit comments

Comments
 (0)