You are describing maintenance programs. While methadone has been the maintenance drug of choice for programs in the US due to legal barriers, it turns out that heroin maintenance programs are even more effective than maintenance programs based on substitution.
With a maintenance program, members come to the site to receive a legally-obtained, pharmaceutical-quality[0] supply of the drug. Depending on the program, they may either use it on-site (e.g. supervised injection) or bring it home. Crucially, the drug is provided free of charge, so members don't have to worry about how to come up with the money to pay for it.
It turns out that these programs reduce crime rates among the members, because most crime that they are committing was in pursuit of the money for their basic needs[1]. Without having to worry about obtaining their drug, or the safety issues associated with the illegal drug market, many are able to find stable jobs, return to stable housing, and lead otherwise normal lives.
This isn't new science - one of the first studied attempts was in the 1990s[2], and there have been many more papers published since, documenting the extraordinary benefits. The science behind it is rock-solid. The challenge, as always, is a political one.
[0] Zero adulterants, no contaminants - just like the supply of morphine or fentanyl that is used in hospitals for inpatient treatment.
[1] Yes, for someone addicted to opiates, the drug is a basic need: involuntary withdrawal is extremely dangerous even under medically supervised conditions, let alone in the conditions most people are forced to experience it.