Giter Site home page Giter Site logo

shr-node-server's Introduction

shr-node-server

This project is a NodeJS server implementation of the shr-rest-api.

Running the server

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

Generating Code

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.

Manual Edits to Generated Code

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.

  1. In nodejs-server-server/controllers/DefaultService.js, import the fluxImplementation/defaultHandlers.js file.
  2. In each function, replace the autogenerated res.end() line with the appropriate function from the defaultHandlers.js file to execute the desired outcome, passing in all parameters. See each function for the appropriate line to add.

Response Headers

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();
});

Request Size

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}));

shr-node-server's People

Contributors

nicoleng12 avatar jafeltra avatar mtorchio avatar dtphelan1 avatar gregquinn2001 avatar

Watchers

Juhan Sonin avatar Andre Quina avatar James Cloos avatar Chris Moesel avatar Daniel Lee avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.