|
35 | 35 |
|
36 | 36 | import uk.nhs.adaptors.gp2gp.common.service.ConfidentialityService; |
37 | 37 | import uk.nhs.adaptors.gp2gp.common.service.RandomIdGeneratorService; |
38 | | -import uk.nhs.adaptors.gp2gp.ehr.exception.EhrMapperException; |
39 | 38 | import uk.nhs.adaptors.gp2gp.ehr.mapper.CommentType; |
40 | 39 | import uk.nhs.adaptors.gp2gp.ehr.mapper.IdMapper; |
41 | 40 | import uk.nhs.adaptors.gp2gp.ehr.mapper.MessageContext; |
@@ -169,25 +168,26 @@ private boolean hasObservationsWithoutSpecimen(List<Observation> observations) { |
169 | 168 | /** |
170 | 169 | * For correct display in EMIS, any observation without a specimen must be assigned a dummy specimen. |
171 | 170 | */ |
172 | | - List<Observation> assignDummySpecimensToObservationsWithNoSpecimen( |
173 | | - List<Observation> observations, List<Specimen> specimens) { |
| 171 | + List<Observation> assignDummySpecimensToObservationsWithNoSpecimen(List<Observation> observations, List<Specimen> specimens) { |
174 | 172 |
|
175 | 173 | List<Observation> filingComments = getFilingComments(observations); |
176 | 174 | List<Observation> nonFilingObservations = new ArrayList<>(stripFilingComments(observations)); |
177 | 175 |
|
178 | | - if (hasObservationsWithoutSpecimen(nonFilingObservations)) { |
179 | | - Specimen dummySpecimen = specimens.stream() |
180 | | - .filter(specimen -> specimen.getId().contains(NOT_PRESENT_SPECIMEN_ID_PREFIX)) |
181 | | - .findFirst() |
182 | | - .orElseThrow(() -> new EhrMapperException( |
183 | | - "No not present specimen found with prefix: " + NOT_PRESENT_SPECIMEN_ID_PREFIX)); |
| 176 | + if (!hasObservationsWithoutSpecimen(nonFilingObservations)) { |
| 177 | + nonFilingObservations.addAll(filingComments); |
| 178 | + return nonFilingObservations; |
| 179 | + } |
184 | 180 |
|
185 | | - Reference dummySpecimenReference = new Reference(dummySpecimen.getId()); |
| 181 | + // The assumption was made that all test results without a specimen will have the same dummy specimen referenced |
| 182 | + Specimen dummySpecimen = specimens.stream() |
| 183 | + .filter(specimen -> specimen.getId().contains(NOT_PRESENT_SPECIMEN_ID_PREFIX)) |
| 184 | + .toList().getFirst(); |
186 | 185 |
|
187 | | - nonFilingObservations.stream() |
188 | | - .filter(obs -> !obs.hasSpecimen()) |
189 | | - .forEach(obs -> obs.setSpecimen(dummySpecimenReference)); |
190 | | - } |
| 186 | + Reference dummySpecimenReference = new Reference(dummySpecimen.getId()); |
| 187 | + |
| 188 | + nonFilingObservations.stream() |
| 189 | + .filter(obs -> !obs.hasSpecimen() && !isFilingComment(obs)) |
| 190 | + .forEach(obs -> obs.setSpecimen(dummySpecimenReference)); |
191 | 191 |
|
192 | 192 | nonFilingObservations.addAll(filingComments); |
193 | 193 | return nonFilingObservations; |
|
0 commit comments