It is commmonly agreed that no part of a pig is halal. On this base, some Muslim states - as well as Israel - impose that medicine capsules be made out of alternative materials, which are available and without any functional drawback. Hence, more and more international companies tend to avoid non-halal ingredients in medicine.
In cases where there is no alternative, it is often agreed to transgress minor commandments for an important reason, in this case to protect a higher value (e.g. ones life or health).
This fatwa exposes it well, saying that it may be acceptable to eat the capsules if
It is reasonably known that the medicine will be effective, and is needed;
There is no permissible alternative reasonably available;
This has been established by an expert Muslim doctor who is at least outwardly upright and god-fearing.
(where the latter to find may be a problem in a non-Muslim country).
Now, you are asking about taking the medicine after removing the capsule.
For this, it may be advisable to ask a doctor or a pharmacist whether this may be harmful or spoil the effect, as some medicine must not dissolve too early.
Physically and chemically, it is compulsory that the capsule is not dissolved by the contents; else, the medicine would perish in short time. Thus, the quantity of gelatine in the medicine will be very small.
I did not find any qualified answer on your particular question as to whether traces should be avoided.
There are two possible approaches to the commandment not to eat from swine.
The approach that God made this commandment because it is not good for us to elevate pigs or eat from them. Under this aspect, some molecules from a substance that may have been made out of bones of a swine are very likely not to be harmful, so that it is evenly likely that the commandment does not concern this.
The approach that keeping the commandments of God is a sign of respect we owe. This would draw the question on the point whether taking away the capsule is an adequate means to show this respect.
Hence, if it is a necessary or at least effective medicine that is only available in swine gelantine capsules, and it does not lose its efficiency when swallowed without the capsule, removing it is for sure a sufficient means to solve the problem.
If it is not very necessary - like ginseng, vitamines etc. - you will usually find it in a different form.
I leave it open whether removing a capsule is halal in this case.