var express = require("./node_modules/express");
var app = express();
var exec = require("child_process").exec;
var os = require('os');
var serverName = os.hostname();
if (serverName == 'edu2')
{
var birtns = "../birtns/o(../birtns)";
var vartns = "../vartns/o(../vartns)";
var gtm_dist = "/usr/local/lib/yottadb/r204";
var gtmgbldir = "../g/mumps.gld";
var docs_base = "/var/www/html/vista/docs";
process.env.gtm_dist = gtm_dist;
process.env.gtmroutines = birtns + " " + vartns + " " + gtm_dist + "/libyottadbutil.so";
process.env.gtmgbldir = gtmgbldir;
}
else
{
var birtns = "../birtns/o(../birtns)";
var vartns = "../vartns/o(../vartns)";
var gtm_dist = "/usr/lib/fis-gtm/V71010";
var gtmgbldir = "../g/mumps.gld";
var docs_base = "/var/www/html/vista/docs";
process.env.gtm_dist = gtm_dist;
process.env.gtmroutines = birtns + " " + vartns + " " + gtm_dist;
process.env.gtmgbldir = gtmgbldir;
}
var server = app.listen(8090,
function(){ console.log(Date() + ": Server has started."); });
app.use(express.text());
//---------------------- VistA Dictionary Viewer ------------------------------
app.get('/dict/list',
function (request, response)
{ gtm(request, response, "list^dictionary"); });
app.get('/dict/stan/:ien',
function (request, response)
{ gtm(request, response, "stan^dictionary " + request.params.ien); });
app.get('/dict/glob/:ien',
function (request, response)
{ gtm(request, response, "glob^dictionary " + request.params.ien); });
app.get('/dict/def/:ien/:filter',
function (request, response)
{ gtm(request, response, "def^dictionary "
+ request.params.ien + "^" + request.params.filter); });
//---------------------- FileMan API Tester -----------------------------------
app.post('/fmapil/do',
function (request, response)
{ gtm(request, response, "en^fmapil " + request.body); });
app.post('/fmapir/do',
function (request, response)
{ gtm(request, response, "en^fmapir " + request.body); });
//---------------------- HL7 to FHIR Converter --------------------------------
app.post('/HL7FHIRAI/do',
function (request, response)
{ gtm(request, response, "en^HL7FHIRAI " + request.body); });
//---------------------- ipl --------------------------------------------------
app.get('/patch/ipl',
function (request, response)
{ gtm(request, response, "view^ipl"); });
app.get('/patch/delimited/:ien',
function (request, response)
{ gtm(request, response, "delimited^ipl " + request.params.ien); });
//---------------------- Monitor ----------------------------------------------
app.get('/mon/pm2list',
function (request, response)
{ cmd(request, response, "pm2 list"); });
app.get('/mon/psefcnt',
function (request, response)
{ cmd(request, response, "ps -ef | wc -l"); });
app.get('/mon/psefgrep',
function (request, response)
{ cmd(request, response, "ps -ef | grep \'nodejs\\\|pm2\\\|mumps\' | grep -ve \'crhvist\'"); });
app.get('/mon/hitcounts',
function (request, response)
{ gtm(request, response, "hitcounts^settings"); });
app.get('/mon/hitslast',
function (request, response)
{ gtm(request, response, "hitslast^settings"); });
app.get('/mon/hitsview',
function (request, response)
{ gtm(request, response, "hitsview^settings"); });
//---------------------- rpc --------------------------------------------------
app.get('/rpc/list',
function (request, response)
{ gtm(request, response, "list^rpcw"); });
app.get('/rpc/main/:ien',
function (request, response)
{ gtm(request, response, "main^rpcw " + request.params.ien); });
//---------------------- surgery ----------------------------------------------
app.get('/surg/list',
function (request, response)
{ gtm(request, response, "list^surgery"); });
app.get('/surg/patient/:search',
function (request, response)
{ gtm(request, response, "patient^surgery "
+ request.params.search); });
app.get('/surg/provider/:search',
function (request, response)
{ gtm(request, response, "provider^surgery "
+ request.params.search); });
app.get('/surg/procedure/:search',
function (request, response)
{ gtm(request, response, "procedure^surgery "
+ request.params.search); });
app.post('/surg/do',
function (request, response)
{ gtm(request, response, "do^surgery " + request.body); });
//---------------------- volp -------------------------------------------------
app.get('/vopl/list',
function (request, response)
{ gtm(request, response, "list^vopl"); });
app.get('/vopl/main/:ien',
function (request, response)
{ gtm(request, response, "main^vopl " + request.params.ien); });
//---------------------- wbrtn ------------------------------------------------
app.get('/wbrtn/list/:alpha',
function (request, response)
{ gtm(request, response, "list^wbrtn " + request.params.alpha); });
app.get('/wbrtn/rtn/:rtn',
function (request, response)
{ gtm(request, response, "rtn^wbrtn " + request.params.rtn); });
//---------------------- Functions --------------------------------------------
// Function to make a command line request.
function cmd(request,response,cmdLine)
{ exec(cmdLine, {maxBuffer: 1024 * 3000},
function(error, stdout, stderr)
{ response.writeHead(200, {"Content-Type": "text/html"});
response.write(stdout); response.end(); });}
// Function to run a gtm routine.
function gtm(request,response,cmdLine)
{ exec(gtm_dist + "/mumps -run " + cmdLine, {maxBuffer: 1024 * 3000},
function(error, stdout, stderr)
{ response.writeHead(200, {"Content-Type": "text/html"});
response.write(stdout); response.end(); });}