Skip to content

Commit 23918de

Browse files
Niad 3304 bug fix for description display (#1150)
* * Remove duplicated test * * Amended test for when Description extension is present with nested display extension when mapping to null flavor codeable concept, to now allow the original text to be taken from the display extension. * Remove now unneeded function overrides and wrappers which were in place to work around this existing bug. * Refactor `findOriginalText` to use existing method to retrieve original text * * Add CHANGELOG.md * * Remove now unused method in the test file.
1 parent a43c118 commit 23918de

File tree

5 files changed

+12
-74
lines changed

5 files changed

+12
-74
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
66

77
## [Unreleased]
88

9+
### Fixed
10+
11+
* When mapping to `<code nullFlavor="UNK">` XML elements from an existing `CodeableConcept` the element will now contain
12+
the original text value from the DisplayExtension, if a separate text field is not provided.
13+
In the case that neither of these are present, the existing behavior of using the `code.display` element is used.
14+
915
### Added
1016

1117
* GP2GP Adaptor now populates the PlanStatement / confidentialityCode field

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

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import java.util.List;
55
import java.util.Optional;
66
import java.util.function.BiFunction;
7-
import java.util.function.Function;
87

98
import org.apache.commons.lang3.StringUtils;
109
import org.hl7.fhir.dstu3.model.AllergyIntolerance;
@@ -153,7 +152,7 @@ public String mapCodeableConceptToCdForBloodPressure(CodeableConcept codeableCon
153152
var mainCode = getSnomedCodeCoding(codeableConcept);
154153

155154
builder.nullFlavor(mainCode.isEmpty());
156-
var originalText = findOriginalTextUsingNestedDisplayExtension(codeableConcept, mainCode);
155+
var originalText = findOriginalText(codeableConcept, mainCode);
157156
originalText.ifPresent(builder::mainOriginalText);
158157

159158
if (mainCode.isPresent()) {
@@ -325,10 +324,7 @@ private List<Coding> getNonSnomedCodeCodings(CodeableConcept codeableConcept) {
325324
return nonSnomedCodeCodings;
326325
}
327326

328-
private Optional<String> findOriginalText(
329-
CodeableConcept codeableConcept,
330-
Optional<Coding> coding,
331-
Function<Coding, Optional<String>> findOriginalTextInDisplayExtension) {
327+
private Optional<String> findOriginalText(CodeableConcept codeableConcept, Optional<Coding> coding) {
332328

333329
if (codeableConcept.hasText()) {
334330
return Optional.ofNullable(codeableConcept.getText());
@@ -339,20 +335,12 @@ private Optional<String> findOriginalText(
339335
return getCodingDisplayName(coding.get());
340336
}
341337

342-
return findOriginalTextInDisplayExtension.apply(coding.get());
338+
return getDisplayTextFromDescriptionExtension(coding.get());
343339
}
344340

345341
return CodeableConceptMappingUtils.extractTextOrCoding(codeableConcept);
346342
}
347343

348-
private Optional<String> findOriginalText(CodeableConcept codeableConcept, Optional<Coding> coding) {
349-
return findOriginalText(codeableConcept, coding, codingParameter -> Optional.empty());
350-
}
351-
352-
private Optional<String> findOriginalTextUsingNestedDisplayExtension(CodeableConcept codeableConcept, Optional<Coding> coding) {
353-
return findOriginalText(codeableConcept, coding, this::getDisplayTextFromDescriptionExtension);
354-
}
355-
356344
private Optional<String> findOriginalTextForAllergy(
357345
CodeableConcept codeableConcept,
358346
Optional<Coding> coding,

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

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323

2424
public class CodeableConceptCdMapperTest {
2525
private static final String TEST_FILE_DIRECTORY = "/ehr/mapper/codeableconcept/";
26-
private static final String TEST_FILE_DIRECTORY_NULL_FLAVOR = "/ehr/mapper/codeableconcept/nullFlavor/";
2726
private static final String TEST_FILE_DIRECTORY_ACTUAL_PROBLEM = "/ehr/mapper/codeableconcept/actualProblem/";
2827
private static final String TEST_FILE_DIRECTORY_ALLERGY_RESOLVED = "/ehr/mapper/codeableconcept/allergyResolved/";
2928
private static final String TEST_FILE_DIRECTORY_ALLERGY_ACTIVE = "/ehr/mapper/codeableconcept/allergyActive/";
@@ -48,10 +47,6 @@ private static Stream<Arguments> getTestArguments() {
4847
return TestArgumentsLoaderUtil.readTestCases(TEST_FILE_DIRECTORY);
4948
}
5049

51-
private static Stream<Arguments> getTestArgumentsNullFlavor() {
52-
return TestArgumentsLoaderUtil.readTestCases(TEST_FILE_DIRECTORY_NULL_FLAVOR);
53-
}
54-
5550
private static Stream<Arguments> getTestArgumentsActualProblem() {
5651
return TestArgumentsLoaderUtil.readTestCases(TEST_FILE_DIRECTORY_ACTUAL_PROBLEM);
5752
}
@@ -184,20 +179,6 @@ public void When_MappingStubbedCodeableConceptForActualProblemHeader_Expect_HL7C
184179
.isEqualToIgnoringWhitespace(expectedOutput);
185180
}
186181

187-
@ParameterizedTest
188-
@MethodSource("getTestArgumentsNullFlavor")
189-
public void When_MappingStubbedCodeableConceptAsNullFlavor_Expect_HL7CdObjectXml(String inputJson, String outputXml)
190-
throws IOException {
191-
var observationCodeableConcept = ResourceTestFileUtils.getFileContent(inputJson);
192-
var expectedOutput = ResourceTestFileUtils.getFileContent(outputXml);
193-
var codeableConcept = fhirParseService.parseResource(observationCodeableConcept, Observation.class).getCode();
194-
195-
var outputMessage = codeableConceptCdMapper.mapToNullFlavorCodeableConcept(codeableConcept);
196-
assertThat(outputMessage)
197-
.describedAs(TestArgumentsLoaderUtil.FAIL_MESSAGE, inputJson, outputXml)
198-
.isEqualToIgnoringWhitespace(expectedOutput);
199-
}
200-
201182
@ParameterizedTest
202183
@MethodSource("getTestArgumentsAllergyResolved")
203184
void When_MappingStubbedCodeableConceptAsResolvedAllergy_Expect_HL7CdObjectXml(String inputJson, String outputXml) {
@@ -502,6 +483,7 @@ void When_WithSnomedCodingNoTextNoDisplayWithDescriptionExtensionWithDisplayExte
502483

503484
var expectedOutput = """
504485
<code nullFlavor="UNK">
486+
<originalText>Prothrombin time (observed)</originalText>
505487
</code>""";
506488
var codeableConcept = fhirParseService.parseResource(inputJson, Observation.class).getCode();
507489

@@ -522,7 +504,7 @@ void When_WithSnomedCodingNoTextNoDisplayWithNonDescriptionExtension_Expect_Snom
522504
"code": "852471000000107",
523505
"extension": [
524506
{
525-
"url": "https://fhir.nhs.uk/STU3/StructureDefinition/Extension-coding-sctdescid",
507+
"url": "https://fhir.nhs.uk/STU3/StructureDefinition/Extension-some-other",
526508
"extension": [
527509
{
528510
"url": "descriptionDisplay",
@@ -547,7 +529,7 @@ void When_WithSnomedCodingNoTextNoDisplayWithNonDescriptionExtension_Expect_Snom
547529
}
548530

549531
@Test
550-
void When_WithNonSnomedCodingWithText_Expect_SnomedCdXmlWithOriginalTexFromText() {
532+
void When_WithNonSnomedCodingWithText_Expect_SnomedCdXmlWithOriginalTextFromText() {
551533
var inputJson = """
552534
{
553535
"resourceType": "Observation",

service/src/test/resources/ehr/mapper/codeableconcept/nullFlavor/codeable_concept_with_text.json

Lines changed: 0 additions & 35 deletions
This file was deleted.

service/src/test/resources/ehr/mapper/codeableconcept/nullFlavor/codeable_concept_with_text.xml

Lines changed: 0 additions & 3 deletions
This file was deleted.

0 commit comments

Comments
 (0)