Added fourth parameter patientdocId which is needed to solve the patients with same patient id in same clinic issue.And refactored the code.