Skip to content

Commit 9d53152

Browse files
removed
1 parent caa8f7b commit 9d53152

File tree

1 file changed

+88
-27
lines changed

1 file changed

+88
-27
lines changed

service/src/test/java/uk/nhs/adaptors/gp2gp/ehr/mapper/diagnosticreport/DiagnosticReportMapperTest.java

Lines changed: 88 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import static org.assertj.core.api.AssertionsForClassTypes.assertThatThrownBy;
55
import static org.junit.Assert.assertFalse;
66
import static org.junit.jupiter.api.Assertions.assertAll;
7-
import static org.mockito.ArgumentMatchers.any;
7+
import static org.mockito.ArgumentMatchers.*;
88
import static org.mockito.Mockito.when;
99
import java.util.ArrayList;
1010
import java.util.Collections;
@@ -31,8 +31,6 @@
3131
import org.junit.jupiter.params.provider.MethodSource;
3232
import org.mockito.Mock;
3333
import org.mockito.junit.jupiter.MockitoExtension;
34-
import org.mockito.junit.jupiter.MockitoSettings;
35-
import org.mockito.quality.Strictness;
3634
import org.mockito.stubbing.Answer;
3735

3836
import uk.nhs.adaptors.gp2gp.ehr.mapper.AgentDirectory;
@@ -49,14 +47,12 @@
4947
import uk.nhs.adaptors.gp2gp.utils.FileParsingUtility;
5048
import uk.nhs.adaptors.gp2gp.utils.ResourceTestFileUtils;
5149

52-
import static org.mockito.ArgumentMatchers.anyList;
5350
import static uk.nhs.adaptors.gp2gp.utils.ConfidentialityCodeUtility.NOPAT_HL7_CONFIDENTIALITY_CODE;
5451
import static uk.nhs.adaptors.gp2gp.utils.ConfidentialityCodeUtility.getNopatConfidentialityCodeXpathSegment;
5552
import static uk.nhs.adaptors.gp2gp.utils.XmlAssertion.assertThatXml;
5653
import static uk.nhs.adaptors.gp2gp.utils.XmlParsingUtility.getXmlStringFromFile;
5754

5855
@ExtendWith(MockitoExtension.class)
59-
@MockitoSettings(strictness = Strictness.LENIENT)
6056
class DiagnosticReportMapperTest {
6157

6258
private static final String TEST_FILE_DIRECTORY = "/ehr/mapper/diagnosticreport/";
@@ -113,19 +109,6 @@ class DiagnosticReportMapperTest {
113109

114110
@BeforeEach
115111
public void setUp() {
116-
final Bundle bundle = getBundleResourceFromJson(INPUT_JSON_BUNDLE);
117-
118-
when(messageContext.getIdMapper()).thenReturn(idMapper);
119-
when(messageContext.getInputBundleHolder()).thenReturn(new InputBundle(bundle));
120-
when(messageContext.getAgentDirectory()).thenReturn(agentDirectory);
121-
when(idMapper.getOrNew(any(ResourceType.class), any(IdType.class))).thenAnswer(mockIdForResourceAndId());
122-
when(agentDirectory.getAgentId(any(Reference.class))).thenAnswer(mockIdForReference());
123-
when(randomIdGeneratorService.createNewId()).thenReturn(TEST_ID);
124-
when(specimenMapper.mapSpecimenToCompoundStatement(any(Specimen.class), anyList(), any(DiagnosticReport.class)))
125-
.thenAnswer(mockSpecimenMapping());
126-
when(codeableConceptCdMapper.mapCodeableConceptToCd(any(CodeableConcept.class)))
127-
.thenReturn(CodeableConceptMapperMockUtil.NULL_FLAVOR_CODE);
128-
129112
mapper = new DiagnosticReportMapper(
130113
messageContext, specimenMapper, new ParticipantMapper(), randomIdGeneratorService, confidentialityService);
131114
}
@@ -207,9 +190,37 @@ void shouldAssignDummySpecimenToObservationsWithoutSpecimen() {
207190
@ParameterizedTest
208191
@MethodSource("resourceFileParams")
209192
void When_MappingDiagnosticReportJson_Expect_CompoundStatementXmlOutput(String inputJson, String outputXml) {
193+
final Bundle bundle = getBundleResourceFromJson(INPUT_JSON_BUNDLE);
194+
195+
when(messageContext.getIdMapper()).thenReturn(idMapper);
196+
when(messageContext.getInputBundleHolder()).thenReturn(new InputBundle(bundle));
197+
when(randomIdGeneratorService.createNewId()).thenReturn(TEST_ID);
198+
when(specimenMapper.mapSpecimenToCompoundStatement(any(Specimen.class), anyList(), any(DiagnosticReport.class)))
199+
.thenAnswer(mockSpecimenMapping());
200+
when(idMapper.getOrNew(any(ResourceType.class), any(IdType.class))).thenAnswer(mockIdForResourceAndId());
201+
210202
final CharSequence expectedOutputMessage = ResourceTestFileUtils.getFileContent(TEST_FILE_DIRECTORY + outputXml);
211203
final DiagnosticReport diagnosticReport = getDiagnosticReportResourceFromJson(inputJson);
204+
final String outputMessage = mapper.mapDiagnosticReportToCompoundStatement(diagnosticReport);
212205

206+
assertThat(outputMessage).isEqualToIgnoringWhitespace(expectedOutputMessage.toString());
207+
}
208+
209+
@Test
210+
void When_MappingDiagnosticReportJson_Expect_CompoundStatementWithParticipantXmlOutput() {
211+
final Bundle bundle = getBundleResourceFromJson(INPUT_JSON_BUNDLE);
212+
213+
when(messageContext.getIdMapper()).thenReturn(idMapper);
214+
when(messageContext.getInputBundleHolder()).thenReturn(new InputBundle(bundle));
215+
when(randomIdGeneratorService.createNewId()).thenReturn(TEST_ID);
216+
when(specimenMapper.mapSpecimenToCompoundStatement(any(Specimen.class), anyList(), any(DiagnosticReport.class)))
217+
.thenAnswer(mockSpecimenMapping());
218+
when(idMapper.getOrNew(any(ResourceType.class), any(IdType.class))).thenAnswer(mockIdForResourceAndId());
219+
when(messageContext.getAgentDirectory()).thenReturn(agentDirectory);
220+
when(agentDirectory.getAgentId(any())).thenReturn("II-for-Organization/5E496953-065B-41F2-9577-BE8F2FBD0757");
221+
222+
final CharSequence expectedOutputMessage = ResourceTestFileUtils.getFileContent(TEST_FILE_DIRECTORY + OUTPUT_XML_PARTICIPANT);
223+
final DiagnosticReport diagnosticReport = getDiagnosticReportResourceFromJson(INPUT_JSON_PERFORMER);
213224
final String outputMessage = mapper.mapDiagnosticReportToCompoundStatement(diagnosticReport);
214225

215226
assertThat(outputMessage).isEqualToIgnoringWhitespace(expectedOutputMessage.toString());
@@ -222,6 +233,13 @@ void When_DiagnosticReport_With_BlankFilingComment_Expect_NoNarrativeStatementPr
222233
final Bundle bundle = getBundleResourceFromJson(INPUT_JSON_BUNDLE_WITH_FILING_COMMENTS);
223234
final InputBundle inputBundle = new InputBundle(bundle);
224235

236+
when(messageContext.getIdMapper()).thenReturn(idMapper);
237+
when(messageContext.getInputBundleHolder()).thenReturn(new InputBundle(bundle));
238+
when(specimenMapper.mapSpecimenToCompoundStatement(any(Specimen.class), anyList(), any(DiagnosticReport.class)))
239+
.thenAnswer(mockSpecimenMapping());
240+
when(confidentialityService.generateConfidentialityCode(diagnosticReport))
241+
.thenReturn(Optional.of(NOPAT_HL7_CONFIDENTIALITY_CODE));
242+
225243
when(messageContext.getInputBundleHolder()).thenReturn(inputBundle);
226244

227245
diagnosticReport.setStatus(null);
@@ -236,7 +254,12 @@ void When_DiagnosticReport_With_BlankFilingComment_Expect_NoNarrativeStatementPr
236254
void When_DiagnosticReport_With_NopatMetaSecurity_Expect_ConfidentialityCodeWithinCompoundStatement() {
237255
final String testFile = "diagnostic-report-with-multi-specimens-nopat.json";
238256
final DiagnosticReport diagnosticReport = getDiagnosticReportResourceFromJson(testFile);
257+
final Bundle bundle = getBundleResourceFromJson(INPUT_JSON_BUNDLE);
239258

259+
when(messageContext.getIdMapper()).thenReturn(idMapper);
260+
when(messageContext.getInputBundleHolder()).thenReturn(new InputBundle(bundle));
261+
when(specimenMapper.mapSpecimenToCompoundStatement(any(Specimen.class), anyList(), any(DiagnosticReport.class)))
262+
.thenAnswer(mockSpecimenMapping());
240263
when(confidentialityService.generateConfidentialityCode(diagnosticReport))
241264
.thenReturn(Optional.of(NOPAT_HL7_CONFIDENTIALITY_CODE));
242265

@@ -252,6 +275,14 @@ void When_DiagnosticReport_With_NopatMetaSecurity_Expect_ConfidentialityCodeWith
252275
void When_DiagnosticReport_With_NoscrubMetaSecurity_Expect_ConfidentialityCodeNotWithinCompoundStatement() {
253276
final String testFile = "diagnostic-report-with-multi-specimens-noscrub.json";
254277
final DiagnosticReport diagnosticReport = getDiagnosticReportResourceFromJson(testFile);
278+
final Bundle bundle = getBundleResourceFromJson(INPUT_JSON_BUNDLE);
279+
280+
when(messageContext.getIdMapper()).thenReturn(idMapper);
281+
when(messageContext.getInputBundleHolder()).thenReturn(new InputBundle(bundle));
282+
when(specimenMapper.mapSpecimenToCompoundStatement(any(Specimen.class), anyList(), any(DiagnosticReport.class)))
283+
.thenAnswer(mockSpecimenMapping());
284+
when(confidentialityService.generateConfidentialityCode(diagnosticReport))
285+
.thenReturn(Optional.of(NOPAT_HL7_CONFIDENTIALITY_CODE));
255286

256287
when(confidentialityService.generateConfidentialityCode(diagnosticReport)).thenReturn(Optional.empty());
257288

@@ -270,6 +301,7 @@ void When_DiagnosticReport_With_RedactedFilingComment_Expect_ConfidentialityCode
270301
final DiagnosticReport diagnosticReport = getDiagnosticReportResourceFromJson(diagnosticReportFileName);
271302
final InputBundle inputBundle = new InputBundle(bundle);
272303

304+
when(messageContext.getIdMapper()).thenReturn(idMapper);
273305
when(confidentialityService.generateConfidentialityCode(bundle.getEntry().getFirst().getResource()))
274306
.thenReturn(Optional.of(NOPAT_HL7_CONFIDENTIALITY_CODE));
275307
when(messageContext.getInputBundleHolder()).thenReturn(inputBundle);
@@ -293,6 +325,7 @@ void When_DiagnosticReport_With_ObservationEffectiveDateTimeTypeAndCommentNote_E
293325
"/component/CompoundStatement/component[1]/NarrativeStatement/" + getNopatConfidentialityCodeXpathSegment()
294326
);
295327

328+
when(messageContext.getIdMapper()).thenReturn(idMapper);
296329
when(confidentialityService.generateConfidentialityCode(observation)).thenReturn(Optional.of(NOPAT_HL7_CONFIDENTIALITY_CODE));
297330
when(messageContext.getInputBundleHolder()).thenReturn(inputBundle);
298331

@@ -315,6 +348,7 @@ void When_DiagnosticReport_With_ObservationEffectivePeriodAndCommentNote_Expect_
315348
"/component/CompoundStatement/component[1]/NarrativeStatement/" + getNopatConfidentialityCodeXpathSegment()
316349
);
317350

351+
when(messageContext.getIdMapper()).thenReturn(idMapper);
318352
when(confidentialityService.generateConfidentialityCode(observation)).thenReturn(Optional.of(NOPAT_HL7_CONFIDENTIALITY_CODE));
319353
when(messageContext.getInputBundleHolder()).thenReturn(inputBundle);
320354

@@ -335,13 +369,14 @@ void When_DR_With_NoReferencedSpecimenAndFilingCommentWithNoComment_Expect_Match
335369
final List<String> expectedXPaths = Collections.singletonList(
336370
"/component/CompoundStatement/component/CompoundStatement/specimen/specimenRole/id[@extension=\"NOT PRESENT\"]");
337371

338-
when(specimenMapper.mapSpecimenToCompoundStatement(
339-
any(Specimen.class),
340-
anyList(),
341-
any(DiagnosticReport.class)
342-
)).thenCallRealMethod();
343-
372+
when(messageContext.getIdMapper()).thenReturn(idMapper);
344373
when(messageContext.getInputBundleHolder()).thenReturn(inputBundle);
374+
when(messageContext.getAgentDirectory()).thenReturn(agentDirectory);
375+
when(idMapper.getOrNew(any(ResourceType.class), any(IdType.class))).thenAnswer(mockIdForResourceAndId());
376+
when(agentDirectory.getAgentId(any(Reference.class))).thenAnswer(mockIdForReference());
377+
when(randomIdGeneratorService.createNewId()).thenReturn(TEST_ID);
378+
when(codeableConceptCdMapper.mapCodeableConceptToCd(any(CodeableConcept.class)))
379+
.thenReturn(CodeableConceptMapperMockUtil.NULL_FLAVOR_CODE);
345380

346381
mapper = new DiagnosticReportMapper(
347382
messageContext,
@@ -380,6 +415,13 @@ void When_DiagnosticReport_Has_SpecimenAndUnlinkedTestResult_Expect_ADummySpecim
380415
final Bundle bundle = getBundleResourceFromJson(INPUT_JSON_BUNDLE);
381416
final InputBundle inputBundle = new InputBundle(bundle);
382417

418+
when(messageContext.getIdMapper()).thenReturn(idMapper);
419+
when(messageContext.getInputBundleHolder()).thenReturn(new InputBundle(bundle));
420+
when(idMapper.getOrNew(any(ResourceType.class), any(IdType.class))).thenAnswer(mockIdForResourceAndId());
421+
when(randomIdGeneratorService.createNewId()).thenReturn(TEST_ID);
422+
when(specimenMapper.mapSpecimenToCompoundStatement(any(Specimen.class), anyList(), any(DiagnosticReport.class)))
423+
.thenAnswer(mockSpecimenMapping());
424+
383425
when(messageContext.getInputBundleHolder()).thenReturn(inputBundle);
384426

385427
final String actualXml = mapper.mapDiagnosticReportToCompoundStatement(diagnosticReport);
@@ -401,7 +443,11 @@ void When_DiagnosticReport_Has_MultipleSpecimensAndOneObservation_Expect_ADummyO
401443
final Bundle bundle = getBundleResourceFromJson(INPUT_JSON_BUNDLE);
402444
final InputBundle inputBundle = new InputBundle(bundle);
403445

446+
when(messageContext.getIdMapper()).thenReturn(idMapper);
404447
when(messageContext.getInputBundleHolder()).thenReturn(inputBundle);
448+
when(randomIdGeneratorService.createNewId()).thenReturn(TEST_ID);
449+
when(specimenMapper.mapSpecimenToCompoundStatement(any(Specimen.class), anyList(), any(DiagnosticReport.class)))
450+
.thenAnswer(mockSpecimenMapping());
405451

406452
final String actualXml = mapper.mapDiagnosticReportToCompoundStatement(diagnosticReport);
407453

@@ -427,7 +473,11 @@ void When_DiagnosticReport_Has_ThreeSpecimensAndOneObservation_Expect_DummyObser
427473
final Bundle bundle = getBundleResourceFromJson(INPUT_JSON_BUNDLE);
428474
final InputBundle inputBundle = new InputBundle(bundle);
429475

476+
when(messageContext.getIdMapper()).thenReturn(idMapper);
430477
when(messageContext.getInputBundleHolder()).thenReturn(inputBundle);
478+
when(randomIdGeneratorService.createNewId()).thenReturn(TEST_ID);
479+
when(specimenMapper.mapSpecimenToCompoundStatement(any(Specimen.class), anyList(), any(DiagnosticReport.class)))
480+
.thenAnswer(mockSpecimenMapping());
431481

432482
final String actualXml = mapper.mapDiagnosticReportToCompoundStatement(diagnosticReport);
433483

@@ -457,7 +507,12 @@ void When_DiagnosticReport_Has_TwoLinkedSpecimensOneUnlinkedSpecimenAndOneObserv
457507
final Bundle bundle = getBundleResourceFromJson(INPUT_JSON_BUNDLE);
458508
final InputBundle inputBundle = new InputBundle(bundle);
459509

510+
when(messageContext.getIdMapper()).thenReturn(idMapper);
460511
when(messageContext.getInputBundleHolder()).thenReturn(inputBundle);
512+
when(randomIdGeneratorService.createNewId()).thenReturn(TEST_ID);
513+
when(specimenMapper.mapSpecimenToCompoundStatement(any(Specimen.class), anyList(), any(DiagnosticReport.class)))
514+
.thenAnswer(mockSpecimenMapping());
515+
461516

462517
final String actualXml = mapper.mapDiagnosticReportToCompoundStatement(diagnosticReport);
463518

@@ -477,11 +532,18 @@ void When_DiagnosticReport_Has_TwoLinkedSpecimensOneUnlinkedSpecimenAndOneObserv
477532

478533
@Test
479534
void When_DiagnosticReport_Has_SpecimenALinkedTestResultAndAnUnlinkedTestResult_Expect_ASpecimenOnAllTestResults() {
535+
final Bundle bundle = getBundleResourceFromJson(INPUT_JSON_BUNDLE);
536+
final InputBundle inputBundle = new InputBundle(bundle);
537+
538+
when(messageContext.getIdMapper()).thenReturn(idMapper);
539+
when(messageContext.getInputBundleHolder()).thenReturn(inputBundle);
540+
when(randomIdGeneratorService.createNewId()).thenReturn(TEST_ID);
541+
when(specimenMapper.mapSpecimenToCompoundStatement(any(Specimen.class), anyList(), any(DiagnosticReport.class)))
542+
.thenAnswer(mockSpecimenMapping());
543+
480544
final String diagnosticReportFileName =
481545
"diagnostic-report-with-one-specimen-one-linked-observation-and-one-unlinked-observation.json";
482546
final DiagnosticReport diagnosticReport = getDiagnosticReportResourceFromJson(diagnosticReportFileName);
483-
final Bundle bundle = getBundleResourceFromJson(INPUT_JSON_BUNDLE);
484-
final InputBundle inputBundle = new InputBundle(bundle);
485547
when(messageContext.getInputBundleHolder()).thenReturn(inputBundle);
486548

487549
final String actualXml = mapper.mapDiagnosticReportToCompoundStatement(diagnosticReport);
@@ -511,7 +573,6 @@ private static Stream<Arguments> resourceFileParams() {
511573
Arguments.of(INPUT_JSON_ONE_RESULT, OUTPUT_XML_REQUIRED_DATA),
512574
Arguments.of(INPUT_JSON_MULTI_SPECIMENS, OUTPUT_XML_MULTI_SPECIMENS),
513575
Arguments.of(INPUT_JSON_MULTI_RESULTS, OUTPUT_XML_MULTIPLE_RESULTS),
514-
Arguments.of(INPUT_JSON_PERFORMER, OUTPUT_XML_PARTICIPANT),
515576
Arguments.of(INPUT_JSON_PERFORMER_NO_ACTOR, OUTPUT_XML_STATUS_NARRATIVE),
516577
Arguments.of(INPUT_JSON_CONCLUSION, OUTPUT_XML_CONCLUSION),
517578
Arguments.of(INPUT_JSON_CODED_DIAGNOSIS, OUTPUT_XML_CODED_DIAGNOSIS),

0 commit comments

Comments
 (0)