What you want is pretty easy.
Set the player's storage 12345, as an example, with the value :maxhealth:.
Then, use this code:
function onHealthChange(player, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin)
if player:getStorageValue(12345) > 0 then...