Skip to content

Commit

Permalink
Next Message column - do not display dates in past (#201)
Browse files Browse the repository at this point in the history
* Next Message column - do not display dates in past

* fix code

---------

Co-authored-by: Amy Chen <clone@cesium.cirg.washington.edu>
  • Loading branch information
achen2401 and Amy Chen authored Oct 20, 2023
1 parent ac942d3 commit 8bb01ce
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
6 changes: 6 additions & 0 deletions patientsearch/src/js/context/PatientListContextProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
getClientsByRequiredRoles,
getPatientIdsByCareTeamParticipant,
getTimeAgoDisplay,
isInPast,
isString,
putPatientData,
getUrlParameter,
Expand Down Expand Up @@ -406,12 +407,17 @@ export default function PatientListContextProvider({ children }) {
}
let value =
nodes && nodes.length ? nodes[nodes.length - 1].value : null;

if (dataType === "date") {
value = value ? getLocalDateTimeString(value) : "--";
}
if (dataType === "timeago" && value) {
value = value ? getTimeAgoDisplay(new Date(value)) : "--";
}
if (col.field === "next_message") {
// TODO maybe a specific data type to handle not displaying past message?
value = isInPast(value) ? "--": getLocalDateTimeString(value);
}
if (col.field) rowData[col.field] = value;
});
return rowData;
Expand Down
12 changes: 12 additions & 0 deletions patientsearch/src/js/helpers/utility.js
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,18 @@ export function addMamotoTracking(siteId, userId) {
headElement.appendChild(g);
}

/*
* @param dateString of type String
* @returns true if supplied dateString is determined to be less than today's date otherwise false
*/
export function isInPast(dateString) {
if (!dateString) return false;
const today = new Date();
const targetDate = new Date(dateString);
if (!isValid(targetDate)) return false;
return targetDate < today;
}

/*
* @param objDate of type Date object
* @returns text display of time ago as string e.g. < 50 seconds, < 1 hour, 1 day 2 hours, 3 hours, 3 days
Expand Down

0 comments on commit 8bb01ce

Please sign in to comment.