66import static org .mockito .ArgumentMatchers .any ;
77import static org .mockito .Mockito .lenient ;
88import 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 ;
1112import java .util .stream .Stream ;
12-
1313import org .hl7 .fhir .dstu3 .model .Bundle ;
1414import org .hl7 .fhir .dstu3 .model .CodeableConcept ;
1515import org .hl7 .fhir .dstu3 .model .IdType ;
3030
3131import org .mockito .stubbing .Answer ;
3232
33+ import uk .nhs .adaptors .gp2gp .common .service .ConfidentialityService ;
3334import uk .nhs .adaptors .gp2gp .common .service .FhirParseService ;
3435import uk .nhs .adaptors .gp2gp .ehr .exception .EhrMapperException ;
3536import 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
0 commit comments