-
Notifications
You must be signed in to change notification settings - Fork 1
/
adfice-evaluator.test.js
77 lines (70 loc) · 2.31 KB
/
adfice-evaluator.test.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
// SPDX-License-Identifier: GPL-3.0-or-later
// Copyright (C) 2021-2024 Stichting Open Electronics Lab
// vim: set sts=4 shiftwidth=4 expandtab :
"use strict";
const adfice_factory = require('./adfice.js');
const ae = require('./adfice-evaluator');
let adfice = adfice_factory.adfice_init();
afterAll(async () => {
return await adfice.shutdown();
});
test('test drugs_without_fired_rules', () => {
let rulesResult = {
C09AA01: ["one", "two"],
J02AB02: [],
C07AA01: ["foo", "bar"]
};
let expected = ["J02AB02"];
let actual = ae.drugs_without_fired_rules(rulesResult);
expect(actual).toStrictEqual(expected);
});
test('test drugs_without_fired_rules', async () => {
let preselectRule = {
"preselect_or": null,
"preselect_not": "C03CA,C03CB",
"sql_condition": null
};
let result = await ae.evaluate_preselected(preselectRule, 1, "C03CA02",
adfice.is_sql_condition_true);
expect(result).toBe(false);
preselectRule = {
"preselect_or": null,
"preselect_not": "C03CA,C03CB",
"sql_condition": null
};
result = await ae.evaluate_preselected(preselectRule, 1, "C03CD02",
adfice.is_sql_condition_true);
expect(result).toBe(true);
});
test('test evaluate_rules as it is called in get_advice_for_patient', async () => {
let meds = [];
let rules = await adfice.get_active_rules();
let patient_id = 160;
let evaluated = await ae.evaluate_rules(meds, rules, patient_id,
adfice.is_sql_condition_true);
let expected = {
"meds_with_rules_to_fire": {},
"meds_with_fired": [],
"meds_without_fired": []
};
expect(evaluated).toStrictEqual(expected);
});
test('test evaluate_rules with med lacking ATC code', async () => {
let garlic = {
ATC_code: null,
medication_name: 'garlic',
generic_name: 'allium sativum',
start_date: '1999-12-31'
}
let meds = [garlic];
let rules = await adfice.get_active_rules();
let patient_id = 160;
let evaluated = await ae.evaluate_rules(meds, rules, patient_id,
adfice.is_sql_condition_true);
let expected = {
"meds_with_rules_to_fire": {},
"meds_with_fired": [],
"meds_without_fired": [garlic]
};
expect(evaluated).toStrictEqual(expected);
});