From 4f986e9c2cb732c1fa35c80fc298b6ae01c44275 Mon Sep 17 00:00:00 2001 From: Kayla Cross Date: Fri, 9 Feb 2024 22:44:46 -0500 Subject: [PATCH] Fix date display (#410) * fix homepage age * fix misspelling * remove log --- .../patient-vitals-widget.component.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/frontend/src/app/widgets/patient-vitals-widget/patient-vitals-widget.component.ts b/frontend/src/app/widgets/patient-vitals-widget/patient-vitals-widget.component.ts index 4aa0080d..22922486 100644 --- a/frontend/src/app/widgets/patient-vitals-widget/patient-vitals-widget.component.ts +++ b/frontend/src/app/widgets/patient-vitals-widget/patient-vitals-widget.component.ts @@ -82,14 +82,17 @@ export class PatientVitalsWidgetComponent extends DashboardWidgetComponent imple return } - //process Patient objecst + //process Patient objects let sortedPatients = _.sortBy(queryResults?.[1], ['birthDate']) for(let patient of sortedPatients){ if(!this.name && _.get(patient, 'name[0].family') && _.get(patient, 'name[0].given[0]')){ this.name = `${_.get(patient, 'name[0].given[0]')} ${_.get(patient, 'name[0].family')}` } - if(!this.age && _.get(patient, 'birthDate')){ - this.age = `${moment().diff(moment(_.get(patient, 'birthDate')), 'years')} years` + const birthDate = _.get(patient, 'birthDate'); + if(!this.age && birthDate){ + const birthDateString = Array.isArray(birthDate) ? birthDate[0] : birthDate; + const birthDateMoment = moment(birthDateString); + this.age = `${moment().diff(birthDateMoment, 'years')} years`; // moment.diff rounds down } if(!this.gender && _.get(patient, 'gender[0]')){ this.gender = _.get(patient, 'gender[0]')