Search in sources :

Example 11 with InboundMessage

use of uk.nhs.adaptors.pss.translator.mhs.model.InboundMessage in project nia-patient-switching-standard-adaptor by NHSDigital.

the class COPCMessageHandlerTest method When_MIDFragmentRecordHasAnAttachmentLog_Expect_AttachmentLogToBeUpdated.

@Test
public void When_MIDFragmentRecordHasAnAttachmentLog_Expect_AttachmentLogToBeUpdated() throws JAXBException, InlineAttachmentProcessingException, SAXException, AttachmentLogException, AttachmentNotFoundException, BundleMappingException, JsonProcessingException {
    var parentMid = "CBBAE92D-C7E8-4A9C-8887-F5AEBA1F8CE1";
    var childMid = "28B31-4245-4AFC-8DA2-8A40623A5101";
    InboundMessage message = new InboundMessage();
    prepareFragmentIndexMocks(message);
    when(patientAttachmentLogService.findAttachmentLog(MESSAGE_ID, CONVERSATION_ID)).thenReturn(buildPatientAttachmentLog(parentMid, null, true));
    when(patientAttachmentLogService.findAttachmentLog(childMid, CONVERSATION_ID)).thenReturn(buildPartialPatientAttachmentLog(childMid, "text/plain"));
    when(patientAttachmentLogService.findAttachmentLog("CBBAE92D-C7E8-4A9C-8887-F5AEBA1F8CE1", CONVERSATION_ID)).thenReturn(buildPatientAttachmentLog("047C22B4-613F-47D3-9A72-44A1758464FB", "CBBAE92D-C7E8-4A9C-8887-F5AEBA1F8CE1", true));
    EbxmlReference reference = new EbxmlReference("First instance is always a payload", "mid:xxxx-xxxx-xxxx-xxxx", "docId");
    EbxmlReference reference2 = new EbxmlReference("desc", "mid:28B31-4245-4AFC-8DA2-8A40623A5101", "docId");
    List<EbxmlReference> attachmentReferenceDescription = new ArrayList<>();
    attachmentReferenceDescription.add(reference);
    attachmentReferenceDescription.add(reference2);
    when(xmlParseUtilService.getEbxmlAttachmentsData(any())).thenReturn(attachmentReferenceDescription);
    // ACT
    copcMessageHandler.handleMessage(message, CONVERSATION_ID);
    // ASSERT
    verify(patientAttachmentLogService).updateAttachmentLog(patientLogCaptor.capture(), conversationIdCaptor.capture());
    PatientAttachmentLog actual = patientLogCaptor.getValue();
    assertThat(actual.getBase64()).isTrue();
    assertThat(actual.getLargeAttachment()).isTrue();
    assertThat(actual.getCompressed()).isFalse();
    assertEquals(0, actual.getOrderNum());
    assertEquals("047C22B4-613F-47D3-9A72-44A1758464FB", actual.getParentMid());
    assertEquals(CONVERSATION_ID, conversationIdCaptor.getValue());
}
Also used : PatientAttachmentLog(uk.nhs.adaptors.connector.model.PatientAttachmentLog) ArrayList(java.util.ArrayList) InboundMessage(uk.nhs.adaptors.pss.translator.mhs.model.InboundMessage) EbxmlReference(uk.nhs.adaptors.pss.translator.model.EbxmlReference) Test(org.junit.jupiter.api.Test)

Example 12 with InboundMessage

use of uk.nhs.adaptors.pss.translator.mhs.model.InboundMessage in project nia-patient-switching-standard-adaptor by NHSDigital.

the class COPCMessageHandlerTest method When_CIDFragmentPartIsReceivedInOrder_Expect_ShouldUploadFile.

@Test
public void When_CIDFragmentPartIsReceivedInOrder_Expect_ShouldUploadFile() throws JAXBException, InlineAttachmentProcessingException, SkeletonEhrProcessingException, SAXException, AttachmentLogException, AttachmentNotFoundException, BundleMappingException, JsonProcessingException {
    InboundMessage message = new InboundMessage();
    prepareExpectedFragmentMocks(message);
    when(patientAttachmentLogService.findAttachmentLog(MESSAGE_ID, CONVERSATION_ID)).thenReturn(buildPatientAttachmentLog("047C22B4-613F-47D3-9A72-44A1758464FB", "CBBAE92D-C7E8-4A9C-8887-F5AEBA1F8CE1", true));
    copcMessageHandler.handleMessage(message, CONVERSATION_ID);
    verify(attachmentHandlerService).storeAttachementWithoutProcessing(filenameCaptor.capture(), payloadCaptor.capture(), conversationIdCaptor.capture(), contentTypeCaptor.capture());
    assertEquals("E39E79A2-FA96-48FF-9373-7BBCB9D036E7.txt", filenameCaptor.getValue());
    assertEquals("This is a payload", payloadCaptor.getValue());
    assertEquals(CONVERSATION_ID, conversationIdCaptor.getValue());
    assertEquals("xml/text", contentTypeCaptor.getValue());
}
Also used : InboundMessage(uk.nhs.adaptors.pss.translator.mhs.model.InboundMessage) Test(org.junit.jupiter.api.Test)

Example 13 with InboundMessage

use of uk.nhs.adaptors.pss.translator.mhs.model.InboundMessage in project nia-patient-switching-standard-adaptor by NHSDigital.

the class COPCMessageHandlerTest method When_CIDMessageFileIsProcessed_Expect_AttachmentLogUploadedColumnIsSetToTrue.

@Test
public void When_CIDMessageFileIsProcessed_Expect_AttachmentLogUploadedColumnIsSetToTrue() throws JAXBException, InlineAttachmentProcessingException, SAXException, AttachmentLogException, AttachmentNotFoundException, BundleMappingException, JsonProcessingException {
    InboundMessage message = new InboundMessage();
    prepareExpectedFragmentMocks(message);
    when(patientAttachmentLogService.findAttachmentLog(MESSAGE_ID, CONVERSATION_ID)).thenReturn(buildPatientAttachmentLog("047C22B4-613F-47D3-9A72-44A1758464FB", "CBBAE92D-C7E8-4A9C-8887-F5AEBA1F8CE1", true));
    copcMessageHandler.handleMessage(message, CONVERSATION_ID);
    verify(patientAttachmentLogService).updateAttachmentLog(patientLogCaptor.capture(), conversationIdCaptor.capture());
    PatientAttachmentLog actual = patientLogCaptor.getAllValues().get(0);
    assertThat(actual.getUploaded()).isTrue();
    assertEquals(CONVERSATION_ID, conversationIdCaptor.getValue());
}
Also used : PatientAttachmentLog(uk.nhs.adaptors.connector.model.PatientAttachmentLog) InboundMessage(uk.nhs.adaptors.pss.translator.mhs.model.InboundMessage) Test(org.junit.jupiter.api.Test)

Example 14 with InboundMessage

use of uk.nhs.adaptors.pss.translator.mhs.model.InboundMessage in project nia-patient-switching-standard-adaptor by NHSDigital.

the class COPCMessageHandlerTest method When_CIDFragmentPartIsReceivedBeforeFragmentIndex_Expect_PartialLogToBeCreated.

@Test
public void When_CIDFragmentPartIsReceivedBeforeFragmentIndex_Expect_PartialLogToBeCreated() throws JAXBException, InlineAttachmentProcessingException, SAXException, AttachmentLogException, AttachmentNotFoundException, BundleMappingException, JsonProcessingException {
    // fragmentAttachmentLog = buildPatientAttachmentLog("28B31-4245-4AFC-8DA2-8A40623A5101", "", 0, true);
    // ARRANGE
    var messageId = "CBBAE92D-C7E8-4A9C-8887-F5AEBA1F8CE1";
    when(patientAttachmentLogService.findAttachmentLog(messageId, CONVERSATION_ID)).thenReturn(null).thenReturn(buildPatientAttachmentLog("047C22B4-613F-47D3-9A72-44A1758464FB", null, true));
    when(patientAttachmentLogService.findAttachmentLog("047C22B4-613F-47D3-9A72-44A1758464FB", CONVERSATION_ID)).thenReturn(buildPatientAttachmentLog("047C22B4-613F-47D3-9A72-44A1758464FB", "CBBAE92D-C7E8-4A9C-8887-F5AEBA1F8CE1", true));
    InboundMessage message = new InboundMessage();
    prepareFragmentMocks(message);
    // ACT
    copcMessageHandler.handleMessage(message, CONVERSATION_ID);
    // ASSERT
    verify(patientAttachmentLogService).addAttachmentLog(patientLogCaptor.capture());
    PatientAttachmentLog actual = patientLogCaptor.getAllValues().get(0);
    assertThat(actual.getUploaded()).isTrue();
    assertEquals("047C22B4-613F-47D3-9A72-44A1758464FB", actual.getMid());
    assertEquals("E39E79A2-FA96-48FF-9373-7BBCB9D036E7_1.messageattachment", actual.getFilename());
    assertEquals("xml/text", actual.getContentType());
    assertEquals(1, actual.getPatientMigrationReqId());
}
Also used : PatientAttachmentLog(uk.nhs.adaptors.connector.model.PatientAttachmentLog) InboundMessage(uk.nhs.adaptors.pss.translator.mhs.model.InboundMessage) Test(org.junit.jupiter.api.Test)

Example 15 with InboundMessage

use of uk.nhs.adaptors.pss.translator.mhs.model.InboundMessage in project nia-patient-switching-standard-adaptor by NHSDigital.

the class EhrExtractMessageHandlerTest method When_HandleMessageWithValidDataIsCalled_Expect_CallsAttachmentHandlerServiceStoreAttachments.

@Test
public void When_HandleMessageWithValidDataIsCalled_Expect_CallsAttachmentHandlerServiceStoreAttachments() throws JsonProcessingException, JAXBException, InlineAttachmentProcessingException, BundleMappingException, AttachmentNotFoundException, ParseException, SAXException {
    InboundMessage inboundMessage = new InboundMessage();
    prepareMocks(inboundMessage);
    ehrExtractMessageHandler.handleMessage(inboundMessage, CONVERSATION_ID);
    verify(attachmentHandlerService).storeAttachments(inboundMessage.getAttachments(), CONVERSATION_ID);
}
Also used : InboundMessage(uk.nhs.adaptors.pss.translator.mhs.model.InboundMessage) Test(org.junit.jupiter.api.Test)

Aggregations

InboundMessage (uk.nhs.adaptors.pss.translator.mhs.model.InboundMessage)36 Test (org.junit.jupiter.api.Test)27 ArrayList (java.util.ArrayList)9 PatientAttachmentLog (uk.nhs.adaptors.connector.model.PatientAttachmentLog)8 Bundle (org.hl7.fhir.dstu3.model.Bundle)6 RCMRIN030000UK06Message (org.hl7.v3.RCMRIN030000UK06Message)6 SAXException (org.xml.sax.SAXException)6 PatientMigrationRequest (uk.nhs.adaptors.connector.model.PatientMigrationRequest)6 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)5 JAXBException (javax.xml.bind.JAXBException)5 BundleMappingException (uk.nhs.adaptors.pss.translator.exception.BundleMappingException)5 InlineAttachmentProcessingException (uk.nhs.adaptors.pss.translator.exception.InlineAttachmentProcessingException)5 EbxmlReference (uk.nhs.adaptors.pss.translator.model.EbxmlReference)5 ParseException (java.text.ParseException)4 Document (org.w3c.dom.Document)4 FileUtil.readResourceAsString (uk.nhs.adaptors.common.util.FileUtil.readResourceAsString)4 AttachmentNotFoundException (uk.nhs.adaptors.pss.translator.exception.AttachmentNotFoundException)4 XmlUnmarshallUtil.unmarshallString (uk.nhs.adaptors.pss.translator.util.XmlUnmarshallUtil.unmarshallString)4 DataFormatException (ca.uhn.fhir.parser.DataFormatException)3 AttachmentLogException (uk.nhs.adaptors.pss.translator.exception.AttachmentLogException)3