Skip to content

Commit cc146ea

Browse files
committed
Added better marking in tests for mapped specimens.
1 parent d511258 commit cc146ea

File tree

3 files changed

+13
-8
lines changed

3 files changed

+13
-8
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ private List<Specimen> fetchSpecimens(DiagnosticReport diagnosticReport, List<Ob
115115

116116
List<Specimen> specimens = new ArrayList<>();
117117

118-
if (hasOrphanedTestResults(observations)) {
118+
if (!diagnosticReport.hasSpecimen() || hasOrphanedTestResults(observations)) {
119119
specimens.add(generateDefaultSpecimen(diagnosticReport));
120120
}
121121

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

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import static org.mockito.Mockito.when;
77

88
import java.io.IOException;
9+
import java.util.ArrayList;
910
import java.util.Collections;
1011
import java.util.List;
1112
import java.util.Optional;
@@ -316,7 +317,7 @@ void When_DiagnosticReport_Has_SpecimenAndUnlinkedTestResult_ExpectADummySpecime
316317
REGEXP_UUID +
317318
" " + MOCKED_SPECIMEN_LINKED_OBSERVATION + ": " +
318319
expectObservation +
319-
", -->.*"
320+
"-->.*"
320321
);
321322
}
322323

@@ -337,15 +338,15 @@ void When_DiagnosticReport_Has_SpecimenALinkedTestResultAndAnUnlinkedTestResult_
337338
REGEXP_UUID +
338339
" " + MOCKED_SPECIMEN_LINKED_OBSERVATION + ": " +
339340
expectObservation +
340-
", -->.*"
341+
"-->.*"
341342
);
342343

343344
// This checks that the linked test result has its correct specimen.
344345
assertThat(actualXml).containsIgnoringWhitespaces("<!-- " + MOCKED_SPECIMEN_PREFIX + ": " +
345346
"Specimen/96B93E28-293D-46E7-B4C2-D477EEBF7098-SPEC-0" +
346347
MOCKED_SPECIMEN_LINKED_OBSERVATION + ":" +
347348
"Observation/B7F05EA7-A1A4-48C0-9C4C-CDB5768796B2" +
348-
", -->"
349+
" -->"
349350
);
350351

351352
}
@@ -403,15 +404,19 @@ private Answer<String> mockSpecimenMapping() {
403404
Specimen specimen = invocation.getArgument(0);
404405
List<Observation> observations = invocation.getArgument(1);
405406

406-
String linkedObservations = "";
407+
List<String> linkedObservations = new ArrayList<>();
407408

408409
for (Observation observation : observations) {
409410
if(observation.getSpecimen().getReference() != null && observation.getSpecimen().getReference().equals(specimen.getId())){
410-
linkedObservations = linkedObservations + observation.getId() + ", ";
411+
linkedObservations.add(observation.getId());
411412
}
412413
}
414+
415+
if(linkedObservations.isEmpty()){
416+
return String.format("<!-- " + MOCKED_SPECIMEN_PREFIX + ": %s -->", specimen.getId());
417+
}
413418

414-
return String.format("<!-- " + MOCKED_SPECIMEN_PREFIX + ": %s " + MOCKED_SPECIMEN_LINKED_OBSERVATION + ": %s-->", specimen.getId(), linkedObservations);
419+
return String.format("<!-- " + MOCKED_SPECIMEN_PREFIX + ": %s " + MOCKED_SPECIMEN_LINKED_OBSERVATION + ": %s-->", specimen.getId(), String.join(",", linkedObservations));
415420
};
416421
}
417422
}

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 -->
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-->
6666
</CompoundStatement>
6767
</component>

0 commit comments

Comments
 (0)