<?xml version="1.0" encoding="utf-8"?>
<odoo>
    <!-- Form View -->
    <record id="view_lims_parameter_range_form" model="ir.ui.view">
        <field name="name">lims.parameter.range.form</field>
        <field name="model">lims.parameter.range</field>
        <field name="arch" type="xml">
            <form string="Rango de Referencia">
                <sheet>
                    <group>
                        <group string="Parámetro">
                            <field name="parameter_id" 
                                   options="{'no_create': True}"
                                   context="{'form_view_ref': 'lims_management.view_lims_analysis_parameter_form'}"/>
                            <field name="parameter_unit"/>
                        </group>
                        <group string="Condiciones">
                            <field name="gender"/>
                            <field name="age_min"/>
                            <field name="age_max"/>
                            <field name="pregnant" invisible="gender == 'male'"/>
                        </group>
                    </group>
                    <group string="Valores de Referencia">
                        <group>
                            <label for="normal_min"/>
                            <div class="o_row">
                                <field name="normal_min" class="oe_inline"/>
                                <span class="oe_inline"> - </span>
                                <field name="normal_max" class="oe_inline"/>
                                <field name="parameter_unit" class="oe_inline" readonly="1"/>
                            </div>
                        </group>
                        <group>
                            <label for="critical_min"/>
                            <div class="o_row">
                                <span class="oe_inline">&lt; </span>
                                <field name="critical_min" class="oe_inline"/>
                                <span class="oe_inline"> o &gt; </span>
                                <field name="critical_max" class="oe_inline"/>
                                <field name="parameter_unit" class="oe_inline" readonly="1"/>
                            </div>
                        </group>
                    </group>
                    <group string="Interpretación Clínica">
                        <field name="interpretation" nolabel="1" 
                               placeholder="Ingrese guías de interpretación clínica para este rango..."/>
                    </group>
                </sheet>
            </form>
        </field>
    </record>

    <!-- List View -->
    <record id="view_lims_parameter_range_list" model="ir.ui.view">
        <field name="name">lims.parameter.range.list</field>
        <field name="model">lims.parameter.range</field>
        <field name="arch" type="xml">
            <list string="Rangos de Referencia" editable="bottom">
                <field name="parameter_id" optional="hide"/>
                <field name="name"/>
                <field name="gender"/>
                <field name="age_min"/>
                <field name="age_max"/>
                <field name="pregnant" optional="show"/>
                <field name="normal_min"/>
                <field name="normal_max"/>
                <field name="critical_min" optional="show"/>
                <field name="critical_max" optional="show"/>
                <field name="parameter_unit" optional="show"/>
            </list>
        </field>
    </record>

    <!-- Search View -->
    <record id="view_lims_parameter_range_search" model="ir.ui.view">
        <field name="name">lims.parameter.range.search</field>
        <field name="model">lims.parameter.range</field>
        <field name="arch" type="xml">
            <search string="Buscar Rangos">
                <field name="parameter_id"/>
                <field name="parameter_name"/>
                <field name="parameter_code"/>
                <field name="name"/>
                <filter string="Masculino" name="male" domain="[('gender', '=', 'male')]"/>
                <filter string="Femenino" name="female" domain="[('gender', '=', 'female')]"/>
                <filter string="Ambos" name="both" domain="[('gender', '=', 'both')]"/>
                <separator/>
                <filter string="Embarazadas" name="pregnant" domain="[('pregnant', '=', True)]"/>
                <separator/>
                <filter string="Pediátrico (&lt;18)" name="pediatric" 
                        domain="[('age_min', '&lt;', 18)]"/>
                <filter string="Adulto (18-65)" name="adult" 
                        domain="[('age_min', '&gt;=', 18), ('age_max', '&lt;=', 65)]"/>
                <filter string="Geriátrico (&gt;65)" name="geriatric" 
                        domain="[('age_max', '&gt;', 65)]"/>
                <group expand="0" string="Agrupar por">
                    <filter string="Parámetro" name="group_parameter" 
                            context="{'group_by': 'parameter_id'}"/>
                    <filter string="Género" name="group_gender" 
                            context="{'group_by': 'gender'}"/>
                    <filter string="Embarazo" name="group_pregnant" 
                            context="{'group_by': 'pregnant'}"/>
                </group>
            </search>
        </field>
    </record>

    <!-- Action -->
    <record id="action_lims_parameter_range" model="ir.actions.act_window">
        <field name="name">Rangos de Referencia</field>
        <field name="res_model">lims.parameter.range</field>
        <field name="view_mode">list,form</field>
        <field name="search_view_id" ref="view_lims_parameter_range_search"/>
        <field name="help" type="html">
            <p class="o_view_nocontent_smiling_face">
                Crear nuevo rango de referencia
            </p>
            <p>
                Los rangos de referencia definen los valores normales y críticos
                para cada parámetro según edad, género y otras condiciones del paciente.
            </p>
        </field>
    </record>
</odoo>