Doctors at a palliative care unit in the Borders are trialling a phone app to help prescribe pain relief for patients nearing the end of their life.
Traditionally, when medication needs to be changed, a doctor has to perform a calculation using tables of equivalence to ensure the correct dosage.
Conversion can be complex and an error could see a patient given too little pain relief or be at risk of overdose.
The Safer Prescribing of Opioids Tool (SPOT) app aims to tackle that.
It was created by Dr Roger Flint following his own experience as a junior doctor and is now on trial at the Margaret Kerr Unit near Melrose.
Two weeks after graduating from medical school Dr Flint was covering a night shift when he was asked to change a patient's method of pain relief.
"The patient was receiving her pain relief and her food through a tube that went into her stomach," he told BBC Scotland's The Nine.
"But that tube had blocked. The nursing staff asked me to change her from the tube pain relief to an infusion under the skin.
"I found it quite difficult to perform that calculation and I asked for some help to double check what I had done.
"Unfortunately, my senior doctor was not available and so that patient went without pain relief until I could get some more help."
Working with app developers Waracle, he created the SPOT app to ensure other doctors would have a means of checking their calculations.
"I designed SPOT to make sure that no other prescriber would be put in that position again," he said.
"If I'd had SPOT at that time I could have confidently performed that calculation, double checked it independently and that patient would have received her pain relief on time."
Dr Annabel Howell from NHS Borders said she hoped the app would increase staff confidence when prescribing.
"You are not using it as the sole way of performing that calculation, you are doing it yourself first but it is a great way to double check that," she said.
"In the past I have always done that by doing the calculation one way and then doing it a different way and checking I come up with the same amount.
"If there is another member of staff then we will ask them to do it but there isn't always someone there so it is really useful."
Increasingly end-of-life care happens in the home supported by nursing staff and out-of-hours GPs.
Dr Scott Jamieson, from Dundee, provides out-of-hours cover for large parts of Angus.
He is often called to see dying patients who have not been in his care through the day and has also been using the app.
"We are managing more and more complicated medication regimes in the community," he said.
"I recognise the distress that I am going into and I am trying to support that.
"I want to make sure that I am confident when I am doing my conversions."
A number of other health boards are now looking at the possibility of trialling the phone app.
Meanwhile, its developers are investigating whether it could be adapted for use with other types of medicine.