@@ -81,7 +81,11 @@ class DocumentReferenceMapperTest {
8181 @ InjectMocks
8282 private DocumentReferenceMapper documentReferenceMapper ;
8383 @ Captor
84- private ArgumentCaptor <Optional <CV >> confidentialityCodeCaptor ;
84+ private ArgumentCaptor <Optional <CV >> ehrCompositionCaptor ;
85+ @ Captor
86+ private ArgumentCaptor <Optional <CV >> narrativeStatementCaptor ;
87+ @ Captor
88+ private ArgumentCaptor <Optional <CV >> externalDocumentCaptor ;
8589
8690 @ BeforeEach
8791 void setup () {
@@ -98,8 +102,32 @@ void mapNarrativeStatementToDocumentReferenceWithValidData() {
98102 assertFullValidData (documentReference );
99103 }
100104
105+ @ Test
106+ void mapNarrativeStatementToDocumentReferenceWithNopatSecurity () {
107+
108+ final Meta stubbedMeta = MetaUtil .getMetaFor (META_WITH_SECURITY , META_PROFILE );
109+ Mockito
110+ .lenient ()
111+ .when (confidentialityService .createMetaAndAddSecurityIfConfidentialityCodesPresent (
112+ any (String .class ), any (Optional .class ), any (Optional .class ), any (Optional .class ))).thenReturn (stubbedMeta );
113+
114+ var ehrExtract = unmarshallEhrExtract ("narrative_statement_has_referred_to_external_document_with_optional_data.xml" );
115+ List <DocumentReference > documentReferences = documentReferenceMapper .mapResources (ehrExtract , createPatient (),
116+ getEncounterList (),
117+ AUTHOR_ORG ,
118+ createAttachmentList ());
119+ var documentReference = documentReferences .getFirst ();
120+
121+ assertAll (
122+ () -> documentReferences .forEach (this ::assertMetaHasSecurity ),
123+ () -> assertOptionalValidData (documentReference )
124+ );
125+
126+ }
127+
101128 @ Test
102129 void mapNarrativeStatementToDocumentReferenceWithOptionalData () {
130+
103131 var ehrExtract = unmarshallEhrExtract ("narrative_statement_has_referred_to_external_document_with_optional_data.xml" );
104132 List <DocumentReference > documentReferences = documentReferenceMapper .mapResources (ehrExtract , createPatient (),
105133 getEncounterList (), AUTHOR_ORG , createAttachmentList ());
@@ -110,6 +138,7 @@ void mapNarrativeStatementToDocumentReferenceWithOptionalData() {
110138
111139 @ Test
112140 void mapMultipleNarrativeStatementToDocumentReference () {
141+
113142 var ehrExtract = unmarshallEhrExtract ("multiple_narrative_statements_has_referred_to_external_document.xml" );
114143 List <DocumentReference > documentReferences = documentReferenceMapper .mapResources (ehrExtract , createPatient (),
115144 getEncounterList (), AUTHOR_ORG , createAttachmentList ());
@@ -204,13 +233,15 @@ void When_NarrativeStatement_With_ExternalDocumentAndNopatConfidentialityCode_Ex
204233
205234 when (confidentialityService .createMetaAndAddSecurityIfConfidentialityCodesPresent (
206235 eq (META_PROFILE ),
207- confidentialityCodeCaptor .capture ()
236+ ehrCompositionCaptor .capture (),
237+ narrativeStatementCaptor .capture (),
238+ externalDocumentCaptor .capture ()
208239 )).thenReturn (META_WITH_SECURITY_ADDED );
209240
210241 final List <DocumentReference > documentReferences = documentReferenceMapper .mapResources (ehrExtract , createPatient (),
211242 getEncounterList (), AUTHOR_ORG , createAttachmentList ());
212243
213- final CV externalDocumentConfidentialityCode = confidentialityCodeCaptor
244+ final CV externalDocumentConfidentialityCode = externalDocumentCaptor
214245 .getValue ()
215246 .orElseThrow (TestUtility .NoConfidentialityCodePresentException ::new );
216247
@@ -227,14 +258,15 @@ void When_NarrativeStatement_With_ExternalDocumentAndNoConfidentialityCode_Expec
227258
228259 when (confidentialityService .createMetaAndAddSecurityIfConfidentialityCodesPresent (
229260 eq (META_PROFILE ),
230- confidentialityCodeCaptor .capture ()
261+ ehrCompositionCaptor .capture (),
262+ narrativeStatementCaptor .capture (),
263+ externalDocumentCaptor .capture ()
231264 )).thenReturn (META_WITHOUT_SECURITY_ADDED );
232265
233266 final List <DocumentReference > documentReferences = documentReferenceMapper .mapResources (ehrExtract , createPatient (),
234267 getEncounterList (), AUTHOR_ORG , createAttachmentList ());
235268
236- final Optional <CV > externalDocumentConfidentialityCode = confidentialityCodeCaptor
237- .getValue ();
269+ final Optional <CV > externalDocumentConfidentialityCode = externalDocumentCaptor .getValue ();
238270
239271 assertAll (
240272 () -> documentReferences .forEach (this ::assertMetaHasNoSecurity ),
@@ -361,7 +393,9 @@ private void configureCommonStubs() {
361393
362394 Mockito .lenient ().when (confidentialityService .createMetaAndAddSecurityIfConfidentialityCodesPresent (
363395 eq (META_PROFILE ),
364- confidentialityCodeCaptor .capture ()
396+ ehrCompositionCaptor .capture (),
397+ narrativeStatementCaptor .capture (),
398+ externalDocumentCaptor .capture ()
365399 )).thenReturn (MetaUtil .getMetaFor (META_WITHOUT_SECURITY , META_PROFILE ));
366400 }
367401}
0 commit comments