Skip to content

Commit 093809e

Browse files
committed
refactoring code and tests
1 parent 45cefd7 commit 093809e

File tree

2 files changed

+10
-21
lines changed

2 files changed

+10
-21
lines changed

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

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ public class NonConsultationResourceMapper {
7575

7676
public List<String> mapRemainingResourcesToEhrCompositions(Bundle bundle) {
7777

78-
7978
var mappedResources = bundle.getEntry().stream()
8079
.map(Bundle.BundleEntryComponent::getResource)
8180
.filter(this::isMappableNonConsultationResource)
@@ -122,11 +121,8 @@ private boolean shouldMapMedicationRequest(MedicationRequest medicationRequest)
122121
String referenceId = medicationRequest.getBasedOn().getFirst().getReference();
123122

124123
try {
125-
Optional<Resource> referencedResource =
126-
messageContext.getInputBundleHolder().getResource(new IdType(referenceId));
127-
124+
Optional<Resource> referencedResource = messageContext.getInputBundleHolder().getResource(new IdType(referenceId));
128125
return referencedResource.isEmpty() || !hasIdBeenMapped(referencedResource.get());
129-
130126
} catch (EhrMapperException e) {
131127
LOGGER.info("MedicationRequest {} cannot be mapped", referenceId);
132128
return true;

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

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -41,23 +41,20 @@
4141

4242
@ExtendWith(MockitoExtension.class)
4343
@MockitoSettings(strictness = Strictness.LENIENT)
44-
public class EhrExtractMapperComponentTest {
44+
class EhrExtractMapperComponentTest {
4545

4646
private static final String TEST_FILE_DIRECTORY = "/ehr/request/fhir/";
4747
private static final String INPUT_DIRECTORY = "input/";
4848
private static final String OUTPUT_DIRECTORY = "output/";
4949
private static final String INPUT_PATH = TEST_FILE_DIRECTORY + INPUT_DIRECTORY;
5050
private static final String OUTPUT_PATH = TEST_FILE_DIRECTORY + OUTPUT_DIRECTORY;
51-
5251
private static final String JSON_INPUT_FILE = "gpc-access-structured.json";
5352
private static final String JSON_INPUT_FILE_WITH_NOPAT = "gpc-access-structured-with-nopat.json";
5453
private static final String DUPLICATE_RESOURCE_BUNDLE = INPUT_PATH + "duplicated-resource-bundle.json";
5554
private static final String ONE_CONSULTATION_RESOURCE_BUNDLE = INPUT_PATH + "1-consultation-resource.json";
5655
private static final String FHIR_BUNDLE_WITH_DUPLICATED_MEDICATION_REQUESTS = "fhir_bundle_with_duplicated_medication_requests.json";
57-
5856
private static final String EXPECTED_XML_FOR_ONE_CONSULTATION_RESOURCE = "ExpectedResponseFrom1ConsultationResponse.xml";
5957

60-
private static final String EXPECTED_XML_WITHOUT_DUPLICATED_RESOURCES = "expected_xml_without_duplicated_medication_resources.xml";
6158
private static final String EXPECTED_XML_TO_JSON_FILE = "expected-ehr-extract-response-from-json.xml";
6259
private static final String EXPECTED_XML_TO_JSON_FILE_WITH_NOPAT = "expected-ehr-extract-response-from-json-with-nopat.xml";
6360

@@ -235,7 +232,7 @@ public void tearDown() {
235232
}
236233

237234
@Test
238-
public void When_MappingUncategorizedObservationWithNOPAT_Expect_ObservationStatementWithConfidentialityCode() {
235+
void When_MappingUncategorizedObservationWithNOPAT_Expect_ObservationStatementWithConfidentialityCode() {
239236

240237
String expectedJsonToXmlContent = ResourceTestFileUtils.getFileContent(OUTPUT_PATH + EXPECTED_XML_TO_JSON_FILE_WITH_NOPAT);
241238
String inputJsonFileContent = ResourceTestFileUtils.getFileContent(INPUT_PATH + JSON_INPUT_FILE_WITH_NOPAT);
@@ -263,7 +260,7 @@ public void When_MappingUncategorizedObservationWithNOPAT_Expect_ObservationStat
263260

264261
@ParameterizedTest
265262
@MethodSource("testData")
266-
public void When_MappingProperJsonRequestBody_Expect_ProperXmlOutput(String input, String expected) {
263+
void When_MappingProperJsonRequestBody_Expect_ProperXmlOutput(String input, String expected) {
267264
String expectedJsonToXmlContent = ResourceTestFileUtils.getFileContent(OUTPUT_PATH + expected);
268265
String inputJsonFileContent = ResourceTestFileUtils.getFileContent(INPUT_PATH + input);
269266
Bundle bundle = new FhirParseService().parseResource(inputJsonFileContent, Bundle.class);
@@ -278,10 +275,10 @@ public void When_MappingProperJsonRequestBody_Expect_ProperXmlOutput(String inpu
278275
assertThat(output).isEqualToIgnoringWhitespace(expectedJsonToXmlContent);
279276
}
280277

281-
@ParameterizedTest
282-
@MethodSource("testDataWithDuplicatedMedicationRequestResources")
283-
public void When_MappingProperJsonRequestBody_Expect_NonDuplicatedMedicationRequestRemainingResources(String input, String expected) {
284-
String inputJsonFileContent = ResourceTestFileUtils.getFileContent(INPUT_PATH + input);
278+
@Test
279+
void When_MappingProperJsonRequestBody_Expect_NonDuplicatedMedicationRequestRemainingResources() {
280+
String inputJsonFileContent =
281+
ResourceTestFileUtils.getFileContent(INPUT_PATH + FHIR_BUNDLE_WITH_DUPLICATED_MEDICATION_REQUESTS);
285282
Bundle bundle = new FhirParseService().parseResource(inputJsonFileContent, Bundle.class);
286283
messageContext.initialize(bundle);
287284

@@ -292,10 +289,6 @@ public void When_MappingProperJsonRequestBody_Expect_NonDuplicatedMedicationRequ
292289
assertThat(ehrExtractTemplateParameters.getComponents()).hasSize(2);
293290
}
294291

295-
private static Stream<Arguments> testDataWithDuplicatedMedicationRequestResources() {
296-
return Stream.of(Arguments.of(FHIR_BUNDLE_WITH_DUPLICATED_MEDICATION_REQUESTS, EXPECTED_XML_WITHOUT_DUPLICATED_RESOURCES));
297-
}
298-
299292
private static Stream<Arguments> testData() {
300293
return Stream.of(
301294
Arguments.of(JSON_INPUT_FILE, EXPECTED_XML_TO_JSON_FILE),
@@ -310,7 +303,7 @@ private static Stream<Arguments> testData() {
310303
}
311304

312305
@Test
313-
public void When_MappingJsonBody_Expect_OnlyOneConsultationResource() {
306+
void When_MappingJsonBody_Expect_OnlyOneConsultationResource() {
314307
String expectedJsonToXmlContent = ResourceTestFileUtils.getFileContent(OUTPUT_PATH + EXPECTED_XML_FOR_ONE_CONSULTATION_RESOURCE);
315308
String inputJsonFileContent = ResourceTestFileUtils.getFileContent(ONE_CONSULTATION_RESOURCE_BUNDLE);
316309
Bundle bundle = new FhirParseService().parseResource(inputJsonFileContent, Bundle.class);
@@ -324,7 +317,7 @@ public void When_MappingJsonBody_Expect_OnlyOneConsultationResource() {
324317
}
325318

326319
@Test
327-
public void When_TransformingResourceToEhrComp_Expect_NoDuplicateMappings() {
320+
void When_TransformingResourceToEhrComp_Expect_NoDuplicateMappings() {
328321
String bundle = ResourceTestFileUtils.getFileContent(DUPLICATE_RESOURCE_BUNDLE);
329322
Bundle parsedBundle = new FhirParseService().parseResource(bundle, Bundle.class);
330323
messageContext.initialize(parsedBundle);

0 commit comments

Comments
 (0)