2 **********************************************************************
4 * Description: Nutritional Assessment App
5 * Author: Agnibho Mondal
6 * Website: http://code.agnibho.com
7 **********************************************************************
8 Copyright (c) 2016 Agnibho Mondal
10 **********************************************************************
11 This file is part of DietSurvey.
13 DietSurvey is free software: you can redistribute it and/or modify
14 it under the terms of the GNU General Public License as published by
15 the Free Software Foundation, either version 3 of the License, or
16 (at your option) any later version.
18 DietSurvey is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 GNU General Public License for more details.
23 You should have received a copy of the GNU General Public License
24 along with DietSurvey. If not, see <http://www.gnu.org/licenses/>.
25 **********************************************************************
28 <div v-if="calcVal" class="panel panel-default">
29 <div class="panel-body">
31 <div class="panel panel-info">
32 <div class="panel-heading">
33 <div class="panel-title"><h3>Nutritional Requirements</h3></div>
35 <div class="panel-body">
38 <tr><th>Member</th><th>Energy</th><th>Protein</th><th>Iron</th><th>Vitamin A</th><th>Thiamine</th><th>Riboflavin</th><th>Vitamin C</th></tr>
41 <tr v-for="i in calcVal.req.list">
42 <td>{{i.name}}</td><td>{{i.energy|dec2}}</td><td>{{i.protein|dec2}}</td><td>{{i.iron|dec2}}</td><td>{{i.vitA|dec2}}</td><td>{{i.thiamine|dec2}}</td><td>{{i.riboflavin|dec2}}</td><td>{{i.vitC|dec2}}</td>
46 <tr><th>Total</th><th>{{calcVal.req.total.energy|dec2}}</th><th>{{calcVal.req.total.protein|dec2}}</th><th>{{calcVal.req.total.iron|dec2}}</th><th>{{calcVal.req.total.vitA|dec2}}</th><th>{{calcVal.req.total.thiamine|dec2}}</th><th>{{calcVal.req.total.riboflavin|dec2}}</th><th>{{calcVal.req.total.vitC|dec2}}</th></tr>
52 <div class="panel panel-info">
53 <div class="panel-heading">
54 <div class="panel-title"><h3>Nutritional Value of Consumed Foods</h3></div>
56 <div class="panel-body">
59 <tr><th>Food</th><th>Energy</th><th>Protein</th><th>Iron</th><th>Vitamin A</th><th>Thiamine</th><th>Riboflavin</th><th>Vitamin C</th></tr>
62 <tr v-for="i in calcVal.intk.list">
63 <td>{{i.name}}</td><td>{{i.energy|dec2}}</td><td>{{i.protein|dec2}}</td><td>{{i.iron|dec2}}</td><td>{{i.vitA|dec2}}</td><td>{{i.thiamine|dec2}}</td><td>{{i.riboflavin|dec2}}</td><td>{{i.vitC|dec2}}</td>
67 <tr><th>Total</th><th>{{calcVal.intk.total.energy|dec2}}</th><th>{{calcVal.intk.total.protein|dec2}}</th><th>{{calcVal.intk.total.iron|dec2}}</th><th>{{calcVal.intk.total.vitA|dec2}}</th><th>{{calcVal.intk.total.thiamine|dec2}}</th><th>{{calcVal.intk.total.riboflavin|dec2}}</th><th>{{calcVal.intk.total.vitC|dec2}}</th></tr>
73 <div class="panel panel-info">
74 <div class="panel-heading">
75 <div class="panel-title"><h3>Requirement vs Intake Comparison</h3></div>
77 <div class="panel-body">
79 <thead><tr><th>Nutrient</th><th>Total Requirement</th><th>Total Intake</th><th>Excess /Deficiency</th></tr></thead>
81 <tr><td>Energy</td><td>{{calcVal.req.total.energy|dec2}}</td><td>{{calcVal.intk.total.energy|dec2}}</td><td>{{calcVal.comp.energy[0]|cmp(2)}}</td></tr>
82 <tr><td>Protein</td><td>{{calcVal.req.total.protein|dec2}}</td><td>{{calcVal.intk.total.protein|dec2}}</td><td>{{calcVal.comp.protein[0]|cmp(2)}}</td></tr>
83 <tr><td>Iron</td><td>{{calcVal.req.total.iron|dec2}}</td><td>{{calcVal.intk.total.iron|dec2}}</td><td>{{calcVal.comp.iron[0]|cmp(2)}}</td></tr>
84 <tr><td>Vitamin A</td><td>{{calcVal.req.total.vitA|dec2}}</td><td>{{calcVal.intk.total.vitA|dec2}}</td><td>{{calcVal.comp.vitA[0]|cmp(2)}}</td></tr>
85 <tr><td>Thiamine</td><td>{{calcVal.req.total.thiamine|dec2}}</td><td>{{calcVal.intk.total.thiamine|dec2}}</td><td>{{calcVal.comp.thiamine[0]|cmp(2)}}</td></tr>
86 <tr><td>Riboflavin</td><td>{{calcVal.req.total.riboflavin|dec2}}</td><td>{{calcVal.intk.total.riboflavin|dec2}}</td><td>{{calcVal.comp.riboflavin[0]|cmp(2)}}</td></tr>
87 <tr><td>Vitamin C</td><td>{{calcVal.req.total.vitC|dec2}}</td><td>{{calcVal.intk.total.vitC|dec2}}</td><td>{{calcVal.comp.vitC[0]|cmp(2)}}</td></tr>
92 <div class="panel panel-info">
93 <div class="panel-heading">
94 <div class="panel-title"><h3>Summary</h3></div>
96 <div class="panel-body">
97 <ul class="list-group col-md-offset-4 col-md-4">
98 <li class="list-group-item" v-bind:class="colorCls(calcVal.comp.energy[0])">Energy {{calcVal.comp.energy[0]|cmp(1)}} is {{calcVal.comp.energy[1]|cmp}}%</li>
99 <li class="list-group-item" v-bind:class="colorCls(calcVal.comp.protein[0])">Protein {{calcVal.comp.protein[0]|cmp(1)}} is {{calcVal.comp.protein[1]|cmp}}%</li>
100 <li class="list-group-item" v-bind:class="colorCls(calcVal.comp.iron[0])">Iron {{calcVal.comp.iron[0]|cmp(1)}} is {{calcVal.comp.iron[1]|cmp}}%</li>
101 <li class="list-group-item" v-bind:class="colorCls(calcVal.comp.vitA[0])">Vitamin A {{calcVal.comp.vitA[0]|cmp(1)}} is {{calcVal.comp.vitA[1]|cmp}}%</li>
102 <li class="list-group-item" v-bind:class="colorCls(calcVal.comp.thiamine[0])">Thiamine {{calcVal.comp.thiamine[0]|cmp(1)}} is {{calcVal.comp.thiamine[1]|cmp}}%</li>
103 <li class="list-group-item" v-bind:class="colorCls(calcVal.comp.riboflavin[0])">Riboflavin {{calcVal.comp.riboflavin[0]|cmp(1)}} is {{calcVal.comp.riboflavin[1]|cmp}}%</li>
104 <li class="list-group-item" v-bind:class="colorCls(calcVal.comp.vitC[0])">Vitamin C {{calcVal.comp.vitC[0]|cmp(1)}} is {{calcVal.comp.vitC[1]|cmp}}%</li>
116 props:["dataObj", "dataRef"],
119 return Math.round(v*100)/100;
123 if(v<0) return "deficit";
124 else return "excess";
126 if(v<0) return "Deficit by "+Math.abs(Math.round(v*100)/100);
127 else return "Excess by "+Math.abs(Math.round(v*100)/100);
130 return Math.abs(Math.round(v*100)/100);
135 colorCls: function(v){
136 if (v<0) return {"list-group-item-danger": true};
137 else return {"list-group-item-success": true};
142 var rda=this.dataRef.rda;
143 var val=this.dataRef.food;
145 // Requirement Calculation
149 for(var i=0; i<this.dataObj.family.length; i++){
150 var mem=this.dataObj.family[i];
152 // Retrieve individual rda
156 if(mem.state=="preg"){
157 buff=rda.filter(function(d){
158 return d.subject=="pregnant";
161 else if(mem.state=="lact-6"){
162 buff=rda.filter(function(d){
163 return d.subject=="lactating_below6";
166 else if(mem.state=="lact+6"){
167 buff=rda.filter(function(d){
168 return d.subject=="lactating_above6";
171 else if(mem.state=="npnl"){
172 if(mem.work=="sedentary"){
173 buff=rda.filter(function(d){
174 return d.subject=="female_sedentary";
177 else if(mem.work=="moderate"){
178 buff=rda.filter(function(d){
179 return d.subject=="female_moderate";
182 else if(mem.work=="heavy"){
183 buff=rda.filter(function(d){
184 return d.subject=="female_heavy";
192 else if(mem.age<18 && mem.age>0){
193 buff=rda.filter(function(d){
194 return d.subject=="female_"+mem.age+"y";
197 else if(mem.month>=9){
198 buff=rda.filter(function(d){
199 return d.subject=="infant_9m-12m";
202 else if(mem.month>=6){
203 buff=rda.filter(function(d){
204 return d.subject=="infant_6m-9m";
207 else if(mem.month>=0){
211 buff=rda.filter(function(d){
212 return d.subject=="infant_0m-6m";
220 else if(mem.sex=="m"){
222 if(mem.work=="sedentary"){
223 buff=rda.filter(function(d){
224 return d.subject=="male_sedentary";
227 else if(mem.work=="moderate"){
228 buff=rda.filter(function(d){
229 return d.subject=="male_moderate";
232 else if(mem.work=="heavy"){
233 buff=rda.filter(function(d){
234 return d.subject=="male_heavy";
241 else if(mem.age<18 && mem.age>0){
242 buff=rda.filter(function(d){
243 return d.subject=="male_"+mem.age+"y";
246 else if(mem.month>=9){
247 buff=rda.filter(function(d){
248 return d.subject=="infant_9m-12m";
251 else if(mem.month>=6){
252 buff=rda.filter(function(d){
253 return d.subject=="infant_6m-9m";
256 else if(mem.month>=0){
260 buff=rda.filter(function(d){
261 return d.subject=="infant_0m-6m";
272 root.req.list.push(buff);
274 root.req.total.energy=0;
275 root.req.total.protein=0;
276 root.req.total.iron=0;
277 root.req.total.vitA=0;
278 root.req.total.thiamine=0;
279 root.req.total.riboflavin=0;
280 root.req.total.vitC=0;
281 for(var i=0; i<root.req.list.length; i++){
282 root.req.total.energy = +root.req.total.energy + +root.req.list[i].energy;
283 root.req.total.protein = +root.req.total.protein + +root.req.list[i].protein;
284 root.req.total.iron = +root.req.total.iron + +root.req.list[i].iron;
285 root.req.total.vitA = +root.req.total.vitA + +root.req.list[i].vitA;
286 root.req.total.thiamine = +root.req.total.thiamine + +root.req.list[i].thiamine;
287 root.req.total.riboflavin = +root.req.total.riboflavin + +root.req.list[i].riboflavin;
288 root.req.total.vitC = +root.req.total.vitC + +root.req.list[i].vitC;
290 // Intake Calculation
294 for(var i=0; i<this.dataObj.food.length; i++){
295 var food=this.dataObj.food[i];
297 if(food.name!=="" && food.amount!=="" && food.amount>=0){
299 buff.energy=val.filter(function(d){
300 return d.name==buff.name;
301 })[0].energy*food.amount/100;
302 buff.protein=val.filter(function(d){
303 return d.name==buff.name;
304 })[0].protein*food.amount/100;
305 buff.iron=val.filter(function(d){
306 return d.name==buff.name;
307 })[0].iron*food.amount/100;
308 buff.vitA=val.filter(function(d){
309 return d.name==buff.name;
310 })[0].vitA*food.amount/100;
311 buff.thiamine=val.filter(function(d){
312 return d.name==buff.name;
313 })[0].thiamine*food.amount/100;
314 buff.riboflavin=val.filter(function(d){
315 return d.name==buff.name;
316 })[0].riboflavin*food.amount/100;
317 buff.vitC=val.filter(function(d){
318 return d.name==buff.name;
319 })[0].vitC*food.amount/100;
320 root.intk.list.push(buff);
327 root.intk.total.energy=0;
328 root.intk.total.protein=0;
329 root.intk.total.iron=0;
330 root.intk.total.vitA=0;
331 root.intk.total.thiamine=0;
332 root.intk.total.riboflavin=0;
333 root.intk.total.vitC=0;
334 for(var i=0; i<root.intk.list.length; i++){
335 root.intk.total.energy = +root.intk.total.energy + +root.intk.list[i].energy;
336 root.intk.total.protein = +root.intk.total.protein + +root.intk.list[i].protein;
337 root.intk.total.iron = +root.intk.total.iron + +root.intk.list[i].iron;
338 root.intk.total.vitA = +root.intk.total.vitA + +root.intk.list[i].vitA;
339 root.intk.total.thiamine = +root.intk.total.thiamine + +root.intk.list[i].thiamine;
340 root.intk.total.riboflavin = +root.intk.total.riboflavin + +root.intk.list[i].riboflavin;
341 root.intk.total.vitC = +root.intk.total.vitC + +root.intk.list[i].vitC;
345 root.comp.energy = [ +root.intk.total.energy - +root.req.total.energy , (+root.intk.total.energy - +root.req.total.energy)*100/(+root.req.total.energy)];
346 root.comp.protein = [ +root.intk.total.protein - +root.req.total.protein , (+root.intk.total.protein - +root.req.total.protein)*100/(+root.req.total.protein)];
347 root.comp.iron = [ +root.intk.total.iron - +root.req.total.iron , (+root.intk.total.iron - +root.req.total.iron)*100/(+root.req.total.iron)];
348 root.comp.vitA = [ +root.intk.total.vitA - +root.req.total.vitA , (+root.intk.total.vitA - +root.req.total.vitA)*100/(+root.req.total.vitA)];
349 root.comp.thiamine = [ +root.intk.total.thiamine - +root.req.total.thiamine , (+root.intk.total.thiamine - +root.req.total.thiamine)*100/(+root.req.total.thiamine)];
350 root.comp.riboflavin = [ +root.intk.total.riboflavin - +root.req.total.riboflavin , (+root.intk.total.riboflavin - +root.req.total.riboflavin)*100/(+root.req.total.riboflavin)];
351 root.comp.vitC = [ +root.intk.total.vitC - +root.req.total.vitC , (+root.intk.total.vitC - +root.req.total.vitC)*100/(+root.req.total.vitC)];