Skip to content

Commit 7907883

Browse files
NIAD 3217 - Fix duplicated Test Results (#1001)
* Reformat xml file * Fixed duplication of test reports during mapping * Adding medications scenarios from PR 958 * Adding WireMock request for Investigations * Remove space at end of file name * Removing wiremock files. --------- Co-authored-by: Steven McCullagh <[email protected]>
1 parent 27a362d commit 7907883

File tree

5 files changed

+275
-290
lines changed

5 files changed

+275
-290
lines changed

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,9 @@ public String mapDiagnosticReportToCompoundStatement(DiagnosticReport diagnostic
8787
specimens);
8888

8989
String mappedSpecimens = specimens.stream()
90-
.map(specimen -> specimenMapper.mapSpecimenToCompoundStatement(specimen, observationsExcludingFilingComments, diagnosticReport))
90+
.map(specimen -> specimenMapper.mapSpecimenToCompoundStatement(specimen,
91+
observationsForSpecimen(specimen, observationsExcludingFilingComments),
92+
diagnosticReport))
9193
.collect(Collectors.joining());
9294

9395
String reportLevelNarrativeStatements = prepareReportLevelNarrativeStatements(diagnosticReport, observations);
@@ -113,6 +115,13 @@ public String mapDiagnosticReportToCompoundStatement(DiagnosticReport diagnostic
113115
);
114116
}
115117

118+
private List<Observation> observationsForSpecimen(Specimen specimen, List<Observation> observations) {
119+
return observations.stream()
120+
.filter(Observation::hasSpecimen)
121+
.filter(observation -> observation.getSpecimen().getReference().equals(specimen.getId()))
122+
.collect(Collectors.toList());
123+
}
124+
116125
private String fetchExtensionId(List<Identifier> identifiers) {
117126
return identifiers.stream()
118127
.filter(DiagnosticReportMapper::isPMIPCodeSystem)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ void When_MappingDefaultSpecimenWithObservation_Expect_DefaultSpecimenAndObserva
139139
final String actualXml = specimenMapper.mapSpecimenToCompoundStatement(
140140
specimen, observations, DIAGNOSTIC_REPORT);
141141

142-
assertThat(actualXml).isEqualTo(expectedXml);
142+
assertThat(actualXml).isEqualToIgnoringWhitespace(expectedXml);
143143
}
144144

145145
@Test

service/src/test/resources/ehr/mapper/diagnosticreport/diagnostic-report-with-no-specimen.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
"reference": "Observation/FILING-COMMENT-WITH-NO-COMMENT"
5555
},
5656
{
57-
"reference": "Observation/6E30A9E3-FF9A-4868-8FCD-7DAC26A16E78"
57+
"reference": "Observation/TestResult-WithoutSpecimenReference"
5858
}
5959
]
6060
}

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

Lines changed: 14 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,8 @@
6868
</specimenRole>
6969
</specimen>
7070
<component typeCode="COMP" contextConductionInd="true">
71-
<CompoundStatement classCode="CLUSTER" moodCode="EVN">
72-
<id root="II-for-Observation-Observation/6E30A9E3-FF9A-4868-8FCD-7DAC26A16E78"/>
71+
<ObservationStatement classCode="OBS" moodCode="EVN">
72+
<id root="II-for-Observation-Observation/TestResult-WithoutSpecimenReference"/>
7373
<code nullFlavor="UNK">
7474
<originalText>Mocked code</originalText>
7575
</code>
@@ -78,46 +78,19 @@
7878
<center value="20100223"/>
7979
</effectiveTime>
8080
<availabilityTime value="20100223"/>
81-
<component typeCode="COMP" contextConductionInd="true">
82-
<ObservationStatement classCode="OBS" moodCode="EVN">
83-
<id root="5E496953-065B-41F2-9577-BE8F2FBD0757"/>
84-
<code nullFlavor="UNK">
85-
<originalText>Mocked code</originalText>
86-
</code>
87-
<statusCode code="COMPLETE"/>
88-
<effectiveTime>
89-
<center value="20100223"/>
90-
</effectiveTime>
91-
<availabilityTime value="20100223"/>
92-
<value xsi:type="PQ" value="8.800" unit="1">
93-
<translation value="8.800">
94-
<originalText>mmol/L</originalText>
95-
</translation>
96-
</value>
97-
<referenceRange typeCode="REFV">
98-
<referenceInterpretationRange classCode="OBS" moodCode="EVN.CRT">
99-
<value>
100-
<low value="10.000"/>
101-
<high value="90.000"/>
102-
</value>
103-
</referenceInterpretationRange>
104-
</referenceRange>
105-
106-
</ObservationStatement>
107-
</component>
108-
<component typeCode="COMP" contextConductionInd="true">
109-
<NarrativeStatement classCode="OBS" moodCode="EVN">
110-
<id root="II-for-Observation-Observation/6E30A9E3-FF9A-4868-8FCD-7DAC26A16E78-COMM"/>
111-
<text mediaType="text/x-h7uk-pmip">CommentType:USER COMMENT
112-
CommentDate:20201215151713
81+
</ObservationStatement>
82+
</component>
83+
<component typeCode="COMP" contextConductionInd="true">
84+
<NarrativeStatement classCode="OBS" moodCode="EVN">
85+
<id root="5E496953-065B-41F2-9577-BE8F2FBD0757"/>
86+
<text mediaType="text/x-h7uk-pmip">CommentType:AGGREGATE COMMENT SET
87+
CommentDate:20100223
11388

114-
(q) - Normal - No Action
115-
</text>
116-
<statusCode code="COMPLETE"/>
117-
<availabilityTime value="20201215151713"/>
118-
</NarrativeStatement>
119-
</component>
120-
</CompoundStatement>
89+
This is a test result without a specimen.
90+
</text>
91+
<statusCode code="COMPLETE"/>
92+
<availabilityTime value="20100223"/>
93+
</NarrativeStatement>
12194
</component>
12295
</CompoundStatement>
12396
</component>

0 commit comments

Comments
 (0)