Overview
The AppointmentService is an Angular injectable service that handles appointment management including scheduling, status updates, attendance tracking, and time modifications.
Interface
AppointmentData
Represents a complete appointment record.
export interface AppointmentData {
id : number ;
fecha : string ;
hora : string ;
paciente : string ;
tratamiento : string ;
doctor : string ;
duracion : string ;
estado : 'confirmada' | 'pendiente' | 'completada' ;
asistido : 'sí' | 'no' | 'pendiente' ;
}
Unique identifier for the appointment
Type of treatment for the appointment
Duration of the appointment (e.g., ‘30 min’, ‘60 min’)
estado
'confirmada' | 'pendiente' | 'completada'
required
Current status of the appointment
asistido
'sí' | 'no' | 'pendiente'
required
Attendance status of the patient
Methods
getAppointments()
Retrieves all appointments.
getAppointments (): AppointmentData []
Array containing all appointment records
Basic Usage
Filter by Status
Get Today's Appointments
import { AppointmentService } from './services/appointment.service' ;
export class AppointmentListComponent {
constructor ( private appointmentService : AppointmentService ) {}
loadAppointments () {
const appointments = this . appointmentService . getAppointments ();
console . log ( `Total appointments: ${ appointments . length } ` );
}
}
updateAppointmentStatus()
Updates the status of an appointment.
updateAppointmentStatus ( id : number , status : 'confirmada' | 'pendiente' | 'completada' ): void
The unique identifier of the appointment
status
'confirmada' | 'pendiente' | 'completada'
required
The new status to set for the appointment
Confirm Appointment
Complete Appointment
With Notification
this . appointmentService . updateAppointmentStatus ( 1 , 'confirmada' );
addAppointment()
Adds a new appointment to the system.
addAppointment ( data : Omit < AppointmentData , 'id' | 'estado' | 'asistido' | 'duracion' > ): void
Appointment data object with the following required properties:
fecha (string): Appointment date
hora (string): Appointment time
paciente (string): Patient name
tratamiento (string): Treatment type
doctor (string): Doctor name
Basic Usage
From Form Submission
const newAppointment = {
fecha: '10/3/2026' ,
hora: '14:00' ,
paciente: 'Roberto Silva' ,
tratamiento: 'Revisión general' ,
doctor: 'Dr. Rodríguez'
};
this . appointmentService . addAppointment ( newAppointment );
deleteAppointment()
Removes an appointment from the system.
deleteAppointment ( id : number ): void
The unique identifier of the appointment to delete
Basic Usage
With Confirmation
this . appointmentService . deleteAppointment ( 3 );
updateAppointmentTime()
Updates the time of an existing appointment.
updateAppointmentTime ( id : number , time : string ): void
The unique identifier of the appointment
The new time for the appointment (e.g., ‘14:30’)
Basic Usage
Reschedule Appointment
this . appointmentService . updateAppointmentTime ( 1 , '15:00' );
updateAppointmentAttendance()
Updates the attendance status of an appointment.
updateAppointmentAttendance ( id : number , asistido : 'sí' | 'no' | 'pendiente' ): void
The unique identifier of the appointment
asistido
'sí' | 'no' | 'pendiente'
required
The attendance status to set
Mark as Attended
Mark as No-Show
Check-in System
this . appointmentService . updateAppointmentAttendance ( 1 , 'sí' );
Usage Example
import { Component , OnInit } from '@angular/core' ;
import { AppointmentService , AppointmentData } from './services/appointment.service' ;
@ Component ({
selector: 'app-appointment-calendar' ,
templateUrl: './appointment-calendar.component.html'
})
export class AppointmentCalendarComponent implements OnInit {
appointments : AppointmentData [] = [];
pendingAppointments : AppointmentData [] = [];
constructor ( private appointmentService : AppointmentService ) {}
ngOnInit () {
this . loadAppointments ();
}
loadAppointments () {
this . appointments = this . appointmentService . getAppointments ();
this . pendingAppointments = this . appointments . filter (
a => a . estado === 'pendiente'
);
}
confirmAppointment ( id : number ) {
this . appointmentService . updateAppointmentStatus ( id , 'confirmada' );
this . loadAppointments ();
}
rescheduleAppointment ( id : number , newTime : string ) {
this . appointmentService . updateAppointmentTime ( id , newTime );
this . loadAppointments ();
}
checkInPatient ( id : number ) {
this . appointmentService . updateAppointmentAttendance ( id , 'sí' );
this . appointmentService . updateAppointmentStatus ( id , 'completada' );
this . loadAppointments ();
}
}