Skip to content

Commit

Permalink
Fix age calc
Browse files Browse the repository at this point in the history
  • Loading branch information
sapk committed Jul 15, 2016
1 parent b4ae09e commit cabf80a
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 23 deletions.
2 changes: 1 addition & 1 deletion config.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version='1.0' encoding='utf-8'?>
<widget id="org.adentes.sofia" version="0.1.1" android-versionCode="201101" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
<widget id="org.adentes.sofia" version="0.1.2" android-versionCode="201201" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
<name>SOFIA</name>
<description>
Suivi Opérationnel des Fiches d'Intervention par Applicatif
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "sofia",
"description": "Suivi Opérationnel des Fiches d'Intervention par Applicatif",
"version": "0.1.1",
"version": "0.1.2",
"private": true,
"authors": [
{
Expand Down
20 changes: 1 addition & 19 deletions www/assets/js/page/fiche.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,25 +39,7 @@ define({
computed: {
_patient_age: function () {
//return moment(this.fiche.patient.birthdate).fromNow(true);
var d = moment(this.fiche.patient.birthdate);
var local = moment.localeData();

var years = moment().diff(d, 'years');
if(years === 0){
var months = moment().diff(d, 'month') //Getting month
if(months === 0){
var days = moment().diff(d, 'day') //Getting day
return days+local["_relativeTime"].dd.substr(2);
}else if(months === 1){
return local["_relativeTime"].M; //1month
}else{
return months+local["_relativeTime"].MM.substr(2);
}
}else if(years === 1){
return local["_relativeTime"].y;
}else{
return years+local["_relativeTime"].yy.substr(2);
}
return S.tool.calAge(moment(this.fiche.patient.birthdate));
},
_last_update: function () { //Get the timestamp of the last update and format it to be shown
return (this.fiche.events.length>0)? moment(this.fiche.events[this.fiche.events.length-1].timestamp).fromNow():"" ;//TODO better order and get the most new timestamp other than the last el in array
Expand Down
2 changes: 1 addition & 1 deletion www/assets/js/sofia.db.js
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ S.db.fiches = {
value.doc.last_update_is_old = m.add(S.config.fiche.update_timeout, 'minutes').isBefore();
var d = moment(value.doc.patient.birthdate);
value.doc.patient.age = moment().diff(d, 'years');
value.doc.patient.age_formatted = d.fromNow(true);
value.doc.patient.age_formatted = S.tool.calAge(d);
});
ret.lang = S.lang;
deferred.resolve(ret);
Expand Down
23 changes: 22 additions & 1 deletion www/assets/js/sofia.tool.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* global $, dialogPolyfill */
/* global $, dialogPolyfill, moment */
'use strict';

var S = S || {};
Expand All @@ -18,6 +18,27 @@ S.tool = {
capitalizeFirstLetter: function (string) {
return string.charAt(0).toUpperCase() + string.slice(1);
},
calAge: function (d) {
var now = moment();
var local = moment.localeData();

var years = now.diff(d, 'years');
if(years === 0){
var months = now.diff(d, 'month') //Getting month
if(months === 0){
var days = now.diff(d, 'day') //Getting day
return days+local["_relativeTime"].dd.substr(2);
}else if(months === 1){
return local["_relativeTime"].M; //1month
}else{
return months+local["_relativeTime"].MM.substr(2);
}
}else if(years === 1){
return local["_relativeTime"].y;
}else{
return years+local["_relativeTime"].yy.substr(2);
}
},
isMenuEntry: function (path) {
//console.log(path, typeof path);
if (typeof path === "object") {
Expand Down

0 comments on commit cabf80a

Please sign in to comment.