This project is a NodeJS server implementation of the shr-rest-api.
In order to install all dependencies, run the following command from inside the ./shr-node-server
directory and the ./shr-node-server/nodejs-server-server
directory:
npm install
This server optionally uses MongoDB as a backend.
Ensure that MongoDB is installed. Detailed MongoDB installation instructions are available for Windows and Mac OS X. It is recommended to configure MongoDB to start at boot. The Windows page includes instructions to create a Windows service. On OS X, it is recommended to install with brew and follow the instructions to have launchd start it at login.
Run the following script from inside './shr-node-server' directory to insert the hard coded patient data into MongoDB:
node insertHardCodedPatient.js
In order to start the server, run the following command from within the shr-node-server
directory:
npm start
The server will be running on port 3001. All routes will be available at /api
. For example, to get the demo hardcoded patient by id, go to:
http://localhost:3001/api/patient/788dcbc3-ed18-470c-89ef-35ff91854c7d
Code in the ./shr-node-server/nodejs-server-server
directory was generated using the Swagger Online Editor (https://editor.swagger.io/).
Code in the ./shr-node-server/fluxImplementation
directory and the './shr-node-server/dataacces" directory are files used specifically in the Flux Project, which is a part of the Standard Health Record Collaborative (see https://github.com/standardhealth/flux)
If an updated swagger.json or swagger.yaml file is defined, a new NodeJS implementation will need to be generated. It can be generated using the Swagger Online Editor, or other Swagger tools. The new server implementation should replace the nodejs-server-server
directory.
In order to have the NodeJS server implementation use code specific to the Flux Project, a few lines need to be added to the generated code.
- In
nodejs-server-server/controllers/DefaultService.js
, import thefluxImplementation/defaultHandlers.js
file. - In each function, replace the autogenerated
res.end()
line with the appropriate function from thedefaultHandlers.js
file to execute the desired outcome, passing in all parameters. See each function for the appropriate line to add.
The index.js file also has manually set headers for responses. Swagger-codegen will not replace modified index.js files, but if new files are downloaded from the online editor, index.js will need to be modified to include necessary response headers.
The headers to include:
// Add headers - NOTE: These were manually added. Using swagger-codegen tool will not replace a modified index.js file
app.use(function (req, res, next) {
// Website you wish to allow to connect
res.setHeader('Access-Control-Allow-Origin', '*');
// Request methods you wish to allow
res.setHeader('Access-Control-Allow-Methods', 'GET, POST, OPTIONS, PUT, PATCH, DELETE');
// Request headers you wish to allow
res.setHeader('Access-Control-Allow-Headers', 'X-Requested-With,content-type');
// Set to true if you need the website to include cookies in the requests sent
// to the API (e.g. in case you use sessions)
res.setHeader('Access-Control-Allow-Credentials', true);
// Pass to next layer of middleware
next();
});
The maximum request size can be increased to allow all entries to be sent and stored. In order to do so, add the following lines to the index.js file.
var bodyParser = require('body-parser');
app.use(bodyParser.json({limit: '1mb'}));
app.use(bodyParser.urlencoded({limit: '1mb', extended: true}));