People who die after suffering a heart attack in the community will be able to donate their organs for the first time as part of a new pilot scheme.

Previously those who have suffered a cardiac arrest either at home or in the community have not been able to do this, even if they had made it clear they wanted to be an organ donor.

But a new pilot project at the Royal Infirmary of Edinburgh will mean they could do this - potentially saving the lives of up to seven people each.

More people who have a cardiac arrest are surviving, thanks to the advanced techniques used by both hospital staff there and the Scottish Ambulance Service.

Doctors in the emergency department will continue to make the best effort to revive heart attack victims, with the resuscitation process continuing to run under the existing policies.

If, however, the best efforts of the medics are unsuccessful, the option of organ donation will be discussed with the patient's family.

Dr Matt Reed, consultant in emergency medicine at the Royal Infirmary of Edinburgh, said the modern resuscitation techniques practised by medics at the hospital and ambulance crews had "seen survival rates for these patients improve dramatically and many more patients are now going on to make a good recovery".

He added: "Unfortunately, however, there are some patients who do not survive despite every attempt to save them.

"Many of those people will have expressed a wish to be an organ donor by joining the NHS Organ Donor Register in the expectation that their wishes be respected in the event of their death.This pilot will allow their wishes to be acted upon."

Public health minister Michael Matheson said: "We welcome the fact that more people who experience a cardiac arrest at home or in the community are now surviving due to the introduction of modern resuscitation techniques by the emergency department clinicians and the Scottish Ambulance Service.

"However, when all attempts at resuscitation in hospital have been unsuccessful it can be a source of comfort to the family to be able to respect the wishes of their loved ones who have made their organ donation wishes known by joining the NHS Organ Donor Register. This pilot programme is about doing this."

Dr Jean Turner, the executive director of the patients' organisation Scotland Patients Association, said the pilot "offers patients and their relatives the utmost assurance for the best outcomes from resuscitation with consideration and respect when organ donation may become an option for them".

Those aged 16 to 60 who have a witnessed heart attack in the community could potentially become organ donors under the pilot - which will initially operate between 9am and 5pm on weekdays.

Already almost half the people in the NHS Lothian area have signed up to the Organ Donor Register.

One donor can save up to seven lives, with the kidneys, heart, lungs, liver, pancreas and small bowel all able to be transplanted.

Other body tissue can also be donated that can transform the lives of recipients, with people able to benefit from new eyes, heart valves, skin, bone and connective tissue from organ donors.