11package uk .nhs .adaptors .gp2gp .ehr ;
22
3+ import org .hl7 .fhir .dstu3 .model .CodeableConcept ;
4+ import org .hl7 .fhir .dstu3 .model .Coding ;
5+ import org .hl7 .fhir .dstu3 .model .Meta ;
36import org .hl7 .fhir .dstu3 .model .OperationOutcome ;
7+ import org .hl7 .fhir .dstu3 .model .UriType ;
48import org .junit .jupiter .api .Test ;
59import org .junit .jupiter .api .extension .ExtendWith ;
610import org .mockito .junit .jupiter .MockitoExtension ;
1519
1620import java .time .Duration ;
1721import java .time .Instant ;
22+ import java .util .Collections ;
1823import java .util .List ;
1924import java .util .UUID ;
2025
2126import static org .assertj .core .api .Assertions .assertThat ;
27+ import static org .hl7 .fhir .dstu3 .model .OperationOutcome .IssueType ;
2228import static uk .nhs .adaptors .gp2gp .ehr .EhrStatusConstants .INCUMBENT_NACK_CODE ;
2329import static uk .nhs .adaptors .gp2gp .ehr .EhrStatusConstants .INCUMBENT_NACK_DISPLAY ;
2430
25-
2631@ SpringBootTest
2732@ DirtiesContext
2833@ ExtendWith ({SpringExtension .class , MongoDBExtension .class , ActiveMQExtension .class , MockitoExtension .class })
2934public class EhrResendControllerTest {
3035
3136 public static final Instant NOW = Instant .parse ("2024-01-01T10:00:00Z" );
3237 private static final Instant FIVE_DAYS_AGO = NOW .minus (Duration .ofDays (5 ));
38+ private static final String URI_TYPE = "https://fhir.nhs.uk/STU3/StructureDefinition/GPConnect-OperationOutcome-1" ;
39+ private static final String CONVERSATION_ID = "123-456" ;
3340
3441 @ Autowired
3542 private EhrExtractStatusRepository ehrExtractStatusRepository ;
43+
3644 @ Autowired
3745 private EhrResendController ehrResendController ;
3846
@@ -41,7 +49,8 @@ public void When_AnEhrExtractHasFailed_Expect_RespondsWith202() {
4149
4250 String ehrMessageRef = generateRandomUppercaseUUID ();
4351 var ehrExtractStatus = new EhrExtractStatus ();
44- ehrExtractStatus .setConversationId ("123-456" );
52+
53+ ehrExtractStatus .setConversationId (CONVERSATION_ID );
4554 ehrExtractStatus .setEhrReceivedAcknowledgement (EhrExtractStatus .EhrReceivedAcknowledgement .builder ()
4655 .conversationClosed (FIVE_DAYS_AGO )
4756 .errors (List .of (
@@ -56,24 +65,48 @@ public void When_AnEhrExtractHasFailed_Expect_RespondsWith202() {
5665
5766 ehrExtractStatusRepository .save (ehrExtractStatus );
5867
59- var response = ehrResendController .scheduleEhrExtractResend ("123-456" );
68+ var response = ehrResendController .scheduleEhrExtractResend (CONVERSATION_ID );
6069
6170 assertThat (response .getStatusCode ()).isEqualTo (HttpStatus .ACCEPTED );
6271 assertThat (response .getBody ()).isNull ();
6372 }
6473
6574 @ Test
6675 public void When_AnEhrExtractDoesNotExist_Expect_RespondsWith404 () {
67- var response = ehrResendController .scheduleEhrExtractResend ("123-456" );
76+
77+ var details = new CodeableConcept ();
78+ var codeableConceptCoding = new Coding ();
79+ codeableConceptCoding .setSystem ("http://fhir.nhs.net/ValueSet/gpconnect-error-or-warning-code-1" );
80+ codeableConceptCoding .setCode ("INVALID_IDENTIFIER_VALUE" );
81+ details .setCoding (List .of (codeableConceptCoding ));
82+ var diagnostics = "Provide a conversationId that exists and retry the operation" ;
83+
84+ var operationOutcome = createOperationOutcome (IssueType .VALUE , OperationOutcome .IssueSeverity .ERROR , details , diagnostics );
85+
86+ var response = ehrResendController .scheduleEhrExtractResend (CONVERSATION_ID );
6887
6988 assertThat (response .getStatusCode ()).isEqualTo (HttpStatus .NOT_FOUND );
70- // TODO: Add more detail to OperationOutcome
71- assertThat (response .getBody ()).usingRecursiveComparison ().isEqualTo (new OperationOutcome () );
89+
90+ assertThat (response .getBody ()).usingRecursiveComparison ().isEqualTo (operationOutcome );
7291 }
7392
7493 private String generateRandomUppercaseUUID () {
7594 return UUID .randomUUID ().toString ().toUpperCase ();
7695 }
7796
97+ public static OperationOutcome createOperationOutcome (
98+ OperationOutcome .IssueType type , OperationOutcome .IssueSeverity severity , CodeableConcept details , String diagnostics ) {
99+ var operationOutcome = new OperationOutcome ();
100+ Meta meta = new Meta ();
101+ meta .setProfile (Collections .singletonList (new UriType (URI_TYPE )));
102+ operationOutcome .setMeta (meta );
103+ operationOutcome .addIssue ()
104+ .setCode (type )
105+ .setSeverity (severity )
106+ .setDetails (details )
107+ .setDiagnostics (diagnostics );
108+ return operationOutcome ;
109+ }
110+
78111
79112}
0 commit comments