Patient complaints about the NHS rose to 22,417 over the last year, according to official figures.

The total for 2014/15 was up by 9% on the previous year.

The increase was attributed to a rise in prisoner complaints after measures were put in place by Scottish health boards during 2013/14 to ensure those in jail have access to the NHS complaints procedure.

The figures include all hospital visits and GP, outpatient, dental and ophthalmic appointments.

The number of prisoner complaints increased from 3,018 to 4,277, a rise of 41%. Of those, 63% were not upheld.

Overall, there were 13,723 complaints about hospital and community health services, with 30% of these fully upheld.

Treatment was the biggest issue, featuring in 45% of those complaints, followed by staff at 28% and waiting times at 15%.

A further 7,422 complaints were about family health services, with 36% relating to treatment and 29% relating to staff.

Health Secretary Shona Robison said: "In the overwhelming majority of cases the NHS does a fantastic job.

"However in an organisation of this size, which deals with such a vast and increasing number of patients, there will be occasions when people's experiences of the NHS do not meet their expectations. When that happens boards must listen to and act on that feedback.

"Indeed, we want and need to hear the views of patients, in particular when things go wrong, so we can learn and do better the next time.

"The number of complaints we are seeing reflects a better awareness of how people can give feedback and make a complaint - and confidence that their complaint will be listened to and acted on. It shows that our work to ensure our NHS is open, transparent and able to learn from mistakes is paying off.

"Prisoners have the same right to make complaints as every other patient and over the last two years prisoners have been able to better access the complaints procedure. This has driven some of the increases we have seen in complaints over the last two years."

Scottish Liberal Democrat health spokesman Jim Hume said: "It would be unwise of the Health Secretary to continue to seem oblivious to the real pressures experienced by health boards and the fact that this could have a detrimental impact on the patient experience.

"Our hospitals are treating more patients with fewer staff. We are grateful to NHS staff for the hard work they do. Their job has been made no easier by the SNP Government, which continues to take its eye off the ball to talk about its independence plans."

Jackie Baillie, Scottish Labour's spokeswoman for public services, said: "Yet again here is the evidence that the SNP Government are failing the people of Scotland.

"The number of complaints about NHS hospital and community health services has gone up every year for the past five years and is now almost double what it was then.

"SNP ministers cannot blame the staff who are overworked and under resourced. The buck stops with them. It is time Shona Robison, the Cabinet Secretary for Health, woke up to the reality of what's happening to Scotland's health services under her watch."