I would do the following:
Do a few 25% or so water changes during the week, like space them a few days apart until you have your nitrate below 20ppm. if it's not a planted tank, just keep it up until you have reduced the nitrates down. But, I say space it out so you're not changing it all out too fast. The goal of this is to keep the tank stable while resetting the nitrate level lower, otherwise the 30-40ppm is going to be your baseline. Once you get to a good level less than 20ppm (less than that if its not planted), then take a nitrate reading throughout the week to get a better understanding of how much it raises during a single week. This will help you determine the appropriate level and frequency of water changes, and might also better help understand other factors that could be impacting nitrate levels -- overstocked, too much feeding, too much organic waste build up in filter or substrate. While you're doing this of course try to keep the other params as stable as possible so you don't accidentally drop or raise the PH or GH too much, etc.
Now I do realize that nitrates don't cause illness in fish directly, but it could be a symptom of other factors impacting your tank, like too much decaying organic matter. Additionally, high nitrates can stress fish out and when they get stressed out this can reduce their immunity to possible illnesses already present in the tank, or present in other fish. So a stable healthy tank that reduces the stress of your fish and increases their immune system helps as lot.
If the fish have been in this system for a while and you have not introduced any new fish recently, the I would guess something about your tank suddenly triggered this outbreak and your fish weren't strong enough to fight off infection.
I say this because I just went through this myself in a large tanks that had been stable and healthy for 1+ years, with few new fish new additions.
Two months ago, I lost half of a heavily planted 125 gallon tank after it got too heavily overgrown and too dense in organic matter (I also raised the temp a bit AND discontinued using my UV sterilizer after it kept tripping my GFI outlet).
Like I said, this was a stable tank. But it apparently had the possibility of an outbreak lurking in it, and my changes (and neglect given a hectic spring and summer) seems to have triggered that.
I lost probably 50 or so fish, mostly tetra species, but I also lost 2 rams, some guppies, CPDs and corys -- so yeah, a lot of fish! My wife wondered if my tank was having its own pandemic!
To fix this I dosed the whole tank with meds (I used the 'med trio' championed by the folks at Aquarium Coop) . I cleaned my sump/filter which was waaaaay overdo, pulled out some of the dense plants and turned the UV back on. My remaining guppies that had clumped, deteriorating tails recovered fine. All there other fish -- mostly danios and corys -- are doing great now.
HOWEVER -- EXCEPT the tetras, they continued to decline and I eventually had to euthanize the remaining 25 or so neons.
My neons were the only ones in the tank to really exhibit any visible illness and I isolated them and ran them through a number of different meds for various parasites and fungus -- following the packaging so as to not med them to death . But none of them ever recovered in the slightest and their symptoms got worse.
All signs pointed to possible 'neon tetra disease' -- they had progressively worse white and pale coloration, fungal patches, bent and curved backbones that they didn't originally have, hard cysts on their mouths -- and this never got better with meds. I'm not saying it was neon tetra disease--which i hear is actually quite rare -- but they were sick and didn't get better and had to be isolated and eventually dispatched.
So . . . . . . sorry for a long winded answer, but I just went through something similar to you and thought I could share how I approached recovering from it to the best of my ability and saving the other 50% of my fish community.
I hope this helps a little.