Skip to content

Commit

Permalink
added lukes logging stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
daco101 authored and jbradl11 committed Aug 2, 2018
1 parent 830e40c commit 0a571aa
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 6 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,7 @@ yarn-error.log
.vscode/

# ssl setup script(kept in server-scripts)
docker_ssl_setup.sh
docker_ssl_setup.sh

#test log file
test_log.info
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,14 @@
"license": "Apache-2.0",
"scripts": {
"start": "node server.js",
"test": "nyc --reporter=html --reporter=text mocha spec/server_spec.js",
"testRunningServer": "nyc --reporter=html --reporter=text mocha spec/server_spec_against_running.js"
"test": "NODE_ENV=test nyc --reporter=html --reporter=text mocha spec/server_spec.js",
"testRunningServer": "NODE_ENV=test nyc --reporter=html --reporter=text mocha spec/server_spec_against_running.js"
},
"dependencies": {
"compression": "^1.7.3",
"cqm-execution": "https://github.com/projecttacoma/cqm-execution.git#bonnie_backend_execution",
"express": "^4.16.3"
"express": "^4.16.3",
"winston": "^3.0.0"
},
"devDependencies": {
"mocha": "^5.2.0",
Expand Down
21 changes: 19 additions & 2 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const app = require('express')();
const bodyParser = require('body-parser');
const calculator = require('cqm-execution').Calculator;
const compression = require('compression');
const winston = require('winston');

app.use(compression());
app.use(bodyParser.json({ limit: '50mb' }));
Expand All @@ -10,6 +11,18 @@ app.use(bodyParser.urlencoded({ extended: true, limit: '50mb', parameterLimit: '
const LISTEN_PORT = process.env.CQM_EXECUTION_SERVICE_PORT || 8081; // Port to listen on
const REQUIRED_PARAMS = ['measure', 'valueSetsByOid', 'patients']; // Required params for calculation


// All logging is to the console, docker can save these messages to file if desired
const logger = winston.createLogger({
level: 'info',
format: winston.format.combine(
winston.format.timestamp(),
winston.format.simple()
),
transports: (process.env.NODE_ENV == 'test') ? [new winston.transports.File({ filename: 'test_log.info'})] : [ new winston.transports.Console() ]
});


/**
* Version; Informs a client which version of js-ecqm-engine and cqm-models this
* service is currently utilizing.
Expand All @@ -18,6 +31,7 @@ const REQUIRED_PARAMS = ['measure', 'valueSetsByOid', 'patients']; // Required p
* @route {GET} /version
*/
app.get('/version', function (request, response) {
logger.log({ level: 'info', message: 'GET /version. headers: ' + JSON.stringify(request.headers) });
response.send({
'cqm-execution': '?', //response.send(engine.version) TODO: Add this when cqm-execution is in NPM
'cqm-models': '?' //response.send(models.version) TODO: Add this when cqm-models is in NPM
Expand Down Expand Up @@ -45,6 +59,7 @@ app.post('/calculate', function (request, response) {
// If there are missing params, return a 400 with a description of which
// params were missing.
if (missing.length) {
logger.log({ level: 'error', message: `GET /calculate. missing params ${missing.join(', ')}, headers: ${JSON.stringify(request.headers)}` });
response.status(400).send({
error: `Missing required parameter(s): ${missing.join(', ')}`, request: request.body
});
Expand All @@ -55,14 +70,17 @@ app.post('/calculate', function (request, response) {
const {measure, valueSetsByOid, patients, options = {}} = request.body

if (Array.isArray(valueSetsByOid)){
logger.log({ level: 'error', message: 'GET /calculate. valueSets passed as array, headers: ' + JSON.stringify(request.headers) });
response.status(400).send({'input error': 'value sets must be passed as an object keyed by oid and then version, not an array'});
return;
}

try {
results = calculator.calculate(measure, patients, valueSetsByOid, options);
logger.log({ level: 'info', message: 'GET /calculate. measure: ' + measure['cms_id'] + ' patient_count: ' + patients.length });
response.json(results);
} catch(error) {
logger.log({ level: 'error', message: `GET /calculate. error in the calculation engine: ${error} headers: ${JSON.stringify(request.headers)}` });
response.status(500).send({'error in the calculation engine': error});
return;
}
Expand All @@ -73,5 +91,4 @@ app.use(function (request, response, next) {
response.status(404).send();
});

module.exports = app.listen(LISTEN_PORT, () => console.log('cqm-execution-service is now listening on port ' + LISTEN_PORT));

module.exports = app.listen(LISTEN_PORT, () => logger.log({level: 'info', message: 'cqm-execution-service is now listening on port ' + LISTEN_PORT}));

0 comments on commit 0a571aa

Please sign in to comment.