I have a fire sprinkler in my bedroom ceiling which is right in the middle. I want to install a ceiling fan. What are code requirements to follow?
It depends on what jurisdiction has authority where you are doing the work. Some sort of electric code applies, but there's nothing unusual involved. There's a requirement for the fan to be securely anchored to the structure. That could be electrical, mechanical, or building codes. They are unlikely to be very specific, "securely anchored" will be roughly all the detail you'll see.
The main issue is the sprinkler head. It seems every jurisdiction has their own requirements, though at least in the USA, the National Fire Protection Association (NFPA) publishes a model code from which most jurisdictions either adopt by reference or base their own code upon it.
The main provision here will be nothing can be installed to obstruct the dispersal pattern of the spray head, which normally means the head needs to be lower than the fan. However, one could argue if the fan were pendant mounted by a narrow tube, one could actually get a better dispersal with the head at ceiling height because the head is higher and the tube provides minimal obstruction. This argument may or may not be viable, depending on exactly where the two components are located relative to each other.
Since this is a judgement call, only the authority having jurisdiction can make such a ruling.
Since you are in a residential occupancy, you will have residential-type sprinkler heads fit, which means that NFPA 13, section 184.108.40.206.1.3 (or the equivalent citation in NFPA 13R or NFPA 13D) applies: