Hi you don't need to do residency first, you will need to arrange your health cover first so you need to take your S1 form to your local INSS office. You can book an appointment online
Read more...
...XV106001
Use this link, fill your details in
then chose the option next available appointment (Quiero la primera cita disponible en el centro más próximo a este Código Postal) and put in your postcode
on the next page choose option 1 (Asist. Sanit. Internac.(Desplazamiento extranjero),
Información Prestaciones Asistencia Sanitaria Internacional (normativa internacional,desplazamiento al extranjero, etc.)
The next page gives you the choice of offices and times to choose from
I hope this helps