diff --git a/service/src/main/java/uk/nhs/adaptors/gp2gp/ehr/mapper/diagnosticreport/DiagnosticReportMapper.java b/service/src/main/java/uk/nhs/adaptors/gp2gp/ehr/mapper/diagnosticreport/DiagnosticReportMapper.java index f2009e4de7..066a06727b 100644 --- a/service/src/main/java/uk/nhs/adaptors/gp2gp/ehr/mapper/diagnosticreport/DiagnosticReportMapper.java +++ b/service/src/main/java/uk/nhs/adaptors/gp2gp/ehr/mapper/diagnosticreport/DiagnosticReportMapper.java @@ -87,7 +87,9 @@ public String mapDiagnosticReportToCompoundStatement(DiagnosticReport diagnostic specimens); String mappedSpecimens = specimens.stream() - .map(specimen -> specimenMapper.mapSpecimenToCompoundStatement(specimen, observationsExcludingFilingComments, diagnosticReport)) + .map(specimen -> specimenMapper.mapSpecimenToCompoundStatement(specimen, + observationsForSpecimen(specimen, observationsExcludingFilingComments), + diagnosticReport)) .collect(Collectors.joining()); String reportLevelNarrativeStatements = prepareReportLevelNarrativeStatements(diagnosticReport, observations); @@ -113,6 +115,13 @@ public String mapDiagnosticReportToCompoundStatement(DiagnosticReport diagnostic ); } + private List observationsForSpecimen(Specimen specimen, List observations) { + return observations.stream() + .filter(Observation::hasSpecimen) + .filter(observation -> observation.getSpecimen().getReference().equals(specimen.getId())) + .collect(Collectors.toList()); + } + private String fetchExtensionId(List identifiers) { return identifiers.stream() .filter(DiagnosticReportMapper::isPMIPCodeSystem) diff --git a/service/src/test/java/uk/nhs/adaptors/gp2gp/ehr/mapper/diagnosticreport/SpecimenMapperTest.java b/service/src/test/java/uk/nhs/adaptors/gp2gp/ehr/mapper/diagnosticreport/SpecimenMapperTest.java index 452c850362..e30749a61d 100644 --- a/service/src/test/java/uk/nhs/adaptors/gp2gp/ehr/mapper/diagnosticreport/SpecimenMapperTest.java +++ b/service/src/test/java/uk/nhs/adaptors/gp2gp/ehr/mapper/diagnosticreport/SpecimenMapperTest.java @@ -139,7 +139,7 @@ void When_MappingDefaultSpecimenWithObservation_Expect_DefaultSpecimenAndObserva final String actualXml = specimenMapper.mapSpecimenToCompoundStatement( specimen, observations, DIAGNOSTIC_REPORT); - assertThat(actualXml).isEqualTo(expectedXml); + assertThat(actualXml).isEqualToIgnoringWhitespace(expectedXml); } @Test diff --git a/service/src/test/resources/ehr/mapper/diagnosticreport/diagnostic-report-with-no-specimen.json b/service/src/test/resources/ehr/mapper/diagnosticreport/diagnostic-report-with-no-specimen.json index 1d25fa39c2..d1486bc558 100644 --- a/service/src/test/resources/ehr/mapper/diagnosticreport/diagnostic-report-with-no-specimen.json +++ b/service/src/test/resources/ehr/mapper/diagnosticreport/diagnostic-report-with-no-specimen.json @@ -54,7 +54,7 @@ "reference": "Observation/FILING-COMMENT-WITH-NO-COMMENT" }, { - "reference": "Observation/6E30A9E3-FF9A-4868-8FCD-7DAC26A16E78" + "reference": "Observation/TestResult-WithoutSpecimenReference" } ] } \ No newline at end of file diff --git a/service/src/test/resources/ehr/mapper/diagnosticreport/diagnostic-report-with-no-specimen.xml b/service/src/test/resources/ehr/mapper/diagnosticreport/diagnostic-report-with-no-specimen.xml index a32421b9de..9fe37d75a0 100644 --- a/service/src/test/resources/ehr/mapper/diagnosticreport/diagnostic-report-with-no-specimen.xml +++ b/service/src/test/resources/ehr/mapper/diagnosticreport/diagnostic-report-with-no-specimen.xml @@ -68,8 +68,8 @@ - - + + Mocked code @@ -78,46 +78,19 @@
- - - - - Mocked code - - - -
- - - - - mmol/L - - - - - - - - - - - - - - - - - CommentType:USER COMMENT - CommentDate:20201215151713 + + + + + + CommentType:AGGREGATE COMMENT SET + CommentDate:20100223 - (q) - Normal - No Action - - - - - - + This is a test result without a specimen. + + + + diff --git a/service/src/test/resources/ehr/request/fhir/output/expected-xml-with-standalone-observations.xml b/service/src/test/resources/ehr/request/fhir/output/expected-xml-with-standalone-observations.xml index 8a5f1a6c55..5fce2b723a 100644 --- a/service/src/test/resources/ehr/request/fhir/output/expected-xml-with-standalone-observations.xml +++ b/service/src/test/resources/ehr/request/fhir/output/expected-xml-with-standalone-observations.xml @@ -1,293 +1,296 @@ - - - + + + - + - - + - - + + - + - - - - - - - Unknown - - - - TEMPLE SOWERBY MEDICAL PRACTICE - - - - - - - - - Unknown - - - - Dr - David - McAvenue - - - - - - - - - - - - -
- - - - - - - - - - - - - - Filed Report - - - -
- - - - - - CommentType:LABORATORY RESULT COMMENT(E141) -CommentDate:20030221115000 + + + + + + Unknown + + + + TEMPLE SOWERBY MEDICAL PRACTICE + + + + + + + + + Unknown + + + + Dr + David + McAvenue + + + + + + + + + + + + +
+ + + + + + + + + + + + + + Filed Report + + + +
+ + + + + + CommentType:LABORATORY RESULT COMMENT(E141) + CommentDate:20030221115000 -Status: unknown - - - - - - - - - - -
- - - - - - - -
- - - UNKNOWN - - - - - - - CommentType:AGGREGATE COMMENT SET - CommentDate:UNK + Status: unknown + + + + + + + + + + + +
+ + + + + + + +
+ + + UNKNOWN + + + + + + + CommentType:AGGREGATE COMMENT SET + CommentDate:UNK - EMPTY REPORT - - - - - - - - - - - -
- - - - - - - -
- - - Blood - - - - - - - CommentType:LAB SPECIMEN COMMENT(E271) -CommentDate:20030109000000 + EMPTY REPORT + + + + + + + + + + + + + +
+ + + + + + + +
+ + + Blood + + + + + + + CommentType:LAB SPECIMEN COMMENT(E271) + CommentDate:20030109000000 -Received Date: 2003-01-09 13:54 - - - - - - - - - CommentType:AGGREGATE COMMENT SET -CommentDate:UNK + Received Date: 2003-01-09 13:54 -EMPTY REPORT - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - This is some random free text - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - Mocked code - - -
- - + EMPTY SPECIMEN + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + This is some random free text + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + Mocked code + + + +
+ + - - - - - - + + + + + + - - - - - - - - - + + + + + + + + + - + - - + +