This very much depends on your health and on the treatment you are having. Always ask your chosen provider before booking your trip, how long you need to remain in Costa Rica after your treatment as your treatment provider will need to confirm you are fit to fly and to leave Costa Rica.