Skip to content

Commit 0b3c27c

Browse files
NIAD-3222: GP2GP adaptor generates an empty CompoundStatement/code which fails the transfer. (#982)
Replace String.Empty when preparing the code element mapping ObservationMapper so that an EhrMapperException is thrown containing the resource identifier. Add test to ensure this exception is found and contains the resource id. Update NOPAT test and associated resource file which previously did not contain a code element Update CHANGELOG.md
1 parent 6f8a136 commit 0b3c27c

File tree

4 files changed

+26
-2
lines changed

4 files changed

+26
-2
lines changed

CHANGELOG.md

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

99
## Fixed
1010

11+
* When mapping an `Observation` related to a diagnostic report which does not contain a `code` element, the adaptor will
12+
now throw an error reporting that an observation requires a code element and provide the affected resource ID.
1113
* When mapping a `valueQuantity` contained in an `Observation`, the produced XML `<value>` element now correctly escapes
1214
any contained XML characters.
1315

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -488,7 +488,7 @@ private String prepareCodeElement(Observation observation) {
488488
return codeableConceptCdMapper.mapCodeableConceptToCd(observation.getCode());
489489
}
490490

491-
return StringUtils.EMPTY;
491+
throw new EhrMapperException("%s must contain a code element.".formatted(observation.getId()));
492492
}
493493

494494
private CompoundStatementClassCode prepareClassCode(List<MultiStatementObservationHolder> derivedObservations) {

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

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import uk.nhs.adaptors.gp2gp.common.service.ConfidentialityService;
2222
import uk.nhs.adaptors.gp2gp.common.service.FhirParseService;
2323
import uk.nhs.adaptors.gp2gp.common.service.RandomIdGeneratorService;
24+
import uk.nhs.adaptors.gp2gp.ehr.exception.EhrMapperException;
2425
import uk.nhs.adaptors.gp2gp.ehr.mapper.AgentDirectory;
2526
import uk.nhs.adaptors.gp2gp.ehr.mapper.CodeableConceptCdMapper;
2627
import uk.nhs.adaptors.gp2gp.ehr.mapper.IdMapper;
@@ -36,6 +37,7 @@
3637
import java.util.stream.Stream;
3738

3839
import static org.assertj.core.api.Assertions.assertThat;
40+
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
3941
import static org.junit.jupiter.api.Assertions.assertAll;
4042
import static org.mockito.ArgumentMatchers.any;
4143
import static org.mockito.Mockito.lenient;
@@ -222,10 +224,21 @@ void When_MappingTestGroupHeader_With_NopatMetaSecurity_Expect_ConfidentialityCo
222224

223225
assertAll(
224226
() -> assertThatXml(actualXml).containsXPath(COMPOUND_STATEMENT_CONFIDENTIALITY_CODE_XPATH),
225-
() -> assertThat(metaWithNopat).hasSize(1)
227+
() -> assertThat(metaWithNopat).hasSize(2)
226228
);
227229
}
228230

231+
@Test
232+
void When_MappingTestGroupHeader_WithoutCode_Expect_ExceptionThrownContainingId() {
233+
final Observation observation = getObservationResourceFromJson(OBSERVATION_TEST_GROUP_HEADER_JSON);
234+
observation.setCode(null);
235+
236+
assertThatExceptionOfType(EhrMapperException.class)
237+
.isThrownBy(() -> observationMapper.mapObservationToCompoundStatement(observation))
238+
.withMessageContaining(observation.getId());
239+
240+
}
241+
229242
@Test
230243
void When_MappingTestGroupHeader_With_NoscrubMetaSecurity_Expect_ConfidentialityCodeNotPresent() {
231244
final Observation observation = getObservationResourceFromJson(OBSERVATION_TEST_GROUP_HEADER_JSON);

service/src/test/resources/ehr/mapper/diagnosticreport/observation/observation_test_group_header.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,15 @@
66
"https://fhir.nhs.uk/STU3/StructureDefinition/CareConnect-GPC-Observation-1"
77
]
88
},
9+
"code": {
10+
"coding": [
11+
{
12+
"system": "http://snomed.info/sct",
13+
"code": "242247008",
14+
"display": "Collision of spacecraft with meteorite"
15+
}
16+
]
17+
},
918
"identifier": [
1019
{
1120
"system": "https://EMISWeb/A82038",

0 commit comments

Comments
 (0)