Médicos: modal de detalle con tab Info e Historial (citas, visitas, ventas recetadas)
This commit is contained in:
@@ -1743,6 +1743,70 @@ class SkeenFrontendController(http.Controller):
|
||||
})
|
||||
except Exception as e:
|
||||
return json_response({'status': 'error', 'message': str(e)}, 500)
|
||||
|
||||
@http.route('/skeen/frontend/v1/doctors/<int:doctor_id>/history', type='http', auth='none', methods=['GET', 'OPTIONS'], csrf=False)
|
||||
@require_role('lectura')
|
||||
def doctor_history(self, doctor_id, **kw):
|
||||
"""Historial de actividad del médico: citas, visitas y líneas recetadas.
|
||||
|
||||
Devuelve las últimas 50 de cada lista (más recientes primero) y
|
||||
`totales` sobre TODO el historial (no solo las 50).
|
||||
"""
|
||||
try:
|
||||
doctor = request.env['hr.employee'].sudo().browse(doctor_id)
|
||||
if not doctor.exists():
|
||||
return json_response({'status': 'error', 'message': 'Médico no encontrado'}, 404)
|
||||
|
||||
Citas = request.env['skeen.cita'].sudo()
|
||||
citas = Citas.search([('doctor_id', '=', doctor_id)], order='date desc, time desc', limit=50)
|
||||
citas_total = Citas.search_count([('doctor_id', '=', doctor_id)])
|
||||
|
||||
Visitas = request.env['skeen.visita'].sudo()
|
||||
visitas = Visitas.search([('doctor_id', '=', doctor_id)], order='date_start desc', limit=50)
|
||||
visitas_total = Visitas.search_count([('doctor_id', '=', doctor_id)])
|
||||
|
||||
Lineas = request.env['skeen.venta.line'].sudo()
|
||||
line_domain = [('prescribed_by_id', '=', doctor_id)]
|
||||
lineas = Lineas.search(line_domain, order='id desc', limit=50)
|
||||
agg = Lineas.read_group(line_domain, ['subtotal:sum'], [])
|
||||
ventas_total_lineas = agg[0]['__count'] if agg else 0
|
||||
monto_total = (agg[0]['subtotal'] or 0.0) if agg else 0.0
|
||||
|
||||
return json_response({
|
||||
'status': 'success',
|
||||
'citas': [{
|
||||
'id': c.id,
|
||||
'date': c.date.strftime('%Y-%m-%d') if c.date else None,
|
||||
'time': c.time_str or '',
|
||||
'patient': c.partner_id.name,
|
||||
'service': c.servicio_id.name,
|
||||
'state': c.state,
|
||||
} for c in citas],
|
||||
'visitas': [{
|
||||
'id': v.id,
|
||||
'date_start': v.date_start.strftime('%Y-%m-%d %H:%M') if v.date_start else None,
|
||||
'patient': v.partner_id.name,
|
||||
'motivo': v.motivo or '',
|
||||
'state': v.state,
|
||||
} for v in visitas],
|
||||
'ventas': [{
|
||||
'id': l.id,
|
||||
'venta': l.venta_id.name,
|
||||
'date': l.venta_id.date.strftime('%Y-%m-%d') if l.venta_id.date else None,
|
||||
'patient': l.venta_id.partner_id.name,
|
||||
'item': l.description or (l.service_id.name if l.service_id else (l.item_id.name if l.item_id else '')),
|
||||
'subtotal': l.subtotal,
|
||||
'state': l.venta_id.state,
|
||||
} for l in lineas],
|
||||
'totales': {
|
||||
'citas_total': citas_total,
|
||||
'visitas_total': visitas_total,
|
||||
'ventas_total_lineas': ventas_total_lineas,
|
||||
'monto_total': round(monto_total, 2),
|
||||
},
|
||||
})
|
||||
except Exception as e:
|
||||
return json_response({'status': 'error', 'message': str(e)}, 500)
|
||||
except Exception as e:
|
||||
return json_response({'status': 'error', 'message': str(e)}, 500)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user