It's awful when dogs bite, what a shocking thing to happen. Do you normally go to pet him on the sofa like that and he's normally okay with it? It sounds like it is a good idea to not do it again for the time being.
I would take him to the vet and get him checked out. Sometimes dogs behave out of character when they are in pain, and from what you say it sounds like he's not well at the moment. However, and especially since it drew blood, I would also take some precautions for now, especially with your ds and any other children that visit the house. Make sure the dog always has somewhere quiet to go, shut him in a different room or behind a pet gate if there are children around, and don't go to pet him, especially if he's laying down - instead call him over to you.
Incidentally, for young children, approaching a dog that is stationary and petting it is a far-too-common scenario that results in a bite.
Once you've seen the vet, and assuming everything is okay, I would suggest seeking advice from a behaviourist. If you have insurance it's worth checking your policy in case it is covered. It's important to find a behaviourist that uses positive reinforcement (i.e. no punishment, in terms of the ordinary use of the word), because harsh methods carry the risk of making aggression worse. They will also be able to help you with the dog's nervousness that you mentioned.
There is a lot you can do to make trips to the vet less stressful. Again a behaviourist can help you with this if you want. For example, you could take a trip to the vet, sit in the waiting room briefly and give the dog lots of treats, then leave again. If you mention it to your vet they will probably be very happy for you to do this. Also you can train the dog in advance to get used to being felt in the way that the vet does and so on. But that's something for the future; in the meantime, best of luck at the vet and ensuring this doesn't happen again. A behaviourist will be able to help and depending where you are in the country people on here might have suggestions.