Search in sources :

Example 1 with MigrationStatusLog

use of uk.nhs.adaptors.connector.model.MigrationStatusLog in project nia-patient-switching-standard-adaptor by NHSDigital.

the class EHRTimeoutHandlerIT method checkDatabaseUpdated.

private void checkDatabaseUpdated(MigrationStatus migrationStatus) throws IOException {
    String losingOdsCode = "P83007";
    String winningOdsCode = "A0378";
    String nhsNumber = "9446363101";
    String persistDuration = "PT4H";
    String conversationId = UUID.randomUUID().toString();
    InboundMessage inboundMessage = createInboundMessage();
    when(sdsService.getPersistDurationFor(any(), any(), any())).thenReturn(Duration.parse(persistDuration));
    patientMigrationRequestDao.addNewRequest(nhsNumber, conversationId, losingOdsCode, winningOdsCode);
    migrationStatusLogService.updatePatientMigrationRequestAndAddMigrationStatusLog(conversationId, "{test bundle}", objectMapper.writeValueAsString(inboundMessage), migrationStatus);
    ehrTimeoutHandler.checkForTimeouts();
    MigrationStatusLog statusLog = migrationStatusLogService.getLatestMigrationStatusLog(conversationId);
    assertEquals(ERROR_LRG_MSG_TIMEOUT, statusLog.getMigrationStatus());
}
Also used : InboundMessage(uk.nhs.adaptors.pss.translator.mhs.model.InboundMessage) MigrationStatusLog(uk.nhs.adaptors.connector.model.MigrationStatusLog)

Example 2 with MigrationStatusLog

use of uk.nhs.adaptors.connector.model.MigrationStatusLog in project nia-patient-switching-standard-adaptor by NHSDigital.

the class EhrExtractMessageHandler method handleMessage.

public void handleMessage(InboundMessage inboundMessage, String conversationId) throws JAXBException, JsonProcessingException, InlineAttachmentProcessingException, BundleMappingException, AttachmentNotFoundException, ParseException, SAXException {
    RCMRIN030000UK06Message payload = unmarshallString(inboundMessage.getPayload(), RCMRIN030000UK06Message.class);
    PatientMigrationRequest migrationRequest = migrationRequestDao.getMigrationRequest(conversationId);
    MigrationStatusLog migrationStatusLog = migrationStatusLogService.getLatestMigrationStatusLog(conversationId);
    migrationStatusLogService.addMigrationStatusLog(EHR_EXTRACT_RECEIVED, conversationId);
    try {
        Document ebXmlDocument = getEbXmlDocument(inboundMessage);
        String messageId = xPathService.getNodeValue(ebXmlDocument, MESSAGE_ID_PATH);
        boolean hasExternalAttachment = !(inboundMessage.getExternalAttachments() == null || inboundMessage.getExternalAttachments().isEmpty());
        // Manage attachments against the EHR message
        var attachments = inboundMessage.getAttachments();
        if (attachments != null) {
            attachmentHandlerService.storeAttachments(attachments, conversationId);
            for (var i = 0; i < attachments.size(); i++) {
                var attachment = attachments.get(i);
                PatientAttachmentLog newAttachmentLog = buildPatientAttachmentLogFromAttachment(messageId, migrationRequest, attachment);
                patientAttachmentLogService.addAttachmentLog(newAttachmentLog);
            }
        }
        if (!hasExternalAttachment) {
            var fileUpdatedPayload = attachmentReferenceUpdaterService.updateReferenceToAttachment(inboundMessage.getAttachments(), conversationId, inboundMessage.getPayload());
            inboundMessage.setPayload(fileUpdatedPayload);
            payload = unmarshallString(inboundMessage.getPayload(), RCMRIN030000UK06Message.class);
            var bundle = bundleMapperService.mapToBundle(payload, migrationRequest.getLosingPracticeOdsCode());
            migrationStatusLogService.updatePatientMigrationRequestAndAddMigrationStatusLog(conversationId, fhirParser.encodeToJson(bundle), objectMapper.writeValueAsString(inboundMessage), EHR_EXTRACT_TRANSLATED);
            nackAckPreparationService.sendAckMessage(payload, conversationId);
        }
        // sending continue message
        if (hasExternalAttachment) {
            String patientNhsNumber = XmlParseUtilService.parseNhsNumber(payload);
            for (InboundMessage.ExternalAttachment externalAttachment : inboundMessage.getExternalAttachments()) {
                PatientAttachmentLog patientAttachmentLog;
                // save COPC_UK01 messages
                patientAttachmentLog = buildPatientAttachmentLogFromExternalAttachment(migrationRequest, externalAttachment);
                patientAttachmentLogService.addAttachmentLog(patientAttachmentLog);
            }
            migrationStatusLogService.updatePatientMigrationRequestAndAddMigrationStatusLog(conversationId, null, objectMapper.writeValueAsString(inboundMessage), EHR_EXTRACT_TRANSLATED);
            sendContinueRequest(payload, conversationId, patientNhsNumber, migrationRequest.getWinningPracticeOdsCode(), migrationStatusLog.getDate().toInstant());
        }
    } catch (BundleMappingException | DataFormatException | JsonProcessingException | InlineAttachmentProcessingException | AttachmentNotFoundException | SAXException | StorageException ex) {
        nackAckPreparationService.sendNackMessage(EHR_EXTRACT_CANNOT_BE_PROCESSED, payload, conversationId);
        throw ex;
    } catch (ParseException ex) {
        throw ex;
    }
}
Also used : AttachmentNotFoundException(uk.nhs.adaptors.pss.translator.exception.AttachmentNotFoundException) InboundMessage(uk.nhs.adaptors.pss.translator.mhs.model.InboundMessage) XmlUnmarshallUtil.unmarshallString(uk.nhs.adaptors.pss.translator.util.XmlUnmarshallUtil.unmarshallString) Document(org.w3c.dom.Document) SAXException(org.xml.sax.SAXException) PatientMigrationRequest(uk.nhs.adaptors.connector.model.PatientMigrationRequest) DataFormatException(ca.uhn.fhir.parser.DataFormatException) PatientAttachmentLog(uk.nhs.adaptors.connector.model.PatientAttachmentLog) MigrationStatusLog(uk.nhs.adaptors.connector.model.MigrationStatusLog) BundleMappingException(uk.nhs.adaptors.pss.translator.exception.BundleMappingException) ParseException(java.text.ParseException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) StorageException(uk.nhs.adaptors.pss.translator.storage.StorageException) RCMRIN030000UK06Message(org.hl7.v3.RCMRIN030000UK06Message) InlineAttachmentProcessingException(uk.nhs.adaptors.pss.translator.exception.InlineAttachmentProcessingException)

Example 3 with MigrationStatusLog

use of uk.nhs.adaptors.connector.model.MigrationStatusLog in project nia-patient-switching-standard-adaptor by NHSDigital.

the class PatientTransferController method migratePatientStructuredRecord.

@PostMapping(path = "/Patient/$gpc.migratestructuredrecord", consumes = { APPLICATION_FHIR_JSON_VALUE }, produces = { APPLICATION_FHIR_JSON_VALUE })
public ResponseEntity<String> migratePatientStructuredRecord(@RequestBody @PatientTransferRequest Parameters body, @RequestHeader(TO_ASID) @NotNull String toAsid, @RequestHeader(FROM_ASID) @NotNull String fromAsid, @RequestHeader(TO_ODS) @NotNull String toOds, @RequestHeader(FROM_ODS) @NotNull String fromOds) {
    LOGGER.info("Received patient transfer request");
    Map<String, String> headers = Map.of(TO_ASID, toAsid, FROM_ASID, fromAsid, TO_ODS, toOds, FROM_ODS, fromOds);
    MigrationStatusLog request = patientTransferService.handlePatientMigrationRequest(body, headers);
    if (request == null) {
        return new ResponseEntity<>(ACCEPTED);
    } else if (IN_PROGRESS_STATUSES.contains(request.getMigrationStatus())) {
        return new ResponseEntity<>(NO_CONTENT);
    } else if (MIGRATION_COMPLETED == request.getMigrationStatus()) {
        return new ResponseEntity<>(patientTransferService.getBundleResource(), OK);
    } else if (LRG_MESSAGE_ERRORS.contains(request.getMigrationStatus()) || EHR_GENERAL_PROCESSING_ERROR == request.getMigrationStatus()) {
        return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
    } else {
        throw new IllegalStateException("Unsupported transfer status: " + request.getMigrationStatus());
    }
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) MigrationStatusLog(uk.nhs.adaptors.connector.model.MigrationStatusLog) PostMapping(org.springframework.web.bind.annotation.PostMapping)

Example 4 with MigrationStatusLog

use of uk.nhs.adaptors.connector.model.MigrationStatusLog in project nia-patient-switching-standard-adaptor by NHSDigital.

the class PatientTransferServiceTest method handlePatientMigrationRequestWhenRequestIsInProgress.

@Test
public void handlePatientMigrationRequestWhenRequestIsInProgress() {
    PatientMigrationRequest expectedPatientMigrationRequest = createPatientMigrationRequest();
    MigrationStatusLog expectedMigrationStatusLog = createMigrationStatusLog();
    when(mdcService.getConversationId()).thenReturn(CONVERSATION_ID);
    when(patientMigrationRequestDao.getMigrationRequest(CONVERSATION_ID)).thenReturn(expectedPatientMigrationRequest);
    when(migrationStatusLogDao.getLatestMigrationStatusLog(expectedPatientMigrationRequest.getId())).thenReturn(expectedMigrationStatusLog);
    MigrationStatusLog patientMigrationRequest = service.handlePatientMigrationRequest(parameters, HEADERS);
    assertThat(patientMigrationRequest).isEqualTo(expectedMigrationStatusLog);
    verifyNoInteractions(pssQueuePublisher);
    verify(patientMigrationRequestDao).getMigrationRequest(CONVERSATION_ID);
    verifyNoMoreInteractions(patientMigrationRequestDao);
}
Also used : PatientMigrationRequest(uk.nhs.adaptors.connector.model.PatientMigrationRequest) MigrationStatusLog(uk.nhs.adaptors.connector.model.MigrationStatusLog) Test(org.junit.jupiter.api.Test)

Example 5 with MigrationStatusLog

use of uk.nhs.adaptors.connector.model.MigrationStatusLog in project nia-patient-switching-standard-adaptor by NHSDigital.

the class EhrExtractMessageHandlerTest method prepareMigrationRequestAndMigrationStatusMocks.

@SneakyThrows
private void prepareMigrationRequestAndMigrationStatusMocks() {
    PatientMigrationRequest migrationRequest = PatientMigrationRequest.builder().losingPracticeOdsCode(LOSING_ODE_CODE).winningPracticeOdsCode(WINNING_ODE_CODE).build();
    MigrationStatusLog migrationStatusLog = MigrationStatusLog.builder().date(OffsetDateTime.ofInstant(Instant.now(), ZoneId.systemDefault())).build();
    when(migrationRequestDao.getMigrationRequest(CONVERSATION_ID)).thenReturn(migrationRequest);
    when(migrationStatusLogService.getLatestMigrationStatusLog(CONVERSATION_ID)).thenReturn(migrationStatusLog);
}
Also used : PatientMigrationRequest(uk.nhs.adaptors.connector.model.PatientMigrationRequest) MigrationStatusLog(uk.nhs.adaptors.connector.model.MigrationStatusLog) SneakyThrows(lombok.SneakyThrows)

Aggregations

MigrationStatusLog (uk.nhs.adaptors.connector.model.MigrationStatusLog)6 PatientMigrationRequest (uk.nhs.adaptors.connector.model.PatientMigrationRequest)3 Test (org.junit.jupiter.api.Test)2 InboundMessage (uk.nhs.adaptors.pss.translator.mhs.model.InboundMessage)2 DataFormatException (ca.uhn.fhir.parser.DataFormatException)1 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 ParseException (java.text.ParseException)1 OffsetDateTime (java.time.OffsetDateTime)1 SneakyThrows (lombok.SneakyThrows)1 RCMRIN030000UK06Message (org.hl7.v3.RCMRIN030000UK06Message)1 ResponseEntity (org.springframework.http.ResponseEntity)1 PostMapping (org.springframework.web.bind.annotation.PostMapping)1 Document (org.w3c.dom.Document)1 SAXException (org.xml.sax.SAXException)1 PatientAttachmentLog (uk.nhs.adaptors.connector.model.PatientAttachmentLog)1 AttachmentNotFoundException (uk.nhs.adaptors.pss.translator.exception.AttachmentNotFoundException)1 BundleMappingException (uk.nhs.adaptors.pss.translator.exception.BundleMappingException)1 InlineAttachmentProcessingException (uk.nhs.adaptors.pss.translator.exception.InlineAttachmentProcessingException)1 StorageException (uk.nhs.adaptors.pss.translator.storage.StorageException)1 XmlUnmarshallUtil.unmarshallString (uk.nhs.adaptors.pss.translator.util.XmlUnmarshallUtil.unmarshallString)1