Skip to content

Commit

Permalink
Merge pull request #62 from mcode/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
smalho01 authored Jan 12, 2024
2 parents 9b83086 + 8fbf5a4 commit 405c738
Show file tree
Hide file tree
Showing 11 changed files with 99 additions and 69 deletions.
16 changes: 0 additions & 16 deletions .github/auto_assign.yml

This file was deleted.

File renamed without changes.
2 changes: 0 additions & 2 deletions Dockerfile.dev
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
32 changes: 23 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -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.
6 changes: 3 additions & 3 deletions backend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
48 changes: 48 additions & 0 deletions backend/src/ncpdpScriptBuilder/buildScript.v2017071.js
Original file line number Diff line number Diff line change
@@ -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;
}
9 changes: 8 additions & 1 deletion backend/src/routes/doctorOrders.js
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down Expand Up @@ -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);
});

/**
Expand Down
2 changes: 1 addition & 1 deletion backend/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
22 changes: 0 additions & 22 deletions pm2.config.dev.js

This file was deleted.

30 changes: 15 additions & 15 deletions pm2.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}
}
]
};
NODE_ENV: "production",
},
},
],
};

0 comments on commit 405c738

Please sign in to comment.