11package uk .nhs .adaptors .gp2gp .ehr .mapper ;
22
3- import org .hl7 .fhir .dstu3 .model .AllergyIntolerance ;
4- import org .hl7 .fhir .dstu3 .model .Bundle ;
5- import org .hl7 .fhir .dstu3 .model .CodeableConcept ;
6- import org .hl7 .fhir .dstu3 .model .Observation ;
7- import org .hl7 .fhir .dstu3 .model .ResourceType ;
3+ import org .hl7 .fhir .dstu3 .model .*;
84import org .junit .jupiter .api .AfterEach ;
95import org .junit .jupiter .api .BeforeEach ;
106import org .junit .jupiter .api .Test ;
4137import static org .mockito .Mockito .when ;
4238
4339@ ExtendWith (MockitoExtension .class )
44- @ MockitoSettings (strictness = Strictness .LENIENT )
4540class EhrExtractMapperComponentTest {
4641
4742 private static final String TEST_FILE_DIRECTORY = "/ehr/request/fhir/" ;
@@ -119,10 +114,6 @@ public void setUp() {
119114 .toOdsCode (TEST_TO_ODS_CODE )
120115 .build ();
121116
122- setupRandomIdMocks ();
123- setupTimestampMock ();
124- setupCodeableConceptMocks ();
125-
126117 messageContext = new MessageContext (randomIdGeneratorService );
127118
128119 ParticipantMapper participantMapper = new ParticipantMapper ();
@@ -202,7 +193,7 @@ private void setupRandomIdMocks() {
202193 when (randomIdGeneratorService .createNewId ())
203194 .thenReturn (TEST_ID_1 , TEST_ID_2 , TEST_ID_3 );
204195
205- lenient (). when (randomIdGeneratorService .createNewOrUseExistingUUID (anyString ()))
196+ when (randomIdGeneratorService .createNewOrUseExistingUUID (anyString ()))
206197 .thenReturn (TEST_ID_3 );
207198 }
208199
@@ -262,26 +253,69 @@ public void tearDown() {
262253
263254 @ Test
264255 void When_MappingUncategorizedObservationWithNOPAT_Expect_ObservationStatementWithConfidentialityCode () {
256+ when (codeableConceptCdMapper .mapCodeableConceptToCd (any (CodeableConcept .class )))
257+ .thenReturn (CodeableConceptMapperMockUtil .NULL_FLAVOR_CODE );
258+
259+ when (codeableConceptCdMapper .mapCodeableConceptForMedication (any (CodeableConcept .class )))
260+ .thenReturn (CodeableConceptMapperMockUtil .NULL_FLAVOR_CODE );
261+
262+ when (codeableConceptCdMapper .mapCodeableConceptToCdForTransformedActualProblemHeader (any (CodeableConcept .class )))
263+ .thenReturn (CodeableConceptMapperMockUtil .ACTUAL_PROBLEM_CODE );
264+
265+ when (codeableConceptCdMapper .mapCodeableConceptToCdForAllergy (any (CodeableConcept .class ), any ()))
266+ .thenReturn (CodeableConceptMapperMockUtil .NULL_FLAVOR_CODE );
267+
268+ when (codeableConceptCdMapper .getDisplayFromCodeableConcept (any (CodeableConcept .class )))
269+ .thenCallRealMethod ();
270+
271+ when (codeableConceptCdMapper .mapCodeableConceptToCdForBloodPressure (any (CodeableConcept .class )))
272+ .thenReturn (CodeableConceptMapperMockUtil .NULL_FLAVOR_CODE );
273+
274+ when (codeableConceptCdMapper .mapToCdForTopic (any (CodeableConcept .class ), any (String .class )))
275+ .thenReturn (CodeableConceptMapperMockUtil .NULL_FLAVOR_CODE );
276+
277+ when (codeableConceptCdMapper .getCdForTopic ())
278+ .thenReturn (CodeableConceptMapperMockUtil .NULL_FLAVOR_CODE );
279+
280+ when (codeableConceptCdMapper .mapToCdForCategory (any (String .class )))
281+ .thenReturn (CodeableConceptMapperMockUtil .NULL_FLAVOR_CODE );
282+
283+ when (codeableConceptCdMapper .getCdForCategory ())
284+ .thenReturn (CodeableConceptMapperMockUtil .NULL_FLAVOR_CODE );
285+
286+ when (confidentialityService .generateConfidentialityCode (any (Encounter .class )))
287+ .thenReturn (Optional .empty ());
288+
289+ setupTimestampMock ();
290+ setupRandomIdMocks ();
265291
266292 String expectedJsonToXmlContent = ResourceTestFileUtils .getFileContent (OUTPUT_PATH + EXPECTED_XML_TO_JSON_FILE_WITH_NOPAT );
267293 String inputJsonFileContent = ResourceTestFileUtils .getFileContent (INPUT_PATH + JSON_INPUT_FILE_WITH_NOPAT );
268294 Bundle bundle = new FhirParseService ().parseResource (inputJsonFileContent , Bundle .class );
269295
270296 Observation uncategorizedObservation = bundle .getEntry ().stream ()
271- .map (Bundle .BundleEntryComponent ::getResource )
272- .filter (resource -> ResourceType .Observation .equals (resource .getResourceType ()))
273- .map (Observation .class ::cast )
274- .filter (o -> "Observation/FB5E6E97-3152-46EB-B46A-B48D21FC1099" .equals (o .getId ()))
275- .findFirst ()
276- .get ();
297+ .map (Bundle .BundleEntryComponent ::getResource )
298+ .filter (resource -> ResourceType .Observation .equals (resource .getResourceType ()))
299+ .map (Observation .class ::cast )
300+ .filter (o -> "Observation/FB5E6E97-3152-46EB-B46A-B48D21FC1099" .equals (o .getId ()))
301+ .findFirst ()
302+ .get ();
303+
304+ when (confidentialityService .generateConfidentialityCode (any (Observation .class )))
305+ .thenReturn (Optional .empty ());
277306
278- when (confidentialityService .generateConfidentialityCode (uncategorizedObservation )).thenReturn (Optional .of (CONFIDENTIALITY_CODE ));
307+ when (confidentialityService .generateConfidentialityCode (any (org .hl7 .fhir .dstu3 .model .ListResource .class )))
308+ .thenReturn (Optional .empty ());
309+
310+ when (confidentialityService .generateConfidentialityCode (uncategorizedObservation ))
311+ .thenReturn (Optional .of (CONFIDENTIALITY_CODE ));
279312
280313 messageContext .initialize (bundle );
281314
282315 EhrExtractTemplateParameters ehrExtractTemplateParameters = ehrExtractMapper .mapBundleToEhrFhirExtractParams (
283- getGpcStructuredTaskDefinition ,
284- bundle );
316+ getGpcStructuredTaskDefinition ,
317+ bundle );
318+
285319 String output = ehrExtractMapper .mapEhrExtractToXml (ehrExtractTemplateParameters );
286320
287321 assertThat (output ).isEqualToIgnoringWhitespace (expectedJsonToXmlContent );
@@ -294,6 +328,8 @@ void When_MappingProperJsonRequestBody_Expect_ProperXmlOutput(String input, Stri
294328 String inputJsonFileContent = ResourceTestFileUtils .getFileContent (INPUT_PATH + input );
295329 Bundle bundle = new FhirParseService ().parseResource (inputJsonFileContent , Bundle .class );
296330 messageContext .initialize (bundle );
331+ setupTimestampMock ();
332+ setupRandomIdMocks ();
297333
298334 EhrExtractTemplateParameters ehrExtractTemplateParameters = ehrExtractMapper .mapBundleToEhrFhirExtractParams (
299335 getGpcStructuredTaskDefinition ,
@@ -307,10 +343,30 @@ void When_MappingProperJsonRequestBody_Expect_ProperXmlOutput(String input, Stri
307343 @ Test
308344 void When_MappingProperJsonRequestBody_Expect_NonDuplicatedMedicationRequestRemainingResources () {
309345 String inputJsonFileContent =
310- ResourceTestFileUtils .getFileContent (INPUT_PATH + FHIR_BUNDLE_WITH_DUPLICATED_MEDICATION_REQUESTS );
346+ ResourceTestFileUtils .getFileContent (INPUT_PATH + FHIR_BUNDLE_WITH_DUPLICATED_MEDICATION_REQUESTS );
311347 Bundle bundle = new FhirParseService ().parseResource (inputJsonFileContent , Bundle .class );
312348 messageContext .initialize (bundle );
313349
350+ setupTimestampMock ();
351+ setupRandomIdMocks ();
352+ when (codeableConceptCdMapper .mapCodeableConceptToCd (any (CodeableConcept .class )))
353+ .thenReturn (CodeableConceptMapperMockUtil .NULL_FLAVOR_CODE );
354+
355+ when (codeableConceptCdMapper .mapCodeableConceptForMedication (any (CodeableConcept .class )))
356+ .thenReturn (CodeableConceptMapperMockUtil .NULL_FLAVOR_CODE );
357+
358+ when (codeableConceptCdMapper .mapCodeableConceptToCdForAllergy (any (CodeableConcept .class ), any ()))
359+ .thenReturn (CodeableConceptMapperMockUtil .NULL_FLAVOR_CODE );
360+
361+ when (codeableConceptCdMapper .mapToCdForTopic (any (String .class )))
362+ .thenReturn (CodeableConceptMapperMockUtil .NULL_FLAVOR_CODE );
363+
364+ when (codeableConceptCdMapper .mapToCdForCategory (any (String .class )))
365+ .thenReturn (CodeableConceptMapperMockUtil .NULL_FLAVOR_CODE );
366+
367+ when (codeableConceptCdMapper .getCdForCategory ())
368+ .thenReturn (CodeableConceptMapperMockUtil .NULL_FLAVOR_CODE );
369+
314370 EhrExtractTemplateParameters ehrExtractTemplateParameters = ehrExtractMapper .mapBundleToEhrFhirExtractParams (
315371 getGpcStructuredTaskDefinition ,
316372 bundle );
@@ -333,6 +389,11 @@ private static Stream<Arguments> testData() {
333389
334390 @ Test
335391 void When_MappingJsonBody_Expect_OnlyOneConsultationResource () {
392+ when (codeableConceptCdMapper .mapToNullFlavorCodeableConceptForAllergy (any (CodeableConcept .class ), any ()))
393+ .thenReturn (CodeableConceptMapperMockUtil .NULL_FLAVOR_CODE );
394+ setupTimestampMock ();
395+ setupRandomIdMocks ();
396+
336397 String expectedJsonToXmlContent = ResourceTestFileUtils .getFileContent (OUTPUT_PATH + EXPECTED_XML_FOR_ONE_CONSULTATION_RESOURCE );
337398 String inputJsonFileContent = ResourceTestFileUtils .getFileContent (ONE_CONSULTATION_RESOURCE_BUNDLE );
338399 Bundle bundle = new FhirParseService ().parseResource (inputJsonFileContent , Bundle .class );
0 commit comments