-
Notifications
You must be signed in to change notification settings - Fork 6
/
advanced.js
46 lines (37 loc) · 1.06 KB
/
advanced.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
const { calculate, symptoms, conditions } = require('../dist/index.js');
// create shared hashing algorithm for input
const hashKey = v => {
return v
.replace(/[,".]/g, '')
.replace(/\s/g, '')
.toLowerCase();
};
// create hash map for symptoms
let symptomsHashMap = {};
symptoms.items.forEach((v, i) => {
symptomsHashMap[hashKey(v.prompt)] = v.key;
if (v.aliases != undefined) {
v.aliases.forEach(a => {
symptomsHashMap[hashKey(a)] = v.key;
});
}
});
// create hash map for conditions
let conditionsHashMap = {};
conditions.items.forEach((v, i) => {
conditionsHashMap[hashKey(v.prompt)] = v.key;
if (v.aliases != undefined) {
v.aliases.forEach(a => {
conditionsHashMap[hashKey(a)] = v.key;
});
}
});
let inputSymptoms = ['Shortness of breath'];
let newSymptoms = inputSymptoms.map(v => symptomsHashMap[hashKey(v)]);
let inputConditions = [];
let newConditions = inputConditions.map(v => conditionsHashMap[hashKey(v)]);
const result = calculate({
symptoms: newSymptoms,
conditions: newConditions,
});
console.log(result);