Hospitals and other institutions across Europe, Asia and beyond were simultaneously struck on Friday by a cyberattack that locked their computer systems and demanded a ransom to restore access, leading to chaos in emergency rooms, in doctors’ offices and aboard ambulances.