Skip to content

Commit 4ac12ee

Browse files
split test
1 parent 8f90912 commit 4ac12ee

File tree

1 file changed

+103
-81
lines changed

1 file changed

+103
-81
lines changed

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

Lines changed: 103 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
package uk.nhs.adaptors.gp2gp.ehr.mapper;
2-
3-
import org.hl7.fhir.dstu3.model.*;
2+
import org.hl7.fhir.dstu3.model.Bundle;
3+
import org.hl7.fhir.dstu3.model.Encounter;
4+
import org.hl7.fhir.dstu3.model.Observation;
5+
import org.hl7.fhir.dstu3.model.CodeableConcept;
6+
import org.hl7.fhir.dstu3.model.ResourceType;
47
import org.junit.jupiter.api.AfterEach;
58
import org.junit.jupiter.api.BeforeEach;
69
import org.junit.jupiter.api.Test;
@@ -10,8 +13,6 @@
1013
import org.junit.jupiter.params.provider.MethodSource;
1114
import org.mockito.Mock;
1215
import org.mockito.junit.jupiter.MockitoExtension;
13-
import org.mockito.junit.jupiter.MockitoSettings;
14-
import org.mockito.quality.Strictness;
1516
import uk.nhs.adaptors.gp2gp.common.configuration.RedactionsContext;
1617
import uk.nhs.adaptors.gp2gp.common.service.ConfidentialityService;
1718
import uk.nhs.adaptors.gp2gp.common.service.FhirParseService;
@@ -33,7 +34,6 @@
3334
import static org.assertj.core.api.Assertions.assertThat;
3435
import static org.mockito.ArgumentMatchers.any;
3536
import static org.mockito.ArgumentMatchers.anyString;
36-
import static org.mockito.Mockito.lenient;
3737
import static org.mockito.Mockito.when;
3838

3939
@ExtendWith(MockitoExtension.class)
@@ -201,51 +201,6 @@ private void setupTimestampMock() {
201201
when(timestampService.now()).thenReturn(Instant.parse(TEST_DATE_TIME));
202202
}
203203

204-
private void setupCodeableConceptMocks() {
205-
when(codeableConceptCdMapper.mapCodeableConceptToCd(any(CodeableConcept.class)))
206-
.thenReturn(CodeableConceptMapperMockUtil.NULL_FLAVOR_CODE);
207-
208-
when(codeableConceptCdMapper.mapCodeableConceptForMedication(any(CodeableConcept.class)))
209-
.thenReturn(CodeableConceptMapperMockUtil.NULL_FLAVOR_CODE);
210-
211-
when(codeableConceptCdMapper.mapCodeableConceptToCdForTransformedActualProblemHeader(any(CodeableConcept.class)))
212-
.thenReturn(CodeableConceptMapperMockUtil.ACTUAL_PROBLEM_CODE);
213-
214-
when(codeableConceptCdMapper.mapToNullFlavorCodeableConcept(any(CodeableConcept.class)))
215-
.thenReturn(CodeableConceptMapperMockUtil.NULL_FLAVOR_CODE);
216-
217-
when(codeableConceptCdMapper.mapCodeableConceptToCdForAllergy(any(CodeableConcept.class), any()))
218-
.thenReturn(CodeableConceptMapperMockUtil.NULL_FLAVOR_CODE);
219-
220-
when(codeableConceptCdMapper.mapToNullFlavorCodeableConceptForAllergy(any(CodeableConcept.class), any()))
221-
.thenReturn(CodeableConceptMapperMockUtil.NULL_FLAVOR_CODE);
222-
223-
when(codeableConceptCdMapper.getDisplayFromCodeableConcept(any(CodeableConcept.class)))
224-
.thenCallRealMethod();
225-
226-
when(codeableConceptCdMapper.mapCodeableConceptToCdForBloodPressure(any(CodeableConcept.class)))
227-
.thenReturn(CodeableConceptMapperMockUtil.NULL_FLAVOR_CODE);
228-
229-
when(codeableConceptCdMapper.mapToCdForTopic(any(CodeableConcept.class)))
230-
.thenReturn(CodeableConceptMapperMockUtil.NULL_FLAVOR_CODE);
231-
232-
when(codeableConceptCdMapper.mapToCdForTopic(any(CodeableConcept.class), any(String.class)))
233-
.thenReturn(CodeableConceptMapperMockUtil.NULL_FLAVOR_CODE);
234-
235-
when(codeableConceptCdMapper.mapToCdForTopic(any(String.class)))
236-
.thenReturn(CodeableConceptMapperMockUtil.NULL_FLAVOR_CODE);
237-
238-
when(codeableConceptCdMapper.getCdForTopic())
239-
.thenReturn(CodeableConceptMapperMockUtil.NULL_FLAVOR_CODE);
240-
241-
when(codeableConceptCdMapper.mapToCdForCategory(any(String.class)))
242-
.thenReturn(CodeableConceptMapperMockUtil.NULL_FLAVOR_CODE);
243-
244-
when(codeableConceptCdMapper.getCdForCategory())
245-
.thenReturn(CodeableConceptMapperMockUtil.NULL_FLAVOR_CODE);
246-
}
247-
248-
249204
@AfterEach
250205
public void tearDown() {
251206
messageContext.resetMessageContext();
@@ -255,34 +210,24 @@ public void tearDown() {
255210
void When_MappingUncategorizedObservationWithNOPAT_Expect_ObservationStatementWithConfidentialityCode() {
256211
when(codeableConceptCdMapper.mapCodeableConceptToCd(any(CodeableConcept.class)))
257212
.thenReturn(CodeableConceptMapperMockUtil.NULL_FLAVOR_CODE);
258-
259213
when(codeableConceptCdMapper.mapCodeableConceptForMedication(any(CodeableConcept.class)))
260214
.thenReturn(CodeableConceptMapperMockUtil.NULL_FLAVOR_CODE);
261-
262215
when(codeableConceptCdMapper.mapCodeableConceptToCdForTransformedActualProblemHeader(any(CodeableConcept.class)))
263216
.thenReturn(CodeableConceptMapperMockUtil.ACTUAL_PROBLEM_CODE);
264-
265217
when(codeableConceptCdMapper.mapCodeableConceptToCdForAllergy(any(CodeableConcept.class), any()))
266218
.thenReturn(CodeableConceptMapperMockUtil.NULL_FLAVOR_CODE);
267-
268219
when(codeableConceptCdMapper.getDisplayFromCodeableConcept(any(CodeableConcept.class)))
269220
.thenCallRealMethod();
270-
271221
when(codeableConceptCdMapper.mapCodeableConceptToCdForBloodPressure(any(CodeableConcept.class)))
272222
.thenReturn(CodeableConceptMapperMockUtil.NULL_FLAVOR_CODE);
273-
274223
when(codeableConceptCdMapper.mapToCdForTopic(any(CodeableConcept.class), any(String.class)))
275224
.thenReturn(CodeableConceptMapperMockUtil.NULL_FLAVOR_CODE);
276-
277225
when(codeableConceptCdMapper.getCdForTopic())
278226
.thenReturn(CodeableConceptMapperMockUtil.NULL_FLAVOR_CODE);
279-
280227
when(codeableConceptCdMapper.mapToCdForCategory(any(String.class)))
281228
.thenReturn(CodeableConceptMapperMockUtil.NULL_FLAVOR_CODE);
282-
283229
when(codeableConceptCdMapper.getCdForCategory())
284230
.thenReturn(CodeableConceptMapperMockUtil.NULL_FLAVOR_CODE);
285-
286231
when(confidentialityService.generateConfidentialityCode(any(Encounter.class)))
287232
.thenReturn(Optional.empty());
288233

@@ -292,6 +237,7 @@ void When_MappingUncategorizedObservationWithNOPAT_Expect_ObservationStatementWi
292237
String expectedJsonToXmlContent = ResourceTestFileUtils.getFileContent(OUTPUT_PATH + EXPECTED_XML_TO_JSON_FILE_WITH_NOPAT);
293238
String inputJsonFileContent = ResourceTestFileUtils.getFileContent(INPUT_PATH + JSON_INPUT_FILE_WITH_NOPAT);
294239
Bundle bundle = new FhirParseService().parseResource(inputJsonFileContent, Bundle.class);
240+
messageContext.initialize(bundle);
295241

296242
Observation uncategorizedObservation = bundle.getEntry().stream()
297243
.map(Bundle.BundleEntryComponent::getResource)
@@ -303,14 +249,11 @@ void When_MappingUncategorizedObservationWithNOPAT_Expect_ObservationStatementWi
303249

304250
when(confidentialityService.generateConfidentialityCode(any(Observation.class)))
305251
.thenReturn(Optional.empty());
306-
307252
when(confidentialityService.generateConfidentialityCode(any(org.hl7.fhir.dstu3.model.ListResource.class)))
308253
.thenReturn(Optional.empty());
309-
310254
when(confidentialityService.generateConfidentialityCode(uncategorizedObservation))
311255
.thenReturn(Optional.of(CONFIDENTIALITY_CODE));
312256

313-
messageContext.initialize(bundle);
314257

315258
EhrExtractTemplateParameters ehrExtractTemplateParameters = ehrExtractMapper.mapBundleToEhrFhirExtractParams(
316259
getGpcStructuredTaskDefinition,
@@ -321,6 +264,65 @@ void When_MappingUncategorizedObservationWithNOPAT_Expect_ObservationStatementWi
321264
assertThat(output).isEqualToIgnoringWhitespace(expectedJsonToXmlContent);
322265
}
323266

267+
@Test
268+
void When_MappingProperJsonRequestBody_Expect_XmlWithoutEffectiveTime() {
269+
String expectedJsonToXmlContent = ResourceTestFileUtils.getFileContent(OUTPUT_PATH + EXPECTED_XML_WITHOUT_EFFECTIVE_TIME);
270+
String inputJsonFileContent = ResourceTestFileUtils.getFileContent(INPUT_PATH + FHIR_BUNDLE_WITHOUT_EFFECTIVE_TIME);
271+
Bundle bundle = new FhirParseService().parseResource(inputJsonFileContent, Bundle.class);
272+
messageContext.initialize(bundle);
273+
setupTimestampMock();
274+
setupRandomIdMocks();
275+
when(codeableConceptCdMapper.mapToNullFlavorCodeableConceptForAllergy(any(CodeableConcept.class), any()))
276+
.thenReturn(CodeableConceptMapperMockUtil.NULL_FLAVOR_CODE);
277+
278+
EhrExtractTemplateParameters ehrExtractTemplateParameters = ehrExtractMapper.mapBundleToEhrFhirExtractParams(
279+
getGpcStructuredTaskDefinition,
280+
bundle
281+
);
282+
String output = ehrExtractMapper.mapEhrExtractToXml(ehrExtractTemplateParameters);
283+
284+
assertThat(output).isEqualToIgnoringWhitespace(expectedJsonToXmlContent);
285+
}
286+
287+
288+
@Test
289+
void When_MappingProperJsonRequestBody_Expect_EhrExtractResponseFromJson() {
290+
String expectedJsonToXmlContent = ResourceTestFileUtils.getFileContent(OUTPUT_PATH + EXPECTED_XML_TO_JSON_FILE);
291+
String inputJsonFileContent = ResourceTestFileUtils.getFileContent(INPUT_PATH + JSON_INPUT_FILE);
292+
Bundle bundle = new FhirParseService().parseResource(inputJsonFileContent, Bundle.class);
293+
messageContext.initialize(bundle);
294+
setupTimestampMock();
295+
setupRandomIdMocks();
296+
297+
when(codeableConceptCdMapper.mapCodeableConceptToCd(any(CodeableConcept.class)))
298+
.thenReturn(CodeableConceptMapperMockUtil.NULL_FLAVOR_CODE);
299+
when(codeableConceptCdMapper.mapCodeableConceptForMedication(any(CodeableConcept.class)))
300+
.thenReturn(CodeableConceptMapperMockUtil.NULL_FLAVOR_CODE);
301+
when(codeableConceptCdMapper.mapCodeableConceptToCdForTransformedActualProblemHeader(any(CodeableConcept.class)))
302+
.thenReturn(CodeableConceptMapperMockUtil.ACTUAL_PROBLEM_CODE);
303+
when(codeableConceptCdMapper.mapCodeableConceptToCdForAllergy(any(CodeableConcept.class), any()))
304+
.thenReturn(CodeableConceptMapperMockUtil.NULL_FLAVOR_CODE);
305+
when(codeableConceptCdMapper.getDisplayFromCodeableConcept(any(CodeableConcept.class)))
306+
.thenCallRealMethod();
307+
when(codeableConceptCdMapper.mapCodeableConceptToCdForBloodPressure(any(CodeableConcept.class)))
308+
.thenReturn(CodeableConceptMapperMockUtil.NULL_FLAVOR_CODE);
309+
when(codeableConceptCdMapper.mapToCdForTopic(any(CodeableConcept.class), any(String.class)))
310+
.thenReturn(CodeableConceptMapperMockUtil.NULL_FLAVOR_CODE);
311+
when(codeableConceptCdMapper.getCdForTopic())
312+
.thenReturn(CodeableConceptMapperMockUtil.NULL_FLAVOR_CODE);
313+
when(codeableConceptCdMapper.mapToCdForCategory(any(String.class)))
314+
.thenReturn(CodeableConceptMapperMockUtil.NULL_FLAVOR_CODE);
315+
when(codeableConceptCdMapper.getCdForCategory())
316+
.thenReturn(CodeableConceptMapperMockUtil.NULL_FLAVOR_CODE);
317+
EhrExtractTemplateParameters ehrExtractTemplateParameters = ehrExtractMapper.mapBundleToEhrFhirExtractParams(
318+
getGpcStructuredTaskDefinition,
319+
bundle
320+
);
321+
String output = ehrExtractMapper.mapEhrExtractToXml(ehrExtractTemplateParameters);
322+
323+
assertThat(output).isEqualToIgnoringWhitespace(expectedJsonToXmlContent);
324+
}
325+
324326
@ParameterizedTest
325327
@MethodSource("testData")
326328
void When_MappingProperJsonRequestBody_Expect_ProperXmlOutput(String input, String expected) {
@@ -340,6 +342,28 @@ void When_MappingProperJsonRequestBody_Expect_ProperXmlOutput(String input, Stri
340342
assertThat(output).isEqualToIgnoringWhitespace(expectedJsonToXmlContent);
341343
}
342344

345+
@ParameterizedTest
346+
@MethodSource("testDataWithObservations")
347+
void When_MappingProperJsonRequestBody_Expect_ProperXmlOutputWithObservations(String input, String expected) {
348+
String expectedJsonToXmlContent = ResourceTestFileUtils.getFileContent(OUTPUT_PATH + expected);
349+
String inputJsonFileContent = ResourceTestFileUtils.getFileContent(INPUT_PATH + input);
350+
Bundle bundle = new FhirParseService().parseResource(inputJsonFileContent, Bundle.class);
351+
messageContext.initialize(bundle);
352+
353+
setupTimestampMock();
354+
setupRandomIdMocks();
355+
when(codeableConceptCdMapper.mapCodeableConceptToCd(any(CodeableConcept.class)))
356+
.thenReturn(CodeableConceptMapperMockUtil.NULL_FLAVOR_CODE);
357+
358+
EhrExtractTemplateParameters ehrExtractTemplateParameters = ehrExtractMapper.mapBundleToEhrFhirExtractParams(
359+
getGpcStructuredTaskDefinition,
360+
bundle
361+
);
362+
String output = ehrExtractMapper.mapEhrExtractToXml(ehrExtractTemplateParameters);
363+
364+
assertThat(output).isEqualToIgnoringWhitespace(expectedJsonToXmlContent);
365+
}
366+
343367
@Test
344368
void When_MappingProperJsonRequestBody_Expect_NonDuplicatedMedicationRequestRemainingResources() {
345369
String inputJsonFileContent =
@@ -351,19 +375,14 @@ void When_MappingProperJsonRequestBody_Expect_NonDuplicatedMedicationRequestRema
351375
setupRandomIdMocks();
352376
when(codeableConceptCdMapper.mapCodeableConceptToCd(any(CodeableConcept.class)))
353377
.thenReturn(CodeableConceptMapperMockUtil.NULL_FLAVOR_CODE);
354-
355378
when(codeableConceptCdMapper.mapCodeableConceptForMedication(any(CodeableConcept.class)))
356379
.thenReturn(CodeableConceptMapperMockUtil.NULL_FLAVOR_CODE);
357-
358380
when(codeableConceptCdMapper.mapCodeableConceptToCdForAllergy(any(CodeableConcept.class), any()))
359381
.thenReturn(CodeableConceptMapperMockUtil.NULL_FLAVOR_CODE);
360-
361382
when(codeableConceptCdMapper.mapToCdForTopic(any(String.class)))
362383
.thenReturn(CodeableConceptMapperMockUtil.NULL_FLAVOR_CODE);
363-
364384
when(codeableConceptCdMapper.mapToCdForCategory(any(String.class)))
365385
.thenReturn(CodeableConceptMapperMockUtil.NULL_FLAVOR_CODE);
366-
367386
when(codeableConceptCdMapper.getCdForCategory())
368387
.thenReturn(CodeableConceptMapperMockUtil.NULL_FLAVOR_CODE);
369388

@@ -374,19 +393,6 @@ void When_MappingProperJsonRequestBody_Expect_NonDuplicatedMedicationRequestRema
374393
assertThat(ehrExtractTemplateParameters.getComponents()).hasSize(2);
375394
}
376395

377-
private static Stream<Arguments> testData() {
378-
return Stream.of(
379-
Arguments.of(JSON_INPUT_FILE, EXPECTED_XML_TO_JSON_FILE),
380-
Arguments.of(FHIR_BUNDLE_WITHOUT_EFFECTIVE_TIME, EXPECTED_XML_WITHOUT_EFFECTIVE_TIME),
381-
Arguments.of(FHIR_BUNDLE_WITHOUT_HIGH_EFFECTIVE_TIME, EXPECTED_XML_WITHOUT_HIGH_EFFECTIVE_TIME),
382-
Arguments.of(FHIR_BUNDLE_WITH_EFFECTIVE_TIME, EXPECTED_XML_WITH_EFFECTIVE_TIME),
383-
Arguments.of(FHIR_BUNDLE_WITH_WITH_OBSERVATIONS_BEFORE_DIAGNOSTIC_REPORT, EXPECTED_XML_WITH_OBSERVATIONS_INSIDE_REPORT),
384-
Arguments.of(FHIR_BUNDLE_WITH_WITH_OBSERVATIONS_AFTER_DIAGNOSTIC_REPORT, EXPECTED_XML_WITH_OBSERVATIONS_INSIDE_REPORT),
385-
Arguments.of(FHIR_BUNDLE_WITH_OBSERVATIONS_UNRELATED_TO_DIAGNOSTIC_REPORT, EXPECTED_XML_WITH_STANDALONE_OBSERVATIONS),
386-
Arguments.of(FHIR_BUNDLE_WITH_OBSERVATIONS_WITH_RELATED_OBSERVATIONS, EXPECTED_XML_WITH_RELATED_OBSERVATIONS)
387-
);
388-
}
389-
390396
@Test
391397
void When_MappingJsonBody_Expect_OnlyOneConsultationResource() {
392398
when(codeableConceptCdMapper.mapToNullFlavorCodeableConceptForAllergy(any(CodeableConcept.class), any()))
@@ -414,4 +420,20 @@ void When_TransformingResourceToEhrComp_Expect_NoDuplicateMappings() {
414420
var translatedOutput = nonConsultationResourceMapper.mapRemainingResourcesToEhrCompositions(parsedBundle);
415421
assertThat(translatedOutput).hasSize(1);
416422
}
423+
424+
private static Stream<Arguments> testData() {
425+
return Stream.of(
426+
Arguments.of(FHIR_BUNDLE_WITHOUT_HIGH_EFFECTIVE_TIME, EXPECTED_XML_WITHOUT_HIGH_EFFECTIVE_TIME),
427+
Arguments.of(FHIR_BUNDLE_WITH_EFFECTIVE_TIME, EXPECTED_XML_WITH_EFFECTIVE_TIME)
428+
);
429+
}
430+
431+
private static Stream<Arguments> testDataWithObservations() {
432+
return Stream.of(
433+
Arguments.of(FHIR_BUNDLE_WITH_WITH_OBSERVATIONS_BEFORE_DIAGNOSTIC_REPORT, EXPECTED_XML_WITH_OBSERVATIONS_INSIDE_REPORT),
434+
Arguments.of(FHIR_BUNDLE_WITH_WITH_OBSERVATIONS_AFTER_DIAGNOSTIC_REPORT, EXPECTED_XML_WITH_OBSERVATIONS_INSIDE_REPORT),
435+
Arguments.of(FHIR_BUNDLE_WITH_OBSERVATIONS_UNRELATED_TO_DIAGNOSTIC_REPORT, EXPECTED_XML_WITH_STANDALONE_OBSERVATIONS),
436+
Arguments.of(FHIR_BUNDLE_WITH_OBSERVATIONS_WITH_RELATED_OBSERVATIONS, EXPECTED_XML_WITH_RELATED_OBSERVATIONS)
437+
);
438+
}
417439
}

0 commit comments

Comments
 (0)