From 6538ebcfb4ce714069fe31dc6abc03abff34ecef Mon Sep 17 00:00:00 2001 From: Andy Flint Date: Tue, 2 Jul 2024 16:38:23 +0100 Subject: [PATCH 1/3] [PRMP-534] Negative ACK POC --- .../send-ehr-acknowledgement-controller.js | 14 ++++-- src/templates/generate-ehr-acknowledgement.js | 47 +++++++++++++++++-- 2 files changed, 54 insertions(+), 7 deletions(-) diff --git a/src/api/health-record-requests/send-ehr-acknowledgement-controller.js b/src/api/health-record-requests/send-ehr-acknowledgement-controller.js index cba84b8..44dc68a 100644 --- a/src/api/health-record-requests/send-ehr-acknowledgement-controller.js +++ b/src/api/health-record-requests/send-ehr-acknowledgement-controller.js @@ -22,15 +22,23 @@ export const sendEhrAcknowledgement = async (req, res) => { try { const interactionId = 'MCCI_IN010000UK13'; const serviceId = `urn:nhs:names:services:gp2gp:${interactionId}`; - const { messageId: ehrCoreMessageId, conversationId, odsCode, repositoryAsid } = req.body; + const { + messageId: ehrCoreMessageId, + conversationId, + odsCode, + repositoryAsid, + errorCode + } = req.body; const practiceAsid = await getPracticeAsid(odsCode, serviceId); + setCurrentSpanAttributes({ conversationId, messageId: ehrCoreMessageId }); - const message = await buildEhrAcknowledgementPayload({ + const message = buildEhrAcknowledgementPayload({ acknowledgementMessageId: conversationId, receivingAsid: practiceAsid, sendingAsid: repositoryAsid, - acknowledgedMessageId: ehrCoreMessageId + acknowledgedMessageId: ehrCoreMessageId, + errorCode }); await sendMessage({ interactionId, conversationId, odsCode, message }); logInfo('Acknowledgement sent to MHS'); diff --git a/src/templates/generate-ehr-acknowledgement.js b/src/templates/generate-ehr-acknowledgement.js index dad67ff..24a8fdb 100644 --- a/src/templates/generate-ehr-acknowledgement.js +++ b/src/templates/generate-ehr-acknowledgement.js @@ -1,27 +1,65 @@ import dateFormat from 'dateformat'; +import {logInfo} from "../middleware/logging"; export const buildEhrAcknowledgementPayload = ({ acknowledgementMessageId, receivingAsid, sendingAsid, - acknowledgedMessageId + acknowledgedMessageId, + errorCode }) => { const timestamp = dateFormat(Date.now(), 'yyyymmddHHMMss'); + let acknowledgementTypeCode; + let controlActEventReason; + + switch (errorCode) { + case null: + logInfo('Building positive acknowledgement message with typeCode: AA'); + acknowledgementTypeCode = 'AA'; // positive ACK + break; + case '30': + case '99': + logInfo(`Building negative acknowledgement message with typeCode: AE and errorCode: ${errorCode}`); + acknowledgementTypeCode = 'AE'; // negative ACK, unknown failure reason + controlActEventReason = controlActEventReasonTemplate(errorCode); + break; + default: // negative ACK, known failure reason + logInfo(`Building negative acknowledgement message with typeCode: AR and errorCode: ${errorCode}`); + acknowledgementTypeCode = 'AR'; + controlActEventReason = controlActEventReasonTemplate(errorCode); + } + return ackMessageTemplate({ acknowledgementMessageId: acknowledgementMessageId.toUpperCase(), timestamp, + acknowledgementTypeCode: acknowledgementTypeCode, + acknowledgedMessageId: acknowledgedMessageId.toUpperCase(), receivingAsid, sendingAsid, - acknowledgedMessageId: acknowledgedMessageId.toUpperCase() + controlActEventReason }); }; +const controlActEventReasonTemplate = errorCode => + // TODO PRMP-534 identify what the 'codeSystem' codes need to be. is it the sending/receiving ASID? + ` + + + + + + + + `; + const ackMessageTemplate = ({ acknowledgementMessageId, timestamp, + acknowledgementTypeCode, + acknowledgedMessageId, receivingAsid, sendingAsid, - acknowledgedMessageId + controlActEventReason // will be null in the case of positive ack }) => ` @@ -31,7 +69,7 @@ const ackMessageTemplate = ({ - + @@ -47,6 +85,7 @@ const ackMessageTemplate = ({ + ${controlActEventReason} From 81ed396e8bf0ca63adbce4f4807e64493104a678 Mon Sep 17 00:00:00 2001 From: Andy Flint Date: Fri, 5 Jul 2024 17:36:08 +0100 Subject: [PATCH 2/3] [PRMP-534] Added displayName to negative acknowledgements --- .../send-ehr-acknowledgement-controller.js | 6 ++-- src/templates/generate-ehr-acknowledgement.js | 33 ++++++++++++------- 2 files changed, 26 insertions(+), 13 deletions(-) diff --git a/src/api/health-record-requests/send-ehr-acknowledgement-controller.js b/src/api/health-record-requests/send-ehr-acknowledgement-controller.js index 44dc68a..0d7af36 100644 --- a/src/api/health-record-requests/send-ehr-acknowledgement-controller.js +++ b/src/api/health-record-requests/send-ehr-acknowledgement-controller.js @@ -27,7 +27,8 @@ export const sendEhrAcknowledgement = async (req, res) => { conversationId, odsCode, repositoryAsid, - errorCode + errorCode, + errorDisplayName } = req.body; const practiceAsid = await getPracticeAsid(odsCode, serviceId); @@ -38,7 +39,8 @@ export const sendEhrAcknowledgement = async (req, res) => { receivingAsid: practiceAsid, sendingAsid: repositoryAsid, acknowledgedMessageId: ehrCoreMessageId, - errorCode + errorCode, + errorDisplayName }); await sendMessage({ interactionId, conversationId, odsCode, message }); logInfo('Acknowledgement sent to MHS'); diff --git a/src/templates/generate-ehr-acknowledgement.js b/src/templates/generate-ehr-acknowledgement.js index 24a8fdb..711dec3 100644 --- a/src/templates/generate-ehr-acknowledgement.js +++ b/src/templates/generate-ehr-acknowledgement.js @@ -1,15 +1,17 @@ import dateFormat from 'dateformat'; -import {logInfo} from "../middleware/logging"; +import { logInfo } from '../middleware/logging'; export const buildEhrAcknowledgementPayload = ({ acknowledgementMessageId, receivingAsid, sendingAsid, acknowledgedMessageId, - errorCode + errorCode, + errorDisplayName }) => { const timestamp = dateFormat(Date.now(), 'yyyymmddHHMMss'); let acknowledgementTypeCode; + let acknowledgementDetail; let controlActEventReason; switch (errorCode) { @@ -19,20 +21,23 @@ export const buildEhrAcknowledgementPayload = ({ break; case '30': case '99': - logInfo(`Building negative acknowledgement message with typeCode: AE and errorCode: ${errorCode}`); + logInfo(`Building negative acknowledgement message with typeCode: AE, errorCode: ${errorCode} and errorDisplayName: ${errorDisplayName}`); acknowledgementTypeCode = 'AE'; // negative ACK, unknown failure reason - controlActEventReason = controlActEventReasonTemplate(errorCode); + acknowledgementDetail = acknowledgementDetailTemplate(acknowledgementTypeCode, errorCode, errorDisplayName); + controlActEventReason = controlActEventReasonTemplate(errorCode, errorDisplayName); break; default: // negative ACK, known failure reason - logInfo(`Building negative acknowledgement message with typeCode: AR and errorCode: ${errorCode}`); + logInfo(`Building negative acknowledgement message with typeCode: AR and errorCode: ${errorCode} and errorDisplayName: ${errorDisplayName}`); acknowledgementTypeCode = 'AR'; - controlActEventReason = controlActEventReasonTemplate(errorCode); + acknowledgementDetail = acknowledgementDetailTemplate(acknowledgementTypeCode, errorCode, errorDisplayName); + controlActEventReason = controlActEventReasonTemplate(errorCode, errorDisplayName); } return ackMessageTemplate({ acknowledgementMessageId: acknowledgementMessageId.toUpperCase(), timestamp, - acknowledgementTypeCode: acknowledgementTypeCode, + acknowledgementTypeCode, + acknowledgementDetail, acknowledgedMessageId: acknowledgedMessageId.toUpperCase(), receivingAsid, sendingAsid, @@ -40,11 +45,15 @@ export const buildEhrAcknowledgementPayload = ({ }); }; -const controlActEventReasonTemplate = errorCode => - // TODO PRMP-534 identify what the 'codeSystem' codes need to be. is it the sending/receiving ASID? +const acknowledgementDetailTemplate = (acknowledgementTypeCode, errorCode, errorDisplayName) => + ` + + `; + +const controlActEventReasonTemplate = (errorCode, errorDisplayName) => ` - + @@ -56,6 +65,7 @@ const ackMessageTemplate = ({ acknowledgementMessageId, timestamp, acknowledgementTypeCode, + acknowledgementDetail, // will be null in the case of positive ack acknowledgedMessageId, receivingAsid, sendingAsid, @@ -69,7 +79,8 @@ const ackMessageTemplate = ({ - + + ${acknowledgementDetail} From b3f386a311672e9429a4df9321437d35ec12c41f Mon Sep 17 00:00:00 2001 From: Andy Flint Date: Mon, 8 Jul 2024 16:11:24 +0100 Subject: [PATCH 3/3] [PRMP-534] Replaced null areas in NACK template with empty strings --- src/templates/generate-ehr-acknowledgement.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/templates/generate-ehr-acknowledgement.js b/src/templates/generate-ehr-acknowledgement.js index 711dec3..8bb52fe 100644 --- a/src/templates/generate-ehr-acknowledgement.js +++ b/src/templates/generate-ehr-acknowledgement.js @@ -18,6 +18,8 @@ export const buildEhrAcknowledgementPayload = ({ case null: logInfo('Building positive acknowledgement message with typeCode: AA'); acknowledgementTypeCode = 'AA'; // positive ACK + acknowledgementDetail = ''; + controlActEventReason = ''; break; case '30': case '99':