The sum $$\sum _{d,d'\leq D}\sum _{h,h'=1}^q(h,q)e\left (\frac {dh+d'h'}{q}\right )$$ is easily seen to be $$\ll q^{2+\epsilon }+D^2.$$ Indeed with a standard estimate for a linear exponential sum it is $$\sum _{h,h'=1}^q(h,q)\min \left (D,\frac {1}{||h/q||}\right )\min \left (D,\frac {1}{||h'/q||}\right )\\ \ll D^2+D\sum _{h=1}^{q-1}\frac {(q,h)}{||h/q||}+\sum _{h,h'=1}^{q-1}\frac {(q,h)}{||h/q||\cdot ||h'/q||}$$ and then the claim follows from $$\sum _{h=1}^{q-1}\frac {(q,h)}{||h/q||}\ll \sum _{l|q}l\sum _{h=1\atop {(q,h)=l}}^{q-1}\frac {1}{||h/q||}\leq 2q\sum _{l|q}l\sum _{h=1\atop {(q,h)=l}}^{q-1}\frac {1}{h}\ll q(\log q)d(q)\ll q^{1+\epsilon }$$.
If I have instead the sum $$\sum _{d,d'\leq D}\sum _{h,h'=1}^q(h+h',q)e\left (\frac {dh+d'h'}{q}\right )$$ then I'm not sure if the same bound holds (the $h\equiv h'$ contribution is already too large, but perhaps there are other large contributions). Does it?