...
Get all employees with a related party (party.id = employee.party_id)
Get all declared specialities (where speciality_officio = true) per party
Get current limit for each speciality from global parameters
PEDIATRICIAN: pediatrician_declaration_limit
THERAPIST: therapist_declaration_limit
FAMILY_DOCTOR: family_doctor_declaration_limit
Get lowest limit for each party (declarations_limit)
Find and count all active (status active or pending_verification) declarations for all this employees (per party) (declarations_count)
...