Skip to content

Commit

Permalink
NIAD-2832: Fix continue message not being accepted by EMIS (#316)
Browse files Browse the repository at this point in the history
* Add fixed value attributes to Continue Message template.

* Add EHR Extract ID to continue message

* Add Message ID header to mhs outbound requests.

* Update CHANGELOG.md

* Add additional tests
  • Loading branch information
benhession authored Sep 28, 2023
1 parent 4abb1fa commit a848cae
Show file tree
Hide file tree
Showing 22 changed files with 254 additions and 156 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),

## [Unreleased]

### Fixed

* Fix issue where continue message was not accepted by EMIS.

## [0.13] - 2023-09-13

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,29 +34,29 @@ public class MhsRequestBuilder {
private static final String WAIT_FOR_RESPONSE = "wait-for-response";
private static final String FALSE = "false";
private static final String CONTENT_TYPE = "Content-type";
private static final String MESSAGE_ID = "Message-Id";

private final RequestBuilderService requestBuilderService;
private final MhsOutboundConfiguration mhsOutboundConfiguration;

public WebClient.RequestHeadersSpec<?> buildSendEhrExtractRequest(
String conversationId, String toOdsCode, OutboundMessage outboundMessage) {
return buildSendRequest(conversationId, toOdsCode, outboundMessage, MHS_OUTBOUND_EXTRACT_CORE_INTERACTION_ID);
String conversationId, String toOdsCode, OutboundMessage outboundMessage, String messageId) {
return buildSendRequest(conversationId, toOdsCode, outboundMessage, MHS_OUTBOUND_EXTRACT_CORE_INTERACTION_ID, messageId);
}

// TODO: this method is related to the large messaging epic and can be used during implementation of NIAD-2045
public WebClient.RequestHeadersSpec<?> buildSendContinueRequest(
String conversationId, String toOdsCode, OutboundMessage outboundMessage) {
return buildSendRequest(conversationId, toOdsCode, outboundMessage, MHS_OUTBOUND_COMMON_INTERACTION_ID);
String conversationId, String toOdsCode, OutboundMessage outboundMessage, String messageId) {
return buildSendRequest(conversationId, toOdsCode, outboundMessage, MHS_OUTBOUND_COMMON_INTERACTION_ID, messageId);
}

public WebClient.RequestHeadersSpec<?> buildSendACKRequest(
String conversationId, String toOdsCode, OutboundMessage outboundMessage) {
String conversationId, String toOdsCode, OutboundMessage outboundMessage, String messageId) {
return buildSendRequest(conversationId, toOdsCode, outboundMessage,
MHS_OUTBOUND_APPLICATION_ACKNOWLEDGMENT_INTERACTION_ID);
MHS_OUTBOUND_APPLICATION_ACKNOWLEDGMENT_INTERACTION_ID, messageId);
}

private WebClient.RequestHeadersSpec<?> buildSendRequest(
String conversationId, String toOdsCode, OutboundMessage outboundMessage, String interactionId) {
String conversationId, String toOdsCode, OutboundMessage outboundMessage, String interactionId, String messageId) {
SslContext sslContext = requestBuilderService.buildSSLContext();
HttpClient httpClient = HttpClient.create().secure(t -> t.sslContext(sslContext));
WebClient client = buildWebClient(httpClient);
Expand All @@ -72,6 +72,7 @@ private WebClient.RequestHeadersSpec<?> buildSendRequest(
.header(INTERACTION_ID, interactionId)
.header(WAIT_FOR_RESPONSE, FALSE)
.header(CORRELATION_ID, conversationId)
.header(MESSAGE_ID, messageId)
.body(bodyInserter);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ public class ContinueRequestData {
private String fromOdsCode;
private String conversationId;
private String mcciIN010000UK13creationTime;
private String ehrExtractId;
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,13 @@ public class ApplicationAcknowledgementMessageService {
loadTemplate("applicationAcknowledgementTemplate.mustache");

private final DateUtils dateUtils;
private final IdGeneratorService idGeneratorService;

public String buildNackMessage(NACKMessageData messageData) throws IllegalArgumentException {
public String buildNackMessage(NACKMessageData messageData, String messageId) throws IllegalArgumentException {

LOGGER.debug("Building NACK message for message = [{}]", messageData.getMessageRef());

ApplicationAcknowledgmentParams params = ApplicationAcknowledgmentParams.builder()
.messageId(idGeneratorService.generateUuid())
.messageId(messageId)
.creationTime(toHl7Format(dateUtils.getCurrentInstant()))
.toAsid(messageData.getToAsid())
.fromAsid(messageData.getFromAsid())
Expand All @@ -45,12 +44,12 @@ public String buildNackMessage(NACKMessageData messageData) throws IllegalArgume
return fillTemplate(NACK_MESSAGE_TEMPLATE, params);
}

public String buildAckMessage(ACKMessageData messageData) throws IllegalArgumentException {
public String buildAckMessage(ACKMessageData messageData, String messageId) throws IllegalArgumentException {

LOGGER.debug("Building ACK message for message = [{}]", messageData.getMessageRef());

ApplicationAcknowledgmentParams params = ApplicationAcknowledgmentParams.builder()
.messageId(idGeneratorService.generateUuid())
.messageId(messageId)
.creationTime(toHl7Format(dateUtils.getCurrentInstant()))
.toAsid(messageData.getToAsid())
.fromAsid(messageData.getFromAsid())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import uk.nhs.adaptors.common.util.DateUtils;
import uk.nhs.adaptors.pss.translator.model.ContinueRequestData;
import uk.nhs.adaptors.pss.translator.util.DateFormatUtil;
import uk.nhs.adaptors.pss.translator.util.template.parameter.SendContinueRequestParams;
import static uk.nhs.adaptors.pss.translator.util.template.TemplateUtil.fillTemplate;
Expand All @@ -20,29 +21,20 @@
public class ContinueRequestService {
private static final Mustache CONTINUE_REQUEST_FILE = loadTemplate("sendContinueRequest.mustache");
private final DateUtils dateUtils;
private final IdGeneratorService idGeneratorService;

public String buildContinueRequest(
String conversationId,
String nhsNumber,
String fromAsid,
String toAsid,
String fromOdsCode,
String toOdsCode,
String mcciIn010000UK13creationTime
) throws IOException {
public String buildContinueRequest(ContinueRequestData data, String messageId) throws IOException {
LOGGER.debug("Building ContinueRequest");

SendContinueRequestParams params = SendContinueRequestParams.builder()
.messageId(idGeneratorService.generateUuid().toLowerCase())
.messageId(messageId)
.timestamp(DateFormatUtil.toHl7Format(dateUtils.getCurrentInstant()))
.conversationId(conversationId)
.nhsNumber(nhsNumber)
.toAsid(toAsid)
.fromAsid(fromAsid)
.fromOdsCode(fromOdsCode)
.toOdsCode(toOdsCode)
.mcciIN010000UK13creationTime(mcciIn010000UK13creationTime)
.nhsNumber(data.getNhsNumber())
.toAsid(data.getToAsid())
.fromAsid(data.getFromAsid())
.fromOdsCode(data.getFromOdsCode())
.toOdsCode(data.getToOdsCode())
.mcciIN010000UK13creationTime(data.getMcciIN010000UK13creationTime())
.ehrExtractId(data.getEhrExtractId())
.build();

return fillTemplate(CONTINUE_REQUEST_FILE, params);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ public class EhrExtractRequestService {
private final DateUtils dateUtils;
private final IdGeneratorService idGeneratorService;

public String buildEhrExtractRequest(TransferRequestMessage transferRequestMessage) {
public String buildEhrExtractRequest(TransferRequestMessage transferRequestMessage, String messageId) {
LOGGER.debug("Building EHRExtractRequest with nhsNumber=[{}]", transferRequestMessage.getPatientNhsNumber());

SendEhrExtractRequestParams params = SendEhrExtractRequestParams.builder()
.messageId(idGeneratorService.generateUuid())
.messageId(messageId)
.timestamp(toHl7Format(dateUtils.getCurrentInstant()))
.toAsid(transferRequestMessage.getToAsid())
.fromAsid(transferRequestMessage.getFromAsid())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,8 @@ private void processExternalAttachmentsAndSendContinueMessage(InboundMessage inb
conversationId,
patientNhsNumber,
migrationRequest.getWinningPracticeOdsCode(),
migrationStatusLog.getDate().toInstant()
migrationStatusLog.getDate().toInstant(),
messageId
);
}

Expand Down Expand Up @@ -305,10 +306,18 @@ public void sendContinueRequest(
String conversationId,
String patientNhsNumber,
String winningPracticeOdsCode,
Instant mcciIN010000UK13creationTime
Instant mcciIN010000UK13creationTime,
String ehrExtractId
) {
sendContinueRequestHandler.prepareAndSendRequest(
prepareContinueRequestData(payload, conversationId, patientNhsNumber, winningPracticeOdsCode, mcciIN010000UK13creationTime)
prepareContinueRequestData(
payload,
conversationId,
patientNhsNumber,
winningPracticeOdsCode,
mcciIN010000UK13creationTime,
ehrExtractId
)
);
}

Expand All @@ -317,7 +326,8 @@ private ContinueRequestData prepareContinueRequestData(
String conversationId,
String patientNhsNumber,
String winningPracticeOdsCode,
Instant mcciIN010000UK13creationTime
Instant mcciIN010000UK13creationTime,
String ehrExtractId
) {
var fromAsid = XmlParseUtilService.parseFromAsid(payload);
var toAsid = XmlParseUtilService.parseToAsid(payload);
Expand All @@ -332,6 +342,7 @@ private ContinueRequestData prepareContinueRequestData(
.toOdsCode(toOdsCode)
.fromOdsCode(winningPracticeOdsCode)
.mcciIN010000UK13creationTime(mcciIN010000UK13creationTimeToHl7Format)
.ehrExtractId(ehrExtractId)
.build();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
package uk.nhs.adaptors.pss.translator.task;

import lombok.AllArgsConstructor;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.reactive.function.client.WebClientResponseException;

import lombok.AllArgsConstructor;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import uk.nhs.adaptors.pss.translator.exception.MhsServerErrorException;
import uk.nhs.adaptors.pss.translator.mhs.MhsRequestBuilder;
import uk.nhs.adaptors.pss.translator.mhs.model.OutboundMessage;
import uk.nhs.adaptors.pss.translator.model.ACKMessageData;
import uk.nhs.adaptors.pss.translator.service.ApplicationAcknowledgementMessageService;
import uk.nhs.adaptors.pss.translator.service.IdGeneratorService;
import uk.nhs.adaptors.pss.translator.service.MhsClientService;

@Slf4j
Expand All @@ -22,16 +23,20 @@ public class SendACKMessageHandler {
private final MhsRequestBuilder requestBuilder;
private final MhsClientService mhsClientService;
private final ApplicationAcknowledgementMessageService messageService;
private final IdGeneratorService idGeneratorService;

@SneakyThrows
public boolean prepareAndSendMessage(ACKMessageData messageData) {
String ackMessage = messageService.buildAckMessage(messageData);
String messageId = idGeneratorService.generateUuid().toUpperCase();

String ackMessage = messageService.buildAckMessage(messageData, messageId);
OutboundMessage outboundMessage = new OutboundMessage(ackMessage);

var request = requestBuilder.buildSendACKRequest(
messageData.getConversationId(),
messageData.getToOdsCode(),
outboundMessage);
outboundMessage,
messageId);

try {
mhsClientService.send(request);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import uk.nhs.adaptors.pss.translator.mhs.model.OutboundMessage;
import uk.nhs.adaptors.pss.translator.model.ContinueRequestData;
import uk.nhs.adaptors.pss.translator.service.ContinueRequestService;
import uk.nhs.adaptors.pss.translator.service.IdGeneratorService;
import uk.nhs.adaptors.pss.translator.service.MhsClientService;

@Slf4j
Expand All @@ -24,20 +25,17 @@ public class SendContinueRequestHandler {
private final MhsClientService mhsClientService;
private final MigrationStatusLogService migrationStatusLogService;
private final ContinueRequestService continueRequestService;
private final IdGeneratorService idGeneratorService;

@SneakyThrows
public void prepareAndSendRequest(ContinueRequestData data) {
String continueRequest = continueRequestService.buildContinueRequest(
data.getConversationId(),
data.getNhsNumber(),
data.getFromAsid(),
data.getToAsid(),
data.getFromOdsCode(),
data.getToOdsCode(),
data.getMcciIN010000UK13creationTime()
);

String messageId = idGeneratorService.generateUuid().toUpperCase();

String continueRequest = continueRequestService.buildContinueRequest(data, messageId);
var outboundMessage = new OutboundMessage(continueRequest);
var request = requestBuilder.buildSendContinueRequest(data.getConversationId(), data.getToOdsCode(), outboundMessage);
var request = requestBuilder.buildSendContinueRequest(
data.getConversationId(), data.getToOdsCode(), outboundMessage, messageId);

try {
mhsClientService.send(request);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@
import lombok.AllArgsConstructor;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import uk.nhs.adaptors.common.model.TransferRequestMessage;
import uk.nhs.adaptors.common.enums.MigrationStatus;
import uk.nhs.adaptors.common.model.TransferRequestMessage;
import uk.nhs.adaptors.connector.service.MigrationStatusLogService;
import uk.nhs.adaptors.pss.translator.mhs.MhsRequestBuilder;
import uk.nhs.adaptors.pss.translator.mhs.model.OutboundMessage;
import uk.nhs.adaptors.pss.translator.service.EhrExtractRequestService;
import uk.nhs.adaptors.pss.translator.service.IdGeneratorService;
import uk.nhs.adaptors.pss.translator.service.MhsClientService;

@Slf4j
Expand All @@ -24,16 +25,18 @@ public class SendEhrExtractRequestHandler {
private final MhsRequestBuilder requestBuilder;
private final MhsClientService mhsClientService;
private final MigrationStatusLogService migrationStatusLogService;
private final IdGeneratorService idGeneratorService;

@SneakyThrows
public boolean prepareAndSendRequest(TransferRequestMessage message) {
String conversationId = message.getConversationId();
String toOdsCode = message.getToOds();
String messageId = idGeneratorService.generateUuid().toUpperCase();

String ehrExtractRequest = ehrExtractRequestService.buildEhrExtractRequest(message);
String ehrExtractRequest = ehrExtractRequestService.buildEhrExtractRequest(message, messageId);

var outboundMessage = new OutboundMessage(ehrExtractRequest);
var request = requestBuilder.buildSendEhrExtractRequest(conversationId, toOdsCode, outboundMessage);
var request = requestBuilder.buildSendEhrExtractRequest(conversationId, toOdsCode, outboundMessage, messageId);

try {
var response = mhsClientService.send(request);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import uk.nhs.adaptors.pss.translator.mhs.model.OutboundMessage;
import uk.nhs.adaptors.pss.translator.model.NACKMessageData;
import uk.nhs.adaptors.pss.translator.service.ApplicationAcknowledgementMessageService;
import uk.nhs.adaptors.pss.translator.service.IdGeneratorService;
import uk.nhs.adaptors.pss.translator.service.MhsClientService;

@Slf4j
Expand All @@ -22,16 +23,20 @@ public class SendNACKMessageHandler {
private final MhsRequestBuilder requestBuilder;
private final MhsClientService mhsClientService;
private final ApplicationAcknowledgementMessageService messageService;
private final IdGeneratorService idGeneratorService;

@SneakyThrows
public boolean prepareAndSendMessage(NACKMessageData messageData) {
String ackMessage = messageService.buildNackMessage(messageData);
String messageId = idGeneratorService.generateUuid().toUpperCase();

String ackMessage = messageService.buildNackMessage(messageData, messageId);
OutboundMessage outboundMessage = new OutboundMessage(ackMessage);

var request = requestBuilder.buildSendACKRequest(
messageData.getConversationId(),
messageData.getToOdsCode(),
outboundMessage);
outboundMessage,
messageId);

try {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
public class SendContinueRequestParams {
private String messageId;
private String timestamp;
private String conversationId;
private String nhsNumber;
private String toAsid;
private String fromAsid;
private String toOdsCode;
private String fromOdsCode;
private String mcciIN010000UK13creationTime;
private String ehrExtractId;
}
Loading

0 comments on commit a848cae

Please sign in to comment.