Skip to main content

Overview

The PatientService is an Angular injectable service that manages patient information including personal details, medical history, appointments, and treatments. It provides methods to retrieve and add patient records.

Interfaces

PatientData

Represents a complete patient record with all associated information.
export interface PatientData {
  id: number;
  nombre: string;
  edad: number;
  phone: string;
  email: string;
  address: string;
  medication_allergies: string;
  billing_data: string;
  health_status: string;
  family_history: string;
  ultimaVisita: string;
  proximaCita: string;
  estado: string;
  citas: Cita[];
  tratamientos: Tratamiento[];
}
id
number
required
Unique identifier for the patient
nombre
string
required
Full name of the patient
edad
number
required
Age of the patient
phone
string
required
Contact phone number
email
string
required
Email address
address
string
required
Physical address
medication_allergies
string
required
Known medication allergies
billing_data
string
required
Insurance or billing information
health_status
string
required
Current health status description
family_history
string
required
Family medical history
ultimaVisita
string
required
Date of last visit
proximaCita
string
required
Date of next appointment
estado
string
required
Patient status (e.g., ‘activo’, ‘pendiente’, ‘urgente’)
citas
Cita[]
required
Array of appointments associated with this patient
tratamientos
Tratamiento[]
required
Array of treatments associated with this patient

Cita

Represents an appointment record.
export interface Cita {
  titulo: string;
  fecha: string;
  hora: string;
  doctor: string;
  estado: string;
}

Tratamiento

Represents a treatment record for a patient.
export interface Tratamiento {
  titulo: string;
  precio: number;
  fecha: string;
  doctor: string;
  descripcion: string;
}

Methods

getPatients()

Retrieves all patient records.
getPatients(): PatientData[]
return
PatientData[]
Array containing all patient records
import { PatientService } from './services/patient.service';

export class PatientListComponent {
  constructor(private patientService: PatientService) {}

  loadPatients() {
    const patients = this.patientService.getPatients();
    console.log(`Found ${patients.length} patients`);
  }
}

getPatientById()

Retrieves a specific patient by their ID.
getPatientById(id: number): PatientData | undefined
id
number
required
The unique identifier of the patient to retrieve
return
PatientData | undefined
The patient record if found, otherwise undefined
const patient = this.patientService.getPatientById(1);

if (patient) {
  console.log(`Patient: ${patient.nombre}`);
  console.log(`Email: ${patient.email}`);
} else {
  console.log('Patient not found');
}

addPatient()

Adds a new patient to the system.
addPatient(patient: any): void
patient
object
required
Patient data object with the following properties:
  • first_name (string): Patient’s first name
  • last_name (string): Patient’s last name
  • edad (number): Age
  • phone (string): Phone number
  • email (string): Email address
  • address (string, optional): Physical address
  • medication_allergies (string, optional): Known allergies
  • billing_data (string, optional): Insurance information
  • health_status (string, optional): Current health status
  • family_history (string, optional): Family medical history
const newPatient = {
  first_name: 'Pedro',
  last_name: 'Martínez',
  edad: 38,
  phone: '622 333 444',
  email: '[email protected]',
  address: 'Calle Sol 15, Madrid',
  medication_allergies: 'Ninguna',
  billing_data: 'Sanitas - 456789',
  health_status: 'Revisión general necesaria',
  family_history: 'Ninguno relevante'
};

this.patientService.addPatient(newPatient);

Usage Example

import { Component, OnInit } from '@angular/core';
import { PatientService, PatientData } from './services/patient.service';

@Component({
  selector: 'app-patient-dashboard',
  templateUrl: './patient-dashboard.component.html'
})
export class PatientDashboardComponent implements OnInit {
  patients: PatientData[] = [];
  urgentPatients: PatientData[] = [];

  constructor(private patientService: PatientService) {}

  ngOnInit() {
    this.loadPatients();
  }

  loadPatients() {
    this.patients = this.patientService.getPatients();
    this.urgentPatients = this.patients.filter(p => p.estado === 'urgente');
  }

  viewPatientDetails(patientId: number) {
    const patient = this.patientService.getPatientById(patientId);
    if (patient) {
      console.log('Appointments:', patient.citas.length);
      console.log('Treatments:', patient.tratamientos.length);
    }
  }
}

Build docs developers (and LLMs) love