Skip to content

Commit 27e3f34

Browse files
authored
NIAD-3153: Adding confidentialityCode to RequestStatement (#1149)
* Adding confidentialityCode to RequestStatement * changelog
1 parent 87a467f commit 27e3f34

File tree

10 files changed

+76
-19
lines changed

10 files changed

+76
-19
lines changed

CHANGELOG.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ In the case that neither of these are present, the existing behavior of using th
1414

1515
### Added
1616

17-
* GP2GP Adaptor now populates the PlanStatement / confidentialityCode field
18-
when the ProcedureRequest.meta.security field contains NOPAT and the message type is RCMR_IN030000UK07
17+
* GP2GP Adaptor now populates the PlanStatement / confidentialityCode field when the ProcedureRequest.meta.security field contains NOPAT
18+
* When the ReferralRequest.meta.security field contains NOPAT, the GP2GP Adaptor will now populate the RequestStatement / confidentialityCode field accordingly.
1919

2020
## [2.2.2] - 2025-02-07
2121

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,7 @@ public String mapCodeableConceptForMedication(CodeableConcept codeableConcept) {
6262

6363
private String mapCodeableConcept(
6464
CodeableConcept codeableConcept,
65-
BiFunction<Optional<List<Extension>>, Coding, Optional<String>> getMainCodeFunction
66-
) {
65+
BiFunction<Optional<List<Extension>>, Coding, Optional<String>> getMainCodeFunction) {
6766
Optional<Coding> snomedCodeCoding = getSnomedCodeCoding(codeableConcept);
6867

6968
if (snomedCodeCoding.isEmpty()) {

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import org.springframework.beans.factory.annotation.Autowired;
3434
import org.springframework.stereotype.Component;
3535

36+
import uk.nhs.adaptors.gp2gp.common.service.ConfidentialityService;
3637
import uk.nhs.adaptors.gp2gp.ehr.exception.EhrMapperException;
3738
import uk.nhs.adaptors.gp2gp.ehr.mapper.parameters.RequestStatementTemplateParameters;
3839
import uk.nhs.adaptors.gp2gp.ehr.mapper.parameters.RequestStatementTemplateParameters.RequestStatementTemplateParametersBuilder;
@@ -66,11 +67,6 @@ public class RequestStatementMapper {
6667
private static final String NOTE_WITH_NO_AUTHOR_AND_TIME = "Annotation: %s";
6768
private static final String COMMA = ", ";
6869

69-
private static final String PRIORITY_CODE_IMMEDIATE =
70-
"<priorityCode code=\"88694003\" displayName=\"Immediate\" codeSystem=\"2.16.840.1.113883.2.1.3.2.4.15\">"
71-
+ "<originalText>Asap</originalText>"
72-
+ "</priorityCode>";
73-
7470
private static final String PRIORITY_CODE_NORMAL =
7571
"<priorityCode code=\"394848005\" displayName=\"Normal\" codeSystem=\"2.16.840.1.113883.2.1.3.2.4.15\">"
7672
+ "<originalText>Routine</originalText>"
@@ -84,6 +80,7 @@ public class RequestStatementMapper {
8480
private final MessageContext messageContext;
8581
private final CodeableConceptCdMapper codeableConceptCdMapper;
8682
private final ParticipantMapper participantMapper;
83+
private final ConfidentialityService confidentialityService;
8784

8885
public String mapReferralRequestToRequestStatement(ReferralRequest referralRequest, boolean isNested) {
8986
return new InnerMapper(referralRequest, isNested).map();
@@ -106,11 +103,14 @@ private String map() {
106103
processAgent(agentRef, onBehalfOf);
107104
}
108105

106+
var confidentialityCode = confidentialityService.generateConfidentialityCode(referralRequest);
107+
109108
final IdMapper idMapper = messageContext.getIdMapper();
110109
templateParameters
111110
.requestStatementId(idMapper.getOrNew(ResourceType.ReferralRequest, referralRequest.getIdElement()))
112111
.isNested(isNested)
113112
.availabilityTime(StatementTimeMappingUtils.prepareAvailabilityTime(referralRequest.getAuthoredOnElement()))
113+
.confidentialityCode(confidentialityCode.orElse(null))
114114
.text(buildTextDescription())
115115
.priorityCode(buildPriorityCode())
116116
.code(buildCode());

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,5 @@ public class RequestStatementTemplateParameters {
1717
private String participant;
1818
private String responsibleParty;
1919
private String text;
20+
private String confidentialityCode;
2021
}

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
<center nullFlavor="NI"/>
1111
</effectiveTime>
1212
{{{availabilityTime}}}
13+
{{#confidentialityCode}}
14+
{{{confidentialityCode}}}
15+
{{/confidentialityCode}}
1316
{{#priorityCode}}
1417
{{{priorityCode}}}
1518
{{/priorityCode}}

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
@@ -187,7 +187,7 @@ codeableConceptCdMapper, new ParticipantMapper()),
187187
codeableConceptCdMapper,
188188
participantMapper
189189
),
190-
new RequestStatementMapper(messageContext, codeableConceptCdMapper, participantMapper),
190+
new RequestStatementMapper(messageContext, codeableConceptCdMapper, participantMapper, confidentialityService),
191191
new DiagnosticReportMapper(
192192
messageContext, specimenMapper, participantMapper, randomIdGeneratorService, confidentialityService
193193
),

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ public void setUp() {
181181
confidentialityService
182182
);
183183
RequestStatementMapper requestStatementMapper
184-
= new RequestStatementMapper(messageContext, codeableConceptCdMapper, participantMapper);
184+
= new RequestStatementMapper(messageContext, codeableConceptCdMapper, participantMapper, confidentialityService);
185185
DiagnosticReportMapper diagnosticReportMapper = new DiagnosticReportMapper(
186186
messageContext, specimenMapper, participantMapper, randomIdGeneratorService, confidentialityService
187187
);

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

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66
import static org.mockito.ArgumentMatchers.any;
77
import static org.mockito.Mockito.lenient;
88
import static org.mockito.Mockito.when;
9+
import static uk.nhs.adaptors.gp2gp.utils.ConfidentialityCodeUtility.NOPAT_HL7_CONFIDENTIALITY_CODE;
910

10-
import java.io.IOException;
11+
import java.util.Optional;
1112
import java.util.stream.Stream;
12-
1313
import org.hl7.fhir.dstu3.model.Bundle;
1414
import org.hl7.fhir.dstu3.model.CodeableConcept;
1515
import org.hl7.fhir.dstu3.model.IdType;
@@ -30,6 +30,7 @@
3030

3131
import org.mockito.stubbing.Answer;
3232

33+
import uk.nhs.adaptors.gp2gp.common.service.ConfidentialityService;
3334
import uk.nhs.adaptors.gp2gp.common.service.FhirParseService;
3435
import uk.nhs.adaptors.gp2gp.ehr.exception.EhrMapperException;
3536
import uk.nhs.adaptors.gp2gp.utils.CodeableConceptMapperMockUtil;
@@ -77,6 +78,7 @@ public class RequestStatementMapperTest {
7778
+ "example-referral-request-no-resolved-reference-requester.json";
7879
private static final String INPUT_JSON_WITH_NO_RESOLVED_REFERENCE_RECIPIENT = TEST_FILE_DIRECTORY
7980
+ "example-referral-request-no-resolved-reference-recipient.json";
81+
private static final String INPUT_JSON_WITH_NOPAT = TEST_FILE_DIRECTORY + "example-referral-request-with-nopat.json";
8082
private static final String INPUT_JSON_WITH_NO_RESOLVED_REFERENCE_NOTE_AUTHOR = TEST_FILE_DIRECTORY
8183
+ "example-referral-request-no-resolved-reference-note-author.json";
8284
private static final String INPUT_JSON_WITH_PRACTITIONER_REQUESTER_NO_ONBEHALFOF = TEST_FILE_DIRECTORY
@@ -197,6 +199,8 @@ public class RequestStatementMapperTest {
197199
private IdMapper idMapper;
198200
@Mock
199201
private AgentDirectory agentDirectory;
202+
@Mock
203+
private ConfidentialityService confidentialityService;
200204

201205
private InputBundle inputBundle;
202206

@@ -272,7 +276,7 @@ private static Stream<Arguments> resourceFileParamsWithInvalidData() {
272276
}
273277

274278
@BeforeEach
275-
public void setUp() throws IOException {
279+
public void setUp() {
276280
var bundleInput = ResourceTestFileUtils.getFileContent(INPUT_JSON_BUNDLE);
277281
Bundle bundle = new FhirParseService().parseResource(bundleInput, Bundle.class);
278282
inputBundle = new InputBundle(bundle);
@@ -285,7 +289,10 @@ public void setUp() throws IOException {
285289
lenient().when(agentDirectory.getAgentId(any(Reference.class))).thenAnswer(mockIdForReference());
286290
lenient().when(agentDirectory.getAgentRef(any(Reference.class), any(Reference.class))).thenAnswer(mockIdForAgentReference());
287291

288-
requestStatementMapper = new RequestStatementMapper(messageContext, codeableConceptCdMapper, new ParticipantMapper());
292+
requestStatementMapper = new RequestStatementMapper(messageContext,
293+
codeableConceptCdMapper,
294+
new ParticipantMapper(),
295+
confidentialityService);
289296
}
290297

291298
private Answer<String> mockIdForResourceAndId() {
@@ -342,7 +349,7 @@ public void When_MappingObservationJsonWithReason_Expect_NarrativeStatementXmlOu
342349
}
343350

344351
@Test
345-
public void When_MappingReferralRequestJsonWithNestedTrue_Expect_RequestStatementXmlOutput() throws IOException {
352+
public void When_MappingReferralRequestJsonWithNestedTrue_Expect_RequestStatementXmlOutput() {
346353
String expectedOutputMessage = ResourceTestFileUtils.getFileContent(OUTPUT_XML_USES_NO_OPTIONAL_FIELDS_NESTED);
347354
var jsonInput = ResourceTestFileUtils.getFileContent(INPUT_JSON_WITH_NO_OPTIONAL_FIELDS);
348355
ReferralRequest parsedReferralRequest = new FhirParseService().parseResource(jsonInput, ReferralRequest.class);
@@ -352,10 +359,21 @@ public void When_MappingReferralRequestJsonWithNestedTrue_Expect_RequestStatemen
352359
assertThat(outputMessage).isEqualTo(expectedOutputMessage);
353360
}
354361

362+
@Test
363+
public void When_MappingReferralRequestWithNoPat_Expect_RequestStatementWithConfidentialityCode() {
364+
when(confidentialityService.generateConfidentialityCode(any(ReferralRequest.class)))
365+
.thenReturn(Optional.of(NOPAT_HL7_CONFIDENTIALITY_CODE));
366+
var jsonInput = ResourceTestFileUtils.getFileContent(INPUT_JSON_WITH_NOPAT);
367+
ReferralRequest parsedReferralRequest = new FhirParseService().parseResource(jsonInput, ReferralRequest.class);
368+
369+
String outputMessage = requestStatementMapper.mapReferralRequestToRequestStatement(parsedReferralRequest, true);
370+
371+
assertThat(outputMessage).contains(NOPAT_HL7_CONFIDENTIALITY_CODE);
372+
}
373+
355374
@ParameterizedTest
356375
@MethodSource("resourceFileParamsWithInvalidData")
357-
public void When_MappingReferralRequestJsonWithInvalidData_Expect_Exception(String inputJson, String exceptionMessage)
358-
throws IOException {
376+
public void When_MappingReferralRequestJsonWithInvalidData_Expect_Exception(String inputJson, String exceptionMessage) {
359377
var jsonInput = ResourceTestFileUtils.getFileContent(inputJson);
360378
ReferralRequest parsedReferralRequest = new FhirParseService().parseResource(jsonInput, ReferralRequest.class);
361379

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
@@ -207,7 +207,7 @@ codeableConceptCdMapper, new ParticipantMapper()),
207207
codeableConceptCdMapper,
208208
participantMapper
209209
),
210-
new RequestStatementMapper(messageContext, codeableConceptCdMapper, participantMapper),
210+
new RequestStatementMapper(messageContext, codeableConceptCdMapper, participantMapper, confidentialityService),
211211
new DiagnosticReportMapper(messageContext, specimenMapper, participantMapper, randomIdGeneratorService, confidentialityService),
212212
new BloodPressureValidator(),
213213
codeableConceptCdMapper
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
{
2+
"resourceType": "ReferralRequest",
3+
"id": "E63AF323-919F-4D5F-9A1D-BA933BC230BC",
4+
"meta": {
5+
"profile": [
6+
"https://fhir.nhs.uk/STU3/StructureDefinition/CareConnect-GPC-Immunization-1"
7+
],
8+
"security": [{
9+
"system":"http://hl7.org/fhir/v3/ActCode",
10+
"code":"NOPAT",
11+
"display":"no disclosure to patient, family or caregivers without attending provider's authorization"
12+
}]
13+
},
14+
"authoredOn": "2010-01-19",
15+
"priority": "routine",
16+
"description": "Referred for investigation into low blood pressure",
17+
"specialty": {
18+
"coding": [
19+
{
20+
"system": "http://hl7.org/fhir/v3/NullFlavor",
21+
"code": "UNK",
22+
"display": "unknown"
23+
}
24+
]
25+
},
26+
"identifier": [
27+
{
28+
"system": "https://fhir.nhs.uk/Id/cross-care-setting-identifier",
29+
"value": "B154D1A3-D631-49BD-8B67-2F76D7D85865"
30+
},
31+
{
32+
"system": "https://fhir.nhs.uk/Id/ubr-number",
33+
"value": "bb2378b6-dde2-11e9-9d36-2a2ae2dbcce4"
34+
}
35+
]
36+
}

0 commit comments

Comments
 (0)