We have implemented similar feature on our health information opensource project, mNet. Check this controller code. Follow through the service implementations and dao. You will find the details you are looking for.