-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #99 from mcode/649_script_single_endpoint
Create a new /ncpdp/script endpoint for all NCPDP SCRIPT messages
- Loading branch information
Showing
4 changed files
with
108 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import express from 'express'; | ||
const router = express.Router(); | ||
// XML Parsing Middleware used for NCPDP SCRIPT | ||
import bodyParser from 'body-parser'; | ||
import bpx from 'body-parser-xml'; | ||
|
||
import { processNewRx } from './doctorOrders.js'; | ||
import { buildRxError } from '../ncpdpScriptBuilder/buildScript.v2017071.js'; | ||
|
||
bpx(bodyParser); | ||
router.use( | ||
bodyParser.xml({ | ||
xmlParseOptions: { | ||
normalize: true, // Trim whitespace inside text nodes | ||
explicitArray: false // Only put nodes in array if >1 | ||
} | ||
}) | ||
); | ||
router.use(bodyParser.urlencoded({ extended: false })); | ||
|
||
/** | ||
* Route: 'ncpdp/script' | ||
* Description : 'Supports NCPDP SCRIPT messages, currntly only NewRx' | ||
*/ | ||
router.post('/script', async (req, res) => { | ||
// Parsing incoming NCPDP SCRIPT XML to JSON | ||
console.log('received /ncpdp/script message'); | ||
const newRxMessageConvertedToJSON = req.body; | ||
let message = newRxMessageConvertedToJSON?.Message; | ||
let body = message?.Body; | ||
let status = null; | ||
if (body?.NewRx) { | ||
// process NewRx message | ||
status = await processNewRx(newRxMessageConvertedToJSON); | ||
} else { | ||
let errorStr = 'unknown message type'; | ||
console.log('/ncpdp/script ' + errorStr); | ||
status = buildRxError(newRxMessageConvertedToJSON, errorStr); | ||
} | ||
|
||
res.send(status); | ||
console.log('Sent Status/Error'); | ||
}); | ||
|
||
export default router; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters