Yeovil District Hospital NHSFT's RESTful CRUD API for community team contact details
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.
- Node.js >=14.0.0 (if running outside of Docker)
- SQL Server or PostgreSQL (either as services/instances or Docker containers)
Perform the following steps before deployment:
- Clone or download the repo
- Navigate to the project directory
- Make a copy of
.env.template
in the root directory and rename it to.env
- Configure the application using the environment variables in
.env
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"
- Run
npm install --ignore-scripts --production
to install dependencies - Run
npm run db:migrate
to create supporting database, schemas, and tables - 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!
This requires Docker installed.
- Run
docker compose up
(ordocker compose up -d
to run in background)
If you are unable to deploy this into production using Docker, it is recommended that you use a process manager such as PM2.
- Run
npm install --ignore-scripts --production
to install dependencies - Run
npm run db:migrate
to create supporting database, schemas, and tables - Run
npm install -g pm2
to install pm2 globally - Launch application with
pm2 start .pm2.config.js
- Check the application has been deployed using
pm2 list
orpm2 monit
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.
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.
ydh-community-contacts-api
is licensed under the MIT license.