There are many interpretations of this prayer of faith. This is a tough topic to navigate as we seek to balance allowing people to hope but also cautioning against false hope.
This passage does speak of sin and suffering, however we know not all suffering/sickness is due to personal sin (see the Book of Job, John 9). The reverse is also true, being healthy doesn't automatically indicate righteousness. Sickness can be due to our actions or are parents' actions.
We should pray to discern where we have sin in our lives. God can use times of sickness to cause us to slow down and ask these questions. James may be referring to an individual who is physically sick and spiritually weak (may have wandered from the Lord). This is why he says if you are in such a position then you should inform the elders and then the community can come beside you to help. After repenting God may lift such an illness.
Elders are to pray and anoint with oil. Oil is associated with setting apart something/someone for God. Jesus has never been recorded as using oil in a medical sense so we must be careful not to regard oil as a miracle cure. We should call upon the name of the Lord to heal the body and soul to be fully restored.