Contacting support for the diagnostic lab or hospital (Node.js)
In this use case, the user contacts the diagnostic center support with or without reference to a particular appointment via a specific channel like phone, email or chat
Code snippets
Client calls the BAP server to trigger support:
router.post("/healthcare_diagnostics/contact_delivery", contactDelivery);
async function contactDelivery({ body }, res) {
try {
// .. Validate the client request before below function
await generateSupportRequest(body)
} catch (error) {
res.status(500).send(httpResponse("NACK", error));
}
};
BAP server generates the protocol request body
// Code to generate the protocol request body i.e. function generateSupportRequest() specified above
async function generateSupportRequest(body) {
/*
Example Request JSON :
{
"context": {
"domain": "nic2004:85195",
"country": "IND",
"city": "std:080",
"action": "support",
"core_version": "0.9.2",
"bap_id": "https://mock_bap.com/",
"bap_uri": "https://mock_bap.com/beckn/",
"transaction_id": "1239890342",
"message_id": "123793824",
"timestamp": "2021-03-23T10:00:40.065Z"
},
"message": {
"ref_id": "order_1"
}
}
*/
//The below code generates the above example JSON.
const transactionId = _.get(body, "transactionId");
// Returns the Context including MessageId
const context = createContext(transactionId);
const supportRequestBody = {
context,
message: {
// Construct from the request
}
};
//call protocol support
const response = await callSupport(supportRequestBody);
res
.status(200)
.send({ ...response.data, messageId: context["message_id"] });
}
BAP server calls protocol support to the network
async function callSupport(supportRequestBody) {
// It lookups the registry for BG OR BPP
let uri = lookup();
// Construct Header
const headers = constructAuthHeader(); // Auth Header with digital Signature
return axios({ url: `${uri}/healthcare_diagnostics/support`, method: "POST", headers, data: supportRequestBody });
}
BAP receives protocol on_support
/*
Example Response JSON:
{
"context": {
"domain": "nic2004:85195",
"country": "IND",
"city": "std:080",
"action": "on_support",
"core_version": "0.9.2",
"bap_id": "https://mock_bap.com/",
"bap_uri": "https://mock_bap.com/beckn/",
"transaction_id": "1239890342",
"message_id": "123793824",
"timestamp": "2021-03-23T10:00:40.065Z"
},
"message": {
"phone": "+919898989898",
"email": "[email protected]",
"uri": "http://support.bpp.com?order_id=1"
}
}
*/
// Auth middleware authenticates the digital signature of the incoming request
router.post("/healthcare_diagnostics/on_support", auth, onSupport);
async function onSupport({ body }, res) {
// Save the response to Database
await saveToDb(body);
};
Client polls BAP to get the on_support results
// Endpoint for the client to poll the search data based on the message id
async function getMessageById(req) {
try {
const messageId = _.get(req, "messageId");
// Get the data using message Id
const response = await getData(messageId);
res.status(200).send(httpResponse('ACK', "", response));
} catch(error) {
res.status(500).send(httpResponse("NACK", error));
}
};