Skip to content

Commit

Permalink
Updated algorithm names
Browse files Browse the repository at this point in the history
  • Loading branch information
jmcameron committed Mar 15, 2021
1 parent e4039ac commit 29912b5
Show file tree
Hide file tree
Showing 9 changed files with 49 additions and 57 deletions.
8 changes: 4 additions & 4 deletions client/src/i18n/en/stock.json
Original file line number Diff line number Diff line change
Expand Up @@ -138,10 +138,10 @@
"MONTHLY_CONSUM" : "Average Monthly Consumption",
"MONTHLY_CONSUMPTION" : {
"AVERAGE_MONTHLY_CONSUMPTION" : "Average Monthly Consumption",
"ALGO_1" : "Algorithm 1",
"ALGO_1_COMMENT" : "The average monthly consumption is obtained by dividing the quantity consumed during the period by the number of days with stock during the period, and by multiplying the result by 30.5.",
"ALGO_4" : "Algorithm 4 (MSH)",
"ALGO_4_COMMENT" : "The average consumption is obtained by dividing the quantity consumed during the period by number of months of stock (found by subtracting the number of days of stock outs divided by 30.5 from the number of months in the period). The MSH algorithm is recommended by the Management Sciences for Health organization (https://www.msh.org).",
"ALGORITHM_DEFAULT" : "Default Algorithm",
"ALGORITHM_DEFAULT_COMMENT" : "The average monthly consumption is obtained by dividing the quantity consumed during the period by the number of days with stock during the period, and by multiplying the result by 30.5.",
"ALGORITHM_MSH" : "MSH Algorithm",
"ALGORITHM_MSH_COMMENT" : "The average consumption is obtained by dividing the quantity consumed during the period by number of months of stock (found by subtracting the number of days of stock outs divided by 30.5 from the number of months in the period). The MSH algorithm is recommended by the Management Sciences for Health organization (https://www.msh.org).",
"FIRST_INVENTORY_MOVEMENT_DATE" : "First Recorded Movement",
"LAST_INVENTORY_MOVEMENT_DATE" : "Last Recorded Movement",
"DAYS_BEFORE_CONSUMPTION" : "Days before First Consumption",
Expand Down
8 changes: 4 additions & 4 deletions client/src/i18n/fr/stock.json
Original file line number Diff line number Diff line change
Expand Up @@ -140,10 +140,10 @@
"MONTHLY_CONSUM" : "Consommation Mensuelle Moyenne",
"MONTHLY_CONSUMPTION" : {
"AVERAGE_MONTHLY_CONSUMPTION" : "Consommation Mensuelle Moyenne",
"ALGO_1" : "Algorithme 1",
"ALGO_1_COMMENT" : "La consommation moyenne mensuel est obtenue en divisant la quantité consommée durant la période définie par le nombre de jour de stock pour ladite période, et en multipliant le résultat obtenu par 30.5",
"ALGO_4" : "Algorithme 4 (MSH)",
"ALGO_4_COMMENT" : "La consommation moyenne est égale à : La quantité consommée durant la période / (Nombre de mois à considérer - (Le nombre de jour de rupture de stock / 30.5)). L'algorithme MSH est recommandé par l'organisation Management Sciences for Health (https://www.msh.org).",
"ALGORITHM_DEFAULT" : "Algorithme par défaut ",
"ALGORITHM_DEFAULT_COMMENT" : "La consommation moyenne mensuel est obtenue en divisant la quantité consommée durant la période définie par le nombre de jour de stock pour ladite période, et en multipliant le résultat obtenu par 30.5",
"ALGORITHM_MSH" : "Algorithme MSH",
"ALGORITHM_MSH_COMMENT" : "La consommation moyenne est égale à : La quantité consommée durant la période / (Nombre de mois à considérer - (Le nombre de jour de rupture de stock / 30.5)). L'algorithme MSH est recommandé par l'organisation Management Sciences for Health (https://www.msh.org).",
"FIRST_INVENTORY_MOVEMENT_DATE" : "Premier mouvement enregistré ",
"LAST_INVENTORY_MOVEMENT_DATE" : "Dernier mouvement enregistré ",
"DAYS_BEFORE_CONSUMPTION" : "Jours avant la première consommation ",
Expand Down
10 changes: 5 additions & 5 deletions client/src/js/constants/bhConstants.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,14 +180,14 @@ function constantConfig() {
},
average_consumption_algo : [
{
name : 'algo1',
label : 'STOCK.MONTHLY_CONSUMPTION.ALGO_1',
comment : 'STOCK.MONTHLY_CONSUMPTION.ALGO_1_COMMENT',
name : 'algo_def',
label : 'STOCK.MONTHLY_CONSUMPTION.ALGORITHM_DEFAULT',
comment : 'STOCK.MONTHLY_CONSUMPTION.ALGORITHM_DEFAULT_COMMENT',
},
{
name : 'algo_msh',
label : 'STOCK.MONTHLY_CONSUMPTION.ALGO_4',
comment : 'STOCK.MONTHLY_CONSUMPTION.ALGO_4_COMMENT',
label : 'STOCK.MONTHLY_CONSUMPTION.ALGORITHM_MSH',
comment : 'STOCK.MONTHLY_CONSUMPTION.ALGORITHM_MSH_COMMENT',
},
],
};
Expand Down
28 changes: 14 additions & 14 deletions client/src/modules/stock/inventories/modals/amc.modal.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,16 @@
<div ng-if="!ModalCtrl.loading">
<p class="alert alert-info">
<i class="fa fa-info-circle"></i>
<span ng-show="ModalCtrl.isAlgo1">
<strong translate>STOCK.MONTHLY_CONSUMPTION.ALGO_1</strong>
<span ng-show="ModalCtrl.isAlgoDef">
<strong translate>STOCK.MONTHLY_CONSUMPTION.ALGORITHM_DEFAULT</strong>
<br />
<span translate>STOCK.MONTHLY_CONSUMPTION.ALGO_1_COMMENT</span>
<span translate>STOCK.MONTHLY_CONSUMPTION.ALGORITHM_DEFAULT_COMMENT</span>
</span>

<span ng-show="ModalCtrl.isAlgo4">
<strong translate>STOCK.MONTHLY_CONSUMPTION.ALGO_4</strong>
<span ng-show="ModalCtrl.isAlgoMSH">
<strong translate>STOCK.MONTHLY_CONSUMPTION.ALGORITHM_MSH</strong>
<br />
<span translate>STOCK.MONTHLY_CONSUMPTION.ALGO_4_COMMENT</span>
<span translate>STOCK.MONTHLY_CONSUMPTION.ALGORITHM_MSH_COMMENT</span>
</span>
</p>

Expand Down Expand Up @@ -65,26 +65,26 @@
<table class="table table-condensed table-bordered">
<thead>
<tr>
<th translate translate-attr="{ 'title' : 'STOCK.MONTHLY_CONSUMPTION.ALGO_1_COMMENT' }">STOCK.MONTHLY_CONSUMPTION.ALGO_1</th>
<th translate translate-attr="{ 'title' : 'STOCK.MONTHLY_CONSUMPTION.ALGO_4_COMMENT' }">STOCK.MONTHLY_CONSUMPTION.ALGO_4</th>
<th translate translate-attr="{ 'title' : 'STOCK.MONTHLY_CONSUMPTION.ALGORITHM_DEFAULT_COMMENT' }">STOCK.MONTHLY_CONSUMPTION.ALGORITHM_DEFAULT</th>
<th translate translate-attr="{ 'title' : 'STOCK.MONTHLY_CONSUMPTION.ALGORITHM_MSH_COMMENT' }">STOCK.MONTHLY_CONSUMPTION.ALGORITHM_MSH</th>
</tr>
</thead>
<tbody>
<tr class="text-right">
<td ng-class="{ 'bg-success text-success' : ModalCtrl.isAlgo1 }">{{ModalCtrl.data.algo1}}</td>
<td ng-class="{ 'bg-success text-success' : ModalCtrl.isAlgo4 }">{{ModalCtrl.data.algo_msh}}</td>
<td ng-class="{ 'bg-success text-success' : ModalCtrl.isAlgoDef }">{{ModalCtrl.data.algo_def}}</td>
<td ng-class="{ 'bg-success text-success' : ModalCtrl.isAlgoMSH }">{{ModalCtrl.data.algo_msh}}</td>
</tr>
</tbody>
</table>

<hr />

<dl>
<dt ng-show="ModalCtrl.isAlgo1" translate>STOCK.MONTHLY_CONSUMPTION.ALGO_1</dt>
<dd ng-show="ModalCtrl.isAlgo1">30.5 &times; (<span class="text-primary">{{ModalCtrl.data.sum_consumed_quantity}}</span> / <span class="text-success">{{ModalCtrl.data.sum_stock_day}}</span>) &equals; <u>{{ModalCtrl.data.avg_consumption}}</u> </dd>
<dt ng-show="ModalCtrl.isAlgoDef" translate>STOCK.MONTHLY_CONSUMPTION.ALGORITHM_DEFAULT</dt>
<dd ng-show="ModalCtrl.isAlgoDef">30.5 &times; (<span class="text-primary">{{ModalCtrl.data.sum_consumed_quantity}}</span> / <span class="text-success">{{ModalCtrl.data.sum_stock_day}}</span>) &equals; <u>{{ModalCtrl.data.avg_consumption}}</u> </dd>

<dt ng-show="ModalCtrl.isAlgo4" translate>STOCK.MONTHLY_CONSUMPTION.ALGO_4</dt>
<dd ng-show="ModalCtrl.isAlgo4"><span class="text-primary">{{ModalCtrl.data.sum_consumed_quantity}}</span> / (<span class="text-warning">{{ModalCtrl.data.number_of_month}}</span> &minus; (<span class="text-danger">{{ModalCtrl.data.sum_stock_out_days}}</span> / 30.5)) &equals; <u>{{ModalCtrl.data.avg_consumption}}</u></dd>
<dt ng-show="ModalCtrl.isAlgoMSH" translate>STOCK.MONTHLY_CONSUMPTION.ALGORITHM_MSH</dt>
<dd ng-show="ModalCtrl.isAlgoMSH"><span class="text-primary">{{ModalCtrl.data.sum_consumed_quantity}}</span> / (<span class="text-warning">{{ModalCtrl.data.number_of_month}}</span> &minus; (<span class="text-danger">{{ModalCtrl.data.sum_stock_out_days}}</span> / 30.5)) &equals; <u>{{ModalCtrl.data.avg_consumption}}</u></dd>
</dl>
<hr />
<dl>
Expand Down
4 changes: 2 additions & 2 deletions client/src/modules/stock/inventories/modals/amc.modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ function StockAMCModalController(Stock, Notify, Instance, data, moment, Constant
vm.data.stock_out_date = moment().add(daysOfStockLeft, 'days').toDate();

// nicer aliases to use in the HTML
vm.isAlgo1 = vm.settings.average_consumption_algo === 'algo1';
vm.isAlgo4 = vm.settings.average_consumption_algo === 'algo_msh';
vm.isAlgoDef = vm.settings.average_consumption_algo === 'algo_def';
vm.isAlgoMSH = vm.settings.average_consumption_algo === 'algo_msh';
})
.catch(Notify.handleError)
.finally(() => {
Expand Down
10 changes: 5 additions & 5 deletions server/models/procedures/stock.sql
Original file line number Diff line number Diff line change
Expand Up @@ -529,7 +529,7 @@ CREATE PROCEDURE GetAMC(
_head_days,
_tail_days INTEGER;

DECLARE _algo_1,
DECLARE _algo_def,
_algo_msh DECIMAL(19,4);

-- NOTE(@jniles): I am ignoring the enterprise_id for ease of use. For full correctness,
Expand Down Expand Up @@ -615,12 +615,12 @@ CREATE PROCEDURE GetAMC(
-- the number of days in the period
SELECT DATEDIFF(_date, _start_date) INTO _sum_day;

-- Algo 1
-- Default algorithm
-- The average monthly consumption is obtained by dividing the quantity consumed during the period by
-- the number of days with stock during the period, and by multiplying the result by 30.5.
SET _algo_1 = (_sum_consumed_quantity / IF(_sum_stock_day IS NULL OR _sum_stock_day = 0, 1, _sum_stock_day)) * 30.5;
SET _algo_def = (_sum_consumed_quantity / IF(_sum_stock_day IS NULL OR _sum_stock_day = 0, 1, _sum_stock_day)) * 30.5;

-- Algo 4 (MSH)
-- MSH algorithm
-- The average consumption is obtained by dividing the quantity consumed during the period by the difference of the
-- number of months in the period minus the total number of days of stock out in the period. The MSH algorithm
-- is recommended by the Management Sciences for Health organization (https://www.msh.org).
Expand All @@ -631,7 +631,7 @@ CREATE PROCEDURE GetAMC(
BUID(_inventory_uuid) AS inventory_uuid,
_start_date AS start_date,
_date AS end_date,
ROUND(IFNULL(_algo_1, 0), 2) AS algo1,
ROUND(IFNULL(_algo_def, 0), 2) AS algo_def,
ROUND(IFNULL(_algo_msh, 0), 2) AS algo_msh,
_last_quantity AS quantity_in_stock,
_sum_day AS sum_days,
Expand Down
24 changes: 8 additions & 16 deletions test/end-to-end/stock/stock.setting.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,12 @@ function StockSettingTests() {
await page.setRadio('yes', 'enable_strict_depot_permission');
await page.setRadio('yes', 'enable_auto_stock_accounting');
await page.setRadio('yes', 'enable_supplier_credit');
await element(by.id('algo_msh')).click();

const checkSelectAlgo1 = element.all(by.model('StockSettingsCtrl.settings.average_consumption_algo')).get(0);
const checkSelectAlgo2 = element.all(by.model('StockSettingsCtrl.settings.average_consumption_algo')).get(1);
const checkSelectAlgo3 = element.all(by.model('StockSettingsCtrl.settings.average_consumption_algo')).get(2);
const checkSelectAlgoMsh = element.all(by.model('StockSettingsCtrl.settings.average_consumption_algo')).get(3);
await element(by.id('algo_msh')).click();
const checkSelectAlgoDef = element.all(by.model('StockSettingsCtrl.settings.average_consumption_algo')).get(0);
const checkSelectAlgoMsh = element.all(by.model('StockSettingsCtrl.settings.average_consumption_algo')).get(1);

expect(await checkSelectAlgo1.isSelected()).to.equal(false);
expect(await checkSelectAlgo2.isSelected()).to.equal(false);
expect(await checkSelectAlgo3.isSelected()).to.equal(false);
expect(await checkSelectAlgoDef.isSelected()).to.equal(false);
expect(await checkSelectAlgoMsh.isSelected()).to.equal(true);

// submit
Expand All @@ -46,16 +42,12 @@ function StockSettingTests() {
await page.setRadio('no', 'enable_strict_depot_permission');
await page.setRadio('no', 'enable_auto_stock_accounting');
await page.setRadio('no', 'enable_supplier_credit');
await element(by.id('algo3')).click();

const checkSelectAlgo1 = element.all(by.model('StockSettingsCtrl.settings.average_consumption_algo')).get(0);
const checkSelectAlgo2 = element.all(by.model('StockSettingsCtrl.settings.average_consumption_algo')).get(1);
const checkSelectAlgo3 = element.all(by.model('StockSettingsCtrl.settings.average_consumption_algo')).get(2);
const checkSelectAlgoMsh = element.all(by.model('StockSettingsCtrl.settings.average_consumption_algo')).get(3);
await element(by.id('algo_def')).click();
const checkSelectAlgoDef = element.all(by.model('StockSettingsCtrl.settings.average_consumption_algo')).get(0);
const checkSelectAlgoMsh = element.all(by.model('StockSettingsCtrl.settings.average_consumption_algo')).get(1);

expect(await checkSelectAlgo1.isSelected()).to.equal(false);
expect(await checkSelectAlgo2.isSelected()).to.equal(false);
expect(await checkSelectAlgo3.isSelected()).to.equal(true);
expect(await checkSelectAlgoDef.isSelected()).to.equal(true);
expect(await checkSelectAlgoMsh.isSelected()).to.equal(false);

// submit
Expand Down
12 changes: 6 additions & 6 deletions test/integration-stock/depots.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ describe('(/depots) The depots API ', () => {
expect(res).to.be.json; // eslint-disable-line

let values = {
algo1 : 53.48,
algo_def : 53.48,
algo_msh : 53.33,
sum_days : 365,
sum_stock_day : 365,
Expand All @@ -71,14 +71,14 @@ describe('(/depots) The depots API ', () => {
head_days : 0,
};

expect(res.body.algo1, 'quinine CMM algorithm 1 is not calculated correctly').to.equal(values.algo1);
expect(res.body.algo_def, 'quinine CMM algorithm 1 is not calculated correctly').to.equal(values.algo_def);
expect(res.body.algo_msh, 'quinine CMM algorithm MSH is not calculated correctly').to.equal(values.algo_msh);

expect(res.body, 'quinine CMM not calculated correctly').to.deep.include(values);

res = await agent.get(`/depots/${principal}/inventories/${oxytocine}/cmm`);
values = {
algo1 : 74.37,
algo_def : 74.37,
algo_msh : 74.17,
sum_days : 365,
sum_stock_day : 365,
Expand All @@ -89,13 +89,13 @@ describe('(/depots) The depots API ', () => {
head_days : 0,
};

expect(res.body.algo1, 'oxytocine CMM algorithm 1 is not calculated correctly').to.equal(values.algo1);
expect(res.body.algo_def, 'oxytocine CMM algorithm 1 is not calculated correctly').to.equal(values.algo_def);
expect(res.body.algo_msh, 'oxytocine CMM algorithm MSH is not calculated correctly').to.equal(values.algo_msh);
expect(res.body, 'oxytocine CMM not calculated correctly').to.deep.include(values);

res = await agent.get(`/depots/${principal}/inventories/${ampicilline}/cmm`);
values = {
algo1 : 33.27,
algo_def : 33.27,
algo_msh : 33.15,
sum_days : 365,
sum_stock_day : 275,
Expand All @@ -106,7 +106,7 @@ describe('(/depots) The depots API ', () => {
head_days : 0,
};

expect(res.body.algo1, 'ampicilline CMM algorithm 1 is not calculated correctly').to.equal(values.algo1);
expect(res.body.algo_def, 'ampicilline CMM algorithm 1 is not calculated correctly').to.equal(values.algo_def);
expect(res.body.algo_msh, 'ampicilline CMM algorithm MSH is not calculated correctly').to.equal(values.algo_msh);
expect(res.body, 'ampicilline CMM not calculated correctly').to.deep.include(values);
} catch (err) {
Expand Down
2 changes: 1 addition & 1 deletion test/integration/depots.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ describe('(/depots) The depots API ', () => {
return agent.get(`/depots/${principal}/inventories/${QUININE}/cmm`)
.then(res => {
expect(res).to.be.json; // eslint-disable-line
expect(res.body).to.have.any.keys('algo1', 'algo2', 'algo3', 'algo_msh');
expect(res.body).to.have.any.keys('algo_def', 'algo_msh');
})
.catch(helpers.handler);
});
Expand Down

0 comments on commit 29912b5

Please sign in to comment.