Skip to content

Commit cc14997

Browse files
authored
NIAD-3401: DUMMY instances replacement in DiagnosticReportMapper (#1376)
* init changes * removing more references to "dummy" words * addressing pitest complains * addressing pitest complains * changelog
1 parent a6017f5 commit cc14997

File tree

8 files changed

+109
-36
lines changed

8 files changed

+109
-36
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1818
* The GP2GP Adaptor now throws an exception when the Access Structure Record is empty, thereby rejecting the transfer
1919

2020
### Fixed
21-
* When DiagnosticReport doesn't contain a Specimen reference, instead of "DUMMY" "NOT-PRESENT" value is used
21+
* When DiagnosticReport doesn't contain a Specimen or Observation reference, instead of "DUMMY" "NOT-PRESENT" value is used
2222

2323
### Update
2424

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

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
public class DiagnosticReportMapper {
5454

5555
public static final String NOT_PRESENT_SPECIMEN_ID_PREFIX = "NOT-PRESENT-SPECIMEN-";
56-
public static final String DUMMY_OBSERVATION_ID_PREFIX = "DUMMY-OBSERVATION-";
56+
public static final String NOT_PRESENT_OBSERVATION_ID_PREFIX = "NOT-PRESENT-OBSERVATION-";
5757

5858
private static final Mustache DIAGNOSTIC_REPORT_COMPOUND_STATEMENT_TEMPLATE =
5959
TemplateUtils.loadTemplate("diagnostic_report_compound_statement_template.mustache");
@@ -80,25 +80,25 @@ public String mapDiagnosticReportToCompoundStatement(DiagnosticReport diagnostic
8080
final IdMapper idMapper = messageContext.getIdMapper();
8181
markObservationsAsProcessed(idMapper, observations);
8282

83-
List<Observation> observationsWithAttachedDummySpecimens =
84-
new ArrayList<>(assignDummySpecimensToObservationsWithNoSpecimen(observations, specimens));
83+
List<Observation> observationsWithAttachedNotPresentSpecimens =
84+
new ArrayList<>(assignNotPresentSpecimensToObservationsWithNoSpecimen(observations, specimens));
8585

86-
observations = addDummyObservationsToObservationList(
87-
observationsWithAttachedDummySpecimens,
86+
observations = addNotPresentObservationsToObservationList(
87+
observationsWithAttachedNotPresentSpecimens,
8888
specimens,
8989
diagnosticReport);
9090

91-
List<Observation> observationsWithDummySpecimensAndDummyObservations = observations;
91+
List<Observation> observationsWithNotPresentSpecimensAndNotPresentObservations = observations;
9292

9393
String mappedSpecimens = specimens.stream()
9494
.map(specimen -> specimenMapper.mapSpecimenToCompoundStatement(specimen,
95-
observationsForSpecimen(specimen, observationsWithDummySpecimensAndDummyObservations),
95+
observationsForSpecimen(specimen, observationsWithNotPresentSpecimensAndNotPresentObservations),
9696
diagnosticReport))
9797
.collect(Collectors.joining());
9898

9999
String reportLevelNarrativeStatements = prepareReportLevelNarrativeStatements(
100100
diagnosticReport,
101-
observationsWithDummySpecimensAndDummyObservations);
101+
observationsWithNotPresentSpecimensAndNotPresentObservations);
102102

103103
var diagnosticReportCompoundStatementTemplateParameters = DiagnosticReportCompoundStatementTemplateParameters.builder()
104104
.compoundStatementId(idMapper.getOrNew(ResourceType.DiagnosticReport, diagnosticReport.getIdElement()))
@@ -146,14 +146,14 @@ private List<Specimen> fetchSpecimens(DiagnosticReport diagnosticReport, List<Ob
146146
}
147147

148148
var inputBundleHolder = messageContext.getInputBundleHolder();
149-
List<Specimen> nonDummySpecimens = diagnosticReport.getSpecimen()
149+
List<Specimen> nonNotPresentSpecimens = diagnosticReport.getSpecimen()
150150
.stream()
151151
.map(specimenReference -> inputBundleHolder.getResource(specimenReference.getReferenceElement()))
152152
.flatMap(Optional::stream)
153153
.map(Specimen.class::cast)
154154
.toList();
155155

156-
specimens.addAll(nonDummySpecimens);
156+
specimens.addAll(nonNotPresentSpecimens);
157157

158158
return specimens;
159159
}
@@ -166,9 +166,9 @@ private boolean hasObservationsWithoutSpecimen(List<Observation> observations) {
166166
}
167167

168168
/**
169-
* For correct display in EMIS, any observation without a specimen must be assigned a dummy specimen.
169+
* For correct display in EMIS, any observation without a specimen must be assigned a not present specimen.
170170
*/
171-
List<Observation> assignDummySpecimensToObservationsWithNoSpecimen(List<Observation> observations, List<Specimen> specimens) {
171+
List<Observation> assignNotPresentSpecimensToObservationsWithNoSpecimen(List<Observation> observations, List<Specimen> specimens) {
172172

173173
List<Observation> filingComments = getFilingComments(observations);
174174
List<Observation> nonFilingObservations = new ArrayList<>(stripFilingComments(observations));
@@ -178,7 +178,7 @@ List<Observation> assignDummySpecimensToObservationsWithNoSpecimen(List<Observat
178178
return nonFilingObservations;
179179
}
180180

181-
// The assumption was made that all test results without a specimen will have the same dummy specimen referenced
181+
// The assumption was made that all test results without a specimen will have the same not present specimen referenced
182182
Specimen notPresentSpecimen = specimens.stream()
183183
.filter(specimen -> specimen.getId().contains(NOT_PRESENT_SPECIMEN_ID_PREFIX))
184184
.toList().getFirst();
@@ -219,21 +219,21 @@ private List<Observation> fetchObservations(DiagnosticReport diagnosticReport) {
219219
}
220220

221221
/**
222-
* For correct display in EMIS, any specimen without an observation must be assigned a dummy observation.
222+
* For correct display in EMIS, any specimen without an observation must be assigned a not present observation.
223223
*/
224-
private List<Observation> addDummyObservationsToObservationList(
224+
private List<Observation> addNotPresentObservationsToObservationList(
225225
List<Observation> observations,
226226
List<Specimen> specimens,
227227
DiagnosticReport diagnosticReport) {
228228
List<Observation> completeObservations = new ArrayList<>();
229229
completeObservations.addAll(observations);
230230

231-
// Generate a dummy Observation for each Specimen without an Observation
231+
// Generate a not present Observation for each Specimen without an Observation
232232
for (String specimenWithoutObservations : getSpecimenIdsWithoutObservation(specimens, observations)) {
233-
Observation dummyObservation = generateDummyObservation(diagnosticReport);
233+
Observation notPresentObservation = generateNotPresentObservation(diagnosticReport);
234234
Reference specimenReference = new Reference(specimenWithoutObservations);
235-
dummyObservation.setSpecimen(specimenReference);
236-
completeObservations.add(dummyObservation);
235+
notPresentObservation.setSpecimen(specimenReference);
236+
completeObservations.add(notPresentObservation);
237237
}
238238

239239
return completeObservations;
@@ -243,7 +243,7 @@ private List<String> getSpecimenIdsWithoutObservation(List<Specimen> specimens,
243243
List<String> specimenIDList = new ArrayList<>();
244244
List<String> nonOrphanSpecimenIDList = new ArrayList<>();
245245
for (Specimen specimen : specimens) {
246-
// Dummy Specimens should not have a dummy observation attached.
246+
// Not present Specimens should not have a not present observation attached.
247247
if (!specimen.getId().contains(NOT_PRESENT_SPECIMEN_ID_PREFIX)) {
248248
specimenIDList.add(specimen.getId());
249249
}
@@ -264,10 +264,10 @@ private List<String> getSpecimenIdsWithoutObservation(List<Specimen> specimens,
264264
return specimensWithoutObservations;
265265
}
266266

267-
private Observation generateDummyObservation(DiagnosticReport diagnosticReport) {
267+
private Observation generateNotPresentObservation(DiagnosticReport diagnosticReport) {
268268
Observation observation = new Observation();
269269

270-
observation.setId(DUMMY_OBSERVATION_ID_PREFIX + randomIdGeneratorService.createNewId());
270+
observation.setId(NOT_PRESENT_OBSERVATION_ID_PREFIX + randomIdGeneratorService.createNewId());
271271

272272
return observation
273273
.setIssuedElement(diagnosticReport.getIssuedElement())

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package uk.nhs.adaptors.gp2gp.ehr.mapper.diagnosticreport;
22

3-
import static uk.nhs.adaptors.gp2gp.ehr.mapper.diagnosticreport.DiagnosticReportMapper.DUMMY_OBSERVATION_ID_PREFIX;
43

54
import java.util.List;
65
import java.util.Objects;
@@ -46,6 +45,8 @@
4645
import uk.nhs.adaptors.gp2gp.ehr.utils.StatementTimeMappingUtils;
4746
import uk.nhs.adaptors.gp2gp.ehr.utils.TemplateUtils;
4847

48+
import static uk.nhs.adaptors.gp2gp.ehr.mapper.diagnosticreport.DiagnosticReportMapper.NOT_PRESENT_OBSERVATION_ID_PREFIX;
49+
4950
@Component
5051
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
5152
@Slf4j
@@ -240,7 +241,7 @@ private String mapObservationToObservationStatement(MultiStatementObservationHol
240241
private Optional<String> prepareNarrativeStatements(MultiStatementObservationHolder holder, boolean interpretationCodeMapped) {
241242
Observation observation = holder.getObservation();
242243

243-
if (observation.getIdElement().getIdPart().contains(DUMMY_OBSERVATION_ID_PREFIX)) {
244+
if (observation.getIdElement().getIdPart().contains(NOT_PRESENT_OBSERVATION_ID_PREFIX)) {
244245
return Optional.of(
245246
mapObservationToNarrativeStatement(holder, observation.getComment(), CommentType.AGGREGATE_COMMENT_SET.getCode())
246247
);

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ void shouldAssignDummySpecimenOnlyToNonFilingObservationsWithoutSpecimen() {
155155
dummySpecimen.setId(NOT_PRESENT_SPECIMEN_ID_PREFIX + "123");
156156
List<Specimen> specimens = List.of(dummySpecimen);
157157

158-
List<Observation> result = mapper.assignDummySpecimensToObservationsWithNoSpecimen(observations, specimens);
158+
List<Observation> result = mapper.assignNotPresentSpecimensToObservationsWithNoSpecimen(observations, specimens);
159159

160160
assertThat(obsWithoutSpecimen.getSpecimen())
161161
.isNotNull()
@@ -178,7 +178,7 @@ void shouldThrowIfNoDummySpecimenFound() {
178178

179179
List<Specimen> specimens = List.of();
180180

181-
assertThatThrownBy(() -> mapper.assignDummySpecimensToObservationsWithNoSpecimen(observations, specimens))
181+
assertThatThrownBy(() -> mapper.assignNotPresentSpecimensToObservationsWithNoSpecimen(observations, specimens))
182182
.isInstanceOf(NoSuchElementException.class);
183183
}
184184

@@ -197,7 +197,7 @@ void shouldAssignDummySpecimenToObservationsWithoutSpecimen() {
197197
realSpecimen.setId("real-specimen");
198198
List<Specimen> specimens = List.of(realSpecimen, dummySpecimen);
199199

200-
List<Observation> result = mapper.assignDummySpecimensToObservationsWithNoSpecimen(observations, specimens);
200+
List<Observation> result = mapper.assignNotPresentSpecimensToObservationsWithNoSpecimen(observations, specimens);
201201

202202
assertThat(result).hasSize(2);
203203
assertThat(result.get(0).getSpecimen().getReference()).contains(dummySpecimen.getId());
@@ -412,7 +412,7 @@ void When_DiagnosticReport_Has_MultipleSpecimensAndOneObservation_Expect_ADummyO
412412

413413
assertThat(actualXml).containsIgnoringWhitespaces(
414414
"<!-- Mapped Specimen with id: Specimen/96B93E28-293D-46E7-B4C2-D477EEBF7098-SPEC-1 "
415-
+ "with linked Observations: DUMMY-OBSERVATION-5E496953-065B-41F2-9577-BE8F2FBD0757-->");
415+
+ "with linked Observations: NOT-PRESENT-OBSERVATION-5E496953-065B-41F2-9577-BE8F2FBD0757-->");
416416

417417
}
418418

@@ -438,11 +438,11 @@ void When_DiagnosticReport_Has_ThreeSpecimensAndOneObservation_Expect_DummyObser
438438

439439
assertThat(actualXml).containsIgnoringWhitespaces(
440440
"<!-- Mapped Specimen with id: Specimen/96B93E28-293D-46E7-B4C2-D477EEBF7098-SPEC-1 "
441-
+ "with linked Observations: DUMMY-OBSERVATION-5E496953-065B-41F2-9577-BE8F2FBD0757-->");
441+
+ "with linked Observations: NOT-PRESENT-OBSERVATION-5E496953-065B-41F2-9577-BE8F2FBD0757-->");
442442

443443
assertThat(actualXml).containsIgnoringWhitespaces(
444444
"<!-- Mapped Specimen with id: Specimen/96B93E28-293D-46E7-B4C2-D477EEBF7098-SPEC-2 "
445-
+ "with linked Observations: DUMMY-OBSERVATION-5E496953-065B-41F2-9577-BE8F2FBD0757-->");
445+
+ "with linked Observations: NOT-PRESENT-OBSERVATION-5E496953-065B-41F2-9577-BE8F2FBD0757-->");
446446
}
447447

448448
/**
@@ -472,7 +472,7 @@ void When_DiagnosticReport_Has_TwoLinkedSpecimensOneUnlinkedSpecimenAndOneObserv
472472

473473
assertThat(actualXml).containsIgnoringWhitespaces(
474474
"<!-- Mapped Specimen with id: Specimen/96B93E28-293D-46E7-B4C2-D477EEBF7098-SPEC-2 "
475-
+ "with linked Observations: DUMMY-OBSERVATION-5E496953-065B-41F2-9577-BE8F2FBD0757-->");
475+
+ "with linked Observations: NOT-PRESENT-OBSERVATION-5E496953-065B-41F2-9577-BE8F2FBD0757-->");
476476
}
477477

478478
@Test

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,8 @@ class ObservationMapperTest {
9090
"observation_test_group_header.json";
9191
private static final String OBSERVATION_TEST_RESULT_JSON =
9292
"observation_test_result.json";
93+
private static final String NOT_PRESENT_OBSERVATION_RESULT_JSON =
94+
"not_present_observation.json";
9395
private static final String OBSERVATION_FILING_COMMENT_JSON =
9496
"observation_filing_comment.json";
9597
private static final String OBSERVATION_ASSOCIATED_WITH_IGNORED_MEMBER_JSON =
@@ -273,6 +275,21 @@ void When_MappingTestResult_With_NopatMetaSecurity_Expect_ConfidentialityCodeWit
273275
assertThatXml(actualXml).containsXPath(OBSERVATION_STATEMENT_CONFIDENTIALITY_CODE_XPATH);
274276
}
275277

278+
@Test
279+
void When_ObservationDoesNotContainNotPresentElements_Expect_MappedObservetionNotContainAggregateComments() {
280+
final Observation not_present_observation = getObservationResourceFromJson(NOT_PRESENT_OBSERVATION_RESULT_JSON);
281+
String expression = "//component/NarrativeStatement/text[contains(normalize-space(.), 'AGGREGATE COMMENT SET')]";
282+
283+
ConfidentialityCodeUtility.appendNopatSecurityToMetaForResource(not_present_observation);
284+
when(confidentialityService.generateConfidentialityCode(not_present_observation))
285+
.thenReturn(Optional.of(NOPAT_HL7_CONFIDENTIALITY_CODE));
286+
287+
final String actualXml = observationMapper.mapObservationToCompoundStatement(not_present_observation);
288+
String wrappedXml = "<root>" + actualXml + "</root>";
289+
290+
assertThatXml(wrappedXml).containsXPath(expression);
291+
}
292+
276293
@Test
277294
void When_MappingTestResult_With_NoscrubMetaSecurity_Expect_ConfidentialityCodeNotPresent() {
278295
final Observation observation = getObservationResourceFromJson(OBSERVATION_TEST_RESULT_JSON);

service/src/test/resources/ehr/mapper/diagnosticreport/diagnostic-report-with-multi-specimens.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ Status: unknown</text>
2020
<availabilityTime value="20100225154100"/>
2121
</NarrativeStatement>
2222
</component>
23-
<!-- Mapped Specimen with id: Specimen/96B93E28-293D-46E7-B4C2-D477EEBF7098-SPEC-0 with linked Observations: DUMMY-OBSERVATION-5E496953-065B-41F2-9577-BE8F2FBD0757-->
24-
<!-- Mapped Specimen with id: Specimen/96B93E28-293D-46E7-B4C2-D477EEBF7098-SPEC-1 with linked Observations: DUMMY-OBSERVATION-5E496953-065B-41F2-9577-BE8F2FBD0757-->
25-
<!-- Mapped Specimen with id: Specimen/96B93E28-293D-46E7-B4C2-D477EEBF7098-SPEC-2 with linked Observations: DUMMY-OBSERVATION-5E496953-065B-41F2-9577-BE8F2FBD0757-->
23+
<!-- Mapped Specimen with id: Specimen/96B93E28-293D-46E7-B4C2-D477EEBF7098-SPEC-0 with linked Observations: NOT-PRESENT-OBSERVATION-5E496953-065B-41F2-9577-BE8F2FBD0757-->
24+
<!-- Mapped Specimen with id: Specimen/96B93E28-293D-46E7-B4C2-D477EEBF7098-SPEC-1 with linked Observations: NOT-PRESENT-OBSERVATION-5E496953-065B-41F2-9577-BE8F2FBD0757-->
25+
<!-- Mapped Specimen with id: Specimen/96B93E28-293D-46E7-B4C2-D477EEBF7098-SPEC-2 with linked Observations: NOT-PRESENT-OBSERVATION-5E496953-065B-41F2-9577-BE8F2FBD0757-->
2626
</CompoundStatement>
2727
</component>

service/src/test/resources/ehr/mapper/diagnosticreport/diagnostic-report-with-one-specimen.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,6 @@ Status: unknown</text>
2020
<availabilityTime value="20100225154100"/>
2121
</NarrativeStatement>
2222
</component>
23-
<!-- Mapped Specimen with id: Specimen/96B93E28-293D-46E7-B4C2-D477EEBF7098-SPEC-0 with linked Observations: DUMMY-OBSERVATION-5E496953-065B-41F2-9577-BE8F2FBD0757-->
23+
<!-- Mapped Specimen with id: Specimen/96B93E28-293D-46E7-B4C2-D477EEBF7098-SPEC-0 with linked Observations: NOT-PRESENT-OBSERVATION-5E496953-065B-41F2-9577-BE8F2FBD0757-->
2424
</CompoundStatement>
2525
</component>
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
{
2+
"resourceType": "Observation",
3+
"id": "NOT-PRESENT-OBSERVATION-32685afe-1d46-4d98-8279-39b9e96ee914",
4+
"meta":
5+
{
6+
"profile": [
7+
"https://fhir.nhs.uk/STU3/StructureDefinition/CareConnect-GPC-Observation-1"
8+
]
9+
},
10+
"identifier": [
11+
{
12+
"system": "https://tools.ietf.org/html/rfc4122",
13+
"value": "2af46949-4938-4c57-bad4-c4363e1965d7"
14+
}
15+
],
16+
"status": "final",
17+
"category": [
18+
{
19+
"coding": [
20+
{
21+
"system": "http://snomed.info/sct",
22+
"code": "394595002",
23+
"display": "Pathology"
24+
}
25+
]
26+
}
27+
],
28+
"code": {
29+
"coding": [
30+
{
31+
"system": "http://snomed.info/sct",
32+
"code": "1022451000000103",
33+
"display": "Red blood cell count"
34+
}
35+
]
36+
},
37+
"subject": {
38+
"reference": "Patient/11",
39+
"display": "SKELLY, Horace"
40+
},
41+
"issued": "2019-04-06T12:00:00+00:00",
42+
"performer": [
43+
{
44+
"reference": "Organization/7",
45+
"display": "COXWOLD Surgery"
46+
}
47+
],
48+
"valueQuantity": {
49+
"value": 4.5700000000000003,
50+
"unit": "10*12/L"
51+
},
52+
"specimen": {
53+
"reference": "Specimen/756a8361-79ce-4561-afcb-a91fe19df123"
54+
}
55+
}

0 commit comments

Comments
 (0)