Subpoenaed medical/sensitive records - practical question

After reading about the efforts of the Kansas attorney general to obtain the medical records of some women who underwent abortions in Kansas, I was wondering how these sorts of records (or, by extension, any subset of records) are obtained by prosecutors. I’m not interested in the particular merits or lack thereof of the Kansas case, so here’s a hypothetical situation:

Anystate has a law requiring the reporting of patients with syphilis to local public health authorities. The Anystate AG believes that Dr X is breaking the law in that she is treating syphilis patients without reporting them, thereby contributing to a threat to general public health. He wants Dr. X to turn over the records of all her syphilis patients so that they can be compared to the public health records, thereby allowing for the prosecution of Dr. X for violating the reporting law.

Now, as a practical matter, how does the AG get these records? If he just asks Dr. X to turn them over, how does he know that he has obtained all the records? It would seem that the AG can’t just look at all of Dr. X’s records, since most of her patients do not have syphilis and examining those records would fall outside the scope of the specific investigation. Clearly, IANAL, but how are these things actually handled in the real world? A quick Google search of ‘legal discovery’ reveals that there are a lot of companies that do this sort of work, but which side pays them, and how are the issues of access vs. confidentiality worked out?

I don’t know about medical records, and while I’m not a lawyer I think that lawyers’ records have a similar privilege/confidentiality problem.

IIRC, when a lawyer’s records are subpoenaed, a special master is appointed to get the records - an impartial lawyer who can then go over the records while maintaining the confidentiality of the clients.

A quick google for related stuff provided this bit from this news article:

So this would indicate to me that a similar concept applies to such records, at least in some places. There are a couple of Law and Order episodes I can think of which could’ve fit into a half hour if the asst. DA’s had applied this concept to get at medical records.