Skip to main content

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';
}
id
number
required
Unique identifier for the appointment
fecha
string
required
Date of the appointment
hora
string
required
Time of the appointment
paciente
string
required
Name of the patient
tratamiento
string
required
Type of treatment for the appointment
doctor
string
required
Name of the doctor
duracion
string
required
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[]
return
AppointmentData[]
Array containing all appointment records
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
id
number
required
The unique identifier of the appointment
status
'confirmada' | 'pendiente' | 'completada'
required
The new status to set for the appointment
this.appointmentService.updateAppointmentStatus(1, 'confirmada');

addAppointment()

Adds a new appointment to the system.
addAppointment(data: Omit<AppointmentData, 'id' | 'estado' | 'asistido' | 'duracion'>): void
data
object
required
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
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
id
number
required
The unique identifier of the appointment to delete
this.appointmentService.deleteAppointment(3);

updateAppointmentTime()

Updates the time of an existing appointment.
updateAppointmentTime(id: number, time: string): void
id
number
required
The unique identifier of the appointment
time
string
required
The new time for the appointment (e.g., ‘14:30’)
this.appointmentService.updateAppointmentTime(1, '15:00');

updateAppointmentAttendance()

Updates the attendance status of an appointment.
updateAppointmentAttendance(id: number, asistido: 'sí' | 'no' | 'pendiente'): void
id
number
required
The unique identifier of the appointment
asistido
'sí' | 'no' | 'pendiente'
required
The attendance status to set
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();
  }
}

Build docs developers (and LLMs) love