Skip to content

Commit aadffa1

Browse files
committed
Correct ordering
1 parent 373c993 commit aadffa1

2 files changed

Lines changed: 14 additions & 7 deletions

File tree

patient-history-controler.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ async function refreshAll(date) {
5555

5656
async function refreshDataTable(date) {
5757
const currentDateStr = date.toISOString().split("T")[0]; // format YYYY-MM-DD;
58+
let currentValue = {};
5859
const { questionaryId, formKey } = navData;
5960
const tableData = await patientLib.getHistoricalContent(
6061
questionaryId,
@@ -73,14 +74,15 @@ async function refreshDataTable(date) {
7374
headerCell.innerHTML = th.label;
7475
headerRow.appendChild(headerCell);
7576
}
76-
for (const [dateStr, data] of Object.entries(tableData.valuesByDate)) {
77+
for (const data of tableData.valuesByDate) {
7778
const row = table.insertRow(-1);
78-
if (currentDateStr === dateStr) {
79+
if (currentDateStr === data.dateStr) {
80+
currentValue = data;
7981
row.style.backgroundColor = 'grey';
8082
}
8183

8284
const cellDate = row.insertCell(-1);
83-
cellDate.innerHTML = dateStr;
85+
cellDate.innerHTML = data.dateStr;
8486
for (const th of tableData.tableHeaders) {
8587
const cell = row.insertCell(-1);
8688
const v = data[th.fieldId]?.value;
@@ -89,7 +91,7 @@ async function refreshDataTable(date) {
8991
}
9092

9193
console.log("## tabledata", tableData);
92-
return tableData.valuesByDate[currentDateStr] || {};
94+
return currentValue;
9395
}
9496

9597
// ------- Form -------- //

patient-lib.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,12 +149,15 @@ async function getHistoricalContent(questionaryId, formKey) {
149149
type: field.type
150150
}));
151151

152-
const valuesByDate = {};
152+
const valuesByDateStr = {};
153153
function addEntry (field, time, event) {
154154
const dateStr = (new Date(time * 1000)).toISOString().split('T')[0];
155-
if (valuesByDate[dateStr] == null) valuesByDate[dateStr] = {};
155+
if (valuesByDateStr[dateStr] == null) valuesByDateStr[dateStr] = {
156+
dateNum: (new Date(dateStr)).getTime() / 100,
157+
dateStr,
158+
};
156159
const fieldId = field.streamId + ':' + field.eventType;
157-
valuesByDate[dateStr][fieldId] = {
160+
valuesByDateStr[dateStr][fieldId] = {
158161
value: valueForField(event.content, field),
159162
eventId: event.id
160163
}
@@ -180,6 +183,8 @@ async function getHistoricalContent(questionaryId, formKey) {
180183
}
181184
}
182185

186+
// order by date
187+
const valuesByDate = Object.values(valuesByDateStr).sort((a, b) => b.dateNum - a.dateNum);
183188
return { tableHeaders, valuesByDate };
184189
}
185190

0 commit comments

Comments
 (0)