A hospital patient in the Borders has been waiting nearly four years to be discharged - in what has been described by the health board as a "very complex case".

Data released to the Scottish Liberal Democrats under freedom of information (FOI) legislation has been branded "miserable" by party health spokesman Alex Cole-Hamilton.

The Lib Dems requested information on the longest case of delayed discharge from each of the country's health boards up to the end of 2018/19.

Delayed discharge happens where a patient is well enough to leave hospital but has to wait for outside assistance to be put in place - that may be social care provisions, such as a place in a care home or upgrades to their home.

NHS Borders tops the list with the patient who has waited 1373 days.

NHS Fife is next with a patient waiting 447 days, followed by the Dumfries and Galloway health board - where a patient has been awaiting discharge for 391 days.

Grampian, Lanarkshire and Lothian all have patients waiting to leave for between 210 and 241 days - which is seven-eight months.

NHS Forth Valley, Western Isles, Orkney and Shetland all have a patient overstaying for under 100 days.

NHS Greater Glasgow and Clyde and Tayside could not release the numbers for fear of identifying the patient, while NHS Highland issued the data in the wrong format and NHS Ayrshire and Arran did not respond to the request.

Mr Cole-Hamilton said capacity at hospitals across Scotland is being strained, with delayed discharges continuing to be a factor.

He also claimed the NHS is forced to fork out £100,000 for every patient kept in hospital for a year unnecessarily.

He said: "Hospitals are getting congested all the way up to critical care because there isn't enough capacity to take care of people in the community.

"Even more damaging is the crushing cost to patients' wellbeing.

“Conditions worsen and critical opportunities to rebuild their lives are lost. It's miserable.

"Medical staff have declared these people ready to leave hospital but the community-based support they need to move on simply doesn't exist.

"These are factors within this government's control.

"Indeed, the SNP Government promised to eradicate delayed discharges from the system by 2016.

"It's time to end the social care scandal. Staff are working tirelessly but there just aren't enough of them to go around.

"The SNP's new workforce plan, published a whole year late, must now make demonstrable progress.

"Furthermore, we simply can't afford for existing staff to be driven away by the Conservatives' damaging Brexit, so Boris Johnson must now step up too."

The Scottish Government released its health and social care integration workforce plan earlier this month, pledging to recruit a further 375 whole time equivalent district nurses by 2024.

A Scottish Government spokesman said: "People should not have to spend unnecessary time in hospital once treatment is complete. That is why we are investing more than £700m this year to support social care and integration.

"Progress has been made in reducing delays - bed days lost are down by 1% overall since 2016/17. However, we want to go further with our partners in local government, the NHS and in integration authorities to address where delays have increased and work to improve performance.

"The ongoing integration of health and social care has been key to achieving progress in recent years, with integration authorities now responsible for nearly £9bn of funding previously managed separately by health boards and councils.

"We have established an expert support group, made up of clinical and social care professionals, to work with those health and social care partnerships facing the most significant challenges and ensure sustainable progress can be achieved."

Nicky Berry, director of nursing, midwifery AHPs and acute services at NHS Borders, said: "We are unable to comment on individual cases for reasons of confidentiality.

"Across our health and social care system it is always our aim to ensure that patients are only admitted to hospital when necessary, and when an admission is required the patient's stay is safe and as brief as possible.

"Occasionally there are factors which lead to a patient not being able to move to their next appropriate place of care as soon as they are medically fit.

"We work very closely with patients, carers and our partners across the health and social care system to ensure that these cases are the exception and not the norm."