1212import org .junit .jupiter .params .provider .MethodSource ;
1313import org .mockito .Mock ;
1414import org .mockito .junit .jupiter .MockitoExtension ;
15- import org .mockito .junit .jupiter .MockitoSettings ;
16- import org .mockito .quality .Strictness ;
1715import uk .nhs .adaptors .gp2gp .common .service .ConfidentialityService ;
1816import uk .nhs .adaptors .gp2gp .common .service .FhirParseService ;
1917import uk .nhs .adaptors .gp2gp .common .service .RandomIdGeneratorService ;
2826import static org .assertj .core .api .Assertions .assertThatThrownBy ;
2927import static org .mockito .ArgumentMatchers .any ;
3028import static org .mockito .ArgumentMatchers .anyString ;
29+ import static org .mockito .Mockito .reset ;
3130import static org .mockito .Mockito .when ;
3231import static uk .nhs .adaptors .gp2gp .utils .ConfidentialityCodeUtility .NOPAT_HL7_CONFIDENTIALITY_CODE ;
3332import static uk .nhs .adaptors .gp2gp .utils .XmlAssertion .assertThatXml ;
3433
3534@ ExtendWith (MockitoExtension .class )
36- @ MockitoSettings (strictness = Strictness .LENIENT )
3735class ImmunizationObservationStatementMapperTest {
3836 private static final String TEST_ID = "test-id" ;
3937 private static final String IMMUNIZATION_FILE_LOCATIONS = "/ehr/mapper/immunization/" ;
@@ -168,7 +166,6 @@ class ImmunizationObservationStatementMapperTest {
168166
169167 @ BeforeEach
170168 void setUp () {
171- when (randomIdGeneratorService .createNewId ()).thenReturn (TEST_ID );
172169 when (randomIdGeneratorService .createNewOrUseExistingUUID (anyString ())).thenReturn (TEST_ID );
173170 when (codeableConceptCdMapper .mapCodeableConceptToCd (any (CodeableConcept .class )))
174171 .thenReturn (CodeableConceptMapperMockUtil .NULL_FLAVOR_CODE );
@@ -197,17 +194,65 @@ void When_MappingImmunizationJson_Expect_ObservationStatementXmlOutput(String in
197194 var expectedOutput = ResourceTestFileUtils .getFileContent (outputXml );
198195 var jsonInput = ResourceTestFileUtils .getFileContent (inputJson );
199196
197+ when (randomIdGeneratorService .createNewId ()).thenReturn (TEST_ID );
198+
200199 Immunization parsedImmunization = fhirParseService .parseResource (jsonInput , Immunization .class );
201200 String outputMessage = observationStatementMapper .mapImmunizationToObservationStatement (parsedImmunization , isNested );
202201 assertThat (outputMessage ).isEqualToIgnoringWhitespace (expectedOutput );
203202 }
204203
204+ @ Test
205+ void When_MappingImmunizationWithoutCodeableConceptText_Expect_ObservationStatementXmlOutput () {
206+ var expectedOutput = ResourceTestFileUtils .getFileContent (OUTPUT_XML_WITH_PERTINENT_INFORMATION );
207+ var jsonInput = ResourceTestFileUtils .getFileContent (INPUT_JSON_WITHOUT_CODEABLE_CONCEPT_TEXT );
208+
209+ Immunization parsedImmunization = fhirParseService .parseResource (jsonInput , Immunization .class );
210+ String outputMessage = observationStatementMapper .mapImmunizationToObservationStatement (parsedImmunization , false );
211+ assertThat (outputMessage ).isEqualToIgnoringWhitespace (expectedOutput );
212+ }
213+
214+ @ Test
215+ void When_MappingImmunizationWithoutRequiredPertinentInformation_Expect_ObservationStatementXmlOutput () {
216+ var expectedOutput = ResourceTestFileUtils .getFileContent (OUTPUT_XML_WITHOUT_REQUIRED_PERTINENT_INFORMATION );
217+ var jsonInput = ResourceTestFileUtils .getFileContent (INPUT_JSON_WITHOUT_REQUIRED_PERTINENT_INFORMATION );
218+
219+ reset (randomIdGeneratorService );
220+
221+ Immunization parsedImmunization = fhirParseService .parseResource (jsonInput , Immunization .class );
222+ String outputMessage = observationStatementMapper .mapImmunizationToObservationStatement (parsedImmunization , false );
223+
224+ assertThat (outputMessage ).isEqualToIgnoringWhitespace (expectedOutput );
225+ }
226+
227+
228+
229+ @ Test
230+ void When_MappingImmunizationWithoutPractitioner_Expect_ObservationStatementXmlOutput () {
231+ var expectedOutput = ResourceTestFileUtils .getFileContent (OUTPUT_XML_WITHOUT_PARTICIPANT );
232+ var jsonInput = ResourceTestFileUtils .getFileContent (INPUT_JSON_WITHOUT_PRACTITIONER );
233+
234+ Immunization parsedImmunization = fhirParseService .parseResource (jsonInput , Immunization .class );
235+ String outputMessage = observationStatementMapper .mapImmunizationToObservationStatement (parsedImmunization , false );
236+ assertThat (outputMessage ).isEqualToIgnoringWhitespace (expectedOutput );
237+ }
238+
239+ @ Test
240+ void When_MappingImmunizationWithPractitionerButNoActor_Expect_ObservationStatementXmlOutput () {
241+ var expectedOutput = ResourceTestFileUtils .getFileContent (OUTPUT_XML_WITHOUT_PARTICIPANT );
242+ var jsonInput = ResourceTestFileUtils .getFileContent (INPUT_JSON_WITH_PRACTITIONER_BUT_NO_ACTOR );
243+
244+ Immunization parsedImmunization = fhirParseService .parseResource (jsonInput , Immunization .class );
245+ String outputMessage = observationStatementMapper .mapImmunizationToObservationStatement (parsedImmunization , false );
246+ assertThat (outputMessage ).isEqualToIgnoringWhitespace (expectedOutput );
247+ }
248+
249+
250+
251+
205252 private static Stream <Arguments > resourceFileParams () {
206253 return Stream .of (
207254 Arguments .of (INPUT_JSON_WITH_PERTINENT_INFORMATION , OUTPUT_XML_WITH_PERTINENT_INFORMATION , false ),
208- Arguments .of (INPUT_JSON_WITHOUT_CODEABLE_CONCEPT_TEXT , OUTPUT_XML_WITH_PERTINENT_INFORMATION , false ),
209255 Arguments .of (INPUT_JSON_WITHOUT_DATE , OUTPUT_XML_WITHOUT_DATE , false ),
210- Arguments .of (INPUT_JSON_WITHOUT_REQUIRED_PERTINENT_INFORMATION , OUTPUT_XML_WITHOUT_REQUIRED_PERTINENT_INFORMATION , false ),
211256 Arguments .of (INPUT_JSON_REASON_NOT_GIVEN , OUTPUT_XML_WITH_REASON_NOT_GIVEN , false ),
212257 Arguments .of (INPUT_JSON_REASON_NOT_GIVEN_TEXT , OUTPUT_XML_WITH_REASON_NOT_GIVEN , false ),
213258 Arguments .of (INPUT_JSON_WITH_PERTINENT_INFORMATION , OUTPUT_XML_WITHOUT_CONTEXT , true ),
@@ -219,8 +264,6 @@ private static Stream<Arguments> resourceFileParams() {
219264 Arguments .of (INPUT_JSON_WITH_NO_RELATION_TO_CONDITION ,
220265 OUTPUT_XML_WITH_IMMUNIZATION_WITH_NO_RELATION_TO_CONDITION , false ),
221266 Arguments .of (INPUT_JSON_WITH_VACCINE_CODE , OUTPUT_XML_WITH_VACCINE_CODE , false ),
222- Arguments .of (INPUT_JSON_WITHOUT_PRACTITIONER , OUTPUT_XML_WITHOUT_PARTICIPANT , false ),
223- Arguments .of (INPUT_JSON_WITH_PRACTITIONER_BUT_NO_ACTOR , OUTPUT_XML_WITHOUT_PARTICIPANT , false ),
224267 Arguments .of (INPUT_JSON_WITH_REPORT_ORIGIN , OUTPUT_XML_WITH_IMMUNIZATION_WITH_REPORT_ORIGIN , false ),
225268 Arguments .of (INPUT_JSON_WITH_PARENT_PRESENT_FALSE , OUTPUT_XML_WITH_IMMUNIZATION_PARENT_PRESENT_FALSE , false ),
226269 Arguments .of (INPUT_JSON_WITH_NO_PARENT_PRESENT , OUTPUT_XML_WITH_IMMUNIZATION_NO_PARENT_PRESENT , false ),
@@ -259,6 +302,7 @@ void When_MappingImmunizationWithoutNopatMetaSecurity_Expect_MessageContainsConf
259302 final var parsedImmunization = fhirParseService .parseResource (jsonInput , Immunization .class );
260303 when (confidentialityService .generateConfidentialityCode (parsedImmunization ))
261304 .thenReturn (Optional .of (NOPAT_HL7_CONFIDENTIALITY_CODE ));
305+ when (randomIdGeneratorService .createNewId ()).thenReturn (TEST_ID );
262306
263307 final var actualMessage = observationStatementMapper .mapImmunizationToObservationStatement (
264308 parsedImmunization ,
0 commit comments