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 management should not be connected to the internet. If you are not on the internet, your system can’t be held for ransom or damaged by malicious hacks. Convenience has to be balanced with security and privacy needs and convenience should not be the first choice.