The Shulhan Aruch (Orah Haim 328:48) rules that it is forbidden on Shabbat to extract blood from a wound, such as by pressing on the skin around the wound, or by tightly tying a piece of material near the wound to apply pressure. This is forbidden only "Mi’de’rabbanan" – on the level of Rabbinic enactment – as the Torah prohibition against extracting blood on Shabbat applies only when one needs the blood for some purpose.
Therefore, extracting blood to be examined in a laboratory would be forbidden on Shabbat on the level of Torah law. Since in this case the blood itself is needed, this constitutes a Biblical violation. Accordingly, Hacham Bension Abba Shaul (Israel, 1924-1998) writes that taking a blood test on Shabbat is forbidden except in the case of a seriously ill patient, where a potentially life-threatening risk is entailed.
Rabbi Moshe Ha’levi (Israel, 1961-2000), in his Menuhat Ahaba (vol. 3, 18:12), adds that in some situations, it would be permissible to ask a gentile to extract blood from a Jewish patient for a blood examination. This leniency would apply if there is a potential risk to the patient’s limb, if the patient is bedridden, or if he experiences pain throughout his body. In such cases, one may ask a gentile to perform the blood test. A Jew, however, may not extract blood from a patient for examination except in situations of potential risk to life.
Summary: It is forbidden to extract blood on Shabbat. Taking blood for a blood test is permitted on Shabbat only in situations of a patient in a potentially life-threatening situation. If the patient is not in danger, but he is quite ill, such as if he is bedridden, then one may ask a gentile to perform the blood test.