@@ -110,9 +120,7 @@ export function AppointmentSuccess(props: AppointmentSuccessProps) {
Doctor/Nurse:
-
- {formatName(appointmentData?.resource)}
-
+
{formatName(doctorData)}
@@ -143,8 +151,7 @@ export function AppointmentSuccess(props: AppointmentSuccessProps) {
- {formatName(appointmentData?.resource)} will visit the patient at the
- scheduled time.
+ {formatName(doctorData)} will visit the patient at the scheduled time.
Thank you for choosing our care service
diff --git a/src/pages/Appoinments/OTP.tsx b/src/pages/Appoinments/OTP.tsx
index cb8ee4a94aa..60a975b7848 100644
--- a/src/pages/Appoinments/OTP.tsx
+++ b/src/pages/Appoinments/OTP.tsx
@@ -77,14 +77,14 @@ export default function OTP({
},
});
if (response.res?.status === 200) {
- navigate(
- `/facility/${facilityId}/appointments/${staffUsername}/book-appointment`,
- );
const OTPaccessToken = response.data?.access;
localStorage.setItem("phoneNumber", phoneNumber);
if (OTPaccessToken) {
localStorage.setItem("OTPaccessToken", OTPaccessToken);
}
+ navigate(
+ `/facility/${facilityId}/appointments/${staffUsername}/book-appointment`,
+ );
}
// To Do: Mock, remove this
navigate(
diff --git a/src/pages/Appointments/AppointmentSuccess.tsx b/src/pages/Appointments/AppointmentSuccess.tsx
new file mode 100644
index 00000000000..e69de29bb2d
diff --git a/src/pages/Facility/AppointmentsPage.tsx b/src/pages/Facility/AppointmentsPage.tsx
index ea6e271bd66..a7a738150d6 100644
--- a/src/pages/Facility/AppointmentsPage.tsx
+++ b/src/pages/Facility/AppointmentsPage.tsx
@@ -1,3 +1,4 @@
+import careConfig from "@careConfig";
import { useQuery } from "@tanstack/react-query";
import { format, parseISO } from "date-fns";
import { Link, navigate } from "raviger";
@@ -15,9 +16,8 @@ import { Textarea } from "@/components/ui/textarea";
import { Avatar } from "@/components/Common/Avatar";
import { FacilityModel } from "@/components/Facility/models";
-import { ScheduleAPIs } from "@/components/Schedule/api";
import { SlotAvailability } from "@/components/Schedule/types";
-import { SkillModel, UserAssignedModel } from "@/components/Users/models";
+import { SkillModel, UserModel } from "@/components/Users/models";
import * as Notification from "@/Utils/Notifications";
import routes from "@/Utils/request/api";
@@ -39,9 +39,10 @@ export function AppointmentsPage(props: AppointmentsProps) {
const [selectedDate, setSelectedDate] = useState(new Date());
const [selectedSlot, setSelectedSlot] = useState
();
const [reason, setReason] = useState("");
- const doctorData: UserAssignedModel = JSON.parse(
+ const doctorData: UserModel = JSON.parse(
localStorage.getItem("doctor") ?? "{}",
);
+ const OTPaccessToken = localStorage.getItem("OTPaccessToken");
if (!staffUsername) {
Notification.Error({ msg: "Staff username not found" });
@@ -99,20 +100,40 @@ export function AppointmentsPage(props: AppointmentsProps) {
Notification.Error({ msg: "Error while fetching skills data" });
}
- const slotsQuery = useQuery>({
+ const slotsQuery = useQuery<{ results: SlotAvailability[] }>({
queryKey: ["slots", facilityId, staffUsername, selectedDate],
- queryFn: () =>
- request(ScheduleAPIs.slots.getAvailableSlotsForADay, {
- pathParams: {
- facility_id: facilityId,
- },
- body: {
- resource: doctorData?.id?.toString() ?? "",
- day: dateQueryString(selectedDate),
+ queryFn: async () => {
+ const response = await fetch(
+ `${careConfig.apiUrl}/api/v1/otp/slots/get_slots_for_day/`,
+ {
+ method: "POST",
+ headers: {
+ "Content-Type": "application/json",
+ Authorization: `Bearer ${OTPaccessToken}`,
+ },
+ body: JSON.stringify({
+ facility: facilityId,
+ resource: doctorData?.external_id?.toString() ?? "",
+ day: dateQueryString(selectedDate),
+ }),
},
- silent: true,
- }),
- enabled: !!staffUsername && !!doctorData && !!selectedDate,
+ );
+ if (!response.ok) {
+ const errorData = await response.json();
+ if (errorData.errors?.[0][0] === "Resource is not schedulable") {
+ Notification.Error({
+ msg: "This user is not available for appointments",
+ });
+ } else {
+ Notification.Error({ msg: "Error while fetching slots data" });
+ }
+ return null;
+ }
+
+ return response.json();
+ },
+ enabled:
+ !!staffUsername && !!doctorData && !!selectedDate && !!OTPaccessToken,
});
if (slotsQuery.error) {
@@ -141,12 +162,15 @@ export function AppointmentsPage(props: AppointmentsProps) {
// To Do: Mock, remove/adjust this
function extendDoctor(
- doctor: UserAssignedModel | undefined,
+ doctor: UserModel | undefined,
): DoctorModel | undefined {
if (!doctor) return undefined;
const randomDoc = mockDoctors[0];
return {
...doctor,
+ date_of_birth: doctor.date_of_birth
+ ? new Date(doctor.date_of_birth)
+ : undefined,
role: randomDoc.role,
gender: randomDoc.gender,
education: doctor.qualification
@@ -160,6 +184,12 @@ export function AppointmentsPage(props: AppointmentsProps) {
skills:
skills?.data?.results.map((s) => s.skill_object) ??
randomDoc.skills.map((s) => s),
+ doctor_experience_commenced_on: doctor.doctor_experience_commenced_on
+ ? new Date(doctor.doctor_experience_commenced_on)
+ : undefined,
+ weekly_working_hours: doctor.weekly_working_hours
+ ? doctor.weekly_working_hours.toString()
+ : undefined,
};
}
@@ -173,7 +203,7 @@ export function AppointmentsPage(props: AppointmentsProps) {
}
// To Do: Mock, remove/adjust this
- const mockTokenSlots: SlotAvailability[] = [
+ /* const mockTokenSlots: SlotAvailability[] = [
// Dec 20 - Morning slots
{
id: "1",
@@ -280,21 +310,21 @@ export function AppointmentsPage(props: AppointmentsProps) {
},
allocated: 3,
},
- ];
+ ]; */
- // To Do: Mock, remove/adjust this
- const slotsData = slotsQuery.data?.data?.results ?? mockTokenSlots;
- const morningSlots = slotsData.filter((slot) => {
+ const slotsData = slotsQuery.data?.results;
+ const morningSlots = slotsData?.filter((slot) => {
const slotTime = parseISO(slot.start_datetime);
return slotTime.getHours() <= 12;
});
- const eveningSlots = slotsData.filter((slot) => {
+ const eveningSlots = slotsData?.filter((slot) => {
const slotTime = parseISO(slot.start_datetime);
return slotTime.getHours() >= 12;
});
- const getSlotButtons = (slots: SlotAvailability[]) => {
+ const getSlotButtons = (slots: SlotAvailability[] | undefined) => {
+ if (!slots) return [];
return slots.map((slot) => (
{slotsData &&
- (morningSlots.length > 0 || eveningSlots.length > 0) ? (
+ ((morningSlots && morningSlots.length > 0) ||
+ (eveningSlots && eveningSlots.length > 0)) ? (
Available Time Slots
- {morningSlots.length > 0 && (
+ {morningSlots && morningSlots.length > 0 && (
- Morning Slots: {morningSlots.length}{" "}
+ Morning Slots: {morningSlots?.length}{" "}
{morningSlots.length > 1 ? "Slots" : "Slot"}
@@ -412,7 +443,7 @@ export function AppointmentsPage(props: AppointmentsProps) {
)}
- {eveningSlots.length > 0 && (
+ {eveningSlots && eveningSlots.length > 0 && (
Evening Slots: {eveningSlots.length}{" "}
diff --git a/src/pages/Landing/LandingPage.tsx b/src/pages/Landing/LandingPage.tsx
index dd98421f446..5a44c67c7d2 100644
--- a/src/pages/Landing/LandingPage.tsx
+++ b/src/pages/Landing/LandingPage.tsx
@@ -88,7 +88,6 @@ export function LandingPage() {
const district = districts.find(
(d) => d.name.toLowerCase() === value.toLowerCase(),
);
- console.log(district);
if (district) {
setSelectedDistrict(district);
setSearchQuery("");
diff --git a/src/pages/Patient/PatientRegistration.tsx b/src/pages/Patient/PatientRegistration.tsx
index 248c7422c79..0ee2cd5df66 100644
--- a/src/pages/Patient/PatientRegistration.tsx
+++ b/src/pages/Patient/PatientRegistration.tsx
@@ -142,15 +142,13 @@ export function PatientRegistration(props: PatientRegistrationProps) {
}
});
- console.log(errors);
-
return errors;
};
const { mutate: createAppointment } = useMutation({
mutationFn: async (body: AppointmentCreate) => {
const res = await fetch(
- `${careConfig.apiUrl}/api/v1/facility/${props.facilityId}/slots/${selectedSlot?.id}/create_appointment/`,
+ `${careConfig.apiUrl}/api/v1/otp/slots/${selectedSlot?.id}/create_appointment/`,
{
method: "POST",
headers: {
@@ -201,8 +199,6 @@ export function PatientRegistration(props: PatientRegistrationProps) {
is_active: true,
};
- console.log(data);
-
const response = await fetch(`${careConfig.apiUrl}/api/v1/otp/patient/`, {
method: "POST",
headers: {
@@ -216,7 +212,7 @@ export function PatientRegistration(props: PatientRegistrationProps) {
if (response.ok && requestData) {
publish("patient:upsert", requestData);
createAppointment({
- patient: requestData.id,
+ patient: requestData.external_id,
reason_for_visit: reason ?? "",
});
}
diff --git a/src/pages/Patient/PatientSelect.tsx b/src/pages/Patient/PatientSelect.tsx
index db95cc44e5e..312f330bdeb 100644
--- a/src/pages/Patient/PatientSelect.tsx
+++ b/src/pages/Patient/PatientSelect.tsx
@@ -1,5 +1,6 @@
import careConfig from "@careConfig";
import { useMutation, useQuery } from "@tanstack/react-query";
+import dayjs from "dayjs";
import { navigate } from "raviger";
import { useState } from "react";
@@ -14,7 +15,6 @@ import {
import * as Notification from "@/Utils/Notifications";
import { PaginatedResponse, RequestResult } from "@/Utils/request/types";
-import { formatDate } from "@/Utils/utils";
import { AppointmentPatient } from "./Utils";
@@ -49,27 +49,24 @@ export default function PatientSelect({
const { data: patientData } = useQuery<
RequestResult>
>({
- queryKey: ["patient", phoneNumber],
+ queryKey: ["otp-patient"],
queryFn: async () => {
- const res = await fetch(
- `${careConfig.apiUrl}/api/v1/otp/patient/?phone_number=${phoneNumber ?? ""}`,
- {
- headers: {
- Authorization: `Bearer ${OTPaccessToken}`,
- "Content-Type": "application/json",
- },
+ const res = await fetch(`${careConfig.apiUrl}/api/v1/otp/patient/`, {
+ headers: {
+ Authorization: `Bearer ${OTPaccessToken}`,
+ "Content-Type": "application/json",
},
- );
+ });
const data = await res.json();
return { res, data, error: res.ok ? undefined : data };
},
- enabled: !!phoneNumber && !!OTPaccessToken,
+ enabled: !!OTPaccessToken,
});
const { mutate: createAppointment } = useMutation({
mutationFn: async (body: AppointmentCreate) => {
const res = await fetch(
- `${careConfig.apiUrl}/api/v1/facility/${facilityId}/slots/${selectedSlot?.id}/create_appointment/`,
+ `${careConfig.apiUrl}/api/v1/otp/slots/${selectedSlot?.id}/create_appointment/`,
{
method: "POST",
headers: {
@@ -93,6 +90,7 @@ export default function PatientSelect({
const mockPatientData = [
{
id: "T105690908240017",
+ external_id: "T105690908240017",
name: "Leo Westervelt",
phone_number: "9876543120",
date_of_birth: "1996-01-04",
@@ -104,6 +102,7 @@ export default function PatientSelect({
},
{
id: "T105690908240019",
+ external_id: "T105690908240019",
name: "Tatiana Franci",
phone_number: "9876543120",
date_of_birth: "1998-06-02",
@@ -114,6 +113,7 @@ export default function PatientSelect({
},
{
id: "T105690908240032",
+ external_id: "T105690908240032",
name: "Rayna Passaquindici Arcand",
phone_number: "9876543120",
date_of_birth: "1991-05-23",
@@ -137,6 +137,15 @@ export default function PatientSelect({
);
};
+ const getPatienDoBorAge = (patient: AppointmentPatient) => {
+ if (patient.date_of_birth) {
+ return dayjs(patient.date_of_birth).format("DD MMM YYYY");
+ }
+ const yearOfBirth = parseInt(patient.year_of_birth ?? "");
+ const age = dayjs().year() - yearOfBirth;
+ return `${age} years`;
+ };
+
const renderPatientList = () => {
return (
@@ -194,12 +203,7 @@ export default function PatientSelect({
{patient.phone_number}
- {patient.date_of_birth
- ? formatDate(
- new Date(patient.date_of_birth ?? ""),
- "dd MMM yyyy",
- )
- : (patient.year_of_birth ?? "")}
+ {getPatienDoBorAge(patient as AppointmentPatient)}
{patient.gender === 1 ? "Male" : "Female"}
diff --git a/src/pages/Patient/Utils.tsx b/src/pages/Patient/Utils.tsx
index 2f9789bb405..6ade991d83b 100644
--- a/src/pages/Patient/Utils.tsx
+++ b/src/pages/Patient/Utils.tsx
@@ -14,6 +14,7 @@ export type AppointmentPatientRegister = {
export type AppointmentPatient = {
id: string;
+ external_id: string;
name: string;
phone_number: string;
address: string;