Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/Jay-byte389/AMS/llms.txt

Use this file to discover all available pages before exploring further.

The Appointments resource handles the full lifecycle of a patient’s booking. AMS reads all existing records on launch with GET /Appointments, writes a new booking with POST /Appointments when the patient submits the schedule form, and updates a record’s status field to "Cancelled" via PUT /Appointments/:id when the patient cancels. All three operations are performed through the shared Axios client in src/services/api.js and are exposed to the UI through Redux Toolkit async thunks.

GET /Appointments

Method: GET — Path: /Appointments
Fetches every appointment record stored on MockAPI. The Home screen and the Appointments screen both dispatch this endpoint to build the UI — the Home screen uses the results to surface the next upcoming appointment, and the Appointments screen groups records by status tab.

Service Function

Defined in src/services/appointmentApi.js:
src/services/appointmentApi.js
import API from './api';

export const fetchAppointmentsFromApi = async () => {
  const response = await API.get('/Appointments');
  return response.data;
};

Redux Thunk

fetchAppointments wraps fetchAppointmentsFromApi and stores the result in state.appointments.list. Defined in src/redux/thunk/appointmentThunk.js:
src/redux/thunk/appointmentThunk.js
export const fetchAppointments = createAsyncThunk(
  'appointments/fetchAppointments',
  async (_, { rejectWithValue }) => {
    try {
      return await fetchAppointmentsFromApi();
    } catch (error) {
      return rejectWithValue(error.response?.data || error.message);
    }
  }
);

Request Parameters

No parameters are accepted. The endpoint always returns the full appointments collection.
AMS filters appointments on the client side. After GET /Appointments resolves, the Home screen filters by userId to isolate the current user’s bookings, then filters by appointmentDay for the selected date, and finally sorts by appointmentTime to surface the earliest upcoming slot.

Response

Returns a JSON array of appointment objects.

Appointment Object Schema

id
string
required
Unique appointment identifier assigned by MockAPI on creation.
userId
string
required
Identifies the patient who booked the appointment. Set to the logged-in user’s email or mobile number — whichever is available — or "guest" if neither is present.
patientType
string
required
Indicates whether the appointment is for the account holder or someone else. One of "Yourself" or "Another Person".
patientName
string
required
Full name of the patient as entered in the Patient Details form on the Schedule screen.
patientAge
string
required
Age of the patient as entered in the form (stored as a string).
patientGender
string
required
Gender selected on the Schedule screen. One of "Male", "Female", or "Other".
patientProblem
string
required
Free-text description of the patient’s medical issue as entered in the Describe your problem field.
appointmentMonth
string
required
Full month name of the appointment (e.g. "January", "February"). Used together with appointmentDay to group appointments by date.
appointmentDay
number
required
Numeric day of the month (e.g. 15). Combined with appointmentMonth for date filtering in the Home and DoctorInfo screens.
appointmentWeek
string
required
Abbreviated weekday name derived from the week selector (e.g. "Mon", "Tue").
appointmentTime
string
required
Selected time slot in 12-hour format (e.g. "10:00 AM", "2:30 PM"). Used to detect booking conflicts and sort upcoming appointments.
appointmentDate
string
required
ISO 8601 date string for the appointment (e.g. "2025-07-15"). Sourced from the calendar’s dateString property.
doctorId
string
required
Foreign key referencing the doctor’s id in the /Doctors resource.
doctorAvatar
string
required
URL of the doctor’s avatar image, copied from the doctor record at booking time.
doctorName
string
required
Doctor’s full name copied from the doctor record at booking time.
doctorDepartment
string
required
Doctor’s department or speciality copied from the doctor record. Falls back to doctor.qualification if department is absent.
doctorQualification
string
required
Doctor’s qualification abbreviation (e.g. "MBBS") copied from the doctor record.
status
string
required
Current appointment status. One of "Upcoming" or "Cancelled". New appointments are always created with "Upcoming"; the cancelAppointment thunk updates this to "Cancelled".
createdAt
string
required
ISO 8601 timestamp of when the appointment was booked (e.g. "2025-07-10T08:45:00.000Z"). Set client-side via new Date().toISOString() at the moment of submission.

Example Response

[
  {
    "id": "42",
    "userId": "patient@example.com",
    "patientType": "Yourself",
    "patientName": "John Doe",
    "patientAge": "32",
    "patientGender": "Male",
    "patientProblem": "Chest pain and occasional shortness of breath",
    "appointmentMonth": "July",
    "appointmentDay": 15,
    "appointmentWeek": "Tue",
    "appointmentTime": "10:00 AM",
    "appointmentDate": "2025-07-15",
    "doctorId": "1",
    "doctorAvatar": "https://example.com/avatars/sarah-mitchell.jpg",
    "doctorName": "Dr. Sarah Mitchell",
    "doctorDepartment": "Cardiology",
    "doctorQualification": "MBBS",
    "status": "Upcoming",
    "createdAt": "2025-07-10T08:45:00.000Z"
  }
]

POST /Appointments

Method: POST — Path: /Appointments
Creates a new appointment record on MockAPI. Called when a patient fills in their details on the Schedule screen and taps Book Appointment. The response includes the server-assigned id which is immediately pushed into the Redux appointments.list array.

Service Function

Defined in src/services/appointmentApi.js:
src/services/appointmentApi.js
import API from './api';

export const createAppointmentOnApi = async (appointmentData) => {
  const response = await API.post('/Appointments', appointmentData);
  return response.data;
};

Redux Thunk

addAppointment wraps createAppointmentOnApi. On success, the returned object (with its MockAPI-assigned id) is appended to state.appointments.list. Defined in src/redux/thunk/appointmentThunk.js:
src/redux/thunk/appointmentThunk.js
export const addAppointment = createAsyncThunk(
  'appointments/addAppointment',
  async (newAppointment, { rejectWithValue }) => {
    try {
      return await createAppointmentOnApi(newAppointment);
    } catch (error) {
      return rejectWithValue(error.response?.data || error.message);
    }
  }
);

Request Body

Send a JSON object containing all appointment fields. MockAPI assigns the id and returns it in the response — do not include id in the request body.

Response

Returns the newly created appointment object with the server-assigned id included.

Usage Example

The Schedule screen builds the payload and dispatches addAppointment:
src/screens/ScheduleScreen.jsx
import { useDispatch, useSelector } from 'react-redux';
import { addAppointment } from '../redux/thunk/appointmentThunk';

const dispatch = useDispatch();
const currentUser = useSelector(state => state.auth.user);

const handleBook = async () => {
  const appointmentData = {
    userId: currentUser?.email || currentUser?.mobile || 'guest',
    patientType,       // "Yourself" | "Another Person"
    patientName: name,
    patientAge: age,
    patientGender: gender,
    patientProblem: problem,
    appointmentMonth: currentMonth,
    appointmentDay: Number(selectedDate.day),
    appointmentWeek: selectedDate.week,
    appointmentTime: selectedTime,
    appointmentDate: selectedDate.dateString,
    doctorId: doctors?.id || doctors?._id || '1',
    doctorAvatar: doctors.avatar,
    doctorName: doctors?.name || 'Doctor',
    doctorDepartment: doctors?.department || doctors?.qualification || 'General Physician',
    doctorQualification: doctors.qualification,
    status: 'Upcoming',
    createdAt: new Date().toISOString(),
  };

  try {
    const savedAppointment = await dispatch(addAppointment(appointmentData)).unwrap();
    // Navigate to the confirmation screen with the returned appointment
    navigation.navigate('YourAppointment', {
      doctor: doctors,
      appoinment: savedAppointment,
    });
  } catch (error) {
    console.error('Failed to save appointment:', error);
  }
};
AMS enforces a slot conflict guard before dispatching: if appointmentTime is already present in the bookedTimes list for the same doctorId and appointmentDay, the booking is blocked client-side and an alert is shown to the user. The API itself performs no duplicate checking.

PUT /Appointments/:id

Method: PUT — Path: /Appointments/:id
Replaces an existing appointment record. AMS uses this endpoint exclusively to cancel appointments by setting status to "Cancelled". The full appointment object (including all original fields) is sent in the request body with the status field overwritten.

Service Function

Defined in src/services/appointmentApi.js:
src/services/appointmentApi.js
import API from './api';

export const updateAppointmentOnApi = async (appointment) => {
  const response = await API.put(`/Appointments/${appointment.id}`, appointment);
  return response.data;
};

Redux Thunk — cancelAppointment

The cancelAppointment thunk accepts the full existing appointment object, spreads all its fields into a new object, overrides status to "Cancelled", and passes the result to updateAppointmentOnApi. Defined in src/redux/thunk/appointmentThunk.js:
src/redux/thunk/appointmentThunk.js
export const cancelAppointment = createAsyncThunk(
  'appointments/cancelAppointment',
  async (appointment, { rejectWithValue }) => {
    try {
      const updatedAppointment = {
        ...appointment,
        status: 'Cancelled',
      };

      return await updateAppointmentOnApi(updatedAppointment);
    } catch (error) {
      return rejectWithValue(error.response?.data || error.message);
    }
  }
);
The spread operator (...appointment) ensures every original field is preserved on the MockAPI record. Only status is changed; all other fields remain unchanged.

Path Parameter

id
string
required
The id of the appointment record to update. This value is present on every object returned by GET /Appointments and POST /Appointments.

Request Body

The complete appointment object with status set to "Cancelled". All fields from the original record must be included since MockAPI replaces the entire document.

Response

Returns the updated appointment object with status: "Cancelled".

Example: Cancel an Appointment

import { useDispatch } from 'react-redux';
import { cancelAppointment } from '../redux/thunk/appointmentThunk';

const dispatch = useDispatch();

// `appointment` is an object already fetched from GET /Appointments
const handleCancel = async (appointment) => {
  try {
    await dispatch(cancelAppointment(appointment)).unwrap();
    // The local Redux list is updated; status is now "Cancelled"
  } catch (error) {
    console.error('Cancellation failed:', error);
  }
};
After a successful cancellation, the cancelAppointment.fulfilled reducer filters the cancelled appointment out of state.appointments.list by id, so the UI updates immediately without a refetch.

Build docs developers (and LLMs) love