diff --git a/backend/package.json b/backend/package.json index 41007ef..2b4614b 100644 --- a/backend/package.json +++ b/backend/package.json @@ -9,6 +9,7 @@ "body-parser-xml": "^2.0.3", "cors": "^2.8.5", "express": "^4.18.2", + "fast-xml-parser": "^4.3.2", "mongoose": "^6.11.4", "var": "^0.4.0", "web-vitals": "^2.1.4", diff --git a/backend/src/ncpdpScriptBuilder/buildScript.v2017071.js b/backend/src/ncpdpScriptBuilder/buildScript.v2017071.js new file mode 100644 index 0000000..3c331d7 --- /dev/null +++ b/backend/src/ncpdpScriptBuilder/buildScript.v2017071.js @@ -0,0 +1,50 @@ +/* NCPDP SCRIPT v2017071 Support */ +import { XMLBuilder } from 'fast-xml-parser'; + +export default function buildRxStatus(caseNumber, doctorName, drugNames) { + var time = new Date(); + var rxStatus = + { + "RxStatus": [ + { + "Message": [ + { + "Header": [ + { + "To": doctorName + }, + { + "From": "Pharmacy" // Placeholder: This is dependant on individual pharmacy + }, + { + "Message": "NewRx Request Recieved For: " + drugNames + }, + { + "RelatesToMessageID": caseNumber // Placeholder: This is dependant on individual pharmacy, using Case Number + }, + { + "Time": time + }, + ] + }, + { + "Body": [ + { + "Status": [ + { + "Code": "200" // Placeholder: This is dependant on individual pharmacy + } + ] + } + ] + } + + ] + } + ] + }; + const builder = new XMLBuilder({ oneListGroup: "true" }); + var RxStatus = builder.build(rxStatus); + + return RxStatus; +} \ No newline at end of file diff --git a/backend/src/routes/doctorOrders.js b/backend/src/routes/doctorOrders.js index 8cb6685..2a33a58 100644 --- a/backend/src/routes/doctorOrders.js +++ b/backend/src/routes/doctorOrders.js @@ -6,6 +6,8 @@ import axios from 'axios'; import bodyParser from 'body-parser'; import bpx from 'body-parser-xml'; import env from 'var'; +import buildRxStatus from '../ncpdpScriptBuilder/buildScript.v2017071.js'; + bpx(bodyParser); router.use( bodyParser.xml({ @@ -47,7 +49,12 @@ router.post('/api/addRx', async (req, res) => { console.log('POST DoctorOrder: '); console.log(newOrder); - res.send(newOrder); + + var RxStatus = buildRxStatus(newOrder.caseNumber, newOrder.doctorName, newOrder.drugNames); + console.log('RxStatus:'); + console.log(RxStatus); + + res.send(RxStatus); }); /**