Skip to main content

Overview

The TreatmentService is an Angular injectable service that manages the catalog of available dental treatments including their descriptions, pricing, duration, and categories.

Interface

Tratamiento

Represents a treatment offering in the dental clinic.
export interface Tratamiento {
  id: number;
  nombre: string;
  categoria: string;
  descripcion: string;
  duracion: number;
  precio: number;
}
id
number
required
Unique identifier for the treatment
nombre
string
required
Name of the treatment
categoria
string
required
Category of the treatment (e.g., ‘Preventiva’, ‘Cirugía’, ‘Estética’, ‘Ortodoncia’)
descripcion
string
required
Detailed description of the treatment
duracion
number
required
Duration of the treatment in minutes
precio
number
required
Price of the treatment in the local currency

Methods

getTratamientos()

Retrieves all available treatments.
getTratamientos(): Tratamiento[]
return
Tratamiento[]
Array containing all treatment records
import { TreatmentService } from './services/treatment.service';

export class TreatmentListComponent {
  constructor(private treatmentService: TreatmentService) {}

  loadTreatments() {
    const treatments = this.treatmentService.getTratamientos();
    console.log(`Available treatments: ${treatments.length}`);
  }
}

addTratamiento()

Adds a new treatment to the catalog.
addTratamiento(tratamiento: Omit<Tratamiento, 'id'>): Tratamiento
tratamiento
object
required
Treatment data object with the following properties:
  • nombre (string): Name of the treatment
  • categoria (string): Treatment category
  • descripcion (string): Treatment description
  • duracion (number): Duration in minutes
  • precio (number): Price of the treatment
return
Tratamiento
The newly created treatment object with assigned ID
const newTreatment = {
  nombre: 'Endodoncia',
  categoria: 'Cirugía',
  descripcion: 'Tratamiento del conducto radicular',
  duracion: 90,
  precio: 300
};

const created = this.treatmentService.addTratamiento(newTreatment);
console.log(`Created treatment with ID: ${created.id}`);

updateTratamiento()

Updates an existing treatment in the catalog.
updateTratamiento(tratamiento: Tratamiento): void
tratamiento
Tratamiento
required
Complete treatment object including the ID to update
const updatedTreatment: Tratamiento = {
  id: 1,
  nombre: 'Limpieza dental profunda',
  categoria: 'Preventiva',
  descripcion: 'Limpieza profesional completa con pulido',
  duracion: 60,
  precio: 90
};

this.treatmentService.updateTratamiento(updatedTreatment);

deleteTratamiento()

Removes a treatment from the catalog.
deleteTratamiento(id: number): void
id
number
required
The unique identifier of the treatment to delete
this.treatmentService.deleteTratamiento(5);

Usage Example

import { Component, OnInit } from '@angular/core';
import { TreatmentService, Tratamiento } from './services/treatment.service';

@Component({
  selector: 'app-treatment-catalog',
  templateUrl: './treatment-catalog.component.html'
})
export class TreatmentCatalogComponent implements OnInit {
  treatments: Tratamiento[] = [];
  categories: string[] = [];
  selectedCategory: string = 'all';

  constructor(private treatmentService: TreatmentService) {}

  ngOnInit() {
    this.loadTreatments();
  }

  loadTreatments() {
    this.treatments = this.treatmentService.getTratamientos();
    this.categories = [...new Set(this.treatments.map(t => t.categoria))];
  }

  getFilteredTreatments(): Tratamiento[] {
    if (this.selectedCategory === 'all') {
      return this.treatments;
    }
    return this.treatments.filter(t => t.categoria === this.selectedCategory);
  }

  addTreatment(treatmentData: Omit<Tratamiento, 'id'>) {
    const newTreatment = this.treatmentService.addTratamiento(treatmentData);
    this.loadTreatments();
    return newTreatment;
  }

  updateTreatmentPrice(id: number, newPrice: number) {
    const treatment = this.treatments.find(t => t.id === id);
    if (treatment) {
      treatment.precio = newPrice;
      this.treatmentService.updateTratamiento(treatment);
    }
  }

  removeTreatment(id: number) {
    this.treatmentService.deleteTratamiento(id);
    this.loadTreatments();
  }
}

Build docs developers (and LLMs) love