Skip to content
This repository has been archived by the owner on Jan 28, 2024. It is now read-only.

Yeovil Hospital's RESTful CRUD API for community team contact details

License

Notifications You must be signed in to change notification settings

Fdawgs/yh-community-contacts-api

Repository files navigation

Yeovil District Hospital NHS Foundation Trust - Community Contacts RESTful CRUD API

GitHub Release Build Status Coverage Status Known Vulnerabilities code style: prettier

Yeovil District Hospital NHSFT's RESTful CRUD API for community team contact details

Intro

This is Yeovil District Hospital NHSFT's Community Contacts RESTful API, a Node.js application using the Fastify web framework, built to support CRUD (Create, Read, Update, and Delete) functionality of community midwife, health visitor, and school nurse team email addresses in YDH's catchment area.

This was built for use by interface engine channels/workflows that automatically dispatch maternity and paediatric discharge summaries via encrypted email to their respective community teams, based on a patient’s postcode, school code, or GP practice code.

Prerequisites

Setup

Perform the following steps before deployment:

  1. Clone or download the repo
  2. Navigate to the project directory
  3. Make a copy of .env.template in the root directory and rename it to .env
  4. Configure the application using the environment variables in .env

Note: You will need to create a database prior to using it in the DB_CONNECTION_STRING environment variable (this does not apply if using the included Docker Compose file to deploy)

Note: Set the following environment variables in .env to meet NHS Digital's recommendation to retain 6 months' worth of logs:

  • LOG_ROTATION_DATE_FORMAT="YYYY-MM-DD"
  • LOG_ROTATION_FREQUENCY="daily"
  • LOG_ROTATION_MAX_LOGS="180"

Deployment

Standard Deployment

  1. Run npm install --ignore-scripts --production to install dependencies
  2. Run npm run db:migrate to create supporting database, schemas, and tables
  3. Run npm start

The service should be up and running on the port set in the config. You should see the following output in stdout or the log file specified using the LOG_ROTATION_FILENAME environment variable:

{
	"level": "info",
	"time": "2022-01-10T10:17:35.556Z",
	"pid": 18,
	"hostname": "MYCOMPUTER",
	"msg": "Connecting to MSSQL DB"
}
{
	"level": "info",
	"time": "2022-01-10T10:17:35.558Z",
	"pid": 18,
	"hostname": "MYCOMPUTER",
	"msg": "MSSQL DB connection opened"
}
{
	"level": "info",
	"time": "2022-01-10T10:17:35.760Z",
	"pid": 18,
	"hostname": "MYCOMPUTER",
	"msg": "Server listening at http:https://0.0.0.0:8204"
}

You can now navigate to http:https://0.0.0.0:8204/docs to see the API documentation!

Deploying Using Docker

This requires Docker installed.

  1. Run docker compose up (or docker compose up -d to run in background)

Deploying Using PM2

If you are unable to deploy this into production using Docker, it is recommended that you use a process manager such as PM2.

  1. Run npm install --ignore-scripts --production to install dependencies
  2. Run npm run db:migrate to create supporting database, schemas, and tables
  3. Run npm install -g pm2 to install pm2 globally
  4. Launch application with pm2 start .pm2.config.js
  5. Check the application has been deployed using pm2 list or pm2 monit

To Install as a Windows Service:

If using a Microsoft Windows OS utilise pm2-installer to install PM2 as a Windows service.

Note: PM2 will automatically restart the application if .env is modified.

Contributing

Contributions are welcome, and any help is greatly appreciated!

See CONTRIBUTING.md for details on how to get started. Please adhere to this project's Code of Conduct when contributing.

Acknowledgements

  • Michael McCormack - MSSQL query optimisation

License

ydh-community-contacts-api is licensed under the MIT license.