During the outbreak of epidemics such as coronavirus disease (COVID-19), the local hospitals often withstand a sharp increase of patient influx, which renders the healthcare system on the verge of collapse. To alleviate the situation, the effective allocation of scarce medical resources during the pandemic plays a vital role. The essence of the healthcare system in time of emergency is to stay functional, and to be able to diagnose and hospitalize as many patients as possible. Fangcang shelter hospital, as a novel way to temporarily increase the capacity of the local healthcare system, is proven to be effective against the COVID-19 pandemic. To improve the performance of the healthcare system with Fangcang, many practical factors need to be taken into account, such as the patient deterioration during waiting to be admitted, the referral mechanism according to the severity of the patients, and the selective admission regulations. To address the high volatility and time-varying feature of the COVID-19, a multistage and multi-type medical service network model is established, and a dynamic allocation strategy of the medical resources at each stage is proposed based on a stochastic optimization problem, which is then solved via the fluid queueing approximation. Combined with the real data collected from Wuhan, it is revealed that the proposed algorithm could help with the allocation of medical resources during the outbreak of epidemics. Even with limited medical resources available, the method could still maintain a guaranteed service level while keeping the healthcare system operational. Furthermore, the simulation analysis validates that our method can effectively allocate medical resources at each stage, so as to stabilize the system performance and fulfill the medical demand for multiple types of patients. <italic xmlns:mml="http://www.w3.org/1998/Math/MathML" xmlns:xlink="http://www.w3.org/1999/xlink">Note to Practitioners</i> —To fend off the outbreak of epidemics, the lessons have to be learned from the past. The successful control of the spread of COVID-19 in Wuhan (China) is a classical example of applying modern medical practices and management tools. In the present article, the treating procedure of COVID-19 in Wuhan is modeled as a multistage decision problem, which includes the screening with nucleic acid testing, the further testing, the treatment of patients with mild/severe symptoms, or even critical patients. The introduction of Fangcang shelter hospital is crucial for winning the battle against COVID-19. The current study attempts to determine the timing of introducing the Fangcang shelter hospital during the outbreak of a major epidemic, and helps allocate the medical resources needed to contain the spread of the virus. It is discovered that the actual number of beds in the Fangcang shelter hospital is far more than what is necessary, and it would be better to have built the Fangcang some time in advance. In the meantime, the number of designated hospitals for COVID-19 is in line with the results obtained via the optimal staffing strategy proposed here, but it is also noticeable that these hospitals should be released of duty sooner to fight against not only COVID-19 but also other diseases in reality.