Skip to main content
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[]>
returns
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>
id
string
required
The patient’s unique identifier (UUID)
patient
object
Complete patient record including all fields:
id
string
Patient UUID
Nombre
string
First name
Paterno
string
Paternal last name
Materno
string
Maternal last name
FechaNacimiento
string
Date of birth (ISO 8601 format)
Sexo
string
Gender (Masculino/Femenino)
Email
string | null
Email address
Telefono
string | null
Phone number
CURP
string | null
Mexican national ID
user_id
string
ID of the user who created the record
idbu
string
Business unit ID
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>
payload
object
required
Patient data object
payload.Nombre
string
required
First name
payload.Paterno
string
required
Paternal last name
payload.Materno
string
Maternal last name
payload.FechaNacimiento
string
required
Date of birth (ISO 8601 format)
payload.Sexo
string
required
Gender (Masculino/Femenino)
payload.Email
string
Email address
payload.Telefono
string
Phone number
payload.CURP
string
Mexican national ID
payload.EstadoCivil
string
Marital status
payload.Alergias
string[]
List of allergies
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>
id
string
required
The patient’s unique identifier (UUID)
payload
object
required
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

Build docs developers (and LLMs) love