Hamiltonian structure of compartmental epidemiological models