Skip to content

Commit

Permalink
feat(CIT): implementa historial de estados en agendas (#2000)
Browse files Browse the repository at this point in the history
  • Loading branch information
ma7payne authored Jan 3, 2025
1 parent 3d11d3d commit 855ae22
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 3 deletions.
14 changes: 12 additions & 2 deletions modules/turnos/controller/agenda.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { NotificationService } from '../../../modules/mobileApp/controller/Notif
import { toArray } from '../../../utils/utils';
import * as prestacionController from '../../rup/controllers/prestacion';
import { Prestacion } from '../../rup/schemas/prestacion';
import { Agenda } from '../../turnos/schemas/agenda';
import { Agenda, HistorialAgenda } from '../../turnos/schemas/agenda';
import { agendaLog } from '../citasLog';
import { SnomedCIE10Mapping } from './../../../core/term/controller/mapping';
import * as cie10 from './../../../core/term/schemas/cie10';
Expand Down Expand Up @@ -426,6 +426,13 @@ export async function agregarSobreturno(req, data) {
}
}

function actualizarHistorial(elem, agenda, req) {
const itemHistorial = new HistorialAgenda(elem);

Auth.audit(itemHistorial, req);
agenda.historial.push(itemHistorial);
}

// Agenda
export function actualizarEstado(req, data) {

Expand Down Expand Up @@ -504,8 +511,9 @@ export function actualizarEstado(req, data) {
sobreturno.avisoSuspension = 'no enviado';
});
}

}

actualizarHistorial({ estado: req.body.estado }, data, req);
}

// Dada una Agenda completa + un id de Turno, busca y devuelve el Turno completo
Expand Down Expand Up @@ -849,6 +857,8 @@ export function actualizarEstadoAgendas(start, end) {
actualizarAux(agenda);
}
}

actualizarHistorial({ estado: agenda.estado }, agenda, (userScheduler as any));
}
} catch (error) {
agendaLog.error('actualizarEstadoAgendas', { agenda }, error);
Expand Down
21 changes: 20 additions & 1 deletion modules/turnos/schemas/agenda.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,21 @@ import * as mongoose from 'mongoose';
import { AuditPlugin } from '@andes/mongoose-plugin-audit';
import { InstitucionSchema } from '../institucion.schema';

export const HistorialAgendaSchema = new mongoose.Schema({
estado: {
type: String,
required: false,
},
op: {
type: String,
required: false,
},
});

HistorialAgendaSchema.plugin(AuditPlugin);

export const HistorialAgenda = mongoose.model('historial', HistorialAgendaSchema);

export const AgendaSchema = new mongoose.Schema({
organizacion: {
type: nombreSchema,
Expand Down Expand Up @@ -77,7 +92,11 @@ export const AgendaSchema = new mongoose.Schema({
type: Boolean,
default: false
},
cupo: Number
cupo: Number,
historial: {
type: [HistorialAgendaSchema],
required: false
},
}, { versionKey: false });

// Defino Virtuals
Expand Down

0 comments on commit 855ae22

Please sign in to comment.