The Patient Service provides methods to create, read, and update patient records in the system. All operations are cached for improved performance.
Methods
getAll
Retrieve all patients in the system.
patients.getAll(): Promise<Patient[]>
Array of patient objects with basic information
Returns:
Patient objects include: id, Nombre, Paterno, Materno, FechaNacimiento, Sexo, Telefono, Email, Refiere
Example:
import { api } from '../lib/api';
const patients = await api.patients.getAll();
console.log(`Found ${patients.length} patients`);
Cache:
Results are cached for 20 minutes with key 'all'.
getById
Retrieve a single patient by ID with complete information.
patients.getById(id: string): Promise<Patient | null>
The patient’s unique identifier (UUID)
Complete patient record including all fields:Date of birth (ISO 8601 format)
Gender (Masculino/Femenino)
ID of the user who created the record
Example:
import { api } from '../lib/api';
// From PatientReport.tsx
const data = await api.patients.getById(patientId);
if (data) {
console.log(`Patient: ${data.Nombre} ${data.Paterno}`);
}
Cache:
Results are cached for 20 minutes with key by_${id}.
create
Create a new patient record.
patients.create(payload: PatientPayload): Promise<Patient>
Patient data objectDate of birth (ISO 8601 format)
Gender (Masculino/Femenino)
Example:
import { api } from '../lib/api';
// From PatientForm.tsx
const patientData = {
Nombre: 'Juan',
Paterno: 'Pérez',
Materno: 'García',
FechaNacimiento: '1990-05-15',
Sexo: 'Masculino',
Email: '[email protected]',
Telefono: '5551234567',
EstadoCivil: 'Soltero'
};
const savedPatient = await api.patients.create(patientData);
console.log(`Created patient with ID: ${savedPatient.id}`);
Cache invalidation:
Clears the 'all' cache key after creation.
update
Update an existing patient record.
patients.update(id: string, payload: Partial<PatientPayload>): Promise<Patient>
The patient’s unique identifier (UUID)
Partial patient data object with fields to update
Example:
import { api } from '../lib/api';
// From PatientForm.tsx
const updatedData = {
Email: '[email protected]',
Telefono: '5559876543'
};
const savedPatient = await api.patients.update(patient.id, updatedData);
Error handling:
Throws an error with message 'No se pudo actualizar el paciente' if the update fails.
Cache invalidation:
Clears both 'all' and by_${id} cache keys after update.
Type definitions
interface Patient {
id: string;
created_at: string;
updated_at: string;
Nombre: string;
Paterno: string;
Materno: string;
FechaNacimiento: string;
CURP: string | null;
RFC: string | null;
Sexo: string;
EstadoCivil: string;
Email: string | null;
Telefono: string | null;
Calle: string | null;
Colonia: string | null;
CodigoPostal: string | null;
Poblacion: string | null;
Municipio: string | null;
EntidadFederativa: string | null;
Ocupacion: string | null;
TipoSangre: string | null;
Alergias: string[] | null;
ContactoEmergencia: string | null;
Aseguradora: string | null;
Responsable: string | null;
Refiere: string | null;
Observaciones: string | null;
deleted_at: string | null;
user_id: string | null;
idbu: string;
}
Source location
~/workspace/source/src/services/patientService.ts