diff --git a/service/src/intTest/java/uk/nhs/adaptors/gp2gp/common/task/BaseTaskTest.java b/service/src/intTest/java/uk/nhs/adaptors/gp2gp/common/task/BaseTaskTest.java index 848a44262f..a61aafae17 100644 --- a/service/src/intTest/java/uk/nhs/adaptors/gp2gp/common/task/BaseTaskTest.java +++ b/service/src/intTest/java/uk/nhs/adaptors/gp2gp/common/task/BaseTaskTest.java @@ -1,5 +1,6 @@ package uk.nhs.adaptors.gp2gp.common.task; +import ca.uhn.fhir.context.FhirContext; import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.mock.mockito.MockBean; @@ -17,7 +18,7 @@ @SuppressWarnings("checkstyle:VisibilityModifier") public abstract class BaseTaskTest { public static final ObjectMapper OBJECT_MAPPER = new ObjectMapper(); - public static final FhirParseService FHIR_PARSE_SERVICE = new FhirParseService(); + public static final FhirParseService FHIR_PARSE_SERVICE = new FhirParseService(FhirContext.forDstu3()); @MockBean protected TaskDispatcher taskDispatcher; diff --git a/service/src/main/java/uk/nhs/adaptors/gp2gp/gpc/configuration/GpcFhirParserConfig.java b/service/src/main/java/uk/nhs/adaptors/gp2gp/common/configuration/FhirParserConfig.java similarity index 63% rename from service/src/main/java/uk/nhs/adaptors/gp2gp/gpc/configuration/GpcFhirParserConfig.java rename to service/src/main/java/uk/nhs/adaptors/gp2gp/common/configuration/FhirParserConfig.java index e157beca96..702acad49b 100644 --- a/service/src/main/java/uk/nhs/adaptors/gp2gp/gpc/configuration/GpcFhirParserConfig.java +++ b/service/src/main/java/uk/nhs/adaptors/gp2gp/common/configuration/FhirParserConfig.java @@ -1,15 +1,21 @@ -package uk.nhs.adaptors.gp2gp.gpc.configuration; - -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; +package uk.nhs.adaptors.gp2gp.common.configuration; import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.parser.IParser; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; @Configuration -public class GpcFhirParserConfig { +public class FhirParserConfig { + + @Bean + public FhirContext fhirContext() { + return FhirContext.forDstu3(); + } + @Bean public IParser fhirJsonParser() { return FhirContext.forDstu3().newJsonParser(); } -} \ No newline at end of file + +} diff --git a/service/src/main/java/uk/nhs/adaptors/gp2gp/common/service/FhirParseService.java b/service/src/main/java/uk/nhs/adaptors/gp2gp/common/service/FhirParseService.java index cad0923425..a3d706d277 100644 --- a/service/src/main/java/uk/nhs/adaptors/gp2gp/common/service/FhirParseService.java +++ b/service/src/main/java/uk/nhs/adaptors/gp2gp/common/service/FhirParseService.java @@ -10,7 +10,11 @@ @Service public class FhirParseService { - private final IParser jsonParser = prepareParser(); + private final IParser jsonParser; + + public FhirParseService(FhirContext fhirContext) { + this.jsonParser = prepareParser(fhirContext); + } public T parseResource(String body, Class fhirClass) { try { @@ -20,14 +24,13 @@ public T parseResource(String body, Class fhirClass } } + private IParser prepareParser(FhirContext fhirContext) { + fhirContext.newJsonParser(); + fhirContext.setParserErrorHandler(new StrictErrorHandler()); + return fhirContext.newJsonParser(); + } + public String encodeToJson(IBaseResource resource) { return jsonParser.setPrettyPrint(true).encodeResourceToString(resource); - } - - private IParser prepareParser() { - FhirContext ctx = FhirContext.forDstu3(); - ctx.newJsonParser(); - ctx.setParserErrorHandler(new StrictErrorHandler()); - return ctx.newJsonParser(); - } + } } diff --git a/service/src/main/java/uk/nhs/adaptors/gp2gp/transformJsonToXmlTool/TransformJsonToXml.java b/service/src/main/java/uk/nhs/adaptors/gp2gp/transformJsonToXmlTool/TransformJsonToXml.java index ca3155fd0d..9890e522f1 100644 --- a/service/src/main/java/uk/nhs/adaptors/gp2gp/transformJsonToXmlTool/TransformJsonToXml.java +++ b/service/src/main/java/uk/nhs/adaptors/gp2gp/transformJsonToXmlTool/TransformJsonToXml.java @@ -12,6 +12,7 @@ import java.util.List; import java.util.stream.Collectors; +import ca.uhn.fhir.context.FhirContext; import org.apache.commons.io.FilenameUtils; import org.hl7.fhir.dstu3.model.Bundle; import org.hl7.fhir.dstu3.model.Identifier; @@ -116,7 +117,7 @@ private List getFiles() throws UnreadableJsonFileException, NoJsonFil final String mapJsonToXml(String jsonAsStringInput) { String hl7TranslatedResponse; try { - final Bundle bundle = new FhirParseService().parseResource(jsonAsStringInput, Bundle.class); + final Bundle bundle = new FhirParseService(FhirContext.forDstu3()).parseResource(jsonAsStringInput, Bundle.class); messageContext.initialize(bundle); diff --git a/service/src/test/java/uk/nhs/adaptors/gp2gp/common/configuration/FhirParserConfigTest.java b/service/src/test/java/uk/nhs/adaptors/gp2gp/common/configuration/FhirParserConfigTest.java new file mode 100644 index 0000000000..c2dbb34547 --- /dev/null +++ b/service/src/test/java/uk/nhs/adaptors/gp2gp/common/configuration/FhirParserConfigTest.java @@ -0,0 +1,22 @@ +package uk.nhs.adaptors.gp2gp.common.configuration; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertNotNull; + +class FhirParserConfigTest { + + private FhirParserConfig fhirParserConfig; + + @BeforeEach + void setUp() { + fhirParserConfig = new FhirParserConfig(); + } + + @Test + void shouldCreateValidConfig() { + assertNotNull(fhirParserConfig.fhirContext()); + } + +} \ No newline at end of file diff --git a/service/src/test/java/uk/nhs/adaptors/gp2gp/common/service/FhirParseServiceTest.java b/service/src/test/java/uk/nhs/adaptors/gp2gp/common/service/FhirParseServiceTest.java index d644441789..b17397edfc 100644 --- a/service/src/test/java/uk/nhs/adaptors/gp2gp/common/service/FhirParseServiceTest.java +++ b/service/src/test/java/uk/nhs/adaptors/gp2gp/common/service/FhirParseServiceTest.java @@ -61,4 +61,5 @@ private static CodeableConcept getCodeableConcept() { details.setCoding(List.of(codeableConceptCoding)); return details; } + } \ No newline at end of file diff --git a/service/src/test/java/uk/nhs/adaptors/gp2gp/ehr/mapper/AgentDirectoryMapperTest.java b/service/src/test/java/uk/nhs/adaptors/gp2gp/ehr/mapper/AgentDirectoryMapperTest.java index 9f396ba13b..04905d89fa 100644 --- a/service/src/test/java/uk/nhs/adaptors/gp2gp/ehr/mapper/AgentDirectoryMapperTest.java +++ b/service/src/test/java/uk/nhs/adaptors/gp2gp/ehr/mapper/AgentDirectoryMapperTest.java @@ -10,6 +10,7 @@ import java.io.IOException; +import ca.uhn.fhir.context.FhirContext; import org.hl7.fhir.dstu3.model.Bundle; import org.hl7.fhir.dstu3.model.ResourceType; import org.junit.jupiter.api.AfterEach; @@ -56,7 +57,7 @@ public void setUp() { lenient().when(agentPersonMapper.mapAgentPerson(any(), any())).thenAnswer(answerWithObjectId()); agentDirectoryMapper = new AgentDirectoryMapper(messageContext, agentPersonMapper); - fhirParseService = new FhirParseService(); + fhirParseService = new FhirParseService(FhirContext.forDstu3()); } private Answer answerWithObjectId() { diff --git a/service/src/test/java/uk/nhs/adaptors/gp2gp/ehr/mapper/AgentDirectoryTest.java b/service/src/test/java/uk/nhs/adaptors/gp2gp/ehr/mapper/AgentDirectoryTest.java index 073bd93920..4a9cd2606a 100644 --- a/service/src/test/java/uk/nhs/adaptors/gp2gp/ehr/mapper/AgentDirectoryTest.java +++ b/service/src/test/java/uk/nhs/adaptors/gp2gp/ehr/mapper/AgentDirectoryTest.java @@ -9,6 +9,7 @@ import java.util.Map; import java.util.Optional; +import ca.uhn.fhir.context.FhirContext; import org.hl7.fhir.dstu3.model.Bundle; import org.hl7.fhir.dstu3.model.ResourceType; import org.junit.jupiter.api.BeforeEach; @@ -44,7 +45,7 @@ public void setUp() throws IOException { lenient().when(randomIdGeneratorService.createNewId()).thenReturn(GENERATED_ID_1, GENERATED_ID_2); String jsonInput = ResourceTestFileUtils.getFileContent(INPUT_BUNDLE); - inputBundle = new FhirParseService().parseResource(jsonInput, Bundle.class); + inputBundle = new FhirParseService(FhirContext.forDstu3()).parseResource(jsonInput, Bundle.class); } @Test diff --git a/service/src/test/java/uk/nhs/adaptors/gp2gp/ehr/mapper/AgentPersonMapperTest.java b/service/src/test/java/uk/nhs/adaptors/gp2gp/ehr/mapper/AgentPersonMapperTest.java index 798a4c30b9..38d87f8ac5 100644 --- a/service/src/test/java/uk/nhs/adaptors/gp2gp/ehr/mapper/AgentPersonMapperTest.java +++ b/service/src/test/java/uk/nhs/adaptors/gp2gp/ehr/mapper/AgentPersonMapperTest.java @@ -6,6 +6,7 @@ import java.io.IOException; import java.util.stream.Stream; +import ca.uhn.fhir.context.FhirContext; import org.hl7.fhir.dstu3.model.Bundle; import org.hl7.fhir.dstu3.model.Organization; import org.hl7.fhir.dstu3.model.Practitioner; @@ -52,7 +53,7 @@ public void setUp() { when(randomIdGeneratorService.createNewId()).thenReturn(TEST_ID); messageContext = new MessageContext(randomIdGeneratorService); agentPersonMapper = new AgentPersonMapper(messageContext); - fhirParseService = new FhirParseService(); + fhirParseService = new FhirParseService(FhirContext.forDstu3()); } @ParameterizedTest @@ -149,12 +150,12 @@ private static Stream readPractitionerRoleTests() { private static Practitioner getPractitionerResource() throws IOException { String jsonPractitioner = ResourceTestFileUtils.getFileContent(PRACTITIONER); - return new FhirParseService().parseResource(jsonPractitioner, Practitioner.class); + return new FhirParseService(FhirContext.forDstu3()).parseResource(jsonPractitioner, Practitioner.class); } private static Organization getOrganizationResource() throws IOException { String jsonOrganization = ResourceTestFileUtils.getFileContent(ORGANIZATION); - return new FhirParseService().parseResource(jsonOrganization, Organization.class); + return new FhirParseService(FhirContext.forDstu3()).parseResource(jsonOrganization, Organization.class); } @AfterEach diff --git a/service/src/test/java/uk/nhs/adaptors/gp2gp/ehr/mapper/AllergyStructureMapperTest.java b/service/src/test/java/uk/nhs/adaptors/gp2gp/ehr/mapper/AllergyStructureMapperTest.java index 3911e0dbe4..fc06cd5dd5 100644 --- a/service/src/test/java/uk/nhs/adaptors/gp2gp/ehr/mapper/AllergyStructureMapperTest.java +++ b/service/src/test/java/uk/nhs/adaptors/gp2gp/ehr/mapper/AllergyStructureMapperTest.java @@ -15,6 +15,7 @@ import java.util.Optional; import java.util.stream.Stream; +import ca.uhn.fhir.context.FhirContext; import org.hl7.fhir.dstu3.model.AllergyIntolerance; import org.hl7.fhir.dstu3.model.Bundle; import org.hl7.fhir.dstu3.model.CodeableConcept; @@ -198,7 +199,7 @@ public void setUp() throws IOException { .thenReturn(Optional.empty()); var bundleInput = ResourceTestFileUtils.getFileContent(INPUT_JSON_BUNDLE); - Bundle bundle = new FhirParseService().parseResource(bundleInput, Bundle.class); + Bundle bundle = new FhirParseService(FhirContext.forDstu3()).parseResource(bundleInput, Bundle.class); messageContext = new MessageContext(randomIdGeneratorService); messageContext.initialize(bundle); List.of(ResourceType.Patient, ResourceType.Device) @@ -265,7 +266,7 @@ public void When_ConfidentialityServiceReturnsEmptyOptional_Expect_MessageDoesNo private static AllergyIntolerance parseAllergyIntoleranceFromJsonFile(String filepath) { final var jsonInput = ResourceTestFileUtils.getFileContent(filepath); - return new FhirParseService().parseResource(jsonInput, AllergyIntolerance.class); + return new FhirParseService(FhirContext.forDstu3()).parseResource(jsonInput, AllergyIntolerance.class); } } diff --git a/service/src/test/java/uk/nhs/adaptors/gp2gp/ehr/mapper/BloodPressureMapperTest.java b/service/src/test/java/uk/nhs/adaptors/gp2gp/ehr/mapper/BloodPressureMapperTest.java index c8952312e3..875b3c636f 100644 --- a/service/src/test/java/uk/nhs/adaptors/gp2gp/ehr/mapper/BloodPressureMapperTest.java +++ b/service/src/test/java/uk/nhs/adaptors/gp2gp/ehr/mapper/BloodPressureMapperTest.java @@ -1,5 +1,6 @@ package uk.nhs.adaptors.gp2gp.ehr.mapper; +import ca.uhn.fhir.context.FhirContext; import org.hl7.fhir.dstu3.model.Bundle; import org.hl7.fhir.dstu3.model.CodeableConcept; import org.hl7.fhir.dstu3.model.Observation; @@ -59,6 +60,7 @@ public class BloodPressureMapperTest { private static final String INPUT_BLOOD_PRESSURE_WITH_CODEABLE_CONCEPTS = "blood-pressure-with-codeable-concepts.json"; private static final String EXPECTED_BLOOD_PRESSURE_WITH_CODEABLE_CONCEPTS = "blood-pressure-with-codeable-concepts.xml"; private static final String INPUT_BLOOD_PRESSURE_WITH_NO_CODEABLE_CONCEPTS = "blood-pressure-with-no-codeable-concepts.json"; + private FhirContext fhirCtx = FhirContext.forDstu3(); @Mock private RandomIdGeneratorService randomIdGeneratorService; @@ -92,7 +94,7 @@ public void When_MappingEmptyObservation_Expect_CompoundStatementXmlReturned() t var jsonInput = ResourceTestFileUtils.getFileContent(BLOOD_PRESSURE_FILE_LOCATION + INPUT_EMPTY_OBSERVATION); var expectedOutput = ResourceTestFileUtils.getFileContent(BLOOD_PRESSURE_FILE_LOCATION + EXPECTED_EMPTY_OBSERVATION); - Observation observation = new FhirParseService().parseResource(jsonInput, Observation.class); + Observation observation = new FhirParseService(fhirCtx).parseResource(jsonInput, Observation.class); var outputMessage = bloodPressureMapper.mapBloodPressure(observation, false); assertThat(outputMessage).isEqualTo(expectedOutput); @@ -106,7 +108,7 @@ public void When_MappingBloodPressureWithNestedTrue_Expect_CompoundStatementXmlR var jsonInput = ResourceTestFileUtils.getFileContent(BLOOD_PRESSURE_FILE_LOCATION + INPUT_BLOOD_PRESSURE_WITH_DATA); var expectedOutput = ResourceTestFileUtils.getFileContent(BLOOD_PRESSURE_FILE_LOCATION + EXPECTED_NESTED_BLOOD_PRESSURE); - Observation observation = new FhirParseService().parseResource(jsonInput, Observation.class); + Observation observation = new FhirParseService(fhirCtx).parseResource(jsonInput, Observation.class); var outputMessage = bloodPressureMapper.mapBloodPressure(observation, true); assertThat(outputMessage).isEqualToIgnoringWhitespace(expectedOutput); @@ -121,7 +123,7 @@ public void When_MappingBloodPressure_Expect_CompoundStatementXmlReturned(String var jsonInput = ResourceTestFileUtils.getFileContent(BLOOD_PRESSURE_FILE_LOCATION + inputJson); var expectedOutput = ResourceTestFileUtils.getFileContent(BLOOD_PRESSURE_FILE_LOCATION + outputXml); - Observation observation = new FhirParseService().parseResource(jsonInput, Observation.class); + Observation observation = new FhirParseService(fhirCtx).parseResource(jsonInput, Observation.class); var outputMessage = bloodPressureMapper.mapBloodPressure(observation, false); assertThat(outputMessage) @@ -157,7 +159,7 @@ public void When_MappingBloodPressureWithCodeableConcepts_Expect_CompoundStateme messageContext, randomIdGeneratorService, new StructuredObservationValueMapper(), codeableConceptCdMapper, new ParticipantMapper()); - Observation observation = new FhirParseService().parseResource(jsonInput, Observation.class); + Observation observation = new FhirParseService(fhirCtx).parseResource(jsonInput, Observation.class); var outputMessage = bloodPressureMapper.mapBloodPressure(observation, true); assertThat(outputMessage).isEqualToIgnoringWhitespace(expectedOutput); @@ -172,7 +174,7 @@ public void When_MappingBloodPressureWithNoCodeableConcepts_Expect_Exception() t messageContext, randomIdGeneratorService, new StructuredObservationValueMapper(), codeableConceptCdMapper, new ParticipantMapper()); - Observation observation = new FhirParseService().parseResource(jsonInput, Observation.class); + Observation observation = new FhirParseService(fhirCtx).parseResource(jsonInput, Observation.class); assertThrows(EhrMapperException.class, () -> bloodPressureMapper.mapBloodPressure(observation, true)); diff --git a/service/src/test/java/uk/nhs/adaptors/gp2gp/ehr/mapper/CodeableConceptCdMapperTest.java b/service/src/test/java/uk/nhs/adaptors/gp2gp/ehr/mapper/CodeableConceptCdMapperTest.java index 28e320ee89..03cc3b76fc 100644 --- a/service/src/test/java/uk/nhs/adaptors/gp2gp/ehr/mapper/CodeableConceptCdMapperTest.java +++ b/service/src/test/java/uk/nhs/adaptors/gp2gp/ehr/mapper/CodeableConceptCdMapperTest.java @@ -5,6 +5,7 @@ import java.io.IOException; import java.util.stream.Stream; +import ca.uhn.fhir.context.FhirContext; import org.hl7.fhir.dstu3.model.AllergyIntolerance; import org.hl7.fhir.dstu3.model.Condition; import org.hl7.fhir.dstu3.model.Medication; @@ -68,7 +69,7 @@ private static Stream getTestArgumentsForTopicRelatedProblem() { @BeforeEach public void setUp() { - fhirParseService = new FhirParseService(); + fhirParseService = new FhirParseService(FhirContext.forDstu3()); codeableConceptCdMapper = new CodeableConceptCdMapper(); } diff --git a/service/src/test/java/uk/nhs/adaptors/gp2gp/ehr/mapper/ConditionLinkSetMapperTest.java b/service/src/test/java/uk/nhs/adaptors/gp2gp/ehr/mapper/ConditionLinkSetMapperTest.java index 9b46c7357f..0405bbef44 100644 --- a/service/src/test/java/uk/nhs/adaptors/gp2gp/ehr/mapper/ConditionLinkSetMapperTest.java +++ b/service/src/test/java/uk/nhs/adaptors/gp2gp/ehr/mapper/ConditionLinkSetMapperTest.java @@ -1,5 +1,6 @@ package uk.nhs.adaptors.gp2gp.ehr.mapper; +import ca.uhn.fhir.context.FhirContext; import org.hl7.fhir.dstu3.model.Bundle; import org.hl7.fhir.dstu3.model.CodeableConcept; import org.hl7.fhir.dstu3.model.Condition; @@ -131,7 +132,7 @@ class ConditionLinkSetMapperTest { @BeforeEach void setUp() throws IOException { var bundleInput = ResourceTestFileUtils.getFileContent(TEST_FILES_DIRECTORY + INPUT_JSON_BUNDLE); - final Bundle bundle = new FhirParseService().parseResource(bundleInput, Bundle.class); + final Bundle bundle = new FhirParseService(FhirContext.forDstu3()).parseResource(bundleInput, Bundle.class); inputBundle = new InputBundle(bundle); lenient().when(codeableConceptCdMapper.mapCodeableConceptToCd(any(CodeableConcept.class))) diff --git a/service/src/test/java/uk/nhs/adaptors/gp2gp/ehr/mapper/DiaryPlanStatementMapperTest.java b/service/src/test/java/uk/nhs/adaptors/gp2gp/ehr/mapper/DiaryPlanStatementMapperTest.java index cf061880b7..6cd2184bac 100644 --- a/service/src/test/java/uk/nhs/adaptors/gp2gp/ehr/mapper/DiaryPlanStatementMapperTest.java +++ b/service/src/test/java/uk/nhs/adaptors/gp2gp/ehr/mapper/DiaryPlanStatementMapperTest.java @@ -9,6 +9,7 @@ import java.io.IOException; import java.util.stream.Stream; +import ca.uhn.fhir.context.FhirContext; import org.hl7.fhir.dstu3.model.Bundle; import org.hl7.fhir.dstu3.model.CodeableConcept; import org.hl7.fhir.dstu3.model.ProcedureRequest; @@ -56,6 +57,7 @@ public class DiaryPlanStatementMapperTest { private static final String OUTPUT_JSON_WITH_MULTIPLE_SUPPORTING_INFO = TEST_DIRECTORY + "expected-output-procedure-request-resource-with-multiple-supportInfo.xml"; private static final String INPUT_BUNDLE = TEST_DIRECTORY + "input-bundle.json"; + private FhirContext fhirCtx = FhirContext.forDstu3(); @Mock private RandomIdGeneratorService randomIdGeneratorService; @@ -68,7 +70,7 @@ public class DiaryPlanStatementMapperTest { @BeforeEach public void setUp() throws IOException { String inputJson = ResourceTestFileUtils.getFileContent(INPUT_BUNDLE); - Bundle bundle = new FhirParseService().parseResource(inputJson, Bundle.class); + Bundle bundle = new FhirParseService(fhirCtx).parseResource(inputJson, Bundle.class); when(randomIdGeneratorService.createNewId()).thenReturn(TEST_ID); when(randomIdGeneratorService.createNewOrUseExistingUUID(anyString())).thenReturn(TEST_ID); @@ -91,7 +93,7 @@ public void When_MappingProcedureRequestIsNested_Expect_ResourceMappedWithIsNest String expectedXml = ResourceTestFileUtils.getFileContent(EXPECTED_PLAN_STATEMENT_WITH_IS_NESTED); String inputJson = ResourceTestFileUtils.getFileContent(INPUT_PROCEDURE_REQUEST_WITH_ALL_DATA); - ProcedureRequest inputProcedureRequest = new FhirParseService().parseResource(inputJson, ProcedureRequest.class); + ProcedureRequest inputProcedureRequest = new FhirParseService(fhirCtx).parseResource(inputJson, ProcedureRequest.class); var mappedXml = diaryPlanStatementMapper.mapProcedureRequestToPlanStatement(inputProcedureRequest, true); assertThat(mappedXml).contains(expectedXml); @@ -100,7 +102,7 @@ public void When_MappingProcedureRequestIsNested_Expect_ResourceMappedWithIsNest @Test public void When_MappingProcedureRequestThatIsNotPlan_Expect_ResourceNotMapped() throws IOException { String inputJson = ResourceTestFileUtils.getFileContent(INPUT_PROCEDURE_REQUEST_IS_NOT_PLAN); - ProcedureRequest inputProcedureRequest = new FhirParseService().parseResource(inputJson, ProcedureRequest.class); + ProcedureRequest inputProcedureRequest = new FhirParseService(fhirCtx).parseResource(inputJson, ProcedureRequest.class); var mappedXml = diaryPlanStatementMapper.mapProcedureRequestToPlanStatement(inputProcedureRequest, true); assertThat(mappedXml).isNull(); @@ -109,7 +111,7 @@ public void When_MappingProcedureRequestThatIsNotPlan_Expect_ResourceNotMapped() @Test public void When_MappingProcedureRequestWithoutRequiredAuthoredOn_Expect_MapperException() throws IOException { String inputJson = ResourceTestFileUtils.getFileContent(INPUT_PROCEDURE_REQUEST_WITHOUT_REQUIRED_AUTHORED_ON); - ProcedureRequest inputProcedureRequest = new FhirParseService().parseResource(inputJson, ProcedureRequest.class); + ProcedureRequest inputProcedureRequest = new FhirParseService(fhirCtx).parseResource(inputJson, ProcedureRequest.class); assertThrows(EhrMapperException.class, () -> diaryPlanStatementMapper.mapProcedureRequestToPlanStatement(inputProcedureRequest, true)); @@ -149,7 +151,7 @@ public void When_MappingWithOccurrenceWithStartAndEnd_Expect_TextContainsEarlies """; - final var procedureRequest = new FhirParseService().parseResource(inputJson, ProcedureRequest.class); + final var procedureRequest = new FhirParseService(fhirCtx).parseResource(inputJson, ProcedureRequest.class); var actualXml = diaryPlanStatementMapper.mapProcedureRequestToPlanStatement(procedureRequest, false); assertThat(actualXml).isEqualTo(expectedXml); @@ -185,7 +187,7 @@ public void When_MappingWithOccurrenceWithOnlyStart_Expect_TextDoesNotContainEar """; - final var procedureRequest = new FhirParseService().parseResource(inputJson, ProcedureRequest.class); + final var procedureRequest = new FhirParseService(fhirCtx).parseResource(inputJson, ProcedureRequest.class); var actualXml = diaryPlanStatementMapper.mapProcedureRequestToPlanStatement(procedureRequest, false); assertThat(actualXml).isEqualTo(expectedXml); @@ -226,7 +228,7 @@ public void When_MappingWithDeviceReferenceWhereDeviceHasManufacturer_Expect_Tex """; - final var procedureRequest = new FhirParseService().parseResource(inputJson, ProcedureRequest.class); + final var procedureRequest = new FhirParseService(fhirCtx).parseResource(inputJson, ProcedureRequest.class); var actualXml = diaryPlanStatementMapper.mapProcedureRequestToPlanStatement(procedureRequest, false); assertThat(actualXml).isEqualTo(expectedXml); @@ -267,7 +269,7 @@ public void When_MappingWithDeviceReferenceWhereDeviceHasNoManufacturer_Expect_T """; - final var procedureRequest = new FhirParseService().parseResource(inputJson, ProcedureRequest.class); + final var procedureRequest = new FhirParseService(fhirCtx).parseResource(inputJson, ProcedureRequest.class); var actualXml = diaryPlanStatementMapper.mapProcedureRequestToPlanStatement(procedureRequest, false); assertThat(actualXml).isEqualTo(expectedXml); @@ -279,7 +281,7 @@ public void When_MappingProcedureRequest_Expect_ResourceMapped(String inputJsonP String expectedXml = ResourceTestFileUtils.getFileContent(expectedXmlPath); String inputJson = ResourceTestFileUtils.getFileContent(inputJsonPath); - ProcedureRequest inputProcedureRequest = new FhirParseService().parseResource(inputJson, ProcedureRequest.class); + ProcedureRequest inputProcedureRequest = new FhirParseService(fhirCtx).parseResource(inputJson, ProcedureRequest.class); var mappedXml = diaryPlanStatementMapper.mapProcedureRequestToPlanStatement(inputProcedureRequest, false); assertThat(mappedXml).contains(expectedXml); diff --git a/service/src/test/java/uk/nhs/adaptors/gp2gp/ehr/mapper/DocumentReferenceToNarrativeStatementMapperTest.java b/service/src/test/java/uk/nhs/adaptors/gp2gp/ehr/mapper/DocumentReferenceToNarrativeStatementMapperTest.java index 1a1567ee1c..2ba7320d77 100644 --- a/service/src/test/java/uk/nhs/adaptors/gp2gp/ehr/mapper/DocumentReferenceToNarrativeStatementMapperTest.java +++ b/service/src/test/java/uk/nhs/adaptors/gp2gp/ehr/mapper/DocumentReferenceToNarrativeStatementMapperTest.java @@ -1,5 +1,6 @@ package uk.nhs.adaptors.gp2gp.ehr.mapper; +import ca.uhn.fhir.context.FhirContext; import org.hl7.fhir.dstu3.model.Attachment; import org.hl7.fhir.dstu3.model.Bundle; import org.hl7.fhir.dstu3.model.DocumentReference; @@ -82,6 +83,7 @@ public class DocumentReferenceToNarrativeStatementMapperTest { public static final String NARRATIVE_STATEMENT_REFERENCE_CONFIDENTIALITY_CODE_XPATH = "/component/NarrativeStatement/reference/referredToExternalDocument/" + ConfidentialityCodeUtility.getNopatConfidentialityCodeXpathSegment(); + private FhirContext fhirCtx = FhirContext.forDstu3(); @Mock private RandomIdGeneratorService randomIdGeneratorService; @@ -104,7 +106,7 @@ public void setUp() { lenient().when(randomIdGeneratorService.createNewOrUseExistingUUID(anyString())).thenReturn(TEST_ID); final String bundleInput = ResourceTestFileUtils.getFileContent(INPUT_JSON_BUNDLE); - final Bundle bundle = new FhirParseService().parseResource(bundleInput, Bundle.class); + final Bundle bundle = new FhirParseService(fhirCtx).parseResource(bundleInput, Bundle.class); messageContext = new MessageContext(randomIdGeneratorService); messageContext.initialize(bundle); @@ -128,7 +130,7 @@ void When_DocReferenceMetaSecurityAndSecurityLabelPopulatedWithoutNoPat_Expect_N final String jsonInput = ResourceTestFileUtils.getFileContent(INPUT_JSON_OPTIONAL_DATA_WITH_NOPAT_WITH_SECURITY_AND_SECURITY_LABEL_BUT_WITHOUT_NOPAT); - final DocumentReference parsedDocumentReference = new FhirParseService().parseResource(jsonInput, DocumentReference.class); + final DocumentReference parsedDocumentReference = new FhirParseService(fhirCtx).parseResource(jsonInput, DocumentReference.class); when(redactionsContext.isRedactionMessage()).thenReturn(true); final String outputMessage = mapper.mapDocumentReferenceToNarrativeStatement(parsedDocumentReference); @@ -140,7 +142,7 @@ void When_DocReferenceMetaSecurityAndSecurityLabelPopulatedWithoutNoPat_Expect_N void When_DocReferenceSecurityLabelPopulatedWithNoPat_Expect_NarrativeStatementPopulatesReferredToExternalDocument() { final String jsonInput = ResourceTestFileUtils.getFileContent(INPUT_JSON_OPTIONAL_DATA_WITH_NOPAT_WITH_SECURITY_LABEL); - final DocumentReference parsedDocumentReference = new FhirParseService().parseResource(jsonInput, DocumentReference.class); + final DocumentReference parsedDocumentReference = new FhirParseService(fhirCtx).parseResource(jsonInput, DocumentReference.class); when(redactionsContext.isRedactionMessage()).thenReturn(true); final String outputMessage = mapper.mapDocumentReferenceToNarrativeStatement(parsedDocumentReference); @@ -152,7 +154,7 @@ void When_DocReferenceSecurityLabelPopulatedWithNoPat_Expect_NarrativeStatementP void When_DocReferenceSecurityLabelPopulatedWithNoPatAndNotReduction_Expect_NarrativeStatementReferredToExternalDocIsNotPopulated() { final String jsonInput = ResourceTestFileUtils.getFileContent(INPUT_JSON_OPTIONAL_DATA_WITH_NOPAT_WITH_SECURITY_LABEL); - final DocumentReference parsedDocumentReference = new FhirParseService().parseResource(jsonInput, DocumentReference.class); + final DocumentReference parsedDocumentReference = new FhirParseService(fhirCtx).parseResource(jsonInput, DocumentReference.class); when(redactionsContext.isRedactionMessage()).thenReturn(false); final String outputMessage = mapper.mapDocumentReferenceToNarrativeStatement(parsedDocumentReference); @@ -164,7 +166,7 @@ void When_DocReferenceSecurityLabelPopulatedWithNoPatAndNotReduction_Expect_Narr void When_DocReferenceJsonPopulatedWithNoPat_Expect_NarrativeStatementPopulatesReferredToExternalDocument() { final String jsonInput = ResourceTestFileUtils.getFileContent(INPUT_JSON_OPTIONAL_DATA_WITH_NOPAT_WITH_SECURITY); - final DocumentReference parsedDocumentReference = new FhirParseService().parseResource(jsonInput, DocumentReference.class); + final DocumentReference parsedDocumentReference = new FhirParseService(fhirCtx).parseResource(jsonInput, DocumentReference.class); when(redactionsContext.isRedactionMessage()).thenReturn(true); final String outputMessage = mapper.mapDocumentReferenceToNarrativeStatement(parsedDocumentReference); @@ -176,7 +178,7 @@ void When_DocReferenceJsonPopulatedWithNoPat_Expect_NarrativeStatementPopulatesR void When_DocReferenceJsonPopulatedWithNoPatAndNotReduction_Expect_NarrativeStatementDoesNotPopulateReferredToExternalDoc() { final String jsonInput = ResourceTestFileUtils.getFileContent(INPUT_JSON_OPTIONAL_DATA_WITH_NOPAT_WITH_SECURITY); - final DocumentReference parsedDocumentReference = new FhirParseService().parseResource(jsonInput, DocumentReference.class); + final DocumentReference parsedDocumentReference = new FhirParseService(fhirCtx).parseResource(jsonInput, DocumentReference.class); when(redactionsContext.isRedactionMessage()).thenReturn(false); final String outputMessage = mapper.mapDocumentReferenceToNarrativeStatement(parsedDocumentReference); @@ -188,7 +190,7 @@ void When_DocReferenceJsonPopulatedWithNoPatAndNotReduction_Expect_NarrativeStat void When_DocReferenceJsonNotPopulatedWithNoPat_Expect_NarrativeStatementDoesNotPopulateReferredToExternalDocumentWithNopat() { final String jsonInput = ResourceTestFileUtils.getFileContent(INPUT_JSON_OPTIONAL_DATA); - final DocumentReference parsedDocumentReference = new FhirParseService().parseResource(jsonInput, DocumentReference.class); + final DocumentReference parsedDocumentReference = new FhirParseService(fhirCtx).parseResource(jsonInput, DocumentReference.class); final String outputMessage = mapper.mapDocumentReferenceToNarrativeStatement(parsedDocumentReference); @@ -202,7 +204,7 @@ void When_MappingDocReferenceJson_Expect_NarrativeStatementXmlOutput(String inpu final CharSequence expectedOutputMessage = ResourceTestFileUtils.getFileContent(outputXml); final String jsonInput = ResourceTestFileUtils.getFileContent(inputJson); final DocumentReference parsedDocumentReference = - new FhirParseService().parseResource(jsonInput, DocumentReference.class); + new FhirParseService(fhirCtx).parseResource(jsonInput, DocumentReference.class); final String outputMessage = mapper.mapDocumentReferenceToNarrativeStatement(parsedDocumentReference); @@ -232,7 +234,7 @@ private static Stream documentReferenceResourceFileParams() { void When_MappingParsedDocumentReferenceJsonWithNoDates_Expect_MapperException() { final String jsonInput = ResourceTestFileUtils.getFileContent(INPUT_JSON_REQUIRED_DATA); final DocumentReference parsedDocumentReference = - new FhirParseService().parseResource(jsonInput, DocumentReference.class); + new FhirParseService(fhirCtx).parseResource(jsonInput, DocumentReference.class); parsedDocumentReference.setIndexedElement(null); assertThatThrownBy(() -> mapper.mapDocumentReferenceToNarrativeStatement(parsedDocumentReference)) @@ -244,7 +246,7 @@ void When_MappingParsedDocumentReferenceJsonWithNoDates_Expect_MapperException() void When_MappingParsedDocumentReferenceJsonWithNoContent_Expect_MapperException() { final String jsonInput = ResourceTestFileUtils.getFileContent(INPUT_JSON_REQUIRED_DATA); final DocumentReference parsedDocumentReference = - new FhirParseService().parseResource(jsonInput, DocumentReference.class); + new FhirParseService(fhirCtx).parseResource(jsonInput, DocumentReference.class); parsedDocumentReference.setContent(null); assertThatThrownBy(() -> mapper.mapDocumentReferenceToNarrativeStatement(parsedDocumentReference)) @@ -256,7 +258,7 @@ void When_MappingParsedDocumentReferenceJsonWithNoContent_Expect_MapperException void When_MappingParsedDocumentReferenceJsonWithContentAndNoAttachment_Expect_MapperException() { final String jsonInput = ResourceTestFileUtils.getFileContent(INPUT_JSON_REQUIRED_DATA); final DocumentReference parsedDocumentReference = - new FhirParseService().parseResource(jsonInput, DocumentReference.class); + new FhirParseService(fhirCtx).parseResource(jsonInput, DocumentReference.class); parsedDocumentReference.getContent().getFirst().setAttachment(null); assertThatThrownBy(() -> mapper.mapDocumentReferenceToNarrativeStatement(parsedDocumentReference)) @@ -268,7 +270,7 @@ void When_MappingParsedDocumentReferenceJsonWithContentAndNoAttachment_Expect_Ma void When_MappingParsedDocumentReferenceJsonWithNoAttachmentContentType_Expect_MapperException() { final String jsonInput = ResourceTestFileUtils.getFileContent(INPUT_JSON_REQUIRED_DATA); final DocumentReference parsedDocumentReference = - new FhirParseService().parseResource(jsonInput, DocumentReference.class); + new FhirParseService(fhirCtx).parseResource(jsonInput, DocumentReference.class); final Attachment attachment = parsedDocumentReference.getContent().getFirst().getAttachment(); attachment.setTitle("some title").setContentType(null); diff --git a/service/src/test/java/uk/nhs/adaptors/gp2gp/ehr/mapper/EhrExtractMapperComponentTest.java b/service/src/test/java/uk/nhs/adaptors/gp2gp/ehr/mapper/EhrExtractMapperComponentTest.java index 3f69d7bf75..16851c69a9 100644 --- a/service/src/test/java/uk/nhs/adaptors/gp2gp/ehr/mapper/EhrExtractMapperComponentTest.java +++ b/service/src/test/java/uk/nhs/adaptors/gp2gp/ehr/mapper/EhrExtractMapperComponentTest.java @@ -1,5 +1,6 @@ package uk.nhs.adaptors.gp2gp.ehr.mapper; +import ca.uhn.fhir.context.FhirContext; import org.hl7.fhir.dstu3.model.AllergyIntolerance; import org.hl7.fhir.dstu3.model.Bundle; import org.hl7.fhir.dstu3.model.CodeableConcept; @@ -80,6 +81,7 @@ public class EhrExtractMapperComponentTest { private static final String TEST_FROM_ODS_CODE = "test-from-ods-code"; private static final String TEST_TO_ODS_CODE = "test-to-ods-code"; private static final String TEST_DATE_TIME = "2020-01-01T01:01:01.01Z"; + private FhirContext fhirCtx = FhirContext.forDstu3(); private static GetGpcStructuredTaskDefinition getGpcStructuredTaskDefinition; @@ -224,7 +226,7 @@ public void tearDown() { public void When_MappingProperJsonRequestBody_Expect_ProperXmlOutput(String input, String expected) { String expectedJsonToXmlContent = ResourceTestFileUtils.getFileContent(OUTPUT_PATH + expected); String inputJsonFileContent = ResourceTestFileUtils.getFileContent(INPUT_PATH + input); - Bundle bundle = new FhirParseService().parseResource(inputJsonFileContent, Bundle.class); + Bundle bundle = new FhirParseService(fhirCtx).parseResource(inputJsonFileContent, Bundle.class); messageContext.initialize(bundle); EhrExtractTemplateParameters ehrExtractTemplateParameters = ehrExtractMapper.mapBundleToEhrFhirExtractParams( @@ -253,7 +255,7 @@ private static Stream testData() { public void When_MappingJsonBody_Expect_OnlyOneConsultationResource() { String expectedJsonToXmlContent = ResourceTestFileUtils.getFileContent(OUTPUT_PATH + EXPECTED_XML_FOR_ONE_CONSULTATION_RESOURCE); String inputJsonFileContent = ResourceTestFileUtils.getFileContent(ONE_CONSULTATION_RESOURCE_BUNDLE); - Bundle bundle = new FhirParseService().parseResource(inputJsonFileContent, Bundle.class); + Bundle bundle = new FhirParseService(fhirCtx).parseResource(inputJsonFileContent, Bundle.class); messageContext.initialize(bundle); EhrExtractTemplateParameters ehrExtractTemplateParameters = ehrExtractMapper.mapBundleToEhrFhirExtractParams( @@ -266,7 +268,7 @@ public void When_MappingJsonBody_Expect_OnlyOneConsultationResource() { @Test public void When_TransformingResourceToEhrComp_Expect_NoDuplicateMappings() { String bundle = ResourceTestFileUtils.getFileContent(DUPLICATE_RESOURCE_BUNDLE); - Bundle parsedBundle = new FhirParseService().parseResource(bundle, Bundle.class); + Bundle parsedBundle = new FhirParseService(fhirCtx).parseResource(bundle, Bundle.class); messageContext.initialize(parsedBundle); var translatedOutput = nonConsultationResourceMapper.mapRemainingResourcesToEhrCompositions(parsedBundle); assertThat(translatedOutput.size()).isEqualTo(1); diff --git a/service/src/test/java/uk/nhs/adaptors/gp2gp/ehr/mapper/EhrFolderEffectiveTimeTest.java b/service/src/test/java/uk/nhs/adaptors/gp2gp/ehr/mapper/EhrFolderEffectiveTimeTest.java index 2a12f52a9e..ee574d59ad 100644 --- a/service/src/test/java/uk/nhs/adaptors/gp2gp/ehr/mapper/EhrFolderEffectiveTimeTest.java +++ b/service/src/test/java/uk/nhs/adaptors/gp2gp/ehr/mapper/EhrFolderEffectiveTimeTest.java @@ -3,6 +3,7 @@ import static org.assertj.core.api.AssertionsForClassTypes.assertThat; import static org.junit.jupiter.api.Assertions.assertAll; +import ca.uhn.fhir.context.FhirContext; import org.apache.commons.lang3.StringUtils; import org.hl7.fhir.dstu3.model.Encounter; import org.hl7.fhir.dstu3.model.Period; @@ -14,7 +15,7 @@ public class EhrFolderEffectiveTimeTest { - private static final FhirParseService FHIR_PARSER = new FhirParseService(); + private static final FhirParseService FHIR_PARSER = new FhirParseService(FhirContext.forDstu3()); private static final String INITIAL_START_DATE_HL7 = "20190828103005"; private static final String EARLIER_START_DATE_HL7 = "20180828103005"; diff --git a/service/src/test/java/uk/nhs/adaptors/gp2gp/ehr/mapper/EncounterComponentsMapperTest.java b/service/src/test/java/uk/nhs/adaptors/gp2gp/ehr/mapper/EncounterComponentsMapperTest.java index 353459eb13..9df1fba1a8 100644 --- a/service/src/test/java/uk/nhs/adaptors/gp2gp/ehr/mapper/EncounterComponentsMapperTest.java +++ b/service/src/test/java/uk/nhs/adaptors/gp2gp/ehr/mapper/EncounterComponentsMapperTest.java @@ -1,5 +1,6 @@ package uk.nhs.adaptors.gp2gp.ehr.mapper; +import ca.uhn.fhir.context.FhirContext; import org.hl7.fhir.dstu3.model.AllergyIntolerance; import org.hl7.fhir.dstu3.model.Bundle; import org.hl7.fhir.dstu3.model.CodeableConcept; @@ -501,7 +502,7 @@ private static Stream emptyResult() { private Bundle initializeMessageContext(String inputJsonPath) { String inputJson = ResourceTestFileUtils.getFileContent(inputJsonPath); - Bundle bundle = new FhirParseService().parseResource(inputJson, Bundle.class); + Bundle bundle = new FhirParseService(FhirContext.forDstu3()).parseResource(inputJson, Bundle.class); messageContext.initialize(bundle); IdType conditionId = buildIdType(ResourceType.Practitioner, PRACTITIONER_ID); diff --git a/service/src/test/java/uk/nhs/adaptors/gp2gp/ehr/mapper/EncounterMapperTest.java b/service/src/test/java/uk/nhs/adaptors/gp2gp/ehr/mapper/EncounterMapperTest.java index 923eca4423..67afaaf903 100644 --- a/service/src/test/java/uk/nhs/adaptors/gp2gp/ehr/mapper/EncounterMapperTest.java +++ b/service/src/test/java/uk/nhs/adaptors/gp2gp/ehr/mapper/EncounterMapperTest.java @@ -13,6 +13,7 @@ import java.util.List; import java.util.stream.Stream; +import ca.uhn.fhir.context.FhirContext; import org.apache.commons.lang3.StringUtils; import org.hl7.fhir.dstu3.model.Bundle; import org.hl7.fhir.dstu3.model.CodeableConcept; @@ -45,6 +46,7 @@ public class EncounterMapperTest { private static final Date CONSULTATION_DATE = Date.from(Instant.parse("2010-01-13T15:13:32Z")); private static final String TEST_LOCATION_NAME = "Test Location"; private static final String TEST_LOCATION_ID = "EB3994A6-5A87-4B53-A414-913137072F57"; + private FhirContext fhirCtx = FhirContext.forDstu3(); public static final Bundle.BundleEntryComponent BUNDLE_ENTRY_WITH_CONSULTATION = new Bundle.BundleEntryComponent() .setResource(new ListResource() @@ -166,7 +168,7 @@ public void When_MappingParsedEncounterJson_Expect_EhrCompositionXmlOutput(Strin String expectedOutputMessage = ResourceTestFileUtils.getFileContent(output); var jsonInput = ResourceTestFileUtils.getFileContent(input); - Encounter parsedEncounter = new FhirParseService().parseResource(jsonInput, Encounter.class); + Encounter parsedEncounter = new FhirParseService(fhirCtx).parseResource(jsonInput, Encounter.class); when(encounterComponentsMapper.mapComponents(parsedEncounter)).thenReturn(sampleComponent); String outputMessage = encounterMapper.mapEncounterToEhrComposition(parsedEncounter); @@ -201,7 +203,7 @@ public void When_MappingEncounterWithNoType_Expect_Exception() throws IOExceptio var jsonInput = ResourceTestFileUtils.getFileContent(INPUT_JSON_WITH_NO_TYPE); - Encounter parsedEncounter = new FhirParseService().parseResource(jsonInput, Encounter.class); + Encounter parsedEncounter = new FhirParseService(fhirCtx).parseResource(jsonInput, Encounter.class); when(encounterComponentsMapper.mapComponents(parsedEncounter)).thenReturn(sampleComponent); @@ -216,7 +218,7 @@ public void When_MappingEncounterWithInvalidParticipantReferenceResourceType_Exp var jsonInput = ResourceTestFileUtils.getFileContent(INPUT_JSON_WITH_PERFORMER_INVALID_REFERENCE_RESOURCE_TYPE); - Encounter parsedEncounter = new FhirParseService().parseResource(jsonInput, Encounter.class); + Encounter parsedEncounter = new FhirParseService(fhirCtx).parseResource(jsonInput, Encounter.class); when(encounterComponentsMapper.mapComponents(parsedEncounter)).thenReturn(sampleComponent); @@ -228,7 +230,7 @@ public void When_MappingEncounterWithInvalidParticipantReferenceResourceType_Exp @Test public void When_MappingEmptyConsultation_Expect_NoEhrCompositionGenerated() throws IOException { var jsonInput = ResourceTestFileUtils.getFileContent(INPUT_JSON_ENCOUNTER_NO_ASSOCIATED_CONSULTATION); - Encounter parsedEncounter = new FhirParseService().parseResource(jsonInput, Encounter.class); + Encounter parsedEncounter = new FhirParseService(fhirCtx).parseResource(jsonInput, Encounter.class); String outputMessage = encounterMapper.mapEncounterToEhrComposition(parsedEncounter); assertThat(outputMessage).isEqualTo(StringUtils.EMPTY); diff --git a/service/src/test/java/uk/nhs/adaptors/gp2gp/ehr/mapper/ImmunizationObservationStatementMapperTest.java b/service/src/test/java/uk/nhs/adaptors/gp2gp/ehr/mapper/ImmunizationObservationStatementMapperTest.java index b0d696d9b8..51c016d2ff 100644 --- a/service/src/test/java/uk/nhs/adaptors/gp2gp/ehr/mapper/ImmunizationObservationStatementMapperTest.java +++ b/service/src/test/java/uk/nhs/adaptors/gp2gp/ehr/mapper/ImmunizationObservationStatementMapperTest.java @@ -1,5 +1,6 @@ package uk.nhs.adaptors.gp2gp.ehr.mapper; +import ca.uhn.fhir.context.FhirContext; import org.hl7.fhir.dstu3.model.Bundle; import org.hl7.fhir.dstu3.model.CodeableConcept; import org.hl7.fhir.dstu3.model.Immunization; @@ -174,7 +175,7 @@ void setUp() throws IOException { when(randomIdGeneratorService.createNewOrUseExistingUUID(anyString())).thenReturn(TEST_ID); when(codeableConceptCdMapper.mapCodeableConceptToCd(any(CodeableConcept.class))) .thenReturn(CodeableConceptMapperMockUtil.NULL_FLAVOR_CODE); - fhirParseService = new FhirParseService(); + fhirParseService = new FhirParseService(FhirContext.forDstu3()); messageContext = new MessageContext(randomIdGeneratorService); var bundleInput = ResourceTestFileUtils.getFileContent(INPUT_JSON_BUNDLE); Bundle bundle = fhirParseService.parseResource(bundleInput, Bundle.class); diff --git a/service/src/test/java/uk/nhs/adaptors/gp2gp/ehr/mapper/InputBundleTest.java b/service/src/test/java/uk/nhs/adaptors/gp2gp/ehr/mapper/InputBundleTest.java index 061b54e84b..6519d79dc3 100644 --- a/service/src/test/java/uk/nhs/adaptors/gp2gp/ehr/mapper/InputBundleTest.java +++ b/service/src/test/java/uk/nhs/adaptors/gp2gp/ehr/mapper/InputBundleTest.java @@ -6,6 +6,7 @@ import java.io.IOException; import java.util.Optional; +import ca.uhn.fhir.context.FhirContext; import org.hl7.fhir.dstu3.model.Bundle; import org.hl7.fhir.dstu3.model.DiagnosticReport; import org.hl7.fhir.dstu3.model.IdType; @@ -42,7 +43,7 @@ public class InputBundleTest { @BeforeEach public void setUp() throws IOException { String inputJson = ResourceTestFileUtils.getFileContent(INPUT_BUNDLE_PATH); - bundle = new FhirParseService().parseResource(inputJson, Bundle.class); + bundle = new FhirParseService(FhirContext.forDstu3()).parseResource(inputJson, Bundle.class); } @Test diff --git a/service/src/test/java/uk/nhs/adaptors/gp2gp/ehr/mapper/MedicationStatementMapperTest.java b/service/src/test/java/uk/nhs/adaptors/gp2gp/ehr/mapper/MedicationStatementMapperTest.java index 3172bc1eba..0e10a27e62 100644 --- a/service/src/test/java/uk/nhs/adaptors/gp2gp/ehr/mapper/MedicationStatementMapperTest.java +++ b/service/src/test/java/uk/nhs/adaptors/gp2gp/ehr/mapper/MedicationStatementMapperTest.java @@ -14,6 +14,7 @@ import java.util.Optional; import java.util.stream.Stream; +import ca.uhn.fhir.context.FhirContext; import org.hl7.fhir.dstu3.model.Bundle; import org.hl7.fhir.dstu3.model.MedicationRequest; import org.hl7.fhir.dstu3.model.Reference; @@ -166,6 +167,7 @@ public class MedicationStatementMapperTest { codeSystem="2.16.840.1.113883.4.642.3.47" displayName="no disclosure to patient, family or caregivers without attending provider's authorization" />"""; + private FhirContext fhirCtx = FhirContext.forDstu3(); private static final String PRACTITIONER_RESOURCE_1 = "Practitioner/1"; private static final String PRACTITIONER_RESOURCE_2 = "Practitioner/2"; @@ -188,7 +190,7 @@ public void setUp() throws IOException { codeableConceptCdMapper = new CodeableConceptCdMapper(); var bundleInput = ResourceTestFileUtils.getFileContent(INPUT_JSON_BUNDLE); - Bundle bundle = new FhirParseService().parseResource(bundleInput, Bundle.class); + Bundle bundle = new FhirParseService(fhirCtx).parseResource(bundleInput, Bundle.class); messageContext = new MessageContext(mockRandomIdGeneratorService); messageContext.initialize(bundle); @@ -242,7 +244,7 @@ private static Stream resourceFileParams() { private void assertThatInputMapsToExpectedOutput(String inputJsonResourcePath, String outputXmlResourcePath) { var expected = ResourceTestFileUtils.getFileContent(outputXmlResourcePath); var input = ResourceTestFileUtils.getFileContent(inputJsonResourcePath); - var parsedMedicationRequest = new FhirParseService().parseResource(input, MedicationRequest.class); + var parsedMedicationRequest = new FhirParseService(fhirCtx).parseResource(input, MedicationRequest.class); String outputMessage = medicationStatementMapper.mapMedicationRequestToMedicationStatement(parsedMedicationRequest); @@ -259,18 +261,18 @@ public void When_MappingBasedOnField_Expect_CorrectReferences() { var inputAuthorise1 = ResourceTestFileUtils.getFileContent(INPUT_JSON_WITH_PLAN_ACUTE_PRESCRIPTION); - var parsedMedicationRequest1 = new FhirParseService().parseResource(inputAuthorise1, MedicationRequest.class); + var parsedMedicationRequest1 = new FhirParseService(fhirCtx).parseResource(inputAuthorise1, MedicationRequest.class); medicationStatementMapper.mapMedicationRequestToMedicationStatement(parsedMedicationRequest1); when(mockRandomIdGeneratorService.createNewId()).thenReturn("456", "123", "789"); var inputWithBasedOn = ResourceTestFileUtils.getFileContent(INPUT_JSON_WITH_ORDER_BASED_ON); - var parsedMedicationRequestWithBasedOn = new FhirParseService().parseResource(inputWithBasedOn, MedicationRequest.class); + var parsedMedicationRequestWithBasedOn = new FhirParseService(fhirCtx).parseResource(inputWithBasedOn, MedicationRequest.class); String outputMessageWithBasedOn = medicationStatementMapper.mapMedicationRequestToMedicationStatement(parsedMedicationRequestWithBasedOn); when(mockRandomIdGeneratorService.createNewId()).thenReturn("789"); var inputAuthorise2 = ResourceTestFileUtils.getFileContent(INPUT_JSON_WITH_PLAN_REPEAT_PRESCRIPTION); - var parsedMedicationRequest2 = new FhirParseService().parseResource(inputAuthorise2, MedicationRequest.class); + var parsedMedicationRequest2 = new FhirParseService(fhirCtx).parseResource(inputAuthorise2, MedicationRequest.class); medicationStatementMapper.mapMedicationRequestToMedicationStatement(parsedMedicationRequest2); assertThat(outputMessageWithBasedOn).isEqualTo(expected); @@ -280,7 +282,7 @@ public void When_MappingBasedOnField_Expect_CorrectReferences() { @MethodSource("resourceFileExpectException") public void When_MappingMedicationRequestWithInvalidResource_Expect_Exception(String inputJson) throws IOException { var jsonInput = ResourceTestFileUtils.getFileContent(inputJson); - MedicationRequest parsedMedicationRequest = new FhirParseService().parseResource(jsonInput, MedicationRequest.class); + MedicationRequest parsedMedicationRequest = new FhirParseService(fhirCtx).parseResource(jsonInput, MedicationRequest.class); assertThrows(EhrMapperException.class, () -> medicationStatementMapper.mapMedicationRequestToMedicationStatement(parsedMedicationRequest)); @@ -306,7 +308,7 @@ public void When_MappingMedicationRequestWithRequesterWithOnBehalfOf_Expect_Part when(mockRandomIdGeneratorService.createNewId()).thenReturn(TEST_ID); codeableConceptCdMapper = new CodeableConceptCdMapper(); var bundleInput = ResourceTestFileUtils.getFileContent(INPUT_JSON_BUNDLE); - Bundle bundle = new FhirParseService().parseResource(bundleInput, Bundle.class); + Bundle bundle = new FhirParseService(fhirCtx).parseResource(bundleInput, Bundle.class); var messageContextMock = mock(MessageContext.class); var agentDirectoryMock = mock(AgentDirectory.class); @@ -327,7 +329,7 @@ public void When_MappingMedicationRequestWithRequesterWithOnBehalfOf_Expect_Part ); var jsonInput = ResourceTestFileUtils.getFileContent(INPUT_JSON_WITH_REQUESTER_ON_BEHALF_OF); - MedicationRequest parsedMedicationRequest = new FhirParseService().parseResource(jsonInput, MedicationRequest.class); + MedicationRequest parsedMedicationRequest = new FhirParseService(fhirCtx).parseResource(jsonInput, MedicationRequest.class); medicationStatementMapper.mapMedicationRequestToMedicationStatement(parsedMedicationRequest); ArgumentCaptor agent = ArgumentCaptor.forClass(Reference.class); @@ -354,7 +356,7 @@ public void When_MappingMedicationRequestWithParticipant_Expect_ParticipantMappe when(mockRandomIdGeneratorService.createNewId()).thenReturn(TEST_ID); codeableConceptCdMapper = new CodeableConceptCdMapper(); var bundleInput = ResourceTestFileUtils.getFileContent(INPUT_JSON_BUNDLE); - Bundle bundle = new FhirParseService().parseResource(bundleInput, Bundle.class); + Bundle bundle = new FhirParseService(fhirCtx).parseResource(bundleInput, Bundle.class); var messageContextMock = mock(MessageContext.class); var agentDirectoryMock = mock(AgentDirectory.class); @@ -375,7 +377,7 @@ public void When_MappingMedicationRequestWithParticipant_Expect_ParticipantMappe ); var jsonInput = ResourceTestFileUtils.getFileContent(inputJson); - MedicationRequest parsedMedicationRequest = new FhirParseService().parseResource(jsonInput, MedicationRequest.class); + MedicationRequest parsedMedicationRequest = new FhirParseService(fhirCtx).parseResource(jsonInput, MedicationRequest.class); medicationStatementMapper.mapMedicationRequestToMedicationStatement(parsedMedicationRequest); ArgumentCaptor agent = ArgumentCaptor.forClass(Reference.class); @@ -405,7 +407,7 @@ public void When_MappingMedicationRequest_WithMedicationStatement_Expect_Prescri codeableConceptCdMapper = new CodeableConceptCdMapper(); var bundleInput = ResourceTestFileUtils.getFileContent(INPUT_JSON_BUNDLE_WITH_MEDICATION_STATEMENTS); - Bundle bundle = new FhirParseService().parseResource(bundleInput, Bundle.class); + Bundle bundle = new FhirParseService(fhirCtx).parseResource(bundleInput, Bundle.class); var messageContextMock = mock(MessageContext.class); var agentDirectoryMock = mock(AgentDirectory.class); @@ -426,7 +428,7 @@ public void When_MappingMedicationRequest_WithMedicationStatement_Expect_Prescri ); var jsonInput = ResourceTestFileUtils.getFileContent(inputJson); - MedicationRequest parsedMedicationRequest = new FhirParseService().parseResource(jsonInput, MedicationRequest.class); + MedicationRequest parsedMedicationRequest = new FhirParseService(fhirCtx).parseResource(jsonInput, MedicationRequest.class); var outputString = medicationStatementMapper.mapMedicationRequestToMedicationStatement(parsedMedicationRequest); assertXmlIsEqual(outputString, expected); @@ -441,7 +443,7 @@ public void When_ConfidentialityServiceReturnsConfidentialityCode_Expect_Message String inputJson ) { final var jsonInput = ResourceTestFileUtils.getFileContent(inputJson); - final var parsedMedicationRequest = new FhirParseService() + final var parsedMedicationRequest = new FhirParseService(fhirCtx) .parseResource(jsonInput, MedicationRequest.class); when(confidentialityService.generateConfidentialityCode(parsedMedicationRequest)) .thenReturn(Optional.of(CONFIDENTIALITY_CODE)); @@ -463,7 +465,7 @@ public void When_ConfidentialityServiceReturnsEmptyOptional_Expect_MessageDoesNo String inputJson ) { final var jsonInput = ResourceTestFileUtils.getFileContent(inputJson); - final var parsedMedicationRequest = new FhirParseService() + final var parsedMedicationRequest = new FhirParseService(fhirCtx) .parseResource(jsonInput, MedicationRequest.class); when(confidentialityService.generateConfidentialityCode(parsedMedicationRequest)) .thenReturn(Optional.empty()); diff --git a/service/src/test/java/uk/nhs/adaptors/gp2gp/ehr/mapper/NonConsultationResourceMapperTest.java b/service/src/test/java/uk/nhs/adaptors/gp2gp/ehr/mapper/NonConsultationResourceMapperTest.java index 1cb527063d..0b0ae9045b 100644 --- a/service/src/test/java/uk/nhs/adaptors/gp2gp/ehr/mapper/NonConsultationResourceMapperTest.java +++ b/service/src/test/java/uk/nhs/adaptors/gp2gp/ehr/mapper/NonConsultationResourceMapperTest.java @@ -1,5 +1,6 @@ package uk.nhs.adaptors.gp2gp.ehr.mapper; +import ca.uhn.fhir.context.FhirContext; import org.hl7.fhir.dstu3.model.Bundle; import org.hl7.fhir.dstu3.model.Resource; import org.hl7.fhir.dstu3.model.ResourceType; @@ -99,7 +100,7 @@ public class NonConsultationResourceMapperTest { public void setUp() { lenient().when(randomIdGeneratorService.createNewId()).thenReturn(TEST_ID); messageContext = new MessageContext(randomIdGeneratorService); - fhirParseService = new FhirParseService(); + fhirParseService = new FhirParseService(FhirContext.forDstu3()); } @AfterEach diff --git a/service/src/test/java/uk/nhs/adaptors/gp2gp/ehr/mapper/ObservationStatementMapperTest.java b/service/src/test/java/uk/nhs/adaptors/gp2gp/ehr/mapper/ObservationStatementMapperTest.java index 68a8de77f9..f3eb54fa57 100644 --- a/service/src/test/java/uk/nhs/adaptors/gp2gp/ehr/mapper/ObservationStatementMapperTest.java +++ b/service/src/test/java/uk/nhs/adaptors/gp2gp/ehr/mapper/ObservationStatementMapperTest.java @@ -13,6 +13,7 @@ import java.io.IOException; import java.util.stream.Stream; +import ca.uhn.fhir.context.FhirContext; import org.hl7.fhir.dstu3.model.Attachment; import org.hl7.fhir.dstu3.model.Bundle; import org.hl7.fhir.dstu3.model.CodeableConcept; @@ -185,6 +186,7 @@ public class ObservationStatementMapperTest { + "expected-output-observation-statement-32.xml"; private static final String OUTPUT_XML_WITH_BODY_SITE = TEST_FILE_DIRECTORY + "expected-output-observation-with-body-site.xml"; + private FhirContext fhirCtx = FhirContext.forDstu3(); private CharSequence expectedOutputMessage; private ObservationStatementMapper observationStatementMapper; @@ -223,7 +225,7 @@ public void When_MappingObservationJson_Expect_ObservationStatementXmlOutput(Str expectedOutputMessage = ResourceTestFileUtils.getFileContent(outputXml); var jsonInput = ResourceTestFileUtils.getFileContent(inputJson); - Observation parsedObservation = new FhirParseService().parseResource(jsonInput, Observation.class); + Observation parsedObservation = new FhirParseService(fhirCtx).parseResource(jsonInput, Observation.class); String outputMessage = observationStatementMapper.mapObservationToObservationStatement(parsedObservation, false); assertThat(outputMessage).isEqualToIgnoringWhitespace(expectedOutputMessage); @@ -235,7 +237,7 @@ public void When_MappingObservationJson_Expect_ErrorThrown(String inputJson, Cla messageContext.getAgentDirectory().getAgentId(buildReference(ResourceType.Practitioner, "something")); var jsonInput = ResourceTestFileUtils.getFileContent(inputJson); - Observation parsedObservation = new FhirParseService().parseResource(jsonInput, Observation.class); + Observation parsedObservation = new FhirParseService(fhirCtx).parseResource(jsonInput, Observation.class); var exception = assertThrows(EhrMapperException.class, () -> observationStatementMapper.mapObservationToObservationStatement(parsedObservation, false)); @@ -248,7 +250,7 @@ public void When_MappingObservationJson_Expect_ErrorThrown(String inputJson, Cla public void When_MappingParsedObservationJsonWithNestedTrue_Expect_ObservationStatementXmlOutput() throws IOException { expectedOutputMessage = ResourceTestFileUtils.getFileContent(OUTPUT_XML_USES_NESTED_COMPONENT); var jsonInput = ResourceTestFileUtils.getFileContent(INPUT_JSON_WITH_EFFECTIVE_DATE_TIME); - Observation parsedObservation = new FhirParseService().parseResource(jsonInput, Observation.class); + Observation parsedObservation = new FhirParseService(fhirCtx).parseResource(jsonInput, Observation.class); String outputMessage = observationStatementMapper.mapObservationToObservationStatement(parsedObservation, true); @@ -258,7 +260,7 @@ public void When_MappingParsedObservationJsonWithNestedTrue_Expect_ObservationSt @Test public void When_MappingObservationWithInvalidParticipantResourceType_Expect_Exception() throws IOException { var jsonInput = ResourceTestFileUtils.getFileContent(INPUT_JSON_WITH_PARTICIPANT_INVALID_REFERENCE_RESOURCE_TYPE); - Observation parsedObservation = new FhirParseService().parseResource(jsonInput, Observation.class); + Observation parsedObservation = new FhirParseService(fhirCtx).parseResource(jsonInput, Observation.class); assertThatThrownBy(() -> observationStatementMapper.mapObservationToObservationStatement(parsedObservation, true)) .isExactlyInstanceOf(EhrMapperException.class) diff --git a/service/src/test/java/uk/nhs/adaptors/gp2gp/ehr/mapper/ObservationToNarrativeStatementMapperTest.java b/service/src/test/java/uk/nhs/adaptors/gp2gp/ehr/mapper/ObservationToNarrativeStatementMapperTest.java index 820b0b4350..3edc42f027 100644 --- a/service/src/test/java/uk/nhs/adaptors/gp2gp/ehr/mapper/ObservationToNarrativeStatementMapperTest.java +++ b/service/src/test/java/uk/nhs/adaptors/gp2gp/ehr/mapper/ObservationToNarrativeStatementMapperTest.java @@ -11,6 +11,7 @@ import java.io.IOException; import java.util.stream.Stream; +import ca.uhn.fhir.context.FhirContext; import org.hl7.fhir.dstu3.model.Attachment; import org.hl7.fhir.dstu3.model.Bundle; import org.hl7.fhir.dstu3.model.Observation; @@ -56,6 +57,7 @@ public class ObservationToNarrativeStatementMapperTest { private static final String OUTPUT_XML_USES_AGENT = TEST_FILE_DIRECTORY + "expected-output-narrative-statement-5.xml"; private static final String INPUT_JSON_WITH_SAMPLED_DATA_VALUE = TEST_FILE_DIRECTORY + "example-observation-with-sampleddata.json"; private static final String INPUT_JSON_WITH_ATTACHMENT_VALUE = TEST_FILE_DIRECTORY + "example-observation-with-attachment.json"; + private FhirContext fhirCtx = FhirContext.forDstu3(); @Mock private RandomIdGeneratorService randomIdGeneratorService; @@ -87,7 +89,7 @@ public void When_MappingObservationJson_Expect_NarrativeStatementXmlOutput(Strin expectedOutputMessage = ResourceTestFileUtils.getFileContent(outputXml); var jsonInput = ResourceTestFileUtils.getFileContent(inputJson); - Observation parsedObservation = new FhirParseService().parseResource(jsonInput, Observation.class); + Observation parsedObservation = new FhirParseService(fhirCtx).parseResource(jsonInput, Observation.class); String outputMessage = observationToNarrativeStatementMapper.mapObservationToNarrativeStatement(parsedObservation, false); @@ -111,7 +113,7 @@ private static Stream resourceFileParams() { public void When_MappingObservationJsonWithNestedTrue_Expect_NarrativeStatementXmlOutput() throws IOException { expectedOutputMessage = ResourceTestFileUtils.getFileContent(OUTPUT_XML_USES_NESTED_COMPONENT); var jsonInput = ResourceTestFileUtils.getFileContent(INPUT_JSON_WITH_EFFECTIVE_DATE_TIME); - Observation parsedObservation = new FhirParseService().parseResource(jsonInput, Observation.class); + Observation parsedObservation = new FhirParseService(fhirCtx).parseResource(jsonInput, Observation.class); String outputMessage = observationToNarrativeStatementMapper.mapObservationToNarrativeStatement(parsedObservation, true); @@ -121,7 +123,7 @@ public void When_MappingObservationJsonWithNestedTrue_Expect_NarrativeStatementX @Test public void When_MappingParsedObservationJsonWithNoDates_Expect_MapperException() throws IOException { var jsonInput = ResourceTestFileUtils.getFileContent(INPUT_JSON_WITH_NO_DATES); - Observation parsedObservation = new FhirParseService().parseResource(jsonInput, Observation.class); + Observation parsedObservation = new FhirParseService(fhirCtx).parseResource(jsonInput, Observation.class); assertThrows(EhrMapperException.class, () -> observationToNarrativeStatementMapper.mapObservationToNarrativeStatement(parsedObservation, true)); @@ -130,7 +132,7 @@ public void When_MappingParsedObservationJsonWithNoDates_Expect_MapperException( @Test public void When_MappingObservationWithInvalidParticipantResourceType_Expect_MapperException() throws IOException { var jsonInput = ResourceTestFileUtils.getFileContent(INPUT_JSON_WITH_PERFORMER_INVALID_REFERENCE_RESOURCE_TYPE); - Observation parsedObservation = new FhirParseService().parseResource(jsonInput, Observation.class); + Observation parsedObservation = new FhirParseService(fhirCtx).parseResource(jsonInput, Observation.class); assertThatThrownBy(() -> observationToNarrativeStatementMapper.mapObservationToNarrativeStatement(parsedObservation, true)) .isExactlyInstanceOf(EhrMapperException.class) @@ -142,7 +144,7 @@ public void When_MappingObservationWithInvalidParticipantResourceType_Expect_Map public void When_MappingObservationWithAttachmentAndSampleData_Expect_MapperException(String inputJson, Class expectedClass) throws IOException { var jsonInput = ResourceTestFileUtils.getFileContent(inputJson); - Observation parsedObservation = new FhirParseService().parseResource(jsonInput, Observation.class); + Observation parsedObservation = new FhirParseService(fhirCtx).parseResource(jsonInput, Observation.class); var exception = assertThrows(EhrMapperException.class, () -> observationToNarrativeStatementMapper.mapObservationToNarrativeStatement(parsedObservation, true)); diff --git a/service/src/test/java/uk/nhs/adaptors/gp2gp/ehr/mapper/OrganizationToAgentMapperTest.java b/service/src/test/java/uk/nhs/adaptors/gp2gp/ehr/mapper/OrganizationToAgentMapperTest.java index 2e88018af2..046fa41990 100644 --- a/service/src/test/java/uk/nhs/adaptors/gp2gp/ehr/mapper/OrganizationToAgentMapperTest.java +++ b/service/src/test/java/uk/nhs/adaptors/gp2gp/ehr/mapper/OrganizationToAgentMapperTest.java @@ -4,6 +4,7 @@ import java.io.IOException; +import ca.uhn.fhir.context.FhirContext; import org.hl7.fhir.dstu3.model.Organization; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; @@ -32,7 +33,7 @@ public void When_MappingOrganization_Expect_AgentResourceXml() throws IOExceptio var jsonInput = ResourceTestFileUtils.getFileContent(INPUT_ORGANIZATION_JSON); var expectedOutput = ResourceTestFileUtils.getFileContent(OUTPUT_ORGANIZATION_AS_AGENT_PERSON_JSON); - Organization organization = new FhirParseService().parseResource(jsonInput, Organization.class); + Organization organization = new FhirParseService(FhirContext.forDstu3()).parseResource(jsonInput, Organization.class); var outputMessage = OrganizationToAgentMapper.mapOrganizationToAgent(organization, TEST_ID); assertThat(outputMessage) .describedAs(TestArgumentsLoaderUtil.FAIL_MESSAGE, INPUT_ORGANIZATION_JSON, OUTPUT_ORGANIZATION_AS_AGENT_PERSON_JSON) diff --git a/service/src/test/java/uk/nhs/adaptors/gp2gp/ehr/mapper/PertinentInformationObservationValueMapperTest.java b/service/src/test/java/uk/nhs/adaptors/gp2gp/ehr/mapper/PertinentInformationObservationValueMapperTest.java index af337f05d5..b9dbd5f4b6 100644 --- a/service/src/test/java/uk/nhs/adaptors/gp2gp/ehr/mapper/PertinentInformationObservationValueMapperTest.java +++ b/service/src/test/java/uk/nhs/adaptors/gp2gp/ehr/mapper/PertinentInformationObservationValueMapperTest.java @@ -6,6 +6,7 @@ import java.io.IOException; import java.util.stream.Stream; +import ca.uhn.fhir.context.FhirContext; import org.hl7.fhir.dstu3.model.Observation; import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; @@ -54,12 +55,13 @@ public class PertinentInformationObservationValueMapperTest { private static final String EXPECTED_REFERENCE_RANGE_WITH_HIGH = "Range: Text: Test reference range text High: 20 "; private static final PertinentInformationObservationValueMapper PERTINENT_INFORMATION_OBSERVATION_VALUE_MAPPER = new PertinentInformationObservationValueMapper(); + private FhirContext fhirCtx = FhirContext.forDstu3(); @ParameterizedTest @MethodSource("testValueFilePaths") public void When_MappingParsedObservationValueJson_Expect_CorrectXmlOutput(String input, String output) throws IOException { var jsonInput = ResourceTestFileUtils.getFileContent(input); - Observation observation = new FhirParseService().parseResource(jsonInput, Observation.class); + Observation observation = new FhirParseService(fhirCtx).parseResource(jsonInput, Observation.class); boolean isProperValue = PERTINENT_INFORMATION_OBSERVATION_VALUE_MAPPER.isPertinentInformation(observation.getValue()); @@ -75,7 +77,7 @@ public void When_MappingParsedObservationValueJson_Expect_CorrectXmlOutput(Strin public void When_MappingParsedObservationJsonWithReferenceRange_Expect_CorrectXmlOutput(String input, String output) throws IOException { var jsonInput = ResourceTestFileUtils.getFileContent(input); - Observation observation = new FhirParseService().parseResource(jsonInput, Observation.class); + Observation observation = new FhirParseService(fhirCtx).parseResource(jsonInput, Observation.class); String outputMessage = PERTINENT_INFORMATION_OBSERVATION_VALUE_MAPPER.mapReferenceRangeToPertinentInformation(observation.getReferenceRangeFirstRep()); @@ -85,7 +87,7 @@ public void When_MappingParsedObservationJsonWithReferenceRange_Expect_CorrectXm @Test public void When_MappingParsedObservationInvalidValueJson_Expect_IllegalArgumentException() throws IOException { var jsonInput = ResourceTestFileUtils.getFileContent(INPUT_JSON_WITH_INVALID_VALUE); - Observation observation = new FhirParseService().parseResource(jsonInput, Observation.class); + Observation observation = new FhirParseService(fhirCtx).parseResource(jsonInput, Observation.class); boolean isProperValue = PERTINENT_INFORMATION_OBSERVATION_VALUE_MAPPER.isPertinentInformation(observation.getValue()); diff --git a/service/src/test/java/uk/nhs/adaptors/gp2gp/ehr/mapper/RequestStatementMapperTest.java b/service/src/test/java/uk/nhs/adaptors/gp2gp/ehr/mapper/RequestStatementMapperTest.java index 3d3ac2b3eb..7df484f422 100644 --- a/service/src/test/java/uk/nhs/adaptors/gp2gp/ehr/mapper/RequestStatementMapperTest.java +++ b/service/src/test/java/uk/nhs/adaptors/gp2gp/ehr/mapper/RequestStatementMapperTest.java @@ -10,6 +10,7 @@ import java.io.IOException; import java.util.stream.Stream; +import ca.uhn.fhir.context.FhirContext; import org.hl7.fhir.dstu3.model.Bundle; import org.hl7.fhir.dstu3.model.CodeableConcept; import org.hl7.fhir.dstu3.model.IdType; @@ -188,6 +189,7 @@ public class RequestStatementMapperTest { + "expected-output-request-statement-no-supportingInfo.xml"; private static final String OUTPUT_XML_WITH_NO_AUTHOR_AND_TIME = TEST_FILE_DIRECTORY + "expected-output-request-statement-no-author-and-time.xml"; + private FhirContext fhirCtx = FhirContext.forDstu3(); @Mock private CodeableConceptCdMapper codeableConceptCdMapper; @@ -274,7 +276,7 @@ private static Stream resourceFileParamsWithInvalidData() { @BeforeEach public void setUp() throws IOException { var bundleInput = ResourceTestFileUtils.getFileContent(INPUT_JSON_BUNDLE); - Bundle bundle = new FhirParseService().parseResource(bundleInput, Bundle.class); + Bundle bundle = new FhirParseService(fhirCtx).parseResource(bundleInput, Bundle.class); inputBundle = new InputBundle(bundle); lenient().when(messageContext.getIdMapper()).thenReturn(idMapper); @@ -326,7 +328,7 @@ public void When_MappingObservationJson_Expect_NarrativeStatementXmlOutput(Strin private void assertThatInputMapsToExpectedOutput(String inputJsonResourcePath, String outputXmlResourcePath) { var expected = ResourceTestFileUtils.getFileContent(outputXmlResourcePath); var input = ResourceTestFileUtils.getFileContent(inputJsonResourcePath); - var referralRequest = new FhirParseService().parseResource(input, ReferralRequest.class); + var referralRequest = new FhirParseService(fhirCtx).parseResource(input, ReferralRequest.class); String outputMessage = requestStatementMapper.mapReferralRequestToRequestStatement(referralRequest, false); @@ -345,7 +347,7 @@ public void When_MappingObservationJsonWithReason_Expect_NarrativeStatementXmlOu public void When_MappingReferralRequestJsonWithNestedTrue_Expect_RequestStatementXmlOutput() throws IOException { String expectedOutputMessage = ResourceTestFileUtils.getFileContent(OUTPUT_XML_USES_NO_OPTIONAL_FIELDS_NESTED); var jsonInput = ResourceTestFileUtils.getFileContent(INPUT_JSON_WITH_NO_OPTIONAL_FIELDS); - ReferralRequest parsedReferralRequest = new FhirParseService().parseResource(jsonInput, ReferralRequest.class); + ReferralRequest parsedReferralRequest = new FhirParseService(fhirCtx).parseResource(jsonInput, ReferralRequest.class); String outputMessage = requestStatementMapper.mapReferralRequestToRequestStatement(parsedReferralRequest, true); @@ -357,7 +359,7 @@ public void When_MappingReferralRequestJsonWithNestedTrue_Expect_RequestStatemen public void When_MappingReferralRequestJsonWithInvalidData_Expect_Exception(String inputJson, String exceptionMessage) throws IOException { var jsonInput = ResourceTestFileUtils.getFileContent(inputJson); - ReferralRequest parsedReferralRequest = new FhirParseService().parseResource(jsonInput, ReferralRequest.class); + ReferralRequest parsedReferralRequest = new FhirParseService(fhirCtx).parseResource(jsonInput, ReferralRequest.class); assertThatThrownBy(() -> requestStatementMapper.mapReferralRequestToRequestStatement(parsedReferralRequest, false)) .isExactlyInstanceOf(EhrMapperException.class) diff --git a/service/src/test/java/uk/nhs/adaptors/gp2gp/ehr/mapper/StructuredObservationValueMapperTest.java b/service/src/test/java/uk/nhs/adaptors/gp2gp/ehr/mapper/StructuredObservationValueMapperTest.java index 7a94fcdecd..12de69c03e 100644 --- a/service/src/test/java/uk/nhs/adaptors/gp2gp/ehr/mapper/StructuredObservationValueMapperTest.java +++ b/service/src/test/java/uk/nhs/adaptors/gp2gp/ehr/mapper/StructuredObservationValueMapperTest.java @@ -6,6 +6,7 @@ import java.io.IOException; import java.util.stream.Stream; +import ca.uhn.fhir.context.FhirContext; import org.hl7.fhir.dstu3.model.Observation; import org.junit.jupiter.api.Test; @@ -43,6 +44,7 @@ public class StructuredObservationValueMapperTest { + "example-output-observation-with-reference-range-high-only.xml"; private static final String OUTPUT_XML_WITH_REFERENCE_RANGE_LOW_ONLY = TEST_FILES_DIRECTORY + "example-output-observation-with-reference-range-low-only.xml"; + private FhirContext fhirCtx = FhirContext.forDstu3(); private static final StructuredObservationValueMapper XML_OBSERVATION_VALUE_MAPPER = new StructuredObservationValueMapper(); @@ -51,7 +53,7 @@ public void When_MappingParsedObservationStringValueJson_Expect_CorrectXmlOutput String expectedOutputMessage = ResourceTestFileUtils.getFileContent(OUTPUT_XML_WITH_STRING_TYPE); var jsonInput = ResourceTestFileUtils.getFileContent(INPUT_JSON_WITH_STRING_TYPE); - Observation observation = new FhirParseService().parseResource(jsonInput, Observation.class); + Observation observation = new FhirParseService(fhirCtx).parseResource(jsonInput, Observation.class); boolean isProperValue = XML_OBSERVATION_VALUE_MAPPER.isStructuredValueType(observation.getValue()); assertThat(isProperValue).isTrue(); @@ -69,7 +71,7 @@ public void When_MappingParsedObservationReferenceRangeJson_Expect_CorrectXmlOut String expectedOutputMessage = ResourceTestFileUtils.getFileContent(expectedOutputXmlPath); var jsonInput = ResourceTestFileUtils.getFileContent(inputJsonPath); - Observation observation = new FhirParseService().parseResource(jsonInput, Observation.class); + Observation observation = new FhirParseService(fhirCtx).parseResource(jsonInput, Observation.class); String outputMessage = XML_OBSERVATION_VALUE_MAPPER.mapReferenceRangeType(observation.getReferenceRangeFirstRep()); assertThat(outputMessage).isEqualTo(expectedOutputMessage); @@ -80,7 +82,7 @@ public void When_MappingParsedObservationInterpretationJson_Expect_CorrectXmlOut String expectedOutputMessage = ResourceTestFileUtils.getFileContent(OUTPUT_XML_WITH_INTERPRETATION); var jsonInput = ResourceTestFileUtils.getFileContent(INPUT_JSON_WITH_INTERPRETATION); - Observation observation = new FhirParseService().parseResource(jsonInput, Observation.class); + Observation observation = new FhirParseService(fhirCtx).parseResource(jsonInput, Observation.class); String outputMessage = XML_OBSERVATION_VALUE_MAPPER.mapInterpretation(observation.getInterpretation() .getCodingFirstRep()); @@ -90,7 +92,7 @@ public void When_MappingParsedObservationInterpretationJson_Expect_CorrectXmlOut @Test public void When_MappingParsedObservationInvalidValueJson_Expect_IllegalArgumentException() throws IOException { var jsonInput = ResourceTestFileUtils.getFileContent(INPUT_JSON_WITH_INVALID_VALUE); - Observation observation = new FhirParseService().parseResource(jsonInput, Observation.class); + Observation observation = new FhirParseService(fhirCtx).parseResource(jsonInput, Observation.class); boolean isProperValue = XML_OBSERVATION_VALUE_MAPPER.isStructuredValueType(observation.getValue()); diff --git a/service/src/test/java/uk/nhs/adaptors/gp2gp/ehr/mapper/diagnosticreport/ObservationMapperTest.java b/service/src/test/java/uk/nhs/adaptors/gp2gp/ehr/mapper/diagnosticreport/ObservationMapperTest.java index d0e213c806..a513807a04 100644 --- a/service/src/test/java/uk/nhs/adaptors/gp2gp/ehr/mapper/diagnosticreport/ObservationMapperTest.java +++ b/service/src/test/java/uk/nhs/adaptors/gp2gp/ehr/mapper/diagnosticreport/ObservationMapperTest.java @@ -1,5 +1,6 @@ package uk.nhs.adaptors.gp2gp.ehr.mapper.diagnosticreport; +import ca.uhn.fhir.context.FhirContext; import org.hl7.fhir.dstu3.model.Bundle; import org.hl7.fhir.dstu3.model.DiagnosticReport; import org.hl7.fhir.dstu3.model.IdType; @@ -147,7 +148,7 @@ class ObservationMapperTest { @BeforeEach void setUp() { String bundleJsonInput = ResourceTestFileUtils.getFileContent(DIAGNOSTIC_REPORT_TEST_FILE_DIRECTORY + "fhir_bundle.json"); - Bundle bundle = new FhirParseService().parseResource(bundleJsonInput, Bundle.class); + Bundle bundle = new FhirParseService(FhirContext.forDstu3()).parseResource(bundleJsonInput, Bundle.class); bundle.addEntry(new Bundle.BundleEntryComponent().setResource( new DiagnosticReport().addResult( diff --git a/service/src/test/java/uk/nhs/adaptors/gp2gp/ehr/mapper/diagnosticreport/SpecimenMapperTest.java b/service/src/test/java/uk/nhs/adaptors/gp2gp/ehr/mapper/diagnosticreport/SpecimenMapperTest.java index 452c850362..d03140e1c7 100644 --- a/service/src/test/java/uk/nhs/adaptors/gp2gp/ehr/mapper/diagnosticreport/SpecimenMapperTest.java +++ b/service/src/test/java/uk/nhs/adaptors/gp2gp/ehr/mapper/diagnosticreport/SpecimenMapperTest.java @@ -12,6 +12,7 @@ import java.util.Optional; import java.util.stream.Stream; +import ca.uhn.fhir.context.FhirContext; import org.hl7.fhir.dstu3.model.Bundle; import org.hl7.fhir.dstu3.model.DiagnosticReport; import org.hl7.fhir.dstu3.model.IdType; @@ -77,7 +78,7 @@ class SpecimenMapperTest { @BeforeEach void setUp() { var inputBundleString = ResourceTestFileUtils.getFileContent(FHIR_INPUT_BUNDLE); - var inputBundle = new FhirParseService().parseResource(inputBundleString, Bundle.class); + var inputBundle = new FhirParseService(FhirContext.forDstu3()).parseResource(inputBundleString, Bundle.class); lenient().when(messageContext.getIdMapper()).thenReturn(idMapper); lenient().when(messageContext.getAgentDirectory()).thenReturn(agentDirectory); lenient().when(messageContext.getInputBundleHolder()).thenReturn(new InputBundle(inputBundle)); diff --git a/service/src/test/java/uk/nhs/adaptors/gp2gp/ehr/mapper/wrapper/ConditionWrapperTestBase.java b/service/src/test/java/uk/nhs/adaptors/gp2gp/ehr/mapper/wrapper/ConditionWrapperTestBase.java index 4f73e5bfc7..f52cfe32af 100644 --- a/service/src/test/java/uk/nhs/adaptors/gp2gp/ehr/mapper/wrapper/ConditionWrapperTestBase.java +++ b/service/src/test/java/uk/nhs/adaptors/gp2gp/ehr/mapper/wrapper/ConditionWrapperTestBase.java @@ -4,6 +4,7 @@ import java.io.IOException; +import ca.uhn.fhir.context.FhirContext; import org.hl7.fhir.dstu3.model.Bundle; import org.hl7.fhir.dstu3.model.Condition; import org.hl7.fhir.dstu3.model.Reference; @@ -33,7 +34,7 @@ public abstract class ConditionWrapperTestBase { @BeforeAll public static void setUp() throws IOException { var bundleInput = ResourceTestFileUtils.getFileContent(INPUT_JSON_BUNDLE); - bundle = new FhirParseService().parseResource(bundleInput, Bundle.class); + bundle = new FhirParseService(FhirContext.forDstu3()).parseResource(bundleInput, Bundle.class); inputBundle = new InputBundle(bundle); } diff --git a/service/src/test/java/uk/nhs/adaptors/gp2gp/ehr/utils/EncounterExtractorTest.java b/service/src/test/java/uk/nhs/adaptors/gp2gp/ehr/utils/EncounterExtractorTest.java index cde98bf9ad..280ff47e6d 100644 --- a/service/src/test/java/uk/nhs/adaptors/gp2gp/ehr/utils/EncounterExtractorTest.java +++ b/service/src/test/java/uk/nhs/adaptors/gp2gp/ehr/utils/EncounterExtractorTest.java @@ -1,5 +1,6 @@ package uk.nhs.adaptors.gp2gp.ehr.utils; +import ca.uhn.fhir.context.FhirContext; import com.google.common.collect.ImmutableList; import org.hl7.fhir.dstu3.model.Bundle; import org.hl7.fhir.dstu3.model.Encounter; @@ -28,7 +29,7 @@ public class EncounterExtractorTest { "D81C5E8F-CB3A-4A78-92EA-51EC3665648E", "8FEB11AA-5785-43D3-99A9-E9D49EAF2161", "4088F3A1-CE58-4374-AABA-763C31738281"); - private static final FhirParseService FHIR_PARSE_SERVICE = new FhirParseService(); + private static final FhirParseService FHIR_PARSE_SERVICE = new FhirParseService(FhirContext.forDstu3()); private static Bundle fullBundle; private static Bundle bundleWithEmptyConsultationList; diff --git a/service/src/test/java/uk/nhs/adaptors/gp2gp/ehr/utils/MedicationRequestUtilsTest.java b/service/src/test/java/uk/nhs/adaptors/gp2gp/ehr/utils/MedicationRequestUtilsTest.java index 814a135286..bacf1fdbbc 100644 --- a/service/src/test/java/uk/nhs/adaptors/gp2gp/ehr/utils/MedicationRequestUtilsTest.java +++ b/service/src/test/java/uk/nhs/adaptors/gp2gp/ehr/utils/MedicationRequestUtilsTest.java @@ -4,6 +4,7 @@ import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertTrue; +import ca.uhn.fhir.context.FhirContext; import org.hl7.fhir.dstu3.model.Condition; import org.hl7.fhir.dstu3.model.MedicationRequest; import org.hl7.fhir.dstu3.model.Reference; @@ -15,7 +16,7 @@ public class MedicationRequestUtilsTest { - private final FhirParseService fhirParseService = new FhirParseService(); + private final FhirParseService fhirParseService = new FhirParseService(FhirContext.forDstu3()); private static final String FILES_ROOT = "/ehr/utils/"; private static final String JSON_CONDITION_WITH_MEDICATION_REQUEST_REF = FILES_ROOT diff --git a/service/src/test/java/uk/nhs/adaptors/gp2gp/ehr/utils/ResourceExtractorTest.java b/service/src/test/java/uk/nhs/adaptors/gp2gp/ehr/utils/ResourceExtractorTest.java index 536a684c7c..317e3701b1 100644 --- a/service/src/test/java/uk/nhs/adaptors/gp2gp/ehr/utils/ResourceExtractorTest.java +++ b/service/src/test/java/uk/nhs/adaptors/gp2gp/ehr/utils/ResourceExtractorTest.java @@ -1,5 +1,6 @@ package uk.nhs.adaptors.gp2gp.ehr.utils; +import ca.uhn.fhir.context.FhirContext; import org.hl7.fhir.dstu3.model.AllergyIntolerance; import org.hl7.fhir.dstu3.model.Bundle; import org.hl7.fhir.dstu3.model.ListResource; @@ -26,6 +27,7 @@ class ResourceExtractorTest { private static final String LIST_RESOURCE_TEST_FILE_DIRECTORY = "/ehr/mapper/listresource/"; private static final String LIST_REFERENCE_ID = "List/ended-allergies#eb306f14-31e9-11ee-b912-0a58a9feac02"; + private FhirContext fhirCtx = FhirContext.forDstu3(); @Mock private MessageContext messageContext; @@ -34,7 +36,7 @@ class ResourceExtractorTest { void extractListWithContainedAllergiesResourceByReference() throws IOException { String bundleJsonInput = ResourceTestFileUtils.getFileContent(LIST_RESOURCE_TEST_FILE_DIRECTORY + "fhir_bundle.json"); - Bundle allBundle = new FhirParseService().parseResource(bundleJsonInput, Bundle.class); + Bundle allBundle = new FhirParseService(fhirCtx).parseResource(bundleJsonInput, Bundle.class); IIdType reference = createAllergyIntoleranceReference(LIST_REFERENCE_ID); Optional resources = ResourceExtractor.extractResourceByReference(allBundle, reference); @@ -49,7 +51,7 @@ void extractEmptyResourceWithValidContainedIdButNotValidResourceTypeReference() final String LIST_REFERENCE_ID_WITH_WRONG_RESOURCE_TYPE = "Organization/ended-allergies#eb306f14-31e9-11ee-b912-0a58a9feac02"; String bundleJsonInput = ResourceTestFileUtils.getFileContent(LIST_RESOURCE_TEST_FILE_DIRECTORY + "fhir_bundle.json"); - Bundle allBundle = new FhirParseService().parseResource(bundleJsonInput, Bundle.class); + Bundle allBundle = new FhirParseService(fhirCtx).parseResource(bundleJsonInput, Bundle.class); IIdType reference = createAllergyIntoleranceReference(LIST_REFERENCE_ID_WITH_WRONG_RESOURCE_TYPE); Optional resources = ResourceExtractor.extractResourceByReference(allBundle, reference); @@ -62,7 +64,7 @@ void extractEmptyResourceByNonExistedReference() throws IOException { final String NON_EXISTED_LIST_REFERENCE_ID = "List/ended-allergies#eb306f14-31e9-11ee-b912-0a58a9feac04"; String bundleJsonInput = ResourceTestFileUtils.getFileContent(LIST_RESOURCE_TEST_FILE_DIRECTORY + "fhir_bundle.json"); - Bundle allBundle = new FhirParseService().parseResource(bundleJsonInput, Bundle.class); + Bundle allBundle = new FhirParseService(fhirCtx).parseResource(bundleJsonInput, Bundle.class); IIdType reference = createAllergyIntoleranceReference(NON_EXISTED_LIST_REFERENCE_ID); Optional resources = ResourceExtractor.extractResourceByReference(allBundle, reference); diff --git a/service/src/test/java/uk/nhs/adaptors/gp2gp/gpc/DocumentToMHSTranslatorTest.java b/service/src/test/java/uk/nhs/adaptors/gp2gp/gpc/DocumentToMHSTranslatorTest.java index b1175f9844..78abdcc184 100644 --- a/service/src/test/java/uk/nhs/adaptors/gp2gp/gpc/DocumentToMHSTranslatorTest.java +++ b/service/src/test/java/uk/nhs/adaptors/gp2gp/gpc/DocumentToMHSTranslatorTest.java @@ -1,5 +1,6 @@ package uk.nhs.adaptors.gp2gp.gpc; +import ca.uhn.fhir.context.FhirContext; import org.hl7.fhir.dstu3.model.Binary; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeEach; @@ -85,7 +86,7 @@ public void When_TranslatingDocumentData_Expect_ProperMhsOutboundRequestPayload( .messageId(MESSAGE_ID) .documentId(TEST_DOCUMENT_ID) .build(); - Binary binary = new FhirParseService().parseResource(jsonBinaryContent, Binary.class); + Binary binary = new FhirParseService(FhirContext.forDstu3()).parseResource(jsonBinaryContent, Binary.class); String payload = documentToMHSTranslator.translateGpcResponseToMhsOutboundRequestData( taskDefinition, binary.getContentAsBase64(), binary.getContentType()); diff --git a/service/src/test/java/uk/nhs/adaptors/gp2gp/uat/EhrExtractUATTest.java b/service/src/test/java/uk/nhs/adaptors/gp2gp/uat/EhrExtractUATTest.java index 8213d1c377..b441c7471f 100644 --- a/service/src/test/java/uk/nhs/adaptors/gp2gp/uat/EhrExtractUATTest.java +++ b/service/src/test/java/uk/nhs/adaptors/gp2gp/uat/EhrExtractUATTest.java @@ -1,5 +1,6 @@ package uk.nhs.adaptors.gp2gp.uat; +import ca.uhn.fhir.context.FhirContext; import lombok.SneakyThrows; import org.hl7.fhir.dstu3.model.Bundle; import org.jetbrains.annotations.NotNull; @@ -78,6 +79,7 @@ public class EhrExtractUATTest { private static final String INPUT_PATH = "/uat/input/"; private static final String OUTPUT_PATH = "/uat/output/"; private static final boolean OVERWRITE_XML = false; + private FhirContext fhirCtx = FhirContext.forDstu3(); @Mock private TimestampService timestampService; @@ -227,7 +229,7 @@ public void When_MappingValidJsonRequestBody_Expect_ValidXmlOutputTC4(String inp final String expectedJsonToXmlContent = ResourceTestFileUtils.getFileContent(expectedXmlResourcePath); String inputJsonFileContent = ResourceTestFileUtils.getFileContent(INPUT_PATH + "TC4/" + inputJson); inputJsonFileContent = removeEmptyDescriptions(inputJsonFileContent); - final Bundle bundle = new FhirParseService().parseResource(inputJsonFileContent, Bundle.class); + final Bundle bundle = new FhirParseService(fhirCtx).parseResource(inputJsonFileContent, Bundle.class); messageContext.initialize(bundle); @@ -261,7 +263,7 @@ public void When_MappingValidJsonRequestBody_Expect_ValidXmlOutputTC7(String inp final String expectedJsonToXmlContent = ResourceTestFileUtils.getFileContent(expectedXmlResourcePath); String inputJsonFileContent = ResourceTestFileUtils.getFileContent(INPUT_PATH + "TC7/" + inputJson); inputJsonFileContent = removeEmptyDescriptions(inputJsonFileContent); - final Bundle bundle = new FhirParseService().parseResource(inputJsonFileContent, Bundle.class); + final Bundle bundle = new FhirParseService(fhirCtx).parseResource(inputJsonFileContent, Bundle.class); messageContext.initialize(bundle); diff --git a/service/src/test/java/uk/nhs/adaptors/gp2gp/utils/DateFormatUtilTest.java b/service/src/test/java/uk/nhs/adaptors/gp2gp/utils/DateFormatUtilTest.java index cf4b95f9ed..e68be691af 100644 --- a/service/src/test/java/uk/nhs/adaptors/gp2gp/utils/DateFormatUtilTest.java +++ b/service/src/test/java/uk/nhs/adaptors/gp2gp/utils/DateFormatUtilTest.java @@ -9,6 +9,7 @@ import java.util.stream.Stream; +import ca.uhn.fhir.context.FhirContext; import org.hl7.fhir.dstu3.model.BaseDateTimeType; import org.hl7.fhir.dstu3.model.Immunization; import org.hl7.fhir.dstu3.model.Observation; @@ -25,7 +26,7 @@ @ExtendWith(MockitoExtension.class) public class DateFormatUtilTest { - private static final FhirParseService FHIR_PARSER = new FhirParseService(); + private static final FhirParseService FHIR_PARSER = new FhirParseService(FhirContext.forDstu3()); private static final String INSTANT_OBSERVATION_TEMPLATE = "{\"resourceType\": \"Observation\", \"issued\": \"%s\"}"; private static final String DATETYPE_IMMUNIZATION_TEMPLATE = "{\"resourceType\": \"Immunization\", \"expirationDate\": \"%s\"}"; private static final String DATETIME_OBSERVATION_TEMPLATE = "{\"resourceType\": \"Observation\", \"valueDateTime\": \"%s\"}"; diff --git a/service/src/test/java/uk/nhs/adaptors/gp2gp/utils/FileParsingUtility.java b/service/src/test/java/uk/nhs/adaptors/gp2gp/utils/FileParsingUtility.java index 1ceb6613de..a43a4341d8 100644 --- a/service/src/test/java/uk/nhs/adaptors/gp2gp/utils/FileParsingUtility.java +++ b/service/src/test/java/uk/nhs/adaptors/gp2gp/utils/FileParsingUtility.java @@ -1,5 +1,6 @@ package uk.nhs.adaptors.gp2gp.utils; +import ca.uhn.fhir.context.FhirContext; import org.hl7.fhir.dstu3.model.BaseResource; import uk.nhs.adaptors.gp2gp.common.service.FhirParseService; @@ -8,6 +9,6 @@ private FileParsingUtility() { } public static R parseResourceFromJsonFile(String filePath, Class resourceClass) { final String jsonInput = ResourceTestFileUtils.getFileContent(filePath); - return new FhirParseService().parseResource(jsonInput, resourceClass); + return new FhirParseService(FhirContext.forDstu3()).parseResource(jsonInput, resourceClass); } } \ No newline at end of file