Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code cleanup: removing unused code variables, excessing throwables and making test assessments more concise #920

Merged
merged 3 commits into from
Nov 11, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -124,28 +124,6 @@ private static void setPractiotionerAndAsserter(RCMRMT030101UKEhrComposition ehr
.addPractitioner(asserter);
}

private void setPractitioners(Immunization immunization, RCMRMT030101UKObservationStatement observationStatement,
RCMRMT030101UKEhrComposition ehrComposition) {

var recorderAndAsserter = ParticipantReferenceUtil.fetchRecorderAndAsserter(ehrComposition);

var practitioner = Optional.ofNullable(getParticipantReference(
observationStatement.getParticipant(),
ehrComposition));

practitioner.ifPresent(participant -> {
var asserter = getImmunizationPractitioner(participant, "");
immunization.addPractitioner(asserter);

recorderAndAsserter.get(RECORDER).ifPresent(recorderRef -> {
if (!recorderRef.getReference().equals(participant.getReference())) {
var recorder = getImmunizationPractitioner(recorderRef, "EP");
immunization.addPractitioner(recorder);
}
});
});
}

private Immunization initializeImmunization(RCMRMT030101UKObservationStatement observationStatement,
RCMRMT030101UKEhrComposition ehrComposition,
List<Encounter> encounterList,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,6 @@ class ReferralRequestMapperTest {
private static final String PRIORITY_NOTE_PREPENDAGE = "Priority: ";
private static final String NOPAT = "NOPAT";

private static final String NOSCRUB = "NOSCRUB";

private static final String TEST_DIRECTORY_NAME = "RequestStatement";

@Mock
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import org.hl7.fhir.dstu3.model.Encounter;
import org.hl7.fhir.dstu3.model.Observation;
import org.hl7.fhir.dstu3.model.Patient;
import org.hl7.fhir.dstu3.model.QuestionnaireResponse;
import org.hl7.v3.RCMRMT030101UKEhrExtract;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
Expand Down Expand Up @@ -44,7 +43,6 @@ public class TemplateMapperTest {
+ "-QuestionnaireResponse-1";
private static final String OBSERVATION_META = "https://fhir.nhs.uk/STU3/StructureDefinition/CareConnect-GPC-Observation-1";
private static final String IDENTIFIER = "https://PSSAdaptor/TESTPRACTISECODE";
private static final int THREE = 3;
private static final String SNOMED_SYSTEM = "http://snomed.info/sct";
private static final CodeableConcept CODEABLE_CONCEPT = createCodeableConcept(null, SNOMED_SYSTEM, CODING_DISPLAY_MOCK);

Expand All @@ -71,13 +69,10 @@ public void testMapTemplateWithAllData() {
var mappedResources = templateMapper.mapResources(ehrExtract, getPatient(), ENCOUNTER_LIST, PRACTISE_CODE);

assertThat(mappedResources.size()).isEqualTo(1);
// var questionnaireResponse = (QuestionnaireResponse) mappedResources.getFirst();

var parentObservation = (Observation) mappedResources.getFirst();

// assertQuestionnaireResponse(questionnaireResponse, ENCOUNTER_ID, "original-text", "20100113151332");
assertParentObservation(parentObservation, ENCOUNTER_ID, "20100113151332", "3707E1F0-9011-11EC-B1E5-0800200C9A66");

// verify(resourceReferenceUtil, atLeast(1)).extractChildReferencesFromTemplate(any(), anyList());
}

@Test
Expand All @@ -90,14 +85,11 @@ public void testMapTemplateWithFallbackData() {
var mappedResources = templateMapper.mapResources(ehrExtract, getPatient(), ENCOUNTER_LIST, PRACTISE_CODE);

assertThat(mappedResources.size()).isEqualTo(1);
// var questionnaireResponse = (QuestionnaireResponse) mappedResources.getFirst();

var parentObservation = (Observation) mappedResources.getFirst();

// assertQuestionnaireResponse(questionnaireResponse, null, "display-text", "20200101010101");
assertParentObservation(parentObservation, null, null, "9007E1F0-9011-11EC-B1E5-0800200C9A66");

// The assertion below is poor as we manually select 1 item above / removed
// assertThat(questionnaireResponse.getItem().size()).isOne();
}

@Test
Expand All @@ -110,13 +102,11 @@ public void testMapNestedTemplate() {
var mappedResources = templateMapper.mapResources(ehrExtract, getPatient(), ENCOUNTER_LIST, PRACTISE_CODE);

assertThat(mappedResources.size()).isEqualTo(1);
//var questionnaireResponse = (QuestionnaireResponse) mappedResources.getFirst();

var parentObservation = (Observation) mappedResources.getFirst();

//assertQuestionnaireResponse(questionnaireResponse, null, "display-text", "20200101010101");
assertParentObservation(parentObservation, null, null, "9007E1F0-9011-11EC-B1E5-0800200C9A66");

// verify(resourceReferenceUtil, atLeast(1)).extractChildReferencesFromTemplate(any(), anyList());
}

@Test
Expand Down Expand Up @@ -184,26 +174,6 @@ public void When_MapTemplateWithoutSnomedCode_Expect_DegradedCode() {
assertThat(parentObservation.getCode().getCodingFirstRep()).isEqualTo(DegradedCodeableConcepts.DEGRADED_OTHER);
}

private void assertQuestionnaireResponse(QuestionnaireResponse questionnaireResponse, String encounter, String linkId,
String authored) {
assertThat(questionnaireResponse.getId()).isEqualTo(COMPOUND_ID + QUESTIONNAIRE_SUFFIX);
assertThat(questionnaireResponse.getMeta().getProfile().getFirst().getValue()).isEqualTo(QUESTIONNAIRE_META);
assertThat(questionnaireResponse.getIdentifier().getSystem()).isEqualTo(IDENTIFIER);
assertThat(questionnaireResponse.getIdentifier().getValue()).isEqualTo(COMPOUND_ID);
assertThat(questionnaireResponse.getParentFirstRep().getResource().getIdElement().getValue()).isEqualTo(COMPOUND_ID);
assertThat(questionnaireResponse.getStatus()).isEqualTo(QuestionnaireResponse.QuestionnaireResponseStatus.COMPLETED);
assertThat(questionnaireResponse.getSubject().getResource().getIdElement().getValue()).isEqualTo(PATIENT_ID);
assertThat(questionnaireResponse.getItemFirstRep().getLinkId()).isEqualTo(linkId);
assertThat(questionnaireResponse.getAuthoredElement().asStringValue()).isEqualTo(
DateFormatUtil.parseToDateTimeType(authored).asStringValue());

if (encounter == null) {
assertThat(questionnaireResponse.getContext().getResource()).isNull();
} else {
assertThat(questionnaireResponse.getContext().getResource().getIdElement().getValue()).isEqualTo(encounter);
}
}

ole4ryb marked this conversation as resolved.
Show resolved Hide resolved
private void assertParentObservation(Observation parentObservation, String encounter, String issued, String performer) {
assertThat(parentObservation.getId()).isEqualTo(COMPOUND_ID);
assertThat(parentObservation.getMeta().getProfile().getFirst().getValue()).isEqualTo(OBSERVATION_META);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import org.hl7.fhir.dstu3.model.Meta;
import org.hl7.fhir.dstu3.model.Observation;
import org.hl7.fhir.dstu3.model.Patient;
import org.hl7.v3.CV;
import org.hl7.v3.RCMRMT030101UKCompoundStatement;
import org.hl7.v3.RCMRMT030101UKEhrComposition;
import org.hl7.v3.RCMRMT030101UKEhrExtract;
Expand All @@ -42,7 +41,6 @@
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
import uk.nhs.adaptors.pss.translator.util.MetaUtil;
import uk.nhs.adaptors.pss.translator.TestUtility;
import uk.nhs.adaptors.pss.translator.service.ConfidentialityService;
import uk.nhs.adaptors.pss.translator.service.IdGeneratorService;
import uk.nhs.adaptors.pss.translator.util.DateFormatUtil;
Expand All @@ -65,10 +63,6 @@ public class DiagnosticReportMapperTest {
private static final String CONCLUSION_FIELD_TEXT = "TEXT_OF_DIRECT_COMPOUND_STATEMENT_CHILD_NARRATIVE_STATEMENT_1\n"
+ "TEXT_OF_DIRECT_COMPOUND_STATEMENT_CHILD_NARRATIVE_STATEMENT_2";
private static final Meta META = MetaUtil.getMetaFor(META_WITH_SECURITY, DIAGNOSTIC_REPORT_META_SUFFIX);
private static final CV NOPAT_CV = TestUtility.createCv(
"NOPAT",
"http://hl7.org/fhir/v3/ActCode",
"no disclosure to patient, family or caregivers without attending provider's authorization");

private static final String NARRATIVE_STATEMENT_COMMENT_BLOCK = """
CommentType:LABORATORY RESULT COMMENT(E141)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,13 @@
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;

import org.hl7.fhir.dstu3.model.DiagnosticReport;
import org.hl7.fhir.dstu3.model.IdType;
import org.hl7.fhir.dstu3.model.Meta;
import org.hl7.fhir.dstu3.model.Observation;
import org.hl7.fhir.dstu3.model.Patient;
import org.hl7.fhir.dstu3.model.Reference;
import org.hl7.fhir.dstu3.model.ResourceType;
import org.hl7.v3.CV;
import org.hl7.v3.RCMRMT030101UKCompoundStatement;
import org.hl7.v3.RCMRMT030101UKEhrComposition;
import org.hl7.v3.RCMRMT030101UKEhrExtract;
Expand All @@ -44,7 +42,6 @@
import lombok.SneakyThrows;
import org.mockito.stubbing.Answer1;
import uk.nhs.adaptors.pss.translator.util.MetaUtil;
import uk.nhs.adaptors.pss.translator.TestUtility;
import uk.nhs.adaptors.pss.translator.service.ConfidentialityService;

@ExtendWith(MockitoExtension.class)
Expand All @@ -64,10 +61,6 @@ public class SpecimenCompoundsMapperTest {
private static final String TEST_COMMENT_LINE_1 = "Test Comment";
private static final String META_PROFILE = "Observation-1";
private static final Meta META = MetaUtil.getMetaFor(META_WITH_SECURITY, META_PROFILE);
private static final CV NOPAT_CV = TestUtility.createCv(
"NOPAT",
"http://hl7.org/fhir/v3/ActCode",
"no disclosure to patient, family or caregivers without attending provider's authorization");

private static final Patient PATIENT = (Patient) new Patient().setId("TEST_PATIENT_ID");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ public class MedicationMapperUtilsTest {
private static final String EXPECTED_CODE_DISPLAY = "NHS prescription";

private static final String AUTHORISE_ID = "8866381C-E5B8-4A6E-ADBC-964F9A77D407";
private static final String MEDICATION_REQUEST_ID = "a9edfd5e-bd52-461f-8b96-9c5b181af5bf";

@Test
public void When_CreatingPrescriptionTypeExtension_Expect_AcuteValues() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package uk.nhs.adaptors.pss.translator.service;

import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

Expand Down Expand Up @@ -92,7 +91,7 @@ public void When_HandleFailedProcess_With_EhrExtract_Expect_UnexpectedCondition(
String conversationId = UUID.randomUUID().toString();

when(ehrExtractMessage.getId()).thenReturn(mockId);
when(nackAckPreparationService.prepareNackMessageData(eq(UNEXPECTED_CONDITION), eq(ehrExtractMessage), eq(conversationId)))
when(nackAckPreparationService.prepareNackMessageData(UNEXPECTED_CONDITION, ehrExtractMessage, conversationId))
.thenReturn(messageData);

failedProcessHandlingService.handleFailedProcess(ehrExtractMessage, conversationId);
Expand Down Expand Up @@ -123,7 +122,7 @@ public void When_HandleFailedProcess_With_COPCAndIncumbentNackdProcess_Expect_Un
when(migrationStatusLogService.getLatestMigrationStatusLog(conversationId))
.thenReturn(statusLog);

when(nackAckPreparationService.prepareNackMessageData(eq(UNEXPECTED_CONDITION), eq(copcMessage), eq(conversationId)))
when(nackAckPreparationService.prepareNackMessageData(UNEXPECTED_CONDITION, copcMessage, conversationId))
.thenReturn(messageData);

failedProcessHandlingService.handleFailedProcess(copcMessage, conversationId);
Expand All @@ -142,7 +141,7 @@ public void When_HandleFailedProcess_With_COPCAndLargeMessageTimeout_Expect_Larg
when(migrationStatusLogService.getLatestMigrationStatusLog(conversationId))
.thenReturn(statusLog);

when(nackAckPreparationService.prepareNackMessageData(eq(LARGE_MESSAGE_TIMEOUT), eq(copcMessage), eq(conversationId)))
when(nackAckPreparationService.prepareNackMessageData(LARGE_MESSAGE_TIMEOUT, copcMessage, conversationId))
.thenReturn(messageData);

failedProcessHandlingService.handleFailedProcess(copcMessage, conversationId);
Expand All @@ -161,7 +160,7 @@ public void When_HandleFailedProcess_With_COPCAndRequestTimeout_Expect_LargeMess
when(migrationStatusLogService.getLatestMigrationStatusLog(conversationId))
.thenReturn(statusLog);

when(nackAckPreparationService.prepareNackMessageData(eq(LARGE_MESSAGE_TIMEOUT), eq(copcMessage), eq(conversationId)))
when(nackAckPreparationService.prepareNackMessageData(LARGE_MESSAGE_TIMEOUT, copcMessage, conversationId))
.thenReturn(messageData);

failedProcessHandlingService.handleFailedProcess(copcMessage, conversationId);
Expand Down Expand Up @@ -206,7 +205,7 @@ public void When_HandleFailedProcess_With_OtherStatus_Expect_LargeMessageGeneral
when(migrationStatusLogService.getLatestMigrationStatusLog(conversationId))
.thenReturn(statusLog);

when(nackAckPreparationService.prepareNackMessageData(eq(LARGE_MESSAGE_GENERAL_FAILURE), eq(copcMessage), eq(conversationId)))
when(nackAckPreparationService.prepareNackMessageData(LARGE_MESSAGE_GENERAL_FAILURE, copcMessage, conversationId))
.thenReturn(messageData);

failedProcessHandlingService.handleFailedProcess(copcMessage, conversationId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ public void When_HappyPathNoSkeleton_Expect_NotToGetAttachmentFromService() thro

@Test
public void When_UpdateInboundMessageWithSkeletonThrowsSAXException_Expect_SendNack() throws JAXBException,
JsonProcessingException, SAXException, TransformerException, AttachmentNotFoundException, InlineAttachmentProcessingException {
JsonProcessingException, SAXException, TransformerException, InlineAttachmentProcessingException {

var inboundMessage = new InboundMessage();
var attachments = createPatientAttachmentList(true, true);
Expand Down Expand Up @@ -301,7 +301,7 @@ public void When_MergeAndBundleMessageThrowsAttachmentNotFoundException_Expect_S
@Test
public void When_UpdateInboundMessageWithSkeletonThrowsTransformerException_Expect_SendNack()
throws JAXBException, JsonProcessingException,
SAXException, TransformerException, AttachmentNotFoundException, InlineAttachmentProcessingException {
SAXException, TransformerException, InlineAttachmentProcessingException {

var inboundMessage = new InboundMessage();

Expand Down Expand Up @@ -448,8 +448,8 @@ public void When_MergeAndBundleMessageHasNullOrEmptyParams_Expect_ThrowIllegalSt

@Test
public void When_AttachmentsPresent_Expect_AttachmentReferenceUpdated()
throws AttachmentNotFoundException, JAXBException, InlineAttachmentProcessingException, JsonProcessingException,
TransformerException, SAXException {
throws AttachmentNotFoundException, JAXBException, InlineAttachmentProcessingException, JsonProcessingException {

var inboundMessage = new InboundMessage();
var attachments = createPatientAttachmentList(true, false);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import java.util.Arrays;
import java.util.List;

import jakarta.xml.bind.JAXBException;
import javax.xml.transform.TransformerException;

import org.junit.jupiter.api.Test;
Expand All @@ -27,8 +26,6 @@
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;

import lombok.SneakyThrows;
Expand Down Expand Up @@ -107,16 +104,15 @@ private void prepareSkeletonNonRCMRMocks(InboundMessage inboundMessage) throws S
when(node.getParentNode()).thenReturn(node);
}

private void prepareSkeletonRCMRMocks(InboundMessage inboundMessage) throws SAXException, TransformerException {
private void prepareSkeletonRCMRMocks(InboundMessage inboundMessage) throws TransformerException {

var fileAsBytes = readInboundMessagePayloadFromFile().getBytes(StandardCharsets.UTF_8);
when(xmlParseUtilService.getStringFromDocument(any())).thenReturn(inboundMessage.getPayload());
when(attachmentHandlerService.getAttachment(any(), any())).thenReturn(fileAsBytes);
}

@Test
public void When_UpdateInboundMessageAttachmentHandlerServiceThrowsIllegalArgumentException_Expect_ThrowsException()
throws JAXBException, JsonProcessingException, TransformerException, SAXException {
public void When_UpdateInboundMessageAttachmentHandlerServiceThrowsIllegalArgumentException_Expect_ThrowsException() {

var inboundMessage = new InboundMessage();
var attachmentLog = createSkeletonPatientAttachmentLog();
Expand Down Expand Up @@ -147,7 +143,7 @@ public void When_HappyPathWithSkeletonAsRCMRMessage_Expect_ThrowNoErrors() throw

@Test
public void When_HappyPathWithSkeletonAsRCMRMessage_Expect_InboundMessagePayloadIsNewRCMRMessage()
throws JAXBException, JsonProcessingException, TransformerException, SAXException {
throws TransformerException, SAXException {
var inboundMessage = new InboundMessage();
var attachmentLog = createSkeletonPatientAttachmentLog();

Expand All @@ -164,7 +160,7 @@ public void When_HappyPathWithSkeletonAsRCMRMessage_Expect_InboundMessagePayload

@Test
public void When_HappyPathWithSkeletonAsSectionMessage_Expect_ThrowNoErrors()
throws JAXBException, JsonProcessingException, TransformerException, SAXException {
throws TransformerException, SAXException {
var inboundMessage = new InboundMessage();
var attachmentLog = createSkeletonPatientAttachmentLog();

Expand All @@ -177,8 +173,7 @@ public void When_HappyPathWithSkeletonAsSectionMessage_Expect_ThrowNoErrors()
}

@Test
public void When_SkeletonAsSectionMessage_Expect_ThrowNoErrors() throws JAXBException, JsonProcessingException, TransformerException,
SAXException {
public void When_SkeletonAsSectionMessage_Expect_ThrowNoErrors() throws TransformerException, SAXException {
var inboundMessage = new InboundMessage();
var attachmentLog = createSkeletonPatientAttachmentLog();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1011,8 +1011,7 @@ public void When_HandleMessage_WithWebClientRequestException_Expect_ExceptionThr

@Test
public void When_HandleMessage_WithMhsServerErrorException_Expect_ExceptionIsBubbledUpSoMessageIsRetriedByJMS()
throws SAXException, AttachmentNotFoundException, JAXBException, BundleMappingException, JsonProcessingException,
InlineAttachmentProcessingException, AttachmentLogException {
throws SAXException, InlineAttachmentProcessingException {

MockedStatic<XmlUnmarshallUtil> mockedXmlUnmarshall = Mockito.mockStatic(XmlUnmarshallUtil.class);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,7 @@ public void When_HandleSingleMessageWithAFilenameDescription_Expect_PatientAttac
public void When_HandleLargeMessageWithValidDataIsCalled_Expect_ItShouldNotTranslate()
throws JAXBException, BundleMappingException, AttachmentNotFoundException,
ParseException, JsonProcessingException, InlineAttachmentProcessingException,
SAXException, TransformerException, InstantiationException, IllegalAccessException {
SAXException, TransformerException {

Bundle bundle = new Bundle();
bundle.setId("Test");
Expand Down
Loading