diff --git a/public/locale/en.json b/public/locale/en.json index f20179944d1..6d2d774c921 100644 --- a/public/locale/en.json +++ b/public/locale/en.json @@ -1588,6 +1588,8 @@ "select_register_patient": "Select/Register Patient", "select_seven_day_period": "Select a seven day period", "select_skills": "Select and add some skills", + "select_time": "Select time", + "select_time_slot": "Select time slot", "select_wards": "Select wards", "self_booked": "Self-booked", "send": "Send", @@ -1631,6 +1633,7 @@ "skill_add_error": "Error while adding skill", "skill_added_successfully": "Skill added successfully", "skills": "Skills", + "slots_left": "slots left", "social_profile": "Social Profile", "social_profile_detail": "Include occupation, ration card category, socioeconomic status, and domestic healthcare support for a complete profile.", "socioeconomic_status": "Socioeconomic status", @@ -1833,6 +1836,7 @@ "view_details": "View Details", "view_facility": "View Facility", "view_files": "View Files", + "view_patient": "View Patient", "view_patients": "View Patients", "view_update_patient_files": "View/Update patient files", "view_updates": "View Updates", diff --git a/src/components/Questionnaire/QuestionTypes/FollowUpAppointmentQuestion.tsx b/src/components/Questionnaire/QuestionTypes/FollowUpAppointmentQuestion.tsx new file mode 100644 index 00000000000..3fc6b63ab02 --- /dev/null +++ b/src/components/Questionnaire/QuestionTypes/FollowUpAppointmentQuestion.tsx @@ -0,0 +1,216 @@ +import { useQuery } from "@tanstack/react-query"; +import { format } from "date-fns"; +import { useState } from "react"; +import { useTranslation } from "react-i18next"; + +import { DatePicker } from "@/components/ui/date-picker"; +import { Label } from "@/components/ui/label"; +import { + Select, + SelectContent, + SelectItem, + SelectTrigger, + SelectValue, +} from "@/components/ui/select"; +import { Textarea } from "@/components/ui/textarea"; + +import { Avatar } from "@/components/Common/Avatar"; +import { groupSlotsByAvailability } from "@/components/Schedule/Appointments/utils"; +import { ScheduleAPIs } from "@/components/Schedule/api"; +import { FollowUpAppointmentRequest } from "@/components/Schedule/types"; + +import useSlug from "@/hooks/useSlug"; + +import query from "@/Utils/request/query"; +import { dateQueryString, formatDisplayName } from "@/Utils/utils"; +import { + QuestionnaireResponse, + ResponseValue, +} from "@/types/questionnaire/form"; +import { Question } from "@/types/questionnaire/question"; +import { UserBase } from "@/types/user/user"; + +interface FollowUpVisitQuestionProps { + question: Question; + questionnaireResponse: QuestionnaireResponse; + updateQuestionnaireResponseCB: (response: QuestionnaireResponse) => void; + disabled?: boolean; +} + +export function FollowUpAppointmentQuestion({ + question, + questionnaireResponse, + updateQuestionnaireResponseCB, + disabled, +}: FollowUpVisitQuestionProps) { + const { t } = useTranslation(); + const [resource, setResource] = useState(); + const [selectedDate, setSelectedDate] = useState(); + + const values = + (questionnaireResponse.values?.[0] + ?.value as unknown as FollowUpAppointmentRequest[]) || []; + + const value = values[0] ?? {}; + + const handleUpdate = (updates: Partial) => { + const followUpAppointment = { ...value, ...updates }; + updateQuestionnaireResponseCB({ + ...questionnaireResponse, + values: [ + { + type: "follow_up_appointment", + value: [followUpAppointment] as unknown as ResponseValue["value"], + }, + ], + }); + }; + + const facilityId = useSlug("facility"); + + const resourcesQuery = useQuery({ + queryKey: ["availableResources", facilityId], + queryFn: query(ScheduleAPIs.appointments.availableDoctors, { + pathParams: { facility_id: facilityId }, + }), + }); + + const slotsQuery = useQuery({ + queryKey: [ + "slots", + facilityId, + resource?.id, + dateQueryString(selectedDate), + ], + queryFn: query(ScheduleAPIs.slots.getSlotsForDay, { + pathParams: { facility_id: facilityId }, + body: { + resource: resource?.id, + day: dateQueryString(selectedDate), + }, + }), + enabled: !!resource && !!selectedDate, + }); + + return ( +
+ +
+
+ +