Everyone is required to comply with a Court Order which affects them or their actions. GPs are not exempt. (However, before complying with such an Order, the relevant person may appeal against it. For example there have been occasions when journalists have been ordered to reveal their sources but they have successfully appealed against such Orders).
A court would normally only make such an order where there was a clear 'public interest' consideration, such as ensuring the proper administration of justice.
For example, someone working in a medical or care environment might sue their employer (or a former employer) claiming that they'd contracted HIV from a patient or client of that employer due to the employer not advising them of the risks and/or not providing adequate physical protection measures. If the employer suspected, but could not prove, that the litigant was HIV-positive before they had commenced such employment, the Court might require the litigant's medical records before adjudicating on the claim.