Skip to content

Commit 349af66

Browse files
committed
observation with NOPAT get translated into narrative with confidentialityCode
1 parent 9ba32c5 commit 349af66

File tree

8 files changed

+296
-13
lines changed

8 files changed

+296
-13
lines changed

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

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -255,32 +255,32 @@ private Optional<String> mapDefaultNotImplemented(Resource resource) {
255255
resource.getIdElement().getIdPart()));
256256
}
257257

258-
private Optional<String> mapAllergyIntolerance(Resource resource) {
258+
protected Optional<String> mapAllergyIntolerance(Resource resource) {
259259
return Optional.of(allergyStructureMapper.mapAllergyIntoleranceToAllergyStructure((AllergyIntolerance) resource));
260260
}
261261

262-
private Optional<String> mapCondition(Resource resource) {
262+
protected Optional<String> mapCondition(Resource resource) {
263263
return Optional.of(conditionLinkSetMapper.mapConditionToLinkSet((Condition) resource, IS_NESTED));
264264
}
265265

266-
private Optional<String> mapDocumentReference(Resource resource) {
266+
protected Optional<String> mapDocumentReference(Resource resource) {
267267
return Optional.of(
268268
documentReferenceToNarrativeStatementMapper.mapDocumentReferenceToNarrativeStatement((DocumentReference) resource));
269269
}
270270

271-
private Optional<String> mapImmunization(Resource resource) {
271+
protected Optional<String> mapImmunization(Resource resource) {
272272
return Optional.of(
273273
immunizationObservationStatementMapper.mapImmunizationToObservationStatement((Immunization) resource, IS_NESTED));
274274
}
275275

276-
private Optional<String> mapMedicationRequest(Resource resource) {
276+
protected Optional<String> mapMedicationRequest(Resource resource) {
277277
return Optional.of(resource)
278278
.map(MedicationRequest.class::cast)
279279
.filter(not(MedicationRequestUtils::isStoppedMedicationOrder))
280280
.map(medicationStatementMapper::mapMedicationRequestToMedicationStatement);
281281
}
282282

283-
private Optional<String> mapObservation(Resource resource) {
283+
protected Optional<String> mapObservation(Resource resource) {
284284
Observation observation = (Observation) resource;
285285
if (CodeableConceptMappingUtils.hasCode(observation.getCode(), List.of(NARRATIVE_STATEMENT_CODE))) {
286286
return Optional.of(observationToNarrativeStatementMapper.mapObservationToNarrativeStatement(observation, IS_NESTED));
@@ -292,17 +292,17 @@ private Optional<String> mapObservation(Resource resource) {
292292
return Optional.of(observationStatementMapper.mapObservationToObservationStatement(observation, IS_NESTED));
293293
}
294294

295-
private Optional<String> mapProcedureRequest(Resource resource) {
295+
protected Optional<String> mapProcedureRequest(Resource resource) {
296296
return Optional.ofNullable(
297297
diaryPlanStatementMapper.mapProcedureRequestToPlanStatement((ProcedureRequest) resource, IS_NESTED)
298298
);
299299
}
300300

301-
private Optional<String> mapReferralRequest(Resource resource) {
301+
protected Optional<String> mapReferralRequest(Resource resource) {
302302
return Optional.of(requestStatementMapper.mapReferralRequestToRequestStatement((ReferralRequest) resource, IS_NESTED));
303303
}
304304

305-
private Optional<String> mapDiagnosticReport(Resource resource) {
305+
protected Optional<String> mapDiagnosticReport(Resource resource) {
306306
return Optional.of(diagnosticReportMapper.mapDiagnosticReportToCompoundStatement((DiagnosticReport) resource));
307307
}
308308

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import com.github.mustachejava.Mustache;
1313

1414
import lombok.RequiredArgsConstructor;
15+
import uk.nhs.adaptors.gp2gp.common.service.ConfidentialityService;
1516
import uk.nhs.adaptors.gp2gp.ehr.exception.EhrMapperException;
1617
import uk.nhs.adaptors.gp2gp.ehr.mapper.parameters.NarrativeStatementTemplateParameters;
1718
import uk.nhs.adaptors.gp2gp.ehr.utils.DateFormatUtil;
@@ -24,12 +25,17 @@ public class ObservationToNarrativeStatementMapper {
2425

2526
private final MessageContext messageContext;
2627
private final ParticipantMapper participantMapper;
28+
private final ConfidentialityService confidentialityService;
2729

2830
public String mapObservationToNarrativeStatement(Observation observation, boolean isNested) {
31+
32+
var confidentialityCode = confidentialityService.generateConfidentialityCode(observation);
33+
2934
final IdMapper idMapper = messageContext.getIdMapper();
3035
var narrativeStatementTemplateParameters = NarrativeStatementTemplateParameters.builder()
3136
.narrativeStatementId(idMapper.getOrNew(ResourceType.Observation, observation.getIdElement()))
3237
.availabilityTime(getAvailabilityTime(observation))
38+
.confidentialityCode(confidentialityCode.orElse(null))
3339
.comment(observation.getComment())
3440
.isNested(isNested);
3541

service/src/main/resources/templates/ehr_narrative_statement_template.mustache

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
<text>{{comment}}</text>
55
<statusCode code="COMPLETE" />
66
<availabilityTime value="{{availabilityTime}}" />
7+
{{#confidentialityCode}}
8+
{{{confidentialityCode}}}
9+
{{/confidentialityCode}}
710
{{#participant}}
811
{{{.}}}
912
{{/participant}}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ codeableConceptCdMapper, new ParticipantMapper(), confidentialityService),
179179
randomIdGeneratorService,
180180
confidentialityService
181181
),
182-
new ObservationToNarrativeStatementMapper(messageContext, participantMapper),
182+
new ObservationToNarrativeStatementMapper(messageContext, participantMapper, confidentialityService),
183183
new ObservationStatementMapper(
184184
messageContext,
185185
new StructuredObservationValueMapper(),

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

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import org.hl7.fhir.dstu3.model.IdType;
88
import org.hl7.fhir.dstu3.model.QuestionnaireResponse;
99
import org.hl7.fhir.dstu3.model.Reference;
10+
import org.hl7.fhir.dstu3.model.Resource;
1011
import org.hl7.fhir.dstu3.model.ResourceType;
1112
import org.jetbrains.annotations.NotNull;
1213
import org.junit.jupiter.api.AfterEach;
@@ -83,6 +84,15 @@ public class EncounterComponentsMapperTest {
8384
+ "expected-components-17-topic-no-categories.xml";
8485
private static final String CONTAINED_TEST_DIRECTORY = TEST_DIRECTORY + "contained-resources/";
8586

87+
private static final String AGENT_DIRECTORY_FOLDER = "/ehr/mapper/observation/";
88+
private static final String INPUT_AGENT_DIRECTORY = AGENT_DIRECTORY_FOLDER + "observation-of-narrative-type-with-nopat.json";
89+
private static final String CONFIDENTIALITY_CODE = """
90+
<confidentialityCode
91+
code="NOPAT"
92+
codeSystem="2.16.840.1.113883.4.642.3.47"
93+
displayName="no disclosure to patient, family or caregivers without attending provider's authorization"
94+
/>""";
95+
8696
@Mock
8797
private RandomIdGeneratorService randomIdGeneratorService;
8898
@Mock
@@ -96,6 +106,7 @@ public class EncounterComponentsMapperTest {
96106

97107
private EncounterComponentsMapper encounterComponentsMapper;
98108
private MessageContext messageContext;
109+
private static final FhirParseService FHIR_PARSE_SERVICE = new FhirParseService();
99110

100111
@BeforeEach
101112
public void setUp() {
@@ -165,7 +176,7 @@ public void setUp() {
165176
confidentialityService
166177
);
167178
ObservationToNarrativeStatementMapper observationToNarrativeStatementMapper =
168-
new ObservationToNarrativeStatementMapper(messageContext, participantMapper);
179+
new ObservationToNarrativeStatementMapper(messageContext, participantMapper, confidentialityService);
169180
SpecimenMapper specimenMapper = getSpecimenMapper(structuredObservationValueMapper, participantMapper);
170181

171182
ObservationStatementMapper observationStatementMapper = new ObservationStatementMapper(
@@ -218,6 +229,19 @@ public void tearDown() {
218229
messageContext.resetMessageContext();
219230
}
220231

232+
@Test
233+
public void testObservationWithNOPATGetsTranslatedIntoNarrativeWithConfidentialityCode() {
234+
var jsonInput = ResourceTestFileUtils.getFileContent(INPUT_AGENT_DIRECTORY);
235+
Bundle bundle = FHIR_PARSE_SERVICE.parseResource(jsonInput, Bundle.class);
236+
Resource observation = bundle.getEntry().get(1).getResource();
237+
238+
when(confidentialityService.generateConfidentialityCode(observation)).thenReturn(Optional.of(CONFIDENTIALITY_CODE));
239+
240+
var result = encounterComponentsMapper.mapObservation(observation);
241+
242+
assertThat(result.get()).contains(CONFIDENTIALITY_CODE);
243+
}
244+
221245
@Test
222246
public void When_MappingEncounterComponents_Expect_ResourceMapped() {
223247
String expectedXml = ResourceTestFileUtils.getFileContent(EXPECTED_COMPONENTS_MAPPED_WITH_ALL_MAPPERS_USED);

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import org.mockito.junit.jupiter.MockitoSettings;
2929
import org.mockito.quality.Strictness;
3030

31+
import uk.nhs.adaptors.gp2gp.common.service.ConfidentialityService;
3132
import uk.nhs.adaptors.gp2gp.common.service.FhirParseService;
3233
import uk.nhs.adaptors.gp2gp.common.service.RandomIdGeneratorService;
3334
import uk.nhs.adaptors.gp2gp.ehr.exception.EhrMapperException;
@@ -60,6 +61,9 @@ public class ObservationToNarrativeStatementMapperTest {
6061
@Mock
6162
private RandomIdGeneratorService randomIdGeneratorService;
6263

64+
@Mock
65+
private ConfidentialityService confidentialityService;
66+
6367
private CharSequence expectedOutputMessage;
6468
private ObservationToNarrativeStatementMapper observationToNarrativeStatementMapper;
6569
private MessageContext messageContext;
@@ -71,7 +75,9 @@ public void setUp() {
7175

7276
messageContext = new MessageContext(randomIdGeneratorService);
7377
messageContext.initialize(new Bundle());
74-
observationToNarrativeStatementMapper = new ObservationToNarrativeStatementMapper(messageContext, new ParticipantMapper());
78+
observationToNarrativeStatementMapper = new ObservationToNarrativeStatementMapper(messageContext,
79+
new ParticipantMapper(),
80+
confidentialityService);
7581
}
7682

7783
@AfterEach

service/src/test/java/uk/nhs/adaptors/gp2gp/uat/EhrExtractUATTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ codeableConceptCdMapper, new ParticipantMapper(), confidentialityService),
199199
randomIdGeneratorService,
200200
confidentialityService
201201
),
202-
new ObservationToNarrativeStatementMapper(messageContext, participantMapper),
202+
new ObservationToNarrativeStatementMapper(messageContext, participantMapper, confidentialityService),
203203
new ObservationStatementMapper(
204204
messageContext,
205205
new StructuredObservationValueMapper(),

0 commit comments

Comments
 (0)