How do you know when to quit a job if you are not paid enough to cover medical costs from it?

Depends. If the medical costs are related to an injury on the job, the employer's workers compensation insurance policy has to pay for it. If it's non work-related and you had insurance through your job, you are entitled to cobra coverage (for a limited time) fully at your cost starting the day you leave.