Global theory of quantum boundary conditions and topology change