Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor. group tasks together based on tasktype #169

Merged
merged 2 commits into from
Apr 4, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -294,8 +294,6 @@ export const ExtractNonMedicationTasks = (
const groupedData = [],
completedExtractedData = [],
pendingExtractedData = [];
let currentStartTime = null;
let currentGroup = [];
nonMedicationTasks?.forEach((nonMedicationTask) => {
const {
name,
Expand Down Expand Up @@ -343,22 +341,45 @@ export const ExtractNonMedicationTasks = (
extractedData.push(...completedExtractedData);
// grouping non-medication tasks together when the filter.id is pending
if (filterValue.id === "pending") {
extractedData.forEach((item) => {
if (item.startTime !== currentStartTime && !item.stopTime) {
if (currentGroup.length > 0) {
groupedData.push(currentGroup);
}
currentGroup = [item];
currentStartTime = item.startTime;
} else {
currentGroup.push(item);
}
});
if (currentGroup.length > 0) {
groupedData.push(currentGroup);
const nursingActivityTask = extractedData.filter(
(data) => data.taskType?.display === "nursing_activity"
);
const systemGeneratedTasks = extractedData.filter(
(data) => data.taskType?.display !== "nursing_activity"
);
const extractedNursingActivityTask = groupTasks(
nursingActivityTask,
groupedData
);
const extractedSystemGeneratedTasks = groupTasks(
systemGeneratedTasks,
groupedData
);
if (extractedNursingActivityTask.length > 0) {
groupedData.push(extractedNursingActivityTask);
}
if (extractedSystemGeneratedTasks.length > 0) {
groupedData.push(extractedSystemGeneratedTasks);
}
} else if (extractedData.length > 0) {
groupedData.push(extractedData);
}
return groupedData;
};

const groupTasks = (extractedData, groupedData) => {
let currentGroup = [];
let currentStartTime = null;
extractedData.forEach((item) => {
if (item.startTime !== currentStartTime && !item.stopTime) {
if (currentGroup.length > 0) {
groupedData.push(currentGroup);
}
currentGroup = [item];
currentStartTime = item.startTime;
} else {
currentGroup.push(item);
}
});
return currentGroup;
};
Loading