With word problems like this, there are always literally infinitely many ways to formalize the written problem into a precise mathematical statement in terms of a sample space $\Omega$, a set of events, and a probability measure $P$.
The method you ultimately choose to translate a word problem into a mathematical model depends on what you're trying to do.
Here's one possible way, but it is by no means the only way or necessarily the best way.
Let the sample space $\Omega$ be the set of all people who have taken the test.
This is a natural choice because the word problem is considering people who have taken the test.
Each of these people either has the disease or doesn't, and each of this people either has a positive test or not.
With this definition, we have
$$
H = \{\text{person} \in \Omega : \text{person has the disease}\}
$$
and
$$
D = \{\text{person} \in \Omega : \text{person's test is positive}\}.
$$
Then you could proceed as in the example, knowing that $P(H) = 0.002$ (the proportion of the population with the disease), $P(D \mid H^c) = 0.01$ (the false positive rate), and $P(D^c \mid H) = 0.01$ (the false negative rate).
Another possibility is letting $\Omega$ be the set of all people, regardless of whether or not they have taken the test.
This sample space is a superset of the previous sample space.
With this formulation, the event $H$ would be stated identically, but $D$ would have to change to something like
$$
D = \{\text{person} \in \Omega : \text{person's test would be positive if they were to take the test}\}.
$$
This wording is necessary because probably not every person in $\Omega$ has taken the test.
Regardless of the formalization, you would still always end up with $H$ and $D$ being events in a common sample space $\Omega$, and you would always have $P(H) = 0.002$, $P(D \mid H^c) = 0.01$, and $P(D^c \mid H) = 0.01$ because of the specification of the problem.
As you get more familiar with probability, you will see that to approach word problems like this is it not always necessary to construct an explicit sample space.
You will be comfortable knowing that you could do it if you really needed to do it, but for the purpose of solving a problem like in the question, you don't need to know the full specification of the sample space.