Skip to content

Commit 3a7c375

Browse files
committed
Fixed test data
Added placeholder for new linking between specimen and observation, and removed the old one. Added test for the second scenario and fixed the test data.
1 parent ff830ba commit 3a7c375

File tree

3 files changed

+46
-14
lines changed

3 files changed

+46
-14
lines changed

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

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,13 +111,15 @@ private String fetchExtensionId(List<Identifier> identifiers) {
111111

112112
private List<Specimen> fetchSpecimens(DiagnosticReport diagnosticReport) {
113113

114-
//if there are any orphan diagnostic reports, add a dummy specimen to each of them
114+
//if there are any orphan observations, add a dummy specimen to each of them
115115

116116
if (!diagnosticReport.hasSpecimen()) {
117117
return Collections.singletonList(generateDefaultSpecimen(diagnosticReport));
118118
}
119119

120-
var inputBundleHolder = messageContext.getInputBundleHolder();
120+
fixOrphanedTestResults(diagnosticReport);
121+
122+
InputBundle inputBundleHolder = messageContext.getInputBundleHolder();
121123
return diagnosticReport.getSpecimen()
122124
.stream()
123125
.map(specimenReference -> inputBundleHolder.getResource(specimenReference.getReferenceElement()))
@@ -126,6 +128,22 @@ private List<Specimen> fetchSpecimens(DiagnosticReport diagnosticReport) {
126128
.collect(Collectors.toList());
127129
}
128130

131+
private void fixOrphanedTestResults(DiagnosticReport diagnosticReport) {
132+
133+
134+
if (diagnosticReport.hasResult()){
135+
List<Reference> results = diagnosticReport.getResult();
136+
List<Reference> specimens = diagnosticReport.getSpecimen();
137+
for (Reference specimen : specimens){
138+
139+
}
140+
for (Reference result : results) {
141+
//
142+
//check each test result one by one, and if it doesn't have a dummy assigned to it, assign it.
143+
}
144+
}
145+
}
146+
129147
private Specimen generateDefaultSpecimen(DiagnosticReport diagnosticReport) {
130148
Specimen specimen = new Specimen();
131149

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

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -137,18 +137,8 @@ private Optional<String> buildSpecimenMaterialType(Specimen specimen) {
137137
}
138138

139139
private String mapObservationsAssociatedWithSpecimen(Specimen specimen, List<Observation> observations) {
140-
List<Observation> observationsAssociatedWithSpecimen;
141-
142-
if (dummySpecimenOrObservationExists(specimen, observations)) {
143-
observationsAssociatedWithSpecimen = observations;
144-
} else {
145-
observationsAssociatedWithSpecimen = observations.stream()
146-
.filter(Observation::hasSpecimen)
147-
.filter(observation -> observation.getSpecimen().getReference().equals(specimen.getId()))
148-
.collect(Collectors.toList());
149-
}
150140

151-
return observationsAssociatedWithSpecimen.stream()
141+
return observations.stream()
152142
.filter(Predicate.not(DiagnosticReportMapper::isFilingComment))
153143
.map(observationMapper::mapObservationToCompoundStatement)
154144
.collect(Collectors.joining());

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

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,19 @@ void When_DiagnosticReport_Has_SpecimenAndUnlinkedTestResult_ExpectADummySpecime
308308
assertThat(actualXml).contains("Mapped Specimen with id: DUMMY-SPECIMEN-");
309309
}
310310

311+
@Test
312+
void When_DiagnosticReport_Has_SpecimenAndUnlinkedTestResult_ExpectScenario2() {
313+
final String diagnosticReportFileName = "diagnostic-report-with-one-specimen-one-linked-observation-and-one-unlinked-observation.json";
314+
final DiagnosticReport diagnosticReport = getDiagnosticReportResourceFromJson(diagnosticReportFileName);
315+
final Bundle bundle = getBundleResourceFromJson(INPUT_JSON_BUNDLE);
316+
final InputBundle inputBundle = new InputBundle(bundle);
317+
318+
when(messageContext.getInputBundleHolder()).thenReturn(inputBundle);
319+
320+
final String actualXml = mapper.mapDiagnosticReportToCompoundStatement(diagnosticReport);
321+
assertThat(actualXml).contains("Mapped Specimen with id: DUMMY-SPECIMEN-");
322+
}
323+
311324
private Bundle getBundleResourceFromJson(String filename) {
312325
final String filePath = TEST_FILE_DIRECTORY + filename;
313326
return FileParsingUtility.parseResourceFromJsonFile(filePath, Bundle.class);
@@ -359,7 +372,18 @@ private Answer<String> mockIdForReference() {
359372
private Answer<String> mockSpecimenMapping() {
360373
return invocation -> {
361374
Specimen specimen = invocation.getArgument(0);
362-
return String.format("<!-- Mapped Specimen with id: %s -->", specimen.getId());
375+
List<Observation> observations = invocation.getArgument(1);
376+
377+
String linkedObservations = "";
378+
379+
for (Observation observation : observations) {
380+
if(observation.getSpecimen().getReference() != null && observation.getSpecimen().getReference().equals(specimen.getId())){
381+
linkedObservations = linkedObservations + observation.getId() + ", ";
382+
}
383+
}
384+
385+
386+
return String.format("<!-- Mapped Specimen with id: %s with linked Observations: %s-->", specimen.getId(), linkedObservations);
363387
};
364388
}
365389
}

0 commit comments

Comments
 (0)