Pacientes
Los pacientes representan personas bajo atencion medica dentro de la plataforma. Esta API permite gestionar sus datos personales, registros medicos, codigo REPROCANN e historial clinico completo.
El acceso a los endpoints de pacientes requiere permisos medicos. Solo usuarios con rol doctor o admin pueden consultar y modificar datos de pacientes.
El modelo de Paciente
El modelo de paciente contiene informacion personal, estado de registro REPROCANN, registro medico y datos de seguimiento.
Propiedades
- Name
id- Type
- string
- Description
Identificador unico del paciente.
- Name
firstName- Type
- string
- Description
Nombre del paciente.
- Name
lastName- Type
- string
- Description
Apellido del paciente.
- Name
email- Type
- string
- Description
Email del paciente.
- Name
phoneNumber- Type
- string
- Description
Telefono de contacto.
- Name
dateOfBirth- Type
- string
- Description
Fecha de nacimiento (formato ISO).
- Name
gender- Type
- string
- Description
Genero del paciente.
- Name
address- Type
- string
- Description
Direccion del paciente.
- Name
avatar- Type
- string
- Description
URL del avatar del paciente.
- Name
status- Type
- PatientStatus
- Description
Estado del paciente. Valores posibles:
- ACTIVE: Paciente activo en tratamiento
- INACTIVE: Paciente dado de baja o sin actividad
- PENDING: Pendiente de aprobacion o primer consulta
- Name
hasReprocann- Type
- boolean
- Description
Indica si el paciente tiene codigo REPROCANN vigente.
- Name
medicalRecord- Type
- object
- Description
Registro medico del paciente.
- Name
reprocannCode- Type
- string
- Description
Codigo REPROCANN asignado.
- Name
reprocannExpiration- Type
- string
- Description
Fecha de vencimiento del REPROCANN.
- Name
allergies- Type
- array
- Description
Lista de alergias conocidas.
- Name
conditions- Type
- array
- Description
Condiciones medicas diagnosticadas.
- Name
medications- Type
- array
- Description
Medicaciones actuales.
- Name
emergencyContact- Type
- object
- Description
Contacto de emergencia.
- Name
name- Type
- string
- Description
Nombre del contacto.
- Name
phoneNumber- Type
- string
- Description
Telefono del contacto.
- Name
relationship- Type
- string
- Description
Relacion con el paciente.
- Name
memberId- Type
- string
- Description
ID del miembro asociado en la organizacion.
- Name
nextAppointment- Type
- string
- Description
Fecha de la proxima cita programada.
- Name
createdAt- Type
- timestamp
- Description
Fecha de creacion del registro.
- Name
updatedAt- Type
- timestamp
- Description
Ultima actualizacion del registro.
Ejemplo de paciente
{
"id": "pat_01HQ8XYZABC123",
"firstName": "Laura",
"lastName": "Martinez",
"email": "laura.martinez@email.com",
"phoneNumber": "+541134567890",
"dateOfBirth": "1990-03-15",
"gender": "Femenino",
"address": "Av. Santa Fe 2100, CABA",
"avatar": "https://storage.cannahub.tech/avatars/laura-m.jpg",
"status": "ACTIVE",
"hasReprocann": true,
"medicalRecord": {
"reprocannCode": "REPRO-2024-AR-005678",
"reprocannExpiration": "2025-06-15",
"allergies": ["Penicilina"],
"conditions": ["Dolor cronico lumbar", "Insomnio"],
"medications": ["Ibuprofeno 400mg"],
"emergencyContact": {
"name": "Roberto Martinez",
"phoneNumber": "+541134567891",
"relationship": "Esposo"
}
},
"memberId": "usr_01HQ8MBR456",
"nextAppointment": "2024-11-20T10:00:00Z",
"createdAt": "2024-01-10T08:00:00Z",
"updatedAt": "2024-10-15T16:30:00Z"
}
Listar pacientes
Este endpoint permite obtener una lista filtrada de pacientes.
Parametros de Consulta
- Name
status- Type
- PatientStatus
- Description
Filtrar por estado (
ACTIVE,INACTIVE,PENDING).
- Name
search- Type
- string
- Description
Busqueda por nombre, apellido o email.
- Name
hasReprocann- Type
- boolean
- Description
Filtrar por tenencia de codigo REPROCANN.
- Name
limit- Type
- integer
- Description
Cantidad maxima de resultados (default: 20).
- Name
offset- Type
- integer
- Description
Offset de inicio para paginacion.
Request
curl -G https://api.cannahub.tech/api/patients \
-H "Authorization: Bearer {token}" \
-d status=ACTIVE \
-d hasReprocann=true \
-d limit=10
Response
{
"patients": [
{
"id": "pat_01HQ8XYZABC123",
"firstName": "Laura",
"lastName": "Martinez",
"email": "laura.martinez@email.com",
"phoneNumber": "+541134567890",
"status": "ACTIVE",
"hasReprocann": true,
"nextAppointment": "2024-11-20T10:00:00Z",
"createdAt": "2024-01-10T08:00:00Z"
},
{
"id": "pat_01HQ8XYZDEF456",
"firstName": "Carlos",
"lastName": "Gomez",
"email": "carlos.gomez@email.com",
"phoneNumber": "+541198765432",
"status": "ACTIVE",
"hasReprocann": true,
"nextAppointment": "2024-11-22T14:00:00Z",
"createdAt": "2024-02-05T12:00:00Z"
}
],
"count": 2
}
Crear paciente
Este endpoint permite registrar un nuevo paciente en el sistema.
Campos Requeridos
- Name
firstName- Type
- string
- Description
Nombre del paciente.
- Name
lastName- Type
- string
- Description
Apellido del paciente.
- Name
email- Type
- string
- Description
Email del paciente (debe ser unico).
- Name
phoneNumber- Type
- string
- Description
Telefono de contacto.
Campos Opcionales
- Name
dateOfBirth- Type
- string
- Description
Fecha de nacimiento (formato ISO).
- Name
gender- Type
- string
- Description
Genero del paciente.
- Name
address- Type
- string
- Description
Direccion del paciente.
- Name
hasReprocann- Type
- boolean
- Description
Si tiene codigo REPROCANN (default:
false).
- Name
medicalRecord- Type
- object
- Description
Registro medico inicial.
- Name
reprocannCode- Type
- string
- Description
Codigo REPROCANN.
- Name
reprocannExpiration- Type
- string
- Description
Fecha de vencimiento del REPROCANN.
- Name
allergies- Type
- array
- Description
Lista de alergias conocidas.
- Name
conditions- Type
- array
- Description
Condiciones medicas.
- Name
medications- Type
- array
- Description
Medicaciones actuales.
- Name
emergencyContact- Type
- object
- Description
Contacto de emergencia.
Request
curl -X POST https://api.cannahub.tech/api/patients \
-H "Authorization: Bearer {token}" \
-H "Content-Type: application/json" \
-d '{
"firstName": "Laura",
"lastName": "Martinez",
"email": "laura.martinez@email.com",
"phoneNumber": "+541134567890",
"dateOfBirth": "1990-03-15",
"gender": "Femenino",
"hasReprocann": true,
"medicalRecord": {
"reprocannCode": "REPRO-2024-AR-005678",
"reprocannExpiration": "2025-06-15",
"allergies": ["Penicilina"],
"conditions": ["Dolor cronico lumbar"],
"medications": ["Ibuprofeno 400mg"]
}
}'
Response (201)
{
"patient": {
"id": "pat_01HQ8XYZABC123",
"firstName": "Laura",
"lastName": "Martinez",
"email": "laura.martinez@email.com",
"phoneNumber": "+541134567890",
"dateOfBirth": "1990-03-15",
"gender": "Femenino",
"status": "PENDING",
"hasReprocann": true,
"medicalRecord": {
"reprocannCode": "REPRO-2024-AR-005678",
"reprocannExpiration": "2025-06-15",
"allergies": ["Penicilina"],
"conditions": ["Dolor cronico lumbar"],
"medications": ["Ibuprofeno 400mg"],
"emergencyContact": null
},
"memberId": null,
"nextAppointment": null,
"createdAt": "2024-10-31T10:00:00Z",
"updatedAt": "2024-10-31T10:00:00Z"
}
}
Obtener paciente
Retorna los datos completos de un paciente especifico, incluyendo su registro medico y proxima cita.
Request
curl https://api.cannahub.tech/api/patients/pat_01HQ8XYZABC123 \
-H "Authorization: Bearer {token}"
Response
{
"patient": {
"id": "pat_01HQ8XYZABC123",
"firstName": "Laura",
"lastName": "Martinez",
"email": "laura.martinez@email.com",
"phoneNumber": "+541134567890",
"dateOfBirth": "1990-03-15",
"gender": "Femenino",
"address": "Av. Santa Fe 2100, CABA",
"avatar": "https://storage.cannahub.tech/avatars/laura-m.jpg",
"status": "ACTIVE",
"hasReprocann": true,
"medicalRecord": {
"reprocannCode": "REPRO-2024-AR-005678",
"reprocannExpiration": "2025-06-15",
"allergies": ["Penicilina"],
"conditions": ["Dolor cronico lumbar", "Insomnio"],
"medications": ["Ibuprofeno 400mg"],
"emergencyContact": {
"name": "Roberto Martinez",
"phoneNumber": "+541134567891",
"relationship": "Esposo"
}
},
"memberId": "usr_01HQ8MBR456",
"nextAppointment": "2024-11-20T10:00:00Z",
"createdAt": "2024-01-10T08:00:00Z",
"updatedAt": "2024-10-15T16:30:00Z"
}
}
Actualizar paciente
Este endpoint permite actualizar los datos de un paciente. Todos los campos son opcionales; solo se actualizan los campos enviados.
Campos Actualizables
- Name
firstName- Type
- string
- Description
Nombre del paciente.
- Name
lastName- Type
- string
- Description
Apellido del paciente.
- Name
email- Type
- string
- Description
Email del paciente.
- Name
phoneNumber- Type
- string
- Description
Telefono de contacto.
- Name
dateOfBirth- Type
- string
- Description
Fecha de nacimiento.
- Name
gender- Type
- string
- Description
Genero del paciente.
- Name
address- Type
- string
- Description
Direccion del paciente.
- Name
status- Type
- PatientStatus
- Description
Estado del paciente.
- Name
hasReprocann- Type
- boolean
- Description
Si tiene codigo REPROCANN.
- Name
medicalRecord- Type
- object
- Description
Registro medico (se fusiona con el existente).
Request
curl -X PATCH https://api.cannahub.tech/api/patients/pat_01HQ8XYZABC123 \
-H "Authorization: Bearer {token}" \
-H "Content-Type: application/json" \
-d '{
"status": "ACTIVE",
"address": "Av. Libertador 5000, CABA",
"medicalRecord": {
"conditions": ["Dolor cronico lumbar", "Insomnio", "Ansiedad"]
}
}'
Response
{
"patient": {
"id": "pat_01HQ8XYZABC123",
"firstName": "Laura",
"lastName": "Martinez",
"email": "laura.martinez@email.com",
"phoneNumber": "+541134567890",
"status": "ACTIVE",
"address": "Av. Libertador 5000, CABA",
"hasReprocann": true,
"medicalRecord": {
"reprocannCode": "REPRO-2024-AR-005678",
"reprocannExpiration": "2025-06-15",
"allergies": ["Penicilina"],
"conditions": ["Dolor cronico lumbar", "Insomnio", "Ansiedad"],
"medications": ["Ibuprofeno 400mg"],
"emergencyContact": {
"name": "Roberto Martinez",
"phoneNumber": "+541134567891",
"relationship": "Esposo"
}
},
"updatedAt": "2024-10-31T12:00:00Z"
}
}
Eliminar paciente
Este endpoint elimina un paciente del sistema.
La eliminacion es permanente y en cascada: se eliminan tambien las citas y prescripciones asociadas al paciente. Considera cambiar el estado a INACTIVE en lugar de eliminar.
Request
curl -X DELETE https://api.cannahub.tech/api/patients/pat_01HQ8XYZABC123 \
-H "Authorization: Bearer {token}"
Response
{
"success": true
}
Listar historial medico
Retorna las entradas del historial medico de un paciente. Cada entrada representa una interaccion clinica: consulta, prescripcion, estudio, procedimiento o nota.
Tipos de Entrada
| Tipo | Descripcion |
|---|---|
consultation | Consulta medica realizada |
prescription | Prescripcion emitida |
test | Estudio o analisis |
procedure | Procedimiento medico |
note | Nota clinica general |
Parametros de Consulta
- Name
type- Type
- string
- Description
Filtrar por tipo de entrada.
- Name
startDate- Type
- string
- Description
Fecha de inicio del rango (ISO).
- Name
endDate- Type
- string
- Description
Fecha de fin del rango (ISO).
Request
curl -G https://api.cannahub.tech/api/patients/pat_01HQ8XYZABC123/history \
-H "Authorization: Bearer {token}" \
-d type=consultation \
-d startDate=2024-01-01
Response
{
"entries": [
{
"id": "entry_01HQ9ABC001",
"type": "consultation",
"title": "Consulta de seguimiento mensual",
"description": "Paciente reporta mejoria en calidad de sueno. Dolor lumbar reducido de 7/10 a 4/10.",
"date": "2024-10-15T10:00:00Z",
"symptoms": ["Dolor lumbar", "Insomnio leve"],
"diagnosis": "Mejoria progresiva con tratamiento cannabico",
"treatment": "Continuar aceite CBD 30mg/dia, agregar THC 5mg nocturno",
"medications": [
{ "name": "Aceite CBD Full Spectrum", "dose": "30mg/dia" },
{ "name": "Aceite THC", "dose": "5mg nocturno" }
],
"followUpDate": "2024-11-15T10:00:00Z",
"createdAt": "2024-10-15T10:30:00Z"
},
{
"id": "entry_01HQ9ABC002",
"type": "prescription",
"title": "Prescripcion aceite CBD",
"description": "Prescripcion inicial de aceite CBD para dolor cronico lumbar.",
"date": "2024-06-10T14:00:00Z",
"medications": [
{ "name": "Aceite CBD Full Spectrum", "dose": "20mg/dia" }
],
"createdAt": "2024-06-10T14:15:00Z"
}
],
"count": 2
}
Crear entrada de historial
Agrega una nueva entrada al historial medico del paciente.
Campos Requeridos
- Name
type- Type
- string
- Description
Tipo de entrada:
consultation,prescription,test,procedure,note.
- Name
title- Type
- string
- Description
Titulo descriptivo de la entrada.
- Name
description- Type
- string
- Description
Descripcion detallada.
Campos Opcionales
- Name
date- Type
- timestamp
- Description
Fecha de la entrada (default: fecha actual).
- Name
symptoms- Type
- array
- Description
Sintomas reportados por el paciente.
- Name
diagnosis- Type
- string
- Description
Diagnostico clinico.
- Name
treatment- Type
- string
- Description
Tratamiento indicado.
- Name
medications- Type
- array
- Description
Medicaciones prescritas o ajustadas.
- Name
followUpDate- Type
- timestamp
- Description
Fecha sugerida para proximo control.
Request
curl -X POST https://api.cannahub.tech/api/patients/pat_01HQ8XYZABC123/history \
-H "Authorization: Bearer {token}" \
-H "Content-Type: application/json" \
-d '{
"type": "consultation",
"title": "Consulta de seguimiento mensual",
"description": "Paciente reporta mejoria en calidad de sueno. Dolor reducido.",
"symptoms": ["Dolor lumbar leve", "Insomnio esporadico"],
"diagnosis": "Mejoria progresiva con tratamiento cannabico",
"treatment": "Continuar aceite CBD 30mg/dia, agregar THC 5mg nocturno",
"medications": [
{ "name": "Aceite CBD Full Spectrum", "dose": "30mg/dia" },
{ "name": "Aceite THC", "dose": "5mg nocturno" }
],
"followUpDate": "2024-11-15T10:00:00Z"
}'
Response (201)
{
"entry": {
"id": "entry_01HQ9ABC003",
"type": "consultation",
"title": "Consulta de seguimiento mensual",
"description": "Paciente reporta mejoria en calidad de sueno. Dolor reducido.",
"date": "2024-10-31T10:00:00Z",
"symptoms": ["Dolor lumbar leve", "Insomnio esporadico"],
"diagnosis": "Mejoria progresiva con tratamiento cannabico",
"treatment": "Continuar aceite CBD 30mg/dia, agregar THC 5mg nocturno",
"medications": [
{ "name": "Aceite CBD Full Spectrum", "dose": "30mg/dia" },
{ "name": "Aceite THC", "dose": "5mg nocturno" }
],
"followUpDate": "2024-11-15T10:00:00Z",
"createdAt": "2024-10-31T10:00:00Z"
}
}
Obtener entrada de historial
Retorna una entrada especifica del historial medico del paciente.
Request
curl https://api.cannahub.tech/api/patients/pat_01HQ8XYZABC123/history/entry_01HQ9ABC001 \
-H "Authorization: Bearer {token}"
Response
{
"entry": {
"id": "entry_01HQ9ABC001",
"type": "consultation",
"title": "Consulta de seguimiento mensual",
"description": "Paciente reporta mejoria en calidad de sueno. Dolor lumbar reducido de 7/10 a 4/10.",
"date": "2024-10-15T10:00:00Z",
"symptoms": ["Dolor lumbar", "Insomnio leve"],
"diagnosis": "Mejoria progresiva con tratamiento cannabico",
"treatment": "Continuar aceite CBD 30mg/dia, agregar THC 5mg nocturno",
"medications": [
{ "name": "Aceite CBD Full Spectrum", "dose": "30mg/dia" },
{ "name": "Aceite THC", "dose": "5mg nocturno" }
],
"followUpDate": "2024-11-15T10:00:00Z",
"createdAt": "2024-10-15T10:30:00Z"
}
}
Actualizar entrada de historial
Actualiza una entrada existente del historial medico. Solo se modifican los campos enviados.
Campos Actualizables
- Name
title- Type
- string
- Description
Titulo de la entrada.
- Name
description- Type
- string
- Description
Descripcion detallada.
- Name
symptoms- Type
- array
- Description
Sintomas reportados.
- Name
diagnosis- Type
- string
- Description
Diagnostico clinico.
- Name
treatment- Type
- string
- Description
Tratamiento indicado.
- Name
medications- Type
- array
- Description
Medicaciones.
- Name
followUpDate- Type
- timestamp
- Description
Fecha de proximo control.
Request
curl -X PATCH https://api.cannahub.tech/api/patients/pat_01HQ8XYZABC123/history/entry_01HQ9ABC001 \
-H "Authorization: Bearer {token}" \
-H "Content-Type: application/json" \
-d '{
"diagnosis": "Mejoria significativa. Dolor reducido de 7/10 a 3/10.",
"treatment": "Reducir ibuprofeno. Mantener CBD 30mg y THC 5mg nocturno.",
"followUpDate": "2024-12-15T10:00:00Z"
}'
Response
{
"entry": {
"id": "entry_01HQ9ABC001",
"type": "consultation",
"title": "Consulta de seguimiento mensual",
"description": "Paciente reporta mejoria en calidad de sueno. Dolor lumbar reducido de 7/10 a 4/10.",
"date": "2024-10-15T10:00:00Z",
"diagnosis": "Mejoria significativa. Dolor reducido de 7/10 a 3/10.",
"treatment": "Reducir ibuprofeno. Mantener CBD 30mg y THC 5mg nocturno.",
"followUpDate": "2024-12-15T10:00:00Z",
"updatedAt": "2024-10-31T12:00:00Z"
}
}
Eliminar entrada de historial
Elimina una entrada del historial medico del paciente.
La eliminacion es permanente. Se recomienda agregar una nota correctiva en lugar de eliminar entradas del historial clinico para mantener la trazabilidad.
Request
curl -X DELETE https://api.cannahub.tech/api/patients/pat_01HQ8XYZABC123/history/entry_01HQ9ABC001 \
-H "Authorization: Bearer {token}"
Response
{
"success": true
}
React Query Hooks
Cannahub provee hooks de React Query para gestionar pacientes e historial medico.
Query Keys
export const patientKeys = {
all: ['patients'] as const,
lists: () => [...patientKeys.all, 'list'] as const,
list: (filters?: PatientFilters) => [...patientKeys.lists(), filters] as const,
details: () => [...patientKeys.all, 'detail'] as const,
detail: (id: string) => [...patientKeys.details(), id] as const,
history: (id: string) => [...patientKeys.detail(id), 'history'] as const,
historyEntry: (id: string, entryId: string) =>
[...patientKeys.history(id), entryId] as const,
}
Queries
import {
usePatientsQuery,
usePatientQuery,
usePatientHistoryQuery,
usePatientHistoryEntryQuery
} from '@/features/Medical/Patients/hooks'
// Listar pacientes con filtros
const { data } = usePatientsQuery({
status: 'ACTIVE',
hasReprocann: true
})
// Obtener paciente individual
const { data: patient } = usePatientQuery('pat_01HQ8XYZABC123')
// Obtener historial medico
const { data: history } = usePatientHistoryQuery('pat_01HQ8XYZABC123', {
type: 'consultation'
})
// Obtener entrada especifica
const { data: entry } = usePatientHistoryEntryQuery(
'pat_01HQ8XYZABC123',
'entry_01HQ9ABC001'
)
Mutations
import {
useCreatePatientMutation,
useUpdatePatientMutation,
useDeletePatientMutation,
useCreateHistoryEntryMutation,
useUpdateHistoryEntryMutation,
useDeleteHistoryEntryMutation
} from '@/features/Medical/Patients/hooks'
// Crear paciente
const { mutate: createPatient } = useCreatePatientMutation()
createPatient({
firstName: 'Laura',
lastName: 'Martinez',
email: 'laura@email.com',
phoneNumber: '+541134567890'
})
// Actualizar paciente
const { mutate: updatePatient } = useUpdatePatientMutation()
updatePatient({
id: 'pat_01HQ8XYZABC123',
data: { status: 'ACTIVE', address: 'Av. Libertador 5000' }
})
// Eliminar paciente
const { mutate: deletePatient } = useDeletePatientMutation()
deletePatient('pat_01HQ8XYZABC123')
// Crear entrada de historial
const { mutate: createEntry } = useCreateHistoryEntryMutation()
createEntry({
patientId: 'pat_01HQ8XYZABC123',
data: {
type: 'consultation',
title: 'Consulta de control',
description: 'Seguimiento mensual del tratamiento.'
}
})
// Actualizar entrada de historial
const { mutate: updateEntry } = useUpdateHistoryEntryMutation()
updateEntry({
patientId: 'pat_01HQ8XYZABC123',
entryId: 'entry_01HQ9ABC001',
data: { diagnosis: 'Mejoria significativa' }
})
// Eliminar entrada de historial
const { mutate: deleteEntry } = useDeleteHistoryEntryMutation()
deleteEntry({
patientId: 'pat_01HQ8XYZABC123',
entryId: 'entry_01HQ9ABC001'
})
Cache Invalidation
Todas las mutaciones invalidan automaticamente las query keys relevantes:
// Mutaciones de paciente invalidan:
queryClient.invalidateQueries({ queryKey: patientKeys.all })
queryClient.invalidateQueries({ queryKey: patientKeys.detail(id) })
// Mutaciones de historial invalidan:
queryClient.invalidateQueries({ queryKey: patientKeys.history(patientId) })
queryClient.invalidateQueries({ queryKey: patientKeys.historyEntry(patientId, entryId) })