Skip to content
This repository has been archived by the owner on Jul 9, 2024. It is now read-only.

Commit

Permalink
fix(participant): ageDisplay for diagnoses
Browse files Browse the repository at this point in the history
 - include leap year in year/day filter

Closes #1842
  • Loading branch information
alex-wilmer committed Mar 31, 2016
1 parent 0e7870a commit 7801e24
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 31 deletions.
6 changes: 3 additions & 3 deletions app/scripts/components/ui/string/string.filters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ module ngApp.components.ui.string {
// use `--` for null, undefined and empty string
if (original === null || original === undefined || (angular.isString(original) && original.length === 0)) {
return '--';
// return all other non-strings
// return all other non-strings
} else if (!angular.isString(original)) return original;

var humanified = "";
Expand Down Expand Up @@ -122,8 +122,8 @@ module ngApp.components.ui.string {
var daysText = gettextCatalog.getPlural(ageInDays, "day", "days");
return ageInDays + " " + daysText;
} else {
var ageInYears = Math.floor(ageInDays / 365);
var remainderDays = Math.ceil(ageInDays % 365);
var ageInYears = Math.floor(ageInDays / 365.25);
var remainderDays = Math.ceil(ageInDays % 365.25);
var yearsText = gettextCatalog.getPlural(ageInYears, "year", "years");
var daysText = gettextCatalog.getPlural(remainderDays, "day", "days");
return ageInYears + " " + yearsText + (remainderDays ? " " + remainderDays + " " + daysText : "");
Expand Down
38 changes: 21 additions & 17 deletions app/scripts/components/ui/string/tests/ageDisplay.filter.tests.js
Original file line number Diff line number Diff line change
@@ -1,30 +1,34 @@
describe("AgeDisplay Filter:", function() {
beforeEach(module("ngApp.components"));

var age = 20

it ("should display ages less than 365 days in days", inject(function ($filter) {
var age1 = 20;
expect($filter("ageDisplay")(age1)).to.equal(age1 + " days");
var age2 = 364;
expect($filter("ageDisplay")(age2)).to.equal(age2 + " days");
expect($filter("ageDisplay")(age)).to.equal(age + " days");
age = 364;
expect($filter("ageDisplay")(age)).to.equal(age + " days");
}));

it ("should display ages greather than or equal to 365 as YYys DDds", inject(function ($filter) {
var age1 = 2248;
expect($filter("ageDisplay")(age1)).to.equal("6 years 58 days");
age = 2248;
expect($filter("ageDisplay")(age)).to.equal("6 years 57 days");
age = 2249;
expect($filter("ageDisplay")(age)).to.equal("6 years 58 days");
}));

it ("should handle plurals/singulars properly", inject(function ($filter) {
var age1 = 1;
expect($filter("ageDisplay")(age1)).to.equal(age1 + " day");
var age2 = 2;
expect($filter("ageDisplay")(age2)).to.equal(age2 + " days");

var age3 = 366;
expect($filter("ageDisplay")(age3)).to.equal("1 year 1 day");
var age4 = 730;
expect($filter("ageDisplay")(age4)).to.equal("2 years");
var age5 = 731
expect($filter("ageDisplay")(age5)).to.equal("2 years 1 day");
age = 1;
expect($filter("ageDisplay")(age)).to.equal(age + " day");
age = 2;
expect($filter("ageDisplay")(age)).to.equal(age + " days");
age = 366;
expect($filter("ageDisplay")(age)).to.equal("1 year 1 day");
age = 730;
expect($filter("ageDisplay")(age)).to.equal("1 year 365 days");
age = 730.5;
expect($filter("ageDisplay")(age)).to.equal("2 years");
age = 731
expect($filter("ageDisplay")(age)).to.equal("2 years 1 day");

}));

Expand Down
12 changes: 6 additions & 6 deletions app/scripts/participant/templates/participant.html
Original file line number Diff line number Diff line change
Expand Up @@ -229,27 +229,27 @@ <h3 class="panel-title pull-left" data-translate>
</tr>
<tr>
<th scope="row" data-translate>Age at Diagnosis</th>
<td>{{ ::pc.participant.diagnoses[ $index ].age_at_diagnosis | humanify }}</td>
<td>{{ ::pc.participant.diagnoses[ $index ].age_at_diagnosis | ageDisplay }}</td>
</tr>
<tr>
<th scope="row" data-translate>Days to Birth</th>
<td>{{ ::pc.participant.diagnoses[ $index ].days_to_birth | humanify }}</td>
<td>{{ ::pc.participant.diagnoses[ $index ].days_to_birth | number }}</td>
</tr>
<tr>
<th scope="row" data-translate>Days to Death</th>
<td>{{ ::pc.participant.diagnoses[ $index ].days_to_death | humanify }}</td>
<td>{{ ::pc.participant.diagnoses[ $index ].days_to_death | number }}</td>
</tr>
<tr>
<th scope="row" data-translate>Days to Last Followup</th>
<td>{{ ::pc.participant.diagnoses[ $index ].days_to_last_follow_up | humanify }}</td>
<td>{{ ::pc.participant.diagnoses[ $index ].days_to_last_follow_up | number }}</td>
</tr>
<tr>
<th scope="row" data-translate>Days to Last Known Disease Status</th>
<td>{{ ::pc.participant.diagnoses[ $index ].days_to_last_known_disease_status | humanify }}</td>
<td>{{ ::pc.participant.diagnoses[ $index ].days_to_last_known_disease_status | number }}</td>
</tr>
<tr>
<th scope="row" data-translate>Days to Recurrence</th>
<td>{{ ::pc.participant.diagnoses[ $index ].days_to_recurrence | humanify }}</td>
<td>{{ ::pc.participant.diagnoses[ $index ].days_to_recurrence | number }}</td>
</tr>
<tr>
<th scope="row" data-translate>Last Known Disease Status</th>
Expand Down
25 changes: 20 additions & 5 deletions app/scripts/search/search.participants.table.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ module ngApp.search.models {
];
return withFilter(getDataCategory(row.summary ? row.summary.data_categories : [], dataCategory), fs, $filter);
}
function youngestDiagnosis(p: { age_at_diagnosis: number }, c: { age_at_diagnosis: number }): { age_at_diagnosis: number } {
return c.age_at_diagnosis < p.age_at_diagnosis ? c : p
}

var searchParticipantsModel = {
title: 'Cases',
Expand Down Expand Up @@ -172,27 +175,39 @@ module ngApp.search.models {
id: 'diagnoses.age_at_diagnosis',
td: (row, $scope) => {
// Use diagnosis with minimum age
const age = row.diagnoses.reduce((p, c) => c.age_at_diagnosis < p ? c.age_at_diagnosis : p, Infinity);
return (row.diagnoses && $scope.$filter("ageDisplay")(age)) || "--"
const age = (row.diagnoses || []).reduce((p, c) => c.age_at_diagnosis < p ? c.age_at_diagnosis : p, Infinity);
return age !== Infinity && row.diagnoses ? $scope.$filter("ageDisplay")(age) : "--";
},
sortable: false,
hidden: true
}, {
name: 'Days to death',
id: 'diagnoses.days_to_death',
td: (row, $scope) => (row.diagnoses && $scope.$filter("number")(row.diagnoses.days_to_death, 0)) || "--",
td: (row, $scope) => {
const primaryDiagnosis = (row.diagnoses || [])
.reduce(youngestDiagnosis, { age_at_diagnosis: Infinity });
return (row.diagnoses && $scope.$filter("number")(primaryDiagnosis.days_to_death, 0)) || "--"
},
sortable: false,
hidden: true
}, {
name: 'Vital Status',
id: 'diagnoses.vital_status',
td: (row, $scope) => row.diagnoses && $scope.$filter("humanify")(row.diagnoses.vital_status),
td: (row, $scope) => {
const primaryDiagnosis = (row.diagnoses || [])
.reduce(youngestDiagnosis, { age_at_diagnosis: Infinity });
return row.diagnoses && $scope.$filter("humanify")(primaryDiagnosis.vital_status)
},
sortable: false,
hidden: true
}, {
name: 'Year of diagnosis',
id: 'diagnoses.year_of_diagnosis',
td: (row, $scope) => (row.diagnoses && row.diagnoses.year_of_diagnosis) || "--",
td: (row, $scope) => {
const primaryDiagnosis = (row.diagnoses || [])
.reduce(youngestDiagnosis, { age_at_diagnosis: Infinity });
return (row.diagnoses && primaryDiagnosis.year_of_diagnosis) || "--"
},
sortable: false,
hidden: true
}, {
Expand Down

0 comments on commit 7801e24

Please sign in to comment.