Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prmp 534 NACK POC #79

Merged
merged 3 commits into from
Jul 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,25 @@ 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,
errorDisplayName
} = 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,
errorDisplayName
});
await sendMessage({ interactionId, conversationId, odsCode, message });
logInfo('Acknowledgement sent to MHS');
Expand Down
60 changes: 56 additions & 4 deletions src/templates/generate-ehr-acknowledgement.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,77 @@
import dateFormat from 'dateformat';
import { logInfo } from '../middleware/logging';

export const buildEhrAcknowledgementPayload = ({
acknowledgementMessageId,
receivingAsid,
sendingAsid,
acknowledgedMessageId
acknowledgedMessageId,
errorCode,
errorDisplayName
}) => {
const timestamp = dateFormat(Date.now(), 'yyyymmddHHMMss');
let acknowledgementTypeCode;
let acknowledgementDetail;
let controlActEventReason;

switch (errorCode) {
case null:
logInfo('Building positive acknowledgement message with typeCode: AA');
AndyFlintNHS marked this conversation as resolved.
Show resolved Hide resolved
acknowledgementTypeCode = 'AA'; // positive ACK
acknowledgementDetail = '';
controlActEventReason = '';
break;
case '30':
case '99':
logInfo(`Building negative acknowledgement message with typeCode: AE, errorCode: ${errorCode} and errorDisplayName: ${errorDisplayName}`);
acknowledgementTypeCode = 'AE'; // negative ACK, unknown failure reason
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} and errorDisplayName: ${errorDisplayName}`);
acknowledgementTypeCode = 'AR';
acknowledgementDetail = acknowledgementDetailTemplate(acknowledgementTypeCode, errorCode, errorDisplayName);
controlActEventReason = controlActEventReasonTemplate(errorCode, errorDisplayName);
}

return ackMessageTemplate({
acknowledgementMessageId: acknowledgementMessageId.toUpperCase(),
timestamp,
acknowledgementTypeCode,
acknowledgementDetail,
acknowledgedMessageId: acknowledgedMessageId.toUpperCase(),
receivingAsid,
sendingAsid,
acknowledgedMessageId: acknowledgedMessageId.toUpperCase()
controlActEventReason
});
};

const acknowledgementDetailTemplate = (acknowledgementTypeCode, errorCode, errorDisplayName) =>
`<acknowledgementDetail typeCode="${acknowledgementTypeCode}">
<code code="${errorCode}" codeSystem="2.16.840.1.113883.2.1.3.2.4.17.101" displayName="${errorDisplayName}"/>
</acknowledgementDetail>`;

const controlActEventReasonTemplate = (errorCode, errorDisplayName) =>
`<reason typeCode="RSON">
<justifyingDetectedIssueEvent classCode="ALRT" moodCode="EVN">
<code code="${errorCode}" codeSystem="2.16.840.1.113883.2.1.3.2.4.17.101" displayName="${errorDisplayName}">
<qualifier>
<value code="ER" codeSystem="2.16.840.1.113883.2.1.3.2.4.17.104" />
</qualifier>
</code>
</justifyingDetectedIssueEvent>
</reason>`;

const ackMessageTemplate = ({
acknowledgementMessageId,
timestamp,
acknowledgementTypeCode,
acknowledgementDetail, // will be null in the case of positive ack
acknowledgedMessageId,
receivingAsid,
sendingAsid,
acknowledgedMessageId
controlActEventReason // will be null in the case of positive ack
}) =>
`<MCCI_IN010000UK13 xmlns="urn:hl7-org:v3" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:hl7-org:v3 ..SchemasMCCI_IN010000UK13.xsd">
<id root="${acknowledgementMessageId}" />
Expand All @@ -31,7 +81,8 @@ const ackMessageTemplate = ({
<processingCode code="P" />
<processingModeCode code="T" />
<acceptAckCode code="NE" />
<acknowledgement typeCode="AA">
<acknowledgement typeCode="${acknowledgementTypeCode}">
${acknowledgementDetail}
<messageRef>
<id root="${acknowledgedMessageId}" />
</messageRef>
Expand All @@ -47,6 +98,7 @@ const ackMessageTemplate = ({
</device>
</communicationFunctionSnd>
<ControlActEvent classCode="CACT" moodCode="EVN">
${controlActEventReason}
AndyFlintNHS marked this conversation as resolved.
Show resolved Hide resolved
<author1 typeCode="AUT">
<AgentSystemSDS classCode="AGNT">
<agentSystemSDS classCode="DEV" determinerCode="INSTANCE">
Expand Down
Loading