Here is the official advice:
"Who can receive all NHS treatment free of charge
Some people from abroad can receive all NHS hospital treatment free of charge. If you are entitled to free NHS hospital treatment, your spouse, civil partner and dependent child(ren) will also be able to receive free treatment, but only if they live with you permanently in the UK.
You can receive free NHS hospital treatment if you:-
have been living legally in the UK for at least 12 months when you seek treatment, and did not come to the UK for private medical treatment. Temporary absences from the UK of up to three months are ignored
have come to the UK to take up permanent residence, for example, if you are a former UK resident who has returned from abroad, or if you have been granted leave to enter or remain as a spouse
have come to the UK to work, either as an employee or self-employed person. This does not include people on short business trips
normally work in the UK, but are temporarily working abroad, have at least 10 years continuous residence in the UK, and have been abroad for less than 5. However, if you are studying abroad you are not entitled to free NHS treatment
are receiving a UK war disablement pension or war widows’ pension
are an asylum seeker or have been granted exceptional leave to remain or refugee status. Proof of your immigration status from the Home Office may be required. In England and Scotland, if you're refused asylum, you do not have the right to free treatment if you have temporary admission. However, if you're a failed asylum seeker who was receiving a course of treatment, that course of treatment should continue until it is finished without you being asked to pay for it. In Wales, there are plans to change the rules and you might get free treatment. If you’re asked to pay, get advice about how to challenge the charge
have been identified as having been trafficked from abroad or are believed to have been trafficked from abroad
are imprisoned in the UK or detained by UK immigration authorities
are a UK state pensioner who spends up to six months a year living in another European Economic Area (EEA) state, but are not a resident of that state
are working in another EEA country, or in Switzerland, but are paying compulsory UK national insurance contributions
are a student following a course of study which lasts at least six months, or is substantially funded by the UK government."
I hope this helps clarify the position.