|
1 | 1 | package uk.nhs.adaptors.gp2gp.ehr.mapper.diagnosticreport; |
2 | 2 |
|
3 | 3 | import static org.assertj.core.api.Assertions.assertThat; |
| 4 | +import static org.assertj.core.api.AssertionsForClassTypes.assertThatThrownBy; |
| 5 | +import static org.junit.Assert.assertFalse; |
4 | 6 | import static org.junit.jupiter.api.Assertions.assertAll; |
5 | 7 | import static org.mockito.ArgumentMatchers.any; |
6 | 8 | import static org.mockito.Mockito.when; |
7 | 9 | import java.util.ArrayList; |
8 | 10 | import java.util.Collections; |
9 | 11 | import java.util.List; |
| 12 | +import java.util.NoSuchElementException; |
10 | 13 | import java.util.Optional; |
11 | 14 | import java.util.stream.Stream; |
12 | 15 |
|
13 | 16 | import org.hl7.fhir.dstu3.model.Bundle; |
14 | 17 | import org.hl7.fhir.dstu3.model.CodeableConcept; |
| 18 | +import org.hl7.fhir.dstu3.model.Coding; |
15 | 19 | import org.hl7.fhir.dstu3.model.DiagnosticReport; |
16 | 20 | import org.hl7.fhir.dstu3.model.IdType; |
17 | 21 | import org.hl7.fhir.dstu3.model.Observation; |
@@ -62,6 +66,7 @@ class DiagnosticReportMapperTest { |
62 | 66 |
|
63 | 67 | private static final String TEST_ID = "5E496953-065B-41F2-9577-BE8F2FBD0757"; |
64 | 68 | public static final String NOT_PRESENT_SPECIMEN_ID_PREFIX = "NOT-PRESENT-SPECIMEN-"; |
| 69 | + private static final String COMMENT_NOTE = "37331000000100"; |
65 | 70 |
|
66 | 71 | private static final String INPUT_JSON_REQUIRED_DATA = "diagnostic-report-with-required-data.json"; |
67 | 72 | private static final String INPUT_JSON_EMPTY_SPECIMENS = "diagnostic-report-with-empty-specimens.json"; |
@@ -130,6 +135,53 @@ public void tearDown() { |
130 | 135 | messageContext.resetMessageContext(); |
131 | 136 | } |
132 | 137 |
|
| 138 | + @Test |
| 139 | + void shouldAssignDummySpecimenOnlyToNonFilingObservationsWithoutSpecimen() { |
| 140 | + |
| 141 | + Observation obsWithoutSpecimen = new Observation(); |
| 142 | + obsWithoutSpecimen.setId("obs1"); |
| 143 | + |
| 144 | + Observation obsWithSpecimen = new Observation(); |
| 145 | + obsWithSpecimen.setId("obs2"); |
| 146 | + obsWithSpecimen.setSpecimen(new Reference("real-specimen")); |
| 147 | + |
| 148 | + Observation filingCommentObs = new Observation(); |
| 149 | + filingCommentObs.setId("obs3"); |
| 150 | + filingCommentObs.getCode().addCoding(new Coding().setCode(COMMENT_NOTE)); |
| 151 | + |
| 152 | + List<Observation> observations = List.of(obsWithoutSpecimen, obsWithSpecimen, filingCommentObs); |
| 153 | + |
| 154 | + Specimen dummySpecimen = new Specimen(); |
| 155 | + dummySpecimen.setId(NOT_PRESENT_SPECIMEN_ID_PREFIX + "123"); |
| 156 | + List<Specimen> specimens = List.of(dummySpecimen); |
| 157 | + |
| 158 | + List<Observation> result = mapper.assignDummySpecimensToObservationsWithNoSpecimen(observations, specimens); |
| 159 | + |
| 160 | + assertThat(obsWithoutSpecimen.getSpecimen()) |
| 161 | + .isNotNull() |
| 162 | + .extracting(Reference::getReference) |
| 163 | + .isEqualTo(dummySpecimen.getId()); |
| 164 | + |
| 165 | + assertThat(obsWithSpecimen.getSpecimen()) |
| 166 | + .extracting(Reference::getReference) |
| 167 | + .isEqualTo("real-specimen"); |
| 168 | + |
| 169 | + assertFalse(filingCommentObs.hasSpecimen()); |
| 170 | + assertThat(result).containsExactlyInAnyOrder(obsWithoutSpecimen, obsWithSpecimen, filingCommentObs); |
| 171 | + } |
| 172 | + |
| 173 | + @Test |
| 174 | + void shouldThrowIfNoDummySpecimenFound() { |
| 175 | + |
| 176 | + Observation obsWithoutSpecimen = new Observation(); |
| 177 | + List<Observation> observations = List.of(obsWithoutSpecimen); |
| 178 | + |
| 179 | + List<Specimen> specimens = List.of(); |
| 180 | + |
| 181 | + assertThatThrownBy(() -> mapper.assignDummySpecimensToObservationsWithNoSpecimen(observations, specimens)) |
| 182 | + .isInstanceOf(NoSuchElementException.class); |
| 183 | + } |
| 184 | + |
133 | 185 | @Test |
134 | 186 | void shouldAssignDummySpecimenToObservationsWithoutSpecimen() { |
135 | 187 |
|
|
0 commit comments