Skip to content

Commit f630524

Browse files
committed
Removed filtering of filing comments from Specimen mapper and added it to diagnostic report mapper
1 parent b53d885 commit f630524

File tree

5 files changed

+14
-34
lines changed

5 files changed

+14
-34
lines changed

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import java.util.Collections;
1313
import java.util.List;
1414
import java.util.Optional;
15+
import java.util.function.Predicate;
1516
import java.util.stream.Collectors;
1617
import java.util.stream.Stream;
1718

@@ -121,7 +122,7 @@ private List<Specimen> fetchSpecimens(DiagnosticReport diagnosticReport, List<Ob
121122

122123
List<Specimen> specimens = new ArrayList<>();
123124

124-
// At least one specimen is required to exist for any DiagnosticReport
125+
// At least one specimen is required to exist for any DiagnosticReport, according to the mim
125126
if (!diagnosticReport.hasSpecimen() || hasOrphanedTestResults(observations)) {
126127
specimens.add(generateDummySpecimen(diagnosticReport));
127128
}
@@ -143,6 +144,7 @@ private List<Specimen> fetchSpecimens(DiagnosticReport diagnosticReport, List<Ob
143144
private boolean hasOrphanedTestResults(List<Observation> observations) {
144145
return observations
145146
.stream()
147+
.filter(observation -> !isFilingComment(observation))
146148
.anyMatch(observation -> !observation.hasSpecimen());
147149
}
148150

@@ -161,7 +163,7 @@ private List<Observation> assignDummySpecimensToOrphanedTestResults(
161163
Reference dummySpecimenReference = new Reference(dummySpecimen.getId());
162164

163165
for (Observation observation : observations) {
164-
if (!observation.hasSpecimen()) {
166+
if (!observation.hasSpecimen() && !isFilingComment(observation)) {
165167
observation.setSpecimen(dummySpecimenReference);
166168
}
167169
}

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,6 @@ private String mapObservationsAssociatedWithSpecimen(Specimen specimen, List<Obs
149149
}
150150

151151
return observationsAssociatedWithSpecimen.stream()
152-
.filter(Predicate.not(DiagnosticReportMapper::isFilingComment))
153152
.map(observationMapper::mapObservationToCompoundStatement)
154153
.collect(Collectors.joining());
155154
}

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

Lines changed: 8 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,6 @@ class DiagnosticReportMapperTest {
9090
private static final String OUTPUT_XML_EXTENSION_ID = "diagnostic-report-with-extension-id.xml";
9191
private static final String OUTPUT_XML_MULTIPLE_RESULTS = "diagnostic-report-with-multiple-results.xml";
9292
private static final String OUTPUT_XML_UNRELATED_TEST_RESULT = "diagnostic-report-with-one-specimen-and-one-unrelated-observation.xml";
93-
private static final String REGEXP_UUID = "[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}";
94-
private static final String MOCKED_SPECIMEN_PREFIX = "Mapped Specimen with id";
95-
private static final String MOCKED_SPECIMEN_LINKED_OBSERVATION = "with linked Observations";
9693

9794
@Mock
9895
private CodeableConceptCdMapper codeableConceptCdMapper;
@@ -307,20 +304,15 @@ void When_DiagnosticReport_Has_SpecimenAndUnlinkedTestResult_Expect_ADummySpecim
307304
final DiagnosticReport diagnosticReport = getDiagnosticReportResourceFromJson(diagnosticReportFileName);
308305
final Bundle bundle = getBundleResourceFromJson(INPUT_JSON_BUNDLE);
309306
final InputBundle inputBundle = new InputBundle(bundle);
310-
final String expectObservation = "Observation/TestResult-WithoutSpecimenReference";
311-
final String dummyNamePrefix = DiagnosticReportMapper.DUMMY_SPECIMEN_ID_PREFIX;
312307

313308
when(messageContext.getInputBundleHolder()).thenReturn(inputBundle);
314309

315310
final String actualXml = mapper.mapDiagnosticReportToCompoundStatement(diagnosticReport);
316311

317312
// This checks that the unlinked test result is given a dummy specimen.
318-
assertThat(actualXml).matches("(?s).*<!-- " + MOCKED_SPECIMEN_PREFIX + ": " + dummyNamePrefix
319-
+ REGEXP_UUID
320-
+ " " + MOCKED_SPECIMEN_LINKED_OBSERVATION + ": "
321-
+ expectObservation
322-
+ "-->.*"
323-
);
313+
assertThat(actualXml).containsIgnoringWhitespaces(
314+
"<!-- Mapped Specimen with id: DUMMY-SPECIMEN-5E496953-065B-41F2-9577-BE8F2FBD0757 "
315+
+ "with linked Observations: Observation/TestResult-WithoutSpecimenReference-->");
324316
}
325317

326318
@Test
@@ -330,25 +322,13 @@ void When_DiagnosticReport_Has_SpecimenALinkedTestResultAndAnUnlinkedTestResult_
330322
final DiagnosticReport diagnosticReport = getDiagnosticReportResourceFromJson(diagnosticReportFileName);
331323
final Bundle bundle = getBundleResourceFromJson(INPUT_JSON_BUNDLE);
332324
final InputBundle inputBundle = new InputBundle(bundle);
333-
final String expectObservation = "Observation/TestResult-WithoutSpecimenReference";
334-
final String dummyNamePrefix = DiagnosticReportMapper.DUMMY_SPECIMEN_ID_PREFIX;
335325
when(messageContext.getInputBundleHolder()).thenReturn(inputBundle);
336326

337327
final String actualXml = mapper.mapDiagnosticReportToCompoundStatement(diagnosticReport);
338328
// This checks that the unlinked test result is given a dummy specimen.
339-
assertThat(actualXml).matches("(?s).*<!-- " + MOCKED_SPECIMEN_PREFIX + ": " + dummyNamePrefix
340-
+ REGEXP_UUID
341-
+ " " + MOCKED_SPECIMEN_LINKED_OBSERVATION + ": "
342-
+ expectObservation
343-
+ "-->.*"
344-
);
345-
// This checks that the linked test result has its correct specimen.
346-
assertThat(actualXml).containsIgnoringWhitespaces("<!-- " + MOCKED_SPECIMEN_PREFIX + ": "
347-
+ "Specimen/96B93E28-293D-46E7-B4C2-D477EEBF7098-SPEC-0"
348-
+ MOCKED_SPECIMEN_LINKED_OBSERVATION + ":"
349-
+ "Observation/B7F05EA7-A1A4-48C0-9C4C-CDB5768796B2"
350-
+ " -->"
351-
);
329+
assertThat(actualXml).containsIgnoringWhitespaces(
330+
"<!-- Mapped Specimen with id: DUMMY-SPECIMEN-5E496953-065B-41F2-9577-BE8F2FBD0757 "
331+
+ "with linked Observations: Observation/TestResult-WithoutSpecimenReference-->");
352332

353333
}
354334

@@ -412,10 +392,9 @@ private Answer<String> mockSpecimenMapping() {
412392
}
413393

414394
if (linkedObservations.isEmpty()) {
415-
return String.format("<!-- " + MOCKED_SPECIMEN_PREFIX + ": %s -->", specimen.getId());
395+
return String.format("<!-- Mapped Specimen with id: %s -->", specimen.getId());
416396
}
417-
return String.format("<!-- " + MOCKED_SPECIMEN_PREFIX + ": %s "
418-
+ MOCKED_SPECIMEN_LINKED_OBSERVATION + ": %s-->",
397+
return String.format("<!-- Mapped Specimen with id: %s with linked Observations: %s-->",
419398
specimen.getId(),
420399
String.join(",", linkedObservations));
421400
};

service/src/test/resources/ehr/mapper/diagnosticreport/diagnostic-report-with-multiple-results.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,6 @@ CommentDate:20100225154100
6262
<availabilityTime value="20100225154100"/>
6363
</NarrativeStatement>
6464
</component>
65-
<!-- Mapped Specimen with id: DUMMY-SPECIMEN-5E496953-065B-41F2-9577-BE8F2FBD0757 with linked Observations: Observation/B7F05EA7-A1A4-48C0-9C4C-CDB5768796B2-COMM,Observation/6E30A9E3-FF9A-4868-8FCD-7DAC26A16E78-COMM,Observation/D0A358C9-4833-4827-B14B-E8515C25CB12-COMM-->
65+
<!-- Mapped Specimen with id: DUMMY-SPECIMEN-5E496953-065B-41F2-9577-BE8F2FBD0757-->
6666
</CompoundStatement>
6767
</component>

service/src/test/resources/ehr/mapper/diagnosticreport/specimen/expected_output_default_specimen_with_observation.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,6 @@ Received Date: 2010-02-24 15:41
3131
<availabilityTime value="20201012143344"/>
3232
</NarrativeStatement>
3333
</component>
34-
<!-- Mapped Observation with id: Observation/B7F05EA7-A1A4-48C0-9C4C-CDB5768796B2 -->
34+
<!-- Mapped Observation with id: Observation/B7F05EA7-A1A4-48C0-9C4C-CDB5768796B2 --><!-- Mapped Observation with id: Observation/B7F05EA7-A1A4-48C0-9C4C-CDB5768796B2-COMM -->
3535
</CompoundStatement>
3636
</component>

0 commit comments

Comments
 (0)