angular-nav-thresholds
Advanced tools
Comparing version 2.6.0 to 2.7.0
@@ -217,3 +217,3 @@ (function (angular) { | ||
var ThresholdsService = function () { | ||
function ThresholdsService($q, smartId, lgasService, statesService) { | ||
function ThresholdsService($q, smartId, lgasService, statesService, locationService) { | ||
_classCallCheck(this, ThresholdsService); | ||
@@ -225,2 +225,3 @@ | ||
this.statesService = statesService; | ||
this.locationService = locationService; | ||
} | ||
@@ -333,15 +334,27 @@ | ||
var id = _this.smartId.idify(scLocation, locationIdPattern); | ||
index[id] = { date: stockCount.date }; | ||
var id = void 0; | ||
if (scLocation.lga) { | ||
if (!promises.lga) { | ||
promises.lga = _this.lgasService.list(); | ||
if (scLocation.national) { | ||
id = _this.smartId.idify(scLocation, 'national:?'); | ||
index[id] = { date: stockCount.date }; | ||
index[id].type = 'national'; | ||
if (!promises.national) { | ||
promises.national = _this.locationService.get('national'); | ||
} | ||
index[id].type = 'lga'; | ||
} else if (scLocation.state) { | ||
if (!promises.state) { | ||
promises.state = _this.statesService.list(); | ||
} else { | ||
id = _this.smartId.idify(scLocation, locationIdPattern); | ||
index[id] = { date: stockCount.date }; | ||
if (scLocation.lga) { | ||
if (!promises.lga) { | ||
promises.lga = _this.lgasService.list(); | ||
} | ||
index[id].type = 'lga'; | ||
} else if (scLocation.state) { | ||
if (!promises.state) { | ||
promises.state = _this.statesService.list(); | ||
} | ||
index[id].type = 'state'; | ||
} | ||
index[id].type = 'state'; | ||
} | ||
@@ -355,3 +368,8 @@ | ||
var item = index[key]; | ||
var location = find(promisesRes[item.type], isId.bind(null, key)); | ||
var location = void 0; | ||
if (item.type === 'national') { | ||
location = promisesRes[item.type]; | ||
} else { | ||
location = find(promisesRes[item.type], isId.bind(null, key)); | ||
} | ||
item.thresholds = _this.calculateThresholds(location, item, products, null, productCoefficients); | ||
@@ -371,3 +389,3 @@ delete item.type; | ||
ThresholdsService.$inject = ['$q', 'smartId', 'lgasService', 'statesService']; | ||
ThresholdsService.$inject = ['$q', 'smartId', 'lgasService', 'statesService', 'locationService']; | ||
@@ -374,0 +392,0 @@ angular.module('angularNavThresholds', ['angularNavData', 'ngSmartId']).service('thresholdsService', ThresholdsService); |
@@ -1,1 +0,1 @@ | ||
!function(e){"use strict";function t(e,t){for(var r=0;r<e.length;r++)if(t(e[r]))return e[r]}function r(e){console&&console.warn("angular-nav-thresholds: "+e)}function o(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}e="default"in e?e.default:e;var a=[{version:1,date:"2016-01-01",coefficients:{"product:2-reconst-syg":{wastage:1.1,coverage:.87},"product:5-reconst-syg":{wastage:1.1,coverage:.87},"product:ad-syg":{wastage:1.05,coverage:.87},"product:bcg":{wastage:2,coverage:.9,doses:1},"product:bcg-syg":{coverage:.87},"product:diluent-bcg":{},"product:diluent-mv":{},"product:diluent-yf":{},"product:hep-b":{wastage:1.3333333333333333,coverage:.9,doses:1},"product:hpv":{wastage:1.1,coverage:.9,doses:2},"product:ipv":{wastage:1.05,coverage:.87,doses:1},"product:mv":{wastage:1.4285714285714286,coverage:.9,doses:1},"product:opv":{wastage:1.3333333333333333,coverage:.9,doses:4},"product:pcv":{wastage:1.05,coverage:.87,doses:3},"product:penta":{wastage:1.3333333333333333,coverage:.87,doses:3},"product:rota":{wastage:1.05,coverage:.87,doses:3},"product:safety-boxes":{wastage:1.05},"product:td":{wastage:1.3333333333333333,coverage:.87,doses:2},"product:yf":{wastage:1.4285714285714286,coverage:.9,doses:1}}},{version:2,date:"2017-01-01",coefficients:{"product:2-reconst-syg":{wastage:1.1,coverage:.87},"product:5-reconst-syg":{wastage:1.1,coverage:.87},"product:ad-syg":{wastage:1.05,coverage:.87},"product:bcg":{wastage:2,coverage:.94,doses:1},"product:bcg-syg":{coverage:.87},"product:diluent-bcg":{},"product:diluent-mv":{},"product:diluent-yf":{},"product:hep-b":{wastage:1.3333333333,coverage:.82,doses:1},"product:hpv":{wastage:1.1,coverage:.9,doses:2},"product:ipv":{wastage:1.25,coverage:.94,doses:1},"product:mv":{wastage:1.4285714285714286,coverage:.95,doses:1},"product:opv":{wastage:1.3333333333333333,coverage:.94,doses:4},"product:pcv":{wastage:1.0526315789,coverage:.94,doses:3},"product:penta":{wastage:1.3333333333333333,coverage:.94,doses:3},"product:rota":{wastage:1.05,coverage:.87,doses:3},"product:safety-boxes":{wastage:1.05},"product:td":{wastage:1.3333333333333333,coverage:.85,doses:2},"product:yf":{wastage:1.4285714285714286,coverage:.95,doses:1}}}],n={versions:a},s={versionDateFormat:"YYYY-MM-DD"},c={"product:bcg":"regular","product:mv":"regular","product:yf":"regular","product:opv":"regular","product:td":"regular","product:penta":"regular","product:hep-b":"regular","product:pcv":"regular","product:ipv":"regular","product:rota":"regular","product:hpv":"regular","product:ad-syg":"adSyg","product:bcg-syg":"bcg","product:5-reconst-syg":"fiveReconst","product:2-reconst-syg":"twoReconst","product:safety-boxes":"safetyBoxes","product:diluent-bcg":"diluentBcg","product:diluent-yf":"diluentYf","product:diluent-mv":"diluentMv"},u={};u.regular=function(e,t,r){return r*t.doses*t.coverage*t.wastage},u.adSyg=function(e){return e["product:penta"]+e["product:mv"]+e["product:yf"]+e["product:hep-b"]+e["product:td"]+e["product:pcv"]+e["product:ipv"]+e["product:hpv"]},u.bcg=function(e){return e["product:bcg"]},u.fiveReconst=function(e,t){return(e["product:mv"]+e["product:yf"])/10*t.wastage},u.twoReconst=function(e,t){return e["product:bcg"]/20*t.wastage},u.safetyBoxes=function(e,t){return(e["product:ad-syg"]+e["product:bcg-syg"]+e["product:5-reconst-syg"]+e["product:2-reconst-syg"])/100*t.wastage},u.diluentBcg=function(e){return e["product:bcg"]},u.diluentYf=function(e){return e["product:yf"]},u.diluentMv=function(e){return e["product:mv"]};var i=function(e,t,r,o){var a=t[o],n=e[o];return r[o]=0,void 0!==n&&a&&(r[o]=u[c[o]](r,a,n/4)),r},d=function(e,t){return Object.keys(c).reduce(i.bind(null,e,t),{})},g=function(e,t){var r=moment().isoWeekYear(e.year).isoWeek(e.week).isoWeekday(1).startOf("day"),o=moment(t.date,s.versionDateFormat).startOf("isoWeek").startOf("day");return r.isSameOrAfter(o)},l=function(e,r){var o=e.slice(0).reverse(),a=t(o,g.bind(null,r));return a?a:e[0]},p=function(e,t){if(!(e&&e.versions&&e.versions.length))throw new Error("missing productCoefficients or productCoefficients.versions");var r=l(e.versions,t);if(!r||!r.coefficients)throw new Error("cannot find version of coefficients for date "+t);return r.coefficients},v=function(e,t){if(!e.plans||!e.plans.length)throw new Error("missing plans on location "+e._id);var r=l(e.plans,t);if(!r||!r.weeksOfStock)throw new Error("cannot find version of weeksOfStock for location "+e._id+" and date "+t);return r.weeksOfStock},f=function(e,t){if(e.targetPopulations&&e.targetPopulations.length){var r=l(e.targetPopulations,t);return{version:r.version,monthlyTargetPopulations:r&&r.monthlyTargetPopulations}}return e.targetPopulation&&Object.keys(e.targetPopulation).length?{version:1,monthlyTargetPopulations:e.targetPopulation}:{version:1}},w=function(e,t){if(!e.allocations||!e.allocations.length)throw new Error("missing allocations on location "+e._id);var r=l(e.allocations,t);if(!r||!r.weeklyLevels)throw new Error("cannot find version of weeklyLevels for location "+e._id+" and date "+t);return r.weeklyLevels},y=function(e,t,r){var o=v(e,r),a=f(e,r),n=a.version,s=a.monthlyTargetPopulations;return 1===n?{weeklyLevels:w(e,r),weeksOfStock:o,monthlyTargetPopulations:s}:{weeklyLevels:d(s,p(t,r)),weeksOfStock:o,monthlyTargetPopulations:s}},h=function(){function e(e,t){for(var r=0;r<t.length;r++){var o=t[r];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,o.key,o)}}return function(t,r,o){return r&&e(t.prototype,r),o&&e(t,o),t}}(),m=function(){function e(t,r,a,n){o(this,e),this.$q=t,this.smartId=r,this.lgasService=a,this.statesService=n}return h(e,[{key:"calculateThresholds",value:function(e,t,o){var a=arguments.length>3&&void 0!==arguments[3]?arguments[3]:{},s=arguments.length>4&&void 0!==arguments[4]?arguments[4]:n;if(!t){return r("missing mandatory param stock count for location "+(e&&e._id?e._id:"with unknown id"))}if(!t.date)return r("missing date on stock count "+t._id);if(!e){return r("missing mandatory param location for stock count "+(t&&t._id?t._id:"with unknown id"))}if(!e.level)return r("missing level on location "+e._id);if(!o||!o.length)return r("missing mandatory param products");var c=void 0;try{c=y(e,s,t.date)}catch(e){return void r(e.message)}var u=c,i=u.weeksOfStock,d=u.weeklyLevels,g=u.monthlyTargetPopulations;return o.reduce(function(t,r){var o=r._id,n=d[o],s=20;return r&&r.presentation&&(s=parseInt(r.presentation,10)),t[o]=Object.keys(i).reduce(function(t,r){var c=n*i[r],u=Math.ceil(c/s)*s;return t[r]=u,"zone"===e.level&&a[o]&&(t[r]+=a[o]),t},{}),t[o].weeklyLevel=n,g&&(t[o].targetPopulation=g[o]),t},{})}},{key:"getThresholdsFor",value:function(e,r){var o=this,a=arguments.length>2&&void 0!==arguments[2]?arguments[2]:n,s=function(e,t){return t._id===e},c={},u={};c=e.reduce(function(e,t){var r=t.location;if(!r)return e;var a=o.smartId.idify(r,"zone:?state:?lga");return e[a]={date:t.date},r.lga?(u.lga||(u.lga=o.lgasService.list()),e[a].type="lga"):r.state&&(u.state||(u.state=o.statesService.list()),e[a].type="state"),e},{});var i=function(e){return Object.keys(c).forEach(function(n){var u=c[n],i=t(e[u.type],s.bind(null,n));u.thresholds=o.calculateThresholds(i,u,r,null,a),delete u.type}),c};return this.$q.all(u).then(i)}}]),e}();m.$inject=["$q","smartId","lgasService","statesService"],e.module("angularNavThresholds",["angularNavData","ngSmartId"]).service("thresholdsService",m)}(angular); | ||
!function(e){"use strict";function t(e,t){for(var o=0;o<e.length;o++)if(t(e[o]))return e[o]}function o(e){console&&console.warn("angular-nav-thresholds: "+e)}function r(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}e="default"in e?e.default:e;var a=[{version:1,date:"2016-01-01",coefficients:{"product:2-reconst-syg":{wastage:1.1,coverage:.87},"product:5-reconst-syg":{wastage:1.1,coverage:.87},"product:ad-syg":{wastage:1.05,coverage:.87},"product:bcg":{wastage:2,coverage:.9,doses:1},"product:bcg-syg":{coverage:.87},"product:diluent-bcg":{},"product:diluent-mv":{},"product:diluent-yf":{},"product:hep-b":{wastage:1.3333333333333333,coverage:.9,doses:1},"product:hpv":{wastage:1.1,coverage:.9,doses:2},"product:ipv":{wastage:1.05,coverage:.87,doses:1},"product:mv":{wastage:1.4285714285714286,coverage:.9,doses:1},"product:opv":{wastage:1.3333333333333333,coverage:.9,doses:4},"product:pcv":{wastage:1.05,coverage:.87,doses:3},"product:penta":{wastage:1.3333333333333333,coverage:.87,doses:3},"product:rota":{wastage:1.05,coverage:.87,doses:3},"product:safety-boxes":{wastage:1.05},"product:td":{wastage:1.3333333333333333,coverage:.87,doses:2},"product:yf":{wastage:1.4285714285714286,coverage:.9,doses:1}}},{version:2,date:"2017-01-01",coefficients:{"product:2-reconst-syg":{wastage:1.1,coverage:.87},"product:5-reconst-syg":{wastage:1.1,coverage:.87},"product:ad-syg":{wastage:1.05,coverage:.87},"product:bcg":{wastage:2,coverage:.94,doses:1},"product:bcg-syg":{coverage:.87},"product:diluent-bcg":{},"product:diluent-mv":{},"product:diluent-yf":{},"product:hep-b":{wastage:1.3333333333,coverage:.82,doses:1},"product:hpv":{wastage:1.1,coverage:.9,doses:2},"product:ipv":{wastage:1.25,coverage:.94,doses:1},"product:mv":{wastage:1.4285714285714286,coverage:.95,doses:1},"product:opv":{wastage:1.3333333333333333,coverage:.94,doses:4},"product:pcv":{wastage:1.0526315789,coverage:.94,doses:3},"product:penta":{wastage:1.3333333333333333,coverage:.94,doses:3},"product:rota":{wastage:1.05,coverage:.87,doses:3},"product:safety-boxes":{wastage:1.05},"product:td":{wastage:1.3333333333333333,coverage:.85,doses:2},"product:yf":{wastage:1.4285714285714286,coverage:.95,doses:1}}}],n={versions:a},s={versionDateFormat:"YYYY-MM-DD"},c={"product:bcg":"regular","product:mv":"regular","product:yf":"regular","product:opv":"regular","product:td":"regular","product:penta":"regular","product:hep-b":"regular","product:pcv":"regular","product:ipv":"regular","product:rota":"regular","product:hpv":"regular","product:ad-syg":"adSyg","product:bcg-syg":"bcg","product:5-reconst-syg":"fiveReconst","product:2-reconst-syg":"twoReconst","product:safety-boxes":"safetyBoxes","product:diluent-bcg":"diluentBcg","product:diluent-yf":"diluentYf","product:diluent-mv":"diluentMv"},i={};i.regular=function(e,t,o){return o*t.doses*t.coverage*t.wastage},i.adSyg=function(e){return e["product:penta"]+e["product:mv"]+e["product:yf"]+e["product:hep-b"]+e["product:td"]+e["product:pcv"]+e["product:ipv"]+e["product:hpv"]},i.bcg=function(e){return e["product:bcg"]},i.fiveReconst=function(e,t){return(e["product:mv"]+e["product:yf"])/10*t.wastage},i.twoReconst=function(e,t){return e["product:bcg"]/20*t.wastage},i.safetyBoxes=function(e,t){return(e["product:ad-syg"]+e["product:bcg-syg"]+e["product:5-reconst-syg"]+e["product:2-reconst-syg"])/100*t.wastage},i.diluentBcg=function(e){return e["product:bcg"]},i.diluentYf=function(e){return e["product:yf"]},i.diluentMv=function(e){return e["product:mv"]};var u=function(e,t,o,r){var a=t[r],n=e[r];return o[r]=0,void 0!==n&&a&&(o[r]=i[c[r]](o,a,n/4)),o},d=function(e,t){return Object.keys(c).reduce(u.bind(null,e,t),{})},g=function(e,t){var o=moment().isoWeekYear(e.year).isoWeek(e.week).isoWeekday(1).startOf("day"),r=moment(t.date,s.versionDateFormat).startOf("isoWeek").startOf("day");return o.isSameOrAfter(r)},l=function(e,o){var r=e.slice(0).reverse(),a=t(r,g.bind(null,o));return a?a:e[0]},p=function(e,t){if(!(e&&e.versions&&e.versions.length))throw new Error("missing productCoefficients or productCoefficients.versions");var o=l(e.versions,t);if(!o||!o.coefficients)throw new Error("cannot find version of coefficients for date "+t);return o.coefficients},v=function(e,t){if(!e.plans||!e.plans.length)throw new Error("missing plans on location "+e._id);var o=l(e.plans,t);if(!o||!o.weeksOfStock)throw new Error("cannot find version of weeksOfStock for location "+e._id+" and date "+t);return o.weeksOfStock},f=function(e,t){if(e.targetPopulations&&e.targetPopulations.length){var o=l(e.targetPopulations,t);return{version:o.version,monthlyTargetPopulations:o&&o.monthlyTargetPopulations}}return e.targetPopulation&&Object.keys(e.targetPopulation).length?{version:1,monthlyTargetPopulations:e.targetPopulation}:{version:1}},y=function(e,t){if(!e.allocations||!e.allocations.length)throw new Error("missing allocations on location "+e._id);var o=l(e.allocations,t);if(!o||!o.weeklyLevels)throw new Error("cannot find version of weeklyLevels for location "+e._id+" and date "+t);return o.weeklyLevels},w=function(e,t,o){var r=v(e,o),a=f(e,o),n=a.version,s=a.monthlyTargetPopulations;return 1===n?{weeklyLevels:y(e,o),weeksOfStock:r,monthlyTargetPopulations:s}:{weeklyLevels:d(s,p(t,o)),weeksOfStock:r,monthlyTargetPopulations:s}},h=function(){function e(e,t){for(var o=0;o<t.length;o++){var r=t[o];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,o,r){return o&&e(t.prototype,o),r&&e(t,r),t}}(),m=function(){function e(t,o,a,n,s){r(this,e),this.$q=t,this.smartId=o,this.lgasService=a,this.statesService=n,this.locationService=s}return h(e,[{key:"calculateThresholds",value:function(e,t,r){var a=arguments.length>3&&void 0!==arguments[3]?arguments[3]:{},s=arguments.length>4&&void 0!==arguments[4]?arguments[4]:n;if(!t){return o("missing mandatory param stock count for location "+(e&&e._id?e._id:"with unknown id"))}if(!t.date)return o("missing date on stock count "+t._id);if(!e){return o("missing mandatory param location for stock count "+(t&&t._id?t._id:"with unknown id"))}if(!e.level)return o("missing level on location "+e._id);if(!r||!r.length)return o("missing mandatory param products");var c=void 0;try{c=w(e,s,t.date)}catch(e){return void o(e.message)}var i=c,u=i.weeksOfStock,d=i.weeklyLevels,g=i.monthlyTargetPopulations;return r.reduce(function(t,o){var r=o._id,n=d[r],s=20;return o&&o.presentation&&(s=parseInt(o.presentation,10)),t[r]=Object.keys(u).reduce(function(t,o){var c=n*u[o],i=Math.ceil(c/s)*s;return t[o]=i,"zone"===e.level&&a[r]&&(t[o]+=a[r]),t},{}),t[r].weeklyLevel=n,g&&(t[r].targetPopulation=g[r]),t},{})}},{key:"getThresholdsFor",value:function(e,o){var r=this,a=arguments.length>2&&void 0!==arguments[2]?arguments[2]:n,s=function(e,t){return t._id===e},c={},i={};c=e.reduce(function(e,t){var o=t.location;if(!o)return e;var a=void 0;return o.national?(a=r.smartId.idify(o,"national:?"),e[a]={date:t.date},e[a].type="national",i.national||(i.national=r.locationService.get("national"))):(a=r.smartId.idify(o,"zone:?state:?lga"),e[a]={date:t.date},o.lga?(i.lga||(i.lga=r.lgasService.list()),e[a].type="lga"):o.state&&(i.state||(i.state=r.statesService.list()),e[a].type="state")),e},{});var u=function(e){return Object.keys(c).forEach(function(n){var i=c[n],u=void 0;u="national"===i.type?e[i.type]:t(e[i.type],s.bind(null,n)),i.thresholds=r.calculateThresholds(u,i,o,null,a),delete i.type}),c};return this.$q.all(i).then(u)}}]),e}();m.$inject=["$q","smartId","lgasService","statesService","locationService"],e.module("angularNavThresholds",["angularNavData","ngSmartId"]).service("thresholdsService",m)}(angular); |
@@ -77,3 +77,3 @@ { | ||
], | ||
"version": "2.6.0" | ||
"version": "2.7.0" | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
38919
324