Surrounded by barbed wire and without shelter from rain or dust, outside Pakistan’s embassy, hundreds of sick Afghans pass days and nights waiting for their visa appointment.

Abdul Ajan is first in the queue for when the embassy opens the next morning, squeezed into a space that smells of urine and is littered with rubbish and stale bread.

A frail looking 70-year-old, he clings to the closed gate with both hands, his shaking fingers tightly gripping the metal bars.

Ajan has been waiting here for three days, but tomorrow, he says, he will be seen. “Inshallah!” (“God willing.”) He travelled several hours from Kapiza province by bus to get to Kabul for his appointment.

“I’ve been sick for a while,” he says, his half-blind eyes barely opening. “I can hardly eat and I’m in pain, but doctors weren’t able to diagnose me here. That’s why I want to go to Pakistan.”

The health system in Afghanistan is overworked and underfunded. The government spends 3% on the sector, equal roughly $5 (£3.9) annually for each of its 37 million citizens. “Our main problem is security. Most of the budget is spent on that,” says Dr Wahid Mayar, spokesman for the public health ministry. It means that 70% of all healthcare in Afghanistan has to be paid for from people’s own pockets.

The country’s health system has been progressing steadily, the UN says, with 3,135 facilities open last year, bringing healthcare to 87% of the population. But quality and equipment are often lacking and, like Abdul Ajan, many Afghans aren’t diagnosed correctly and are left worried about their health and how problems can be treated.

“There are many challenges,” says Dr Ramin Faramarz, an orthopaedic surgeon in Kabul. “It already starts with electricity. When we have power cuts, we can’t operate our machines and – even worse – in surgery, it can become dangerous.”

Surrounded by barbed wire and rubbish, hundreds of Afghans sleep on the floor for days, waiting for their turn to apply for a visa to Pakistan. Photograph: Stefanie Glinski/The Guardian

Last year, a total of 61,731 medical visas were issues by Pakistan’s embassy and consulates in Afghanistan – roughly 5,000 applications are made daily and about 1,400 visas are issued daily.

“It really comes down to making a diagnosis, and that doesn’t always happen here, especially with kidney and heart diseases,” says the Pakistani ambassador to Afghanistan, Zahid Nasrullah Khan. “There are about 100,000 Afghans seeking medical treatment in Pakistan annually.”

Precise numbers are hard to come by, he says, as many might travel to Pakistan for business, but incorporate hospital visits into their trips.

Previously, visas for Pakistan weren’t strictly enforced, but in recent years regulations – and borders – have tightened.

For some, this can be a death sentence. “My neighbour – a good friend of my mother’s – died of kidney complications because there wasn’t enough time to get her a passport and process the visa,” says Mahamt Said, who lives near the Pakistan border in Nangarhar. Resting in the shade of his fruit garden, he has just returned from Pakistan himself, where he had kidney surgery. He looks older than his 26 years. A plastic bag with medical documents rests on his leg. His passport is full of stamps.

“It costs 10,000 afghanis [£99] to apply for a passport and you have to travel to the capital for it,” Said explains. “The visa is free, but the application process is long.” His surgery, done in nearby Peshawar, cost him 50,000 rupees (£260), not including subsequent check-ups and travel costs.

Outside the embassy in Kabul, located in a traffic-jammed, busy part of the capital, hundreds of men prepare for a cold night outside. Procedures for women are slightly different – with fewer lines and a separate room for the applicants. Most arrive in the early hours, or have their husbands queue for them.

Shah Faizal, 25, says he’s holding the spot for both him and his wife. A spinal cord injury has left him bound to a wheelchair and today he’s relying on the assistance from other visa applicants. “They help me lie down on the floor to sleep at night,” he says, adding that he only brought cardboard paper and a blanket for the night. “It’s tough to sleep anyway. Some people are so sick, they should be in hospital and you can hear them suffer at night.”

Shah Faizal, 25, has a spinal cord injury and plans to get medical treatment in Pakistan. Photograph: Stefanie Glinski/The Guardian

Like him, many have come from rural areas, are illiterate and depend on nearby print shops to help them fill out and print visa applications for 100 afghanis. In the early morning, the hustling and bustling starts, as thousands of people try to squeeze into the courtyard of the embassy’s visa section.

“There’s only one other way to get into Pakistan when you’re sick and it’s technically illegal,” explains a border guard at Turkham, the busiest port of entry between the two countries. He didn’t want to reveal his name.

“We talk to our Pakistani colleagues on the other side, and when a person with a life-threatening emergency arrives here without documents, we look away and let them proceed anyway.”