Skip to content

Commit 1f25f00

Browse files
committed
Merge branch 'master' into COM-118
2 parents e19a42b + 4347d6b commit 1f25f00

13 files changed

Lines changed: 138 additions & 97 deletions

File tree

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
# [5.143.0](https://github.com/andes/api/compare/v5.142.0...v5.143.0) (2026-04-01)
2+
3+
4+
### Features
5+
6+
* **TOP:** modifica filtros para listado de solicitudes ([#2186](https://github.com/andes/api/issues/2186)) ([324e3b3](https://github.com/andes/api/commit/324e3b31190459f02e80606a8d9a1de3b3df3dd9))
7+
18
# [5.142.0](https://github.com/andes/api/compare/v5.141.0...v5.142.0) (2026-03-25)
29

310

auth/auth.class.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,13 @@ export class Auth {
226226

227227
};
228228

229+
if (payload.organizacion.fechaVencimiento) {
230+
const now = new Date();
231+
const fechaVencimiento = new Date(payload.organizacion.fechaVencimiento);
232+
if (fechaVencimiento < now) {
233+
return next(403);
234+
}
235+
}
229236

230237
return next();
231238
} else {

auth/auth.controller.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ export function createPayload(user, authOrg, prof) {
6565
},
6666
profesional: prof && String(prof._id),
6767
permisos: [...user.permisosGlobales, ...authOrg.permisos],
68+
fechaVencimiento: authOrg.fechaVencimiento,
6869
feature: { ...(user.configuracion || {}) }
6970
};
7071
}
@@ -77,6 +78,7 @@ export async function findTokenData(username: number, organizacion: ObjectId) {
7778
const pProfesional = Profesional.findOne({ documento: String(username), habilitado: { $ne: false } }, { nombre: true, apellido: true });
7879
const [auth, prof]: [any, any] = await Promise.all([pAuth, pProfesional]);
7980
if (auth) {
81+
await checkAndInactivateExpired(auth);
8082
const authOrganizacion = auth.organizaciones.find(item => String(item._id) === String(organizacion));
8183
return {
8284
usuario: auth,
@@ -130,6 +132,7 @@ export async function findUser(username) {
130132
const pProfesional = Profesional.findOne({ documento: username, habilitado: { $ne: false } }, { matriculas: true, especialidad: true });
131133
const [auth, prof] = await Promise.all([pAuth, pProfesional]);
132134
if (auth) {
135+
await checkAndInactivateExpired(auth);
133136
return {
134137
user: auth,
135138
profesional: prof
@@ -138,6 +141,24 @@ export async function findUser(username) {
138141
return null;
139142
}
140143

144+
/**
145+
* Chequea las organizaciones del usuario e inactiva las que tienen fecha de vencimiento cumplida.
146+
* @param {any} user Instancia de AuthUsers
147+
*/
148+
export async function checkAndInactivateExpired(user) {
149+
let changed = false;
150+
const now = new Date();
151+
user.organizaciones.forEach(org => {
152+
if (org.activo && org.fechaVencimiento && org.fechaVencimiento < now) {
153+
org.activo = false;
154+
changed = true;
155+
}
156+
});
157+
if (changed) {
158+
user.audit(userScheduler);
159+
await user.save();
160+
}
161+
}
141162

142163
export async function updateUser(documento, nombre, apellido, password) {
143164
return await AuthUsers.findOneAndUpdate(

auth/schemas/authUsers.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ export interface IAuthUsers {
2323
nombre: string;
2424
}[];
2525
lastLogin: Date;
26+
fechaVencimiento?: Date;
2627
}[];
2728
lastLogin: Date;
2829
tipo?: String;

auth/schemas/permisos-organizaciones.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ export const PermisosOrganizacionesSchema = new Schema({
1111
_id: Types.ObjectId,
1212
nombre: String
1313
}],
14-
lastLogin: Date
14+
lastLogin: Date,
15+
fechaVencimiento: Date
1516
});
1617
PermisosOrganizacionesSchema.plugin(AuditPlugin);
1718

core/log/routes/logPaciente.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ router.get('/paciente', (req, res, next) => {
2222
if (req.query.idPaciente) {
2323
query.where('paciente').equals(Types.ObjectId(req.query.idPaciente));
2424
}
25+
if (req.query.ids) {
26+
const ids = (req.query.ids as string).split(',').map(id => Types.ObjectId(id));
27+
query.where('paciente').in(ids);
28+
}
2529
if (req.query.operacion) {
2630
query.where('operacion').equals(req.query.operacion);
2731
}
@@ -33,6 +37,9 @@ router.get('/paciente', (req, res, next) => {
3337

3438
query.sort({ createdAt: -1 });
3539

40+
if (req.query.skip) { query.skip(parseInt(req.query.skip as string, 10)); }
41+
if (req.query.limit) { query.limit(parseInt(req.query.limit as string, 10)); }
42+
3643
query.exec((err, data) => {
3744
if (err) {
3845
return next(err);

modules/centroOperativoMedico/derivaciones.routes.ts

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -31,22 +31,6 @@ class DerivacionesResource extends ResourceBase {
3131
return { $ne: null };
3232
}
3333
},
34-
estrategia: {
35-
field: 'estrategiaAtencion.id',
36-
fn: (value) => {
37-
if (!value || value === 'null') {
38-
return {
39-
$or: [
40-
{ estrategiaAtencion: null },
41-
{ estrategiaAtencion: { $exists: false } },
42-
{ 'estrategiaAtencion.id': { $exists: false } },
43-
{ 'estrategiaAtencion.id': null }
44-
]
45-
};
46-
}
47-
return value;
48-
}
49-
},
5034
estrategiaAtencion: {
5135
field: 'estrategiaAtencion.id',
5236
fn: (value) => {

modules/descargas/com/derivacion-body.ts

Lines changed: 63 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,6 @@ export class DerivacionBody extends HTMLComponent {
5252
</div>
5353
</div>
5454
<br>
55-
<div class="row">
56-
<div class="col">
57-
<span>ID:
58-
{{ idDerivacion }}</span>
59-
</div>
60-
</div>
6155
<div class="row">
6256
<div class="col">
6357
<span>ORIGEN:
@@ -82,11 +76,54 @@ export class DerivacionBody extends HTMLComponent {
8276
<span>FECHA Y HORA DE DERIVACIÓN: {{ fecha }} hs</span>
8377
</div>
8478
</div>
79+
{{#if motivo}}
80+
<div class="row" >
81+
<div class="col">
82+
<span>Motivo:
83+
{{ motivo }}</span>
84+
</div>
85+
</div>
86+
{{/if}}
87+
{{#if diagnosticoActual}}
88+
<div class="row" >
89+
<div class="col">
90+
<span>Diagnóstico Actual:
91+
{{ diagnosticoActual }}</span>
92+
</div>
93+
</div>
94+
{{/if}}
95+
{{#if estadoClinico}}
96+
<div class="row" >
97+
<div class="col">
98+
<span>Estado Clínico:
99+
{{ estadoClinico }}</span>
100+
</div>
101+
</div>
102+
{{/if}}
103+
{{#if condicion}}
104+
<div class="row" >
105+
<div class="col">
106+
<span>Condición:
107+
{{ condicion }}</span>
108+
</div>
109+
</div>
110+
{{/if}}
111+
{{#if necesidad}}
112+
<div class="row" >
113+
<div class="col">
114+
<span>Necesidad:
115+
{{ necesidad }}</span>
116+
</div>
117+
</div>
118+
{{/if}}
85119
{{#if tipoTraslado}}
86120
<div class="row" >
87121
<div class="col">
88122
<span>TIPO TRASLADO:
89123
{{ tipoTraslado.nombre }}</span>
124+
<br>
125+
<span>FECHA y HORA DE TRASLADO:
126+
{{ fechaTraslado }}</span>
90127
</div>
91128
</div>
92129
{{/if}}
@@ -137,11 +174,13 @@ export class DerivacionBody extends HTMLComponent {
137174
{{ datosSolicitud.usuario }}</span>
138175
</div>
139176
</div>
140-
<div class="row">
141-
<div class="col">
142-
<span>DETALLE: {{ datosSolicitud.detalle }}</span>
177+
{{#if datosSolicitud.detalle}}
178+
<div class="row">
179+
<div class="col">
180+
<span>DETALLE: {{ datosSolicitud.detalle }}</span>
181+
</div>
143182
</div>
144-
</div>
183+
{{/if}}
145184
{{/if}}
146185
{{#if dispositivoOxigeno}}
147186
<br><br>
@@ -152,62 +191,14 @@ export class DerivacionBody extends HTMLComponent {
152191
</div>
153192
<div class="row" >
154193
<div class="col">
155-
<span>{{ dispositivoOxigeno }}</span>
194+
<span>FECHA y HORA: {{ fechaDispositivo }}</span>
156195
</div>
157196
</div>
158-
{{/if}}
159-
160-
{{#if historial }}
161-
<br><br>
162-
<div class="row">
163-
<div class="col">
164-
<span><b>HISTORIAL DE DERIVACIÓN</b></span>
197+
<div class="row" >
198+
<div class="col">
199+
<span>{{ dispositivoOxigeno }}</span>
200+
</div>
165201
</div>
166-
</div>
167-
<style>
168-
table, th, td {
169-
border: 1px solid grey;
170-
}
171-
172-
table {
173-
border-collapse: collapse;
174-
page-break-before: always;
175-
float:left;
176-
font-size: 7px;
177-
line-height: normal;
178-
}
179-
180-
</style>
181-
<br/>
182-
<font size="1" >
183-
<table>
184-
<thead style='display: table-header-group' >
185-
<th>Fecha</th>
186-
{{#if reporteCOM }}<th>Organización</th>{{/if}}
187-
<th>Evento</th>
188-
{{#if reporteCOM }}<th>Prioridad</th>{{/if}}
189-
<th>Observación</th>
190-
<th>Usuario</th>
191-
{{#if reporteCOM }}<th>Org. Destino</th>{{/if}}
192-
</thead>
193-
194-
{{#each historial}}
195-
196-
<tr>
197-
<td>{{ fechaCreacion }}</td>
198-
{{#if reporteCOM }}<td>{{ createdBy.organizacion.nombre }}</td>{{/if}}
199-
<td>{{#if estado }}{{ estado }}{{/if}} {{#if esActualizacion }}actualización{{/if}}</td>
200-
{{#if reporteCOM }}<td>{{#if prioridad}}{{ prioridad }}{{/if}}</td>{{/if}}
201-
<td>{{#if observacion}}{{observacion}}{{/if}}</td>
202-
<td>{{ createdBy.nombreCompleto }}</td>
203-
{{#if reporteCOM }}<td>{{#if organizacionDestino}}{{ organizacionDestino.nombre }}{{/if}}</td>{{/if}}
204-
</tr>
205-
206-
{{/each}}
207-
208-
</table>
209-
</font>
210-
211202
{{/if}}
212203
213204
{{#if firmaHTML}}
@@ -241,22 +232,29 @@ export class DerivacionBody extends HTMLComponent {
241232
const organizacion = this._data.historial && this._data.organizacionId ? await Organizacion.findById(this._data.organizacionId) : null;
242233
const historial = this._data.historial ? await this.getHistorialDerivacion(organizacion, derivacion) : null;
243234
this.data = {
244-
idDerivacion: derivacion._id,
245235
nombre: derivacion.paciente.nombre,
246236
apellido: derivacion.paciente.apellido,
247237
dni: derivacion.paciente.documento,
248238
fechaNacimiento: moment(derivacion.paciente.fechaNacimiento).format('DD/MM/YYYY'),
249239
sexo: derivacion.paciente.sexo,
250240
obraSocial: derivacion.paciente.obraSocial,
251241
organizacionOrigen: derivacion.organizacionOrigen.nombre,
242+
fechaCreacion: derivacion.createdAt,
243+
creadaPor: derivacion.createdBy.nombreCompleto,
252244
organizacionDestino: derivacion.organizacionDestino?.nombre,
253-
unidadDestino: derivacion.unidadDestino?.term,
245+
motivo: derivacion.motivoDerivacion,
246+
diagnosticoActual: derivacion.diagnosticoActual,
247+
estadoClinico: derivacion.estadoClinico,
248+
condicion: derivacion.condicion,
249+
necesidad: derivacion.necesidad,
254250
dispositivoOxigeno: derivacion.dispositivo ? `${derivacion.dispositivo.nombre}, ${derivacion.dispositivo.descripcion}` : null,
251+
fechaDispositivo: derivacion.dispositivo ? moment(derivacion.dispositivo.createdAt).format('DD/MM/YYYY HH:mm') : null,
255252
fecha,
256253
finalizada,
257254
fechaFinalizacion: moment(fechaFinalizacion).format('DD/MM/YYYY HH:mm'),
258255
profesionalFinalizacion: profesional,
259256
tipoTraslado: derivacion.tipoTraslado,
257+
fechaTraslado: derivacion.tipoTraslado ? moment(derivacion.fechaTraslado).format('DD/MM/YYYY HH:mm') : null,
260258
organizacionTraslado: derivacion.organizacionTraslado,
261259
datosSolicitud,
262260
firmaHTML,

modules/rup/controllers/rup.events.ts

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ EventCore.on('prestacion:receta:create', async ({ prestacion, registro }) => {
3434

3535
const pacienteCUIL = prestacion.paciente.cuil || generarCUIL(prestacion.paciente.documento, prestacion.paciente.sexo);
3636

37-
const dataReceta = {
37+
const dataRecetaBase = {
3838
idPrestacion: prestacion.id,
3939
idRegistro,
4040
fechaRegistro: prestacion.ejecucion.fecha || moment().toDate(),
@@ -45,18 +45,33 @@ EventCore.on('prestacion:receta:create', async ({ prestacion, registro }) => {
4545
medicamento: null,
4646
diagnostico: null,
4747
};
48-
49-
dataReceta.paciente.cuil = pacienteCUIL;
48+
dataRecetaBase.paciente.cuil = pacienteCUIL;
5049

5150
for (const medicamento of registro.valor.medicamentos) {
52-
const receta: any = await Receta.findOne({
53-
'medicamento.concepto.conceptId': medicamento.generico.conceptId,
54-
idRegistro
55-
});
56-
if (!receta) {
57-
dataReceta.medicamento = medicamento;
58-
dataReceta.diagnostico = medicamento.diagnostico;
59-
await crearReceta(dataReceta, prestacion.createdBy); // falta return
51+
try {
52+
const conceptId = medicamento?.concepto?.conceptId || medicamento?.generico?.conceptId;
53+
54+
if (!conceptId) {
55+
logger.error('prestacion:receta:create', { idRegistro, medicamento }, 'No se pudo identificar conceptId del medicamento');
56+
continue;
57+
}
58+
59+
const receta: any = await Receta.findOne({
60+
'medicamento.concepto.conceptId': conceptId,
61+
idRegistro
62+
});
63+
64+
if (!receta) {
65+
const dataReceta = {
66+
...dataRecetaBase,
67+
medicamento,
68+
diagnostico: medicamento?.diagnostico || null,
69+
};
70+
71+
await crearReceta(dataReceta, prestacion.createdBy);
72+
}
73+
} catch (errorMedicamento) {
74+
logger.error('prestacion:receta:create', { idRegistro, medicamento }, errorMedicamento);
6075
}
6176

6277
}

modules/rup/prestaciones.interface.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ export interface IPrestacion {
4343
}
4444

4545
export interface IPrestacionEstado {
46-
tipo: 'anulada' | 'pendiente' | 'ejecucion' | 'auditoria' | 'aceptada' | 'rechazada' | 'validada' | 'desvinculada' | 'modificada' | 'asignada' | 'vencida';
46+
tipo: 'anulada' | 'pendiente' | 'ejecucion' | 'auditoria' | 'aceptada' | 'rechazada' | 'validada' | 'desvinculada' | 'modificada' | 'asignada' | 'vencida' | 'resuelta';
4747
idOrigenModifica?: string;
4848
motivoRechazo?: string;
4949
observaciones?: string;

0 commit comments

Comments
 (0)