The best way to prevent hacks and/or ransom ware attacks is to get your system(s) off of the internet. You don’t have to be completely free of the internet but for sure; utilities, governments, hospitals, schools, etc. should isolate their critical data bases and operations from the internet.
The internet is convenient for many uses but critical operations and data base . . .