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

fix: task bugs #42

Merged
merged 1 commit into from
Dec 31, 2023
Merged
Show file tree
Hide file tree
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
40 changes: 22 additions & 18 deletions apps/expo/src/app/(main)/portal/(modals)/tasks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export default function TasksPage() {
format(new Date(), "yyyy-MM-dd"),
);

const listTask = api.task.search.useQuery({
const { isLoading, isError, data, error } = api.task.search.useQuery({
query: {
patient: `Patient/${patientId}`,
},
Expand Down Expand Up @@ -79,24 +79,28 @@ export default function TasksPage() {
};

const tasks = useMemo(() => {
if (listTask.data) {
const items = listTask.data.entry!.map((task) => ({
name: `${task.resource.description ?? "No Description"}|${
task.resource.status
}`,
height: 80,
day: format(new Date(task.resource.authoredOn!), "yyyy-MM-dd"),
}));
const filteredTasks =
data?.entry?.filter(
(task) =>
task.resource.status === "completed" ||
task.resource.status === "requested",
) ?? [];

return items.reduce((acc, item) => {
(acc[item.day] = acc[item.day] ?? []).push(item);
return acc;
}, {} as AgendaSchedule);
}
return {};
}, [listTask.data]);
const items = filteredTasks.map((task) => ({
name: `${task.resource.description ?? "No Description"}~~~${
task.resource.status
}`,
height: 80,
day: format(new Date(task.resource.authoredOn!), "yyyy-MM-dd"),
}));

return items.reduce((acc, item) => {
(acc[item.day] = acc[item.day] ?? []).push(item);
return acc;
}, {} as AgendaSchedule);
}, [data]);

if (listTask.isLoading) {
if (isLoading) {
return <LoaderComponent />;
}

Expand Down Expand Up @@ -135,7 +139,7 @@ export default function TasksPage() {
monthTextColor: "#888",
}}
renderItem={(item: AgendaEntry, isFirst) => {
const [description, status] = item.name.split("|");
const [description, status] = item.name.split("~~~");

let backgroundColor = "bg-blue-500"; // Default color
if (status === "completed") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,14 @@ export default function ClinicalNotes() {
const processedNotes = data?.entry
?.filter((note) => {
const typeCode = note.resource?.type?.coding?.[0]?.code;
return typeCode !== "11502-2" && typeCode !== "94093-2";
const categoryCode = note.resource?.category?.[0]?.coding?.[0]?.code;

// Filter based on typeCode and categoryCode of bills, lab reports, and consents
return (
typeCode !== "11502-2" &&
typeCode !== "94093-2" &&
categoryCode !== "patientadministrativedocument"
);
})
.map((note) => {
let displayText = note.resource?.type?.coding?.[0]?.display;
Expand All @@ -56,7 +63,7 @@ export default function ClinicalNotes() {

return (
<View className="flex-1 bg-gray-100">
{data && data.total > 0 ? (
{data && data.total > 0 && sortedNotes.length > 0 ? (
<FlashList
data={sortedNotes}
renderItem={({ item }) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,8 @@ export default function QuestionnairesPage() {

return {
...response,
questionnaireName:
questionnaire?.resource?.name ?? "Retired questionnaire",
questionnaireStatus: questionnaire?.resource?.status ?? "retired",
questionnaireName: questionnaire?.resource?.name ?? "Questionnaire",
questionnaireStatus: "completed", // TODO: Get the status of the questionnaire
};
});

Expand Down
2 changes: 1 addition & 1 deletion apps/expo/src/components/next-appointment.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export default function NextAppointment() {
}, [appointmentQuery.data?.entry]);

if (isLoading) {
return <LoaderComponent className="mt-8" />;
return <LoaderComponent className="mt-12" />;
}

if (isError) {
Expand Down
26 changes: 16 additions & 10 deletions apps/expo/src/components/tasks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,15 @@ export default function Tasks() {
// Check if there are tasks to display
const hasTasks = tasksQuery.data?.entry?.length ?? 0 > 0;

// Sort tasks by date using date-fns
// Sort and filter tasks
const sortedTasks = tasksQuery.data?.entry
?.filter((item) => {
if (taskStatus === "") {
return true;
// Exclude 'cancelled' tasks
if (item.resource.status === "cancelled") {
return false;
}
return item.resource.status === taskStatus;
// If taskStatus is set, filter by it; otherwise, include all non-cancelled tasks
return taskStatus === "" || item.resource.status === taskStatus;
})
.sort((a, b) =>
compareAsc(
Expand Down Expand Up @@ -64,18 +66,22 @@ export default function Tasks() {
item.resource.status === "requested"
? "border-blue-400 bg-blue-500"
: item.resource.status === "cancelled"
? "border-yellow-400 bg-yellow-200"
: "border-green-400 bg-green-200"
? "border-yellow-400 bg-yellow-500"
: "border-green-400 bg-green-500"
}`}
>
<Text className="text-base font-medium text-white">
{item.resource.description}
</Text>
<Text className="text-sm text-white">
{formatDateTime(item.resource.authoredOn!)}
</Text>
{item.resource.status !== "completed" && (
<Text className="text-sm text-white">
{formatDateTime(item.resource.authoredOn!)}
</Text>
)}
{item.resource.status === "completed" && (
<Text>{item.resource.status}</Text>
<Text className="text-sm capitalize text-white">
{item.resource.status}
</Text>
)}
</View>
)}
Expand Down
Loading