To adapt to advancements in medical technology and the growing demand for healthcare services, and in response to national policies regarding hospital capacity expansion and improvements in medical service capabilities, it is necessary to optimize and renovate hospital spatial layouts. This article establishes a hospital spatial layout optimization model based on the patient safety accessibility gravity model, with the objectives of enhancing patient safety assurance capabilities and risk management capabilities. Using AnyLogic software, a simulation model and spatial layout optimization strategies were developed. An improved sparrow search algorithm is then introduced to optimize the parameters of the GRU model, thereby solving the optimization model and predicting clinical risks. A simulation analysis is conducted using a certain hospital as the research object. The study shows that the ISSA-GRU model has good solution and prediction performance, and the application of spatial layout optimization strategies can significantly reduce the passenger density, waiting time, and infection risk in the hospital waiting area, providing a reliable guarantee for improving the safety level of the patient’s medical environment.