The easiest way for them to do this would be to search pharmacy records for certain drug sales and cross reference them to gun permits.
They may not have to search pharmacy records.
Pharmacies and/or health insurance companies could report anyone being prescribed these drugs, not saying they would but they could.
Obamacare