55import static org .mockito .ArgumentMatchers .any ;
66import static org .mockito .ArgumentMatchers .anyString ;
77import static org .mockito .Mockito .when ;
8-
9- import java .io .IOException ;
8+ import java .util .Optional ;
109import java .util .stream .Stream ;
1110
1211import org .hl7 .fhir .dstu3 .model .Bundle ;
2221import org .mockito .junit .jupiter .MockitoSettings ;
2322import org .mockito .quality .Strictness ;
2423
24+ import uk .nhs .adaptors .gp2gp .common .service .ConfidentialityService ;
2525import uk .nhs .adaptors .gp2gp .common .service .FhirParseService ;
2626import uk .nhs .adaptors .gp2gp .common .service .RandomIdGeneratorService ;
2727import uk .nhs .adaptors .gp2gp .ehr .exception .EhrMapperException ;
@@ -57,16 +57,23 @@ public class DiaryPlanStatementMapperTest {
5757 + "expected-output-procedure-request-resource-with-multiple-supportInfo.xml" ;
5858 private static final String INPUT_BUNDLE = TEST_DIRECTORY + "input-bundle.json" ;
5959
60+ public static final String CONFIDENTIALITY_CODE = "<confidentialityCode code=\" NOPAT\" "
61+ + "codeSystem=\" 2.16.840.1.113883.4.642.3.47\" "
62+ + "displayName=\" no disclosure to patient, family or "
63+ + "caregivers without attending provider's authorization\" />" ;
64+
6065 @ Mock
6166 private RandomIdGeneratorService randomIdGeneratorService ;
6267 @ Mock
6368 private CodeableConceptCdMapper codeableConceptCdMapper ;
69+ @ Mock
70+ private ConfidentialityService confidentialityService ;
6471
6572 private MessageContext messageContext ;
6673 private DiaryPlanStatementMapper diaryPlanStatementMapper ;
6774
6875 @ BeforeEach
69- public void setUp () throws IOException {
76+ public void setUp () {
7077 String inputJson = ResourceTestFileUtils .getFileContent (INPUT_BUNDLE );
7178 Bundle bundle = new FhirParseService ().parseResource (inputJson , Bundle .class );
7279
@@ -78,7 +85,7 @@ public void setUp() throws IOException {
7885 messageContext .initialize (bundle );
7986
8087 diaryPlanStatementMapper =
81- new DiaryPlanStatementMapper (messageContext , codeableConceptCdMapper , new ParticipantMapper ());
88+ new DiaryPlanStatementMapper (messageContext , codeableConceptCdMapper , new ParticipantMapper (), confidentialityService );
8289 }
8390
8491 @ AfterEach
@@ -87,7 +94,19 @@ public void tearDown() {
8794 }
8895
8996 @ Test
90- public void When_MappingProcedureRequestIsNested_Expect_ResourceMappedWithIsNestedFlag () throws IOException {
97+ public void When_MappingProcedureRequestWithNopat_Expect_ResourceMappedWithConfidentialityCode () {
98+ String inputJson = ResourceTestFileUtils .getFileContent (INPUT_PROCEDURE_REQUEST_WITH_ALL_DATA );
99+ ProcedureRequest inputProcedureRequest = new FhirParseService ().parseResource (inputJson , ProcedureRequest .class );
100+
101+ when (confidentialityService .generateConfidentialityCode (inputProcedureRequest )).thenReturn (Optional .of (CONFIDENTIALITY_CODE ));
102+
103+ var mappedXml = diaryPlanStatementMapper .mapProcedureRequestToPlanStatement (inputProcedureRequest , true );
104+ assertThat (mappedXml ).contains (CONFIDENTIALITY_CODE );
105+ }
106+
107+
108+ @ Test
109+ public void When_MappingProcedureRequestIsNested_Expect_ResourceMappedWithIsNestedFlag () {
91110 String expectedXml = ResourceTestFileUtils .getFileContent (EXPECTED_PLAN_STATEMENT_WITH_IS_NESTED );
92111
93112 String inputJson = ResourceTestFileUtils .getFileContent (INPUT_PROCEDURE_REQUEST_WITH_ALL_DATA );
@@ -98,7 +117,7 @@ public void When_MappingProcedureRequestIsNested_Expect_ResourceMappedWithIsNest
98117 }
99118
100119 @ Test
101- public void When_MappingProcedureRequestThatIsNotPlan_Expect_ResourceNotMapped () throws IOException {
120+ public void When_MappingProcedureRequestThatIsNotPlan_Expect_ResourceNotMapped () {
102121 String inputJson = ResourceTestFileUtils .getFileContent (INPUT_PROCEDURE_REQUEST_IS_NOT_PLAN );
103122 ProcedureRequest inputProcedureRequest = new FhirParseService ().parseResource (inputJson , ProcedureRequest .class );
104123
@@ -107,7 +126,7 @@ public void When_MappingProcedureRequestThatIsNotPlan_Expect_ResourceNotMapped()
107126 }
108127
109128 @ Test
110- public void When_MappingProcedureRequestWithoutRequiredAuthoredOn_Expect_MapperException () throws IOException {
129+ public void When_MappingProcedureRequestWithoutRequiredAuthoredOn_Expect_MapperException () {
111130 String inputJson = ResourceTestFileUtils .getFileContent (INPUT_PROCEDURE_REQUEST_WITHOUT_REQUIRED_AUTHORED_ON );
112131 ProcedureRequest inputProcedureRequest = new FhirParseService ().parseResource (inputJson , ProcedureRequest .class );
113132
@@ -275,7 +294,7 @@ public void When_MappingWithDeviceReferenceWhereDeviceHasNoManufacturer_Expect_T
275294
276295 @ ParameterizedTest
277296 @ MethodSource ("testData" )
278- public void When_MappingProcedureRequest_Expect_ResourceMapped (String inputJsonPath , String expectedXmlPath ) throws IOException {
297+ public void When_MappingProcedureRequest_Expect_ResourceMapped (String inputJsonPath , String expectedXmlPath ) {
279298 String expectedXml = ResourceTestFileUtils .getFileContent (expectedXmlPath );
280299
281300 String inputJson = ResourceTestFileUtils .getFileContent (inputJsonPath );
0 commit comments