85 lines
3.3 KiB
Python
85 lines
3.3 KiB
Python
import odoo
|
|
import json
|
|
|
|
def test_critical_notes_autocomplete(cr):
|
|
"""Prueba el autocompletado de notas críticas en resultados de laboratorio"""
|
|
env = odoo.api.Environment(cr, odoo.SUPERUSER_ID, {})
|
|
|
|
print("\n=== PRUEBA DE AUTOCOMPLETADO DE NOTAS CRÍTICAS ===\n")
|
|
|
|
# Buscar algunas pruebas con resultados
|
|
tests = env['lims.test'].search([('state', 'in', ['result_entered', 'validated'])], limit=5)
|
|
|
|
if not tests:
|
|
print("No se encontraron pruebas con resultados para probar.")
|
|
return
|
|
|
|
for test in tests:
|
|
print(f"\nPrueba: {test.name} - {test.product_id.name}")
|
|
print(f"Paciente: {test.patient_id.name}")
|
|
|
|
for result in test.result_ids:
|
|
if result.parameter_value_type == 'numeric':
|
|
print(f"\n Parámetro: {result.parameter_name}")
|
|
print(f" Valor: {result.value_numeric} {result.parameter_unit or ''}")
|
|
print(f" ¿Es crítico?: {'SÍ' if result.is_critical else 'NO'}")
|
|
|
|
if result.is_critical:
|
|
# Limpiar las notas para probar el autocompletado
|
|
result.notes = ''
|
|
|
|
# Simular cambio en el valor para activar el onchange
|
|
with env.cr.savepoint():
|
|
# Trigger the onchange by updating the value
|
|
result.with_context(force_onchange=True)._onchange_critical_value()
|
|
|
|
print(f" Nota autocompletada: {result.notes}")
|
|
|
|
# No guardar los cambios, solo mostrar
|
|
env.cr.rollback()
|
|
|
|
# Probar con valores específicos
|
|
print("\n\n=== PRUEBA CON VALORES ESPECÍFICOS ===\n")
|
|
|
|
# Buscar parámetros específicos
|
|
test_params = [
|
|
('Glucosa', 200.0, 'high'),
|
|
('Glucosa', 50.0, 'low'),
|
|
('Hemoglobina', 20.0, 'high'),
|
|
('Hemoglobina', 7.0, 'low'),
|
|
('Plaquetas', 600000, 'high'),
|
|
('Plaquetas', 50000, 'low')
|
|
]
|
|
|
|
for param_name, test_value, expected_type in test_params:
|
|
# Buscar un resultado con este parámetro
|
|
result = env['lims.result'].search([
|
|
('parameter_name', 'ilike', param_name),
|
|
('parameter_value_type', '=', 'numeric')
|
|
], limit=1)
|
|
|
|
if result:
|
|
print(f"\nProbando {param_name} con valor {test_value} (esperado: {expected_type})")
|
|
|
|
with env.cr.savepoint():
|
|
# Establecer el valor de prueba
|
|
result.value_numeric = test_value
|
|
result.notes = ''
|
|
|
|
# Forzar recálculo de is_critical
|
|
result._compute_is_out_of_range()
|
|
|
|
# Trigger el onchange
|
|
result._onchange_critical_value()
|
|
|
|
print(f" ¿Es crítico?: {'SÍ' if result.is_critical else 'NO'}")
|
|
print(f" Nota generada: {result.notes[:100]}...")
|
|
|
|
# No guardar
|
|
env.cr.rollback()
|
|
|
|
if __name__ == '__main__':
|
|
db_name = 'lims_demo'
|
|
registry = odoo.registry(db_name)
|
|
with registry.cursor() as cr:
|
|
test_critical_notes_autocomplete(cr) |