diff --git a/.github/auto_assign.yml b/.github/auto_assign.yml deleted file mode 100644 index 407ed6d..0000000 --- a/.github/auto_assign.yml +++ /dev/null @@ -1,16 +0,0 @@ -# Set to true to add reviewers to pull requests -addReviewers: true - -# Set to true to add assignees to pull requests -addAssignees: false - -# A list of reviewers to be added to pull requests (GitHub user name) -reviewers: - - zacharyrobin - - KeeyanGhoreshi - - smalho01 - - plarocque4 - - kennyEung - -# A number of reviewers added to the pull request, Set to 0 to add all reviewers -numberOfReviewers: 0 diff --git a/pull_request_template.md b/.github/pull_request_template.md similarity index 100% rename from pull_request_template.md rename to .github/pull_request_template.md diff --git a/Dockerfile.dev b/Dockerfile.dev index 436f2df..a575c3a 100644 --- a/Dockerfile.dev +++ b/Dockerfile.dev @@ -8,8 +8,6 @@ WORKDIR /home/node/app/frontend RUN npm install WORKDIR /home/node/app -RUN npm install pm2 -g - EXPOSE 5050 EXPOSE 5051 diff --git a/README.md b/README.md index 5e341bb..c07a75f 100644 --- a/README.md +++ b/README.md @@ -1,21 +1,35 @@ # Pharmacy Information Management System -### Setup +## Setup +The application is divided into a frontend and backend service. For an initial setup run `npm install` in both the frontend and backend subdirectories. This will install the dependencies required for each of the services. -The application is divided into a frontend and backend service. For an initial setup you will need to `run npm install` in both the frontend and backend subdirectories. This will install the dependencies required for each of the services. +## Running backend and frontend -### Running +Run the individual services by either launching both of them independently or using pm2 innately through Docker. -Running the individual services can be done by either launching both of them independently or using pm2. To run them individually you will need to open a terminal window in each of the frontend and backend subdirectories. From there you will need to run `npm start` in each of the terminal windows. +### Running independently -To run both the systems under pm2 you will first need to install it: `npm install pm2 -g` After it is installed you can run both the systems with a single command `pm2 start pm2.config.json`. This will start both the frontend and the backend services. +To run them individually you will need to open a terminal window in each of the frontend and backend subdirectories. From there you will need to run `npm start` in each of the terminal windows. -By default, the frontend will start on port 3000 and the backend will start on port 5051. To configure the frontend to start on different port set the PORT environment variable to the port you would like it to start on. ex. `PORT 5050 npm start` To configure the backend to start on a different port set the BACKEND_PORT environment variable to the port you would like it to run on. +By default, the frontend will start on port 5050 (defined in `frontend/.env`) and the backend will start on port 5051 (defined in `backend/env.json`). -These environment variables, and others , can also be set in the pm2 configuration file for the individula service entries. +To configure the frontend to start on different port, set the `PORT` environment variable to the desired port; e.g. `PORT=5050 npm start`, or create a `frontend/.env.local` to override `PORT`. -Once running both the frontend and backend systems open [http://localhost:5050](http://localhost:5050) in your browser to view the application. +To configure the backend to start on a different port, set the `BACKEND_PORT` environment variable to the desired port; e.g. +`BACKEND_PORT=5051 npm start`. + +These environment variables, and others, can also be set in the pm2 configuration file for the individual service entries. + +Once running both the frontend and backend systems, open [http://localhost:5050](http://localhost:5050) in your browser to view the application. + +### Using pm2 + +`pm2` is used in our [Dockerized REMS Integration Prototype setup](https://github.com/mcode/rems-setup/blob/main/DeveloperSetupGuide.md) for production to start both the frontend and the backend services. It is not used in development due to a bug with hot-reloading code changes in the two services. ## Version -This application requires node v20.0 or greater. + +This application requires node.js v20.0 or greater. Using [`nvm`](https://github.com/nvm-sh/nvm) is optional, but easier when managing different node.js versions. + +- `nvm install 20` +- `nvm use 20` or `nvm use default 20`, as most of the REMS Integration Prototype repositories are compatible with node v20.0. diff --git a/backend/package-lock.json b/backend/package-lock.json index 7b6a8bc..9d93004 100644 --- a/backend/package-lock.json +++ b/backend/package-lock.json @@ -3381,9 +3381,9 @@ "dev": true }, "node_modules/follow-redirects": { - "version": "1.15.2", - "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.2.tgz", - "integrity": "sha512-VQLG33o04KaQ8uYi2tVNbdrWp1QWxNNea+nmIB4EVM28v0hmP17z7aG1+wAkNzVq4KeXTq3221ye5qTJP91JwA==", + "version": "1.15.4", + "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.4.tgz", + "integrity": "sha512-Cr4D/5wlrb0z9dgERpUL3LrmPKVDsETIJhaCMeDfuFYcqa5bldGV6wBsAN6X/vxlXQtFBMrXdXxdL8CbDTGniw==", "funding": [ { "type": "individual", 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..49a5370 --- /dev/null +++ b/backend/src/ncpdpScriptBuilder/buildScript.v2017071.js @@ -0,0 +1,48 @@ +/* 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; +} 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); }); /** diff --git a/backend/src/server.ts b/backend/src/server.ts index 118dcce..c9289f4 100644 --- a/backend/src/server.ts +++ b/backend/src/server.ts @@ -27,7 +27,7 @@ async function main() { let server: any = app; if (env.USE_HTTPS) { - console.log('Enabling HTTPS HTTPS'); + console.log('Enabling HTTPS'); const credentials = { key: fs.readFileSync(env.HTTPS_KEY_PATH), cert: fs.readFileSync(env.HTTPS_CERT_PATH) diff --git a/pm2.config.dev.js b/pm2.config.dev.js deleted file mode 100644 index de6fb45..0000000 --- a/pm2.config.dev.js +++ /dev/null @@ -1,22 +0,0 @@ -/** - * This file serves as configuration for the PM2 process manager. - * For more info, see: http://pm2.keymetrics.io/docs/usage/application-declaration/ - * - * This is mainly used in our Docker image. - */ - module.exports = { - apps: [ - // API Server - { - name: 'API', - script: 'npm start', - cwd: 'backend' - }, - // Fronted Server - { - name: 'FrontEnd', - script: 'npm start', - cwd: 'frontend' - } - ] -}; \ No newline at end of file diff --git a/pm2.config.js b/pm2.config.js index 25649bc..a4dc8e2 100644 --- a/pm2.config.js +++ b/pm2.config.js @@ -4,25 +4,25 @@ * * This is mainly used in our Docker image. */ - module.exports = { +module.exports = { apps: [ // API Server { - name: 'API', - script: 'npm start', - cwd: 'backend', + name: "API", + script: "npm start", + cwd: "backend", env_production: { - NODE_ENV: 'production' - } + NODE_ENV: "production", + }, }, - // Fronted Server + // Frontend Server { - name: 'FrontEnd', - script: 'npm start', - cwd: 'frontend', + name: "FrontEnd", + script: "npm start", + cwd: "frontend", env_production: { - NODE_ENV: 'production' - } - } - ] -}; \ No newline at end of file + NODE_ENV: "production", + }, + }, + ], +};