Well if Starfleet patterns its ranks after the US Navy, or Navies of the world, then having physician with the rank of Captain (Colonel), or even Admiral would not be too far. Since the Captain of a ship is a Naval Officer with Surface Warfare/Underseas Warfare experience, they would be the chief officers of the ship. Since McCoy would have risen to the rank of Captain, or even Admiral, he could serve as the overall Medical Officer in charge of a major medical Department, on board a much larger Starship. As for an Admiral, he could be assigned as the overall Medical Officer of a much larger parsec of space, and would have his own staff or floor that would have his own personal offices, or offices for his administrative staff, and his flag would be on that ship.
Now, if McCoy were the senior officer on board a Starship, and all of a sudden all of the senior officers were killed, he may be authorized to take command of the ship for a certain period of time, to get the ship and crew away from the danger. Then if the ship were now in StarFleet territory, he would probably return command to one of the junior officers, or even a senior Petty Officer.