Skip to content

Commit

Permalink
Rename resources to users; disable heatmap (#9693)
Browse files Browse the repository at this point in the history
  • Loading branch information
rithviknishad authored Jan 3, 2025
1 parent e3daa67 commit 1d6ae92
Show file tree
Hide file tree
Showing 20 changed files with 84 additions and 73 deletions.
2 changes: 1 addition & 1 deletion care.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ const careConfig = {
// Kill switch in-case the heatmap API doesn't scale as expected
useAvailabilityStatsAPI: boolean(
"REACT_APPOINTMENTS_USE_AVAILABILITY_STATS_API",
true,
false,
),
},

Expand Down
22 changes: 0 additions & 22 deletions src/Utils/request/api.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,6 @@ import {
CreateFileResponse,
FileUploadModel,
} from "@/components/Patient/models";
import {
Appointment,
AppointmentCreate,
SlotAvailability,
} from "@/components/Schedule/types";
import {
SkillModel,
UpdatePasswordForm,
Expand Down Expand Up @@ -815,23 +810,6 @@ const routes = {
type: "header",
},
},
getSlotsForDay: {
path: "/api/v1/otp/slots/get_slots_for_day/",
method: "POST",
TRes: Type<{ results: SlotAvailability[] }>(),
TBody: Type<{ facility: string; resource: string; day: string }>(),
},
getAppointments: {
path: "/api/v1/otp/slots/get_appointments/",
method: "GET",
TRes: Type<{ results: Appointment[] }>(),
},
createAppointment: {
path: "/api/v1/otp/slots/{id}/create_appointment/",
method: "POST",
TRes: Type<Appointment>(),
TBody: Type<AppointmentCreate>(),
},
},

// Medication
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export function FollowUpAppointmentQuestion({

const resourcesQuery = useQuery({
queryKey: ["availableResources", facilityId],
queryFn: query(ScheduleAPIs.appointments.availableDoctors, {
queryFn: query(ScheduleAPIs.appointments.availableUsers, {
pathParams: { facility_id: facilityId },
}),
});
Expand All @@ -85,7 +85,7 @@ export function FollowUpAppointmentQuestion({
queryFn: query(ScheduleAPIs.slots.getSlotsForDay, {
pathParams: { facility_id: facilityId },
body: {
resource: resource?.id,
user: resource?.id,
day: dateQueryString(selectedDate),
},
}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export default function AppointmentCreatePage(props: Props) {

const resourcesQuery = useQuery({
queryKey: ["availableResources", props.facilityId],
queryFn: query(ScheduleAPIs.appointments.availableDoctors, {
queryFn: query(ScheduleAPIs.appointments.availableUsers, {
pathParams: {
facility_id: props.facilityId,
},
Expand All @@ -75,7 +75,7 @@ export default function AppointmentCreatePage(props: Props) {
queryFn: query(ScheduleAPIs.slots.getSlotsForDay, {
pathParams: { facility_id: props.facilityId },
body: {
resource: resourceId,
user: resourceId,
day: dateQueryString(selectedDate),
},
}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ const AppointmentDetails = ({
appointment: Appointment;
facility: FacilityModel;
}) => {
const { patient, resource } = appointment;
const { patient, user } = appointment;
const { t } = useTranslation();

return (
Expand Down Expand Up @@ -335,8 +335,8 @@ const AppointmentDetails = ({
<CardContent className="space-y-4">
<div className="grid gap-2">
<div className="text-sm">
<p className="font-medium">{formatName(resource)}</p>
<p className="text-gray-600">{resource.email}</p>
<p className="font-medium">{formatName(user)}</p>
<p className="text-gray-600">{user.email}</p>
</div>
<Separator />
<div className="text-sm">
Expand Down
5 changes: 2 additions & 3 deletions src/components/Schedule/Appointments/AppointmentTokenCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { formatAppointmentSlotTime } from "@/components/Schedule/Appointments/ut
import { getFakeTokenNumber } from "@/components/Schedule/helpers";
import { Appointment } from "@/components/Schedule/types";

import { formatPatientAge } from "@/Utils/utils";
import { formatName, formatPatientAge } from "@/Utils/utils";

interface Props {
id?: string;
Expand Down Expand Up @@ -76,8 +76,7 @@ const AppointmentTokenCard = ({ id, appointment, facility }: Props) => {
<div>
<Label>{t("practitioner")}:</Label>
<p className="text-sm font-semibold">
{appointment.resource.first_name}{" "}
{appointment.resource.last_name}
{formatName(appointment.user)}
</p>
</div>
<div>
Expand Down
17 changes: 11 additions & 6 deletions src/components/Schedule/Appointments/AppointmentsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,12 @@ import useAuthUser from "@/hooks/useAuthUser";
import FiltersCache from "@/Utils/FiltersCache";
import mutate from "@/Utils/request/mutate";
import query from "@/Utils/request/query";
import { dateQueryString, formatName, formatPatientAge } from "@/Utils/utils";
import {
dateQueryString,
formatDisplayName,
formatName,
formatPatientAge,
} from "@/Utils/utils";

interface QueryParams {
practitioner?: string;
Expand All @@ -91,7 +96,7 @@ export default function AppointmentsPage(props: { facilityId?: string }) {

const resourcesQuery = useQuery({
queryKey: ["appointments-resources", facilityId],
queryFn: query(ScheduleAPIs.appointments.availableDoctors, {
queryFn: query(ScheduleAPIs.appointments.availableUsers, {
pathParams: { facility_id: facilityId },
}),
});
Expand All @@ -104,7 +109,7 @@ export default function AppointmentsPage(props: { facilityId?: string }) {
queryFn: query(ScheduleAPIs.slots.getSlotsForDay, {
pathParams: { facility_id: facilityId },
body: {
resource: qParams.practitioner ?? "",
user: qParams.practitioner ?? "",
day: date,
},
}),
Expand Down Expand Up @@ -350,7 +355,7 @@ function AppointmentColumn(props: {
status: props.status,
limit: 100,
slot: props.slot,
resource: props.practitioner,
user: props.practitioner,
date: props.date,
},
}),
Expand Down Expand Up @@ -456,7 +461,7 @@ function AppointmentRow(props: {
status: status,
limit: 100,
slot: props.slot,
resource: props.practitioner,
user: props.practitioner,
date: props.date,
},
}),
Expand Down Expand Up @@ -574,7 +579,7 @@ function AppointmentRowItem({
<p>{"Need Room Information"}</p>
</TableCell>
<TableCell className="py-6 group-hover:bg-gray-100 bg-white">
{formatName(appointment.resource)}
{formatDisplayName(appointment.user)}
</TableCell>
<TableCell className="py-6 group-hover:bg-gray-100 bg-white">
<p>{"Need Labels"}</p>
Expand Down
5 changes: 3 additions & 2 deletions src/components/Schedule/Appointments/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
import query from "@/Utils/request/query";
import {
dateQueryString,
formatDisplayName,
formatPatientAge,
getMonthStartAndEnd,
} from "@/Utils/utils";
Expand Down Expand Up @@ -78,7 +79,7 @@ export const useAvailabilityHeatmap = ({
let queryFn = query(ScheduleAPIs.slots.availabilityHeatmap, {
pathParams: { facility_id: facilityId },
body: {
resource: userId,
user: userId,
from_date: fromDate,
to_date: toDate,
},
Expand Down Expand Up @@ -346,7 +347,7 @@ style="
margin: 0.25rem 0 0 0;
"
>
${appointment.resource.first_name} ${appointment.resource.last_name}
${formatDisplayName(appointment.user)}
</p>
</div>
<div>
Expand Down
2 changes: 1 addition & 1 deletion src/components/Schedule/ScheduleExceptionForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ export default function ScheduleExceptionForm({ user, onRefresh }: Props) {
valid_to: dateQueryString(data.valid_to),
start_time: data.start_time,
end_time: data.end_time,
resource: user.id,
user: user.id,
});
}

Expand Down
12 changes: 4 additions & 8 deletions src/components/Schedule/ScheduleExceptionsList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,12 @@ import useSlug from "@/hooks/useSlug";

import mutate from "@/Utils/request/mutate";
import { formatTimeShort } from "@/Utils/utils";
import { UserBase } from "@/types/user/user";

interface Props {
user: UserBase;
items?: ScheduleException[];
}

export default function ScheduleExceptionsList({ user, items }: Props) {
export default function ScheduleExceptionsList({ items }: Props) {
const { t } = useTranslation();

if (items == null) {
Expand All @@ -45,16 +43,14 @@ export default function ScheduleExceptionsList({ user, items }: Props) {
<ul className="flex flex-col gap-4">
{items.map((exception) => (
<li key={exception.id}>
<ScheduleExceptionItem {...exception} user={user} />
<ScheduleExceptionItem {...exception} />
</li>
))}
</ul>
);
}

const ScheduleExceptionItem = (
props: ScheduleException & { user: UserBase },
) => {
const ScheduleExceptionItem = (props: ScheduleException) => {
const { t } = useTranslation();
const facilityId = useSlug("facility");
const queryClient = useQueryClient();
Expand All @@ -69,7 +65,7 @@ const ScheduleExceptionItem = (
onSuccess: () => {
toast.success(t("exception_deleted"));
queryClient.invalidateQueries({
queryKey: ["user-availability-exceptions", props.user.username],
queryKey: ["user-availability-exceptions", props.user],
});
},
});
Expand Down
2 changes: 1 addition & 1 deletion src/components/Schedule/ScheduleTemplateForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ export default function ScheduleTemplateForm({ user, onRefresh }: Props) {
valid_from: dateQueryString(values.valid_from),
valid_to: dateQueryString(values.valid_to),
name: values.name,
resource: user.id as unknown as string,
user: user.id as unknown as string,
availabilities: values.availabilities.map((availability) => ({
name: availability.name,
slot_type: availability.slot_type,
Expand Down
9 changes: 4 additions & 5 deletions src/components/Schedule/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,13 @@ export const ScheduleAPIs = {
path: "/api/v1/facility/{facility_id}/slots/availability_stats/",
method: "POST",
TRes: Type<AvailabilityHeatmap>(),
TBody: Type<{ from_date: string; to_date: string; resource: string }>(),
TBody: Type<{ from_date: string; to_date: string; user: string }>(),
},
getSlotsForDay: {
path: "/api/v1/facility/{facility_id}/slots/get_slots_for_day/",
method: "POST",
TRes: Type<{ results: SlotAvailability[] }>(),
TBody: Type<{ resource: string; day: string }>(),
TBody: Type<{ user: string; day: string }>(),
},
createAppointment: {
path: "/api/v1/facility/{facility_id}/slots/{slot_id}/create_appointment/",
Expand All @@ -73,9 +73,8 @@ export const ScheduleAPIs = {
},

appointments: {
// TODO: rename this to available_resources (or something more accurate)
availableDoctors: {
path: "/api/v1/facility/{facility_id}/appointments/available_doctors/",
availableUsers: {
path: "/api/v1/facility/{facility_id}/appointments/available_users/",
method: "GET",
TRes: Type<{ users: UserBase[] }>(),
},
Expand Down
10 changes: 7 additions & 3 deletions src/components/Schedule/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { UserBase } from "@/types/user/user";

export interface ScheduleTemplate {
readonly id: string;
resource: string;
user: string;
name: string;
valid_from: string;
valid_to: string;
Expand Down Expand Up @@ -33,7 +33,7 @@ export type ScheduleAvailability = ScheduleTemplate["availabilities"][number];

export interface ScheduleException {
readonly id: string;
resource: string; // UUID of the resource
user: string; // UUID of user
reason: string;
valid_from: string; // date in YYYY-MM-DD format
valid_to: string; // date in YYYY-MM-DD format
Expand Down Expand Up @@ -98,13 +98,17 @@ export interface Appointment {
readonly booked_by: UserBase | null;
status: (typeof AppointmentStatuses)[number];
readonly reason_for_visit: string;
readonly resource: UserBase;
readonly user: UserBase;
}

export interface AvailabilityHeatmap {
[date: string]: { total_slots: number; booked_slots: number };
}

export interface CancelAppointmentRequest {
reason: "cancelled" | "entered_in_error";
}

export interface FollowUpAppointmentRequest {
reason_for_visit: string;
slot_id: string;
Expand Down
5 changes: 2 additions & 3 deletions src/components/Users/UserAvailabilityTab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export default function UserAvailabilityTab({ userData: user }: Props) {
queryKey: ["user-availability-templates", user.username],
queryFn: query(ScheduleAPIs.templates.list, {
pathParams: { facility_id: facilityId! },
queryParams: { resource: user.id },
queryParams: { user: user.id },
}),
enabled: !!facilityId,
});
Expand All @@ -64,7 +64,7 @@ export default function UserAvailabilityTab({ userData: user }: Props) {
queryKey: ["user-availability-exceptions", user.username],
queryFn: query(ScheduleAPIs.exceptions.list, {
pathParams: { facility_id: facilityId! },
queryParams: { resource: user.id },
queryParams: { user: user.id },
}),
});

Expand Down Expand Up @@ -274,7 +274,6 @@ export default function UserAvailabilityTab({ userData: user }: Props) {
? undefined
: exceptionsQuery.data?.results
}
user={user}
/>
)}

Expand Down
3 changes: 2 additions & 1 deletion src/pages/Appoinments/PatientRegistration.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import {
AppointmentPatientRegister,
} from "@/pages/Patient/Utils";
import { TokenData } from "@/types/auth/otpToken";
import PublicAppointmentApi from "@/types/scheduling/PublicAppointmentApi";

import OrganizationSelector from "../Organization/components/OrganizationSelector";

Expand Down Expand Up @@ -140,7 +141,7 @@ export function PatientRegistration(props: PatientRegistrationProps) {

const { mutate: createAppointment } = useMutation({
mutationFn: (body: AppointmentCreate) =>
mutate(routes.otp.createAppointment, {
mutate(PublicAppointmentApi.createAppointment, {
pathParams: { id: selectedSlot?.id },
body,
headers: {
Expand Down
3 changes: 2 additions & 1 deletion src/pages/Appoinments/PatientSelect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import query from "@/Utils/request/query";
import { PaginatedResponse } from "@/Utils/request/types";
import { AppointmentPatient } from "@/pages/Patient/Utils";
import { TokenData } from "@/types/auth/otpToken";
import PublicAppointmentApi from "@/types/scheduling/PublicAppointmentApi";

export default function PatientSelect({
facilityId,
Expand Down Expand Up @@ -72,7 +73,7 @@ export default function PatientSelect({

const { mutate: createAppointment } = useMutation({
mutationFn: (body: AppointmentCreate) =>
mutate(routes.otp.createAppointment, {
mutate(PublicAppointmentApi.createAppointment, {
pathParams: { id: selectedSlot?.id },
body,
headers: {
Expand Down
Loading

0 comments on commit 1d6ae92

Please sign in to comment.