hello, Hanna. I'm russian my English is bad, but I'm studying it now
(is должен relating to "ему" or "я" ....? If the speaker is a woman, could she say this, because she is referring to a man? Or should she say "должна" because she is a woman...?
word "должен" is relating to "я" in this case -> so if the speaker is a woman, she could say "должна"

I know this is correct because it's from an example sentence... нужен refers to the doctor and not the wife. But this was confusing at first and it's easy to think that it should be "нужна" because it's a woman that needs something. Hmmmm....
here the word "врач" is Masculine gender , so it should be "нужен"
if instead of the word "врач" was the word, for example, "машина" which is Feminine gender, then it should be "нужна".

I hope, this was helpful for u and good luck with studying