Many hospitals operate with a structure that separates inpatients according to their primary disease. Conversely, these hospitals may reduce the cases of bed shortage and provide a better care for patients with multiple diseases by striving for a setup containing fewer nursing wards. We present a method for optimizing the organizational structure in a hospital where the medical specialties are consolidated into fewer wards. The patient diagnoses are the basis of our approach as we derive an improved organizational structure by using a heuristic optimization algorithm. In this algorithm, we evaluate the solution by simulating the patient flow and penalize the objective value for every patient with a diagnosis that does not match the specialties in the ward. Through numerical experimentation, and data from a Danish hospital, we validate the applicability of our approach. The proposed algorithm converged to the optimal solution in all smaller problem instances. Further, tests with the hospital data indicate that consolidating medical specialties into fewer wards is beneficial for patients with diagnoses stemming from various medical specialties.