-
Notifications
You must be signed in to change notification settings - Fork 1
/
qalyoutcome.js
53 lines (49 loc) · 1.62 KB
/
qalyoutcome.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
const ptlevels = require('./ptlvlConverter')
const lookupindexer = require('./lookupIndexer')
const csvValue = require('./csvlookup')
const fileIndexer = require('./fileIndexer')
function qalyoutcome(path, config, inputs){
var features = inputFeatures(config, inputs)
var output = {}
var ptlvl = ptlevels(config, features)
let fileIndex = fileIndexer(config, inputs.features)
var luindex = lookupindexer(path, config, fileIndex, ptlvl)
if(Object.keys(luindex).length!=0){
var result = csvValue(luindex.tableid, luindex.index)
if(Object.keys(result).length!=0){
config.outputs.forEach(function(e){
let field = e.field.trim().toLowerCase()
let outputObj ={}
outputObj.id = e.id
outputObj.field = field
outputObj.service = config.id
outputObj.qaly = {}
outputObj.qaly.gain = result[field]
outputObj.data_source = {}
outputObj.data_source.updateDate = config.updatedOn
outputObj.data_source.type = config.datatype
if(process.env.DEBUG){
outputObj.data_source.debugentry=result
}
output[e.id]= outputObj
})
} else {
output[config.id]={}
output[config.id].id=config.id
output[config.id].error = "Entry not found in the look up table."
}
} else {
output[config.id]={}
output[config.id].id=config.id
output[config.id].error = "No look up table available."
}
return output
}
function inputFeatures(config, pt){
var features = {}
Object.keys(config.columns).forEach(function(key){
features[key]=pt.features[key]
})
return features
}
module.exports= qalyoutcome