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 cad092342..83074a765 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 @@ -26,7 +26,6 @@ public String encodeToJson(IBaseResource resource) { private IParser prepareParser() { FhirContext ctx = FhirContext.forDstu3(); - ctx.newJsonParser(); ctx.setParserErrorHandler(new StrictErrorHandler()); return ctx.newJsonParser(); } 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 4311b4b8d..785f97bc8 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 @@ -44,6 +44,34 @@ void setUp() { fhirParseService = new FhirParseService(); } + @Test + void shouldThrowValidationExceptionForInvalidJsonDiagnosticsField() { + + String invalidJson = """ + { + "resourceType": "OperationOutcome", + "meta": { + "profile": ["https://fhir.nhs.uk/STU3/StructureDefinition/GPConnect-OperationOutcome-1"] + }, + "issue": [ { + "severity": "error", + "code": "value", + "details": { + "coding": [ { + "system": "http://fhir.nhs.net/ValueSet/gpconnect-error-or-warning-code-1", + "code": "INVALID_IDENTIFIER_VALUE" + } ] + }, + "diagnosticos": "Provide a conversationId that exists and retry the operation" + } ] + } + """; + + assertThrows(FhirValidationException.class, () -> { + fhirParseService.parseResource(invalidJson, OperationOutcome.class); + }); + } + @Test void ableToEncodeOperationOutcomeToJson() throws JsonProcessingException {