The Doctor's mobile emitter is stolen from Voyager by an alien trader named Gar and sold to an overcrowded hospital on a nearby planet run by Administer Chellick. When the Doctor is activated and told to get to work, he protests his kidnapping, but on seeing the number of patients, agrees to take on the duties of tending to them.
The Doctor quickly learns that this hospital is run in a strict manner by a computer called the Allocator, which assigns the staff of doctors and regulates doses of medicine to patients based on a Treatment Coefficient (TC) value assigned each patient based on a complex formula that includes the patient's value to society. One patient, Tebbis, has a terminal condition that requires cytoglobin which the hospital can provide, but Tebbis' TC is too low to allocate it. When the Doctor begins to question this, the Allocator assigns him to Level Blue. Level Blue's facilities are much cleaner and the patients given a greater amount of care. He learns the patients on this level have a much higher TC than those where Tebbis is warded, and that the Allocator prioritizes their prophylactic care over those lower-TC patients that need emergency care. The Doctor is able to convince the nurses to provide him with additional doses of cytogoblin which he smuggles to the lower level and treats Tebbis with. The Doctor continues this until Chellick discovers his scheme and restricts the Doctor to Level Blue.
Meanwhile, the Voyager crew tracks down Gar who had stolen the Doctor's program, and trick him into revealing the planet where he sold the Doctor to. Voyager sets course there.
The Doctor learns that Tebbis has died despite the fact that continued cytogoblin injections would have saved him. He figures a means to escape Level Blue to continue to try to save the other patients in the lower levels. Chellick learns of this and arrives to stop the Doctor, but the Doctor injects him with some of Tebbis' blood, giving him the same condition. The Allocator assigns Chellick a low TC preventing him from being moved to where he could receive the proper treatment. Chellick instead decides that all patients with a low TC including himself should be immediately moved to Level Blue to receive care. Voyager arrives to rescue the Doctor as Chellick's orders are carried out. Aboard the ship, the Doctor considers if his ethics subroutines have failed as he willingly infected Chellick, but Seven of Nine assures him that for the greater good of all, the sacrifice of one can be acceptable.