Skip to main content
The Pathology Service provides methods to manage the catalog of medical pathologies, including ICD-10 codes, specialty filtering, and active/inactive status management.

Methods

getAll

Retrieve all pathologies in the system.
patologies.getAll(): Promise<Pathology[]>
Returns: Array of all pathology records ordered by name.
pathologies
array
Each pathology includes:
id
string
Pathology UUID
nombre
string
Pathology name
especialidad
string
Medical specialty
sexo
string | null
Applicable gender (if gender-specific)
activo
boolean
Whether pathology is active
created_at
string
Creation timestamp
Example:
import { api } from '../lib/api';

const pathologies = await api.patologies.getAll();
console.log(`Total pathologies: ${pathologies.length}`);
Cache: Results are cached for 30 minutes with key 'all'.

getAllActive

Retrieve only active pathologies.
patologies.getAllActive(): Promise<Pathology[]>
Returns: Array of active pathologies ordered by name.
pathologies
array
Includes: id, nombre, especialidad, sexo
Example:
import { api } from '../lib/api';

const activePathologies = await api.patologies.getAllActive();
// Use for dropdowns and selection lists
Filtering: Automatically filters where activo = true.

getById

Retrieve a single pathology by ID.
patologies.getById(id: string): Promise<Pathology | null>
id
string
required
The pathology’s unique identifier (UUID)
Returns: Complete pathology record including all fields. Example:
import { api } from '../lib/api';

const pathology = await api.patologies.getById('abc-123-def');
if (pathology) {
  console.log(`Pathology: ${pathology.nombre}`);
  console.log(`ICD-10: ${pathology.codcie10}`);
  console.log(`Specialty: ${pathology.especialidad}`);
}
Cache: Results are cached for 30 minutes with key by_${id}.
Search pathologies by name or specialty.
patologies.search(searchTerm: string): Promise<Pathology[]>
searchTerm
string
required
Search term to match against name or specialty
Returns: Up to 12 matching active pathologies ordered by name.
results
array
Each result includes: id, nombre, codcie10, especialidad, sexo
Example:
import { api } from '../lib/api';

// Search by pathology name
const diabetesResults = await api.patologies.search('diabetes');

// Search by specialty
const cardioResults = await api.patologies.search('cardiología');

// Display results
diabetesResults.forEach(p => {
  console.log(`${p.nombre} (${p.codcie10})`);
});
Search behavior:
  • Case-insensitive partial matching
  • Searches both nombre and especialidad fields
  • Returns only active pathologies (activo = true)
  • Limited to 12 results
Cache: Results are cached for 30 minutes with key search_${searchTerm}.

create

Create a new pathology record.
patologies.create(payload: PathologyPayload): Promise<Pathology>
payload
object
required
Pathology data
payload.nombre
string
required
Pathology name
payload.codcie10
string
ICD-10 code
payload.especialidad
string
Medical specialty
payload.sexo
string
Applicable gender (if gender-specific)
payload.activo
boolean
default:true
Whether pathology is active
Example:
import { api } from '../lib/api';

const newPathology = await api.patologies.create({
  nombre: 'Diabetes Mellitus Tipo 2',
  codcie10: 'E11',
  especialidad: 'Endocrinología',
  sexo: null, // Applies to all genders
  activo: true
});

console.log(`Created pathology with ID: ${newPathology.id}`);
Auto-populated fields:
  • idusuario - Set from current session
  • idbu - Set from current business unit
Cache invalidation: Clears all cache keys after creation.

update

Update an existing pathology record.
patologies.update(
  id: string,
  payload: Partial<PathologyPayload>
): Promise<Pathology>
id
string
required
The pathology’s unique identifier (UUID)
payload
object
required
Partial pathology data to update
Example:
import { api } from '../lib/api';

// Update ICD-10 code
await api.patologies.update('abc-123-def', {
  codcie10: 'E11.9'
});

// Deactivate a pathology
await api.patologies.update('abc-123-def', {
  activo: false
});

// Update specialty
await api.patologies.update('abc-123-def', {
  especialidad: 'Medicina Interna'
});
Cache invalidation: Clears all cache keys after update.

delete

Permanently delete a pathology record.
patologies.delete(id: string): Promise<void>
id
string
required
The pathology’s unique identifier (UUID)
Example:
import { api } from '../lib/api';

await api.patologies.delete('abc-123-def');
console.log('Pathology deleted');
Warning: This is a hard delete operation. Consider using the update method to set activo: false instead for soft deletion. Cache invalidation: Clears all cache keys after deletion.

Type definitions

interface Pathology {
  id: string;
  created_at: string;
  updated_at: string;
  nombre: string;
  codcie10: string | null;
  especialidad: string | null;
  sexo: string | null;
  activo: boolean;
  idUsuario: string | null;
  idbu: string | null;
}

interface PathologyPayload {
  nombre: string;
  codcie10?: string | null;
  especialidad?: string | null;
  sexo?: string | null;
  activo?: boolean;
}

Common use cases

import { api } from '../lib/api';
import { useState, useEffect } from 'react';

function PathologyAutocomplete({ value, onChange }) {
  const [results, setResults] = useState([]);
  const [search, setSearch] = useState('');
  
  useEffect(() => {
    if (search.length > 2) {
      api.patologies.search(search).then(setResults);
    }
  }, [search]);
  
  return (
    <div>
      <input
        value={search}
        onChange={(e) => setSearch(e.target.value)}
        placeholder="Search pathologies..."
      />
      <ul>
        {results.map(p => (
          <li key={p.id} onClick={() => onChange(p)}>
            {p.nombre} ({p.codcie10})
          </li>
        ))}
      </ul>
    </div>
  );
}

Filter by specialty

import { api } from '../lib/api';

const allActive = await api.patologies.getAllActive();

// Filter by specialty
const cardiology = allActive.filter(
  p => p.especialidad === 'Cardiología'
);

console.log(`Cardiology pathologies: ${cardiology.length}`);

Gender-specific pathologies

import { api } from '../lib/api';

const allActive = await api.patologies.getAllActive();

// Get pathologies for female patients
const femalePathologies = allActive.filter(
  p => p.sexo === null || p.sexo === 'Femenino'
);

// Get pathologies for male patients
const malePathologies = allActive.filter(
  p => p.sexo === null || p.sexo === 'Masculino'
);

Source location

~/workspace/source/src/services/patologyService.ts

Build docs developers (and LLMs) love